plannodes.h 12.2 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;

37
typedef enum EScanType { SCAN_TYPE_TAG = 1, SCAN_TYPE_TABLE, SCAN_TYPE_SYSTEM_TABLE, SCAN_TYPE_STREAM } EScanType;
X
Xiaoyu Wang 已提交
38

X
Xiaoyu Wang 已提交
39
typedef struct SScanLogicNode {
X
Xiaoyu Wang 已提交
40 41 42 43 44
  SLogicNode    node;
  SNodeList*    pScanCols;
  SNodeList*    pScanPseudoCols;
  int8_t        tableType;
  uint64_t      tableId;
X
Xiaoyu Wang 已提交
45
  uint64_t      stableId;
X
Xiaoyu Wang 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  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 已提交
65 66 67 68
} SScanLogicNode;

typedef struct SJoinLogicNode {
  SLogicNode node;
69 70
  EJoinType  joinType;
  SNode*     pOnConditions;
X
Xiaoyu Wang 已提交
71
  bool       isSingleTableJoin;
X
Xiaoyu Wang 已提交
72 73 74 75 76 77 78 79 80 81 82
} SJoinLogicNode;

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

typedef struct SProjectLogicNode {
  SLogicNode node;
  SNodeList* pProjections;
83 84 85 86 87
  char       stmtName[TSDB_TABLE_NAME_LEN];
  int64_t    limit;
  int64_t    offset;
  int64_t    slimit;
  int64_t    soffset;
X
Xiaoyu Wang 已提交
88 89
} SProjectLogicNode;

90 91 92 93 94
typedef struct SIndefRowsFuncLogicNode {
  SLogicNode node;
  SNodeList* pVectorFuncs;
} SIndefRowsFuncLogicNode;

X
Xiaoyu Wang 已提交
95 96 97 98 99 100 101 102
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 已提交
103
  SNode*           pAffectedRows;  // SColumnNode
X
Xiaoyu Wang 已提交
104 105 106 107 108
  uint64_t         tableId;
  int8_t           tableType;  // table type
  char             tableFName[TSDB_TABLE_FNAME_LEN];
  STimeWindow      deleteTimeRange;
} SVnodeModifyLogicNode;
109

X
Xiaoyu Wang 已提交
110 111
typedef struct SExchangeLogicNode {
  SLogicNode node;
112
  int32_t    srcGroupId;
X
Xiaoyu Wang 已提交
113 114
} SExchangeLogicNode;

X
Xiaoyu Wang 已提交
115 116 117
typedef struct SMergeLogicNode {
  SLogicNode node;
  SNodeList* pMergeKeys;
X
Xiaoyu Wang 已提交
118
  SNodeList* pInputs;
X
Xiaoyu Wang 已提交
119 120 121 122
  int32_t    numOfChannels;
  int32_t    srcGroupId;
} SMergeLogicNode;

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

X
Xiaoyu Wang 已提交
125 126
typedef enum EIntervalAlgorithm {
  INTERVAL_ALGO_HASH = 1,
X
Xiaoyu Wang 已提交
127
  INTERVAL_ALGO_MERGE,
X
Xiaoyu Wang 已提交
128 129 130 131
  INTERVAL_ALGO_STREAM_FINAL,
  INTERVAL_ALGO_STREAM_SEMI,
  INTERVAL_ALGO_STREAM_SINGLE,
} EIntervalAlgorithm;
132

X
Xiaoyu Wang 已提交
133
typedef struct SWindowLogicNode {
X
Xiaoyu Wang 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  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 已提交
149 150
} SWindowLogicNode;

X
Xiaoyu Wang 已提交
151
typedef struct SFillLogicNode {
X
Xiaoyu Wang 已提交
152 153 154 155 156
  SLogicNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;
  SNode*      pValues;  // SNodeListNode
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
157 158
} SFillLogicNode;

X
Xiaoyu Wang 已提交
159 160 161 162 163
typedef struct SSortLogicNode {
  SLogicNode node;
  SNodeList* pSortKeys;
} SSortLogicNode;

164 165 166 167 168
typedef struct SPartitionLogicNode {
  SLogicNode node;
  SNodeList* pPartitionKeys;
} SPartitionLogicNode;

