commandInt.h 8.0 KB
Newer Older
D
dapan1121 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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_QUERY_INT_H_
#define _TD_QUERY_INT_H_

#ifdef __cplusplus
extern "C" {
#endif
X
Xiaoyu Wang 已提交
22 23

// clang-format off
D
dapan1121 已提交
24 25 26 27 28 29 30
#include "nodes.h"
#include "plannodes.h"
#include "ttime.h"

#define EXPLAIN_MAX_GROUP_NUM 100

//newline area
D
dapan1121 已提交
31 32
#define EXPLAIN_TAG_SCAN_FORMAT "Tag Scan on %s"
#define EXPLAIN_TBL_SCAN_FORMAT "Table Scan on %s"
33
#define EXPLAIN_TBL_MERGE_SCAN_FORMAT "Table Merge Scan on %s"
D
dapan1121 已提交
34
#define EXPLAIN_SYSTBL_SCAN_FORMAT "System Table Scan on %s"
D
dapan1121 已提交
35 36
#define EXPLAIN_DISTBLK_SCAN_FORMAT "Block Dist Scan on %s"
#define EXPLAIN_LASTROW_SCAN_FORMAT "Last Row Scan on %s"
D
dapan1121 已提交
37 38 39
#define EXPLAIN_PROJECTION_FORMAT "Projection"
#define EXPLAIN_JOIN_FORMAT "%s"
#define EXPLAIN_AGG_FORMAT "Aggragate"
D
dapan1121 已提交
40
#define EXPLAIN_INDEF_ROWS_FORMAT "Indefinite Rows Function"
D
dapan1121 已提交
41 42
#define EXPLAIN_EXCHANGE_FORMAT "Data Exchange %d:1"
#define EXPLAIN_SORT_FORMAT "Sort"
D
dapan1121 已提交
43
#define EXPLAIN_GROUP_SORT_FORMAT "Group Sort"
D
dapan1121 已提交
44
#define EXPLAIN_INTERVAL_FORMAT "Interval on Column %s"
D
dapan1121 已提交
45
#define EXPLAIN_MERGE_INTERVAL_FORMAT "Merge Interval on Column %s"
46
#define EXPLAIN_MERGE_ALIGNED_INTERVAL_FORMAT "Merge Aligned Interval on Column %s"
D
dapan1121 已提交
47
#define EXPLAIN_FILL_FORMAT "Fill"
D
dapan1121 已提交
48
#define EXPLAIN_SESSION_FORMAT "Session"
49 50
#define EXPLAIN_STATE_WINDOW_FORMAT "StateWindow on Column %s"
#define EXPLAIN_PARITION_FORMAT "Partition on Column %s"
D
dapan1121 已提交
51 52
#define EXPLAIN_ORDER_FORMAT "Order: %s"
#define EXPLAIN_FILTER_FORMAT "Filter: "
53
#define EXPLAIN_MERGEBLOCKS_FORMAT "Merge ResBlocks: %s"
D
dapan1121 已提交
54
#define EXPLAIN_FILL_VALUE_FORMAT "Fill Values: "
D
dapan1121 已提交
55 56
#define EXPLAIN_ON_CONDITIONS_FORMAT "Join Cond: "
#define EXPLAIN_TIMERANGE_FORMAT "Time Range: [%" PRId64 ", %" PRId64 "]"
D
dapan1121 已提交
57 58 59
#define EXPLAIN_OUTPUT_FORMAT "Output: "
#define EXPLAIN_TIME_WINDOWS_FORMAT "Time Window: interval=%" PRId64 "%c offset=%" PRId64 "%c sliding=%" PRId64 "%c"
#define EXPLAIN_WINDOW_FORMAT "Window: gap=%" PRId64
D
dapan1121 已提交
60
#define EXPLAIN_RATIO_TIME_FORMAT "Ratio: %f"
61
#define EXPLAIN_MERGE_FORMAT "SortMerge"
D
dapan1121 已提交
62
#define EXPLAIN_MERGE_KEYS_FORMAT "Merge Key: "
63
#define EXPLAIN_IGNORE_GROUPID_FORMAT "Ignore Group Id: %s"
64 65
#define EXPLAIN_PARTITION_KETS_FORMAT "Partition Key: "
#define EXPLAIN_INTERP_FORMAT "Interp"
D
dapan1121 已提交
66

D
dapan1121 已提交
67 68
#define EXPLAIN_PLANNING_TIME_FORMAT "Planning Time: %.3f ms"
#define EXPLAIN_EXEC_TIME_FORMAT "Execution Time: %.3f ms"
D
dapan1121 已提交
69 70

//append area
D
dapan1121 已提交
71 72
#define EXPLAIN_LIMIT_FORMAT "limit=%" PRId64
#define EXPLAIN_SLIMIT_FORMAT "slimit=%" PRId64
D
dapan1121 已提交
73 74 75
#define EXPLAIN_LEFT_PARENTHESIS_FORMAT " ("
#define EXPLAIN_RIGHT_PARENTHESIS_FORMAT ")"
#define EXPLAIN_BLANK_FORMAT " "
76
#define EXPLAIN_COMMA_FORMAT ", "
D
dapan1121 已提交
77 78 79
#define EXPLAIN_COST_FORMAT "cost=%.2f..%.2f"
#define EXPLAIN_ROWS_FORMAT "rows=%" PRIu64
#define EXPLAIN_COLUMNS_FORMAT "columns=%d"
D
dapan1121 已提交
80
#define EXPLAIN_PSEUDO_COLUMNS_FORMAT "pseudo_columns=%d"
D
dapan1121 已提交
81
#define EXPLAIN_WIDTH_FORMAT "width=%d"
82
#define EXPLAIN_TABLE_SCAN_FORMAT "order=[asc|%d desc|%d]"
D
dapan1121 已提交
83 84
#define EXPLAIN_GROUPS_FORMAT "groups=%d"
#define EXPLAIN_WIDTH_FORMAT "width=%d"
D
dapan1121 已提交
85
#define EXPLAIN_INTERVAL_VALUE_FORMAT "interval=%" PRId64 "%c"
D
dapan1121 已提交
86
#define EXPLAIN_FUNCTIONS_FORMAT "functions=%d"
87
#define EXPLAIN_EXECINFO_FORMAT "cost=%.3f..%.3f rows=%" PRIu64
D
dapan1121 已提交
88 89
#define EXPLAIN_MODE_FORMAT "mode=%s"
#define EXPLAIN_STRING_TYPE_FORMAT "%s"
X
Xiaoyu Wang 已提交
90 91
#define EXPLAIN_INPUT_ORDER_FORMAT "input_order=%s"
#define EXPLAIN_OUTPUT_ORDER_TYPE_FORMAT "output_order=%s"
D
dapan1121 已提交
92 93
#define EXPLAIN_OFFSET_FORMAT "offset=%" PRId64
#define EXPLAIN_SOFFSET_FORMAT "soffset=%" PRId64
94
#define EXPLAIN_PARTITIONS_FORMAT "partitions=%d"
D
dapan1121 已提交
95

D
dapan1121 已提交
96 97 98
#define COMMAND_RESET_LOG "resetLog"
#define COMMAND_SCHEDULE_POLICY "schedulePolicy"
#define COMMAND_ENABLE_RESCHEDULE "enableReSchedule"
D
dapan1121 已提交
99
#define COMMAND_CATALOG_DEBUG "catalogDebug"
D
dapan1121 已提交
100

D
dapan1121 已提交
101 102
typedef struct SExplainGroup {
  int32_t   nodeNum;
103
  int32_t   nodeIdx;
D
dapan1121 已提交
104 105
  int32_t   physiPlanExecNum;
  int32_t   physiPlanExecIdx;
106
  bool      singleChannel;
D
dapan1121 已提交
107
  SRWLatch  lock;
D
dapan1121 已提交
108
  SSubplan *plan;
D
dapan1121 已提交
109
  SArray   *nodeExecInfo;      //Array<SExplainRsp>
D
dapan1121 已提交
110 111 112
} SExplainGroup;

typedef struct SExplainResNode {
D
dapan1121 已提交
113 114 115
  SNodeList*        pChildren;
  SPhysiNode*       pNode;
  SArray*           pExecInfo; // Array<SExplainExecInfo>
D
dapan1121 已提交
116 117 118 119 120 121 122 123 124
} SExplainResNode;

typedef struct SQueryExplainRowInfo {
  int32_t level;
  int32_t len;
  char   *buf;
} SQueryExplainRowInfo;

typedef struct SExplainCtx {
D
dapan1121 已提交
125 126 127
  EExplainMode mode;
  double       ratio;
  bool         verbose;
D
dapan1121 已提交
128

D
dapan1121 已提交
129 130 131 132 133 134 135 136 137 138 139
  SRWLatch     lock;
  int32_t      rootGroupId;
  int32_t      dataSize;
  bool         execDone;
  int64_t      reqStartTs;
  int64_t      jobStartTs;
  int64_t      jobDoneTs;
  char        *tbuf;
  SArray      *rows;
  int32_t      groupDoneNum;
  SHashObj    *groupHash;     // Hash<SExplainGroup>
D
dapan1121 已提交
140 141
} SExplainCtx;

X
Xiaoyu Wang 已提交
142
#define EXPLAIN_ORDER_STRING(_order) ((ORDER_ASC == _order) ? "asc" : "desc")
D
dapan1121 已提交
143 144 145 146
#define EXPLAIN_JOIN_STRING(_type) ((JOIN_TYPE_INNER == _type) ? "Inner join" : "Join")

#define INVERAL_TIME_FROM_PRECISION_TO_UNIT(_t, _u, _p) (((_u) == 'n' || (_u) == 'y') ? (_t) : (convertTimeFromPrecisionToUnit(_t, _p, _u)))

D
dapan1121 已提交
147 148 149
#define EXPLAIN_ROW_NEW(level, ...)                                                                               \
  do {                                                                                                            \
    if (isVerboseLine) {                                                                                          \
D
dapan1121 已提交
150
      tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s", (level) * 3 + 3, "");       \
D
dapan1121 已提交
151
    } else {                                                                                                      \
D
dapan1121 已提交
152
      tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s%s", (level) * 3, "", "-> ");  \
D
dapan1121 已提交
153
    }                                                                                                             \
D
dapan1121 已提交
154
    tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__);         \
D
dapan1121 已提交
155 156
  } while (0)
  
