From 9711c830feccf54b489ed1268e1ba398e95547bd Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Wed, 13 Mar 2024 15:17:43 +0800 Subject: [PATCH] show create table --- include/libs/nodes/cmdnodes.h | 3 +- source/common/src/tmsg.c | 23 +++++------ source/libs/command/src/command.c | 54 ++++++++++++++++---------- source/libs/parser/src/parTranslater.c | 22 ++++++----- source/libs/parser/src/parUtil.c | 23 +++++++---- source/libs/qcom/src/queryUtil.c | 11 ++++-- source/libs/qcom/src/querymsg.c | 2 +- 7 files changed, 83 insertions(+), 55 deletions(-) diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 50c9261540..a0097374f4 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -23,7 +23,8 @@ extern "C" { #include "query.h" #include "querynodes.h" -#define DESCRIBE_RESULT_COLS 7 +#define DESCRIBE_RESULT_COLS 4 +#define DESCRIBE_RESULT_COLS_COMPRESS 7 #define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE) #define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE) #define DESCRIBE_RESULT_NOTE_LEN (16 + VARSTR_HEADER_SIZE) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index a667fdd95f..86b84738b5 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2904,11 +2904,13 @@ int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) { if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1; if (tEncodeBinary(&encoder, pRsp->pTags, pRsp->tagsLen) < 0) return -1; - for (int32_t i = 0; i < pRsp->numOfColumns; ++i) - { - SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; - if (tEncodeSSchemaExt(&encoder, pSchemaExt) < 0) return -1; + if (useCompress(pRsp->tableType)) { + for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { + SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; + if (tEncodeSSchemaExt(&encoder, pSchemaExt) < 0) return -1; + } } + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -2967,8 +2969,8 @@ int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) if (tDecodeI32(&decoder, &pRsp->tagsLen) < 0) return -1; if (tDecodeBinaryAlloc(&decoder, (void **)&pRsp->pTags, NULL) < 0) return -1; - if (1 /*!tDecodeIsEnd(&decoder)*/) { - if (pRsp->numOfColumns > 0) { + if (!tDecodeIsEnd(&decoder)) { + if (useCompress(pRsp->tableType) && pRsp->numOfColumns > 0) { pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); if (pRsp->pSchemaExt == NULL) return -1; @@ -4454,7 +4456,7 @@ static int32_t tEncodeSTableMetaRsp(SEncoder *pEncoder, STableMetaRsp *pRsp) { if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1; } - if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) { + if (useCompress(pRsp->tableType)) { for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1; @@ -4492,10 +4494,8 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) { pRsp->pSchemas = NULL; } - // if (tDecodeIsEnd(pDecoder)) return 0; if (!tDecodeIsEnd(pDecoder)) { - if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) { - if (pRsp->numOfColumns > 0) { + if (useCompress(pRsp->tableType) && pRsp->numOfColumns > 0) { pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); if (pRsp->pSchemaExt == NULL) return -1; @@ -4505,9 +4505,6 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) { pSchemaExt->colId = i; pSchemaExt->compress = 0x02000303; } - } else { - pRsp->pSchemaExt = NULL; - } } else { pRsp->pSchemaExt = NULL; } diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 1ca47297bf..5d6ab14986 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -100,7 +100,8 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) { return code; } -static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta, int8_t biMode) { +static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta, + int8_t biMode) { int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows; blockDataEnsureCapacity(pBlock, blockCap); pBlock->info.rows = 0; @@ -114,12 +115,18 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, // Note SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3); // encode - SColumnInfoData* pCol5 = taosArrayGet(pBlock->pDataBlock, 4); + SColumnInfoData* pCol5 = NULL; // compress - SColumnInfoData* pCol6 = taosArrayGet(pBlock->pDataBlock, 5); + SColumnInfoData* pCol6 = NULL; // level - SColumnInfoData* pCol7 = taosArrayGet(pBlock->pDataBlock, 6); - char buf[DESCRIBE_RESULT_FIELD_LEN] = {0}; + SColumnInfoData* pCol7 = NULL; + if (useCompress(pMeta->tableType)) { + pCol5 = taosArrayGet(pBlock->pDataBlock, 4); + pCol6 = taosArrayGet(pBlock->pDataBlock, 5); + pCol7 = taosArrayGet(pBlock->pDataBlock, 6); + } + + char buf[DESCRIBE_RESULT_FIELD_LEN] = {0}; for (int32_t i = 0; i < numOfRows; ++i) { if (invisibleColumn(sysInfoUser, pMeta->tableType, pMeta->schema[i].flags)) { continue; @@ -136,21 +143,24 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, STR_TO_VARSTR(buf, "VIEW COL"); } colDataSetVal(pCol4, pBlock->info.rows, buf, false); - if (i < pMeta->tableInfo.numOfColumns) { - STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress))); - colDataSetVal(pCol5, pBlock->info.rows, buf, false); - STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress))); - colDataSetVal(pCol6, pBlock->info.rows, buf, false); - STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress))); - colDataSetVal(pCol7, pBlock->info.rows, buf, false); - } else { - STR_TO_VARSTR(buf, ""); - colDataSetVal(pCol5, pBlock->info.rows, buf, false); - STR_TO_VARSTR(buf, ""); - colDataSetVal(pCol6, pBlock->info.rows, buf, false); - STR_TO_VARSTR(buf, ""); - colDataSetVal(pCol7, pBlock->info.rows, buf, false); + if (useCompress(pMeta->tableType)) { + if (i < pMeta->tableInfo.numOfColumns) { + STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress))); + colDataSetVal(pCol5, pBlock->info.rows, buf, false); + STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress))); + colDataSetVal(pCol6, pBlock->info.rows, buf, false); + STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress))); + colDataSetVal(pCol7, pBlock->info.rows, buf, false); + } else { + STR_TO_VARSTR(buf, ""); + colDataSetVal(pCol5, pBlock->info.rows, buf, false); + STR_TO_VARSTR(buf, ""); + colDataSetVal(pCol6, pBlock->info.rows, buf, false); + STR_TO_VARSTR(buf, ""); + colDataSetVal(pCol7, pBlock->info.rows, buf, false); + } } + ++(pBlock->info.rows); } if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) { @@ -181,7 +191,11 @@ static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** code = setDescResultIntoDataBlock(sysInfoUser, pBlock, numOfRows, pDesc->pMeta, biMode); } if (TSDB_CODE_SUCCESS == code) { - code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp); + if (pDesc->pMeta && useCompress(pDesc->pMeta->tableType)) { + code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS_COMPRESS, pRsp); + } else { + code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp); + } } blockDataDestroy(pBlock); return code; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index fade19f833..4726fe7401 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -9228,8 +9228,9 @@ static int32_t extractExplainResultSchema(int32_t* numOfCols, SSchema** pSchema) return TSDB_CODE_SUCCESS; } -static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema) { +static int32_t extractDescribeResultSchema(STableMeta* pMeta, int32_t* numOfCols, SSchema** pSchema) { *numOfCols = DESCRIBE_RESULT_COLS; + if (pMeta && useCompress(pMeta->tableType)) *numOfCols = DESCRIBE_RESULT_COLS_COMPRESS; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { return TSDB_CODE_OUT_OF_MEMORY; @@ -9251,17 +9252,19 @@ static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema (*pSchema)[3].bytes = DESCRIBE_RESULT_NOTE_LEN; strcpy((*pSchema)[3].name, "note"); - (*pSchema)[4].type = TSDB_DATA_TYPE_BINARY; - (*pSchema)[4].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; - strcpy((*pSchema)[4].name, "encode"); + if (pMeta && useCompress(pMeta->tableType)) { + (*pSchema)[4].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[4].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; + strcpy((*pSchema)[4].name, "encode"); (*pSchema)[5].type = TSDB_DATA_TYPE_BINARY; - (*pSchema)[5].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; - strcpy((*pSchema)[5].name, "compress"); + (*pSchema)[5].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; + strcpy((*pSchema)[5].name, "compress"); (*pSchema)[6].type = TSDB_DATA_TYPE_BINARY; - (*pSchema)[6].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; - strcpy((*pSchema)[6].name, "level"); + (*pSchema)[6].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; + strcpy((*pSchema)[6].name, "level"); + } return TSDB_CODE_SUCCESS; } @@ -9391,7 +9394,8 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS case QUERY_NODE_EXPLAIN_STMT: return extractExplainResultSchema(numOfCols, pSchema); case QUERY_NODE_DESCRIBE_STMT: - return extractDescribeResultSchema(numOfCols, pSchema); + SDescribeStmt* pNode = (SDescribeStmt*)pRoot; + return extractDescribeResultSchema(pNode->pMeta, numOfCols, pSchema); case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: return extractShowCreateDatabaseResultSchema(numOfCols, pSchema); case QUERY_NODE_SHOW_DB_ALIVE_STMT: diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index cffbe11c52..6cc1446ac1 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -282,16 +282,21 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) { return NULL; } - size_t schemaExtSize = pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt); + size_t schemaExtSize = 0; + if (useCompress(pTableMeta->tableType)) { + schemaExtSize = pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt); + } size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema); STableMeta* p = taosMemoryMalloc(size + schemaExtSize); if (NULL == p) return NULL; - SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size); memcpy(p, pTableMeta, size); - p->schemaExt = pSchemaExt; - memcpy(pSchemaExt, pTableMeta->schemaExt, schemaExtSize); + if (useCompress(pTableMeta->tableType)) { + SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size); + p->schemaExt = pSchemaExt; + memcpy(pSchemaExt, pTableMeta->schemaExt, schemaExtSize); + } return p; } @@ -1145,10 +1150,12 @@ STableCfg* tableCfgDup(STableCfg* pCfg) { SSchema* pSchema = taosMemoryMalloc(schemaSize); memcpy(pSchema, pCfg->pSchemas, schemaSize); - - int32_t schemaExtSize = pCfg->numOfColumns * sizeof(SSchemaExt); - SSchemaExt* pSchemaExt = taosMemoryMalloc(schemaExtSize); - memcpy(pSchemaExt, pCfg->pSchemaExt, schemaExtSize); + SSchemaExt* pSchemaExt = NULL; + if (useCompress(pCfg->tableType)) { + int32_t schemaExtSize = pCfg->numOfColumns * sizeof(SSchemaExt); + pSchemaExt = taosMemoryMalloc(schemaExtSize); + memcpy(pSchemaExt, pCfg->pSchemaExt, schemaExtSize); + } pNew->pSchemas = pSchema; pNew->pSchemaExt = pSchemaExt; diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 9803f1cf43..78d8f11af4 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -463,14 +463,19 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) { } int32_t metaSize = sizeof(STableMeta) + numOfField * sizeof(SSchema); - int32_t schemaExtSize = pSrc->tableInfo.numOfColumns * sizeof(SSchemaExt); + int32_t schemaExtSize = 0; + if (useCompress(pSrc->tableType)) { + schemaExtSize = pSrc->tableInfo.numOfColumns * sizeof(SSchemaExt); + } *pDst = taosMemoryMalloc(metaSize + schemaExtSize); if (NULL == *pDst) { return TSDB_CODE_OUT_OF_MEMORY; } memcpy(*pDst, pSrc, metaSize); - (*pDst)->schemaExt = (SSchemaExt*)((char*)*pDst + metaSize); - memcpy((*pDst)->schemaExt, pSrc->schemaExt, schemaExtSize); + if (useCompress(pSrc->tableType)) { + (*pDst)->schemaExt = (SSchemaExt*)((char*)*pDst + metaSize); + memcpy((*pDst)->schemaExt, pSrc->schemaExt, schemaExtSize); + } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 2130ee7d6b..962a5565f6 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -423,7 +423,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); - if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_NORMAL_TABLE) { + if (useCompress(msg->tableType)) { pTableMeta->schemaExt = pSchemaExt; memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize); }