tscLocalMerge.h 3.8 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

H
Haojun Liao 已提交
16 17
#ifndef TDENGINE_TSCLOCALMERGE_H
#define TDENGINE_TSCLOCALMERGE_H
H
hzcheng 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

H
Haojun Liao 已提交
23 24
#include "qExtbuffer.h"
#include "qFill.h"
S
slguan 已提交
25
#include "taosmsg.h"
H
hzcheng 已提交
26 27 28 29
#include "tlosertree.h"
#include "tsclient.h"

#define MAX_NUM_OF_SUBQUERY_RETRY 3
H
Haojun Liao 已提交
30
  
H
hzcheng 已提交
31 32
struct SQLFunctionCtx;

S
slguan 已提交
33
typedef struct SLocalDataSource {
H
hzcheng 已提交
34 35 36 37 38
  tExtMemBuffer *pMemBuffer;
  int32_t        flushoutIdx;
  int32_t        pageId;
  int32_t        rowIdx;
  tFilePage      filePage;
S
slguan 已提交
39
} SLocalDataSource;
H
hzcheng 已提交
40

H
Haojun Liao 已提交
41
typedef struct SLocalMerger {
S
slguan 已提交
42 43 44 45 46 47 48 49 50
  SLocalDataSource **    pLocalDataSrc;
  int32_t                numOfBuffer;
  int32_t                numOfCompleted;
  int32_t                numOfVnode;
  SLoserTreeInfo *       pLoserTree;
  char *                 prevRowOfInput;
  tFilePage *            pResultBuf;
  int32_t                nResultBufSize;
  tFilePage *            pTempBuffer;
H
hzcheng 已提交
51
  struct SQLFunctionCtx *pCtx;
H
Haojun Liao 已提交
52 53
  int32_t                rowSize;      // size of each intermediate result.
  bool                   hasPrevRow;   // cannot be released
S
slguan 已提交
54 55
  bool                   hasUnprocessedRow;
  tOrderDescriptor *     pDesc;
56
  SColumnModel *         resColModel;
H
Haojun Liao 已提交
57
  SColumnModel*          finalModel;
S
slguan 已提交
58
  tExtMemBuffer **       pExtMemBuffer;      // disk-based buffer
H
Haojun Liao 已提交
59
  SFillInfo*             pFillInfo;          // interpolation support structure
60 61
  char*                  pFinalRes;          // result data after interpo
  tFilePage*             discardData;
S
slguan 已提交
62 63
  bool                   discard;
  int32_t                offset;             // limit offset value
H
Haojun Liao 已提交
64
  bool                   orderPrjOnSTable;   // projection query on stable
H
Haojun Liao 已提交
65
} SLocalMerger;
H
hzcheng 已提交
66

S
slguan 已提交
67
typedef struct SRetrieveSupport {
68
  tExtMemBuffer **  pExtMemBuffer;     // for build loser tree
S
slguan 已提交
69
  tOrderDescriptor *pOrderDescriptor;
H
Haojun Liao 已提交
70 71
  SColumnModel*     pFinalColModel;    // colModel for final result
  SColumnModel*     pFFColModel;
H
hjxilinx 已提交
72
  int32_t           subqueryIndex;     // index of current vnode in vnode list
73
  SSqlObj *         pParentSql;
74 75
  tFilePage *       localBuffer;       // temp buffer, there is a buffer for each vnode to
  uint32_t          numOfRetry;        // record the number of retry times
H
hzcheng 已提交
76 77 78
} SRetrieveSupport;

int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOrderDescriptor **pDesc,
H
Haojun Liao 已提交
79
                                 SColumnModel **pFinalModel, SColumnModel** pFFModel, uint32_t nBufferSize);
H
hzcheng 已提交
80

H
Haojun Liao 已提交
81
void tscLocalReducerEnvDestroy(tExtMemBuffer **pMemBuffer, tOrderDescriptor *pDesc, SColumnModel *pFinalModel, SColumnModel* pFFModel,
H
hzcheng 已提交
82 83 84 85 86 87 88 89 90 91
                               int32_t numOfVnodes);

int32_t saveToBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tFilePage *pPage, void *data,
                     int32_t numOfRows, int32_t orderType);

int32_t tscFlushTmpBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tFilePage *pPage, int32_t orderType);

/*
 * create local reducer to launch the second-stage reduce process at client site
 */
H
Haojun Liao 已提交
92
void tscCreateLocalMerger(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrderDescriptor *pDesc,
H
Haojun Liao 已提交
93
                           SColumnModel *finalModel, SColumnModel *pFFModel, SSqlObj* pSql);
H
hzcheng 已提交
94

H
Haojun Liao 已提交
95
void tscDestroyLocalMerger(SSqlObj *pSql);
H
hzcheng 已提交
96

97
int32_t tscDoLocalMerge(SSqlObj *pSql);
H
hzcheng 已提交
98 99 100 101 102

#ifdef __cplusplus
}
#endif

H
Haojun Liao 已提交
103
#endif  // TDENGINE_TSCLOCALMERGE_H