D
dapan1121 已提交
157
#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__)
D
dapan1121 已提交
158 159
#define EXPLAIN_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; isVerboseLine = true; } while (0)

D
dapan1121 已提交
160 161 162
#define EXPLAIN_SUM_ROW_NEW(...) tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, __VA_ARGS__)
#define EXPLAIN_SUM_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; } while (0)

D
dapan1121 已提交
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
#define EXPLAIN_ROW_APPEND_LIMIT_IMPL(_pLimit, sl) do {                                            \
  if (_pLimit) {                                                                                   \
    EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);                                                      \
    SLimitNode* pLimit = (SLimitNode*)_pLimit;                                                     \
    EXPLAIN_ROW_APPEND(((sl) ? EXPLAIN_SLIMIT_FORMAT : EXPLAIN_LIMIT_FORMAT), pLimit->limit);      \
    if (pLimit->offset) {                                                                          \
      EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);                                                    \
      EXPLAIN_ROW_APPEND(((sl) ? EXPLAIN_SOFFSET_FORMAT : EXPLAIN_OFFSET_FORMAT), pLimit->offset);\
    }                                                                                              \
  }                                                                                                \
} while (0)

#define EXPLAIN_ROW_APPEND_LIMIT(_pLimit) EXPLAIN_ROW_APPEND_LIMIT_IMPL(_pLimit, false)
#define EXPLAIN_ROW_APPEND_SLIMIT(_pLimit) EXPLAIN_ROW_APPEND_LIMIT_IMPL(_pLimit, true)

D
dapan1121 已提交
178 179 180 181 182
#ifdef __cplusplus
}
#endif

#endif /*_TD_QUERY_INT_H_*/