Merge pull request #17181 from taosdata/szhou/fixbugs
fix: ins_tags table name optimization error
This commit is contained in:
commit
f7ab5f1d9a
|
@ -41,9 +41,9 @@ static int32_t buildDbTableInfoBlock(bool sysInfo, const SSDataBlock* p, const S
|
||||||
|
|
||||||
static bool processBlockWithProbability(const SSampleExecInfo* pInfo);
|
static bool processBlockWithProbability(const SSampleExecInfo* pInfo);
|
||||||
|
|
||||||
static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo, SMetaReader* smr, const char* dbname,
|
static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo, SMetaReader* smrSuperTable,
|
||||||
const char* tableName, int32_t* pNumOfRows,
|
SMetaReader* smrChildTable, const char* dbname, const char* tableName,
|
||||||
const SSDataBlock* dataBlock);
|
int32_t* pNumOfRows, const SSDataBlock* dataBlock);
|
||||||
|
|
||||||
static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t numOfRows, SSDataBlock* dataBlock);
|
static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t numOfRows, SSDataBlock* dataBlock);
|
||||||
bool processBlockWithProbability(const SSampleExecInfo* pInfo) {
|
bool processBlockWithProbability(const SSampleExecInfo* pInfo) {
|
||||||
|
@ -2415,11 +2415,10 @@ static bool sysTableIsOperatorCondOnOneTable(SNode* pCond, char* condTable) {
|
||||||
strcasecmp(nodesGetNameFromColumnNode(node->pLeft), "table_name") == 0 &&
|
strcasecmp(nodesGetNameFromColumnNode(node->pLeft), "table_name") == 0 &&
|
||||||
nodeType(node->pRight) == QUERY_NODE_VALUE) {
|
nodeType(node->pRight) == QUERY_NODE_VALUE) {
|
||||||
SValueNode* pValue = (SValueNode*)node->pRight;
|
SValueNode* pValue = (SValueNode*)node->pRight;
|
||||||
if (pValue->node.type == TSDB_DATA_TYPE_NCHAR || pValue->node.type == TSDB_DATA_TYPE_VARCHAR ||
|
if (pValue->node.resType.type == TSDB_DATA_TYPE_NCHAR || pValue->node.resType.type == TSDB_DATA_TYPE_VARCHAR ||
|
||||||
pValue->node.type == TSDB_DATA_TYPE_BINARY) {
|
pValue->node.resType.type == TSDB_DATA_TYPE_BINARY) {
|
||||||
char* value = nodesGetStrValueFromNode(pValue);
|
char* value = nodesGetValueFromNode(pValue);
|
||||||
strncpy(condTable, value, TSDB_TABLE_NAME_LEN);
|
strncpy(condTable, varDataVal(value), TSDB_TABLE_NAME_LEN);
|
||||||
taosMemoryFree(value);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2480,18 +2479,28 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) {
|
||||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(tableName, condTableName);
|
STR_TO_VARSTR(tableName, condTableName);
|
||||||
|
|
||||||
SMetaReader smr = {0};
|
SMetaReader smrChildTable = {0};
|
||||||
metaReaderInit(&smr, pInfo->readHandle.meta, 0);
|
metaReaderInit(&smrChildTable, pInfo->readHandle.meta, 0);
|
||||||
metaGetTableEntryByName(&smr, condTableName);
|
metaGetTableEntryByName(&smrChildTable, condTableName);
|
||||||
sysTableUserTagsFillOneTableTags(pInfo, &smr, dbname, tableName, &numOfRows, dataBlock);
|
if (smrChildTable.me.type != TSDB_CHILD_TABLE) {
|
||||||
metaReaderClear(&smr);
|
metaReaderClear(&smrChildTable);
|
||||||
|
blockDataDestroy(dataBlock);
|
||||||
|
pInfo->loadInfo.totalRows = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
SMetaReader smrSuperTable = {0};
|
||||||
|
metaReaderInit(&smrSuperTable, pInfo->readHandle.meta, 0);
|
||||||
|
metaGetTableEntryByUid(&smrSuperTable, smrChildTable.me.ctbEntry.suid);
|
||||||
|
sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &smrChildTable, dbname, tableName, &numOfRows, dataBlock);
|
||||||
|
metaReaderClear(&smrSuperTable);
|
||||||
|
metaReaderClear(&smrChildTable);
|
||||||
if (numOfRows > 0) {
|
if (numOfRows > 0) {
|
||||||
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock);
|
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock);
|
||||||
numOfRows = 0;
|
numOfRows = 0;
|
||||||
}
|
}
|
||||||
blockDataDestroy(dataBlock);
|
blockDataDestroy(dataBlock);
|
||||||
|
|
||||||
pInfo->loadInfo.totalRows += pInfo->pRes->info.rows;
|
pInfo->loadInfo.totalRows += pInfo->pRes->info.rows;
|
||||||
|
doSetOperatorCompleted(pOperator);
|
||||||
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2508,23 +2517,22 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) {
|
||||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name);
|
STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name);
|
||||||
|
|
||||||
SMetaReader smr = {0};
|
SMetaReader smrSuperTable = {0};
|
||||||
metaReaderInit(&smr, pInfo->readHandle.meta, 0);
|
metaReaderInit(&smrSuperTable, pInfo->readHandle.meta, 0);
|
||||||
|
|
||||||
uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid;
|
uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid;
|
||||||
int32_t code = metaGetTableEntryByUid(&smr, suid);
|
int32_t code = metaGetTableEntryByUid(&smrSuperTable, suid);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
qError("failed to get super table meta, uid:0x%" PRIx64 ", code:%s, %s", suid, tstrerror(terrno),
|
qError("failed to get super table meta, uid:0x%" PRIx64 ", code:%s, %s", suid, tstrerror(terrno),
|
||||||
GET_TASKID(pTaskInfo));
|
GET_TASKID(pTaskInfo));
|
||||||
metaReaderClear(&smr);
|
metaReaderClear(&smrSuperTable);
|
||||||
metaCloseTbCursor(pInfo->pCur);
|
metaCloseTbCursor(pInfo->pCur);
|
||||||
pInfo->pCur = NULL;
|
pInfo->pCur = NULL;
|
||||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
T_LONG_JMP(pTaskInfo->env, terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
sysTableUserTagsFillOneTableTags(pInfo, &smr, dbname, tableName, &numOfRows, dataBlock);
|
sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &pInfo->pCur->mr, dbname, tableName, &numOfRows, dataBlock);
|
||||||
|
|
||||||
metaReaderClear(&smr);
|
metaReaderClear(&smrSuperTable);
|
||||||
|
|
||||||
if (numOfRows >= pOperator->resultInfo.capacity) {
|
if (numOfRows >= pOperator->resultInfo.capacity) {
|
||||||
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock);
|
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock);
|
||||||
|
@ -2562,15 +2570,15 @@ static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t
|
||||||
blockDataCleanup(dataBlock);
|
blockDataCleanup(dataBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo, SMetaReader* smr, const char* dbname,
|
static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo, SMetaReader* smrSuperTable,
|
||||||
const char* tableName, int32_t* pNumOfRows,
|
SMetaReader* smrChildTable, const char* dbname, const char* tableName,
|
||||||
const SSDataBlock* dataBlock) {
|
int32_t* pNumOfRows, const SSDataBlock* dataBlock) {
|
||||||
char stableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char stableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(stableName, (*smr).me.name);
|
STR_TO_VARSTR(stableName, (*smrSuperTable).me.name);
|
||||||
|
|
||||||
int32_t numOfRows = *pNumOfRows;
|
int32_t numOfRows = *pNumOfRows;
|
||||||
|
|
||||||
int32_t numOfTags = (*smr).me.stbEntry.schemaTag.nCols;
|
int32_t numOfTags = (*smrSuperTable).me.stbEntry.schemaTag.nCols;
|
||||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||||
SColumnInfoData* pColInfoData = NULL;
|
SColumnInfoData* pColInfoData = NULL;
|
||||||
|
|
||||||
|
@ -2588,35 +2596,35 @@ static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo,
|
||||||
|
|
||||||
// tag name
|
// tag name
|
||||||
char tagName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char tagName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(tagName, (*smr).me.stbEntry.schemaTag.pSchema[i].name);
|
STR_TO_VARSTR(tagName, (*smrSuperTable).me.stbEntry.schemaTag.pSchema[i].name);
|
||||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 3);
|
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 3);
|
||||||
colDataAppend(pColInfoData, numOfRows, tagName, false);
|
colDataAppend(pColInfoData, numOfRows, tagName, false);
|
||||||
|
|
||||||
// tag type
|
// tag type
|
||||||
int8_t tagType = (*smr).me.stbEntry.schemaTag.pSchema[i].type;
|
int8_t tagType = (*smrSuperTable).me.stbEntry.schemaTag.pSchema[i].type;
|
||||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 4);
|
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 4);
|
||||||
char tagTypeStr[VARSTR_HEADER_SIZE + 32];
|
char tagTypeStr[VARSTR_HEADER_SIZE + 32];
|
||||||
int tagTypeLen = sprintf(varDataVal(tagTypeStr), "%s", tDataTypes[tagType].name);
|
int tagTypeLen = sprintf(varDataVal(tagTypeStr), "%s", tDataTypes[tagType].name);
|
||||||
if (tagType == TSDB_DATA_TYPE_VARCHAR) {
|
if (tagType == TSDB_DATA_TYPE_VARCHAR) {
|
||||||
tagTypeLen += sprintf(varDataVal(tagTypeStr) + tagTypeLen, "(%d)",
|
tagTypeLen += sprintf(varDataVal(tagTypeStr) + tagTypeLen, "(%d)",
|
||||||
(int32_t)((*smr).me.stbEntry.schemaTag.pSchema[i].bytes - VARSTR_HEADER_SIZE));
|
(int32_t)((*smrSuperTable).me.stbEntry.schemaTag.pSchema[i].bytes - VARSTR_HEADER_SIZE));
|
||||||
} else if (tagType == TSDB_DATA_TYPE_NCHAR) {
|
} else if (tagType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
tagTypeLen +=
|
tagTypeLen += sprintf(
|
||||||
sprintf(varDataVal(tagTypeStr) + tagTypeLen, "(%d)",
|
varDataVal(tagTypeStr) + tagTypeLen, "(%d)",
|
||||||
(int32_t)(((*smr).me.stbEntry.schemaTag.pSchema[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
(int32_t)(((*smrSuperTable).me.stbEntry.schemaTag.pSchema[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||||
}
|
}
|
||||||
varDataSetLen(tagTypeStr, tagTypeLen);
|
varDataSetLen(tagTypeStr, tagTypeLen);
|
||||||
colDataAppend(pColInfoData, numOfRows, (char*)tagTypeStr, false);
|
colDataAppend(pColInfoData, numOfRows, (char*)tagTypeStr, false);
|
||||||
|
|
||||||
STagVal tagVal = {0};
|
STagVal tagVal = {0};
|
||||||
tagVal.cid = (*smr).me.stbEntry.schemaTag.pSchema[i].colId;
|
tagVal.cid = (*smrSuperTable).me.stbEntry.schemaTag.pSchema[i].colId;
|
||||||
char* tagData = NULL;
|
char* tagData = NULL;
|
||||||
uint32_t tagLen = 0;
|
uint32_t tagLen = 0;
|
||||||
|
|
||||||
if (tagType == TSDB_DATA_TYPE_JSON) {
|
if (tagType == TSDB_DATA_TYPE_JSON) {
|
||||||
tagData = (char*)pInfo->pCur->mr.me.ctbEntry.pTags;
|
tagData = (char*)smrChildTable->me.ctbEntry.pTags;
|
||||||
} else {
|
} else {
|
||||||
bool exist = tTagGet((STag*)pInfo->pCur->mr.me.ctbEntry.pTags, &tagVal);
|
bool exist = tTagGet((STag*)smrChildTable->me.ctbEntry.pTags, &tagVal);
|
||||||
if (exist) {
|
if (exist) {
|
||||||
if (IS_VAR_DATA_TYPE(tagType)) {
|
if (IS_VAR_DATA_TYPE(tagType)) {
|
||||||
tagData = (char*)tagVal.pData;
|
tagData = (char*)tagVal.pData;
|
||||||
|
|
Loading…
Reference in New Issue