From 13f1efd8edc29fb717ba66da3b80fd993cfb8735 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Fri, 17 Apr 2020 22:25:19 +0800 Subject: [PATCH] [td-98] extract the query.h, and add it into the global inc folder --- src/inc/query.h | 97 +++++++++++++++++++++++++++++++++++ src/query/inc/queryExecutor.h | 44 ---------------- src/query/src/queryExecutor.c | 11 +--- src/tsdb/src/tsdbRead.c | 6 +-- src/vnode/src/vnodeRead.c | 4 +- 5 files changed, 102 insertions(+), 60 deletions(-) create mode 100644 src/inc/query.h diff --git a/src/inc/query.h b/src/inc/query.h new file mode 100644 index 0000000000..1d190c03be --- /dev/null +++ b/src/inc/query.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef TDENGINE_QUERY_H +#define TDENGINE_QUERY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "os.h" + +#include "hash.h" +#include "tsdb.h" +#include "qinterpolation.h" +#include "qresultBuf.h" +#include "qsqlparser.h" +#include "qtsbuf.h" +#include "taosdef.h" +#include "tref.h" +#include "tsqlfunction.h" +#include "tarray.h" + +typedef void* qinfo_t; + +/** + * create the qinfo object according to QueryTableMsg + * @param pVnode + * @param pQueryTableMsg + * @param pQInfo + * @return + */ +int32_t qCreateQueryInfo(void* pVnode, SQueryTableMsg* pQueryTableMsg, qinfo_t* pQInfo); + +/** + * Destroy QInfo object + * + * @param pQInfo + * @return + */ +void qDestroyQueryInfo(qinfo_t pQInfo); + +/** + * the main query execution function, including query on both table and multitables, + * which are decided according to the tag or table name query conditions + * + * @param pQInfo + * @return + */ +void qTableQuery(qinfo_t pQInfo); + +/** + * Retrieve the produced results information, if current query is not paused or completed, + * this function will be blocked to wait for the query execution completed or paused, + * in which case enough results have been produced already. + * + * @param pQInfo + * @return + */ +int32_t qRetrieveQueryResultInfo(qinfo_t pQInfo); + +/** + * + * Retrieve the actual results to fill the response message payload. + * Note that this function must be executed after qRetrieveQueryResultInfo is invoked. + * + * @param pQInfo qinfo object + * @param pRsp response message + * @param contLen payload length + * @return + */ +int32_t qDumpRetrieveResult(qinfo_t pQInfo, SRetrieveTableRsp** pRsp, int32_t* contLen); + +/** + * Decide if more results will be produced or not + * + * @param pQInfo + * @return + */ +bool qHasMoreResultsToRetrieve(qinfo_t pQInfo); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_QUERY_H diff --git a/src/query/inc/queryExecutor.h b/src/query/inc/queryExecutor.h index b230b77950..48df8374ab 100644 --- a/src/query/inc/queryExecutor.h +++ b/src/query/inc/queryExecutor.h @@ -109,8 +109,6 @@ typedef struct STableQueryInfo { } STableQueryInfo; typedef struct STableDataInfo { -// int32_t numOfBlocks; -// int32_t start; // start block index int32_t tableIndex; int32_t groupIdx; // group id in table list STableQueryInfo* pTableQInfo; @@ -188,50 +186,8 @@ typedef struct SQInfo { */ int32_t tableIndex; int32_t numOfGroupResultPages; -// STableDataInfo* pTableDataInfo; TSKEY* tsList; } SQInfo; -/** - * create the qinfo object before adding the query task to each tsdb query worker - * - * @param pReadMsg - * @param pQInfo - * @return - */ -int32_t qCreateQueryInfo(void* pVnode, SQueryTableMsg* pQueryTableMsg, SQInfo** pQInfo); - -/** - * destroy the query info struct - * @param pQInfo - */ -void qDestroyQueryInfo(SQInfo* pQInfo); - -/** - * query on single table - * @param pReadMsg - */ -void qTableQuery(SQInfo* pQInfo); - -/** - * wait for the query completed, and retrieve final results to client - * @param pQInfo - */ -int32_t qRetrieveQueryResultInfo(SQInfo* pQInfo); - -/** - * - * @param pQInfo - * @param pRsp - * @return - */ -int32_t qDumpRetrieveResult(SQInfo *pQInfo, SRetrieveTableRsp** pRsp, int32_t* contLen); - -/** - * - * @param pQInfo - * @return - */ -bool qHasMoreResultsToRetrieve(SQInfo* pQInfo); #endif // TDENGINE_QUERYEXECUTOR_H diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index fc61d98291..1e54496682 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include +#include "tsdbMain.h" //todo use TableId instead of STable object #include "os.h" #include "hash.h" @@ -28,7 +28,6 @@ #include "qresultBuf.h" #include "queryExecutor.h" #include "queryUtil.h" -#include "tsdb.h" #define DEFAULT_INTERN_BUF_SIZE 16384L @@ -4754,14 +4753,6 @@ static void createTableDataInfo(SQInfo* pQInfo) { SQuery* pQuery = pQInfo->runtimeEnv.pQuery; // todo make sure the table are added the reference count to gauranteed that all involved tables are valid -// if (pQInfo->pTableDataInfo == NULL) { -// pQInfo->pTableDataInfo = (STableDataInfo *)calloc(1, sizeof(STableDataInfo) * pQInfo->groupInfo.numOfTables); -// if (pQInfo->pTableDataInfo == NULL) { -// dError("QInfo:%p failed to allocate memory, %s", pQInfo, strerror(errno)); -// pQInfo->code = -TSDB_CODE_SERV_OUT_OF_MEMORY; -// return; -// } - size_t numOfGroups = taosArrayGetSize(pQInfo->groupInfo.pGroupList); int32_t index = 0; for (int32_t i = 0; i < numOfGroups; ++i) { // load all meter meta info diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 89cbdf7608..59225a211c 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -20,10 +20,8 @@ #include "tutil.h" #include "tcompare.h" -#include "../../../query/inc/qast.h" -#include "../../../query/inc/qextbuffer.h" -#include "../../../query/inc/tlosertree.h" -#include "../../../query/inc/tsqlfunction.h" +#include "../../../query/inc/qast.h" // todo move to common module +#include "../../../query/inc/tlosertree.h" // todo move to util module #include "tsdb.h" #include "tsdbMain.h" diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index 59f392eb82..7fcd02a102 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -25,7 +25,7 @@ #include "dataformat.h" #include "vnode.h" #include "vnodeInt.h" -#include "queryExecutor.h" +#include "query.h" static int32_t (*vnodeProcessReadMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *, void *pCont, int32_t contLen, SRspRet *pRet); static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t contLen, SRspRet *pRet); @@ -54,7 +54,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t cont int32_t code = TSDB_CODE_SUCCESS; - SQInfo* pQInfo = NULL; + qinfo_t pQInfo = NULL; if (contLen != 0) { void* tsdb = vnodeGetTsdb(pVnode); pRet->code = qCreateQueryInfo(tsdb, pQueryTableMsg, &pQInfo); -- GitLab