plannodes.h 11.3 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 {
40 41 42
  SLogicNode         node;
  SNodeList*         pScanCols;
  SNodeList*         pScanPseudoCols;
X
Xiaoyu Wang 已提交
43
  struct STableMeta* pMeta;
44 45 46 47 48 49 50 51 52 53 54 55 56 57
  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;
X
Xiaoyu Wang 已提交
58
  SNode*             pTagCond;
5
54liuyao 已提交
59 60 61
  int8_t             triggerType;
  int64_t            watermark;
  int16_t            tsColId;
5
54liuyao 已提交
62
  double             filesFactor;
X
Xiaoyu Wang 已提交
63 64 65 66
} SScanLogicNode;

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

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

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

88
typedef struct SVnodeModifLogicNode {
89 90 91
  SLogicNode     node;
  int32_t        msgType;
  SArray*        pDataBlocks;
92 93 94
  SVgDataBlocks* pVgDataBlocks;
} SVnodeModifLogicNode;

X
Xiaoyu Wang 已提交
95 96
typedef struct SExchangeLogicNode {
  SLogicNode node;
97
  int32_t    srcGroupId;
X
Xiaoyu Wang 已提交
98 99
} SExchangeLogicNode;

X
Xiaoyu Wang 已提交
100 101 102 103 104 105 106
typedef struct SMergeLogicNode {
  SLogicNode node;
  SNodeList* pMergeKeys;
  int32_t    numOfChannels;
  int32_t    srcGroupId;
} SMergeLogicNode;

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

109 110 111 112 113 114
typedef enum EStreamIntervalAlgorithm {
  STREAM_INTERVAL_ALGO_FINAL = 1,
  STREAM_INTERVAL_ALGO_SEMI,
  STREAM_INTERVAL_ALGO_SINGLE
} EStreamIntervalAlgorithm;

X
Xiaoyu Wang 已提交
115
typedef struct SWindowLogicNode {
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
  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;
  EStreamIntervalAlgorithm stmInterAlgo;
X
Xiaoyu Wang 已提交
131 132
} SWindowLogicNode;

X
Xiaoyu Wang 已提交
133
typedef struct SFillLogicNode {
X
Xiaoyu Wang 已提交
134 135 136 137 138
  SLogicNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;
  SNode*      pValues;  // SNodeListNode
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
139 140
} SFillLogicNode;

X
Xiaoyu Wang 已提交
141 142 143 144 145
typedef struct SSortLogicNode {
  SLogicNode node;
  SNodeList* pSortKeys;
} SSortLogicNode;

146 147 148 149 150
typedef struct SPartitionLogicNode {
  SLogicNode node;
  SNodeList* pPartitionKeys;
} SPartitionLogicNode;

151 152 153 154 155 156 157
typedef enum ESubplanType {
  SUBPLAN_TYPE_MERGE = 1,
  SUBPLAN_TYPE_PARTIAL,
  SUBPLAN_TYPE_SCAN,
  SUBPLAN_TYPE_MODIFY
} ESubplanType;

X
Xiaoyu Wang 已提交
158 159
typedef struct SSubplanId {
  uint64_t queryId;
160 161
  int32_t  groupId;
  int32_t  subplanId;
X
Xiaoyu Wang 已提交
162 163
} SSubplanId;

X
Xiaoyu Wang 已提交
164
typedef struct SLogicSubplan {
165 166 167 168 169 170
  ENodeType     type;
  SSubplanId    id;
  SNodeList*    pChildren;
  SNodeList*    pParents;
  SLogicNode*   pNode;
  ESubplanType  subplanType;
X
Xiaoyu Wang 已提交
171
  SVgroupsInfo* pVgroupList;
172 173
  int32_t       level;
  int32_t       splitFlag;
X
Xiaoyu Wang 已提交
174
} SLogicSubplan;
X
Xiaoyu Wang 已提交
175 176

typedef struct SQueryLogicPlan {
177
  ENodeType  type;
X
Xiaoyu Wang 已提交
178
  SNodeList* pTopSubplans;
X
Xiaoyu Wang 已提交
179 180
} SQueryLogicPlan;

X
Xiaoyu Wang 已提交
181 182
typedef struct SSlotDescNode {
  ENodeType type;
183
  int16_t   slotId;
X
Xiaoyu Wang 已提交
184
  SDataType dataType;
185 186 187
  bool      reserve;
  bool      output;
  bool      tag;
X
Xiaoyu Wang 已提交
188 189
} SSlotDescNode;

X
Xiaoyu Wang 已提交
190
typedef struct SDataBlockDescNode {
191 192
  ENodeType  type;
  int16_t    dataBlockId;
X
Xiaoyu Wang 已提交
193
  SNodeList* pSlots;
194 195 196
  int32_t    totalRowSize;
  int32_t    outputRowSize;
  uint8_t    precision;
X
Xiaoyu Wang 已提交
197
} SDataBlockDescNode;
X
Xiaoyu Wang 已提交
198 199

