From d57b94599f2a44af26f4fbeecb6c20fae3858f9a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 6 May 2021 15:05:45 +0800 Subject: [PATCH] [td-3299] --- src/client/inc/tsclient.h | 4 ++-- src/client/src/tscSQLParser.c | 6 +++++- src/query/src/qPlan.c | 32 +++++++++++--------------------- src/query/src/qSqlParser.c | 1 - 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index a8ab715edf..c62b830a69 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -134,8 +134,8 @@ typedef struct SJoinNode { } SJoinNode; typedef struct SJoinInfo { - bool hasJoin; - SJoinNode* joinTables[TSDB_MAX_JOIN_TABLE_NUM]; + bool hasJoin; + SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM]; } SJoinInfo; typedef struct STagCond { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index eb27c01ede..e6c2ca12bc 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3678,10 +3678,14 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr SSchema* pLeftSchema = tscGetTableSchema(pLeftMeterMeta->pTableMeta); int16_t leftType = pLeftSchema[pLeftIndex->columnIndex].type; + tscColumnListInsert(pQueryInfo->colList, pLeftIndex->columnIndex, pLeftMeterMeta->pTableMeta->id.uid, &pLeftSchema[pLeftIndex->columnIndex]); + STableMetaInfo* pRightMeterMeta = tscGetMetaInfo(pQueryInfo, rightIndex.tableIndex); SSchema* pRightSchema = tscGetTableSchema(pRightMeterMeta->pTableMeta); int16_t rightType = pRightSchema[rightIndex.columnIndex].type; + tscColumnListInsert(pQueryInfo->colList, rightIndex.columnIndex, pRightMeterMeta->pTableMeta->id.uid, &pRightSchema[rightIndex.columnIndex]); + if (leftType != rightType) { invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return false; @@ -3846,7 +3850,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql taosArrayPush((*rightNode)->tsJoin, &leftIdx); /* - * to release expression, e.g., m1.ts = m2.ts, + * To release expression, e.g., m1.ts = m2.ts, * since this expression is used to set the join query type */ tSqlExprDestroy(*pExpr); diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 5e43469f7b..2686473d87 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -23,9 +23,15 @@ typedef struct SFillEssInfo { int32_t fillType; // fill type - int64_t *val; // fill value + int64_t *val; // fill value } SFillEssInfo; +typedef struct SJoinCond { + bool tagExists; // denote if tag condition exists or not + SColumn *tagCond[2]; + SColumn *colCond[2]; +} SJoinCond; + static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** prev, int32_t numOfPrev, SExprInfo** pExpr, int32_t numOfOutput, SQueryTableInfo* pTableInfo, void* pExtInfo) { @@ -92,8 +98,8 @@ static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** return pNode; } -static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, - SQueryTableInfo* info, SArray* pExprs, SArray* tableCols) { +static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SQueryTableInfo* info, + SArray* pExprs, SArray* tableCols) { if (pQueryInfo->onlyTagQuery) { int32_t num = taosArrayGetSize(pExprs); SQueryNode* pNode = createQueryNode(QNODE_TAGSCAN, "TableTagScan", NULL, 0, pExprs->pData, num, info, NULL); @@ -232,28 +238,12 @@ SArray* createQueryPlanImpl(SQueryInfo* pQueryInfo) { tNameExtractFullName(&pTableMetaInfo->name, name); SQueryTableInfo info = {.tableName = strdup(name), .id = pTableMetaInfo->pTableMeta->id,}; - // 3. add the join columns (the tags and the primary timestamp column) - tscInsertPrimaryTsSourceColumn(pQueryInfo, info.id.uid); - + // 3. get the required table column list SArray* tableColumnList = taosArrayInit(4, sizeof(SColumn)); tscColumnListCopy(tableColumnList, pQueryInfo->colList, uid); - // TODO add the tag column into the required column list - if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - int16_t tagColId = tscGetJoinTagColIdByUid(&pQueryInfo->tagCond, info.id.uid); - SSchema* s = tscGetColumnSchemaById(pTableMetaInfo->pTableMeta, tagColId); - - SColumn* col = calloc(1, sizeof(SColumn)); - col->tableUid = info.id.uid; - col->info.colId = tagColId; - col->info.type = s->type; - col->info.bytes = s->bytes; - taosArrayPush(pQueryInfo->colList, &col); - } - // 4. add the projection query node SQueryNode* pNode = doAddTableColumnNode(pQueryInfo, pTableMetaInfo, &info, exprList, tableColumnList); - taosArrayPush(upstream, &pNode); } @@ -497,7 +487,7 @@ static int32_t doPrintPlan(char* buf, SQueryNode* pQueryNode, int32_t level, int case QNODE_JOIN: { // print join condition - len1 = sprintf(buf + len, "\n"); + len1 = sprintf(buf + len, ")\n"); len += len1; break; } diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index fb8f164ed3..ed4ac11141 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -229,7 +229,6 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) { pExpr->flags &= ~(1 << EXPR_FLAG_TS_ERROR); } - switch (optrType) { case TK_PLUS: { pExpr->value.i64 = pLeft->value.i64 + pRight->value.i64; -- GitLab