TDengine/include/libs/executor/executor.h

235 lines
6.6 KiB
C
Raw Normal View History

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"
#include "tmsgcb.h"
#include "storageapi.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;
2023-04-08 17:39:09 +00:00
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;
typedef struct {
void* tqReader; // todo remove it
void* vnode;
void* mnd;
SMsgCb* pMsgCb;
int64_t version;
uint64_t checkpointId;
bool initTableReader;
bool initTqReader;
2023-11-07 11:59:05 +00:00
bool skipRollup;
int32_t numOfVgroups;
void* sContext; // SSnapContext*
void* pStateBackend;
int8_t fillHistory;
STimeWindow winRange;
struct SStorageAPI api;
2024-06-24 10:28:56 +00:00
void* pWorkerCb;
2022-01-28 02:44:02 +00:00
} SReadHandle;
2022-07-12 06:10:22 +00:00
// in queue mode, data streams are seperated by msg
typedef enum {
OPTR_EXEC_MODEL_BATCH = 0x1,
OPTR_EXEC_MODEL_STREAM = 0x2,
2022-07-12 06:10:22 +00:00
OPTR_EXEC_MODEL_QUEUE = 0x3,
} 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
2023-03-19 02:49:30 +00:00
* @param vgId
2022-03-22 10:00:03 +00:00
* @return
*/
2024-09-13 15:04:41 +00:00
int32_t qCreateStreamExecTaskInfo(qTaskInfo_t* pInfo, void* msg, SReadHandle* readers, int32_t vgId, int32_t taskId);
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
*/
2023-04-04 06:50:58 +00:00
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* pReaderHandle, int32_t vgId, int32_t* numOfCols,
uint64_t id);
2022-06-23 05:35:24 +00:00
2023-05-29 09:25:11 +00:00
int32_t qGetTableList(int64_t suid, void* pVnode, void* node, SArray **tableList, void* pTaskInfo);
2023-03-19 11:06:28 +00:00
/**
* set the task Id, usually used by message queue process
* @param tinfo
* @param taskId
* @param queryId
*/
2024-09-13 15:04:41 +00:00
int32_t qSetTaskId(qTaskInfo_t tinfo, uint64_t taskId, uint64_t queryId);
2022-06-23 05:35:24 +00:00
2022-11-01 03:56:14 +00:00
int32_t qSetStreamOpOpen(qTaskInfo_t tinfo);
2023-03-29 11:35:04 +00:00
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);
/**
* Update the table id list, add or remove.
*
* @param tinfo
* @param id
* @param isAdd
* @return
*/
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd);
bool qIsDynamicExecTask(qTaskInfo_t tinfo);
void qUpdateOperatorParam(qTaskInfo_t tinfo, void* pParam);
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* pSubplan,
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, int8_t compressResult, char* sql,
EOPTR_EXEC_MODEL model);
2021-10-06 15:34:38 +00:00
/**
*
* @param tinfo
* @param sversion
* @param tversion
* @return
*/
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, int32_t dbNameBuffLen, char* tableName,
int32_t tbaleNameBuffLen, int32_t* sversion, int32_t* tversion, int32_t idx,
bool* tbGet);
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
*/
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal);
2022-11-27 06:57:44 +00:00
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
2024-09-08 06:54:08 +00:00
void qResetTaskCode(qTaskInfo_t tinfo);
2022-11-27 06:57:44 +00:00
void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo);
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-11-29 08:17:05 +00:00
int32_t qAsyncKillTask(qTaskInfo_t tinfo, int32_t rspCode);
2023-04-08 17:39:09 +00:00
int32_t qKillTask(qTaskInfo_t tinfo, int32_t rspCode);
2022-01-20 11:34:46 +00:00
bool qTaskIsExecuting(qTaskInfo_t qinfo);
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
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
2023-11-03 01:30:50 +00:00
int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, SArray* pExecInfoList);
void getNextTimeWindow(const SInterval* pInterval, STimeWindow* tw, int32_t order);
void getInitialStartTimeWindow(SInterval* pInterval, TSKEY ts, STimeWindow* w, bool ascQuery);
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key);
2023-04-08 17:39:09 +00:00
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo);
2022-07-08 09:48:34 +00:00
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType);
2022-07-08 09:48:34 +00:00
void qStreamSetOpen(qTaskInfo_t tinfo);
void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded);
2024-07-29 02:29:40 +00:00
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
2022-07-08 09:48:34 +00:00
2024-05-23 09:35:54 +00:00
SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
2022-06-30 06:41:50 +00:00
2022-08-09 11:06:24 +00:00
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo);
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
2022-08-09 11:06:24 +00:00
2022-07-13 08:37:33 +00:00
void* qExtractReaderFromStreamScanner(void* scanner);
void qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
2022-07-07 09:16:12 +00:00
int32_t qSetStreamOperatorOptionForScanHistory(qTaskInfo_t tinfo);
2023-06-19 09:28:19 +00:00
int32_t qStreamSourceScanParamForHistoryScanStep1(qTaskInfo_t tinfo, SVersionRange *pVerRange, STimeWindow* pWindow);
int32_t qStreamSourceScanParamForHistoryScanStep2(qTaskInfo_t tinfo, SVersionRange *pVerRange, STimeWindow* pWindow);
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo);
bool qStreamScanhistoryFinished(qTaskInfo_t tinfo);
2023-07-31 07:24:35 +00:00
int32_t qStreamInfoResetTimewindowFilter(qTaskInfo_t tinfo);
2023-03-07 05:34:17 +00:00
void resetTaskInfo(qTaskInfo_t tinfo);
2022-07-22 13:16:52 +00:00
2023-06-15 06:13:17 +00:00
int32_t qStreamOperatorReleaseState(qTaskInfo_t tInfo);
int32_t qStreamOperatorReloadState(qTaskInfo_t tInfo);
2021-09-24 10:05:56 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_EXECUTOR_H_*/