queryExecutor.h 6.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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 TDENGINE_QUERYEXECUTOR_H
#define TDENGINE_QUERYEXECUTOR_H

#include "os.h"

#include "hash.h"
21
#include "tsdb.h"
22 23 24 25 26 27 28
#include "qinterpolation.h"
#include "qresultBuf.h"
#include "qsqlparser.h"
#include "qtsbuf.h"
#include "taosdef.h"
#include "tref.h"
#include "tsqlfunction.h"
H
hjxilinx 已提交
29
#include "tarray.h"
30

31 32 33 34
//typedef struct tFilePage {
//  int64_t num;
//  char    data[];
//} tFilePage;
35 36 37

struct SColumnFilterElem;
typedef bool (*__filter_func_t)(struct SColumnFilterElem* pFilter, char* val1, char* val2);
H
hjxilinx 已提交
38
typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int32_t order);
39 40 41

typedef struct SSqlGroupbyExpr {
  int16_t     tableIndex;
42
  SArray*     columnInfo;      // SArray<SColIndex>, group by columns information
43
  int16_t     numOfGroupCols;
44 45
  int16_t     orderIndex;      // order by column index
  int16_t     orderType;       // order by type: asc/desc
46 47 48 49 50 51 52 53 54 55 56 57
} SSqlGroupbyExpr;

typedef struct SPosInfo {
  int16_t pageId;
  int16_t rowId;
} SPosInfo;

typedef struct SWindowStatus {
  bool closed;
} SWindowStatus;

typedef struct SWindowResult {
H
hjxilinx 已提交
58
  uint16_t      numOfRows;   // number of rows of current  time window
59 60 61
  SPosInfo      pos;         // Position of current result in disk-based output buffer
  SResultInfo*  resultInfo;  // For each result column, there is a resultInfo
  STimeWindow   window;      // The time window that current result covers.
H
hjxilinx 已提交
62
  SWindowStatus status;      // this result status: closed or opened
63 64 65
} SWindowResult;

typedef struct SResultRec {
H
hjxilinx 已提交
66
  int64_t total;     // total generated result size in rows
67
  int64_t rows;      // current result set size in rows
H
hjxilinx 已提交
68 69 70 71
  int64_t capacity;  // capacity of current result output buffer
  
  // result size threshold in rows. If the result buffer is larger than this, pause query and return to client
  int32_t threshold;
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
} SResultRec;

typedef struct SWindowResInfo {
  SWindowResult* pResult;    // result list
  void*          hashList;   // hash list for quick access
  int16_t        type;       // data type for hash key
  int32_t        capacity;   // max capacity
  int32_t        curIndex;   // current start active index
  int32_t        size;       // number of result set
  int64_t        startTime;  // start time of the first time window for sliding query
  int64_t        prevSKey;   // previous (not completed) sliding window start key
  int64_t        threshold;  // threshold to pausing query and return closed results.
} SWindowResInfo;

typedef struct SColumnFilterElem {
  int16_t           bytes;  // column length
  __filter_func_t   fp;
  SColumnFilterInfo filterInfo;
} SColumnFilterElem;

typedef struct SSingleColumnFilterInfo {
93
  SColumnInfo        info;
94 95 96 97 98
  int32_t            numOfFilters;
  SColumnFilterElem* pFilters;
  void*              pData;
} SSingleColumnFilterInfo;

H
hjxilinx 已提交
99 100 101 102
typedef struct STableQueryInfo {  // todo merge with the STableQueryInfo struct
  int32_t     tableIndex;
  int32_t     groupIdx;       // group id in table list
  TSKEY       lastKey;
103 104 105
  int32_t     numOfRes;
  int16_t     queryRangeSet;  // denote if the query range is set, only available for interval query
  int64_t     tag;
H
hjxilinx 已提交
106
  STimeWindow win;
107
  STSCursor   cur;
H
hjxilinx 已提交
108 109
  STableId    id;             // for retrieve the page id list
  
110 111 112
  SWindowResInfo windowResInfo;
} STableQueryInfo;

