From 69c2cf11d3f964e2488927e3341e375e15413751 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 12 Apr 2022 18:38:13 +0800 Subject: [PATCH] ehn(query): return the performance_schema db when "show databases" sql statement issued. --- include/util/tdef.h | 1 + source/dnode/mnode/impl/src/mndDb.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/util/tdef.h b/include/util/tdef.h index 263c90c0f8..246c3e2eaa 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -95,6 +95,7 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_TIME_PRECISION_NANO_STR "ns" #define TSDB_INFORMATION_SCHEMA_DB "information_schema" +#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" #define TSDB_INS_TABLE_DNODES "dnodes" #define TSDB_INS_TABLE_MNODES "mnodes" #define TSDB_INS_TABLE_MODULES "modules" diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 49e9ccaba6..f82e381715 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -1486,6 +1486,18 @@ static void setInformationSchemaDbCfg(SDbObj *pDbObj) { pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; } +static void setPerfSchemaDbCfg(SDbObj* pDbObj) { + ASSERT(pDbObj != NULL); + strncpy(pDbObj->name, TSDB_PERFORMANCE_SCHEMA_DB, tListLen(pDbObj->name)); + + pDbObj->createdTime = 0; + pDbObj->cfg.numOfVgroups = 0; + pDbObj->cfg.quorum = 1; + pDbObj->cfg.replications = 1; + pDbObj->cfg.update = 1; + pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; +} + static bool mndGetTablesOfDbFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) { SVgObj *pVgroup = pObj; int32_t *numOfTables = p1; @@ -1515,10 +1527,15 @@ static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 } // Append the information_schema database into the result. - if (numOfRows < rowsCapacity) { - SDbObj dummyISDb = {0}; - setInformationSchemaDbCfg(&dummyISDb); - dumpDbInfoToPayload(data, &dummyISDb, pShow, numOfRows, rowsCapacity, 14); + if (numOfRows + 2 < rowsCapacity) { + SDbObj infoschemaDb = {0}; + setInformationSchemaDbCfg(&infoschemaDb); + dumpDbInfoToPayload(data, &infoschemaDb, pShow, numOfRows, rowsCapacity, 14); + numOfRows += 1; + + SDbObj perfschemaDb = {0}; + setPerfSchemaDbCfg(&perfschemaDb); + dumpDbInfoToPayload(data, &perfschemaDb, pShow, numOfRows, rowsCapacity, 14); numOfRows += 1; } -- GitLab