plannerInt.h 3.8 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
43

44 45 46 47 48 49 50 51
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;

52
typedef struct SQueryTableInfo {
53 54 55
  char           *tableName; // to be deleted
  uint64_t        uid;       // to be deleted
  STableMetaInfo* pMeta;
56
  STimeWindow window;
57 58
} SQueryTableInfo;

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

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

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

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

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

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

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

H
Hongze Cheng 已提交
123 124 125 126 127
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANNER_INT_H_*/