show create table

This commit is contained in:
factosea 2024-03-13 15:17:43 +08:00
parent b10deacd63
commit 9711c830fe
7 changed files with 83 additions and 55 deletions

View File

@ -23,7 +23,8 @@ extern "C" {
#include "query.h" #include "query.h"
#include "querynodes.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_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE)
#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE) #define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE)
#define DESCRIBE_RESULT_NOTE_LEN (16 + VARSTR_HEADER_SIZE) #define DESCRIBE_RESULT_NOTE_LEN (16 + VARSTR_HEADER_SIZE)

View File

@ -2904,11 +2904,13 @@ int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) {
if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1; if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1;
if (tEncodeBinary(&encoder, pRsp->pTags, pRsp->tagsLen) < 0) return -1; if (tEncodeBinary(&encoder, pRsp->pTags, pRsp->tagsLen) < 0) return -1;
for (int32_t i = 0; i < pRsp->numOfColumns; ++i) if (useCompress(pRsp->tableType)) {
{ for (int32_t i = 0; i < pRsp->numOfColumns; ++i) {
SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i];
if (tEncodeSSchemaExt(&encoder, pSchemaExt) < 0) return -1; if (tEncodeSSchemaExt(&encoder, pSchemaExt) < 0) return -1;
}
} }
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; 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 (tDecodeI32(&decoder, &pRsp->tagsLen) < 0) return -1;
if (tDecodeBinaryAlloc(&decoder, (void **)&pRsp->pTags, NULL) < 0) return -1; if (tDecodeBinaryAlloc(&decoder, (void **)&pRsp->pTags, NULL) < 0) return -1;
if (1 /*!tDecodeIsEnd(&decoder)*/) { if (!tDecodeIsEnd(&decoder)) {
if (pRsp->numOfColumns > 0) { if (useCompress(pRsp->tableType) && pRsp->numOfColumns > 0) {
pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns);
if (pRsp->pSchemaExt == NULL) return -1; 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 (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) { for (int32_t i = 0; i < pRsp->numOfColumns; ++i) {
SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i];
if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1; if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1;
@ -4492,10 +4494,8 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
pRsp->pSchemas = NULL; pRsp->pSchemas = NULL;
} }
// if (tDecodeIsEnd(pDecoder)) return 0;
if (!tDecodeIsEnd(pDecoder)) { if (!tDecodeIsEnd(pDecoder)) {
if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) { if (useCompress(pRsp->tableType) && pRsp->numOfColumns > 0) {
if (pRsp->numOfColumns > 0) {
pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns);
if (pRsp->pSchemaExt == NULL) return -1; if (pRsp->pSchemaExt == NULL) return -1;
@ -4505,9 +4505,6 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
pSchemaExt->colId = i; pSchemaExt->colId = i;
pSchemaExt->compress = 0x02000303; pSchemaExt->compress = 0x02000303;
} }
} else {
pRsp->pSchemaExt = NULL;
}
} else { } else {
pRsp->pSchemaExt = NULL; pRsp->pSchemaExt = NULL;
} }

View File

@ -100,7 +100,8 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
return code; 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; int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows;
blockDataEnsureCapacity(pBlock, blockCap); blockDataEnsureCapacity(pBlock, blockCap);
pBlock->info.rows = 0; pBlock->info.rows = 0;
@ -114,12 +115,18 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
// Note // Note
SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3); SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3);
// encode // encode
SColumnInfoData* pCol5 = taosArrayGet(pBlock->pDataBlock, 4); SColumnInfoData* pCol5 = NULL;
// compress // compress
SColumnInfoData* pCol6 = taosArrayGet(pBlock->pDataBlock, 5); SColumnInfoData* pCol6 = NULL;
// level // level
SColumnInfoData* pCol7 = taosArrayGet(pBlock->pDataBlock, 6); SColumnInfoData* pCol7 = NULL;
char buf[DESCRIBE_RESULT_FIELD_LEN] = {0}; 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) { for (int32_t i = 0; i < numOfRows; ++i) {
if (invisibleColumn(sysInfoUser, pMeta->tableType, pMeta->schema[i].flags)) { if (invisibleColumn(sysInfoUser, pMeta->tableType, pMeta->schema[i].flags)) {
continue; continue;
@ -136,21 +143,24 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
STR_TO_VARSTR(buf, "VIEW COL"); STR_TO_VARSTR(buf, "VIEW COL");
} }
colDataSetVal(pCol4, pBlock->info.rows, buf, false); colDataSetVal(pCol4, pBlock->info.rows, buf, false);
if (i < pMeta->tableInfo.numOfColumns) { if (useCompress(pMeta->tableType)) {
STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress))); if (i < pMeta->tableInfo.numOfColumns) {
colDataSetVal(pCol5, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress)));
STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress))); colDataSetVal(pCol5, pBlock->info.rows, buf, false);
colDataSetVal(pCol6, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress)));
STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress))); colDataSetVal(pCol6, pBlock->info.rows, buf, false);
colDataSetVal(pCol7, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress)));
} else { colDataSetVal(pCol7, pBlock->info.rows, buf, false);
STR_TO_VARSTR(buf, ""); } else {
colDataSetVal(pCol5, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, "");
STR_TO_VARSTR(buf, ""); colDataSetVal(pCol5, pBlock->info.rows, buf, false);
colDataSetVal(pCol6, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, "");
STR_TO_VARSTR(buf, ""); colDataSetVal(pCol6, pBlock->info.rows, buf, false);
colDataSetVal(pCol7, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, "");
colDataSetVal(pCol7, pBlock->info.rows, buf, false);
}
} }
++(pBlock->info.rows); ++(pBlock->info.rows);
} }
if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) { 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); code = setDescResultIntoDataBlock(sysInfoUser, pBlock, numOfRows, pDesc->pMeta, biMode);
} }
if (TSDB_CODE_SUCCESS == code) { 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); blockDataDestroy(pBlock);
return code; return code;

