desc table
This commit is contained in:
parent
e2ca8c45a3
commit
5dd4d05b2e
|
@ -56,7 +56,7 @@
|
|||
#define TSDB_COLVAL_LEVEL_LOW 3
|
||||
|
||||
#define TSDB_CL_COMMENT_LEN 1025
|
||||
#define TSDB_CL_COMPRESS_OPTION_LEN 32
|
||||
#define TSDB_CL_COMPRESS_OPTION_LEN 12
|
||||
|
||||
extern const char* supportedEncode[4];
|
||||
extern const char* supportedCompress[6];
|
||||
|
|
|
@ -27,18 +27,19 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SBuffer SBuffer;
|
||||
typedef struct SSchema SSchema;
|
||||
typedef struct SSchema2 SSchema2;
|
||||
typedef struct STColumn STColumn;
|
||||
typedef struct STSchema STSchema;
|
||||
typedef struct SValue SValue;
|
||||
typedef struct SColVal SColVal;
|
||||
typedef struct SRow SRow;
|
||||
typedef struct SRowIter SRowIter;
|
||||
typedef struct STagVal STagVal;
|
||||
typedef struct STag STag;
|
||||
typedef struct SColData SColData;
|
||||
typedef struct SBuffer SBuffer;
|
||||
typedef struct SSchema SSchema;
|
||||
typedef struct SSchemaExt SSchemaExt;
|
||||
typedef struct SSchema2 SSchema2;
|
||||
typedef struct STColumn STColumn;
|
||||
typedef struct STSchema STSchema;
|
||||
typedef struct SValue SValue;
|
||||
typedef struct SColVal SColVal;
|
||||
typedef struct SRow SRow;
|
||||
typedef struct SRowIter SRowIter;
|
||||
typedef struct STagVal STagVal;
|
||||
typedef struct STag STag;
|
||||
typedef struct SColData SColData;
|
||||
|
||||
#define HAS_NONE ((uint8_t)0x1)
|
||||
#define HAS_NULL ((uint8_t)0x2)
|
||||
|
|
|
@ -543,15 +543,19 @@ struct SSchema {
|
|||
int32_t bytes;
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
};
|
||||
struct SSchemaExt {
|
||||
col_id_t colId;
|
||||
uint32_t compress;
|
||||
};
|
||||
|
||||
// compress flag
|
||||
|
||||
// |----l1 compAlg----|-----l2 compAlg---|---level--|
|
||||
// |------8bit--------|------16bit-------|---8bit---|
|
||||
|
||||
#define COMPRESS_L1_TYPE_U32(type) ((type)&0xFF)
|
||||
#define COMPRESS_L1_TYPE_U32(type) (((type) >> 24) & 0xFF)
|
||||
#define COMPRESS_L2_TYPE_U32(type) (((type) >> 8) & 0xFFFF)
|
||||
#define COMPRESS_L2_TYPE_LEVEL_U32(type) (((type) >> 24) & 0xFF)
|
||||
#define COMPRESS_L2_TYPE_LEVEL_U32(type) ((type) & 0xFF)
|
||||
|
||||
// compress flag
|
||||
// |----l2lel--|----l2Alg---|---l1Alg--|
|
||||
|
@ -573,21 +577,22 @@ struct SSchema2 {
|
|||
};
|
||||
|
||||
typedef struct {
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
char stbName[TSDB_TABLE_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
int64_t dbId;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
int8_t precision;
|
||||
int8_t tableType;
|
||||
int32_t sversion;
|
||||
int32_t tversion;
|
||||
uint64_t suid;
|
||||
uint64_t tuid;
|
||||
int32_t vgId;
|
||||
int8_t sysInfo;
|
||||
SSchema* pSchemas;
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
char stbName[TSDB_TABLE_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
int64_t dbId;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
int8_t precision;
|
||||
int8_t tableType;
|
||||
int32_t sversion;
|
||||
int32_t tversion;
|
||||
uint64_t suid;
|
||||
uint64_t tuid;
|
||||
int32_t vgId;
|
||||
int8_t sysInfo;
|
||||
SSchema* pSchemas;
|
||||
SSchemaExt* pSchemaExt;
|
||||
} STableMetaRsp;
|
||||
|
||||
typedef struct {
|
||||
|
@ -766,6 +771,18 @@ static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
|
||||
// if (tEncodeI16v(pEncoder, pSchemaExt->colId) < 0) return -1;
|
||||
// if (tEncodeU32(pEncoder, pSchemaExt->compress) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
|
||||
// if (tDecodeI16v(pDecoder, &pSchemaExt->colId) < 0) return -1;
|
||||
// if (tDecodeU32(pDecoder, &pSchemaExt->compress) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeVariantI32(buf, pSW->nCols);
|
||||
|
|
|
@ -23,10 +23,11 @@ extern "C" {
|
|||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
#define DESCRIBE_RESULT_COLS 4
|
||||
#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)
|
||||
#define DESCRIBE_RESULT_COLS 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)
|
||||
#define DESCRIBE_RESULT_COPRESS_OPTION_LEN (TSDB_CL_COMPRESS_OPTION_LEN + VARSTR_HEADER_SIZE)
|
||||
|
||||
#define SHOW_CREATE_DB_RESULT_COLS 2
|
||||
#define SHOW_CREATE_DB_RESULT_FIELD1_LEN (TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE)
|
||||
|
|
|
@ -117,6 +117,7 @@ typedef struct STableMeta {
|
|||
int32_t sversion;
|
||||
int32_t tversion;
|
||||
STableComInfo tableInfo;
|
||||
SSchemaExt* schemaExt; // There is no additional memory allocation, and the pointer is fixed to the next address of the schema content.
|
||||
SSchema schema[];
|
||||
} STableMeta;
|
||||
#pragma pack(pop)
|
||||
|
|
|
@ -4433,6 +4433,11 @@ static int32_t tEncodeSTableMetaRsp(SEncoder *pEncoder, STableMetaRsp *pRsp) {
|
|||
if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pRsp->numOfColumns; ++i) {
|
||||
SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i];
|
||||
if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4464,6 +4469,21 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
|
|||
pRsp->pSchemas = NULL;
|
||||
}
|
||||
|
||||
// if (tDecodeIsEnd(pDecoder)) return 0;
|
||||
if (pRsp->numOfColumns > 0) {
|
||||
pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns);
|
||||
if (pRsp->pSchemaExt == NULL) return -1;
|
||||
|
||||
for (int32_t i = 0; i < pRsp->numOfColumns; ++i) {
|
||||
SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i];
|
||||
if (tDecodeSSchemaExt(pDecoder, pSchemaExt) < 0) return -1;
|
||||
pSchemaExt->colId = i;
|
||||
pSchemaExt->compress = 0x02000303;
|
||||
}
|
||||
} else {
|
||||
pRsp->pSchemaExt = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4594,6 +4614,7 @@ void tFreeSTableMetaRsp(void *pRsp) {
|
|||
}
|
||||
|
||||
taosMemoryFreeClear(((STableMetaRsp *)pRsp)->pSchemas);
|
||||
taosMemoryFreeClear(((STableMetaRsp *)pRsp)->pSchemaExt);
|
||||
}
|
||||
|
||||
void tFreeSTableIndexRsp(void *info) {
|
||||
|
|
|
@ -1550,16 +1550,31 @@ static void* ctgCloneDbInfo(void* pSrc) {
|
|||
|
||||
static void ctgFreeDbInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); }
|
||||
|
||||
static void* ctgCloneTableMeta(void* pSrc) {
|
||||
STableMeta* pMeta = pSrc;
|
||||
int32_t size = sizeof(STableMeta) + (pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags) * sizeof(SSchema);
|
||||
STableMeta* pDst = taosMemoryMalloc(size);
|
||||
if (NULL == pDst) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(pDst, pSrc, size);
|
||||
return pDst;
|
||||
}
|
||||
// static void* ctgCloneTableMeta(void* pSrc) {
|
||||
// STableMeta* pMeta = pSrc;
|
||||
// int32_t total = pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags;
|
||||
// STableMeta* pDst = taosMemoryMalloc(sizeof(STableMeta));
|
||||
// if (NULL == pDst) {
|
||||
// return NULL;
|
||||
// }
|
||||
// void* pSchema = taosMemoryMalloc(total * sizeof(SSchema));
|
||||
// if (NULL == pSchema) {
|
||||
// taosMemoryFree(pDst);
|
||||
// return NULL;
|
||||
// }
|
||||
// void* pSchemaExt = taosMemoryMalloc(pMeta->tableInfo.numOfColumns * sizeof(SSchemaExt));
|
||||
// if (NULL == pSchemaExt) {
|
||||
// taosMemoryFree(pSchema);
|
||||
// taosMemoryFree(pDst);
|
||||
// return NULL;
|
||||
// }
|
||||
// memcpy(pDst, pSrc, sizeof(STableMeta));
|
||||
// pDst->schema = pSchema;
|
||||
// pDst->schemaExt = pSchemaExt;
|
||||
// memcpy(pDst->schema, pMeta->schema, total * sizeof(SSchema));
|
||||
// memcpy(pDst->schemaExt, pMeta->schemaExt, pMeta->tableInfo.numOfColumns * sizeof(SSchemaExt));
|
||||
// return pDst;
|
||||
// }
|
||||
|
||||
static void ctgFreeTableMeta(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); }
|
||||
|
||||
|
|
|
@ -79,6 +79,18 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
|
|||
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_NOTE_LEN, 4);
|
||||
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 5);
|
||||
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 6);
|
||||
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 7);
|
||||
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
|
@ -101,6 +113,12 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
SColumnInfoData* pCol3 = taosArrayGet(pBlock->pDataBlock, 2);
|
||||
// Note
|
||||
SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3);
|
||||
// encode
|
||||
SColumnInfoData* pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
|
||||
// compress
|
||||
SColumnInfoData* pCol6 = taosArrayGet(pBlock->pDataBlock, 5);
|
||||
// level
|
||||
SColumnInfoData* 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)) {
|
||||
|
@ -118,6 +136,21 @@ 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);
|
||||
}
|
||||
++(pBlock->info.rows);
|
||||
}
|
||||
if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) {
|
||||
|
|
|
@ -9251,6 +9251,18 @@ 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");
|
||||
|
||||
(*pSchema)[5].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*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");
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -275,16 +275,22 @@ int32_t getTableTypeFromTableNode(SNode *pTable) {
|
|||
return ((SRealTableNode *)pTable)->pMeta->tableType;
|
||||
}
|
||||
|
||||
|
||||
STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
|
||||
int32_t numOfFields = TABLE_TOTAL_COL_NUM(pTableMeta);
|
||||
if (numOfFields > TSDB_MAX_COLUMNS || numOfFields < TSDB_MIN_COLUMNS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t schemaExtSize = pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt);
|
||||
size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema);
|
||||
STableMeta* p = taosMemoryMalloc(size);
|
||||
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);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -463,11 +463,15 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
|
|||
}
|
||||
|
||||
int32_t metaSize = sizeof(STableMeta) + numOfField * sizeof(SSchema);
|
||||
*pDst = taosMemoryMalloc(metaSize);
|
||||
int32_t 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);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -401,12 +401,14 @@ int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
|
|||
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
|
||||
int32_t total = msg->numOfColumns + msg->numOfTags;
|
||||
int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
|
||||
int32_t schemaExtSize = sizeof(SSchemaExt) * msg->numOfColumns;
|
||||
|
||||
STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize);
|
||||
STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize);
|
||||
if (NULL == pTableMeta) {
|
||||
qError("calloc size[%d] failed", metaSize);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)pTableMeta + metaSize);
|
||||
|
||||
pTableMeta->vgId = isStb ? 0 : msg->vgId;
|
||||
pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
|
||||
|
@ -419,7 +421,9 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta *
|
|||
pTableMeta->tableInfo.precision = msg->precision;
|
||||
pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
|
||||
|
||||
pTableMeta->schemaExt = pSchemaExt;
|
||||
memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
|
||||
memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
|
||||
|
||||
for (int32_t i = 0; i < msg->numOfColumns; ++i) {
|
||||
pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
|
||||
|
|
Loading…
Reference in New Issue