169 170 171 172 173 174 175
typedef enum ESubplanType {
  SUBPLAN_TYPE_MERGE = 1,
  SUBPLAN_TYPE_PARTIAL,
  SUBPLAN_TYPE_SCAN,
  SUBPLAN_TYPE_MODIFY
} ESubplanType;

X
Xiaoyu Wang 已提交
176 177
typedef struct SSubplanId {
  uint64_t queryId;
178 179
  int32_t  groupId;
  int32_t  subplanId;
X
Xiaoyu Wang 已提交
180 181
} SSubplanId;

X
Xiaoyu Wang 已提交
182
typedef struct SLogicSubplan {
183 184 185 186 187 188
  ENodeType     type;
  SSubplanId    id;
  SNodeList*    pChildren;
  SNodeList*    pParents;
  SLogicNode*   pNode;
  ESubplanType  subplanType;
X
Xiaoyu Wang 已提交
189
  SVgroupsInfo* pVgroupList;
190 191
  int32_t       level;
  int32_t       splitFlag;
X
Xiaoyu Wang 已提交
192
} SLogicSubplan;
X
Xiaoyu Wang 已提交
193 194

typedef struct SQueryLogicPlan {
195
  ENodeType  type;
X
Xiaoyu Wang 已提交
196
  SNodeList* pTopSubplans;
X
Xiaoyu Wang 已提交
197 198
} SQueryLogicPlan;

X
Xiaoyu Wang 已提交
199 200
typedef struct SSlotDescNode {
  ENodeType type;
201
  int16_t   slotId;
X
Xiaoyu Wang 已提交
202
  SDataType dataType;
203 204 205
  bool      reserve;
  bool      output;
  bool      tag;
X
Xiaoyu Wang 已提交
206 207
} SSlotDescNode;

X
Xiaoyu Wang 已提交
208
typedef struct SDataBlockDescNode {
209 210
  ENodeType  type;
  int16_t    dataBlockId;
X
Xiaoyu Wang 已提交
211
  SNodeList* pSlots;
212 213 214
  int32_t    totalRowSize;
  int32_t    outputRowSize;
  uint8_t    precision;
X
Xiaoyu Wang 已提交
215
} SDataBlockDescNode;
X
Xiaoyu Wang 已提交
216 217

typedef struct SPhysiNode {
218
  ENodeType           type;
X
Xiaoyu Wang 已提交
219
  SDataBlockDescNode* pOutputDataBlockDesc;
220 221 222
  SNode*              pConditions;
  SNodeList*          pChildren;
  struct SPhysiNode*  pParent;
X
Xiaoyu Wang 已提交
223 224 225
} SPhysiNode;

typedef struct SScanPhysiNode {
X
Xiaoyu Wang 已提交
226
  SPhysiNode node;
X
Xiaoyu Wang 已提交
227
  SNodeList* pScanCols;
228 229
  SNodeList* pScanPseudoCols;
  uint64_t   uid;  // unique id of the table
X
Xiaoyu Wang 已提交
230
  uint64_t   suid;
231 232
  int8_t     tableType;
  SName      tableName;
X
Xiaoyu Wang 已提交
233 234 235 236
} SScanPhysiNode;

typedef SScanPhysiNode STagScanPhysiNode;

X
Xiaoyu Wang 已提交
237 238
typedef struct SSystemTableScanPhysiNode {
  SScanPhysiNode scan;
239 240 241
  SEpSet         mgmtEpSet;
  bool           showRewrite;
  int32_t        accountId;
X
Xiaoyu Wang 已提交
242 243
} SSystemTableScanPhysiNode;

X
Xiaoyu Wang 已提交
244 245
typedef struct STableScanPhysiNode {
  SScanPhysiNode scan;
246 247 248 249 250
  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 已提交
251
  SNodeList*     pPartitionKeys;
252 253 254 255 256
  int64_t        interval;
  int64_t        offset;
  int64_t        sliding;
  int8_t         intervalUnit;
  int8_t         slidingUnit;
5
54liuyao 已提交
257 258 259
  int8_t         triggerType;
  int64_t        watermark;
  int16_t        tsColId;
5
54liuyao 已提交
260
  double         filesFactor;
X
Xiaoyu Wang 已提交
261 262 263
} STableScanPhysiNode;

typedef STableScanPhysiNode STableSeqScanPhysiNode;
5
54liuyao 已提交
264
typedef STableScanPhysiNode SStreamScanPhysiNode;
X
Xiaoyu Wang 已提交
265 266 267 268

