From d54ea3c2978efce1bbeed67b60284470b2b64e2d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 16 Apr 2021 17:49:37 +0800 Subject: [PATCH] [td-225]refactor code. --- src/client/src/tscLocalMerge.c | 1 - src/client/src/tscSQLParser.c | 11 +++++++---- src/client/src/tscSubquery.c | 24 ++++++++++++++++++++---- src/client/src/tscUtil.c | 8 ++++---- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 59d1cf7a43..064d793a9c 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -327,7 +327,6 @@ void tscCreateLocalMerger(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrde pMerger->pCtx = (SQLFunctionCtx *)calloc(tscSqlExprNumOfExprs(pQueryInfo), sizeof(SQLFunctionCtx)); pMerger->rowSize = pMemBuffer[0]->nElemSize; -// tscRestoreFuncForSTableQuery(pQueryInfo); tscFieldInfoUpdateOffset(pQueryInfo); if (pMerger->rowSize > pMemBuffer[0]->pageSize) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 5aabd94428..60f6f54335 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3379,9 +3379,9 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSq static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { int32_t code = 0; const char* msg1 = "timestamp required for join tables"; + const char* msg2 = "only support one join tag for each table"; 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; @@ -3415,11 +3415,14 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS (*leftNode)->tagColId = pTagSchema1->colId; if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; + index.columnIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta); if (!tscColumnExists(pTableMetaInfo->tagColList, index.columnIndex, pTableMetaInfo->pTableMeta->id.uid)) { -// tscColumnListInsert(pTableMetaInfo->tagColList, &index, ); + tscColumnListInsert(pTableMetaInfo->tagColList, index.columnIndex, pTableMeta->id.uid, pTagSchema1); + if (taosArrayGetSize(pTableMetaInfo->tagColList) > 1) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } } } @@ -3451,7 +3454,7 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS tscColumnListInsert(pTableMetaInfo->tagColList, index.columnIndex, pTableMeta->id.uid, pTagSchema2); if (taosArrayGetSize(pTableMetaInfo->tagColList) > 1) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } } } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 24c87897d6..3a09a8ad9b 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -604,7 +604,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) { * during the timestamp intersection. */ pSupporter->limit = pQueryInfo->limit; - pQueryInfo->limit = pSupporter->limit; +// pQueryInfo->limit = pSupporter->limit; SColumnIndex index = {.tableIndex = 0, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX}; SSchema* s = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, 0); @@ -3239,9 +3239,11 @@ static char* getResultBlockPosition(SSqlCmd* pCmd, SSqlRes* pRes, int32_t column assert(pInfo->pExpr->pExpr == NULL); *bytes = pInfo->pExpr->base.resBytes; - char* pData = pRes->data + pInfo->pExpr->base.offset * pRes->numOfRows + pRes->row * (*bytes); - - return pData; + if (pRes->data != NULL) { + return pRes->data + pInfo->pExpr->base.offset * pRes->numOfRows + pRes->row * (*bytes); + } else { + return pRes->urow[columnIndex] + pRes->row * (*bytes); + } } static void doBuildResFromSubqueries(SSqlObj* pSql) { @@ -3265,6 +3267,7 @@ static void doBuildResFromSubqueries(SSqlObj* pSql) { return; } + tscRestoreFuncForSTableQuery(pQueryInfo); int32_t rowSize = tscGetResRowLength(pQueryInfo->exprList); assert(numOfRes * rowSize > 0); @@ -3284,6 +3287,19 @@ static void doBuildResFromSubqueries(SSqlObj* pSql) { int16_t bytes = 0; + tscRestoreFuncForSTableQuery(pQueryInfo); + tscFieldInfoUpdateOffset(pQueryInfo); + for (int32_t i = 0; i < pSql->subState.numOfSub; ++i) { + SSqlObj* pSub = pSql->pSubs[i]; + if (pSub == NULL) { + continue; + } + + SQueryInfo* pSubQueryInfo = pSub->cmd.pQueryInfo[0]; + tscRestoreFuncForSTableQuery(pSubQueryInfo); + tscFieldInfoUpdateOffset(pSubQueryInfo); + } + size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo); for(int32_t i = 0; i < numOfExprs; ++i) { SColumnIndex* pIndex = &pRes->pColumnIndex[i]; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 8146ed134b..da310beb49 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2353,7 +2353,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, SName* name, STableM } if (pTagCols != NULL) { - tscColumnListCopy(pTableMetaInfo->tagColList, pTagCols, -1); + tscColumnListCopy(pTableMetaInfo->tagColList, pTagCols, pTableMetaInfo->pTableMeta->id.uid); } pTableMetaInfo->pVgroupTables = tscVgroupTableInfoDup(pVgroupTables); @@ -2584,8 +2584,9 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } - - tscColumnListCopy(pNewQueryInfo->colList, pQueryInfo->colList, (int16_t)tableIndex); + + uint64_t uid = pTableMetaInfo->pTableMeta->id.uid; + tscColumnListCopy(pNewQueryInfo->colList, pQueryInfo->colList, uid); // set the correct query type if (pPrevSql != NULL) { @@ -2595,7 +2596,6 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t TSDB_QUERY_SET_TYPE(pNewQueryInfo->type, TSDB_QUERY_TYPE_SUBQUERY);// it must be the subquery } - uint64_t uid = pTableMetaInfo->pTableMeta->id.uid; if (tscSqlExprCopy(pNewQueryInfo->exprList, pQueryInfo->exprList, uid, true) != 0) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; -- GitLab