plannerInt.h 4.6 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"
H
Haojun Liao 已提交
26
#include "taosmsg.h"
27

28 29 30 31 32 33 34 35 36 37 38 39 40
enum LOGIC_PLAN_E {
  LP_SCAN     = 1,
  LP_SESSION  = 2,
  LP_STATE    = 3,
  LP_INTERVAL = 4,
  LP_FILL     = 5,
  LP_AGG      = 6,
  LP_JOIN     = 7,
  LP_PROJECT  = 8,
  LP_DISTINCT = 9,
  LP_ORDER    = 10
};

41
typedef struct SQueryNodeBasicInfo {
42 43
  int32_t   type;          // operator type
  char     *name;          // operator name
44 45
} SQueryNodeBasicInfo;

46 47 48 49 50 51 52 53
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;

54
typedef struct SQueryTableInfo {
55 56 57
  char       *tableName;
  uint64_t    uid;
  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 67 68 69
  void               *pExtInfo;     // additional information
  // previous operator to generated result for current node to process
  // in case of join, multiple prev nodes exist.
  SArray             *pPrevNodes;   // upstream nodes
70 71
  struct SQueryPlanNode  *nextNode;
} SQueryPlanNode;
72

73 74
typedef SSchema SSlotSchema;

75 76
typedef struct SDataBlockSchema {
  int32_t             index;
77
  SSlotSchema        *pSchema;
78 79
  int32_t             numOfCols;    // number of columns
} SDataBlockSchema;
80

81
typedef struct SPhyNode {
82
  SQueryNodeBasicInfo info;
83 84
  SArray             *pTargets;      // target list to be computed or scanned at this node
  SArray             *pConditions;         // implicitly-ANDed qual conditions
85 86 87 88
  SDataBlockSchema    targetSchema;
  // children plan to generated result for current node to process
  // in case of join, multiple plan nodes exist.
  SArray             *pChildren;
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
} SPhyNode;

typedef struct SScanPhyNode {
  SPhyNode node;
  uint64_t     uid;  // unique id of the table
} SScanPhyNode;

typedef SScanPhyNode STagScanPhyNode;

typedef SScanPhyNode SSystemTableScanPhyNode;

typedef struct SMultiTableScanPhyNode {
  SScanPhyNode scan;
  SArray      *pTagsConditions; // implicitly-ANDed tag qual conditions
} SMultiTableScanPhyNode;

typedef SMultiTableScanPhyNode SMultiTableSeqScanPhyNode;

typedef struct SProjectPhyNode {
  SPhyNode node;
} SProjectPhyNode;

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

/**
 * Convert to physical plan to string to enable to print it out in the shell.
 * @param pPhyNode
 * @param str
 * @return
 */
int32_t phyPlanToString(struct SPhyNode *pPhyNode, char** str);

/**
 * Destroy the query plan object.
 * @return
 */
void* destroyQueryPlan(struct SQueryPlanNode* pQueryNode);

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

H
Hongze Cheng 已提交
162 163 164 165 166
#ifdef __cplusplus
}
#endif

#endif /*_TD_PLANNER_INT_H_*/