2021-09-24 10:05:56 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
|
|
|
*
|
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _TD_EXECUTOR_H_
|
|
|
|
|
#define _TD_EXECUTOR_H_
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-10 11:05:58 +00:00
|
|
|
#include "query.h"
|
2022-03-29 07:24:25 +00:00
|
|
|
#include "tcommon.h"
|
2022-05-07 12:19:40 +00:00
|
|
|
#include "tmsgcb.h"
|
2022-01-18 06:12:25 +00:00
|
|
|
|
2022-01-08 08:28:44 +00:00
|
|
|
typedef void* qTaskInfo_t;
|
2022-01-11 02:51:23 +00:00
|
|
|
typedef void* DataSinkHandle;
|
2022-01-25 07:18:56 +00:00
|
|
|
struct SRpcMsg;
|
2022-01-11 02:51:23 +00:00
|
|
|
struct SSubplan;
|
|
|
|
|
|
2022-09-28 02:38:49 +00:00
|
|
|
typedef int32_t (*localFetchFp)(void*, uint64_t, uint64_t, uint64_t, int64_t, int32_t, void**, SArray*);
|
2022-09-09 11:03:42 +00:00
|
|
|
|
|
|
|
|
typedef struct {
|
2022-09-28 02:38:49 +00:00
|
|
|
void* handle;
|
2022-09-15 08:30:21 +00:00
|
|
|
bool localExec;
|
2022-09-09 11:03:42 +00:00
|
|
|
localFetchFp fp;
|
2022-09-28 02:38:49 +00:00
|
|
|
SArray* explainRes;
|
2022-09-09 11:03:42 +00:00
|
|
|
} SLocalFetch;
|
|
|
|
|
|
2022-08-23 11:25:17 +00:00
|
|
|
typedef struct {
|
2022-07-07 09:16:12 +00:00
|
|
|
void* tqReader;
|
2022-05-07 12:19:40 +00:00
|
|
|
void* meta;
|
|
|
|
|
void* config;
|
|
|
|
|
void* vnode;
|
|
|
|
|
void* mnd;
|
|
|
|
|
SMsgCb* pMsgCb;
|
2022-07-10 08:34:45 +00:00
|
|
|
int64_t version;
|
2022-07-06 06:20:07 +00:00
|
|
|
bool initMetaReader;
|
|
|
|
|
bool initTableReader;
|
2022-07-07 09:16:12 +00:00
|
|
|
bool initTqReader;
|
2022-07-19 06:17:53 +00:00
|
|
|
int32_t numOfVgroups;
|
2022-08-04 07:01:59 +00:00
|
|
|
|
2022-09-28 02:38:49 +00:00
|
|
|
void* sContext; // SSnapContext*
|
2022-08-05 13:12:18 +00:00
|
|
|
|
2022-09-28 02:38:49 +00:00
|
|
|
void* pStateBackend;
|
2022-01-28 02:44:02 +00:00
|
|
|
} SReadHandle;
|
2022-02-17 10:37:43 +00:00
|
|
|
|
2022-07-12 06:10:22 +00:00
|
|
|
// in queue mode, data streams are seperated by msg
|
2022-03-30 06:54:00 +00:00
|
|
|
typedef enum {
|
2022-05-18 08:13:58 +00:00
|
|
|
OPTR_EXEC_MODEL_BATCH = 0x1,
|
2022-03-30 06:54:00 +00:00
|
|
|
OPTR_EXEC_MODEL_STREAM = 0x2,
|
2022-07-12 06:10:22 +00:00
|
|
|
OPTR_EXEC_MODEL_QUEUE = 0x3,
|
2022-03-30 06:54:00 +00:00
|
|
|
} EOPTR_EXEC_MODEL;
|
|
|
|
|
|
2022-03-22 10:00:03 +00:00
|
|
|
/**
|
2022-07-12 06:10:22 +00:00
|
|
|
* Create the exec task for stream mode
|
2022-03-22 10:00:03 +00:00
|
|
|
* @param pMsg
|
2022-07-12 06:10:22 +00:00
|
|
|
* @param SReadHandle
|
2022-03-22 10:00:03 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-07-07 09:16:12 +00:00
|
|
|
qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers);
|
2022-01-21 06:21:13 +00:00
|
|
|
|
2022-06-23 05:35:24 +00:00
|
|
|
/**
|
2022-07-12 06:10:22 +00:00
|
|
|
* Create the exec task for queue mode
|
|
|
|
|
* @param pMsg
|
|
|
|
|
* @param SReadHandle
|
2022-06-23 05:35:24 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-07-27 08:55:23 +00:00
|
|
|
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema);
|
2022-06-23 05:35:24 +00:00
|
|
|
|
2022-11-01 03:56:14 +00:00
|
|
|
int32_t qSetStreamOpOpen(qTaskInfo_t tinfo);
|
2022-03-29 05:31:17 +00:00
|
|
|
/**
|
|
|
|
|
* Set multiple input data blocks for the stream scan.
|
|
|
|
|
* @param tinfo
|
|
|
|
|
* @param pBlocks
|
|
|
|
|
* @param numOfInputBlock
|
|
|
|
|
* @param type
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-07-27 08:55:23 +00:00
|
|
|
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type);
|
2022-03-29 05:31:17 +00:00
|
|
|
|
2022-10-27 03:06:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set block for sma
|
|
|
|
|
* @param tinfo
|
|
|
|
|
* @param pBlocks
|
|
|
|
|
* @param numOfInputBlock
|
|
|
|
|
* @param type
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type);
|
|
|
|
|
|
2022-02-17 10:37:43 +00:00
|
|
|
/**
|
|
|
|
|
* Update the table id list, add or remove.
|
|
|
|
|
*
|
|
|
|
|
* @param tinfo
|
|
|
|
|
* @param id
|
|
|
|
|
* @param isAdd
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-05-18 08:13:58 +00:00
|
|
|
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd);
|
2022-02-17 10:37:43 +00:00
|
|
|
|
2022-03-22 10:00:03 +00:00
|
|
|
/**
|
|
|
|
|
* Create the exec task object according to task json
|
|
|
|
|
* @param readHandle
|
|
|
|
|
* @param vgId
|
|
|
|
|
* @param pTaskInfoMsg
|
|
|
|
|
* @param pTaskInfo
|
|
|
|
|
* @param qId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan,
|
2022-08-06 10:00:26 +00:00
|
|
|
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, char* sql, EOPTR_EXEC_MODEL model);
|
2021-10-06 15:34:38 +00:00
|
|
|
|
2022-05-18 12:39:00 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param tinfo
|
|
|
|
|
* @param sversion
|
|
|
|
|
* @param tversion
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-07-10 09:34:21 +00:00
|
|
|
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion,
|
2022-07-12 06:10:22 +00:00
|
|
|
int32_t* tversion);
|
2022-05-18 12:39:00 +00:00
|
|
|
|
2021-10-06 15:34:38 +00:00
|
|
|
/**
|
2022-01-11 02:51:23 +00:00
|
|
|
* The main task execution function, including query on both table and multiple tables,
|
2021-10-06 15:34:38 +00:00
|
|
|
* which are decided according to the tag or table name query conditions
|
|
|
|
|
*
|
2022-01-11 02:51:23 +00:00
|
|
|
* @param tinfo
|
|
|
|
|
* @param handle
|
2021-10-06 15:34:38 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-09-28 12:27:09 +00:00
|
|
|
|
2022-10-09 08:54:27 +00:00
|
|
|
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal);
|
2022-08-09 05:55:51 +00:00
|
|
|
int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pBlock, uint64_t* useconds);
|
2021-10-06 15:34:38 +00:00
|
|
|
|
2022-01-20 11:34:46 +00:00
|
|
|
/**
|
|
|
|
|
* kill the ongoing query asynchronously
|
2022-01-21 07:16:17 +00:00
|
|
|
* @param tinfo qhandle
|
2022-01-20 11:34:46 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-01-21 07:16:17 +00:00
|
|
|
int32_t qAsyncKillTask(qTaskInfo_t tinfo);
|
2022-01-20 11:34:46 +00:00
|
|
|
|
2021-10-06 15:34:38 +00:00
|
|
|
/**
|
|
|
|
|
* destroy query info structure
|
|
|
|
|
* @param qHandle
|
|
|
|
|
*/
|
2022-01-21 07:16:17 +00:00
|
|
|
void qDestroyTask(qTaskInfo_t tinfo);
|
2021-10-06 15:34:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the queried table uid
|
|
|
|
|
* @param qHandle
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-01-21 07:16:17 +00:00
|
|
|
int64_t qGetQueriedTableUid(qTaskInfo_t tinfo);
|
2021-10-06 15:34:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract the qualified table id list, and than pass them to the TSDB driver to load the required table data blocks.
|
|
|
|
|
*
|
|
|
|
|
* @param iter the table iterator to traverse all tables belongs to a super table, or an invert index
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t tagCondLen, SArray* pTableIdList);
|
|
|
|
|
|
2022-07-06 08:29:51 +00:00
|
|
|
void qProcessRspMsg(void* parent, struct SRpcMsg* pMsg, struct SEpSet* pEpSet);
|
2022-01-25 07:18:56 +00:00
|
|
|
|
2022-08-23 11:25:17 +00:00
|
|
|
int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, SArray* pExecInfoList /*,int32_t* resNum, SExplainExecInfo** pRes*/);
|
2022-04-01 11:45:45 +00:00
|
|
|
|
2022-06-17 12:09:49 +00:00
|
|
|
int32_t qSerializeTaskStatus(qTaskInfo_t tinfo, char** pOutput, int32_t* len);
|
|
|
|
|
|
|
|
|
|
int32_t qDeserializeTaskStatus(qTaskInfo_t tinfo, const char* pInput, int32_t len);
|
|
|
|
|
|
2022-10-25 16:31:00 +00:00
|
|
|
STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key);
|
2022-06-29 08:19:19 +00:00
|
|
|
/**
|
|
|
|
|
* return the scan info, in the form of tuple of two items, including table uid and current timestamp
|
|
|
|
|
* @param tinfo
|
|
|
|
|
* @param uid
|
|
|
|
|
* @param ts
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
int32_t qGetStreamScanStatus(qTaskInfo_t tinfo, uint64_t* uid, int64_t* ts);
|
|
|
|
|
|
2022-07-08 09:48:34 +00:00
|
|
|
int32_t qStreamPrepareTsdbScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts);
|
|
|
|
|
|
2022-08-04 07:01:59 +00:00
|
|
|
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType);
|
2022-07-08 09:48:34 +00:00
|
|
|
|
2022-09-28 02:38:49 +00:00
|
|
|
int32_t qStreamScanMemData(qTaskInfo_t tinfo, const SSubmitReq* pReq);
|
|
|
|
|
|
2022-07-08 09:48:34 +00:00
|
|
|
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
|
|
|
|
|
|
2022-08-05 13:12:18 +00:00
|
|
|
SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
|
2022-06-30 06:41:50 +00:00
|
|
|
|
2022-08-09 11:06:24 +00:00
|
|
|
int64_t qStreamExtractPrepareUid(qTaskInfo_t tinfo);
|
|
|
|
|
|
|
|
|
|
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo);
|
|
|
|
|
|
|
|
|
|
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
|
|
|
|
|
|
2022-07-13 08:37:33 +00:00
|
|
|
void* qExtractReaderFromStreamScanner(void* scanner);
|
|
|
|
|
|
2022-07-07 09:16:12 +00:00
|
|
|
int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
|
|
|
|
|
|
2022-07-13 08:37:33 +00:00
|
|
|
int32_t qStreamInput(qTaskInfo_t tinfo, void* pItem);
|
|
|
|
|
|
2022-10-25 16:31:00 +00:00
|
|
|
int32_t qStreamSetParamForRecover(qTaskInfo_t tinfo);
|
|
|
|
|
int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver);
|
|
|
|
|
int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver);
|
|
|
|
|
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo);
|
|
|
|
|
int32_t qStreamRestoreParam(qTaskInfo_t tinfo);
|
2022-07-22 13:16:52 +00:00
|
|
|
|
2021-09-24 10:05:56 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-01-21 05:45:24 +00:00
|
|
|
#endif /*_TD_EXECUTOR_H_*/
|