From 0108d6da7313b6ee05c61ad4e5911e5ae1663647 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 29 Oct 2021 15:50:10 +0800 Subject: [PATCH] [td-10564] fix bug in planner. --- include/libs/parser/parser.h | 2 ++ source/libs/parser/inc/queryInfoUtil.h | 1 - source/libs/parser/src/astValidate.c | 2 ++ source/libs/planner/src/planner.c | 19 ++++++++++--------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index f3199ac0d6..d9a7b0ea41 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -230,6 +230,8 @@ SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SC int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy); STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex); +SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex); + int32_t getNewResColId(); #ifdef __cplusplus diff --git a/source/libs/parser/inc/queryInfoUtil.h b/source/libs/parser/inc/queryInfoUtil.h index fc892762cd..d75637e3c5 100644 --- a/source/libs/parser/inc/queryInfoUtil.h +++ b/source/libs/parser/inc/queryInfoUtil.h @@ -27,7 +27,6 @@ int32_t getNumOfColumns(const STableMeta* pTableMeta); int32_t getNumOfTags(const STableMeta* pTableMeta); SSchema *getTableColumnSchema(const STableMeta *pTableMeta); SSchema *getTableTagSchema(const STableMeta* pTableMeta); -SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex); size_t getNumOfExprs(SQueryStmtInfo* pQueryInfo); SExprInfo* createBinaryExprInfo(struct tExprNode* pNode, SSchema* pResSchema); diff --git a/source/libs/parser/src/astValidate.c b/source/libs/parser/src/astValidate.c index 372ca1bffb..26ab04cb85 100644 --- a/source/libs/parser/src/astValidate.c +++ b/source/libs/parser/src/astValidate.c @@ -1790,6 +1790,8 @@ static void setTsOutputExprInfo(SQueryStmtInfo* pQueryInfo, STableMetaInfo* pTab SSchema s = createSchema(TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(), "ts"); SExprInfo* pExpr = createExprInfo(pTableMetaInfo, FUNCTION_TS_DUMMY, &indexTS, NULL, &s, TSDB_KEYSIZE); + strncpy(pExpr->base.token, "ts", tListLen(pExpr->base.token)); + addExprInfo(pQueryInfo, outputIndex, pExpr); SSchema* pSourceSchema = getOneColumnSchema(pTableMetaInfo->pTableMeta, indexTS.columnIndex); diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 18e63904de..39564dd057 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -108,9 +108,7 @@ static SQueryPlanNode* createQueryNode(int32_t type, const char* name, SQueryPla pNode->pExpr = taosArrayInit(numOfOutput, POINTER_BYTES); for(int32_t i = 0; i < numOfOutput; ++i) { - SExprInfo* p = calloc(1, sizeof(SExprInfo)); - assignExprInfo(p, pExpr[i]); - taosArrayPush(pNode->pExpr, &p); + taosArrayPush(pNode->pExpr, &pExpr[i]); } pNode->pPrevNodes = taosArrayInit(4, POINTER_BYTES); @@ -183,16 +181,16 @@ static SQueryPlanNode* doAddTableColumnNode(SQueryStmtInfo* pQueryInfo, STableMe // table source column projection, generate the projection expr int32_t numOfCols = (int32_t) taosArrayGetSize(tableCols); SExprInfo** pExpr = calloc(numOfCols, POINTER_BYTES); - SSchema* pSchema = pTableMetaInfo->pTableMeta->schema; STableMetaInfo* pTableMetaInfo1 = getMetaInfo(pQueryInfo, 0); - SSchema resultSchema = *pSchema; - resultSchema.colId = getNewResColId(); for (int32_t i = 0; i < numOfCols; ++i) { SColumn* pCol = taosArrayGetP(tableCols, i); SColumnIndex index = {.tableIndex = 0, .columnIndex = pCol->columnIndex}; + SSchema* pSchema = getOneColumnSchema(pTableMetaInfo->pTableMeta, i); + SSchema resultSchema = *pSchema; + SExprInfo* p = createExprInfo(pTableMetaInfo1, FUNCTION_PRJ, &index, NULL, &resultSchema, 0); pExpr[i] = p; } @@ -252,7 +250,8 @@ static SQueryPlanNode* doCreateQueryPlanForOneTableImpl(SQueryStmtInfo* pQueryIn static SQueryPlanNode* doCreateQueryPlanForOneTable(SQueryStmtInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SArray* pExprs, SArray* tableCols) { char name[TSDB_TABLE_FNAME_LEN] = {0}; - tNameExtractFullName(&pTableMetaInfo->name, name); + tstrncpy(name, pTableMetaInfo->name.tname, TSDB_TABLE_FNAME_LEN); +// tNameExtractFullName(&pTableMetaInfo->name, name); SQueryTableInfo info = {.tableName = strdup(name), .uid = pTableMetaInfo->pTableMeta->uid,}; @@ -450,9 +449,11 @@ static int32_t doPrintPlan(char* buf, SQueryPlanNode* pQueryNode, int32_t level, len += len1; SInterval* pInterval = pQueryNode->pExtInfo; - len1 = sprintf(buf + len, "interval:%" PRId64 "(%s), sliding:%" PRId64 "(%s), offset:%" PRId64 "\n", + + // todo dynamic return the time precision + len1 = sprintf(buf + len, "interval:%" PRId64 "(%s), sliding:%" PRId64 "(%s), offset:%" PRId64 "(%s)\n", pInterval->interval, TSDB_TIME_PRECISION_MILLI_STR, pInterval->sliding, TSDB_TIME_PRECISION_MILLI_STR, - pInterval->offset); + pInterval->offset, TSDB_TIME_PRECISION_MILLI_STR); len += len1; break;