H
hjxilinx 已提交
113 114 115 116 117 118 119 120
typedef struct SQueryCostSummary {
} SQueryCostSummary;

typedef struct SGroupItem {
  STableId id;
  STableQueryInfo* info;
} SGroupItem;

121 122
typedef struct SQuery {
  int16_t           numOfCols;
123 124
  int16_t           numOfTags;
  
125 126 127 128 129 130
  SOrderVal         order;
  STimeWindow       window;
  int64_t           intervalTime;
  int64_t           slidingTime;      // sliding time for sliding window query
  char              slidingTimeUnit;  // interval data type, used for daytime revise
  int8_t            precision;
131
  int16_t           numOfOutput;
132
  int16_t           fillType;
133
  int16_t           checkBuffer;  // check if the buffer is full during scan each block
134 135 136
  SLimitVal         limit;
  int32_t           rowSize;
  SSqlGroupbyExpr*  pGroupbyExpr;
H
hjxilinx 已提交
137
  SExprInfo*        pSelectExpr;
138
  SColumnInfo*      colList;
139
  SColumnInfo*      tagColList;
140 141 142 143 144
  int32_t           numOfFilterCols;
  int64_t*          defaultVal;
  uint32_t          status;  // query status
  SResultRec        rec;
  int32_t           pos;
145
  tFilePage**       sdata;
H
hjxilinx 已提交
146
  STableQueryInfo*  current;
147 148 149 150 151 152 153 154 155 156
  SSingleColumnFilterInfo* pFilterInfo;
} SQuery;

typedef struct SQueryRuntimeEnv {
  SResultInfo*       resultInfo;  // todo refactor to merge with SWindowResInfo
  SQuery*            pQuery;
  SQLFunctionCtx*    pCtx;
  int16_t            numOfRowsPerPage;
  int16_t            offset[TSDB_MAX_COLUMNS];
  uint16_t           scanFlag;  // denotes reversed scan of data or not
157
  SFillInfo* pFillInfo;
158 159 160 161 162 163
  SWindowResInfo     windowResInfo;
  STSBuf*            pTSBuf;
  STSCursor          cur;
  SQueryCostSummary  summary;
  bool               stableQuery;  // super table query or not
  void*              pQueryHandle;
164
  void*              pSecQueryHandle; // another thread for
165 166 167 168
  SDiskbasedResultBuf* pResultBuf;  // query result buffer based on blocked-wised disk file
} SQueryRuntimeEnv;

typedef struct SQInfo {
H
hjxilinx 已提交
169
  void*            signature;
170
  TSKEY            startTime;
H
hjxilinx 已提交
171
  TSKEY            elapsedTime;
H
hjxilinx 已提交
172
  int32_t          pointsInterpo;
H
hjxilinx 已提交
173
  int32_t          code;              // error code to returned to client
174
  sem_t            dataReady;
175
  void*            tsdb;
176
  int32_t          vgId;
177
  
H
hjxilinx 已提交
178 179
  STableGroupInfo  tableIdGroupInfo;  // table id list < only includes the STableId list>
  STableGroupInfo  groupInfo;         //
180
  SQueryRuntimeEnv runtimeEnv;
181
  int32_t          groupIndex;
H
hjxilinx 已提交
182
  int32_t          offset;            // offset in group result set of subgroup, todo refactor
weixin_48148422's avatar
weixin_48148422 已提交
183
  SArray*          arrTableIdInfo;
H
hjxilinx 已提交
184
  
185 186 187 188 189 190 191 192 193 194 195 196
  T_REF_DECLARE()
  /*
   * the query is executed position on which meter of the whole list.
   * when the index reaches the last one of the list, it means the query is completed.
   * We later may refactor to remove this attribution by using another flag to denote
   * whether a multimeter query is completed or not.
   */
  int32_t         tableIndex;
  int32_t         numOfGroupResultPages;
} SQInfo;

#endif  // TDENGINE_QUERYEXECUTOR_H