diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index b4b45ced46..c1793bfb90 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -277,7 +277,12 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols return SCAN_TYPE_TABLE; } -static SNode* createFirstCol(uint64_t tableId, const SSchema* pSchema) { + +static bool hasPkInTable(const STableMeta* pTableMeta) { + return pTableMeta->tableInfo.numOfColumns>=2 && pTableMeta->schema[1].flags & COL_IS_KEY; +} + +static SNode* createFirstCol(uint64_t tableId, const SSchema* pSchema, const STableMeta* pMeta) { SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); if (NULL == pCol) { return NULL; @@ -287,11 +292,13 @@ static SNode* createFirstCol(uint64_t tableId, const SSchema* pSchema) { pCol->tableId = tableId; pCol->colId = pSchema->colId; pCol->colType = COLUMN_TYPE_COLUMN; + pCol->isPk = pSchema->flags & COL_IS_KEY; + pCol->tableHasPk = hasPkInTable(pMeta); strcpy(pCol->colName, pSchema->name); return (SNode*)pCol; } -static int32_t addPrimaryKeyCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols) { +static int32_t addPrimaryKeyCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols, const STableMeta* pMeta) { bool found = false; SNode* pCol = NULL; FOREACH(pCol, *pCols) { @@ -302,12 +309,12 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, const SSchema* pSchema, SNodeL } if (!found) { - return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema)); + return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema, pMeta)); } return TSDB_CODE_SUCCESS; } -static int32_t addPkCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols) { +static int32_t addPkCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols, const STableMeta* pMeta) { bool found = false; SNode* pCol = NULL; FOREACH(pCol, *pCols) { @@ -318,30 +325,26 @@ static int32_t addPkCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pC } if (!found) { - return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema)); + return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema, pMeta)); } return TSDB_CODE_SUCCESS; } -static bool hasPkInTable(const STableMeta* pTableMeta) { - return pTableMeta->tableInfo.numOfColumns>=2 && pTableMeta->schema[1].flags & COL_IS_KEY; -} - -static int32_t addSystableFirstCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols) { +static int32_t addSystableFirstCol(uint64_t tableId, const SSchema* pSchema, SNodeList** pCols, const STableMeta* pMeta) { if (LIST_LENGTH(*pCols) > 0) { return TSDB_CODE_SUCCESS; } - return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema)); + return nodesListMakeStrictAppend(pCols, createFirstCol(tableId, pSchema, pMeta)); } static int32_t addDefaultScanCol(const STableMeta* pMeta, SNodeList** pCols) { if (TSDB_SYSTEM_TABLE == pMeta->tableType) { - return addSystableFirstCol(pMeta->uid, pMeta->schema, pCols); + return addSystableFirstCol(pMeta->uid, pMeta->schema, pCols, pMeta); } if (hasPkInTable(pMeta)) { - addPkCol(pMeta->uid, pMeta->schema + 1, pCols); + addPkCol(pMeta->uid, pMeta->schema + 1, pCols, pMeta); } - return addPrimaryKeyCol(pMeta->uid, pMeta->schema, pCols); + return addPrimaryKeyCol(pMeta->uid, pMeta->schema, pCols, pMeta); } static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealTable, bool hasRepeatScanFuncs,