typedef struct SProjectPhysiNode {
  SPhysiNode node;
  SNodeList* pProjections;
269 270 271 272
  int64_t    limit;
  int64_t    offset;
  int64_t    slimit;
  int64_t    soffset;
X
Xiaoyu Wang 已提交
273 274
} SProjectPhysiNode;

275 276 277 278 279 280
typedef struct SIndefRowsFuncPhysiNode {
  SPhysiNode node;
  SNodeList* pExprs;
  SNodeList* pVectorFuncs;
} SIndefRowsFuncPhysiNode;

X
Xiaoyu Wang 已提交
281 282
typedef struct SJoinPhysiNode {
  SPhysiNode node;
283
  EJoinType  joinType;
X
Xiaoyu Wang 已提交
284
  SNode*     pOnConditions;
X
Xiaoyu Wang 已提交
285 286 287
  SNodeList* pTargets;
} SJoinPhysiNode;

X
Xiaoyu Wang 已提交
288 289
typedef SJoinPhysiNode SSortMergeJoinPhysiNode;

X
Xiaoyu Wang 已提交
290 291
typedef struct SAggPhysiNode {
  SPhysiNode node;
292
  SNodeList* pExprs;  // these are expression list of group_by_clause and parameter expression of aggregate function
X
Xiaoyu Wang 已提交
293
  SNodeList* pGroupKeys;
X
Xiaoyu Wang 已提交
294 295 296
  SNodeList* pAggFuncs;
} SAggPhysiNode;

X
Xiaoyu Wang 已提交
297
typedef struct SDownstreamSourceNode {
298
  ENodeType      type;
X
Xiaoyu Wang 已提交
299
  SQueryNodeAddr addr;
300 301
  uint64_t       taskId;
  uint64_t       schedId;
X
Xiaoyu Wang 已提交
302
} SDownstreamSourceNode;
X
Xiaoyu Wang 已提交
303 304

typedef struct SExchangePhysiNode {
X
Xiaoyu Wang 已提交
305
  SPhysiNode node;
306
  int32_t    srcGroupId;     // group id of datasource suplans
D
dapan1121 已提交
307
  bool       singleChannel;
X
Xiaoyu Wang 已提交
308
  SNodeList* pSrcEndPoints;  // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
X
Xiaoyu Wang 已提交
309 310
} SExchangePhysiNode;

X
Xiaoyu Wang 已提交
311 312 313
typedef struct SMergePhysiNode {
  SPhysiNode node;
  SNodeList* pMergeKeys;
X
Xiaoyu Wang 已提交
314
  SNodeList* pTargets;
X
Xiaoyu Wang 已提交
315 316 317 318
  int32_t    numOfChannels;
  int32_t    srcGroupId;
} SMergePhysiNode;

X
Xiaoyu Wang 已提交
319
typedef struct SWinodwPhysiNode {
X
Xiaoyu Wang 已提交
320
  SPhysiNode node;
321
  SNodeList* pExprs;  // these are expression list of parameter expression of function
X
Xiaoyu Wang 已提交
322
  SNodeList* pFuncs;
323 324 325
  SNode*     pTspk;  // timestamp primary key
  int8_t     triggerType;
  int64_t    watermark;
5
54liuyao 已提交
326
  double     filesFactor;
X
Xiaoyu Wang 已提交
327 328 329 330
} SWinodwPhysiNode;

typedef struct SIntervalPhysiNode {
  SWinodwPhysiNode window;
331 332 333 334 335
  int64_t          interval;
  int64_t          offset;
  int64_t          sliding;
  int8_t           intervalUnit;
  int8_t           slidingUnit;
X
Xiaoyu Wang 已提交
336 337
} SIntervalPhysiNode;

X
Xiaoyu Wang 已提交
338
typedef SIntervalPhysiNode SMergeIntervalPhysiNode;
X
Xiaoyu Wang 已提交
339
typedef SIntervalPhysiNode SStreamIntervalPhysiNode;
340 341
typedef SIntervalPhysiNode SStreamFinalIntervalPhysiNode;
typedef SIntervalPhysiNode SStreamSemiIntervalPhysiNode;
X
Xiaoyu Wang 已提交
342