typedef struct SPhysiNode {
200
  ENodeType           type;
X
Xiaoyu Wang 已提交
201
  SDataBlockDescNode* pOutputDataBlockDesc;
202 203 204
  SNode*              pConditions;
  SNodeList*          pChildren;
  struct SPhysiNode*  pParent;
X
Xiaoyu Wang 已提交
205 206 207
} SPhysiNode;

typedef struct SScanPhysiNode {
X
Xiaoyu Wang 已提交
208
  SPhysiNode node;
X
Xiaoyu Wang 已提交
209
  SNodeList* pScanCols;
210 211 212 213
  SNodeList* pScanPseudoCols;
  uint64_t   uid;  // unique id of the table
  int8_t     tableType;
  SName      tableName;
X
Xiaoyu Wang 已提交
214 215 216 217
} SScanPhysiNode;

typedef SScanPhysiNode STagScanPhysiNode;

X
Xiaoyu Wang 已提交
218 219
typedef struct SSystemTableScanPhysiNode {
  SScanPhysiNode scan;
220 221 222
  SEpSet         mgmtEpSet;
  bool           showRewrite;
  int32_t        accountId;
X
Xiaoyu Wang 已提交
223 224
} SSystemTableScanPhysiNode;

X
Xiaoyu Wang 已提交
225 226
typedef struct STableScanPhysiNode {
  SScanPhysiNode scan;
227 228 229 230 231
  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 已提交
232
  SNodeList*     pPartitionKeys;
233 234 235 236 237
  int64_t        interval;
  int64_t        offset;
  int64_t        sliding;
  int8_t         intervalUnit;
  int8_t         slidingUnit;
5
54liuyao 已提交
238 239 240
  int8_t         triggerType;
  int64_t        watermark;
  int16_t        tsColId;
5
54liuyao 已提交
241
  double         filesFactor;
X
Xiaoyu Wang 已提交
242 243 244
} STableScanPhysiNode;

typedef STableScanPhysiNode STableSeqScanPhysiNode;
5
54liuyao 已提交
245
typedef STableScanPhysiNode SStreamScanPhysiNode;
X
Xiaoyu Wang 已提交
246 247 248 249

typedef struct SProjectPhysiNode {
  SPhysiNode node;
  SNodeList* pProjections;
250 251 252 253
  int64_t    limit;
  int64_t    offset;
  int64_t    slimit;
  int64_t    soffset;
X
Xiaoyu Wang 已提交
254 255
} SProjectPhysiNode;

X
Xiaoyu Wang 已提交
256 257
typedef struct SJoinPhysiNode {
  SPhysiNode node;
258
  EJoinType  joinType;
X
Xiaoyu Wang 已提交
259
  SNode*     pOnConditions;
X
Xiaoyu Wang 已提交
260 261 262
  SNodeList* pTargets;
} SJoinPhysiNode;

X
Xiaoyu Wang 已提交
263 264
typedef SJoinPhysiNode SSortMergeJoinPhysiNode;

X
Xiaoyu Wang 已提交
265 266
typedef struct SAggPhysiNode {
  SPhysiNode node;
267
  SNodeList* pExprs;  // these are expression list of group_by_clause and parameter expression of aggregate function
X
Xiaoyu Wang 已提交
268
  SNodeList* pGroupKeys;
X
Xiaoyu Wang 已提交
269 270 271
  SNodeList* pAggFuncs;
} SAggPhysiNode;

X
Xiaoyu Wang 已提交
272
typedef struct SDownstreamSourceNode {
273
  ENodeType      type;
X
Xiaoyu Wang 已提交
274
  SQueryNodeAddr addr;
275 276
  uint64_t       taskId;
  uint64_t       schedId;
X
Xiaoyu Wang 已提交
277
} SDownstreamSourceNode;
X
Xiaoyu Wang 已提交
278 279

typedef struct SExchangePhysiNode {
X
Xiaoyu Wang 已提交
280
  SPhysiNode node;
281
  int32_t    srcGroupId;     // group id of datasource suplans
X
Xiaoyu Wang 已提交
282
  SNodeList* pSrcEndPoints;  // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
X
Xiaoyu Wang 已提交
283 284
} SExchangePhysiNode;

X
Xiaoyu Wang 已提交
285 286 287 288 289 290 291
typedef struct SMergePhysiNode {
  SPhysiNode node;
  SNodeList* pMergeKeys;
  int32_t    numOfChannels;
  int32_t    srcGroupId;
} SMergePhysiNode;

