From 624fb8b308af6e0179844c21b796a1008fcff6c1 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 17 Mar 2021 19:47:29 +0800 Subject: [PATCH 01/10] support multiple tables join --- src/client/inc/tscUtil.h | 17 + src/client/inc/tsclient.h | 8 +- src/client/src/tscSQLParser.c | 213 ++++++++++--- src/client/src/tscSubquery.c | 570 ++++++++++++++++++++++++++++------ src/client/src/tscUtil.c | 78 ++++- src/inc/taosdef.h | 2 +- src/query/src/qExecutor.c | 2 + 7 files changed, 744 insertions(+), 146 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index f69ee23222..3eba5d579b 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -83,6 +83,22 @@ typedef struct SJoinSupporter { SArray* pVgroupTables; } SJoinSupporter; + +typedef struct SMergeCtx { + SJoinSupporter* p; + int32_t idx; + SArray* res; + int8_t compared; +}SMergeCtx; + +typedef struct SMergeTsCtx { + SJoinSupporter* p; + STSBuf* res; + int64_t numOfInput; + int8_t compared; +}SMergeTsCtx; + + typedef struct SVgroupTableInfo { SVgroupInfo vgInfo; SArray* itemList; //SArray @@ -183,6 +199,7 @@ int32_t tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deep void tscSqlExprInfoDestroy(SArray* pExprInfo); SColumn* tscColumnClone(const SColumn* src); +bool tscColumnExists(SArray* pColumnList, SColumnIndex* pColIndex); SColumn* tscColumnListInsert(SArray* pColList, SColumnIndex* colIndex); SArray* tscColumnListClone(const SArray* src, int16_t tableIndex); void tscColumnListDestroy(SArray* pColList); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 1740266518..faa5a0be64 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -142,15 +142,15 @@ typedef struct SCond { } SCond; typedef struct SJoinNode { - char tableName[TSDB_TABLE_FNAME_LEN]; uint64_t uid; int16_t tagColId; + SArray* tsJoin; + SArray* tagJoin; } SJoinNode; typedef struct SJoinInfo { - bool hasJoin; - SJoinNode left; - SJoinNode right; + 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 29eaecfea0..8ca313cca6 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3334,24 +3334,26 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSq } } -static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { - const char* msg1 = "invalid join query condition"; - const char* msg2 = "invalid table name in join query"; +static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { + int32_t code = 0; + const char* msg1 = "timestamp required for join tables"; const char* msg3 = "type of join columns must be identical"; const char* msg4 = "invalid column name in join condition"; + const char* msg5 = "only support one join tag for each table"; if (pExpr == NULL) { return TSDB_CODE_SUCCESS; } if (!tSqlExprIsParentOfLeaf(pExpr)) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); + code = checkAndSetJoinCondInfo(pCmd, pQueryInfo, pExpr->pLeft); + if (code) { + return code; + } + + return checkAndSetJoinCondInfo(pCmd, pQueryInfo, pExpr->pRight); } - STagCond* pTagCond = &pQueryInfo->tagCond; - SJoinNode* pLeft = &pTagCond->joinInfo.left; - SJoinNode* pRight = &pTagCond->joinInfo.right; - SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(pCmd, &pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); @@ -3360,13 +3362,28 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); SSchema* pTagSchema1 = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex); - pLeft->uid = pTableMetaInfo->pTableMeta->id.uid; - pLeft->tagColId = pTagSchema1->colId; + assert(index.tableIndex >= 0 && index.tableIndex < TSDB_MAX_JOIN_TABLE_NUM); - int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pLeft->tableName); - if (code != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + SJoinNode **leftNode = &pQueryInfo->tagCond.joinInfo.joinTables[index.tableIndex]; + if (*leftNode == NULL) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } + + (*leftNode)->uid = pTableMetaInfo->pTableMeta->id.uid; + (*leftNode)->tagColId = pTagSchema1->colId; + + if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + index.columnIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta); + if (!tscColumnExists(pTableMetaInfo->tagColList, &index)) { + tscColumnListInsert(pTableMetaInfo->tagColList, &index); + if (taosArrayGetSize(pTableMetaInfo->tagColList) > 1) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); + } + } + } + + int16_t leftIdx = index.tableIndex; + index = (SColumnIndex)COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(pCmd, &pExpr->pRight->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { @@ -3376,20 +3393,55 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); SSchema* pTagSchema2 = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex); - pRight->uid = pTableMetaInfo->pTableMeta->id.uid; - pRight->tagColId = pTagSchema2->colId; + assert(index.tableIndex >= 0 && index.tableIndex < TSDB_MAX_JOIN_TABLE_NUM); - code = tNameExtractFullName(&pTableMetaInfo->name, pRight->tableName); - if (code != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + SJoinNode **rightNode = &pQueryInfo->tagCond.joinInfo.joinTables[index.tableIndex]; + if (*rightNode == NULL) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } + (*rightNode)->uid = pTableMetaInfo->pTableMeta->id.uid; + (*rightNode)->tagColId = pTagSchema2->colId; + + if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + index.columnIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta); + if (!tscColumnExists(pTableMetaInfo->tagColList, &index)) { + tscColumnListInsert(pTableMetaInfo->tagColList, &index); + if (taosArrayGetSize(pTableMetaInfo->tagColList) > 1) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); + } + } + } + + int16_t rightIdx = index.tableIndex; + if (pTagSchema1->type != pTagSchema2->type) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } - pTagCond->joinInfo.hasJoin = true; + if ((*leftNode)->tagJoin == NULL) { + (*leftNode)->tagJoin = taosArrayInit(2, sizeof(int16_t)); + } + + if ((*rightNode)->tagJoin == NULL) { + (*rightNode)->tagJoin = taosArrayInit(2, sizeof(int16_t)); + } + + taosArrayPush((*leftNode)->tagJoin, &rightIdx); + taosArrayPush((*rightNode)->tagJoin, &leftIdx); + + pQueryInfo->tagCond.joinInfo.hasJoin = true; + return TSDB_CODE_SUCCESS; + +} + +static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { + if (pExpr == NULL) { + return TSDB_CODE_SUCCESS; + } + + return checkAndSetJoinCondInfo(pCmd, pQueryInfo, pExpr); } static int32_t validateSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, @@ -3655,7 +3707,6 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql const char* msg1 = "table query cannot use tags filter"; const char* msg2 = "illegal column name"; const char* msg3 = "only one query time range allowed"; - const char* msg4 = "only one join condition allowed"; const char* msg5 = "not support ordinary column join"; const char* msg6 = "only one query condition on tbname allowed"; const char* msg7 = "only in/like allowed in filter table name"; @@ -3686,6 +3737,45 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY); pCondExpr->tsJoin = true; + assert(index.tableIndex >= 0 && index.tableIndex < TSDB_MAX_JOIN_TABLE_NUM); + SJoinNode **leftNode = &pQueryInfo->tagCond.joinInfo.joinTables[index.tableIndex]; + if (*leftNode == NULL) { + *leftNode = calloc(1, sizeof(SJoinNode)); + if (*leftNode == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + } + + int16_t leftIdx = index.tableIndex; + + SColumnIndex index = COLUMN_INDEX_INITIALIZER; + if (getColumnIndexByName(pCmd, &pRight->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + + assert(index.tableIndex >= 0 && index.tableIndex < TSDB_MAX_JOIN_TABLE_NUM); + + SJoinNode **rightNode = &pQueryInfo->tagCond.joinInfo.joinTables[index.tableIndex]; + if (*rightNode == NULL) { + *rightNode = calloc(1, sizeof(SJoinNode)); + if (*rightNode == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + } + + int16_t rightIdx = index.tableIndex; + + if ((*leftNode)->tsJoin == NULL) { + (*leftNode)->tsJoin = taosArrayInit(2, sizeof(int16_t)); + } + + if ((*rightNode)->tsJoin == NULL) { + (*rightNode)->tsJoin = taosArrayInit(2, sizeof(int16_t)); + } + + taosArrayPush((*leftNode)->tsJoin, &rightIdx); + taosArrayPush((*rightNode)->tsJoin, &leftIdx); + /* * to release expression, e.g., m1.ts = m2.ts, * since this expression is used to set the join query type @@ -3743,10 +3833,6 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql return TSDB_CODE_TSC_INVALID_SQL; } - if (pCondExpr->pJoinExpr != NULL) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); - } - pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_QUERY; ret = setExprToCond(&pCondExpr->pJoinExpr, *pExpr, NULL, parentOptr, pQueryInfo->msg); *pExpr = NULL; @@ -3974,7 +4060,8 @@ static bool validateFilterExpr(SQueryInfo* pQueryInfo) { static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { const char* msg0 = "invalid timestamp"; const char* msg1 = "only one time stamp window allowed"; - + int32_t code = 0; + if (pExpr == NULL) { return TSDB_CODE_SUCCESS; } @@ -3984,8 +4071,11 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlE return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft); - + code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft); + if (code) { + return code; + } + return getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pRight); } else { SColumnIndex index = COLUMN_INDEX_INITIALIZER; @@ -4066,6 +4156,7 @@ static void cleanQueryExpr(SCondExpr* pCondExpr) { } } +/* static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr* pCondExpr) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); if (QUERY_IS_JOIN_QUERY(pQueryInfo->type) && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { @@ -4088,6 +4179,7 @@ static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SQueryInfo* pQueryInf tscColumnListInsert(pTableMetaInfo->tagColList, &index); } } +*/ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) { const char *msg1 = "invalid tag operator"; @@ -4223,6 +4315,32 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE return ret; } +int32_t validateJoinNodes(SQueryInfo* pQueryInfo, SSqlObj* pSql) { + const char* msg1 = "timestamp required for join tables"; + const char* msg2 = "tag required for join stables"; + + for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { + SJoinNode *node = pQueryInfo->tagCond.joinInfo.joinTables[i]; + + if (node == NULL || node->tsJoin == NULL || taosArrayGetSize(node->tsJoin) <= 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(&pSql->cmd), msg1); + } + } + + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { + SJoinNode *node = pQueryInfo->tagCond.joinInfo.joinTables[i]; + + if (node == NULL || node->tagJoin == NULL || taosArrayGetSize(node->tagJoin) <= 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2); + } + } + } + + return TSDB_CODE_SUCCESS; +} + int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql) { if (pExpr == NULL) { return TSDB_CODE_SUCCESS; @@ -4243,7 +4361,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql int32_t type = 0; if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } tSqlExprCompact(pExpr); @@ -4253,32 +4371,32 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql // 1. check if it is a join query if ((ret = validateJoinExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 2. get the query time range if ((ret = getTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 3. get the tag query condition if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 4. get the table name query condition if ((ret = getTablenameCond(&pSql->cmd, pQueryInfo, condExpr.pTableCond, &sb)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 5. other column query condition if ((ret = getColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 6. join condition if ((ret = getJoinCondInfo(&pSql->cmd, pQueryInfo, condExpr.pJoinExpr)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 7. query condition for table name @@ -4286,12 +4404,24 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql ret = setTableCondForSTableQuery(&pSql->cmd, pQueryInfo, getAccountId(pSql), condExpr.pTableCond, condExpr.tableCondIndex, &sb); taosStringBuilderDestroy(&sb); - - if (!validateFilterExpr(pQueryInfo)) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2); + if (ret) { + goto PARSE_WHERE_EXIT; } - doAddJoinTagsColumnsIntoTagList(&pSql->cmd, pQueryInfo, &condExpr); + if (!validateFilterExpr(pQueryInfo)) { + ret = invalidSqlErrMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2); + goto PARSE_WHERE_EXIT; + } + + //doAddJoinTagsColumnsIntoTagList(&pSql->cmd, pQueryInfo, &condExpr); + if (pQueryInfo->tagCond.joinInfo.hasJoin) { + ret = validateJoinNodes(pQueryInfo, pSql); + if (ret) { + goto PARSE_WHERE_EXIT; + } + } + +PARSE_WHERE_EXIT: cleanQueryExpr(&condExpr); return ret; @@ -6504,7 +6634,6 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i const char* msg1 = "point interpolation query needs timestamp"; const char* msg2 = "fill only available for interval query"; const char* msg3 = "start(end) time of query range required or time range too large"; - const char* msg4 = "illegal number of tables in from clause"; const char* msg5 = "too many columns in selection clause"; const char* msg6 = "too many tables in from clause"; const char* msg7 = "invalid table alias name"; @@ -6541,15 +6670,11 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i size_t fromSize = taosArrayGetSize(pQuerySqlNode->from); if (fromSize > TSDB_MAX_JOIN_TABLE_NUM * 2) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6); } pQueryInfo->command = TSDB_SQL_SELECT; - if (fromSize > 4) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6); - } - // set all query tables, which are maybe more than one. for (int32_t i = 0; i < fromSize; ) { tVariantListItem* item = taosArrayGet(pQuerySqlNode->from, i); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 22cb580951..3bfed7abae 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -264,6 +264,287 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ return output1->numOfTotal; } + + + + +static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { + SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex); + + win->skey = INT64_MAX; + win->ekey = INT64_MIN; + + SLimitVal* pLimit = &pQueryInfo->limit; + int32_t order = pQueryInfo->order.order; + int32_t joinNum = pSql->subState.numOfSub; + SMergeTsCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {0}; + SMergeTsCtx* ctxStack[TSDB_MAX_JOIN_TABLE_NUM] = {0}; + + for (int32_t i = 0; i < joinNum; ++i) { + STSBuf* output = tsBufCreate(true, pQueryInfo->order.order); + SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0); + + pSubQueryInfo->tsBuf = output; + + SJoinSupporter* pSupporter = pSql->pSubs[i]->param; + + if (pSupporter[i]->pTSBuf == NULL) { + tscDebug("%p at least one ts-comp is empty, 0 for secondary query after ts blocks intersecting", pSql); + return 0; + } + + tsBufResetPos(pSupporter[i]->pTSBuf); + + if (!tsBufNextPos(pSupporter[i]->pTSBuf)) { + tscDebug("%p input1 is empty, 0 for secondary query after ts blocks intersecting", pSql); + return 0; + } + + ctxlist[i].p = pSupporter; + ctxlist[i].res = output; + } + + TSKEY st = taosGetTimestampUs(); + + + + + + + + + + int32_t slot = 0; + int32_t tableNum = 0; + int16_t* tableMIdx = 0; + int32_t equalNum = 0; + int32_t stackidx = 0; + int32_t mergeDone = 0; + SMergeCtx* ctx = NULL; + SMergeCtx* pctx = NULL; + STidTags* cur = NULL; + STidTags* prev = NULL; + SArray* tagCond = NULL; + + for (int16_t tidx = 0; tidx < joinNum; tidx++) { + pctx = &ctxlist[tidx]; + if (pctx->compared) { + continue; + } + + assert(pctx->idx == 0 && taosArrayGetSize(pctx->res) == 0); + + tagCond = pQueryInfo->tagCond.joinInfo.joinTables[tidx]->tagJoin; + + taosArrayInsert(tagCond, 0, &tidx); + + tableNum = taosArrayGetSize(tagCond); + assert(tableNum >= 1); + + prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); + pctx->compared = 1; + + ctxStack[stackidx++] = pctx; + + tableMIdx = taosArrayGet(tagCond, ++slot); + + equalNum = 1; + + while (1) { + ctx = &ctxlist[*tableMIdx]; + + ctx->compared = 1; + + cur = (STidTags*) varDataVal(ctx->p->pIdTagList + ctx->idx * ctx->p->tagSize); + + assert(cur->tid != 0 && prev->tid != 0); + + ctxStack[stackidx++] = ctx; + + int32_t ret = doCompare(prev->tag, cur->tag, pColSchema->type, pColSchema->bytes); + if (ret == 0) { + if (++equalNum < tableNum) { + prev = cur; + pctx = ctx; + + if (++slot >= tableNum) { + slot = 0; + } + + tableMIdx = taosArrayGet(tagCond, slot); + continue; + } + + tscDebug("%p tag matched, vgId:%d, val:%d, tid:%d, uid:%"PRIu64", tid:%d, uid:%"PRIu64, pParentSql, prev->vgId, + *(int*) prev->tag, prev->tid, prev->uid, cur->tid, cur->uid); + + assert(stackidx == tableNum); + + for (int32_t i = 0; i < stackidx; ++i) { + SMergeCtx* tctx = ctxStack[i]; + prev = (STidTags*) varDataVal(tctx->p->pIdTagList + tctx->idx * tctx->p->tagSize); + + taosArrayPush(tctx->res, &prev); + } + + for (int32_t i = 0; i < stackidx; ++i) { + SMergeCtx* tctx = ctxStack[i]; + + if (++tctx->idx >= tctx->p->num) { + mergeDone = 1; + break; + } + } + + if (mergeDone) { + break; + } + + stackidx = 0; + equalNum = 1; + + prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); + + ctxStack[stackidx++] = pctx; + } else if (ret > 0) { + if (++ctx->idx >= ctx->p->num) { + break; + } + } else { + for (int32_t i = 0; i < stackidx; ++i) { + SMergeCtx* tctx = ctxStack[i]; + if (++tctx->idx >= tctx->p->num) { + mergeDone = 1; + break; + } + } + + if (mergeDone) { + break; + } + + stackidx = 0; + equalNum = 1; + + prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); + ctxStack[stackidx++] = pctx; + } + + } + + slot = 0; + mergeDone = 0; + } + + + + + + + + + int64_t numOfInput1 = 1; + int64_t numOfInput2 = 1; + + while(1) { + STSElem elem = tsBufGetElem(pSupporter1->pTSBuf); + + // no data in pSupporter1 anymore, jump out of loop + if (!tsBufIsValidElem(&elem)) { + break; + } + + // find the data in supporter2 with the same tag value + STSElem e2 = tsBufFindElemStartPosByTag(pSupporter2->pTSBuf, elem.tag); + + /** + * there are elements in pSupporter2 with the same tag, continue + */ + tVariant tag1 = {0}; + tVariantAssign(&tag1, elem.tag); + + if (tsBufIsValidElem(&e2)) { + while (1) { + STSElem elem1 = tsBufGetElem(pSupporter1->pTSBuf); + STSElem elem2 = tsBufGetElem(pSupporter2->pTSBuf); + + // data with current are exhausted + if (!tsBufIsValidElem(&elem1) || tVariantCompare(elem1.tag, &tag1) != 0) { + break; + } + + if (!tsBufIsValidElem(&elem2) || tVariantCompare(elem2.tag, &tag1) != 0) { // ignore all records with the same tag + skipRemainValue(pSupporter1->pTSBuf, &tag1); + break; + } + + /* + * in case of stable query, limit/offset is not applied here. the limit/offset is applied to the + * final results which is acquired after the secondary merge of in the client. + */ + int32_t re = tsCompare(order, elem1.ts, elem2.ts); + if (re < 0) { + tsBufNextPos(pSupporter1->pTSBuf); + numOfInput1++; + } else if (re > 0) { + tsBufNextPos(pSupporter2->pTSBuf); + numOfInput2++; + } else { + if (pLimit->offset == 0 || pQueryInfo->interval.interval > 0 || QUERY_IS_STABLE_QUERY(pQueryInfo->type)) { + if (win->skey > elem1.ts) { + win->skey = elem1.ts; + } + + if (win->ekey < elem1.ts) { + win->ekey = elem1.ts; + } + + tsBufAppend(output1, elem1.id, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts)); + tsBufAppend(output2, elem2.id, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts)); + } else { + pLimit->offset -= 1;//offset apply to projection? + } + + tsBufNextPos(pSupporter1->pTSBuf); + numOfInput1++; + + tsBufNextPos(pSupporter2->pTSBuf); + numOfInput2++; + } + } + } else { // no data in pSupporter2, ignore current data in pSupporter2 + skipRemainValue(pSupporter1->pTSBuf, &tag1); + } + } + + /* + * failed to set the correct ts order yet in two cases: + * 1. only one element + * 2. only one element for each tag. + */ + if (output1->tsOrder == -1) { + output1->tsOrder = TSDB_ORDER_ASC; + output2->tsOrder = TSDB_ORDER_ASC; + } + + tsBufFlush(output1); + tsBufFlush(output2); + + tsBufDestroy(pSupporter1->pTSBuf); + pSupporter1->pTSBuf = NULL; + tsBufDestroy(pSupporter2->pTSBuf); + pSupporter2->pTSBuf = NULL; + + TSKEY et = taosGetTimestampUs(); + tscDebug("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks " + "intersecting, skey:%" PRId64 ", ekey:%" PRId64 ", numOfVnode:%d, elapsed time:%" PRId64 " us", + pSql, numOfInput1, numOfInput2, output1->numOfTotal, output1->numOfGroups, win->skey, win->ekey, + tsBufGetNumOfGroup(output1), et - st); + + return output1->numOfTotal; +} + + // todo handle failed to create sub query SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, int32_t index) { SJoinSupporter* pSupporter = calloc(1, sizeof(SJoinSupporter)); @@ -652,7 +933,7 @@ void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArr size_t numOfTables = taosArrayGetSize(tables); for (size_t i = 0; i < numOfTables; i++) { - STidTags* tt = taosArrayGet(tables, i); + STidTags* tt = *(STidTags **)taosArrayGet(tables, i); if (prev == NULL || tt->vgId != prev->vgId) { SVgroupsInfo* pvg = pTableMetaInfo->vgroupList; @@ -768,76 +1049,194 @@ static bool checkForDuplicateTagVal(SSchema* pColSchema, SJoinSupporter* p1, SSq return true; } -static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray** s1, SArray** s2) { - SJoinSupporter* p1 = pParentSql->pSubs[0]->param; - SJoinSupporter* p2 = pParentSql->pSubs[1]->param; - - tscDebug("%p all subquery retrieve complete, do tags match, %d, %d", pParentSql, p1->num, p2->num); - - // sort according to the tag value - qsort(p1->pIdTagList, p1->num, p1->tagSize, tagValCompar); - qsort(p2->pIdTagList, p2->num, p2->tagSize, tagValCompar); +static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray* resList) { + int16_t joinNum = pParentSql->subState.numOfSub; STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); int16_t tagColId = tscGetJoinTagColIdByUid(&pQueryInfo->tagCond, pTableMetaInfo->pTableMeta->id.uid); - - SSchema* pColSchema = tscGetColumnSchemaById(pTableMetaInfo->pTableMeta, tagColId); + SJoinSupporter* p0 = pParentSql->pSubs[0]->param; + SMergeCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {0}; + SMergeCtx* ctxStack[TSDB_MAX_JOIN_TABLE_NUM] = {0}; // int16_t for padding - int32_t size = p1->tagSize - sizeof(int16_t); - *s1 = taosArrayInit(p1->num, size); - *s2 = taosArrayInit(p2->num, size); + int32_t size = p0->tagSize - sizeof(int16_t); - if (!(checkForDuplicateTagVal(pColSchema, p1, pParentSql) && checkForDuplicateTagVal(pColSchema, p2, pParentSql))) { - return TSDB_CODE_QRY_DUP_JOIN_KEY; - } + SSchema* pColSchema = tscGetColumnSchemaById(pTableMetaInfo->pTableMeta, tagColId); + + tscDebug("%p all subquery retrieve complete, do tags match", pParentSql); - int32_t i = 0, j = 0; - while(i < p1->num && j < p2->num) { - STidTags* pp1 = (STidTags*) varDataVal(p1->pIdTagList + i * p1->tagSize); - STidTags* pp2 = (STidTags*) varDataVal(p2->pIdTagList + j * p2->tagSize); - assert(pp1->tid != 0 && pp2->tid != 0); + for (int32_t i = 0; i < joinNum; i++) { + SJoinSupporter* p = pParentSql->pSubs[i]->param; - int32_t ret = doCompare(pp1->tag, pp2->tag, pColSchema->type, pColSchema->bytes); - if (ret == 0) { - tscDebug("%p tag matched, vgId:%d, val:%d, tid:%d, uid:%"PRIu64", tid:%d, uid:%"PRIu64, pParentSql, pp1->vgId, - *(int*) pp1->tag, pp1->tid, pp1->uid, pp2->tid, pp2->uid); - - taosArrayPush(*s1, pp1); - taosArrayPush(*s2, pp2); - j++; - i++; - } else if (ret > 0) { - j++; - } else { - i++; + ctxlist[i].p = p; + ctxlist[i].res = taosArrayInit(p->num, sizeof(STidTags*)); + + tscDebug("Join %d - num:%d", i, p->num); + + // sort according to the tag valu + qsort(p->pIdTagList, p->num, p->tagSize, tagValCompar); + + if (!checkForDuplicateTagVal(pColSchema, p, pParentSql)) { + for (int32_t j = 0; j <= i; j++) { + taosArrayDestroy(ctxlist[j].res); + } + return TSDB_CODE_QRY_DUP_JOIN_KEY; } } - // reorganize the tid-tag value according to both the vgroup id and tag values - // sort according to the tag value - size_t t1 = taosArrayGetSize(*s1); - size_t t2 = taosArrayGetSize(*s2); + int32_t slot = 0; + int32_t tableNum = 0; + int16_t* tableMIdx = 0; + int32_t equalNum = 0; + int32_t stackidx = 0; + int32_t mergeDone = 0; + SMergeCtx* ctx = NULL; + SMergeCtx* pctx = NULL; + STidTags* cur = NULL; + STidTags* prev = NULL; + SArray* tagCond = NULL; - qsort((*s1)->pData, t1, size, tidTagsCompar); - qsort((*s2)->pData, t2, size, tidTagsCompar); + for (int16_t tidx = 0; tidx < joinNum; tidx++) { + pctx = &ctxlist[tidx]; + if (pctx->compared) { + continue; + } -#if 0 - for(int32_t k = 0; k < t1; ++k) { - STidTags* p = (*s1)->pData + size * k; - printf("%d, tag:%s\n", p->vgId, ((tstr*)(p->tag))->data); + assert(pctx->idx == 0 && taosArrayGetSize(pctx->res) == 0); + + tagCond = pQueryInfo->tagCond.joinInfo.joinTables[tidx]->tagJoin; + + taosArrayInsert(tagCond, 0, &tidx); + + tableNum = taosArrayGetSize(tagCond); + assert(tableNum >= 1); + + prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); + pctx->compared = 1; + + ctxStack[stackidx++] = pctx; + + tableMIdx = taosArrayGet(tagCond, ++slot); + + equalNum = 1; + + while (1) { + ctx = &ctxlist[*tableMIdx]; + + ctx->compared = 1; + + cur = (STidTags*) varDataVal(ctx->p->pIdTagList + ctx->idx * ctx->p->tagSize); + + assert(cur->tid != 0 && prev->tid != 0); + + ctxStack[stackidx++] = ctx; + + int32_t ret = doCompare(prev->tag, cur->tag, pColSchema->type, pColSchema->bytes); + if (ret == 0) { + if (++equalNum < tableNum) { + prev = cur; + pctx = ctx; + + if (++slot >= tableNum) { + slot = 0; + } + + tableMIdx = taosArrayGet(tagCond, slot); + continue; + } + + tscDebug("%p tag matched, vgId:%d, val:%d, tid:%d, uid:%"PRIu64", tid:%d, uid:%"PRIu64, pParentSql, prev->vgId, + *(int*) prev->tag, prev->tid, prev->uid, cur->tid, cur->uid); + + assert(stackidx == tableNum); + + for (int32_t i = 0; i < stackidx; ++i) { + SMergeCtx* tctx = ctxStack[i]; + prev = (STidTags*) varDataVal(tctx->p->pIdTagList + tctx->idx * tctx->p->tagSize); + + taosArrayPush(tctx->res, &prev); + } + + for (int32_t i = 0; i < stackidx; ++i) { + SMergeCtx* tctx = ctxStack[i]; + + if (++tctx->idx >= tctx->p->num) { + mergeDone = 1; + break; + } + } + + if (mergeDone) { + break; + } + + stackidx = 0; + equalNum = 1; + + prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); + + ctxStack[stackidx++] = pctx; + } else if (ret > 0) { + if (++ctx->idx >= ctx->p->num) { + break; + } + } else { + for (int32_t i = 0; i < stackidx; ++i) { + SMergeCtx* tctx = ctxStack[i]; + if (++tctx->idx >= tctx->p->num) { + mergeDone = 1; + break; + } + } + + if (mergeDone) { + break; + } + + stackidx = 0; + equalNum = 1; + + prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); + ctxStack[stackidx++] = pctx; + } + + } + + slot = 0; + mergeDone = 0; } - for(int32_t k = 0; k < t1; ++k) { - STidTags* p = (*s2)->pData + size * k; - printf("%d, tag:%s\n", p->vgId, ((tstr*)(p->tag))->data); - } -#endif + for (int32_t i = 0; i < joinNum; ++i) { + // reorganize the tid-tag value according to both the vgroup id and tag values + // sort according to the tag value + size_t num = taosArrayGetSize(ctxlist[i].res); + + qsort((ctxlist[i].res)->pData, num, size, tidTagsCompar); - tscDebug("%p tags match complete, result: %"PRIzu", %"PRIzu, pParentSql, t1, t2); + taosArrayPush(resList, &ctxlist[i].res); + + tscDebug("%p tags match complete, result num: %"PRIzu, pParentSql, num); + } + return TSDB_CODE_SUCCESS; } +bool emptyTagList(SArray* resList, int32_t size) { + int32_t rsize = taosArrayGetSize(resList); + if (rsize != size) { + return true; + } + + for (int32_t i = 0; i < size; ++i) { + SArray** s = taosArrayGet(resList, i); + if (taosArrayGetSize(*s) <= 0) { + return true; + } + } + + return false; +} + static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) { SJoinSupporter* pSupporter = (SJoinSupporter*)param; @@ -939,19 +1338,19 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow return; } - SArray *s1 = NULL, *s2 = NULL; - int32_t code = getIntersectionOfTableTuple(pQueryInfo, pParentSql, &s1, &s2); + SArray* resList = taosArrayInit(pParentSql->subState.numOfSub, sizeof(SArray *)); + + int32_t code = getIntersectionOfTableTuple(pQueryInfo, pParentSql, resList); if (code != TSDB_CODE_SUCCESS) { freeJoinSubqueryObj(pParentSql); pParentSql->res.code = code; tscAsyncResultOnError(pParentSql); - taosArrayDestroy(s1); - taosArrayDestroy(s2); + taosArrayDestroy(resList); return; } - if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return. + if (emptyTagList(resList, pParentSql->subState.numOfSub)) { // no results,return. assert(pParentSql->fp != tscJoinQueryCallback); tscDebug("%p tag intersect does not generated qualified tables for join, free all sub SqlObj and quit", pParentSql); @@ -963,37 +1362,34 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow (*pParentSql->fp)(pParentSql->param, pParentSql, 0); } else { - // proceed to for ts_comp query - SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd; - SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd; - - SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0); - STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0); - tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo1, s1); - - SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0); - STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0); - tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo2, s2); - - SSqlObj* psub1 = pParentSql->pSubs[0]; - ((SJoinSupporter*)psub1->param)->pVgroupTables = tscVgroupTableInfoDup(pTableMetaInfo1->pVgroupTables); - - SSqlObj* psub2 = pParentSql->pSubs[1]; - ((SJoinSupporter*)psub2->param)->pVgroupTables = tscVgroupTableInfoDup(pTableMetaInfo2->pVgroupTables); - - pParentSql->subState.numOfSub = 2; - - memset(pParentSql->subState.states, 0, sizeof(pParentSql->subState.states[0]) * pParentSql->subState.numOfSub); - tscDebug("%p reset all sub states to 0", pParentSql); - for (int32_t m = 0; m < pParentSql->subState.numOfSub; ++m) { - SSqlObj* sub = pParentSql->pSubs[m]; - issueTsCompQuery(sub, sub->param, pParentSql); + // proceed to for ts_comp query + SSqlCmd* pSubCmd = &pParentSql->pSubs[m]->cmd; + SArray** s = taosArrayGet(resList, m); + + SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pSubCmd, 0); + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo, *s); + + SSqlObj* psub = pParentSql->pSubs[m]; + ((SJoinSupporter*)psub->param)->pVgroupTables = tscVgroupTableInfoDup(pTableMetaInfo->pVgroupTables); + + memset(pParentSql->subState.states, 0, sizeof(pParentSql->subState.states[0]) * pParentSql->subState.numOfSub); + tscDebug("%p reset all sub states to 0", pParentSql); + + issueTsCompQuery(psub, psub->param, pParentSql); } } - taosArrayDestroy(s1); - taosArrayDestroy(s2); + int32_t rsize = taosArrayGetSize(resList); + for (int32_t i = 0; i < rsize; ++i) { + SArray** s = taosArrayGet(resList, i); + if (*s) { + taosArrayDestroy(*s); + } + } + + taosArrayDestroy(resList); } static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) { @@ -1124,12 +1520,8 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow tscDebug("%p all subquery retrieve ts complete, do ts block intersect", pParentSql); - // proceeds to launched secondary query to retrieve final data - SJoinSupporter* p1 = pParentSql->pSubs[0]->param; - SJoinSupporter* p2 = pParentSql->pSubs[1]->param; - STimeWindow win = TSWINDOW_INITIALIZER; - int64_t num = doTSBlockIntersect(pParentSql, p1, p2, &win); + int64_t num = doTSBlockIntersect(pParentSql, &win); if (num <= 0) { // no result during ts intersect tscDebug("%p no results generated in ts intersection, free all sub SqlObj and quit", pParentSql); freeJoinSubqueryObj(pParentSql); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 2d5e8382a4..13c2dc0af5 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1279,6 +1279,33 @@ int32_t tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepco return 0; } +bool tscColumnExists(SArray* pColumnList, SColumnIndex* pColIndex) { + // ignore the tbname columnIndex to be inserted into source list + if (pColIndex->columnIndex < 0) { + return false; + } + + size_t numOfCols = taosArrayGetSize(pColumnList); + int16_t col = pColIndex->columnIndex; + + int32_t i = 0; + while (i < numOfCols) { + SColumn* pCol = taosArrayGetP(pColumnList, i); + if ((pCol->colIndex.columnIndex != col) || (pCol->colIndex.tableIndex != pColIndex->tableIndex)) { + continue; + } else { + break; + } + } + + if (i >= numOfCols || numOfCols == 0) { + return false; + } + + return true; +} + + SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) { // ignore the tbname columnIndex to be inserted into source list if (pColIndex->columnIndex < 0) { @@ -1583,7 +1610,20 @@ int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { dest->tbnameCond.uid = src->tbnameCond.uid; dest->tbnameCond.len = src->tbnameCond.len; - memcpy(&dest->joinInfo, &src->joinInfo, sizeof(SJoinInfo)); + dest->joinInfo.hasJoin = src->joinInfo.hasJoin; + + for (int32_t i = 0; i < TSDB_MAX_JOIN_TABLE_NUM; ++i) { + if (src->joinInfo.joinTables[i]) { + dest->joinInfo.joinTables[i] = calloc(1, sizeof(SJoinNode)); + + memcpy(dest->joinInfo.joinTables[i], src->joinInfo.joinTables[i], sizeof(SJoinNode)); + + dest->joinInfo.joinTables[i]->tsJoin = taosArrayDup(src->joinInfo.joinTables[i]->tsJoin); + dest->joinInfo.joinTables[i]->tagJoin = taosArrayDup(src->joinInfo.joinTables[i]->tagJoin); + } + } + + dest->relType = src->relType; if (src->pCond == NULL) { @@ -1629,6 +1669,23 @@ void tscTagCondRelease(STagCond* pTagCond) { taosArrayDestroy(pTagCond->pCond); } + for (int32_t i = 0; i < TSDB_MAX_JOIN_TABLE_NUM; ++i) { + SJoinNode *node = pTagCond->joinInfo.joinTables[i]; + if (node == NULL) { + continue; + } + + if (node->tsJoin != NULL) { + taosArrayDestroy(node->tsJoin); + } + + if (node->tagJoin != NULL) { + taosArrayDestroy(node->tagJoin); + } + + tfree(node); + } + memset(pTagCond, 0, sizeof(STagCond)); } @@ -2318,16 +2375,21 @@ void tscDoQuery(SSqlObj* pSql) { } int16_t tscGetJoinTagColIdByUid(STagCond* pTagCond, uint64_t uid) { - if (pTagCond->joinInfo.left.uid == uid) { - return pTagCond->joinInfo.left.tagColId; - } else if (pTagCond->joinInfo.right.uid == uid) { - return pTagCond->joinInfo.right.tagColId; - } else { - assert(0); - return -1; + int32_t i = 0; + while (i < TSDB_MAX_JOIN_TABLE_NUM) { + SJoinNode* node = pTagCond->joinInfo.joinTables[i]; + if (node && node->uid == uid) { + return node->tagColId; + } + + i++; } + + assert(0); + return -1; } + int16_t tscGetTagColIndexById(STableMeta* pTableMeta, int16_t colId) { int32_t numOfTags = tscGetNumOfTags(pTableMeta); diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index d9a50e8914..024bc198df 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -317,7 +317,7 @@ do { \ #define TSDB_MAX_DB_QUORUM_OPTION 2 #define TSDB_DEFAULT_DB_QUORUM_OPTION 1 -#define TSDB_MAX_JOIN_TABLE_NUM 5 +#define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 #define TSDB_MAX_BINARY_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index ff5e9efb09..6fc25eedc5 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2393,6 +2393,8 @@ void filterRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInf break; } } + + pRuntimeEnv->pQuery->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf); } else { for (int32_t i = 0; i < numOfRows; ++i) { bool qualified = false; From c07d2ff9eefd6d059e5fa17e9709892006e34c43 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 18 Mar 2021 19:30:51 +0800 Subject: [PATCH 02/10] fix bug --- src/client/src/tscSQLParser.c | 64 ++++ src/client/src/tscSubquery.c | 531 ++++++++++++---------------------- src/client/src/tscUtil.c | 1 + 3 files changed, 252 insertions(+), 344 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 8ca313cca6..939bb6d964 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4341,6 +4341,65 @@ int32_t validateJoinNodes(SQueryInfo* pQueryInfo, SSqlObj* pSql) { return TSDB_CODE_SUCCESS; } + +void mergeJoinNodesImpl(int8_t* r, int8_t* p, int16_t* tidx, SJoinNode** nodes, int32_t type) { + SJoinNode *node = nodes[*tidx]; + SArray* arr = (type == 0) ? node->tsJoin : node->tagJoin; + int32_t size = taosArrayGetSize(arr); + + p[*tidx] = 1; + + for (int32_t j = 0; j < size; j++) { + int16_t* idx = taosArrayGet(arr, j); + r[*idx] = 1; + if (p[*idx] == 0) { + mergeJoinNodesImpl(r, p, idx, nodes, type); + } + } +} + +int32_t mergeJoinNodes(SQueryInfo* pQueryInfo) { + int8_t r[TSDB_MAX_JOIN_TABLE_NUM] = {0}; + int8_t p[TSDB_MAX_JOIN_TABLE_NUM] = {0}; + + for (int16_t i = 0; i < pQueryInfo->numOfTables; ++i) { + mergeJoinNodesImpl(r, p, &i, pQueryInfo->tagCond.joinInfo.joinTables, 0); + + taosArrayClear(pQueryInfo->tagCond.joinInfo.joinTables[i]->tsJoin); + + for (int32_t j = 0; j < TSDB_MAX_JOIN_TABLE_NUM; ++j) { + if (r[j]) { + taosArrayPush(pQueryInfo->tagCond.joinInfo.joinTables[i]->tsJoin, &j); + } + } + + memset(r, 0, sizeof(r)); + memset(p, 0, sizeof(p)); + } + + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + for (int16_t i = 0; i < pQueryInfo->numOfTables; ++i) { + mergeJoinNodesImpl(r, p, &i, pQueryInfo->tagCond.joinInfo.joinTables, 1); + + taosArrayClear(pQueryInfo->tagCond.joinInfo.joinTables[i]->tagJoin); + + for (int32_t j = 0; j < TSDB_MAX_JOIN_TABLE_NUM; ++j) { + if (r[j]) { + taosArrayPush(pQueryInfo->tagCond.joinInfo.joinTables[i]->tagJoin, &j); + } + } + + memset(r, 0, sizeof(r)); + memset(p, 0, sizeof(p)); + } + + } + + return TSDB_CODE_SUCCESS; +} + + int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql) { if (pExpr == NULL) { return TSDB_CODE_SUCCESS; @@ -4419,6 +4478,11 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql if (ret) { goto PARSE_WHERE_EXIT; } + + ret = mergeJoinNodes(pQueryInfo); + if (ret) { + goto PARSE_WHERE_EXIT; + } } PARSE_WHERE_EXIT: diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 3bfed7abae..4780998785 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -118,156 +118,6 @@ static bool subAndCheckDone(SSqlObj *pSql, SSqlObj *pParentSql, int idx) { -static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJoinSupporter* pSupporter2, STimeWindow * win) { - SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex); - - STSBuf* output1 = tsBufCreate(true, pQueryInfo->order.order); - STSBuf* output2 = tsBufCreate(true, pQueryInfo->order.order); - - win->skey = INT64_MAX; - win->ekey = INT64_MIN; - - SLimitVal* pLimit = &pQueryInfo->limit; - int32_t order = pQueryInfo->order.order; - - SQueryInfo* pSubQueryInfo1 = tscGetQueryInfoDetail(&pSql->pSubs[0]->cmd, 0); - SQueryInfo* pSubQueryInfo2 = tscGetQueryInfoDetail(&pSql->pSubs[1]->cmd, 0); - - pSubQueryInfo1->tsBuf = output1; - pSubQueryInfo2->tsBuf = output2; - - TSKEY st = taosGetTimestampUs(); - - // no result generated, return directly - if (pSupporter1->pTSBuf == NULL || pSupporter2->pTSBuf == NULL) { - tscDebug("%p at least one ts-comp is empty, 0 for secondary query after ts blocks intersecting", pSql); - return 0; - } - - tsBufResetPos(pSupporter1->pTSBuf); - tsBufResetPos(pSupporter2->pTSBuf); - - if (!tsBufNextPos(pSupporter1->pTSBuf)) { - tsBufFlush(output1); - tsBufFlush(output2); - - tscDebug("%p input1 is empty, 0 for secondary query after ts blocks intersecting", pSql); - return 0; - } - - if (!tsBufNextPos(pSupporter2->pTSBuf)) { - tsBufFlush(output1); - tsBufFlush(output2); - - tscDebug("%p input2 is empty, 0 for secondary query after ts blocks intersecting", pSql); - return 0; - } - - int64_t numOfInput1 = 1; - int64_t numOfInput2 = 1; - - while(1) { - STSElem elem = tsBufGetElem(pSupporter1->pTSBuf); - - // no data in pSupporter1 anymore, jump out of loop - if (!tsBufIsValidElem(&elem)) { - break; - } - - // find the data in supporter2 with the same tag value - STSElem e2 = tsBufFindElemStartPosByTag(pSupporter2->pTSBuf, elem.tag); - - /** - * there are elements in pSupporter2 with the same tag, continue - */ - tVariant tag1 = {0}; - tVariantAssign(&tag1, elem.tag); - - if (tsBufIsValidElem(&e2)) { - while (1) { - STSElem elem1 = tsBufGetElem(pSupporter1->pTSBuf); - STSElem elem2 = tsBufGetElem(pSupporter2->pTSBuf); - - // data with current are exhausted - if (!tsBufIsValidElem(&elem1) || tVariantCompare(elem1.tag, &tag1) != 0) { - break; - } - - if (!tsBufIsValidElem(&elem2) || tVariantCompare(elem2.tag, &tag1) != 0) { // ignore all records with the same tag - skipRemainValue(pSupporter1->pTSBuf, &tag1); - break; - } - - /* - * in case of stable query, limit/offset is not applied here. the limit/offset is applied to the - * final results which is acquired after the secondary merge of in the client. - */ - int32_t re = tsCompare(order, elem1.ts, elem2.ts); - if (re < 0) { - tsBufNextPos(pSupporter1->pTSBuf); - numOfInput1++; - } else if (re > 0) { - tsBufNextPos(pSupporter2->pTSBuf); - numOfInput2++; - } else { - if (pLimit->offset == 0 || pQueryInfo->interval.interval > 0 || QUERY_IS_STABLE_QUERY(pQueryInfo->type)) { - if (win->skey > elem1.ts) { - win->skey = elem1.ts; - } - - if (win->ekey < elem1.ts) { - win->ekey = elem1.ts; - } - - tsBufAppend(output1, elem1.id, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts)); - tsBufAppend(output2, elem2.id, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts)); - } else { - pLimit->offset -= 1;//offset apply to projection? - } - - tsBufNextPos(pSupporter1->pTSBuf); - numOfInput1++; - - tsBufNextPos(pSupporter2->pTSBuf); - numOfInput2++; - } - } - } else { // no data in pSupporter2, ignore current data in pSupporter2 - skipRemainValue(pSupporter1->pTSBuf, &tag1); - } - } - - /* - * failed to set the correct ts order yet in two cases: - * 1. only one element - * 2. only one element for each tag. - */ - if (output1->tsOrder == -1) { - output1->tsOrder = TSDB_ORDER_ASC; - output2->tsOrder = TSDB_ORDER_ASC; - } - - tsBufFlush(output1); - tsBufFlush(output2); - - tsBufDestroy(pSupporter1->pTSBuf); - pSupporter1->pTSBuf = NULL; - tsBufDestroy(pSupporter2->pTSBuf); - pSupporter2->pTSBuf = NULL; - - TSKEY et = taosGetTimestampUs(); - tscDebug("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks " - "intersecting, skey:%" PRId64 ", ekey:%" PRId64 ", numOfVnode:%d, elapsed time:%" PRId64 " us", - pSql, numOfInput1, numOfInput2, output1->numOfTotal, output1->numOfGroups, win->skey, win->ekey, - tsBufGetNumOfGroup(output1), et - st); - - return output1->numOfTotal; -} - - - - - static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex); @@ -279,7 +129,19 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { int32_t joinNum = pSql->subState.numOfSub; SMergeTsCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {0}; SMergeTsCtx* ctxStack[TSDB_MAX_JOIN_TABLE_NUM] = {0}; - + int32_t slot = 0; + int32_t tableNum = 0; + int16_t* tableMIdx = 0; + int32_t equalNum = 0; + int32_t stackidx = 0; + SMergeTsCtx* ctx = NULL; + SMergeTsCtx* pctx = NULL; + SMergeTsCtx* mainCtx = NULL; + STSElem cur; + STSElem prev; + SArray* tsCond = NULL; + int32_t mergeDone = 0; + for (int32_t i = 0; i < joinNum; ++i) { STSBuf* output = tsBufCreate(true, pQueryInfo->order.order); SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0); @@ -288,14 +150,14 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { SJoinSupporter* pSupporter = pSql->pSubs[i]->param; - if (pSupporter[i]->pTSBuf == NULL) { + if (pSupporter->pTSBuf == NULL) { tscDebug("%p at least one ts-comp is empty, 0 for secondary query after ts blocks intersecting", pSql); return 0; } - tsBufResetPos(pSupporter[i]->pTSBuf); + tsBufResetPos(pSupporter->pTSBuf); - if (!tsBufNextPos(pSupporter[i]->pTSBuf)) { + if (!tsBufNextPos(pSupporter->pTSBuf)) { tscDebug("%p input1 is empty, 0 for secondary query after ts blocks intersecting", pSql); return 0; } @@ -306,215 +168,181 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { TSKEY st = taosGetTimestampUs(); - - - - - - - - - int32_t slot = 0; - int32_t tableNum = 0; - int16_t* tableMIdx = 0; - int32_t equalNum = 0; - int32_t stackidx = 0; - int32_t mergeDone = 0; - SMergeCtx* ctx = NULL; - SMergeCtx* pctx = NULL; - STidTags* cur = NULL; - STidTags* prev = NULL; - SArray* tagCond = NULL; - for (int16_t tidx = 0; tidx < joinNum; tidx++) { pctx = &ctxlist[tidx]; if (pctx->compared) { continue; } - assert(pctx->idx == 0 && taosArrayGetSize(pctx->res) == 0); + assert(pctx->numOfInput == 0); - tagCond = pQueryInfo->tagCond.joinInfo.joinTables[tidx]->tagJoin; + tsCond = pQueryInfo->tagCond.joinInfo.joinTables[tidx]->tsJoin; - taosArrayInsert(tagCond, 0, &tidx); + tableNum = taosArrayGetSize(tsCond); + assert(tableNum >= 2); - tableNum = taosArrayGetSize(tagCond); - assert(tableNum >= 1); - - prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); - pctx->compared = 1; + for (int32_t i = 0; i < tableNum; ++i) { + tableMIdx = taosArrayGet(tsCond, i); + SMergeTsCtx* tctx = &ctxlist[*tableMIdx]; + tctx->compared = 1; + } - ctxStack[stackidx++] = pctx; + tableMIdx = taosArrayGet(tsCond, 0); + pctx = &ctxlist[*tableMIdx]; - tableMIdx = taosArrayGet(tagCond, ++slot); + mainCtx = pctx; - equalNum = 1; - - while (1) { - ctx = &ctxlist[*tableMIdx]; + while (1) { + pctx = mainCtx; - ctx->compared = 1; - - cur = (STidTags*) varDataVal(ctx->p->pIdTagList + ctx->idx * ctx->p->tagSize); + prev = tsBufGetElem(pctx->p->pTSBuf); - assert(cur->tid != 0 && prev->tid != 0); + ctxStack[stackidx++] = pctx; - ctxStack[stackidx++] = ctx; - - int32_t ret = doCompare(prev->tag, cur->tag, pColSchema->type, pColSchema->bytes); - if (ret == 0) { - if (++equalNum < tableNum) { - prev = cur; - pctx = ctx; - - if (++slot >= tableNum) { - slot = 0; - } - - tableMIdx = taosArrayGet(tagCond, slot); - continue; - } - - tscDebug("%p tag matched, vgId:%d, val:%d, tid:%d, uid:%"PRIu64", tid:%d, uid:%"PRIu64, pParentSql, prev->vgId, - *(int*) prev->tag, prev->tid, prev->uid, cur->tid, cur->uid); - - assert(stackidx == tableNum); - - for (int32_t i = 0; i < stackidx; ++i) { - SMergeCtx* tctx = ctxStack[i]; - prev = (STidTags*) varDataVal(tctx->p->pIdTagList + tctx->idx * tctx->p->tagSize); - - taosArrayPush(tctx->res, &prev); - } - - for (int32_t i = 0; i < stackidx; ++i) { - SMergeCtx* tctx = ctxStack[i]; - - if (++tctx->idx >= tctx->p->num) { - mergeDone = 1; - break; - } - } - - if (mergeDone) { - break; - } - - stackidx = 0; - equalNum = 1; - - prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); - - ctxStack[stackidx++] = pctx; - } else if (ret > 0) { - if (++ctx->idx >= ctx->p->num) { - break; - } - } else { - for (int32_t i = 0; i < stackidx; ++i) { - SMergeCtx* tctx = ctxStack[i]; - if (++tctx->idx >= tctx->p->num) { - mergeDone = 1; - break; - } - } - - if (mergeDone) { - break; - } - - stackidx = 0; - equalNum = 1; - - prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); - ctxStack[stackidx++] = pctx; + if (!tsBufIsValidElem(&prev)) { + break; } - } + tVariant tag = {0}; + tVariantAssign(&tag, prev.tag); - slot = 0; - mergeDone = 0; - } + int32_t skipped = 0; + for (int32_t i = 1; i < tableNum; ++i) { + SMergeTsCtx* tctx = &ctxlist[i]; + + // find the data in supporter2 with the same tag value + STSElem e2 = tsBufFindElemStartPosByTag(tctx->p->pTSBuf, &tag); + if (!tsBufIsValidElem(&e2)) { + skipRemainValue(pctx->p->pTSBuf, &tag); + skipped = 1; + break; + } + } + if (skipped) { + slot = 0; + stackidx = 0; + continue; + } + + tableMIdx = taosArrayGet(tsCond, ++slot); + equalNum = 1; - - - - - int64_t numOfInput1 = 1; - int64_t numOfInput2 = 1; - - while(1) { - STSElem elem = tsBufGetElem(pSupporter1->pTSBuf); - - // no data in pSupporter1 anymore, jump out of loop - if (!tsBufIsValidElem(&elem)) { - break; - } - - // find the data in supporter2 with the same tag value - STSElem e2 = tsBufFindElemStartPosByTag(pSupporter2->pTSBuf, elem.tag); - - /** - * there are elements in pSupporter2 with the same tag, continue - */ - tVariant tag1 = {0}; - tVariantAssign(&tag1, elem.tag); - - if (tsBufIsValidElem(&e2)) { while (1) { - STSElem elem1 = tsBufGetElem(pSupporter1->pTSBuf); - STSElem elem2 = tsBufGetElem(pSupporter2->pTSBuf); + ctx = &ctxlist[*tableMIdx]; + + prev = tsBufGetElem(pctx->p->pTSBuf); + cur = tsBufGetElem(ctx->p->pTSBuf); // data with current are exhausted - if (!tsBufIsValidElem(&elem1) || tVariantCompare(elem1.tag, &tag1) != 0) { + if (!tsBufIsValidElem(&prev) || tVariantCompare(prev.tag, &tag) != 0) { break; } - if (!tsBufIsValidElem(&elem2) || tVariantCompare(elem2.tag, &tag1) != 0) { // ignore all records with the same tag - skipRemainValue(pSupporter1->pTSBuf, &tag1); + if (!tsBufIsValidElem(&cur) || tVariantCompare(cur.tag, &tag) != 0) { // ignore all records with the same tag break; } - /* - * in case of stable query, limit/offset is not applied here. the limit/offset is applied to the - * final results which is acquired after the secondary merge of in the client. - */ - int32_t re = tsCompare(order, elem1.ts, elem2.ts); - if (re < 0) { - tsBufNextPos(pSupporter1->pTSBuf); - numOfInput1++; - } else if (re > 0) { - tsBufNextPos(pSupporter2->pTSBuf); - numOfInput2++; - } else { + ctxStack[stackidx++] = ctx; + + int32_t ret = tsCompare(order, prev.ts, cur.ts); + if (ret == 0) { + if (++equalNum < tableNum) { + pctx = ctx; + + if (++slot >= tableNum) { + slot = 0; + } + + tableMIdx = taosArrayGet(tsCond, slot); + continue; + } + + assert(stackidx == tableNum); + if (pLimit->offset == 0 || pQueryInfo->interval.interval > 0 || QUERY_IS_STABLE_QUERY(pQueryInfo->type)) { - if (win->skey > elem1.ts) { - win->skey = elem1.ts; + if (win->skey > prev.ts) { + win->skey = prev.ts; + } + + if (win->ekey < prev.ts) { + win->ekey = prev.ts; } - if (win->ekey < elem1.ts) { - win->ekey = elem1.ts; + for (int32_t i = 0; i < stackidx; ++i) { + SMergeTsCtx* tctx = ctxStack[i]; + prev = tsBufGetElem(tctx->p->pTSBuf); + + tsBufAppend(tctx->res, prev.id, prev.tag, (const char*)&prev.ts, sizeof(prev.ts)); } - - tsBufAppend(output1, elem1.id, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts)); - tsBufAppend(output2, elem2.id, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts)); } else { pLimit->offset -= 1;//offset apply to projection? } - tsBufNextPos(pSupporter1->pTSBuf); - numOfInput1++; + for (int32_t i = 0; i < stackidx; ++i) { + SMergeTsCtx* tctx = ctxStack[i]; + + if (!tsBufNextPos(tctx->p->pTSBuf)) { + mergeDone = 1; + } + tctx->numOfInput++; + } - tsBufNextPos(pSupporter2->pTSBuf); - numOfInput2++; + if (mergeDone) { + break; + } + + stackidx = 0; + equalNum = 1; + + ctxStack[stackidx++] = pctx; + } else if (ret > 0) { + if (!tsBufNextPos(ctx->p->pTSBuf)) { + mergeDone = 1; + break; + } + + ctx->numOfInput++; + stackidx--; + } else { + stackidx--; + + for (int32_t i = 0; i < stackidx; ++i) { + SMergeTsCtx* tctx = ctxStack[i]; + + if (!tsBufNextPos(tctx->p->pTSBuf)) { + mergeDone = 1; + } + tctx->numOfInput++; + } + + if (mergeDone) { + break; + } + + stackidx = 0; + equalNum = 1; + + ctxStack[stackidx++] = pctx; } + } - } else { // no data in pSupporter2, ignore current data in pSupporter2 - skipRemainValue(pSupporter1->pTSBuf, &tag1); + + if (mergeDone) { + break; + } + + slot = 0; + stackidx = 0; + + skipRemainValue(mainCtx->p->pTSBuf, &tag); } + + stackidx = 0; + slot = 0; + mergeDone = 0; } /* @@ -522,26 +350,31 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { * 1. only one element * 2. only one element for each tag. */ - if (output1->tsOrder == -1) { - output1->tsOrder = TSDB_ORDER_ASC; - output2->tsOrder = TSDB_ORDER_ASC; + if (ctxlist[0].res->tsOrder == -1) { + for (int32_t i = 0; i < joinNum; ++i) { + ctxlist[i].res->tsOrder = TSDB_ORDER_ASC; + } } - tsBufFlush(output1); - tsBufFlush(output2); - - tsBufDestroy(pSupporter1->pTSBuf); - pSupporter1->pTSBuf = NULL; - tsBufDestroy(pSupporter2->pTSBuf); - pSupporter2->pTSBuf = NULL; + for (int32_t i = 0; i < joinNum; ++i) { + tsBufFlush(ctxlist[i].res); + + tsBufDestroy(ctxlist[i].p->pTSBuf); + ctxlist[i].p->pTSBuf = NULL; + } TSKEY et = taosGetTimestampUs(); - tscDebug("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks " - "intersecting, skey:%" PRId64 ", ekey:%" PRId64 ", numOfVnode:%d, elapsed time:%" PRId64 " us", - pSql, numOfInput1, numOfInput2, output1->numOfTotal, output1->numOfGroups, win->skey, win->ekey, - tsBufGetNumOfGroup(output1), et - st); - return output1->numOfTotal; + for (int32_t i = 0; i < joinNum; ++i) { + tsBufFlush(ctxlist[i].res); + + tscDebug("%p tblidx:%d, input:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks " + "intersecting, skey:%" PRId64 ", ekey:%" PRId64 ", numOfVnode:%d, elapsed time:%" PRId64 " us", + pSql, i, ctxlist[i].numOfInput, ctxlist[i].res->numOfTotal, ctxlist[i].res->numOfGroups, win->skey, win->ekey, + tsBufGetNumOfGroup(ctxlist[i].res), et - st); + } + + return ctxlist[0].res->numOfTotal; } @@ -933,7 +766,7 @@ void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArr size_t numOfTables = taosArrayGetSize(tables); for (size_t i = 0; i < numOfTables; i++) { - STidTags* tt = *(STidTags **)taosArrayGet(tables, i); + STidTags* tt = taosArrayGet(tables, i); if (prev == NULL || tt->vgId != prev->vgId) { SVgroupsInfo* pvg = pTableMetaInfo->vgroupList; @@ -1069,7 +902,7 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar SJoinSupporter* p = pParentSql->pSubs[i]->param; ctxlist[i].p = p; - ctxlist[i].res = taosArrayInit(p->num, sizeof(STidTags*)); + ctxlist[i].res = taosArrayInit(p->num, size); tscDebug("Join %d - num:%d", i, p->num); @@ -1106,13 +939,20 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar tagCond = pQueryInfo->tagCond.joinInfo.joinTables[tidx]->tagJoin; - taosArrayInsert(tagCond, 0, &tidx); - tableNum = taosArrayGetSize(tagCond); - assert(tableNum >= 1); + assert(tableNum >= 2); + + for (int32_t i = 0; i < tableNum; ++i) { + tableMIdx = taosArrayGet(tagCond, i); + SMergeCtx* tctx = &ctxlist[*tableMIdx]; + tctx->compared = 1; + } + tableMIdx = taosArrayGet(tagCond, slot); + + pctx = &ctxlist[*tableMIdx]; + prev = (STidTags*) varDataVal(pctx->p->pIdTagList + pctx->idx * pctx->p->tagSize); - pctx->compared = 1; ctxStack[stackidx++] = pctx; @@ -1122,8 +962,6 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar while (1) { ctx = &ctxlist[*tableMIdx]; - - ctx->compared = 1; cur = (STidTags*) varDataVal(ctx->p->pIdTagList + ctx->idx * ctx->p->tagSize); @@ -1154,7 +992,7 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar SMergeCtx* tctx = ctxStack[i]; prev = (STidTags*) varDataVal(tctx->p->pIdTagList + tctx->idx * tctx->p->tagSize); - taosArrayPush(tctx->res, &prev); + taosArrayPush(tctx->res, prev); } for (int32_t i = 0; i < stackidx; ++i) { @@ -1177,10 +1015,14 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar ctxStack[stackidx++] = pctx; } else if (ret > 0) { + stackidx--; + if (++ctx->idx >= ctx->p->num) { break; } } else { + stackidx--; + for (int32_t i = 0; i < stackidx; ++i) { SMergeCtx* tctx = ctxStack[i]; if (++tctx->idx >= tctx->p->num) { @@ -1204,6 +1046,7 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar slot = 0; mergeDone = 0; + stackidx = 0; } for (int32_t i = 0; i < joinNum; ++i) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 13c2dc0af5..0ca4653acd 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1292,6 +1292,7 @@ bool tscColumnExists(SArray* pColumnList, SColumnIndex* pColIndex) { while (i < numOfCols) { SColumn* pCol = taosArrayGetP(pColumnList, i); if ((pCol->colIndex.columnIndex != col) || (pCol->colIndex.tableIndex != pColIndex->tableIndex)) { + ++i; continue; } else { break; From 647a0e9919d82c4b0e304f3bce875761151f024b Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 19 Mar 2021 14:37:25 +0800 Subject: [PATCH 03/10] fix bug --- src/client/src/tscSubquery.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 4780998785..db43a6776e 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -46,6 +46,13 @@ static int32_t tsCompare(int32_t order, int64_t left, int64_t right) { } static void skipRemainValue(STSBuf* pTSBuf, tVariant* tag1) { + STSElem el1 = tsBufGetElem(pTSBuf); + + int32_t res = tVariantCompare(el1.tag, tag1); + if (res != 0) { // it is a record with new tag + return; + } + while (tsBufNextPos(pTSBuf)) { STSElem el1 = tsBufGetElem(pTSBuf); From 7d246d656edfd7d8dd4a26d23a646a5fe239f2b2 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 19 Mar 2021 19:47:33 +0800 Subject: [PATCH 04/10] fix bug --- src/client/src/tscSQLParser.c | 28 +++++++++++++++++++++------- src/client/src/tscUtil.c | 9 +++++++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index b8345ea96c..77af4eb1f5 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2344,13 +2344,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col // todo REFACTOR // set the first column ts for top/bottom query - SColumnIndex index1 = {0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; + SColumnIndex index1 = {index.tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(pQueryInfo), TSDB_KEYSIZE, false); tstrncpy(pExpr->aliasName, aAggs[TSDB_FUNC_TS].name, sizeof(pExpr->aliasName)); const int32_t TS_COLUMN_INDEX = PRIMARYKEY_TIMESTAMP_COL_INDEX; - SColumnList ids = getColumnList(1, 0, TS_COLUMN_INDEX); + SColumnList ids = getColumnList(1, index.tableIndex, TS_COLUMN_INDEX); insertResultField(pQueryInfo, TS_COLUMN_INDEX, &ids, TSDB_KEYSIZE, TSDB_DATA_TYPE_TIMESTAMP, aAggs[TSDB_FUNC_TS].name, pExpr); @@ -2363,7 +2363,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col memset(pExpr->aliasName, 0, tListLen(pExpr->aliasName)); getColumnName(pItem, pExpr->aliasName, sizeof(pExpr->aliasName) - 1); - SColumnList ids = getColumnList(1, 0, index.columnIndex); + SColumnList ids = getColumnList(1, index.tableIndex, index.columnIndex); if (finalResult) { insertResultField(pQueryInfo, colIndex, &ids, resultSize, resultType, pExpr->aliasName, pExpr); } else { @@ -3715,6 +3715,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql const char* msg1 = "table query cannot use tags filter"; const char* msg2 = "illegal column name"; const char* msg3 = "only one query time range allowed"; + const char* msg4 = "too many join tables"; const char* msg5 = "not support ordinary column join"; const char* msg6 = "only one query condition on tbname allowed"; const char* msg7 = "only in/like allowed in filter table name"; @@ -3761,7 +3762,9 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } - assert(index.tableIndex >= 0 && index.tableIndex < TSDB_MAX_JOIN_TABLE_NUM); + if (index.tableIndex < 0 || index.tableIndex >= TSDB_MAX_JOIN_TABLE_NUM) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); + } SJoinNode **rightNode = &pQueryInfo->tagCond.joinInfo.joinTables[index.tableIndex]; if (*rightNode == NULL) { @@ -4374,7 +4377,10 @@ void mergeJoinNodesImpl(int8_t* r, int8_t* p, int16_t* tidx, SJoinNode** nodes, } } -int32_t mergeJoinNodes(SQueryInfo* pQueryInfo) { +int32_t mergeJoinNodes(SQueryInfo* pQueryInfo, SSqlObj* pSql) { + const char* msg1 = "not all join tables have same timestamp"; + const char* msg2 = "not all join tables have same tag"; + int8_t r[TSDB_MAX_JOIN_TABLE_NUM] = {0}; int8_t p[TSDB_MAX_JOIN_TABLE_NUM] = {0}; @@ -4393,6 +4399,10 @@ int32_t mergeJoinNodes(SQueryInfo* pQueryInfo) { memset(p, 0, sizeof(p)); } + if (taosArrayGetSize(pQueryInfo->tagCond.joinInfo.joinTables[0]->tsJoin) != pQueryInfo->numOfTables) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(&pSql->cmd), msg1); + } + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { for (int16_t i = 0; i < pQueryInfo->numOfTables; ++i) { @@ -4410,6 +4420,10 @@ int32_t mergeJoinNodes(SQueryInfo* pQueryInfo) { memset(p, 0, sizeof(p)); } + if (taosArrayGetSize(pQueryInfo->tagCond.joinInfo.joinTables[0]->tagJoin) != pQueryInfo->numOfTables) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2); + } + } return TSDB_CODE_SUCCESS; @@ -4489,13 +4503,13 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql } //doAddJoinTagsColumnsIntoTagList(&pSql->cmd, pQueryInfo, &condExpr); - if (pQueryInfo->tagCond.joinInfo.hasJoin) { + if (condExpr.tsJoin) { ret = validateJoinNodes(pQueryInfo, pSql); if (ret) { goto PARSE_WHERE_EXIT; } - ret = mergeJoinNodes(pQueryInfo); + ret = mergeJoinNodes(pQueryInfo, pSql); if (ret) { goto PARSE_WHERE_EXIT; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 0b44a4cba6..8d320c9a83 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1619,8 +1619,13 @@ int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { memcpy(dest->joinInfo.joinTables[i], src->joinInfo.joinTables[i], sizeof(SJoinNode)); - dest->joinInfo.joinTables[i]->tsJoin = taosArrayDup(src->joinInfo.joinTables[i]->tsJoin); - dest->joinInfo.joinTables[i]->tagJoin = taosArrayDup(src->joinInfo.joinTables[i]->tagJoin); + if (src->joinInfo.joinTables[i]->tsJoin) { + dest->joinInfo.joinTables[i]->tsJoin = taosArrayDup(src->joinInfo.joinTables[i]->tsJoin); + } + + if (src->joinInfo.joinTables[i]->tagJoin) { + dest->joinInfo.joinTables[i]->tagJoin = taosArrayDup(src->joinInfo.joinTables[i]->tagJoin); + } } } From 139ed7dea1d76221ff3736f0133d916ce49fff8c Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Mon, 22 Mar 2021 17:35:10 +0800 Subject: [PATCH 05/10] add test case --- src/client/src/tscSubquery.c | 16 +- .../general/parser/join_multitables.sim | 2326 +++++++++++++++++ 2 files changed, 2335 insertions(+), 7 deletions(-) create mode 100644 tests/script/general/parser/join_multitables.sim diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index db43a6776e..1c8433f541 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -169,6 +169,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { return 0; } + tscDebug("%p sub:%p table idx:%d, input group number:%d", pSql, pSql->pSubs[i], i, pSupporter->pTSBuf->numOfGroups); + ctxlist[i].p = pSupporter; ctxlist[i].res = output; } @@ -291,7 +293,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { for (int32_t i = 0; i < stackidx; ++i) { SMergeTsCtx* tctx = ctxStack[i]; - if (!tsBufNextPos(tctx->p->pTSBuf)) { + if (!tsBufNextPos(tctx->p->pTSBuf) && tctx == mainCtx) { mergeDone = 1; } tctx->numOfInput++; @@ -306,7 +308,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { ctxStack[stackidx++] = pctx; } else if (ret > 0) { - if (!tsBufNextPos(ctx->p->pTSBuf)) { + if (!tsBufNextPos(ctx->p->pTSBuf) && ctx == mainCtx) { mergeDone = 1; break; } @@ -319,7 +321,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { for (int32_t i = 0; i < stackidx; ++i) { SMergeTsCtx* tctx = ctxStack[i]; - if (!tsBufNextPos(tctx->p->pTSBuf)) { + if (!tsBufNextPos(tctx->p->pTSBuf) && tctx == mainCtx) { mergeDone = 1; } tctx->numOfInput++; @@ -373,11 +375,9 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { TSKEY et = taosGetTimestampUs(); for (int32_t i = 0; i < joinNum; ++i) { - tsBufFlush(ctxlist[i].res); - - tscDebug("%p tblidx:%d, input:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks " + tscDebug("%p sub:%p tblidx:%d, input:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks " "intersecting, skey:%" PRId64 ", ekey:%" PRId64 ", numOfVnode:%d, elapsed time:%" PRId64 " us", - pSql, i, ctxlist[i].numOfInput, ctxlist[i].res->numOfTotal, ctxlist[i].res->numOfGroups, win->skey, win->ekey, + pSql, pSql->pSubs[i], i, ctxlist[i].numOfInput, ctxlist[i].res->numOfTotal, ctxlist[i].res->numOfGroups, win->skey, win->ekey, tsBufGetNumOfGroup(ctxlist[i].res), et - st); } @@ -1881,6 +1881,8 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter pNewQueryInfo->limit.limit = -1; pNewQueryInfo->limit.offset = 0; + pNewQueryInfo->order.orderColId = INT32_MIN; + // backup the data and clear it in the sqlcmd object memset(&pNewQueryInfo->groupbyExpr, 0, sizeof(SSqlGroupbyExpr)); diff --git a/tests/script/general/parser/join_multitables.sim b/tests/script/general/parser/join_multitables.sim new file mode 100644 index 0000000000..acb8be10e7 --- /dev/null +++ b/tests/script/general/parser/join_multitables.sim @@ -0,0 +1,2326 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 2 +system sh/exec.sh -n dnode1 -s start + +sleep 100 +sql connect +print ======================== dnode1 start + +$db = testdb + +sql create database $db +sql use $db + +sql create stable st0 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st1 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st2 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st3 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st4 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st5 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st6 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st7 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st8 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable st9 (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable sta (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); +sql create stable stb (ts timestamp, f1 int, f2 double, f3 binary(10)) tags(id1 int, id2 smallint, id3 double, id4 bool, id5 binary(5)); + +sql create table tb0_1 using st0 tags(0,1,2.0,true,'3'); +sql create table tb0_2 using st0 tags(1,2,3.0,false,'4'); +sql create table tb0_3 using st0 tags(2,3,4.0,true,'5'); +sql create table tb0_4 using st0 tags(3,4,5.0,false,'6'); +sql create table tb0_5 using st0 tags(4,5,6.0,true,'7'); + +sql create table tb1_1 using st1 tags(0,1,2.0,true,'3'); +sql create table tb1_2 using st1 tags(1,2,3.0,false,'4'); +sql create table tb1_3 using st1 tags(2,3,4.0,true,'5'); +sql create table tb1_4 using st1 tags(3,4,5.0,false,'6'); +sql create table tb1_5 using st1 tags(4,5,6.0,true,'7'); + +sql create table tb2_1 using st2 tags(0,1,2.0,true,'3'); +sql create table tb2_2 using st2 tags(1,2,3.0,false,'4'); +sql create table tb2_3 using st2 tags(2,3,4.0,true,'5'); +sql create table tb2_4 using st2 tags(3,4,5.0,false,'6'); +sql create table tb2_5 using st2 tags(4,5,6.0,true,'7'); + +sql create table tb3_1 using st3 tags(0,1,2.0,true,'3'); +sql create table tb3_2 using st3 tags(1,2,3.0,false,'4'); +sql create table tb3_3 using st3 tags(2,3,4.0,true,'5'); +sql create table tb3_4 using st3 tags(3,4,5.0,false,'6'); +sql create table tb3_5 using st3 tags(4,5,6.0,true,'7'); + +sql create table tb4_1 using st4 tags(0,1,2.0,true,'3'); +sql create table tb4_2 using st4 tags(1,2,3.0,false,'4'); +sql create table tb4_3 using st4 tags(2,3,4.0,true,'5'); +sql create table tb4_4 using st4 tags(3,4,5.0,false,'6'); +sql create table tb4_5 using st4 tags(4,5,6.0,true,'7'); + +sql create table tb5_1 using st5 tags(0,1,2.0,true,'3'); +sql create table tb5_2 using st5 tags(1,2,3.0,false,'4'); +sql create table tb5_3 using st5 tags(2,3,4.0,true,'5'); +sql create table tb5_4 using st5 tags(3,4,5.0,false,'6'); +sql create table tb5_5 using st5 tags(4,5,6.0,true,'7'); + +sql create table tb6_1 using st6 tags(0,1,2.0,true,'3'); +sql create table tb6_2 using st6 tags(1,2,3.0,false,'4'); +sql create table tb6_3 using st6 tags(2,3,4.0,true,'5'); +sql create table tb6_4 using st6 tags(3,4,5.0,false,'6'); +sql create table tb6_5 using st6 tags(4,5,6.0,true,'7'); + +sql create table tb7_1 using st7 tags(0,1,2.0,true,'3'); +sql create table tb7_2 using st7 tags(1,2,3.0,false,'4'); +sql create table tb7_3 using st7 tags(2,3,4.0,true,'5'); +sql create table tb7_4 using st7 tags(3,4,5.0,false,'6'); +sql create table tb7_5 using st7 tags(4,5,6.0,true,'7'); + +sql create table tb8_1 using st8 tags(0,1,2.0,true,'3'); +sql create table tb8_2 using st8 tags(1,2,3.0,false,'4'); +sql create table tb8_3 using st8 tags(2,3,4.0,true,'5'); +sql create table tb8_4 using st8 tags(3,4,5.0,false,'6'); +sql create table tb8_5 using st8 tags(4,5,6.0,true,'7'); + +sql create table tb9_1 using st9 tags(0,1,2.0,true,'3'); +sql create table tb9_2 using st9 tags(1,2,3.0,false,'4'); +sql create table tb9_3 using st9 tags(2,3,4.0,true,'5'); +sql create table tb9_4 using st9 tags(3,4,5.0,false,'6'); +sql create table tb9_5 using st9 tags(4,5,6.0,true,'7'); + +sql create table tba_1 using sta tags(0,1,2.0,true,'3'); +sql create table tba_2 using sta tags(0,1,2.0,true,'3'); +sql create table tba_3 using sta tags(0,1,2.0,true,'3'); +sql create table tba_4 using sta tags(0,1,2.0,true,'3'); +sql create table tba_5 using sta tags(0,1,2.0,true,'3'); + +sql create table tbb_1 using stb tags(0,1,2.0,true,'3'); +sql create table tbb_2 using stb tags(0,1,2.0,true,'3'); +sql create table tbb_3 using stb tags(0,1,2.0,true,'3'); +sql create table tbb_4 using stb tags(0,1,2.0,true,'3'); +sql create table tbb_5 using stb tags(0,1,2.0,true,'3'); + +sql insert into tb0_1 values('2021-03-01 01:00:00.000', 9901,9901.0,'01'); +sql insert into tb0_1 values('2021-03-02 01:00:00.000', 9901,9901.0,'01'); +sql insert into tb0_1 values('2021-03-03 01:00:00.000', 9901,9901.0,'01'); +sql insert into tb0_1 values('2021-03-04 01:00:00.000', 9901,9901.0,'01'); +sql insert into tb0_1 values('2021-03-05 01:00:00.000', 9901,9901.0,'01'); +sql insert into tb0_2 values('2021-03-01 02:00:00.000', 9902,9902.0,'02'); +sql insert into tb0_2 values('2021-03-02 02:00:00.000', 9902,9902.0,'02'); +sql insert into tb0_2 values('2021-03-03 02:00:00.000', 9902,9902.0,'02'); +sql insert into tb0_2 values('2021-03-04 02:00:00.000', 9902,9902.0,'02'); +sql insert into tb0_2 values('2021-03-05 02:00:00.000', 9902,9902.0,'02'); +sql insert into tb0_3 values('2021-03-01 03:00:00.000', 9903,9903.0,'03'); +sql insert into tb0_3 values('2021-03-02 03:00:00.000', 9903,9903.0,'03'); +sql insert into tb0_3 values('2021-03-03 03:00:00.000', 9903,9903.0,'03'); +sql insert into tb0_3 values('2021-03-04 03:00:00.000', 9903,9903.0,'03'); +sql insert into tb0_3 values('2021-03-05 03:00:00.000', 9903,9903.0,'03'); +sql insert into tb0_4 values('2021-03-01 04:00:00.000', 9904,9904.0,'04'); +sql insert into tb0_4 values('2021-03-02 04:00:00.000', 9904,9904.0,'04'); +sql insert into tb0_4 values('2021-03-03 04:00:00.000', 9904,9904.0,'04'); +sql insert into tb0_4 values('2021-03-04 04:00:00.000', 9904,9904.0,'04'); +sql insert into tb0_4 values('2021-03-05 04:00:00.000', 9904,9904.0,'04'); +sql insert into tb0_5 values('2021-03-01 05:00:00.000', 9905,9905.0,'05'); +sql insert into tb0_5 values('2021-03-02 05:00:00.000', 9905,9905.0,'05'); +sql insert into tb0_5 values('2021-03-03 05:00:00.000', 9905,9905.0,'05'); +sql insert into tb0_5 values('2021-03-04 05:00:00.000', 9905,9905.0,'05'); +sql insert into tb0_5 values('2021-03-05 05:00:00.000', 9905,9905.0,'05'); + +sql insert into tb1_1 values('2021-03-01 01:00:00.000', 9911,9911.0,'11'); +sql insert into tb1_1 values('2021-03-02 01:00:00.000', 9911,9911.0,'11'); +sql insert into tb1_1 values('2021-03-03 01:00:00.000', 9911,9911.0,'11'); +sql insert into tb1_1 values('2021-03-04 01:00:00.000', 9911,9911.0,'11'); +sql insert into tb1_1 values('2021-03-05 01:00:00.000', 9911,9911.0,'11'); +sql insert into tb1_2 values('2021-03-01 02:00:00.000', 9912,9912.0,'12'); +sql insert into tb1_2 values('2021-03-02 02:00:00.000', 9912,9912.0,'12'); +sql insert into tb1_2 values('2021-03-03 02:00:00.000', 9912,9912.0,'12'); +sql insert into tb1_2 values('2021-03-04 02:00:00.000', 9912,9912.0,'12'); +sql insert into tb1_2 values('2021-03-05 02:00:00.000', 9912,9912.0,'12'); +sql insert into tb1_3 values('2021-03-01 03:00:00.000', 9913,9913.0,'13'); +sql insert into tb1_3 values('2021-03-02 03:00:00.000', 9913,9913.0,'13'); +sql insert into tb1_3 values('2021-03-03 03:00:00.000', 9913,9913.0,'13'); +sql insert into tb1_3 values('2021-03-04 03:00:00.000', 9913,9913.0,'13'); +sql insert into tb1_3 values('2021-03-05 03:00:00.000', 9913,9913.0,'13'); +sql insert into tb1_4 values('2021-03-01 04:00:00.000', 9914,9914.0,'14'); +sql insert into tb1_4 values('2021-03-02 04:00:00.000', 9914,9914.0,'14'); +sql insert into tb1_4 values('2021-03-03 04:00:00.000', 9914,9914.0,'14'); +sql insert into tb1_4 values('2021-03-04 04:00:00.000', 9914,9914.0,'14'); +sql insert into tb1_4 values('2021-03-05 04:00:00.000', 9914,9914.0,'14'); +sql insert into tb1_5 values('2021-03-01 05:00:00.000', 9915,9915.0,'15'); +sql insert into tb1_5 values('2021-03-02 05:00:00.000', 9915,9915.0,'15'); +sql insert into tb1_5 values('2021-03-03 05:00:00.000', 9915,9915.0,'15'); +sql insert into tb1_5 values('2021-03-04 05:00:00.000', 9915,9915.0,'15'); +sql insert into tb1_5 values('2021-03-05 05:00:00.000', 9915,9915.0,'15'); + +sql insert into tb2_1 values('2021-03-01 01:00:00.000', 9921,9921.0,'21'); +sql insert into tb2_1 values('2021-03-02 01:00:00.000', 9921,9921.0,'21'); +sql insert into tb2_1 values('2021-03-03 01:00:00.000', 9921,9921.0,'21'); +sql insert into tb2_1 values('2021-03-04 01:00:00.000', 9921,9921.0,'21'); +sql insert into tb2_1 values('2021-03-05 01:00:00.000', 9921,9921.0,'21'); +sql insert into tb2_2 values('2021-03-01 02:00:00.000', 9922,9922.0,'22'); +sql insert into tb2_2 values('2021-03-02 02:00:00.000', 9922,9922.0,'22'); +sql insert into tb2_2 values('2021-03-03 02:00:00.000', 9922,9922.0,'22'); +sql insert into tb2_2 values('2021-03-04 02:00:00.000', 9922,9922.0,'22'); +sql insert into tb2_2 values('2021-03-05 02:00:00.000', 9922,9922.0,'22'); +sql insert into tb2_3 values('2021-03-01 03:00:00.000', 9923,9923.0,'23'); +sql insert into tb2_3 values('2021-03-02 03:00:00.000', 9923,9923.0,'23'); +sql insert into tb2_3 values('2021-03-03 03:00:00.000', 9923,9923.0,'23'); +sql insert into tb2_3 values('2021-03-04 03:00:00.000', 9923,9923.0,'23'); +sql insert into tb2_3 values('2021-03-05 03:00:00.000', 9923,9923.0,'23'); +sql insert into tb2_4 values('2021-03-01 04:00:00.000', 9924,9924.0,'24'); +sql insert into tb2_4 values('2021-03-02 04:00:00.000', 9924,9924.0,'24'); +sql insert into tb2_4 values('2021-03-03 04:00:00.000', 9924,9924.0,'24'); +sql insert into tb2_4 values('2021-03-04 04:00:00.000', 9924,9924.0,'24'); +sql insert into tb2_4 values('2021-03-05 04:00:00.000', 9924,9924.0,'24'); +sql insert into tb2_5 values('2021-03-01 05:00:00.000', 9925,9925.0,'25'); +sql insert into tb2_5 values('2021-03-02 05:00:00.000', 9925,9925.0,'25'); +sql insert into tb2_5 values('2021-03-03 05:00:00.000', 9925,9925.0,'25'); +sql insert into tb2_5 values('2021-03-04 05:00:00.000', 9925,9925.0,'25'); +sql insert into tb2_5 values('2021-03-05 05:00:00.000', 9925,9925.0,'25'); + + +sql insert into tb3_1 values('2021-03-01 01:00:00.000', 9931,9931.0,'31'); +sql insert into tb3_1 values('2021-03-02 01:00:00.000', 9931,9931.0,'31'); +sql insert into tb3_1 values('2021-03-03 01:00:00.000', 9931,9931.0,'31'); +sql insert into tb3_1 values('2021-03-04 01:00:00.000', 9931,9931.0,'31'); +sql insert into tb3_1 values('2021-03-05 01:00:00.000', 9931,9931.0,'31'); +sql insert into tb3_2 values('2021-03-01 02:00:00.000', 9932,9932.0,'32'); +sql insert into tb3_2 values('2021-03-02 02:00:00.000', 9932,9932.0,'32'); +sql insert into tb3_2 values('2021-03-03 02:00:00.000', 9932,9932.0,'32'); +sql insert into tb3_2 values('2021-03-04 02:00:00.000', 9932,9932.0,'32'); +sql insert into tb3_2 values('2021-03-05 02:00:00.000', 9932,9932.0,'32'); +sql insert into tb3_3 values('2021-03-01 03:00:00.000', 9933,9933.0,'33'); +sql insert into tb3_3 values('2021-03-02 03:00:00.000', 9933,9933.0,'33'); +sql insert into tb3_3 values('2021-03-03 03:00:00.000', 9933,9933.0,'33'); +sql insert into tb3_3 values('2021-03-04 03:00:00.000', 9933,9933.0,'33'); +sql insert into tb3_3 values('2021-03-05 03:00:00.000', 9933,9933.0,'33'); +sql insert into tb3_4 values('2021-03-01 04:00:00.000', 9934,9934.0,'34'); +sql insert into tb3_4 values('2021-03-02 04:00:00.000', 9934,9934.0,'34'); +sql insert into tb3_4 values('2021-03-03 04:00:00.000', 9934,9934.0,'34'); +sql insert into tb3_4 values('2021-03-04 04:00:00.000', 9934,9934.0,'34'); +sql insert into tb3_4 values('2021-03-05 04:00:00.000', 9934,9934.0,'34'); +sql insert into tb3_5 values('2021-03-01 05:00:00.000', 9935,9935.0,'35'); +sql insert into tb3_5 values('2021-03-02 05:00:00.000', 9935,9935.0,'35'); +sql insert into tb3_5 values('2021-03-03 05:00:00.000', 9935,9935.0,'35'); +sql insert into tb3_5 values('2021-03-04 05:00:00.000', 9935,9935.0,'35'); +sql insert into tb3_5 values('2021-03-05 05:00:00.000', 9935,9935.0,'35'); + + +sql insert into tb4_1 values('2021-03-01 01:00:00.000', 9941,9941.0,'41'); +sql insert into tb4_1 values('2021-03-02 01:00:00.000', 9941,9941.0,'41'); +sql insert into tb4_1 values('2021-03-03 01:00:00.000', 9941,9941.0,'41'); +sql insert into tb4_1 values('2021-03-04 01:00:00.000', 9941,9941.0,'41'); +sql insert into tb4_1 values('2021-03-05 01:00:00.000', 9941,9941.0,'41'); +sql insert into tb4_2 values('2021-03-01 02:00:00.000', 9942,9942.0,'42'); +sql insert into tb4_2 values('2021-03-02 02:00:00.000', 9942,9942.0,'42'); +sql insert into tb4_2 values('2021-03-03 02:00:00.000', 9942,9942.0,'42'); +sql insert into tb4_2 values('2021-03-04 02:00:00.000', 9942,9942.0,'42'); +sql insert into tb4_2 values('2021-03-05 02:00:00.000', 9942,9942.0,'42'); +sql insert into tb4_3 values('2021-03-01 03:00:00.000', 9943,9943.0,'43'); +sql insert into tb4_3 values('2021-03-02 03:00:00.000', 9943,9943.0,'43'); +sql insert into tb4_3 values('2021-03-03 03:00:00.000', 9943,9943.0,'43'); +sql insert into tb4_3 values('2021-03-04 03:00:00.000', 9943,9943.0,'43'); +sql insert into tb4_3 values('2021-03-05 03:00:00.000', 9943,9943.0,'43'); +sql insert into tb4_4 values('2021-03-01 04:00:00.000', 9944,9944.0,'44'); +sql insert into tb4_4 values('2021-03-02 04:00:00.000', 9944,9944.0,'44'); +sql insert into tb4_4 values('2021-03-03 04:00:00.000', 9944,9944.0,'44'); +sql insert into tb4_4 values('2021-03-04 04:00:00.000', 9944,9944.0,'44'); +sql insert into tb4_4 values('2021-03-05 04:00:00.000', 9944,9944.0,'44'); +sql insert into tb4_5 values('2021-03-01 05:00:00.000', 9945,9945.0,'45'); +sql insert into tb4_5 values('2021-03-02 05:00:00.000', 9945,9945.0,'45'); +sql insert into tb4_5 values('2021-03-03 05:00:00.000', 9945,9945.0,'45'); +sql insert into tb4_5 values('2021-03-04 05:00:00.000', 9945,9945.0,'45'); +sql insert into tb4_5 values('2021-03-05 05:00:00.000', 9945,9945.0,'45'); + +sql insert into tb5_1 values('2021-03-01 01:00:00.000', 9951,9951.0,'51'); +sql insert into tb5_1 values('2021-03-02 01:00:00.000', 9951,9951.0,'51'); +sql insert into tb5_1 values('2021-03-03 01:00:00.000', 9951,9951.0,'51'); +sql insert into tb5_1 values('2021-03-04 01:00:00.000', 9951,9951.0,'51'); +sql insert into tb5_1 values('2021-03-05 01:00:00.000', 9951,9951.0,'51'); +sql insert into tb5_2 values('2021-03-01 02:00:00.000', 9952,9952.0,'52'); +sql insert into tb5_2 values('2021-03-02 02:00:00.000', 9952,9952.0,'52'); +sql insert into tb5_2 values('2021-03-03 02:00:00.000', 9952,9952.0,'52'); +sql insert into tb5_2 values('2021-03-04 02:00:00.000', 9952,9952.0,'52'); +sql insert into tb5_2 values('2021-03-05 02:00:00.000', 9952,9952.0,'52'); +sql insert into tb5_3 values('2021-03-01 03:00:00.000', 9953,9953.0,'53'); +sql insert into tb5_3 values('2021-03-02 03:00:00.000', 9953,9953.0,'53'); +sql insert into tb5_3 values('2021-03-03 03:00:00.000', 9953,9953.0,'53'); +sql insert into tb5_3 values('2021-03-04 03:00:00.000', 9953,9953.0,'53'); +sql insert into tb5_3 values('2021-03-05 03:00:00.000', 9953,9953.0,'53'); +sql insert into tb5_4 values('2021-03-01 04:00:00.000', 9954,9954.0,'54'); +sql insert into tb5_4 values('2021-03-02 04:00:00.000', 9954,9954.0,'54'); +sql insert into tb5_4 values('2021-03-03 04:00:00.000', 9954,9954.0,'54'); +sql insert into tb5_4 values('2021-03-04 04:00:00.000', 9954,9954.0,'54'); +sql insert into tb5_4 values('2021-03-05 04:00:00.000', 9954,9954.0,'54'); +sql insert into tb5_5 values('2021-03-01 05:00:00.000', 9955,9955.0,'55'); +sql insert into tb5_5 values('2021-03-02 05:00:00.000', 9955,9955.0,'55'); +sql insert into tb5_5 values('2021-03-03 05:00:00.000', 9955,9955.0,'55'); +sql insert into tb5_5 values('2021-03-04 05:00:00.000', 9955,9955.0,'55'); +sql insert into tb5_5 values('2021-03-05 05:00:00.000', 9955,9955.0,'55'); + +sql insert into tb6_1 values('2021-03-01 01:00:00.000', 9961,9961.0,'61'); +sql insert into tb6_1 values('2021-03-02 01:00:00.000', 9961,9961.0,'61'); +sql insert into tb6_1 values('2021-03-03 01:00:00.000', 9961,9961.0,'61'); +sql insert into tb6_1 values('2021-03-04 01:00:00.000', 9961,9961.0,'61'); +sql insert into tb6_1 values('2021-03-05 01:00:00.000', 9961,9961.0,'61'); +sql insert into tb6_2 values('2021-03-01 02:00:00.000', 9962,9962.0,'62'); +sql insert into tb6_2 values('2021-03-02 02:00:00.000', 9962,9962.0,'62'); +sql insert into tb6_2 values('2021-03-03 02:00:00.000', 9962,9962.0,'62'); +sql insert into tb6_2 values('2021-03-04 02:00:00.000', 9962,9962.0,'62'); +sql insert into tb6_2 values('2021-03-05 02:00:00.000', 9962,9962.0,'62'); +sql insert into tb6_3 values('2021-03-01 03:00:00.000', 9963,9963.0,'63'); +sql insert into tb6_3 values('2021-03-02 03:00:00.000', 9963,9963.0,'63'); +sql insert into tb6_3 values('2021-03-03 03:00:00.000', 9963,9963.0,'63'); +sql insert into tb6_3 values('2021-03-04 03:00:00.000', 9963,9963.0,'63'); +sql insert into tb6_3 values('2021-03-05 03:00:00.000', 9963,9963.0,'63'); +sql insert into tb6_4 values('2021-03-01 04:00:00.000', 9964,9964.0,'64'); +sql insert into tb6_4 values('2021-03-02 04:00:00.000', 9964,9964.0,'64'); +sql insert into tb6_4 values('2021-03-03 04:00:00.000', 9964,9964.0,'64'); +sql insert into tb6_4 values('2021-03-04 04:00:00.000', 9964,9964.0,'64'); +sql insert into tb6_4 values('2021-03-05 04:00:00.000', 9964,9964.0,'64'); +sql insert into tb6_5 values('2021-03-01 05:00:00.000', 9965,9965.0,'65'); +sql insert into tb6_5 values('2021-03-02 05:00:00.000', 9965,9965.0,'65'); +sql insert into tb6_5 values('2021-03-03 05:00:00.000', 9965,9965.0,'65'); +sql insert into tb6_5 values('2021-03-04 05:00:00.000', 9965,9965.0,'65'); +sql insert into tb6_5 values('2021-03-05 05:00:00.000', 9965,9965.0,'65'); + +sql insert into tb7_1 values('2021-03-01 01:00:00.000', 9971,9971.0,'71'); +sql insert into tb7_1 values('2021-03-02 01:00:00.000', 9971,9971.0,'71'); +sql insert into tb7_1 values('2021-03-03 01:00:00.000', 9971,9971.0,'71'); +sql insert into tb7_1 values('2021-03-04 01:00:00.000', 9971,9971.0,'71'); +sql insert into tb7_1 values('2021-03-05 01:00:00.000', 9971,9971.0,'71'); +sql insert into tb7_2 values('2021-03-01 02:00:00.000', 9972,9972.0,'72'); +sql insert into tb7_2 values('2021-03-02 02:00:00.000', 9972,9972.0,'72'); +sql insert into tb7_2 values('2021-03-03 02:00:00.000', 9972,9972.0,'72'); +sql insert into tb7_2 values('2021-03-04 02:00:00.000', 9972,9972.0,'72'); +sql insert into tb7_2 values('2021-03-05 02:00:00.000', 9972,9972.0,'72'); +sql insert into tb7_3 values('2021-03-01 03:00:00.000', 9973,9973.0,'73'); +sql insert into tb7_3 values('2021-03-02 03:00:00.000', 9973,9973.0,'73'); +sql insert into tb7_3 values('2021-03-03 03:00:00.000', 9973,9973.0,'73'); +sql insert into tb7_3 values('2021-03-04 03:00:00.000', 9973,9973.0,'73'); +sql insert into tb7_3 values('2021-03-05 03:00:00.000', 9973,9973.0,'73'); +sql insert into tb7_4 values('2021-03-01 04:00:00.000', 9974,9974.0,'74'); +sql insert into tb7_4 values('2021-03-02 04:00:00.000', 9974,9974.0,'74'); +sql insert into tb7_4 values('2021-03-03 04:00:00.000', 9974,9974.0,'74'); +sql insert into tb7_4 values('2021-03-04 04:00:00.000', 9974,9974.0,'74'); +sql insert into tb7_4 values('2021-03-05 04:00:00.000', 9974,9974.0,'74'); +sql insert into tb7_5 values('2021-03-01 05:00:00.000', 9975,9975.0,'75'); +sql insert into tb7_5 values('2021-03-02 05:00:00.000', 9975,9975.0,'75'); +sql insert into tb7_5 values('2021-03-03 05:00:00.000', 9975,9975.0,'75'); +sql insert into tb7_5 values('2021-03-04 05:00:00.000', 9975,9975.0,'75'); +sql insert into tb7_5 values('2021-03-05 05:00:00.000', 9975,9975.0,'75'); + +sql insert into tb8_1 values('2021-03-01 01:00:00.000', 9981,9981.0,'81'); +sql insert into tb8_1 values('2021-03-02 01:00:00.000', 9981,9981.0,'81'); +sql insert into tb8_1 values('2021-03-03 01:00:00.000', 9981,9981.0,'81'); +sql insert into tb8_1 values('2021-03-04 01:00:00.000', 9981,9981.0,'81'); +sql insert into tb8_1 values('2021-03-05 01:00:00.000', 9981,9981.0,'81'); +sql insert into tb8_2 values('2021-03-01 02:00:00.000', 9982,9982.0,'82'); +sql insert into tb8_2 values('2021-03-02 02:00:00.000', 9982,9982.0,'82'); +sql insert into tb8_2 values('2021-03-03 02:00:00.000', 9982,9982.0,'82'); +sql insert into tb8_2 values('2021-03-04 02:00:00.000', 9982,9982.0,'82'); +sql insert into tb8_2 values('2021-03-05 02:00:00.000', 9982,9982.0,'82'); +sql insert into tb8_3 values('2021-03-01 03:00:00.000', 9983,9983.0,'83'); +sql insert into tb8_3 values('2021-03-02 03:00:00.000', 9983,9983.0,'83'); +sql insert into tb8_3 values('2021-03-03 03:00:00.000', 9983,9983.0,'83'); +sql insert into tb8_3 values('2021-03-04 03:00:00.000', 9983,9983.0,'83'); +sql insert into tb8_3 values('2021-03-05 03:00:00.000', 9983,9983.0,'83'); +sql insert into tb8_4 values('2021-03-01 04:00:00.000', 9984,9984.0,'84'); +sql insert into tb8_4 values('2021-03-02 04:00:00.000', 9984,9984.0,'84'); +sql insert into tb8_4 values('2021-03-03 04:00:00.000', 9984,9984.0,'84'); +sql insert into tb8_4 values('2021-03-04 04:00:00.000', 9984,9984.0,'84'); +sql insert into tb8_4 values('2021-03-05 04:00:00.000', 9984,9984.0,'84'); +sql insert into tb8_5 values('2021-03-01 05:00:00.000', 9985,9985.0,'85'); +sql insert into tb8_5 values('2021-03-02 05:00:00.000', 9985,9985.0,'85'); +sql insert into tb8_5 values('2021-03-03 05:00:00.000', 9985,9985.0,'85'); +sql insert into tb8_5 values('2021-03-04 05:00:00.000', 9985,9985.0,'85'); +sql insert into tb8_5 values('2021-03-05 05:00:00.000', 9985,9985.0,'85'); + +sql insert into tb9_1 values('2021-03-01 01:00:00.000', 9991,9991.0,'91'); +sql insert into tb9_1 values('2021-03-02 01:00:00.000', 9991,9991.0,'91'); +sql insert into tb9_1 values('2021-03-03 01:00:00.000', 9991,9991.0,'91'); +sql insert into tb9_1 values('2021-03-04 01:00:00.000', 9991,9991.0,'91'); +sql insert into tb9_1 values('2021-03-05 01:00:00.000', 9991,9991.0,'91'); +sql insert into tb9_2 values('2021-03-01 02:00:00.000', 9992,9992.0,'92'); +sql insert into tb9_2 values('2021-03-02 02:00:00.000', 9992,9992.0,'92'); +sql insert into tb9_2 values('2021-03-03 02:00:00.000', 9992,9992.0,'92'); +sql insert into tb9_2 values('2021-03-04 02:00:00.000', 9992,9992.0,'92'); +sql insert into tb9_2 values('2021-03-05 02:00:00.000', 9992,9992.0,'92'); +sql insert into tb9_3 values('2021-03-01 03:00:00.000', 9993,9993.0,'93'); +sql insert into tb9_3 values('2021-03-02 03:00:00.000', 9993,9993.0,'93'); +sql insert into tb9_3 values('2021-03-03 03:00:00.000', 9993,9993.0,'93'); +sql insert into tb9_3 values('2021-03-04 03:00:00.000', 9993,9993.0,'93'); +sql insert into tb9_3 values('2021-03-05 03:00:00.000', 9993,9993.0,'93'); +sql insert into tb9_4 values('2021-03-01 04:00:00.000', 9994,9994.0,'94'); +sql insert into tb9_4 values('2021-03-02 04:00:00.000', 9994,9994.0,'94'); +sql insert into tb9_4 values('2021-03-03 04:00:00.000', 9994,9994.0,'94'); +sql insert into tb9_4 values('2021-03-04 04:00:00.000', 9994,9994.0,'94'); +sql insert into tb9_4 values('2021-03-05 04:00:00.000', 9994,9994.0,'94'); +sql insert into tb9_5 values('2021-03-01 05:00:00.000', 9995,9995.0,'95'); +sql insert into tb9_5 values('2021-03-02 05:00:00.000', 9995,9995.0,'95'); +sql insert into tb9_5 values('2021-03-03 05:00:00.000', 9995,9995.0,'95'); +sql insert into tb9_5 values('2021-03-04 05:00:00.000', 9995,9995.0,'95'); +sql insert into tb9_5 values('2021-03-05 05:00:00.000', 9995,9995.0,'95'); + +sql insert into tba_1 values('2021-03-01 01:00:00.000', 99101,99101.0,'a1'); +sql insert into tba_1 values('2021-03-02 01:00:00.000', 99101,99101.0,'a1'); +sql insert into tba_1 values('2021-03-03 01:00:00.000', 99101,99101.0,'a1'); +sql insert into tba_1 values('2021-03-04 01:00:00.000', 99101,99101.0,'a1'); +sql insert into tba_1 values('2021-03-05 01:00:00.000', 99101,99101.0,'a1'); +sql insert into tba_2 values('2021-03-01 02:00:00.000', 99102,99102.0,'a2'); +sql insert into tba_2 values('2021-03-02 02:00:00.000', 99102,99102.0,'a2'); +sql insert into tba_2 values('2021-03-03 02:00:00.000', 99102,99102.0,'a2'); +sql insert into tba_2 values('2021-03-04 02:00:00.000', 99102,99102.0,'a2'); +sql insert into tba_2 values('2021-03-05 02:00:00.000', 99102,99102.0,'a2'); +sql insert into tba_3 values('2021-03-01 03:00:00.000', 99103,99103.0,'a3'); +sql insert into tba_3 values('2021-03-02 03:00:00.000', 99103,99103.0,'a3'); +sql insert into tba_3 values('2021-03-03 03:00:00.000', 99103,99103.0,'a3'); +sql insert into tba_3 values('2021-03-04 03:00:00.000', 99103,99103.0,'a3'); +sql insert into tba_3 values('2021-03-05 03:00:00.000', 99103,99103.0,'a3'); +sql insert into tba_4 values('2021-03-01 04:00:00.000', 99104,99104.0,'a4'); +sql insert into tba_4 values('2021-03-02 04:00:00.000', 99104,99104.0,'a4'); +sql insert into tba_4 values('2021-03-03 04:00:00.000', 99104,99104.0,'a4'); +sql insert into tba_4 values('2021-03-04 04:00:00.000', 99104,99104.0,'a4'); +sql insert into tba_4 values('2021-03-05 04:00:00.000', 99104,99104.0,'a4'); +sql insert into tba_5 values('2021-03-01 05:00:00.000', 99105,99105.0,'a5'); +sql insert into tba_5 values('2021-03-02 05:00:00.000', 99105,99105.0,'a5'); +sql insert into tba_5 values('2021-03-03 05:00:00.000', 99105,99105.0,'a5'); +sql insert into tba_5 values('2021-03-04 05:00:00.000', 99105,99105.0,'a5'); +sql insert into tba_5 values('2021-03-05 05:00:00.000', 99105,99105.0,'a5'); + +sql insert into tbb_1 values('2021-03-01 01:00:00.000', 99111,99111.0,'b1'); +sql insert into tbb_1 values('2021-03-02 01:00:00.000', 99111,99111.0,'b1'); +sql insert into tbb_1 values('2021-03-03 01:00:00.000', 99111,99111.0,'b1'); +sql insert into tbb_1 values('2021-03-04 01:00:00.000', 99111,99111.0,'b1'); +sql insert into tbb_1 values('2021-03-05 01:00:00.000', 99111,99111.0,'b1'); +sql insert into tbb_2 values('2021-03-01 02:00:00.000', 99112,99112.0,'b2'); +sql insert into tbb_2 values('2021-03-02 02:00:00.000', 99112,99112.0,'b2'); +sql insert into tbb_2 values('2021-03-03 02:00:00.000', 99112,99112.0,'b2'); +sql insert into tbb_2 values('2021-03-04 02:00:00.000', 99112,99112.0,'b2'); +sql insert into tbb_2 values('2021-03-05 02:00:00.000', 99112,99112.0,'b2'); +sql insert into tbb_3 values('2021-03-01 03:00:00.000', 99113,99113.0,'b3'); +sql insert into tbb_3 values('2021-03-02 03:00:00.000', 99113,99113.0,'b3'); +sql insert into tbb_3 values('2021-03-03 03:00:00.000', 99113,99113.0,'b3'); +sql insert into tbb_3 values('2021-03-04 03:00:00.000', 99113,99113.0,'b3'); +sql insert into tbb_3 values('2021-03-05 03:00:00.000', 99113,99113.0,'b3'); +sql insert into tbb_4 values('2021-03-01 04:00:00.000', 99114,99114.0,'b4'); +sql insert into tbb_4 values('2021-03-02 04:00:00.000', 99114,99114.0,'b4'); +sql insert into tbb_4 values('2021-03-03 04:00:00.000', 99114,99114.0,'b4'); +sql insert into tbb_4 values('2021-03-04 04:00:00.000', 99114,99114.0,'b4'); +sql insert into tbb_4 values('2021-03-05 04:00:00.000', 99114,99114.0,'b4'); +sql insert into tbb_5 values('2021-03-01 05:00:00.000', 99115,99115.0,'b5'); +sql insert into tbb_5 values('2021-03-02 05:00:00.000', 99115,99115.0,'b5'); +sql insert into tbb_5 values('2021-03-03 05:00:00.000', 99115,99115.0,'b5'); +sql insert into tbb_5 values('2021-03-04 05:00:00.000', 99115,99115.0,'b5'); +sql insert into tbb_5 values('2021-03-05 05:00:00.000', 99115,99115.0,'b5'); + + +sql select * from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi +if $data09 != @21-03-01 01:00:00.000@ then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi +if $data19 != @21-03-02 01:00:00.000@ then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9901 then + return -1 +endi +if $data22 != 9901.000000000 then + return -1 +endi +if $data23 != 01 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi +if $data29 != @21-03-03 01:00:00.000@ then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9901 then + return -1 +endi +if $data32 != 9901.000000000 then + return -1 +endi +if $data33 != 01 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi +if $data39 != @21-03-04 01:00:00.000@ then + return -1 +endi + + + + +sql select * from st0, st1 where st0.ts=st1.ts and st0.id2=st1.id2; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi +if $data09 != @21-03-01 01:00:00.000@ then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi +if $data19 != @21-03-02 01:00:00.000@ then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9901 then + return -1 +endi +if $data22 != 9901.000000000 then + return -1 +endi +if $data23 != 01 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi +if $data29 != @21-03-03 01:00:00.000@ then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9901 then + return -1 +endi +if $data32 != 9901.000000000 then + return -1 +endi +if $data33 != 01 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi +if $data39 != @21-03-04 01:00:00.000@ then + return -1 +endi + + + + +sql select * from st0, st1 where st0.id3=st1.id3 and st1.ts=st0.ts; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi +if $data09 != @21-03-01 01:00:00.000@ then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi +if $data19 != @21-03-02 01:00:00.000@ then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9901 then + return -1 +endi +if $data22 != 9901.000000000 then + return -1 +endi +if $data23 != 01 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi +if $data29 != @21-03-03 01:00:00.000@ then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9901 then + return -1 +endi +if $data32 != 9901.000000000 then + return -1 +endi +if $data33 != 01 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi +if $data39 != @21-03-04 01:00:00.000@ then + return -1 +endi + + + + + +sql select * from st0, st1 where st1.id5=st0.id5 and st0.ts=st1.ts; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi +if $data09 != @21-03-01 01:00:00.000@ then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi +if $data19 != @21-03-02 01:00:00.000@ then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9901 then + return -1 +endi +if $data22 != 9901.000000000 then + return -1 +endi +if $data23 != 01 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi +if $data29 != @21-03-03 01:00:00.000@ then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9901 then + return -1 +endi +if $data32 != 9901.000000000 then + return -1 +endi +if $data33 != 01 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi +if $data39 != @21-03-04 01:00:00.000@ then + return -1 +endi + + + + +sql select st0.* from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9901 then + return -1 +endi +if $data22 != 9901.000000000 then + return -1 +endi +if $data23 != 01 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9901 then + return -1 +endi +if $data32 != 9901.000000000 then + return -1 +endi +if $data33 != 01 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi + + + + +sql select st0.* from st0, st1 where st0.ts=st1.ts and st1.id2=st0.id2; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9901 then + return -1 +endi +if $data22 != 9901.000000000 then + return -1 +endi +if $data23 != 01 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9901 then + return -1 +endi +if $data32 != 9901.000000000 then + return -1 +endi +if $data33 != 01 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi + + + + + +sql select st0.* from st0, st1 where st0.id3=st1.id3 and st1.ts=st0.ts; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9901 then + return -1 +endi +if $data22 != 9901.000000000 then + return -1 +endi +if $data23 != 01 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9901 then + return -1 +endi +if $data32 != 9901.000000000 then + return -1 +endi +if $data33 != 01 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi + + + + +sql select st1.* from st0, st1 where st1.id5=st0.id5 and st0.ts=st1.ts; + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9911 then + return -1 +endi +if $data02 != 9911.000000000 then + return -1 +endi +if $data03 != 11 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + print $data07 + return -1 +endi +if $data08 != 3 then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9911 then + return -1 +endi +if $data12 != 9911.000000000 then + return -1 +endi +if $data13 != 11 then + return -1 +endi +if $data14 != 0 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != 2.000000000 then + return -1 +endi +if $data17 != 1 then + return -1 +endi +if $data18 != 3 then + return -1 +endi + + + +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != 9911 then + return -1 +endi +if $data22 != 9911.000000000 then + return -1 +endi +if $data23 != 11 then + return -1 +endi +if $data24 != 0 then + return -1 +endi +if $data25 != 1 then + return -1 +endi +if $data26 != 2.000000000 then + return -1 +endi +if $data27 != 1 then + return -1 +endi +if $data28 != 3 then + return -1 +endi + + +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != 9911 then + return -1 +endi +if $data32 != 9911.000000000 then + return -1 +endi +if $data33 != 11 then + return -1 +endi +if $data34 != 0 then + return -1 +endi +if $data35 != 1 then + return -1 +endi +if $data36 != 2.000000000 then + return -1 +endi +if $data37 != 1 then + return -1 +endi +if $data38 != 3 then + return -1 +endi + + +sql select st0.f1,st1.f1 from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1; + +if $rows != 25 then + return -1 +endi + +if $data00 != 9901 then + return -1 +endi +if $data01 != 9911 then + return -1 +endi +if $data10 != 9901 then + return -1 +endi +if $data11 != 9911 then + return -1 +endi +if $data20 != 9901 then + return -1 +endi +if $data21 != 9911 then + return -1 +endi +if $data30 != 9901 then + return -1 +endi +if $data31 != 9911 then + return -1 +endi + + + + +sql select st0.ts,st1.ts from st0, st1 where st0.ts=st1.ts and st1.id2=st0.id2; + + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data20 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data21 != @21-03-03 01:00:00.000@ then + return -1 +endi +if $data30 != @21-03-04 01:00:00.000@ then + return -1 +endi +if $data31 != @21-03-04 01:00:00.000@ then + return -1 +endi + + + +sql select st1.ts,st0.ts,st0.id3,st1.id3,st0.f3,st1.f3 from st0, st1 where st0.id3=st1.id3 and st1.ts=st0.ts; + + +if $rows != 25 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data02 != 2.000000000 then + return -1 +endi +if $data03 != 2.000000000 then + return -1 +endi +if $data04 != 01 then + return -1 +endi +if $data05 != 11 then + return -1 +endi + +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data02 != 2.000000000 then + return -1 +endi +if $data03 != 2.000000000 then + return -1 +endi +if $data04 != 01 then + return -1 +endi +if $data05 != 11 then + return -1 +endi + + + +sql select st0.ts,st0.f2,st1.f3,st1.f2,st0.f3 from st0, st1 where st1.id5=st0.id5 and st0.ts=st1.ts; +if $rows != 25 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901.000000000 then + return -1 +endi +if $data02 != 11 then + return -1 +endi +if $data03 != 9911.000000000 then + return -1 +endi +if $data04 != 01 then + return -1 +endi +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901.000000000 then + return -1 +endi +if $data12 != 11 then + return -1 +endi +if $data13 != 9911.000000000 then + return -1 +endi +if $data14 != 01 then + return -1 +endi + + + + +sql select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 interval(10a); +if $rows != 25 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data02 != 9901 then + return -1 +endi +if $data03 != 9901.000000000 then + return -1 +endi +if $data04 != 01 then + return -1 +endi +if $data05 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data06 != 9911 then + return -1 +endi +if $data07 != 9911.000000000 then + return -1 +endi +if $data08 != 11 then + return -1 +endi +if $data10 != @21-03-01 02:00:00.000@ then + return -1 +endi +if $data11 != @21-03-01 02:00:00.000@ then + return -1 +endi +if $data12 != 9902 then + return -1 +endi +if $data13 != 9902.000000000 then + return -1 +endi +if $data14 != 02 then + return -1 +endi +if $data15 != @21-03-01 02:00:00.000@ then + return -1 +endi +if $data16 != 9912 then + return -1 +endi +if $data17 != 9912.000000000 then + return -1 +endi +if $data18 != 12 then + return -1 +endi + + + +sql select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 interval(1d) sliding(1d); +if $rows != 5 then + return -1 +endi +if $data00 != @21-03-01 00:00:00.000@ then + return -1 +endi +if $data01 != @21-03-01 05:00:00.000@ then + return -1 +endi +if $data02 != 9905 then + return -1 +endi +if $data03 != 9905.000000000 then + return -1 +endi +if $data04 != 05 then + return -1 +endi +if $data05 != @21-03-01 05:00:00.000@ then + return -1 +endi +if $data06 != 9915 then + return -1 +endi +if $data07 != 9915.000000000 then + return -1 +endi +if $data08 != 15 then + return -1 +endi +if $data10 != @21-03-02 00:00:00.000@ then + return -1 +endi +if $data11 != @21-03-02 05:00:00.000@ then + return -1 +endi +if $data12 != 9905 then + return -1 +endi +if $data13 != 9905.000000000 then + return -1 +endi +if $data14 != 05 then + return -1 +endi +if $data15 != @21-03-02 05:00:00.000@ then + return -1 +endi +if $data16 != 9915 then + return -1 +endi +if $data17 != 9915.000000000 then + return -1 +endi +if $data18 != 15 then + return -1 +endi + + + +sql select st0.*,st1.* from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1; +if $rows != 25 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + return -1 +endi +if $data08 != 3 then + return -1 +endi +if $data09 != @21-03-01 01:00:00.000@ then + return -1 +endi + + + + + +sql select st0.ts,* from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 order by st0.ts; + +if $rows != 25 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data02 != 9901 then + return -1 +endi +if $data03 != 9901.000000000 then + return -1 +endi +if $data04 != 01 then + return -1 +endi +if $data05 != 0 then + return -1 +endi +if $data06 != 1 then + return -1 +endi +if $data07 != 2.000000000 then + return -1 +endi +if $data08 != 1 then + return -1 +endi +if $data09 != 3 then + return -1 +endi + + + + + +sql select st0.*,st1.* from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1 order by st0.ts limit 5 offset 5 +if $rows != 5 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + print $data00 + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + return -1 +endi +if $data08 != 3 then + return -1 +endi +if $data09 != @21-03-01 01:00:00.000@ then + return -1 +endi + + + +sql select top(st1.f1, 5) from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1; +if $rows != 5 then + return -1 +endi +if $data00 != @21-03-01 05:00:00.000@ then + return -1 +endi +if $data01 != 9915 then + return -1 +endi +if $data10 != @21-03-02 05:00:00.000@ then + return -1 +endi +if $data11 != 9915 then + return -1 +endi +if $data20 != @21-03-03 05:00:00.000@ then + return -1 +endi +if $data21 != 9915 then + return -1 +endi +if $data30 != @21-03-04 05:00:00.000@ then + return -1 +endi +if $data31 != 9915 then + return -1 +endi +if $data40 != @21-03-05 05:00:00.000@ then + return -1 +endi +if $data41 != 9915 then + return -1 +endi + + + + + +sql select top(st0.f1,5) from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1; +if $rows != 5 then + return -1 +endi +if $data00 != @21-03-01 05:00:00.000@ then + return -1 +endi +if $data01 != 9905 then + return -1 +endi +if $data10 != @21-03-02 05:00:00.000@ then + return -1 +endi +if $data11 != 9905 then + return -1 +endi +if $data20 != @21-03-03 05:00:00.000@ then + return -1 +endi +if $data21 != 9905 then + return -1 +endi +if $data30 != @21-03-04 05:00:00.000@ then + return -1 +endi +if $data31 != 9905 then + return -1 +endi +if $data40 != @21-03-05 05:00:00.000@ then + return -1 +endi +if $data41 != 9905 then + return -1 +endi + + +#sql select st0.*,st1.*,st2.*,st3.* from st3,st2,st1,st0 where st0.id1=st3.id1 and st3.ts=st2.ts and st2.id1=st1.id1 and st1.ts=st0.ts; +#sql select st0.*,st1.*,st2.*,st3.* from st3,st2,st1,st0 where st0.id1=st3.id1 and st3.ts=st2.ts and st2.id1=st1.id1 and st1.ts=st0.ts and st0.id1=st2.id1 and st1.ts=st2.ts; +#if $rows != 25 then +# print $rows +# return -1 +#endi +#if $data00 != @21-03-01 01:00:00.000@ then +# return -1 +#endi +#if $data01 != 9901 then +# return -1 +#endi +#if $data02 != 9901.000000000 then +# return -1 +#endi +#if $data03 != 01 then +# return -1 +#endi +#if $data04 != 0 then +# return -1 +#endi +#if $data05 != 1 then +# return -1 +#endi +#if $data06 != 2.000000000 then +# return -1 +#endi +#if $data07 != 1 then +# return -1 +#endi +#if $data08 != 3 then +# return -1 +#endi +#if $data09 != @21-03-01 01:00:00.000@ then +# return -1 +#endi + + + +#sql select st0.*,st1.*,st2.*,st3.* from st3,st2,st1,st0 where st0.id1=st1.id1 and st1.ts=st0.ts and st2.id1=st3.id1 and st3.ts=st2.ts; +#sql select st0.*,st1.*,st2.*,st3.* from st3,st2,st1,st0 where st0.id1=st1.id1 and st1.ts=st0.ts and st2.id1=st3.id1 and st3.ts=st2.ts and st0.id1=st2.id1 and st0.ts=st2.ts; +#if $rows != 25 then +# return -1 +#endi +#if $data00 != @21-03-01 01:00:00.000@ then +# return -1 +#endi +#if $data01 != 9901 then +# return -1 +#endi +#if $data02 != 9901.000000000 then +# return -1 +#endi +#if $data03 != 01 then +# return -1 +#endi +#if $data04 != 0 then +# return -1 +#endi +#if $data05 != 1 then +# return -1 +#endi +#if $data06 != 2.000000000 then +# return -1 +#endi +#if $data07 != 1 then +# return -1 +#endi +#if $data08 != 3 then +# return -1 +#endi +#if $data09 != @21-03-01 01:00:00.000@ then +# return -1 +#endi + + + +sql select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9 where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.ts=st1.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1 and st0.id1=st1.id1; +if $rows != 25 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 2.000000000 then + return -1 +endi +if $data07 != 1 then + return -1 +endi +if $data08 != 3 then + return -1 +endi +if $data09 != @21-03-01 01:00:00.000@ then + return -1 +endi + + + +sql select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.ts=tb1_1.ts; +if $rows != 5 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data05 != 9911 then + return -1 +endi +if $data06 != 9911.000000000 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data15 != 9911 then + return -1 +endi +if $data16 != 9911.000000000 then + return -1 +endi +if $data17 != 11 then + return -1 +endi + + + +sql select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.ts=tb1_1.ts and tb0_1.id1=tb1_1.id1; +if $rows != 5 then + return -1 +endi +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data05 != 9911 then + return -1 +endi +if $data06 != 9911.000000000 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data15 != 9911 then + return -1 +endi +if $data16 != 9911.000000000 then + return -1 +endi +if $data17 != 11 then + return -1 +endi + + +sql select tb0_1.*, tb1_2.*,tb2_3.*,tb3_4.*,tb4_5.* from tb0_1, tb1_2, tb2_3, tb3_4, tb4_5 where tb0_1.ts=tb1_2.ts and tb0_1.ts=tb2_3.ts and tb0_1.ts=tb3_4.ts and tb0_1.ts=tb4_5.ts; +if $rows != 0 then + return -1 +endi + + + +sql select tb0_1.*, tb1_1.*,tb2_1.*,tb3_1.*,tb4_1.* from tb0_1, tb1_1, tb2_1, tb3_1, tb4_1 where tb0_1.ts=tb1_1.ts and tb0_1.ts=tb2_1.ts and tb0_1.ts=tb3_1.ts and tb0_1.ts=tb4_1.ts; + +if $rows != 5 then + return -1 +endi + +if $data00 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data01 != 9901 then + return -1 +endi +if $data02 != 9901.000000000 then + return -1 +endi +if $data03 != 01 then + return -1 +endi +if $data04 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data05 != 9911 then + return -1 +endi +if $data06 != 9911.000000000 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +if $data08 != @21-03-01 01:00:00.000@ then + return -1 +endi +if $data09 != 9921 then + return -1 +endi +if $data10 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data11 != 9901 then + return -1 +endi +if $data12 != 9901.000000000 then + return -1 +endi +if $data13 != 01 then + return -1 +endi +if $data14 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data15 != 9911 then + return -1 +endi +if $data16 != 9911.000000000 then + return -1 +endi +if $data17 != 11 then + return -1 +endi +if $data18 != @21-03-02 01:00:00.000@ then + return -1 +endi +if $data19 != 9921 then + return -1 +endi + + + +sql select tb0_5.*, tb1_5.*,tb2_5.*,tb3_5.*,tb4_5.*,tb5_5.*, tb6_5.*,tb7_5.*,tb8_5.*,tb9_5.* from tb0_5, tb1_5, tb2_5, tb3_5, tb4_5,tb5_5, tb6_5, tb7_5, tb8_5, tb9_5 where tb9_5.ts=tb8_5.ts and tb8_5.ts=tb7_5.ts and tb7_5.ts=tb6_5.ts and tb6_5.ts=tb5_5.ts and tb5_5.ts=tb4_5.ts and tb4_5.ts=tb3_5.ts and tb3_5.ts=tb2_5.ts and tb2_5.ts=tb1_5.ts and tb1_5.ts=tb0_5.ts; + +if $rows != 5 then + return -1 +endi + +if $data00 != @21-03-01 05:00:00.000@ then + return -1 +endi +if $data01 != 9905 then + return -1 +endi +if $data02 != 9905.000000000 then + return -1 +endi +if $data03 != 05 then + return -1 +endi +if $data04 != @21-03-01 05:00:00.000@ then + return -1 +endi +if $data05 != 9915 then + return -1 +endi +if $data06 != 9915.000000000 then + return -1 +endi +if $data07 != 15 then + return -1 +endi +if $data08 != @21-03-01 05:00:00.000@ then + return -1 +endi +if $data09 != 9925 then + return -1 +endi +if $data10 != @21-03-02 05:00:00.000@ then + return -1 +endi +if $data11 != 9905 then + return -1 +endi +if $data12 != 9905.000000000 then + return -1 +endi +if $data13 != 05 then + return -1 +endi +if $data14 != @21-03-02 05:00:00.000@ then + return -1 +endi +if $data15 != 9915 then + return -1 +endi +if $data16 != 9915.000000000 then + return -1 +endi +if $data17 != 15 then + return -1 +endi +if $data18 != @21-03-02 05:00:00.000@ then + return -1 +endi +if $data19 != 9925 then + return -1 +endi + + +sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.f1=tb1_1.f1; +sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.ts=tb1_1.ts and tb0_1.id1=tb1_1.id2; +sql_error select tb0_5.*, tb1_5.*,tb2_5.*,tb3_5.*,tb4_5.*,tb5_5.*, tb6_5.*,tb7_5.*,tb8_5.*,tb9_5.*,tba_5.* from tb0_5, tb1_5, tb2_5, tb3_5, tb4_5,tb5_5, tb6_5, tb7_5, tb8_5, tb9_5, tba_5 where tb9_5.ts=tb8_5.ts and tb8_5.ts=tb7_5.ts and tb7_5.ts=tb6_5.ts and tb6_5.ts=tb5_5.ts and tb5_5.ts=tb4_5.ts and tb4_5.ts=tb3_5.ts and tb3_5.ts=tb2_5.ts and tb2_5.ts=tb1_5.ts and tb1_5.ts=tb0_5.ts and tb0_5.ts=tba_5.ts; + +sql_error select * from st0, st1 where st0.ts=st1.ts; +sql_error select * from st0, st1 where st0.id1=st1.id1; +sql_error select * from st0, st1 where st0.f1=st1.f1 and st0.id1=st1.id1; +sql_error select * from st0, st1, st2, st3 where st0.id1=st1.id1 and st2.id1=st3.id1 and st0.ts=st1.ts and st1.ts=st2.ts and st2.ts=st3.ts; +sql_error select * from st0, st1, st2 where st0.id1=st1.id1; +sql_error select * from st0, st1 where st0.id1=st1.id1 and st0.id2=st1.id3; +sql_error select * from st0, st1 where st0.id1=st1.id1 or st0.ts=st1.ts; +sql_error select * from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 or st0.id2=st1.id2; +sql_error select * from st0, st1, st2 where st0.ts=st1.ts and st0.id1=st1.id1; +sql_error select * from st0, st1 where st0.id1=st1.ts and st0.ts=st1.id1; +sql_error select * from st0, st1 where st0.id1=st1.id2 and st0.ts=st1.ts; +sql_error select * from st0, st1 where st1.id4=st0.id4 and st1.ts=st0.ts; +sql_error select * from st0, st1 where st0.id1=st1.id2 and st1.ts=st0.ts; +sql_error select * from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 interval 10a; +sql_error select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 group by f1; +sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9 where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1; +sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9,sta where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.ts=st1.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1 and st0.id1=st1.id1 and st0.id1=sta.id1 and st0.ts=sta.ts; + + + + + + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT From ff41983d02c16e0664fe9d95ba5b5fdc0a27d5d5 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Mon, 22 Mar 2021 18:42:39 +0800 Subject: [PATCH 06/10] fix windows compile err --- src/client/src/tscSQLParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 77af4eb1f5..e1dce3b4c2 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4364,7 +4364,7 @@ int32_t validateJoinNodes(SQueryInfo* pQueryInfo, SSqlObj* pSql) { void mergeJoinNodesImpl(int8_t* r, int8_t* p, int16_t* tidx, SJoinNode** nodes, int32_t type) { SJoinNode *node = nodes[*tidx]; SArray* arr = (type == 0) ? node->tsJoin : node->tagJoin; - int32_t size = taosArrayGetSize(arr); + size_t size = taosArrayGetSize(arr); p[*tidx] = 1; From 54d94e1a9659f7e0bb727597d2a80e52c69d9a0a Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Mon, 22 Mar 2021 18:58:05 +0800 Subject: [PATCH 07/10] fix compile err --- src/client/src/tscSubquery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 1c8433f541..e258e7c63a 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -137,7 +137,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { SMergeTsCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {0}; SMergeTsCtx* ctxStack[TSDB_MAX_JOIN_TABLE_NUM] = {0}; int32_t slot = 0; - int32_t tableNum = 0; + size_t tableNum = 0; int16_t* tableMIdx = 0; int32_t equalNum = 0; int32_t stackidx = 0; @@ -925,7 +925,7 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar } int32_t slot = 0; - int32_t tableNum = 0; + size_t tableNum = 0; int16_t* tableMIdx = 0; int32_t equalNum = 0; int32_t stackidx = 0; @@ -1072,7 +1072,7 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar } bool emptyTagList(SArray* resList, int32_t size) { - int32_t rsize = taosArrayGetSize(resList); + size_t rsize = taosArrayGetSize(resList); if (rsize != size) { return true; } @@ -1231,7 +1231,7 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow } } - int32_t rsize = taosArrayGetSize(resList); + size_t rsize = taosArrayGetSize(resList); for (int32_t i = 0; i < rsize; ++i) { SArray** s = taosArrayGet(resList, i); if (*s) { From ff4328c319c452c68a638588beb1468cd0b92a0e Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Mon, 22 Mar 2021 19:29:12 +0800 Subject: [PATCH 08/10] fix error --- src/client/src/tscSubquery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index e258e7c63a..830caad486 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -134,7 +134,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, STimeWindow * win) { SLimitVal* pLimit = &pQueryInfo->limit; int32_t order = pQueryInfo->order.order; int32_t joinNum = pSql->subState.numOfSub; - SMergeTsCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {0}; + SMergeTsCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {{0}}; SMergeTsCtx* ctxStack[TSDB_MAX_JOIN_TABLE_NUM] = {0}; int32_t slot = 0; size_t tableNum = 0; @@ -895,7 +895,7 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); int16_t tagColId = tscGetJoinTagColIdByUid(&pQueryInfo->tagCond, pTableMetaInfo->pTableMeta->id.uid); SJoinSupporter* p0 = pParentSql->pSubs[0]->param; - SMergeCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {0}; + SMergeCtx ctxlist[TSDB_MAX_JOIN_TABLE_NUM] = {{0}}; SMergeCtx* ctxStack[TSDB_MAX_JOIN_TABLE_NUM] = {0}; // int16_t for padding From a8a7c7db6786c04340e78410271054c4103a7304 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Tue, 23 Mar 2021 11:07:01 +0800 Subject: [PATCH 09/10] fix double free error --- src/client/src/tscSQLParser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index e1dce3b4c2..299ebebd7d 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4450,7 +4450,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql int32_t type = 0; if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + return ret; } tSqlExprCompact(pExpr); @@ -4460,17 +4460,17 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql // 1. check if it is a join query if ((ret = validateJoinExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + return ret; } // 2. get the query time range if ((ret = getTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + return ret; } // 3. get the tag query condition if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + return ret; } // 4. get the table name query condition From 4e5733c0acb9f857747cb4b1cca53e6fbdcb9379 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Tue, 23 Mar 2021 15:48:57 +0800 Subject: [PATCH 10/10] support multiple tables join --- src/client/src/tscSubquery.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 830caad486..76237ebb95 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -954,6 +954,20 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar SMergeCtx* tctx = &ctxlist[*tableMIdx]; tctx->compared = 1; } + + for (int32_t i = 0; i < tableNum; ++i) { + tableMIdx = taosArrayGet(tagCond, i); + SMergeCtx* tctx = &ctxlist[*tableMIdx]; + if (tctx->p->num <= 0 || tctx->p->pIdTagList == NULL) { + mergeDone = 1; + break; + } + } + + if (mergeDone) { + mergeDone = 0; + continue; + } tableMIdx = taosArrayGet(tagCond, slot);