plannodes.h 12.4 KB
Newer Older
X
Xiaoyu Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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_PLANN_NODES_H_
#define _TD_PLANN_NODES_H_

#ifdef __cplusplus
extern "C" {
#endif

X
Xiaoyu Wang 已提交
23
#include "query.h"
24
#include "querynodes.h"
X
Xiaoyu Wang 已提交
25
#include "tname.h"
X
Xiaoyu Wang 已提交
26 27

typedef struct SLogicNode {
28 29 30 31
  ENodeType          type;
  SNodeList*         pTargets;  // SColumnNode
  SNode*             pConditions;
  SNodeList*         pChildren;
X
Xiaoyu Wang 已提交
32
  struct SLogicNode* pParent;
33
  int32_t            optimizedFlag;
X
Xiaoyu Wang 已提交
34
  uint8_t            precision;
X
Xiaoyu Wang 已提交
35 36
} SLogicNode;

X
Xiaoyu Wang 已提交
37 38 39 40 41 42 43
typedef enum EScanType {
  SCAN_TYPE_TAG = 1,
  SCAN_TYPE_TABLE,
  SCAN_TYPE_SYSTEM_TABLE,
  SCAN_TYPE_STREAM,
  SCAN_TYPE_TABLE_MERGE
} EScanType;
X
Xiaoyu Wang 已提交
44

X
Xiaoyu Wang 已提交
45
typedef struct SScanLogicNode {
X
Xiaoyu Wang 已提交
46 47 48 49 50
  SLogicNode    node;
  SNodeList*    pScanCols;
  SNodeList*    pScanPseudoCols;
  int8_t        tableType;
  uint64_t      tableId;
X
Xiaoyu Wang 已提交
51
  uint64_t      stableId;
X
Xiaoyu Wang 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
  SVgroupsInfo* pVgroupList;
  EScanType     scanType;
  uint8_t       scanSeq[2];  // first is scan count, and second is reverse scan count
  STimeWindow   scanRange;
  SName         tableName;
  bool          showRewrite;
  double        ratio;
  SNodeList*    pDynamicScanFuncs;
  int32_t       dataRequired;
  int64_t       interval;
  int64_t       offset;
  int64_t       sliding;
  int8_t        intervalUnit;
  int8_t        slidingUnit;
  SNode*        pTagCond;
  int8_t        triggerType;
  int64_t       watermark;
  int16_t       tsColId;
  double        filesFactor;
X
Xiaoyu Wang 已提交
71
  SArray*       pSmaIndexes;
X
Xiaoyu Wang 已提交
72 73 74 75
} SScanLogicNode;

typedef struct SJoinLogicNode {
  SLogicNode node;
76 77
  EJoinType  joinType;
  SNode*     pOnConditions;
X
Xiaoyu Wang 已提交
78
  bool       isSingleTableJoin;
X
Xiaoyu Wang 已提交
79 80 81 82 83 84 85 86 87 88 89
} SJoinLogicNode;

typedef struct SAggLogicNode {
  SLogicNode node;
  SNodeList* pGroupKeys;
  SNodeList* pAggFuncs;
} SAggLogicNode;

typedef struct SProjectLogicNode {
  SLogicNode node;
  SNodeList* pProjections;
90 91 92 93 94
  char       stmtName[TSDB_TABLE_NAME_LEN];
  int64_t    limit;
  int64_t    offset;
  int64_t    slimit;
  int64_t    soffset;
X
Xiaoyu Wang 已提交
95 96
} SProjectLogicNode;

97 98 99 100 101
typedef struct SIndefRowsFuncLogicNode {
  SLogicNode node;
  SNodeList* pVectorFuncs;
} SIndefRowsFuncLogicNode;

X
Xiaoyu Wang 已提交
102 103 104 105 106 107 108 109
typedef enum EModifyTableType { MODIFY_TABLE_TYPE_INSERT = 1, MODIFY_TABLE_TYPE_DELETE } EModifyTableType;

typedef struct SVnodeModifyLogicNode {
  SLogicNode       node;
  EModifyTableType modifyType;
  int32_t          msgType;
  SArray*          pDataBlocks;
  SVgDataBlocks*   pVgDataBlocks;
X
Xiaoyu Wang 已提交
110
  SNode*           pAffectedRows;  // SColumnNode
X
Xiaoyu Wang 已提交
111 112 113 114 115
  uint64_t         tableId;
  int8_t           tableType;  // table type
  char             tableFName[TSDB_TABLE_FNAME_LEN];
  STimeWindow      deleteTimeRange;
} SVnodeModifyLogicNode;
116

X
Xiaoyu Wang 已提交
117 118
typedef struct SExchangeLogicNode {
  SLogicNode node;
119
  int32_t    srcGroupId;
X
Xiaoyu Wang 已提交
120 121
} SExchangeLogicNode;

X
Xiaoyu Wang 已提交
122 123 124
typedef struct SMergeLogicNode {
  SLogicNode node;
  SNodeList* pMergeKeys;
X
Xiaoyu Wang 已提交
125
  SNodeList* pInputs;
X
Xiaoyu Wang 已提交
126 127 128 129
  int32_t    numOfChannels;
  int32_t    srcGroupId;
} SMergeLogicNode;

130
typedef enum EWindowType { WINDOW_TYPE_INTERVAL = 1, WINDOW_TYPE_SESSION, WINDOW_TYPE_STATE } EWindowType;
X
Xiaoyu Wang 已提交
131

X
Xiaoyu Wang 已提交
132 133
typedef enum EIntervalAlgorithm {
  INTERVAL_ALGO_HASH = 1,
X
Xiaoyu Wang 已提交
134
  INTERVAL_ALGO_MERGE,
X
Xiaoyu Wang 已提交
135 136 137 138
  INTERVAL_ALGO_STREAM_FINAL,
  INTERVAL_ALGO_STREAM_SEMI,
  INTERVAL_ALGO_STREAM_SINGLE,
} EIntervalAlgorithm;
139

X
Xiaoyu Wang 已提交
140
typedef struct SWindowLogicNode {
X
Xiaoyu Wang 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  SLogicNode         node;
  EWindowType        winType;
  SNodeList*         pFuncs;
  int64_t            interval;
  int64_t            offset;
  int64_t            sliding;
  int8_t             intervalUnit;
  int8_t             slidingUnit;
  int64_t            sessionGap;
  SNode*             pTspk;
  SNode*             pStateExpr;
  int8_t             triggerType;
  int64_t            watermark;
  double             filesFactor;
  EIntervalAlgorithm intervalAlgo;
X
Xiaoyu Wang 已提交
156 157
} SWindowLogicNode;

X
Xiaoyu Wang 已提交
158
typedef struct SFillLogicNode {
X
Xiaoyu Wang 已提交
159 160 161 162 163
  SLogicNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;
  SNode*      pValues;  // SNodeListNode
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
164 165
} SFillLogicNode;

X
Xiaoyu Wang 已提交
166 167 168 169 170
typedef struct SSortLogicNode {
  SLogicNode node;
  SNodeList* pSortKeys;
} SSortLogicNode;

171 172 173 174 175
typedef struct SPartitionLogicNode {
  SLogicNode node;
  SNodeList* pPartitionKeys;
} SPartitionLogicNode;

176 177 178 179
typedef enum ESubplanType {
  SUBPLAN_TYPE_MERGE = 1,
  SUBPLAN_TYPE_PARTIAL,
  SUBPLAN_TYPE_SCAN,
180 181
  SUBPLAN_TYPE_MODIFY,
  SUBPLAN_TYPE_COMPUTE
182 183
} ESubplanType;

X
Xiaoyu Wang 已提交
184 185
typedef struct SSubplanId {
  uint64_t queryId;
186 187
  int32_t  groupId;
  int32_t  subplanId;
X
Xiaoyu Wang 已提交
188 189
} SSubplanId;

X
Xiaoyu Wang 已提交
190
typedef struct SLogicSubplan {
191 192 193 194 195 196
  ENodeType     type;
  SSubplanId    id;
  SNodeList*    pChildren;
  SNodeList*    pParents;
  SLogicNode*   pNode;
  ESubplanType  subplanType;
X
Xiaoyu Wang 已提交
197
  SVgroupsInfo* pVgroupList;
198 199
  int32_t       level;
  int32_t       splitFlag;
200
  int32_t       numOfComputeNodes;
X
Xiaoyu Wang 已提交
201
} SLogicSubplan;
X
Xiaoyu Wang 已提交
202 203

typedef struct SQueryLogicPlan {
204
  ENodeType  type;
X
Xiaoyu Wang 已提交
205
  SNodeList* pTopSubplans;
X
Xiaoyu Wang 已提交
206 207
} SQueryLogicPlan;

X
Xiaoyu Wang 已提交
208 209
typedef struct SSlotDescNode {
  ENodeType type;
210
  int16_t   slotId;
X
Xiaoyu Wang 已提交
211
  SDataType dataType;
212 213 214
  bool      reserve;
  bool      output;
  bool      tag;
X
Xiaoyu Wang 已提交
215 216
} SSlotDescNode;

X
Xiaoyu Wang 已提交
217
typedef struct SDataBlockDescNode {
218 219
  ENodeType  type;
  int16_t    dataBlockId;
X
Xiaoyu Wang 已提交
220
  SNodeList* pSlots;
221 222 223
  int32_t    totalRowSize;
  int32_t    outputRowSize;
  uint8_t    precision;
X
Xiaoyu Wang 已提交
224
} SDataBlockDescNode;
X
Xiaoyu Wang 已提交
225 226

typedef struct SPhysiNode {
227
  ENodeType           type;
X
Xiaoyu Wang 已提交
228
  SDataBlockDescNode* pOutputDataBlockDesc;
229 230 231
  SNode*              pConditions;
  SNodeList*          pChildren;
  struct SPhysiNode*  pParent;
X
Xiaoyu Wang 已提交
232 233 234
} SPhysiNode;

typedef struct SScanPhysiNode {
X
Xiaoyu Wang 已提交
235
  SPhysiNode node;
X
Xiaoyu Wang 已提交
236
  SNodeList* pScanCols;
237 238
  SNodeList* pScanPseudoCols;
  uint64_t   uid;  // unique id of the table
X
Xiaoyu Wang 已提交
239
  uint64_t   suid;
240 241
  int8_t     tableType;
  SName      tableName;
X
Xiaoyu Wang 已提交
242 243 244 245
} SScanPhysiNode;

typedef SScanPhysiNode STagScanPhysiNode;

X
Xiaoyu Wang 已提交
246 247
typedef struct SSystemTableScanPhysiNode {
  SScanPhysiNode scan;
248 249 250
  SEpSet         mgmtEpSet;
  bool           showRewrite;
  int32_t        accountId;
X
Xiaoyu Wang 已提交
251 252
} SSystemTableScanPhysiNode;

X
Xiaoyu Wang 已提交
253 254
typedef struct STableScanPhysiNode {
  SScanPhysiNode scan;
255 256 257 258 259
  uint8_t        scanSeq[2];  // first is scan count, and second is reverse scan count
  STimeWindow    scanRange;
  double         ratio;
  int32_t        dataRequired;
  SNodeList*     pDynamicScanFuncs;
wmmhello's avatar
wmmhello 已提交
260
  SNodeList*     pPartitionKeys;
261 262 263 264 265
  int64_t        interval;
  int64_t        offset;
  int64_t        sliding;
  int8_t         intervalUnit;
  int8_t         slidingUnit;
5
54liuyao 已提交
266 267 268
  int8_t         triggerType;
  int64_t        watermark;
  int16_t        tsColId;
5
54liuyao 已提交
269
  double         filesFactor;
X
Xiaoyu Wang 已提交
270 271 272
} STableScanPhysiNode;

typedef STableScanPhysiNode STableSeqScanPhysiNode;
X
Xiaoyu Wang 已提交
273
typedef STableScanPhysiNode STableMergeScanPhysiNode;
5
54liuyao 已提交
274
typedef STableScanPhysiNode SStreamScanPhysiNode;
X
Xiaoyu Wang 已提交
275 276 277 278

typedef struct SProjectPhysiNode {
  SPhysiNode node;
  SNodeList* pProjections;
279 280 281 282
  int64_t    limit;
  int64_t    offset;
  int64_t    slimit;
  int64_t    soffset;
X
Xiaoyu Wang 已提交
283 284
} SProjectPhysiNode;

285 286 287 288 289 290
typedef struct SIndefRowsFuncPhysiNode {
  SPhysiNode node;
  SNodeList* pExprs;
  SNodeList* pVectorFuncs;
} SIndefRowsFuncPhysiNode;

X
Xiaoyu Wang 已提交
291 292
typedef struct SJoinPhysiNode {
  SPhysiNode node;
293
  EJoinType  joinType;
X
Xiaoyu Wang 已提交
294
  SNode*     pOnConditions;
X
Xiaoyu Wang 已提交
295 296 297
  SNodeList* pTargets;
} SJoinPhysiNode;

X
Xiaoyu Wang 已提交
298 299
typedef SJoinPhysiNode SSortMergeJoinPhysiNode;

X
Xiaoyu Wang 已提交
300 301
typedef struct SAggPhysiNode {
  SPhysiNode node;
302
  SNodeList* pExprs;  // these are expression list of group_by_clause and parameter expression of aggregate function
X
Xiaoyu Wang 已提交
303
  SNodeList* pGroupKeys;
X
Xiaoyu Wang 已提交
304 305 306
  SNodeList* pAggFuncs;
} SAggPhysiNode;

X
Xiaoyu Wang 已提交
307
typedef struct SDownstreamSourceNode {
308
  ENodeType      type;
X
Xiaoyu Wang 已提交
309
  SQueryNodeAddr addr;
310 311
  uint64_t       taskId;
  uint64_t       schedId;
X
Xiaoyu Wang 已提交
312
} SDownstreamSourceNode;
X
Xiaoyu Wang 已提交
313 314

typedef struct SExchangePhysiNode {
X
Xiaoyu Wang 已提交
315
  SPhysiNode node;
X
Xiaoyu Wang 已提交
316
  int32_t    srcGroupId;  // group id of datasource suplans
D
dapan1121 已提交
317
  bool       singleChannel;
X
Xiaoyu Wang 已提交
318
  SNodeList* pSrcEndPoints;  // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
X
Xiaoyu Wang 已提交
319 320
} SExchangePhysiNode;

X
Xiaoyu Wang 已提交
321 322 323
typedef struct SMergePhysiNode {
  SPhysiNode node;
  SNodeList* pMergeKeys;
X
Xiaoyu Wang 已提交
324
  SNodeList* pTargets;
X
Xiaoyu Wang 已提交
325 326 327 328
  int32_t    numOfChannels;
  int32_t    srcGroupId;
} SMergePhysiNode;

X
Xiaoyu Wang 已提交
329
typedef struct SWinodwPhysiNode {
X
Xiaoyu Wang 已提交
330
  SPhysiNode node;
331
  SNodeList* pExprs;  // these are expression list of parameter expression of function
X
Xiaoyu Wang 已提交
332
  SNodeList* pFuncs;
333 334 335
  SNode*     pTspk;  // timestamp primary key
  int8_t     triggerType;
  int64_t    watermark;
5
54liuyao 已提交
336
  double     filesFactor;
X
Xiaoyu Wang 已提交
337 338 339 340
} SWinodwPhysiNode;

typedef struct SIntervalPhysiNode {
  SWinodwPhysiNode window;
341 342 343 344 345
  int64_t          interval;
  int64_t          offset;
  int64_t          sliding;
  int8_t           intervalUnit;
  int8_t           slidingUnit;
X
Xiaoyu Wang 已提交
346 347
} SIntervalPhysiNode;

X
Xiaoyu Wang 已提交
348
typedef SIntervalPhysiNode SMergeIntervalPhysiNode;
X
Xiaoyu Wang 已提交
349
typedef SIntervalPhysiNode SStreamIntervalPhysiNode;
350 351
typedef SIntervalPhysiNode SStreamFinalIntervalPhysiNode;
typedef SIntervalPhysiNode SStreamSemiIntervalPhysiNode;
X
Xiaoyu Wang 已提交
352

X
Xiaoyu Wang 已提交
353
typedef struct SFillPhysiNode {
X
Xiaoyu Wang 已提交
354 355 356 357 358 359
  SPhysiNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;  // SColumnNode
  SNode*      pValues;    // SNodeListNode
  SNodeList*  pTargets;
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
360 361
} SFillPhysiNode;

362 363
typedef struct SMultiTableIntervalPhysiNode {
  SIntervalPhysiNode interval;
364
  SNodeList*         pPartitionKeys;
365 366
} SMultiTableIntervalPhysiNode;

X
Xiaoyu Wang 已提交
367 368
typedef struct SSessionWinodwPhysiNode {
  SWinodwPhysiNode window;
369
  int64_t          gap;
X
Xiaoyu Wang 已提交
370 371
} SSessionWinodwPhysiNode;

5
54liuyao 已提交
372 373
typedef SSessionWinodwPhysiNode SStreamSessionWinodwPhysiNode;

374 375
typedef struct SStateWinodwPhysiNode {
  SWinodwPhysiNode window;
376
  SNode*           pStateKey;
377 378
} SStateWinodwPhysiNode;

5
54liuyao 已提交
379 380
typedef SStateWinodwPhysiNode SStreamStateWinodwPhysiNode;

X
Xiaoyu Wang 已提交
381 382
typedef struct SSortPhysiNode {
  SPhysiNode node;
383 384
  SNodeList* pExprs;     // these are expression list of order_by_clause and parameter expression of aggregate function
  SNodeList* pSortKeys;  // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
X
Xiaoyu Wang 已提交
385
  SNodeList* pTargets;
X
Xiaoyu Wang 已提交
386 387
} SSortPhysiNode;

388 389
typedef struct SPartitionPhysiNode {
  SPhysiNode node;
390
  SNodeList* pExprs;  // these are expression list of partition_by_clause
391
  SNodeList* pPartitionKeys;
X
Xiaoyu Wang 已提交
392
  SNodeList* pTargets;
393 394
} SPartitionPhysiNode;

X
Xiaoyu Wang 已提交
395
typedef struct SDataSinkNode {
396
  ENodeType           type;
X
Xiaoyu Wang 已提交
397
  SDataBlockDescNode* pInputDataBlockDesc;
X
Xiaoyu Wang 已提交
398 399 400 401 402 403 404 405
} SDataSinkNode;

typedef struct SDataDispatcherNode {
  SDataSinkNode sink;
} SDataDispatcherNode;

typedef struct SDataInserterNode {
  SDataSinkNode sink;
406 407 408
  int32_t       numOfTables;
  uint32_t      size;
  char*         pData;
X
Xiaoyu Wang 已提交
409 410
} SDataInserterNode;

X
Xiaoyu Wang 已提交
411 412 413 414 415 416
typedef struct SDataDeleterNode {
  SDataSinkNode sink;
  uint64_t      tableId;
  int8_t        tableType;  // table type
  char          tableFName[TSDB_TABLE_FNAME_LEN];
  STimeWindow   deleteTimeRange;
X
Xiaoyu Wang 已提交
417
  SNode*        pAffectedRows;
X
Xiaoyu Wang 已提交
418 419
} SDataDeleterNode;

X
Xiaoyu Wang 已提交
420
typedef struct SSubplan {
421 422 423 424 425 426 427 428 429 430 431 432
  ENodeType      type;
  SSubplanId     id;  // unique id of the subplan
  ESubplanType   subplanType;
  int32_t        msgType;  // message type for subplan, used to denote the send message type to vnode.
  int32_t        level;    // the execution level of current subplan, starting from 0 in a top-down manner.
  char           dbFName[TSDB_DB_FNAME_LEN];
  SQueryNodeAddr execNode;      // for the scan/modify subplan, the optional execution node
  SQueryNodeStat execNodeStat;  // only for scan subplan
  SNodeList*     pChildren;     // the datasource subplan,from which to fetch the result
  SNodeList*     pParents;      // the data destination subplan, get data from current subplan
  SPhysiNode*    pNode;         // physical plan of current subplan
  SDataSinkNode* pDataSink;     // data of the subplan flow into the datasink
X
Xiaoyu Wang 已提交
433
  SNode*         pTagCond;
X
Xiaoyu Wang 已提交
434 435
} SSubplan;

436
typedef enum EExplainMode { EXPLAIN_MODE_DISABLE = 1, EXPLAIN_MODE_STATIC, EXPLAIN_MODE_ANALYZE } EExplainMode;
437 438 439

typedef struct SExplainInfo {
  EExplainMode mode;
440 441
  bool         verbose;
  double       ratio;
442
} SExplainInfo;
443

X
Xiaoyu Wang 已提交
444
typedef struct SQueryPlan {
445 446 447 448
  ENodeType    type;
  uint64_t     queryId;
  int32_t      numOfSubplans;
  SNodeList*   pSubplans;  // Element is SNodeListNode. The execution level of subplan, starting from 0.
449
  SExplainInfo explainInfo;
X
Xiaoyu Wang 已提交
450 451
} SQueryPlan;

452 453
void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext);

X
Xiaoyu Wang 已提交
454 455 456 457 458
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANN_NODES_H_*/