X
Xiaoyu Wang 已提交
292
typedef struct SWinodwPhysiNode {
X
Xiaoyu Wang 已提交
293
  SPhysiNode node;
294
  SNodeList* pExprs;  // these are expression list of parameter expression of function
X
Xiaoyu Wang 已提交
295
  SNodeList* pFuncs;
296 297 298
  SNode*     pTspk;  // timestamp primary key
  int8_t     triggerType;
  int64_t    watermark;
5
54liuyao 已提交
299
  double     filesFactor;
X
Xiaoyu Wang 已提交
300 301 302 303
} SWinodwPhysiNode;

typedef struct SIntervalPhysiNode {
  SWinodwPhysiNode window;
304 305 306 307 308
  int64_t          interval;
  int64_t          offset;
  int64_t          sliding;
  int8_t           intervalUnit;
  int8_t           slidingUnit;
X
Xiaoyu Wang 已提交
309 310
} SIntervalPhysiNode;

X
Xiaoyu Wang 已提交
311
typedef SIntervalPhysiNode SStreamIntervalPhysiNode;
312 313
typedef SIntervalPhysiNode SStreamFinalIntervalPhysiNode;
typedef SIntervalPhysiNode SStreamSemiIntervalPhysiNode;
X
Xiaoyu Wang 已提交
314

X
Xiaoyu Wang 已提交
315
typedef struct SFillPhysiNode {
X
Xiaoyu Wang 已提交
316 317 318 319 320 321
  SPhysiNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;  // SColumnNode
  SNode*      pValues;    // SNodeListNode
  SNodeList*  pTargets;
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
322 323
} SFillPhysiNode;

324 325
typedef struct SMultiTableIntervalPhysiNode {
  SIntervalPhysiNode interval;
326
  SNodeList*         pPartitionKeys;
327 328
} SMultiTableIntervalPhysiNode;

X
Xiaoyu Wang 已提交
329 330
typedef struct SSessionWinodwPhysiNode {
  SWinodwPhysiNode window;
331
  int64_t          gap;
X
Xiaoyu Wang 已提交
332 333
} SSessionWinodwPhysiNode;

5
54liuyao 已提交
334 335
typedef SSessionWinodwPhysiNode SStreamSessionWinodwPhysiNode;

336 337
typedef struct SStateWinodwPhysiNode {
  SWinodwPhysiNode window;
338
  SNode*           pStateKey;
339 340
} SStateWinodwPhysiNode;

X
Xiaoyu Wang 已提交
341 342
typedef struct SSortPhysiNode {
  SPhysiNode node;
343 344
  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 已提交
345
  SNodeList* pTargets;
X
Xiaoyu Wang 已提交
346 347
} SSortPhysiNode;

348 349
typedef struct SPartitionPhysiNode {
  SPhysiNode node;
350
  SNodeList* pExprs;  // these are expression list of partition_by_clause
351
  SNodeList* pPartitionKeys;
X
Xiaoyu Wang 已提交
352
  SNodeList* pTargets;
353 354
} SPartitionPhysiNode;

X
Xiaoyu Wang 已提交
355
typedef struct SDataSinkNode {
356
  ENodeType           type;
X
Xiaoyu Wang 已提交
357
  SDataBlockDescNode* pInputDataBlockDesc;
X
Xiaoyu Wang 已提交
358 359 360 361 362 363 364 365
} SDataSinkNode;

typedef struct SDataDispatcherNode {
  SDataSinkNode sink;
} SDataDispatcherNode;

typedef struct SDataInserterNode {
  SDataSinkNode sink;
366 367 368
  int32_t       numOfTables;
  uint32_t      size;
  char*         pData;
X
Xiaoyu Wang 已提交
369 370
} SDataInserterNode;

X
Xiaoyu Wang 已提交
371
typedef struct SSubplan {
372 373 374 375 376 377 378 379 380 381 382 383
  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 已提交
384
  SNode*         pTagCond;
X
Xiaoyu Wang 已提交
385 386
} SSubplan;

387
typedef enum EExplainMode { EXPLAIN_MODE_DISABLE = 1, EXPLAIN_MODE_STATIC, EXPLAIN_MODE_ANALYZE } EExplainMode;
388 389 390

typedef struct SExplainInfo {
  EExplainMode mode;
391 392
  bool         verbose;
  double       ratio;
393
} SExplainInfo;
394

X
Xiaoyu Wang 已提交
395
typedef struct SQueryPlan {
396 397 398 399
  ENodeType    type;
  uint64_t     queryId;
  int32_t      numOfSubplans;
  SNodeList*   pSubplans;  // Element is SNodeListNode. The execution level of subplan, starting from 0.
400
  SExplainInfo explainInfo;
X
Xiaoyu Wang 已提交
401
  SArray*      pPlaceholderValues;
X
Xiaoyu Wang 已提交
402 403
} SQueryPlan;

404 405
void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext);

X
Xiaoyu Wang 已提交
406 407 408 409 410
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANN_NODES_H_*/