plannerInt.h 3.9 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
Haojun Liao 已提交
27
#include "taosmsg.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
X
Xiaoyu Wang 已提交
43
#define QNODE_INSERT        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 56
  char           *tableName; // to be deleted
  uint64_t        uid;       // to be deleted
  STableMetaInfo* pMeta;
57
  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

73 74 75 76 77 78 79 80 81 82 83 84 85
/**
 * 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 已提交
86
int32_t createQueryPlan(const SQueryNode* pNode, struct SQueryPlanNode** pQueryPlan);
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

/**
 * 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);

103
int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag);
D
dapan 已提交
104
int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep);
105
int32_t subPlanToString(const SSubplan *pPhyNode, char** str, int32_t* len);
106
int32_t stringToSubplan(const char* str, SSubplan** subplan);
107 108 109 110 111

/**
 * Destroy the query plan object.
 * @return
 */
112
void destroyQueryPlan(struct SQueryPlanNode* pQueryNode);
113 114 115 116 117 118 119

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

121
const char* opTypeToOpName(int32_t type);
X
Xiaoyu Wang 已提交
122 123
int32_t opNameToOpType(const char* name);

124 125 126
const char* dsinkTypeToDsinkName(int32_t type);
int32_t dsinkNameToDsinkType(const char* name);

H
Hongze Cheng 已提交
127 128 129 130 131
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANNER_INT_H_*/