tresultBuf.h 2.8 KB
Newer Older
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/>.
 */

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#ifndef TDENGINE_VNODEQUERYUTIL_H
#define TDENGINE_VNODEQUERYUTIL_H

#ifdef __cplusplus
extern "C" {
#endif

#include "os.h"
#include "textbuffer.h"

typedef struct SIDList {
  uint32_t alloc;
  int32_t  size;
  int32_t* pData;
} SIDList;

32
typedef struct SQueryDiskbasedResultBuf {
33 34 35 36 37 38 39 40 41 42 43 44
  int32_t  numOfRowsPerPage;
  int32_t  numOfPages;
  int64_t  totalBufSize;
  int32_t  fd;                  // data file fd
  int32_t  allocateId;          // allocated page id
  int32_t  incStep;             // minimum allocated pages
  char*    pBuf;                // mmap buffer pointer
  char*    path;                // file path
  
  uint32_t numOfAllocGroupIds;  // number of allocated id list
  void*    idsTable;            // id hash table
  SIDList* list;                // for each id, there is a page id list
45
} SQueryDiskbasedResultBuf;
46 47 48 49 50 51 52 53

/**
 * create disk-based result buffer
 * @param pResultBuf
 * @param size
 * @param rowSize
 * @return
 */
54
int32_t createDiskbasedResultBuffer(SQueryDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize);
55 56 57 58 59 60 61 62

/**
 *
 * @param pResultBuf
 * @param groupId
 * @param pageId
 * @return
 */
63
tFilePage* getNewDataBuf(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
64 65 66 67 68 69

/**
 *
 * @param pResultBuf
 * @return
 */
70
int32_t getNumOfRowsPerPage(SQueryDiskbasedResultBuf* pResultBuf);
71 72 73 74 75 76 77

/**
 *
 * @param pResultBuf
 * @param groupId
 * @return
 */
78
SIDList getDataBufPagesIdList(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId);
79 80 81 82 83 84 85

/**
 * get the specified buffer page by id
 * @param pResultBuf
 * @param id
 * @return
 */
86
tFilePage* getResultBufferPageById(SQueryDiskbasedResultBuf* pResultBuf, int32_t id);
87 88 89 90 91 92

/**
 * get the total buffer size in the format of disk file
 * @param pResultBuf
 * @return
 */
93
int32_t getResBufSize(SQueryDiskbasedResultBuf* pResultBuf);
94 95 96 97 98 99

/**
 * get the number of groups in the result buffer
 * @param pResultBuf
 * @return
 */
100
int32_t getNumOfResultBufGroupId(SQueryDiskbasedResultBuf* pResultBuf);
101 102 103 104 105

/**
 * destroy result buffer
 * @param pResultBuf
 */
106
void destroyResultBuf(SQueryDiskbasedResultBuf* pResultBuf);
107 108 109 110 111 112 113 114 115 116 117 118 119

/**
 *
 * @param pList
 * @return
 */
int32_t getLastPageId(SIDList *pList);

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_VNODEQUERYUTIL_H