X
Xiaoyu Wang 已提交
343
typedef struct SFillPhysiNode {
X
Xiaoyu Wang 已提交
344 345 346 347 348 349
  SPhysiNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;  // SColumnNode
  SNode*      pValues;    // SNodeListNode
  SNodeList*  pTargets;
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
350 351
} SFillPhysiNode;

352 353
typedef struct SMultiTableIntervalPhysiNode {
  SIntervalPhysiNode interval;
354
  SNodeList*         pPartitionKeys;
355 356
} SMultiTableIntervalPhysiNode;

X
Xiaoyu Wang 已提交
357 358
typedef struct SSessionWinodwPhysiNode {
  SWinodwPhysiNode window;
359
  int64_t          gap;
X
Xiaoyu Wang 已提交
360 361
} SSessionWinodwPhysiNode;

5
54liuyao 已提交
362 363
typedef SSessionWinodwPhysiNode SStreamSessionWinodwPhysiNode;

364 365
typedef struct SStateWinodwPhysiNode {
  SWinodwPhysiNode window;
366
  SNode*           pStateKey;
367 368
} SStateWinodwPhysiNode;

5
54liuyao 已提交
369 370
typedef SStateWinodwPhysiNode SStreamStateWinodwPhysiNode;

X
Xiaoyu Wang 已提交
371 372
typedef struct SSortPhysiNode {
  SPhysiNode node;
373 374
  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 已提交
375
  SNodeList* pTargets;
X
Xiaoyu Wang 已提交
376 377
} SSortPhysiNode;

378 379
typedef struct SPartitionPhysiNode {
  SPhysiNode node;
380
  SNodeList* pExprs;  // these are expression list of partition_by_clause
381
  SNodeList* pPartitionKeys;
X
Xiaoyu Wang 已提交
382
  SNodeList* pTargets;
383 384
} SPartitionPhysiNode;

X
Xiaoyu Wang 已提交
385
typedef struct SDataSinkNode {
386
  ENodeType           type;
X
Xiaoyu Wang 已提交
387
  SDataBlockDescNode* pInputDataBlockDesc;
X
Xiaoyu Wang 已提交
388 389 390 391 392 393 394 395
} SDataSinkNode;

typedef struct SDataDispatcherNode {
  SDataSinkNode sink;
} SDataDispatcherNode;

typedef struct SDataInserterNode {
  SDataSinkNode sink;
396 397 398
  int32_t       numOfTables;
  uint32_t      size;
  char*         pData;
X
Xiaoyu Wang 已提交
399 400
} SDataInserterNode;

X
Xiaoyu Wang 已提交
401 402 403 404 405 406
typedef struct SDataDeleterNode {
  SDataSinkNode sink;
  uint64_t      tableId;
  int8_t        tableType;  // table type
  char          tableFName[TSDB_TABLE_FNAME_LEN];
  STimeWindow   deleteTimeRange;
X
Xiaoyu Wang 已提交
407
  SNode*        pAffectedRows;
X
Xiaoyu Wang 已提交
408 409
} SDataDeleterNode;

X
Xiaoyu Wang 已提交
410
typedef struct SSubplan {
411 412 413 414 415 416 417 418 419 420 421 422
  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 已提交
423
  SNode*         pTagCond;
X
Xiaoyu Wang 已提交
424 425
} SSubplan;

426
typedef enum EExplainMode { EXPLAIN_MODE_DISABLE = 1, EXPLAIN_MODE_STATIC, EXPLAIN_MODE_ANALYZE } EExplainMode;
427 428 429

typedef struct SExplainInfo {
  EExplainMode mode;
430 431
  bool         verbose;
  double       ratio;
432
} SExplainInfo;
433

X
Xiaoyu Wang 已提交
434
typedef struct SQueryPlan {
435 436 437 438
  ENodeType    type;
  uint64_t     queryId;
  int32_t      numOfSubplans;
  SNodeList*   pSubplans;  // Element is SNodeListNode. The execution level of subplan, starting from 0.
439
  SExplainInfo explainInfo;
X
Xiaoyu Wang 已提交
440
  SArray*      pPlaceholderValues;
X
Xiaoyu Wang 已提交
441 442
} SQueryPlan;

443 444
void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext);

X
Xiaoyu Wang 已提交
445 446 447 448 449
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANN_NODES_H_*/