From 27c481c8863a909006b003e5f89f27193780c8e2 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 7 May 2020 15:25:13 +0800 Subject: [PATCH] [td-225] --- src/client/inc/tsclient.h | 2 +- src/client/src/tscSQLParser.c | 22 +++++++++++----------- src/client/src/tscServer.c | 19 ------------------- src/client/src/tscSub.c | 2 +- src/query/src/queryExecutor.c | 10 ++++++---- 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 854a12629f..3a26d294a4 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -195,7 +195,7 @@ typedef struct SDataBlockList { // todo remove typedef struct SQueryInfo { int16_t command; // the command may be different for each subclause, so keep it seperately. - uint16_t type; // query/insert/import type + uint32_t type; // query/insert/import type char slidingTimeUnit; STimeWindow window; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 6e7b902111..947384a992 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1117,7 +1117,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel // if the name of column is quoted, remove it and set the right information for later process extractColumnNameFromString(pItem); - pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY; + TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_PROJECTION_QUERY); // select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2 if (addProjectionExprAndResultField(pQueryInfo, pItem) != TSDB_CODE_SUCCESS) { @@ -1238,7 +1238,6 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel } if (isSTable) { - pQueryInfo->type |= TSDB_QUERY_TYPE_STABLE_QUERY; /* * transfer sql functions that need secondary merge into another format * in dealing with metric queries such as: count/first/last @@ -1289,10 +1288,8 @@ SSqlExpr* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t outputIndex, int32_t c index.columnIndex = colIndex - tscGetNumOfColumns(pTableMeta); tscColumnListInsert(pTableMetaInfo->tagColList, &index); - pQueryInfo->type = TSDB_QUERY_TYPE_STABLE_QUERY; } else { index.columnIndex = colIndex; - pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY; } return tscSqlExprAppend(pQueryInfo, functionId, &index, pSchema->type, pSchema->bytes, @@ -1377,7 +1374,7 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pItem) { const char* msg0 = "invalid column name"; - const char* msg1 = "tag for table query is not allowed"; + const char* msg1 = "tag for normal table query is not allowed"; int32_t startPos = tscSqlExprNumOfExprs(pQueryInfo); @@ -1414,7 +1411,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - if (index.columnIndex >= tscGetNumOfColumns(pTableMeta) && UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo)) { + if (index.columnIndex >= tscGetNumOfColumns(pTableMeta) && !UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo)) { return invalidSqlErrMsg(pQueryInfo->msg, msg1); } @@ -5716,12 +5713,16 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { } assert(pQueryInfo->numOfTables == pQuerySql->from->nExpr); + bool isSTable = false; if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { - code = tscGetSTableVgroupInfo(pSql, index); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + isSTable = true; + code = tscGetSTableVgroupInfo(pSql, index); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STABLE_QUERY); } else { TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TABLE_QUERY); } @@ -5731,7 +5732,6 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { return TSDB_CODE_INVALID_SQL; } - bool isSTable = UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo); if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) { return TSDB_CODE_INVALID_SQL; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 6fe76cedce..5a658f6693 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -439,25 +439,6 @@ int tscProcessSql(SSqlObj *pSql) { } else { // local handler return (*tscProcessMsgRsp[pCmd->command])(pSql); } - -// if (QUERY_IS_JOIN_QUERY(type)) { -// if ((pQueryInfo->type & TSDB_QUERY_TYPE_SUBQUERY) == 0) { -// return tscHandleMasterJoinQuery(pSql); -// } else { -// // for first stage sub query, iterate all vnodes to get all timestamp -// if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != TSDB_QUERY_TYPE_JOIN_SEC_STAGE) { -// return doProcessSql(pSql); -// } -// } -// } -// -// if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { // super table query -// tscHandleMasterSTableQuery(pSql); -// return pRes->code; -// } else if (pSql->fp == (void(*)())tscHandleMultivnodeInsert) { // multi-vnodes insertion -// tscHandleMultivnodeInsert(pSql); -// return pRes->code; -// } return doProcessSql(pSql); } diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 7b40d69f1b..856b678391 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -374,7 +374,7 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) { } else { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); - uint16_t type = pQueryInfo->type; + uint32_t type = pQueryInfo->type; taos_free_result_imp(pSql, 1); pRes->numOfRows = 1; pRes->numOfTotal = 0; diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index 267619e782..b84df58383 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -4233,10 +4233,12 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool // normal query setup the queryhandle here - if (isFirstLastRowQuery(pQuery) && !isSTableQuery) { // in case of last_row query, invoke a different API. - pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableIdGroupInfo); - } else if (!isSTableQuery || isIntervalQuery(pQuery) || isFixedOutputQuery(pQuery)) { - pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo); + if (!onlyQueryTags(pQuery)) { + if (!isSTableQuery && isFirstLastRowQuery(pQuery)) { // in case of last_row query, invoke a different API. + pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableIdGroupInfo); + } else if (!isSTableQuery || isIntervalQuery(pQuery) || isFixedOutputQuery(pQuery)) { + pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo); + } } pQInfo->tsdb = tsdb; -- GitLab