plannodes.h 10.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 {
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;
X
Xiaoyu Wang 已提交
59 60 61 62
} SScanLogicNode;

typedef struct SJoinLogicNode {
  SLogicNode node;
63 64
  EJoinType  joinType;
  SNode*     pOnConditions;
X
Xiaoyu Wang 已提交
65
  bool       isSingleTableJoin;
X
Xiaoyu Wang 已提交
66 67 68 69 70 71 72 73 74 75 76
} SJoinLogicNode;

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

typedef struct SProjectLogicNode {
  SLogicNode node;
  SNodeList* pProjections;
77 78 79 80 81
  char       stmtName[TSDB_TABLE_NAME_LEN];
  int64_t    limit;
  int64_t    offset;
  int64_t    slimit;
  int64_t    soffset;
X
Xiaoyu Wang 已提交
82 83
} SProjectLogicNode;

84
typedef struct SVnodeModifLogicNode {
85 86 87
  SLogicNode     node;
  int32_t        msgType;
  SArray*        pDataBlocks;
88 89 90
  SVgDataBlocks* pVgDataBlocks;
} SVnodeModifLogicNode;

X
Xiaoyu Wang 已提交
91 92
typedef struct SExchangeLogicNode {
  SLogicNode node;
93 94
  int32_t    srcGroupId;
  uint8_t    precision;
X
Xiaoyu Wang 已提交
95 96
} SExchangeLogicNode;

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

X
Xiaoyu Wang 已提交
99
typedef struct SWindowLogicNode {
100
  SLogicNode  node;
X
Xiaoyu Wang 已提交
101
  EWindowType winType;
102 103 104 105 106 107 108 109 110 111 112
  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;
X
Xiaoyu Wang 已提交
113 114
} SWindowLogicNode;

X
Xiaoyu Wang 已提交
115
typedef struct SFillLogicNode {
X
Xiaoyu Wang 已提交
116 117 118 119 120
  SLogicNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;
  SNode*      pValues;  // SNodeListNode
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
121 122
} SFillLogicNode;

X
Xiaoyu Wang 已提交
123 124 125 126 127
typedef struct SSortLogicNode {
  SLogicNode node;
  SNodeList* pSortKeys;
} SSortLogicNode;

128 129 130 131 132
typedef struct SPartitionLogicNode {
  SLogicNode node;
  SNodeList* pPartitionKeys;
} SPartitionLogicNode;

133 134 135 136 137 138 139
typedef enum ESubplanType {
  SUBPLAN_TYPE_MERGE = 1,
  SUBPLAN_TYPE_PARTIAL,
  SUBPLAN_TYPE_SCAN,
  SUBPLAN_TYPE_MODIFY
} ESubplanType;

X
Xiaoyu Wang 已提交
140 141
typedef struct SSubplanId {
  uint64_t queryId;
142 143
  int32_t  groupId;
  int32_t  subplanId;
X
Xiaoyu Wang 已提交
144 145
} SSubplanId;

X
Xiaoyu Wang 已提交
146
typedef struct SLogicSubplan {
147 148 149 150 151 152
  ENodeType     type;
  SSubplanId    id;
  SNodeList*    pChildren;
  SNodeList*    pParents;
  SLogicNode*   pNode;
  ESubplanType  subplanType;
X
Xiaoyu Wang 已提交
153
  SVgroupsInfo* pVgroupList;
154 155
  int32_t       level;
  int32_t       splitFlag;
X
Xiaoyu Wang 已提交
156
} SLogicSubplan;
X
Xiaoyu Wang 已提交
157 158

typedef struct SQueryLogicPlan {
159
  ENodeType  type;
X
Xiaoyu Wang 已提交
160
  SNodeList* pTopSubplans;
X
Xiaoyu Wang 已提交
161 162
} SQueryLogicPlan;

X
Xiaoyu Wang 已提交
163 164
typedef struct SSlotDescNode {
  ENodeType type;
165
  int16_t   slotId;
X
Xiaoyu Wang 已提交
166
  SDataType dataType;
167 168 169
  bool      reserve;
  bool      output;
  bool      tag;
X
Xiaoyu Wang 已提交
170 171
} SSlotDescNode;

X
Xiaoyu Wang 已提交
172
typedef struct SDataBlockDescNode {
173 174
  ENodeType  type;
  int16_t    dataBlockId;
X
Xiaoyu Wang 已提交
175
  SNodeList* pSlots;
176 177 178
  int32_t    totalRowSize;
  int32_t    outputRowSize;
  uint8_t    precision;
X
Xiaoyu Wang 已提交
179
} SDataBlockDescNode;
X
Xiaoyu Wang 已提交
180 181

