plannerInt.h 4.1 KB
Newer Older
H
Hongze Cheng 已提交
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_PLANNER_INT_H_
#define _TD_PLANNER_INT_H_

#ifdef __cplusplus
extern "C" {
#endif

23 24 25
#include "common.h"
#include "tarray.h"
#include "planner.h"
26
#include "parser.h"
H
Hongze Cheng 已提交
27
#include "tmsg.h"
28

X
Xiaoyu Wang 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42
#define QNODE_TAGSCAN       1
#define QNODE_TABLESCAN     2
#define QNODE_PROJECT       3
#define QNODE_AGGREGATE     4
#define QNODE_GROUPBY       5
#define QNODE_LIMIT         6
#define QNODE_JOIN          7
#define QNODE_DISTINCT      8
#define QNODE_SORT          9
#define QNODE_UNION         10
#define QNODE_TIMEWINDOW    11
#define QNODE_SESSIONWINDOW 12
#define QNODE_STATEWINDOW   13
#define QNODE_FILL          14
43
#define QNODE_MODIFY        15
44

45 46 47 48 49 50 51 52
typedef struct SQueryDistPlanNodeInfo {
  bool      stableQuery;   // super table query or not
  int32_t   phase;         // merge|partial
  int32_t   type;          // operator type
  char     *name;          // operator name
  SEpSet   *sourceEp;      // data source epset
} SQueryDistPlanNodeInfo;

53
typedef struct SQueryTableInfo {
54 55
  char           *tableName; // to be deleted
  uint64_t        uid;       // to be deleted
H
Haojun Liao 已提交
56 57
  STableMetaInfo *pMeta;
  STimeWindow     window;
58 59
} SQueryTableInfo;

60
typedef struct SQueryPlanNode {
61 62 63
  SQueryNodeBasicInfo info;
  SSchema            *pSchema;      // the schema of the input SSDatablock
  int32_t             numOfCols;    // number of input columns
64
  SArray             *pExpr;        // the query functions or sql aggregations
65
  int32_t             numOfExpr;    // number of result columns, which is also the number of pExprs
66
  void               *pExtInfo;     // additional information
X
Xiaoyu Wang 已提交
67
  // children operator to generated result for current node to process
68
  // in case of join, multiple prev nodes exist.
X
Xiaoyu Wang 已提交
69 70
  SArray             *pChildren;   // upstream nodes
  struct SQueryPlanNode  *pParent;
71
} SQueryPlanNode;
72

H
Haojun Liao 已提交
73 74 75 76 77
typedef struct SDataPayloadInfo {
  int32_t msgType;
  SArray *payload;
} SDataPayloadInfo;

78 79 80 81 82 83 84 85 86 87 88 89 90
/**
 * Optimize the query execution plan, currently not implement yet.
 * @param pQueryNode
 * @return
 */
int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode);

/**
 * Create the query plan according to the bound AST, which is in the form of pQueryInfo
 * @param pQueryInfo
 * @param pQueryNode
 * @return
 */
X
Xiaoyu Wang 已提交
91
int32_t createQueryPlan(const SQueryNode* pNode, struct SQueryPlanNode** pQueryPlan);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

/**
 * Convert the query plan to string, in order to display it in the shell.
 * @param pQueryNode
 * @return
 */
int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str);

/**
 * Restore the SQL statement according to the logic query plan.
 * @param pQueryNode
 * @param sql
 * @return
 */
int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql);

108
int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag, uint64_t requestId);
109
void setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep);
110
int32_t subPlanToString(const SSubplan *pPhyNode, char** str, int32_t* len);
111
int32_t stringToSubplan(const char* str, SSubplan** subplan);
112 113 114 115 116

/**
 * Destroy the query plan object.
 * @return
 */
117
void destroyQueryPlan(struct SQueryPlanNode* pQueryNode);
118 119 120 121 122 123 124

/**
 * Destroy the physical plan.
 * @param pQueryPhyNode
 * @return
 */
void* destroyQueryPhyPlan(struct SPhyNode* pQueryPhyNode);
125

126
const char* opTypeToOpName(int32_t type);
X
Xiaoyu Wang 已提交
127 128
int32_t opNameToOpType(const char* name);

129 130 131
const char* dsinkTypeToDsinkName(int32_t type);
int32_t dsinkNameToDsinkType(const char* name);

H
Hongze Cheng 已提交
132 133 134 135 136
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANNER_INT_H_*/