View File

@ -9228,8 +9228,9 @@ static int32_t extractExplainResultSchema(int32_t* numOfCols, SSchema** pSchema)
return TSDB_CODE_SUCCESS; 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; *numOfCols = DESCRIBE_RESULT_COLS;
if (pMeta && useCompress(pMeta->tableType)) *numOfCols = DESCRIBE_RESULT_COLS_COMPRESS;
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
if (NULL == (*pSchema)) { if (NULL == (*pSchema)) {
return TSDB_CODE_OUT_OF_MEMORY; 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; (*pSchema)[3].bytes = DESCRIBE_RESULT_NOTE_LEN;
strcpy((*pSchema)[3].name, "note"); strcpy((*pSchema)[3].name, "note");
(*pSchema)[4].type = TSDB_DATA_TYPE_BINARY; if (pMeta && useCompress(pMeta->tableType)) {
(*pSchema)[4].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; (*pSchema)[4].type = TSDB_DATA_TYPE_BINARY;
strcpy((*pSchema)[4].name, "encode"); (*pSchema)[4].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN;
strcpy((*pSchema)[4].name, "encode");
(*pSchema)[5].type = TSDB_DATA_TYPE_BINARY; (*pSchema)[5].type = TSDB_DATA_TYPE_BINARY;
(*pSchema)[5].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; (*pSchema)[5].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN;
strcpy((*pSchema)[5].name, "compress"); strcpy((*pSchema)[5].name, "compress");
(*pSchema)[6].type = TSDB_DATA_TYPE_BINARY; (*pSchema)[6].type = TSDB_DATA_TYPE_BINARY;
(*pSchema)[6].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN; (*pSchema)[6].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN;
strcpy((*pSchema)[6].name, "level"); strcpy((*pSchema)[6].name, "level");
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -9391,7 +9394,8 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS
case QUERY_NODE_EXPLAIN_STMT: case QUERY_NODE_EXPLAIN_STMT:
return extractExplainResultSchema(numOfCols, pSchema); return extractExplainResultSchema(numOfCols, pSchema);
case QUERY_NODE_DESCRIBE_STMT: 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: case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
return extractShowCreateDatabaseResultSchema(numOfCols, pSchema); return extractShowCreateDatabaseResultSchema(numOfCols, pSchema);
case QUERY_NODE_SHOW_DB_ALIVE_STMT: case QUERY_NODE_SHOW_DB_ALIVE_STMT:

View File

@ -282,16 +282,21 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
return NULL; 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); size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema);
STableMeta* p = taosMemoryMalloc(size + schemaExtSize); STableMeta* p = taosMemoryMalloc(size + schemaExtSize);
if (NULL == p) return NULL; if (NULL == p) return NULL;
SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size);
memcpy(p, pTableMeta, size); memcpy(p, pTableMeta, size);
p->schemaExt = pSchemaExt; if (useCompress(pTableMeta->tableType)) {
memcpy(pSchemaExt, pTableMeta->schemaExt, schemaExtSize); SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size);
p->schemaExt = pSchemaExt;
memcpy(pSchemaExt, pTableMeta->schemaExt, schemaExtSize);
}
return p; return p;
} }
@ -1145,10 +1150,12 @@ STableCfg* tableCfgDup(STableCfg* pCfg) {
SSchema* pSchema = taosMemoryMalloc(schemaSize); SSchema* pSchema = taosMemoryMalloc(schemaSize);
memcpy(pSchema, pCfg->pSchemas, schemaSize); memcpy(pSchema, pCfg->pSchemas, schemaSize);
SSchemaExt* pSchemaExt = NULL;
int32_t schemaExtSize = pCfg->numOfColumns * sizeof(SSchemaExt); if (useCompress(pCfg->tableType)) {
SSchemaExt* pSchemaExt = taosMemoryMalloc(schemaExtSize); int32_t schemaExtSize = pCfg->numOfColumns * sizeof(SSchemaExt);
memcpy(pSchemaExt, pCfg->pSchemaExt, schemaExtSize); pSchemaExt = taosMemoryMalloc(schemaExtSize);
memcpy(pSchemaExt, pCfg->pSchemaExt, schemaExtSize);
}
pNew->pSchemas = pSchema; pNew->pSchemas = pSchema;
pNew->pSchemaExt = pSchemaExt; pNew->pSchemaExt = pSchemaExt;

View File

@ -463,14 +463,19 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
} }
int32_t metaSize = sizeof(STableMeta) + numOfField * sizeof(SSchema); 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); *pDst = taosMemoryMalloc(metaSize + schemaExtSize);
if (NULL == *pDst) { if (NULL == *pDst) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
memcpy(*pDst, pSrc, metaSize); memcpy(*pDst, pSrc, metaSize);
(*pDst)->schemaExt = (SSchemaExt*)((char*)*pDst + metaSize); if (useCompress(pSrc->tableType)) {
memcpy((*pDst)->schemaExt, pSrc->schemaExt, schemaExtSize); (*pDst)->schemaExt = (SSchemaExt*)((char*)*pDst + metaSize);
memcpy((*pDst)->schemaExt, pSrc->schemaExt, schemaExtSize);
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -423,7 +423,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta *
pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); 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; pTableMeta->schemaExt = pSchemaExt;
memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize); memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
} }