typedef struct SPhysiNode {
182
  ENodeType           type;
X
Xiaoyu Wang 已提交
183
  SDataBlockDescNode* pOutputDataBlockDesc;
184 185 186
  SNode*              pConditions;
  SNodeList*          pChildren;
  struct SPhysiNode*  pParent;
X
Xiaoyu Wang 已提交
187 188 189
} SPhysiNode;

typedef struct SScanPhysiNode {
X
Xiaoyu Wang 已提交
190
  SPhysiNode node;
X
Xiaoyu Wang 已提交
191
  SNodeList* pScanCols;
192 193 194 195
  SNodeList* pScanPseudoCols;
  uint64_t   uid;  // unique id of the table
  int8_t     tableType;
  SName      tableName;
X
Xiaoyu Wang 已提交
196 197 198 199
} SScanPhysiNode;

typedef SScanPhysiNode STagScanPhysiNode;

X
Xiaoyu Wang 已提交
200 201
typedef struct SSystemTableScanPhysiNode {
  SScanPhysiNode scan;
202 203 204
  SEpSet         mgmtEpSet;
  bool           showRewrite;
  int32_t        accountId;
X
Xiaoyu Wang 已提交
205 206
} SSystemTableScanPhysiNode;

X
Xiaoyu Wang 已提交
207 208
typedef struct STableScanPhysiNode {
  SScanPhysiNode scan;
209 210 211 212 213 214 215 216 217 218
  uint8_t        scanSeq[2];  // first is scan count, and second is reverse scan count
  STimeWindow    scanRange;
  double         ratio;
  int32_t        dataRequired;
  SNodeList*     pDynamicScanFuncs;
  int64_t        interval;
  int64_t        offset;
  int64_t        sliding;
  int8_t         intervalUnit;
  int8_t         slidingUnit;
X
Xiaoyu Wang 已提交
219 220 221
} STableScanPhysiNode;

typedef STableScanPhysiNode STableSeqScanPhysiNode;
5
54liuyao 已提交
222
typedef STableScanPhysiNode SStreamScanPhysiNode;
X
Xiaoyu Wang 已提交
223 224 225 226

typedef struct SProjectPhysiNode {
  SPhysiNode node;
  SNodeList* pProjections;
227 228 229 230
  int64_t    limit;
  int64_t    offset;
  int64_t    slimit;
  int64_t    soffset;
X
Xiaoyu Wang 已提交
231 232
} SProjectPhysiNode;

X
Xiaoyu Wang 已提交
233 234
typedef struct SJoinPhysiNode {
  SPhysiNode node;
235
  EJoinType  joinType;
X
Xiaoyu Wang 已提交
236
  SNode*     pOnConditions;
X
Xiaoyu Wang 已提交
237 238 239
  SNodeList* pTargets;
} SJoinPhysiNode;

X
Xiaoyu Wang 已提交
240 241
typedef SJoinPhysiNode SSortMergeJoinPhysiNode;

X
Xiaoyu Wang 已提交
242 243
typedef struct SAggPhysiNode {
  SPhysiNode node;
244
  SNodeList* pExprs;  // these are expression list of group_by_clause and parameter expression of aggregate function
X
Xiaoyu Wang 已提交
245
  SNodeList* pGroupKeys;
X
Xiaoyu Wang 已提交
246 247 248
  SNodeList* pAggFuncs;
} SAggPhysiNode;

X
Xiaoyu Wang 已提交
249
typedef struct SDownstreamSourceNode {
250
  ENodeType      type;
X
Xiaoyu Wang 已提交
251
  SQueryNodeAddr addr;
252 253
  uint64_t       taskId;
  uint64_t       schedId;
X
Xiaoyu Wang 已提交
254
} SDownstreamSourceNode;
X
Xiaoyu Wang 已提交
255 256

typedef struct SExchangePhysiNode {
X
Xiaoyu Wang 已提交
257
  SPhysiNode node;
258
  int32_t    srcGroupId;     // group id of datasource suplans
X
Xiaoyu Wang 已提交
259
  SNodeList* pSrcEndPoints;  // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
X
Xiaoyu Wang 已提交
260 261
} SExchangePhysiNode;

X
Xiaoyu Wang 已提交
262
typedef struct SWinodwPhysiNode {
X
Xiaoyu Wang 已提交
263
  SPhysiNode node;
264
  SNodeList* pExprs;  // these are expression list of parameter expression of function
X
Xiaoyu Wang 已提交
265
  SNodeList* pFuncs;
266 267 268
  SNode*     pTspk;  // timestamp primary key
  int8_t     triggerType;
  int64_t    watermark;
X
Xiaoyu Wang 已提交
269 270 271 272
} SWinodwPhysiNode;

typedef struct SIntervalPhysiNode {
  SWinodwPhysiNode window;
273 274 275 276 277
  int64_t          interval;
  int64_t          offset;
  int64_t          sliding;
  int8_t           intervalUnit;
  int8_t           slidingUnit;
X
Xiaoyu Wang 已提交
278 279
} SIntervalPhysiNode;

X
Xiaoyu Wang 已提交
280 281
typedef SIntervalPhysiNode SStreamIntervalPhysiNode;

X
Xiaoyu Wang 已提交
282
typedef struct SFillPhysiNode {
X
Xiaoyu Wang 已提交
283 284 285 286 287 288
  SPhysiNode  node;
  EFillMode   mode;
  SNode*      pWStartTs;  // SColumnNode
  SNode*      pValues;    // SNodeListNode
  SNodeList*  pTargets;
  STimeWindow timeRange;
X
Xiaoyu Wang 已提交
289 290
} SFillPhysiNode;

291 292
typedef struct SMultiTableIntervalPhysiNode {
  SIntervalPhysiNode interval;
293
  SNodeList*         pPartitionKeys;
294 295
} SMultiTableIntervalPhysiNode;

X
Xiaoyu Wang 已提交
296 297
typedef struct SSessionWinodwPhysiNode {
  SWinodwPhysiNode window;
298
  int64_t          gap;
X
Xiaoyu Wang 已提交
299 300
} SSessionWinodwPhysiNode;

5
54liuyao 已提交
301 302
typedef SSessionWinodwPhysiNode SStreamSessionWinodwPhysiNode;

303 304
typedef struct SStateWinodwPhysiNode {
  SWinodwPhysiNode window;
305
  SNode*           pStateKey;
306 307
} SStateWinodwPhysiNode;

X
Xiaoyu Wang 已提交
308 309
typedef struct SSortPhysiNode {
  SPhysiNode node;
310 311
  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 已提交
312
  SNodeList* pTargets;
X
Xiaoyu Wang 已提交
313 314
} SSortPhysiNode;

315 316
typedef struct SPartitionPhysiNode {
  SPhysiNode node;
317
  SNodeList* pExprs;  // these are expression list of partition_by_clause
318
  SNodeList* pPartitionKeys;
X
Xiaoyu Wang 已提交
319
  SNodeList* pTargets;
320 321
} SPartitionPhysiNode;

X
Xiaoyu Wang 已提交
322
typedef struct SDataSinkNode {
323
  ENodeType           type;
X
Xiaoyu Wang 已提交
324
  SDataBlockDescNode* pInputDataBlockDesc;
X
Xiaoyu Wang 已提交
325 326 327 328 329 330 331 332
} SDataSinkNode;

typedef struct SDataDispatcherNode {
  SDataSinkNode sink;
} SDataDispatcherNode;

typedef struct SDataInserterNode {
  SDataSinkNode sink;
333 334 335
  int32_t       numOfTables;
  uint32_t      size;
  char*         pData;
X
Xiaoyu Wang 已提交
336 337
} SDataInserterNode;

X
Xiaoyu Wang 已提交
338
typedef struct SSubplan {
339 340 341 342 343 344 345 346 347 348 349 350
  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 已提交
351
  SNode*         pTagCond;
X
Xiaoyu Wang 已提交
352 353
} SSubplan;

354
typedef enum EExplainMode { EXPLAIN_MODE_DISABLE = 1, EXPLAIN_MODE_STATIC, EXPLAIN_MODE_ANALYZE } EExplainMode;
355 356 357

typedef struct SExplainInfo {
  EExplainMode mode;
358 359
  bool         verbose;
  double       ratio;
360
} SExplainInfo;
361

X
Xiaoyu Wang 已提交
362
typedef struct SQueryPlan {
363 364 365 366
  ENodeType    type;
  uint64_t     queryId;
  int32_t      numOfSubplans;
  SNodeList*   pSubplans;  // Element is SNodeListNode. The execution level of subplan, starting from 0.
367
  SExplainInfo explainInfo;
X
Xiaoyu Wang 已提交
368
  SArray*      pPlaceholderValues;
X
Xiaoyu Wang 已提交
369 370
} SQueryPlan;

371 372
void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext);

X
Xiaoyu Wang 已提交
373 374 375 376 377
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANN_NODES_H_*/