fix: a plan problem of system table complex query
This commit is contained in:
parent
55f8ff3534
commit
417a29af0a
|
@ -197,28 +197,21 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols
|
||||||
return SCAN_TYPE_TABLE;
|
return SCAN_TYPE_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SNode* createPrimaryKeyCol(uint64_t tableId) {
|
static SNode* createFirstCol(uint64_t tableId, const SSchema* pSchema) {
|
||||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||||
if (NULL == pCol) {
|
if (NULL == pCol) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
pCol->node.resType.type = pSchema->type;
|
||||||
pCol->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
pCol->node.resType.bytes = pSchema->bytes;
|
||||||
pCol->tableId = tableId;
|
pCol->tableId = tableId;
|
||||||
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
pCol->colId = pSchema->colId;
|
||||||
pCol->colType = COLUMN_TYPE_COLUMN;
|
pCol->colType = COLUMN_TYPE_COLUMN;
|
||||||
strcpy(pCol->colName, "#primarykey");
|
strcpy(pCol->colName, pSchema->name);
|
||||||
return (SNode*)pCol;
|
return (SNode*)pCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) {
|
static int32_t addPrimaryKeyCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols) {
|
||||||
if (NULL == *pCols) {
|
|
||||||
*pCols = nodesMakeList();
|
|
||||||
if (NULL == *pCols) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
SNode* pCol = NULL;
|
SNode* pCol = NULL;
|
||||||
FOREACH(pCol, *pCols) {
|
FOREACH(pCol, *pCols) {
|
||||||
|
@ -229,13 +222,25 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(*pCols, createPrimaryKeyCol(tableId))) {
|
return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema));
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t addSystableFirstCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols) {
|
||||||
|
if (LIST_LENGTH(*pCols) > 0) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t addDefaultScanCol(const STableMeta* pMeta, SNodeList** pCols) {
|
||||||
|
if (TSDB_SYSTEM_TABLE == pMeta->tableType) {
|
||||||
|
return addSystableFirstCol(pMeta->uid, pMeta->schema, pCols);
|
||||||
|
}
|
||||||
|
return addPrimaryKeyCol(pMeta->uid, pMeta->schema, pCols);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealTable, bool hasRepeatScanFuncs,
|
static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealTable, bool hasRepeatScanFuncs,
|
||||||
SLogicNode** pLogicNode) {
|
SLogicNode** pLogicNode) {
|
||||||
SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN);
|
SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN);
|
||||||
|
@ -299,8 +304,8 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
||||||
pScan->hasNormalCols = true;
|
pScan->hasNormalCols = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && SCAN_TYPE_SYSTEM_TABLE != pScan->scanType) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = addPrimaryKeyCol(pScan->tableId, &pScan->pScanCols);
|
code = addDefaultScanCol(pRealTable->pMeta, &pScan->pScanCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set output
|
// set output
|
||||||
|
@ -787,10 +792,8 @@ static int32_t createWindowLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
||||||
static EDealRes needFillValueImpl(SNode* pNode, void* pContext) {
|
static EDealRes needFillValueImpl(SNode* pNode, void* pContext) {
|
||||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||||
if (COLUMN_TYPE_WINDOW_START != pCol->colType &&
|
if (COLUMN_TYPE_WINDOW_START != pCol->colType && COLUMN_TYPE_WINDOW_END != pCol->colType &&
|
||||||
COLUMN_TYPE_WINDOW_END != pCol->colType &&
|
COLUMN_TYPE_WINDOW_DURATION != pCol->colType && COLUMN_TYPE_GROUP_KEY != pCol->colType) {
|
||||||
COLUMN_TYPE_WINDOW_DURATION != pCol->colType &&
|
|
||||||
COLUMN_TYPE_GROUP_KEY != pCol->colType) {
|
|
||||||
*(bool*)pContext = true;
|
*(bool*)pContext = true;
|
||||||
return DEAL_RES_END;
|
return DEAL_RES_END;
|
||||||
}
|
}
|
||||||
|
@ -1008,7 +1011,8 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS
|
||||||
int32_t code =
|
int32_t code =
|
||||||
nodesCollectColumns(pSelect, SQL_CLAUSE_PARTITION_BY, NULL, COLLECT_COL_TYPE_ALL, &pPartition->node.pTargets);
|
nodesCollectColumns(pSelect, SQL_CLAUSE_PARTITION_BY, NULL, COLLECT_COL_TYPE_ALL, &pPartition->node.pTargets);
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL == pPartition->node.pTargets) {
|
if (TSDB_CODE_SUCCESS == code && NULL == pPartition->node.pTargets) {
|
||||||
code = nodesListMakeStrictAppend(&pPartition->node.pTargets, nodesCloneNode(nodesListGetNode(pCxt->pCurrRoot->pTargets, 0)));
|
code = nodesListMakeStrictAppend(&pPartition->node.pTargets,
|
||||||
|
nodesCloneNode(nodesListGetNode(pCxt->pCurrRoot->pTargets, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
|
|
@ -32,3 +32,9 @@ TEST_F(PlanSysTableTest, informationSchema) {
|
||||||
|
|
||||||
run("SELECT * FROM information_schema.ins_databases WHERE name = 'information_schema'");
|
run("SELECT * FROM information_schema.ins_databases WHERE name = 'information_schema'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PlanSysTableTest, withAgg) {
|
||||||
|
useDb("root", "information_schema");
|
||||||
|
|
||||||
|
run("SELECT COUNT(1) FROM ins_users");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue