plannodes.h 8.9 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 23
/*
 * 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

#include "querynodes.h"
X
Xiaoyu Wang 已提交
24
#include "query.h"
X
Xiaoyu Wang 已提交
25
#include "tname.h"
X
Xiaoyu Wang 已提交
26 27 28 29 30 31 32

typedef struct SLogicNode {
  ENodeType type;
  SNodeList* pTargets; // SColumnNode
  SNode* pConditions;
  SNodeList* pChildren;
  struct SLogicNode* pParent;
33
  int32_t optimizedFlag;
X
Xiaoyu Wang 已提交
34 35
} SLogicNode;

X
Xiaoyu Wang 已提交
36 37 38
typedef enum EScanType {
  SCAN_TYPE_TAG,
  SCAN_TYPE_TABLE,
X
Xiaoyu Wang 已提交
39
  SCAN_TYPE_SYSTEM_TABLE,
X
Xiaoyu Wang 已提交
40 41 42
  SCAN_TYPE_STREAM
} EScanType;

X
Xiaoyu Wang 已提交
43 44 45 46
typedef struct SScanLogicNode {
  SLogicNode node;
  SNodeList* pScanCols;
  struct STableMeta* pMeta;
47
  SVgroupsInfo* pVgroupList;
X
Xiaoyu Wang 已提交
48
  EScanType scanType;
X
Xiaoyu Wang 已提交
49
  uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count
X
Xiaoyu Wang 已提交
50
  STimeWindow scanRange;
X
Xiaoyu Wang 已提交
51
  SName tableName;
D
dapan1121 已提交
52
  bool showRewrite;
53
  double ratio;
54 55
  SNodeList* pDynamicScanFuncs;
  int32_t dataRequired;
X
Xiaoyu Wang 已提交
56 57 58 59 60
  int64_t interval;
  int64_t offset;
  int64_t sliding;
  int8_t intervalUnit;
  int8_t slidingUnit;
X
Xiaoyu Wang 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
} SScanLogicNode;

typedef struct SJoinLogicNode {
  SLogicNode node;
  EJoinType joinType;
  SNode* pOnConditions;
} SJoinLogicNode;

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

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

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

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

X
Xiaoyu Wang 已提交
98 99 100 101 102 103
typedef enum EWindowType {
  WINDOW_TYPE_INTERVAL = 1,
  WINDOW_TYPE_SESSION,
  WINDOW_TYPE_STATE
} EWindowType;

X
Xiaoyu Wang 已提交
104 105
typedef struct SWindowLogicNode {
  SLogicNode node;
X
Xiaoyu Wang 已提交
106 107 108 109 110
  EWindowType winType;
  SNodeList* pFuncs;
  int64_t interval;
  int64_t offset;
  int64_t sliding;
H
Haojun Liao 已提交
111 112
  int8_t  intervalUnit;
  int8_t  slidingUnit;
X
Xiaoyu Wang 已提交
113
  SFillNode* pFill;
X
Xiaoyu Wang 已提交
114
  int64_t sessionGap;
X
bugfix  
Xiaoyu Wang 已提交
115
  SNode* pTspk;
116
  SNode* pStateExpr;
X
Xiaoyu Wang 已提交
117 118
  int8_t triggerType;
  int64_t watermark;
X
Xiaoyu Wang 已提交
119 120
} SWindowLogicNode;

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

126 127 128 129 130
typedef struct SPartitionLogicNode {
  SLogicNode node;
  SNodeList* pPartitionKeys;
} SPartitionLogicNode;

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

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

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

typedef struct SQueryLogicPlan {
D
dapan1121 已提交
157
  ENodeType type;
X
Xiaoyu Wang 已提交
158
  SNodeList* pTopSubplans;
X
Xiaoyu Wang 已提交
159 160
} SQueryLogicPlan;

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

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

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

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

typedef SScanPhysiNode STagScanPhysiNode;
X
Xiaoyu Wang 已提交
196
typedef SScanPhysiNode SStreamScanPhysiNode;
X
Xiaoyu Wang 已提交
197

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

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

typedef STableScanPhysiNode STableSeqScanPhysiNode;

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

X
Xiaoyu Wang 已提交
230 231 232 233 234 235 236 237 238 239
typedef struct SJoinPhysiNode {
  SPhysiNode node;
  EJoinType joinType;
  SNode* pOnConditions; // in or out tuple ?
  SNodeList* pTargets;
} SJoinPhysiNode;

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

X
Xiaoyu Wang 已提交
244 245
typedef struct SDownstreamSourceNode {
  ENodeType type;
X
Xiaoyu Wang 已提交
246
  SQueryNodeAddr addr;
X
Xiaoyu Wang 已提交
247 248 249
  uint64_t taskId;
  uint64_t schedId;
} SDownstreamSourceNode;
X
Xiaoyu Wang 已提交
250 251

typedef struct SExchangePhysiNode {
X
Xiaoyu Wang 已提交
252
  SPhysiNode node;
H
Haojun Liao 已提交
253
  int32_t    srcGroupId;  // group id of datasource suplans
X
Xiaoyu Wang 已提交
254
  SNodeList* pSrcEndPoints;  // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
X
Xiaoyu Wang 已提交
255 256
} SExchangePhysiNode;

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

typedef struct SIntervalPhysiNode {
  SWinodwPhysiNode window;
H
Haojun Liao 已提交
268 269 270 271 272
  int64_t    interval;
  int64_t    offset;
  int64_t    sliding;
  int8_t     intervalUnit;
  int8_t     slidingUnit;
X
Xiaoyu Wang 已提交
273 274 275
  SFillNode* pFill;
} SIntervalPhysiNode;

276 277 278 279 280
typedef struct SMultiTableIntervalPhysiNode {
  SIntervalPhysiNode interval;
  SNodeList* pPartitionKeys;
} SMultiTableIntervalPhysiNode;

X
Xiaoyu Wang 已提交
281 282
typedef struct SSessionWinodwPhysiNode {
  SWinodwPhysiNode window;
283
  int64_t gap;
X
Xiaoyu Wang 已提交
284 285
} SSessionWinodwPhysiNode;

286 287 288 289 290
typedef struct SStateWinodwPhysiNode {
  SWinodwPhysiNode window;
  SNode* pStateKey;
} SStateWinodwPhysiNode;

X
Xiaoyu Wang 已提交
291 292 293 294
typedef struct SSortPhysiNode {
  SPhysiNode node;
  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 已提交
295
  SNodeList* pTargets;
X
Xiaoyu Wang 已提交
296 297
} SSortPhysiNode;

298 299 300 301
typedef struct SPartitionPhysiNode {
  SPhysiNode node;
  SNodeList* pExprs;   // these are expression list of partition_by_clause
  SNodeList* pPartitionKeys;
X
Xiaoyu Wang 已提交
302
  SNodeList* pTargets;
303 304
} SPartitionPhysiNode;

X
Xiaoyu Wang 已提交
305
typedef struct SDataSinkNode {
X
Xiaoyu Wang 已提交
306
  ENodeType type;
X
Xiaoyu Wang 已提交
307
  SDataBlockDescNode* pInputDataBlockDesc;
X
Xiaoyu Wang 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320
} SDataSinkNode;

typedef struct SDataDispatcherNode {
  SDataSinkNode sink;
} SDataDispatcherNode;

typedef struct SDataInserterNode {
  SDataSinkNode sink;
  int32_t   numOfTables;
  uint32_t  size;
  char     *pData;
} SDataInserterNode;

X
Xiaoyu Wang 已提交
321 322 323 324 325 326
typedef struct SSubplan {
  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.
X
Xiaoyu Wang 已提交
327
  char dbFName[TSDB_DB_FNAME_LEN];
X
Xiaoyu Wang 已提交
328
  SQueryNodeAddr execNode;    // for the scan/modify subplan, the optional execution node
D
dapan1121 已提交
329
  SQueryNodeStat execNodeStat; // only for scan subplan
X
Xiaoyu Wang 已提交
330 331 332 333 334 335
  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
} SSubplan;

336 337 338 339 340 341 342 343 344
typedef enum EExplainMode {
  EXPLAIN_MODE_DISABLE = 1,
  EXPLAIN_MODE_STATIC,
  EXPLAIN_MODE_ANALYZE
} EExplainMode;

typedef struct SExplainInfo {
  EExplainMode mode;
  bool verbose;
D
dapan1121 已提交
345
  double ratio;
346
} SExplainInfo;
347

X
Xiaoyu Wang 已提交
348
typedef struct SQueryPlan {
349
  ENodeType type;
X
Xiaoyu Wang 已提交
350
  uint64_t queryId;
X
Xiaoyu Wang 已提交
351 352
  int32_t numOfSubplans;
  SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
353
  SExplainInfo explainInfo;
D
dapan1121 已提交
354
  SArray* pPlaceholderValues;
X
Xiaoyu Wang 已提交
355 356
} SQueryPlan;

357 358
void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext);

X
Xiaoyu Wang 已提交
359 360 361 362 363
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANN_NODES_H_*/