refactor codes.
This commit is contained in:
parent
08854f86ae
commit
08df5bf992
|
@ -112,7 +112,7 @@ typedef struct SLimitVal {
|
|||
} SLimitVal;
|
||||
|
||||
typedef struct SOrderVal {
|
||||
int32_t order;
|
||||
uint32_t order;
|
||||
int32_t orderColId;
|
||||
} SOrderVal;
|
||||
|
||||
|
|
|
@ -697,12 +697,15 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
|
|||
return BLK_DATA_NO_NEEDED;
|
||||
}
|
||||
|
||||
SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
|
||||
if (pInfo->hasResult != DATA_SET_FLAG) {
|
||||
return BLK_DATA_ALL_NEEDED;
|
||||
} else { // data in current block is not earlier than current result
|
||||
return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
|
||||
}
|
||||
// result buffer has not been set yet.
|
||||
return BLK_DATA_ALL_NEEDED;
|
||||
//todo optimize the filter info
|
||||
// SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
|
||||
// if (pInfo->hasResult != DATA_SET_FLAG) {
|
||||
// return BLK_DATA_ALL_NEEDED;
|
||||
// } else { // data in current block is not earlier than current result
|
||||
// return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
|
||||
// }
|
||||
}
|
||||
|
||||
static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId,
|
||||
|
@ -1415,7 +1418,9 @@ static void stddev_next_step(SQLFunctionCtx *pCtx) {
|
|||
*/
|
||||
pStd->stage++;
|
||||
avg_finalizer(pCtx);
|
||||
|
||||
|
||||
pResInfo->initialized = true; // set it initialized to avoid re-initialization
|
||||
|
||||
// save average value into tmpBuf, for second stage scan
|
||||
SAvgInfo *pAvg = pResInfo->interResultBuf;
|
||||
|
||||
|
@ -2078,6 +2083,7 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) {
|
|||
TSKEY *output = pCtx->ptsOutputBuf;
|
||||
for (int32_t i = 0; i < len; ++i, output += step) {
|
||||
*output = tvp[i]->timestamp;
|
||||
printf("-------------%lld\n", *output);
|
||||
}
|
||||
|
||||
// set the corresponding tag data for each record
|
||||
|
|
|
@ -765,22 +765,22 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo*
|
|||
}
|
||||
|
||||
// todo merge with following function
|
||||
static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) {
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
|
||||
int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
char * src = pFinalDataPage->data + (pRes->numOfRows - 1) * pField->bytes + pRes->numOfRows * offset;
|
||||
char * dst = pRes->data + pRes->numOfRows * offset;
|
||||
|
||||
for (int32_t j = 0; j < pRes->numOfRows; ++j) {
|
||||
memcpy(dst, src, (size_t)pField->bytes);
|
||||
dst += pField->bytes;
|
||||
src -= pField->bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
//static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) {
|
||||
//
|
||||
// for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
// TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
//
|
||||
// int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
// char * src = pFinalDataPage->data + (pRes->numOfRows - 1) * pField->bytes + pRes->numOfRows * offset;
|
||||
// char * dst = pRes->data + pRes->numOfRows * offset;
|
||||
//
|
||||
// for (int32_t j = 0; j < pRes->numOfRows; ++j) {
|
||||
// memcpy(dst, src, (size_t)pField->bytes);
|
||||
// dst += pField->bytes;
|
||||
// src -= pField->bytes;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
static void reversedCopyFromInterpolationToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage **pResPages, SLocalReducer *pLocalReducer) {
|
||||
assert(0);
|
||||
|
|
|
@ -25,7 +25,7 @@ extern "C" {
|
|||
#include "hash.h"
|
||||
#include "hashutil.h"
|
||||
|
||||
#define GET_QINFO_ADDR(x) ((char*)(x)-offsetof(SQInfo, query))
|
||||
#define GET_QINFO_ADDR(x) ((char*)(x)-offsetof(SQInfo, query))
|
||||
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0)
|
||||
|
||||
/*
|
||||
|
@ -33,10 +33,10 @@ extern "C" {
|
|||
* The page size should be sufficient for at least one output result or intermediate result.
|
||||
* Some intermediate results may be extremely large, such as top/bottom(100) query.
|
||||
*/
|
||||
#define DEFAULT_INTERN_BUF_SIZE 16384L
|
||||
#define DEFAULT_INTERN_BUF_SIZE 16384L
|
||||
|
||||
#define INIT_ALLOCATE_DISK_PAGES 60L
|
||||
#define DEFAULT_DATA_FILE_MAPPING_PAGES 2L
|
||||
#define INIT_ALLOCATE_DISK_PAGES 60L
|
||||
#define DEFAULT_DATA_FILE_MAPPING_PAGES 2L
|
||||
#define DEFAULT_DATA_FILE_MMAP_WINDOW_SIZE (DEFAULT_DATA_FILE_MAPPING_PAGES * DEFAULT_INTERN_BUF_SIZE)
|
||||
|
||||
#define IO_ENGINE_MMAP 0
|
||||
|
@ -120,7 +120,7 @@ typedef enum {
|
|||
typedef int (*__block_search_fn_t)(char* data, int num, int64_t key, int order);
|
||||
|
||||
static FORCE_INLINE SMeterObj* getMeterObj(void* hashHandle, int32_t sid) {
|
||||
return *(SMeterObj**)taosGetDataFromHashTable(hashHandle, (const char*) &sid, sizeof(sid));
|
||||
return *(SMeterObj**)taosGetDataFromHashTable(hashHandle, (const char*)&sid, sizeof(sid));
|
||||
}
|
||||
|
||||
bool isQueryKilled(SQuery* pQuery);
|
||||
|
@ -129,7 +129,7 @@ bool isPointInterpoQuery(SQuery* pQuery);
|
|||
bool isTopBottomQuery(SQuery* pQuery);
|
||||
bool isFirstLastRowQuery(SQuery* pQuery);
|
||||
bool isTSCompQuery(SQuery* pQuery);
|
||||
bool notHasQueryTimeRange(SQuery *pQuery);
|
||||
bool notHasQueryTimeRange(SQuery* pQuery);
|
||||
|
||||
bool needSupplementaryScan(SQuery* pQuery);
|
||||
bool onDemandLoadDatablock(SQuery* pQuery, int16_t queryRangeSet);
|
||||
|
@ -148,16 +148,16 @@ void vnodeScanAllData(SQueryRuntimeEnv* pRuntimeEnv);
|
|||
|
||||
int32_t vnodeQueryResultInterpolate(SQInfo* pQInfo, tFilePage** pDst, tFilePage** pDataSrc, int32_t numOfRows,
|
||||
int32_t* numOfInterpo);
|
||||
void copyResToQueryResultBuf(SMeterQuerySupportObj* pSupporter, SQuery* pQuery);
|
||||
void copyResToQueryResultBuf(STableQuerySupportObj* pSupporter, SQuery* pQuery);
|
||||
|
||||
void doSkipResults(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
void doSkipResults(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
int64_t getNumOfResult(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
|
||||
void forwardIntervalQueryRange(SMeterQuerySupportObj* pSupporter, SQueryRuntimeEnv* pRuntimeEnv);
|
||||
void forwardIntervalQueryRange(STableQuerySupportObj* pSupporter, SQueryRuntimeEnv* pRuntimeEnv);
|
||||
void forwardQueryStartPosition(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
|
||||
bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, SMeterQuerySupportObj* pSupporter,
|
||||
bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, STableQuerySupportObj* pSupporter,
|
||||
SPointInterpoSupporter* pPointInterpSupporter, int64_t* key);
|
||||
|
||||
void pointInterpSupporterInit(SQuery* pQuery, SPointInterpoSupporter* pInterpoSupport);
|
||||
|
@ -165,42 +165,46 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter* pPointInterpSupport);
|
|||
void pointInterpSupporterSetData(SQInfo* pQInfo, SPointInterpoSupporter* pPointInterpSupport);
|
||||
|
||||
int64_t loadRequiredBlockIntoMem(SQueryRuntimeEnv* pRuntimeEnv, SPositionInfo* position);
|
||||
int32_t doCloseAllOpenedResults(SMeterQuerySupportObj* pSupporter);
|
||||
void disableFunctForSuppleScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
|
||||
void enableFunctForMasterScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
|
||||
int32_t doCloseAllOpenedResults(STableQuerySupportObj* pSupporter);
|
||||
void disableFunctForSuppleScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
|
||||
void enableFunctForMasterScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
|
||||
|
||||
int32_t mergeMetersResultToOneGroups(SMeterQuerySupportObj* pSupporter);
|
||||
void copyFromGroupBuf(SQInfo* pQInfo, SWindowResult* result);
|
||||
int32_t mergeMetersResultToOneGroups(STableQuerySupportObj* pSupporter);
|
||||
void copyFromGroupBuf(SQInfo* pQInfo, SWindowResult* result);
|
||||
|
||||
SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv* pRuntimeEnv, void* pBlock, int32_t blockType);
|
||||
SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv* pRuntimeEnv, void* pBlock, int32_t blockType);
|
||||
SCacheBlock* getCacheDataBlock(SMeterObj* pMeterObj, SQueryRuntimeEnv* pRuntimeEnv, int32_t slot);
|
||||
|
||||
void queryOnBlock(SMeterQuerySupportObj* pSupporter, int32_t blockStatus, SBlockInfo* pBlockBasicInfo, SMeterDataInfo* pDataHeadInfoEx, SField* pFields,
|
||||
__block_search_fn_t searchFn);
|
||||
// void queryOnBlock(STableQuerySupportObj* pSupporter, int32_t blockStatus, SBlockInfo* pBlockBasicInfo,
|
||||
// SMeterDataInfo* pDataHeadInfoEx, SField* pFields,
|
||||
// __block_search_fn_t searchFn);
|
||||
|
||||
int32_t vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, tSidSet *pSidSet, SMeterDataInfo *pMeterDataInfo,
|
||||
int32_t *numOfMeters, SMeterDataInfo ***pReqMeterDataInfo);
|
||||
void applyIntervalQueryOnBlock(STableQuerySupportObj* pSupporter, SMeterDataInfo* pMeterDataInfo,
|
||||
SBlockInfo* pBlockInfo, SField* pFields, __block_search_fn_t searchFn);
|
||||
|
||||
int32_t vnodeFilterQualifiedMeters(SQInfo* pQInfo, int32_t vid, tSidSet* pSidSet, SMeterDataInfo* pMeterDataInfo,
|
||||
int32_t* numOfMeters, SMeterDataInfo*** pReqMeterDataInfo);
|
||||
int32_t vnodeGetVnodeHeaderFileIndex(int32_t* fid, SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
|
||||
|
||||
int32_t createDataBlocksInfoEx(SMeterDataInfo** pMeterDataInfo, int32_t numOfMeters,
|
||||
SMeterDataBlockInfoEx** pDataBlockInfoEx, int32_t numOfCompBlocks,
|
||||
int32_t* nAllocBlocksInfoSize, int64_t addr);
|
||||
void freeMeterBlockInfoEx(SMeterDataBlockInfoEx* pDataBlockInfoEx, int32_t len);
|
||||
void freeMeterBlockInfoEx(SMeterDataBlockInfoEx* pDataBlockInfoEx, int32_t len);
|
||||
|
||||
void setExecutionContext(SMeterQuerySupportObj* pSupporter, SWindowResult* outputRes, int32_t meterIdx, int32_t groupIdx,
|
||||
SMeterQueryInfo* sqinfo);
|
||||
int32_t setIntervalQueryExecutionContext(SMeterQuerySupportObj* pSupporter, int32_t meterIdx, SMeterQueryInfo* sqinfo);
|
||||
void doGetAlignedIntervalQueryRangeImpl(SQuery *pQuery, int64_t pKey, int64_t keyFirst, int64_t keyLast,
|
||||
int64_t *actualSkey, int64_t *actualEkey, int64_t *skey, int64_t *ekey);
|
||||
void setExecutionContext(STableQuerySupportObj* pSupporter, SWindowResult* outputRes, int32_t meterIdx,
|
||||
int32_t groupIdx, SMeterQueryInfo* sqinfo);
|
||||
int32_t setIntervalQueryExecutionContext(STableQuerySupportObj* pSupporter, int32_t meterIdx, SMeterQueryInfo* sqinfo);
|
||||
void doGetAlignedIntervalQueryRangeImpl(SQuery* pQuery, int64_t pKey, int64_t keyFirst, int64_t keyLast,
|
||||
int64_t* actualSkey, int64_t* actualEkey, int64_t* skey, int64_t* ekey);
|
||||
|
||||
int64_t getQueryStartPositionInCache(SQueryRuntimeEnv* pRuntimeEnv, int32_t* slot, int32_t* pos, bool ignoreQueryRange);
|
||||
int64_t getQueryStartPositionInCache(SQueryRuntimeEnv* pRuntimeEnv, int32_t* slot, int32_t* pos, bool ignoreQueryRange);
|
||||
int64_t getNextAccessedKeyInData(SQuery* pQuery, int64_t* pPrimaryCol, SBlockInfo* pBlockInfo, int32_t blockStatus);
|
||||
|
||||
int32_t getDataBlocksForMeters(SMeterQuerySupportObj* pSupporter, SQuery* pQuery, int32_t numOfMeters,
|
||||
const char* filePath, SMeterDataInfo** pMeterDataInfo, uint32_t* numOfBlocks);
|
||||
int32_t getDataBlocksForMeters(STableQuerySupportObj* pSupporter, SQuery* pQuery, int32_t numOfMeters,
|
||||
const char* filePath, SMeterDataInfo** pMeterDataInfo, uint32_t* numOfBlocks);
|
||||
int32_t LoadDatablockOnDemand(SCompBlock* pBlock, SField** pFields, uint8_t* blkStatus, SQueryRuntimeEnv* pRuntimeEnv,
|
||||
int32_t fileIdx, int32_t slotIdx, __block_search_fn_t searchFn, bool onDemand);
|
||||
int32_t vnodeGetHeaderFile(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex);
|
||||
int32_t vnodeGetHeaderFile(SQueryRuntimeEnv* pRuntimeEnv, int32_t fileIndex);
|
||||
|
||||
/**
|
||||
* Create SMeterQueryInfo.
|
||||
|
@ -210,14 +214,14 @@ int32_t vnodeGetHeaderFile(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex);
|
|||
* @param ekey
|
||||
* @return
|
||||
*/
|
||||
SMeterQueryInfo* createMeterQueryInfo(SMeterQuerySupportObj *pSupporter, int32_t sid, TSKEY skey, TSKEY ekey);
|
||||
SMeterQueryInfo* createMeterQueryInfo(STableQuerySupportObj* pSupporter, int32_t sid, TSKEY skey, TSKEY ekey);
|
||||
|
||||
/**
|
||||
* Destroy meter query info
|
||||
* @param pMeterQInfo
|
||||
* @param numOfCols
|
||||
*/
|
||||
void destroyMeterQueryInfo(SMeterQueryInfo *pMeterQueryInfo, int32_t numOfCols);
|
||||
void destroyMeterQueryInfo(SMeterQueryInfo* pMeterQueryInfo, int32_t numOfCols);
|
||||
|
||||
/**
|
||||
* change the meter query info for supplement scan
|
||||
|
@ -225,7 +229,8 @@ void destroyMeterQueryInfo(SMeterQueryInfo *pMeterQueryInfo, int32_t numOfCols);
|
|||
* @param skey
|
||||
* @param ekey
|
||||
*/
|
||||
void changeMeterQueryInfoForSuppleQuery(SQueryDiskbasedResultBuf* pResultBuf, SMeterQueryInfo *pMeterQueryInfo, TSKEY skey, TSKEY ekey);
|
||||
void changeMeterQueryInfoForSuppleQuery(SQueryDiskbasedResultBuf* pResultBuf, SMeterQueryInfo* pMeterQueryInfo,
|
||||
TSKEY skey, TSKEY ekey);
|
||||
|
||||
/**
|
||||
* add the new allocated disk page to meter query info
|
||||
|
@ -234,7 +239,8 @@ void changeMeterQueryInfoForSuppleQuery(SQueryDiskbasedResultBuf* pResultBuf, SM
|
|||
* @param pMeterQueryInfo
|
||||
* @param pSupporter
|
||||
*/
|
||||
tFilePage* addDataPageForMeterQueryInfo(SQuery* pQuery, SMeterQueryInfo *pMeterQueryInfo, SMeterQuerySupportObj *pSupporter);
|
||||
tFilePage* addDataPageForMeterQueryInfo(SQuery* pQuery, SMeterQueryInfo* pMeterQueryInfo,
|
||||
STableQuerySupportObj* pSupporter);
|
||||
|
||||
/**
|
||||
* save the query range data into SMeterQueryInfo
|
||||
|
@ -258,7 +264,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv* pRuntimeEnv, SMeterQueryInfo* p
|
|||
* @param pSupporter
|
||||
* @param key
|
||||
*/
|
||||
void setIntervalQueryRange(SMeterQueryInfo *pMeterQueryInfo, SMeterQuerySupportObj* pSupporter, int64_t key);
|
||||
void setIntervalQueryRange(SMeterQueryInfo* pMeterQueryInfo, STableQuerySupportObj* pSupporter, int64_t key);
|
||||
|
||||
/**
|
||||
* set the meter data information
|
||||
|
@ -275,19 +281,20 @@ void vnodeCheckIfDataExists(SQueryRuntimeEnv* pRuntimeEnv, SMeterObj* pMeterObj,
|
|||
|
||||
void displayInterResult(SData** pdata, SQuery* pQuery, int32_t numOfRows);
|
||||
|
||||
void vnodePrintQueryStatistics(SMeterQuerySupportObj* pSupporter);
|
||||
void vnodePrintQueryStatistics(STableQuerySupportObj* pSupporter);
|
||||
|
||||
void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pOneOutputRes);
|
||||
void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult* dst, const SWindowResult* src);
|
||||
void clearTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* pOneOutputRes);
|
||||
void copyTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* dst, const SWindowResult* src);
|
||||
|
||||
int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t size, int32_t threshold, int16_t type);
|
||||
int32_t initWindowResInfo(SWindowResInfo* pWindowResInfo, SQueryRuntimeEnv* pRuntimeEnv, int32_t size,
|
||||
int32_t threshold, int16_t type);
|
||||
|
||||
void cleanupTimeWindowInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRuntimeEnv);
|
||||
void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo* pWindowResInfo);
|
||||
void clearClosedTimeWindow(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
void cleanupTimeWindowInfo(SWindowResInfo* pWindowResInfo, SQueryRuntimeEnv* pRuntimeEnv);
|
||||
void resetTimeWindowInfo(SQueryRuntimeEnv* pRuntimeEnv, SWindowResInfo* pWindowResInfo);
|
||||
void clearClosedTimeWindow(SQueryRuntimeEnv* pRuntimeEnv);
|
||||
int32_t numOfClosedTimeWindow(SWindowResInfo* pWindowResInfo);
|
||||
void closeTimeWindow(SWindowResInfo* pWindowResInfo, int32_t slot);
|
||||
void closeAllTimeWindow(SWindowResInfo* pWindowResInfo);
|
||||
void closeTimeWindow(SWindowResInfo* pWindowResInfo, int32_t slot);
|
||||
void closeAllTimeWindow(SWindowResInfo* pWindowResInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -101,7 +101,6 @@ typedef struct SWindowStatus {
|
|||
|
||||
typedef struct SWindowResult {
|
||||
uint16_t numOfRows;
|
||||
int16_t nAlloc;
|
||||
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.
|
||||
|
@ -191,8 +190,8 @@ typedef struct SMeterQueryInfo {
|
|||
int64_t skey;
|
||||
int64_t ekey;
|
||||
int32_t numOfRes;
|
||||
int32_t reverseIndex; // reversed output indicator, start from (numOfRes-1)
|
||||
int16_t reverseFillRes; // denote if reverse fill the results in supplementary scan required or not
|
||||
// int32_t reverseIndex; // reversed output indicator, start from (numOfRes-1)
|
||||
// int16_t reverseFillRes; // denote if reverse fill the results in supplementary scan required or not
|
||||
int16_t queryRangeSet; // denote if the query range is set, only available for interval query
|
||||
int16_t lastResRows;
|
||||
int64_t tag;
|
||||
|
@ -213,7 +212,7 @@ typedef struct SMeterDataInfo {
|
|||
SMeterQueryInfo* pMeterQInfo;
|
||||
} SMeterDataInfo;
|
||||
|
||||
typedef struct SMeterQuerySupportObj {
|
||||
typedef struct STableQuerySupportObj {
|
||||
void* pMetersHashTable; // meter table hash list
|
||||
|
||||
SMeterSidExtInfo** pMeterSidExtInfo;
|
||||
|
@ -248,7 +247,7 @@ typedef struct SMeterQuerySupportObj {
|
|||
SMeterDataInfo* pMeterDataInfo;
|
||||
|
||||
TSKEY* tsList;
|
||||
} SMeterQuerySupportObj;
|
||||
} STableQuerySupportObj;
|
||||
|
||||
typedef struct _qinfo {
|
||||
uint64_t signature;
|
||||
|
@ -274,18 +273,18 @@ typedef struct _qinfo {
|
|||
SMeterObj* pObj;
|
||||
sem_t dataReady;
|
||||
|
||||
SMeterQuerySupportObj* pMeterQuerySupporter;
|
||||
STableQuerySupportObj* pTableQuerySupporter;
|
||||
int (*fp)(SMeterObj*, SQuery*);
|
||||
} SQInfo;
|
||||
|
||||
int32_t vnodeQuerySingleTablePrepare(SQInfo* pQInfo, SMeterObj* pMeterObj, SMeterQuerySupportObj* pSMultiMeterObj,
|
||||
int32_t vnodeQueryTablePrepare(SQInfo* pQInfo, SMeterObj* pMeterObj, STableQuerySupportObj* pSMultiMeterObj,
|
||||
void* param);
|
||||
|
||||
void vnodeQueryFreeQInfoEx(SQInfo* pQInfo);
|
||||
|
||||
bool vnodeParametersSafetyCheck(SQuery* pQuery);
|
||||
|
||||
int32_t vnodeMultiMeterQueryPrepare(SQInfo* pQInfo, SQuery* pQuery, void* param);
|
||||
int32_t vnodeSTableQueryPrepare(SQInfo* pQInfo, SQuery* pQuery, void* param);
|
||||
|
||||
/**
|
||||
* decrease the numofQuery of each table that is queried, enable the
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -26,8 +26,9 @@
|
|||
|
||||
#include "vnodeQueryImpl.h"
|
||||
|
||||
#define ALL_CACHE_BLOCKS_CHECKED(q) \
|
||||
(((q)->slot == (q)->currentSlot && QUERY_IS_ASC_QUERY(q)) || ((q)->slot == (q)->firstSlot && (!QUERY_IS_ASC_QUERY(q))))
|
||||
#define ALL_CACHE_BLOCKS_CHECKED(q) \
|
||||
(((q)->slot == (q)->currentSlot && QUERY_IS_ASC_QUERY(q)) || \
|
||||
((q)->slot == (q)->firstSlot && (!QUERY_IS_ASC_QUERY(q))))
|
||||
|
||||
#define FORWARD_CACHE_BLOCK_CHECK_SLOT(slot, step, maxblocks) (slot) = ((slot) + (step) + (maxblocks)) % (maxblocks);
|
||||
|
||||
|
@ -47,23 +48,10 @@ static bool isGroupbyEachTable(SSqlGroupbyExpr *pGroupbyExpr, tSidSet *pSidset)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool doCheckWithPrevQueryRange(SQInfo *pQInfo, TSKEY nextKey, SMeterDataInfo *pMeterInfo) {
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
SMeterObj * pMeterObj = pMeterInfo->pMeterObj;
|
||||
|
||||
/* no data for current query */
|
||||
static bool doCheckWithPrevQueryRange(SQuery *pQuery, TSKEY nextKey) {
|
||||
if ((nextKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
(nextKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
|
||||
if (((nextKey > pSupporter->rawEKey) && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
((nextKey < pSupporter->rawEKey) && (!QUERY_IS_ASC_QUERY(pQuery)))) {
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, no data qualified in block, ignore", pQInfo, pMeterObj->vnode,
|
||||
pMeterObj->sid, pMeterObj->meterId);
|
||||
|
||||
return false;
|
||||
} else { // in case of interval query, forward the query range
|
||||
setIntervalQueryRange(pMeterInfo->pMeterQInfo, pSupporter, nextKey);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -86,8 +74,8 @@ static void setStartPositionForCacheBlock(SQuery *pQuery, SCacheBlock *pBlock, b
|
|||
}
|
||||
|
||||
static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||
SQuery* pQuery = pRuntimeEnv->pQuery;
|
||||
|
||||
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||
|
||||
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
|
||||
SResultInfo *pResInfo = GET_RES_INFO(&pRuntimeEnv->pCtx[i]);
|
||||
if (pResInfo != NULL) {
|
||||
|
@ -98,8 +86,8 @@ static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
|
|||
|
||||
static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
|
||||
|
||||
SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
|
||||
|
||||
|
@ -132,7 +120,8 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
|||
pRuntimeEnv->pMeterObj = pMeterObj;
|
||||
|
||||
if (pMeterInfo[k].pMeterQInfo == NULL) {
|
||||
pMeterInfo[k].pMeterQInfo = createMeterQueryInfo(pSupporter, pMeterObj->sid, pSupporter->rawSKey, pSupporter->rawEKey);
|
||||
pMeterInfo[k].pMeterQInfo =
|
||||
createMeterQueryInfo(pSupporter, pMeterObj->sid, pSupporter->rawSKey, pSupporter->rawEKey);
|
||||
}
|
||||
|
||||
if (pMeterInfo[k].pMeterObj == NULL) { // no data in disk for this meter, set its pointer
|
||||
|
@ -154,29 +143,18 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
|||
vnodeUpdateQueryColumnIndex(pQuery, pMeterObj);
|
||||
vnodeUpdateFilterColumnIndex(pQuery);
|
||||
|
||||
if (pQuery->intervalTime == 0) {
|
||||
if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
(pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
|
||||
dTrace(
|
||||
"QInfo:%p vid:%d sid:%d id:%s, query completed, ignore data in cache. qrange:%" PRId64 "-%" PRId64 ", "
|
||||
"lastKey:%" PRId64,
|
||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey,
|
||||
pQuery->lastKey);
|
||||
if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
(pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, query completed, ignore data in cache. qrange:%" PRId64 "-%" PRId64
|
||||
", lastKey:%" PRId64,
|
||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey,
|
||||
pQuery->lastKey);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
setExecutionContext(pSupporter, pRuntimeEnv->windowResInfo.pResult, k, pMeterInfo[k].groupIdx, pMeterQueryInfo);
|
||||
} else {
|
||||
int32_t ret = setIntervalQueryExecutionContext(pSupporter, k, pMeterQueryInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
pQInfo->killed = 1;
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
qTrace("QInfo:%p vid:%d sid:%d id:%s, query in cache, qrange:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64, pQInfo, pMeterObj->vnode,
|
||||
pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery->lastKey);
|
||||
qTrace("QInfo:%p vid:%d sid:%d id:%s, query in cache, qrange:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64, pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery->lastKey);
|
||||
|
||||
/*
|
||||
* find the appropriated start position in cache
|
||||
|
@ -186,7 +164,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
|||
* should be ignored (the fourth parameter).
|
||||
*/
|
||||
TSKEY nextKey = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, true);
|
||||
if (nextKey < 0) {
|
||||
if (nextKey < 0 || !doCheckWithPrevQueryRange(pQuery, nextKey)) {
|
||||
qTrace("QInfo:%p vid:%d sid:%d id:%s, no data qualified in cache, cache blocks:%d, lastKey:%" PRId64, pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->numOfBlocks, pQuery->lastKey);
|
||||
continue;
|
||||
|
@ -199,10 +177,6 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!doCheckWithPrevQueryRange(pQInfo, nextKey, &pMeterInfo[k])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool firstCheckSlot = true;
|
||||
SCacheInfo *pCacheInfo = (SCacheInfo *)pMeterObj->pCache;
|
||||
|
||||
|
@ -224,14 +198,29 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
|||
|
||||
setStartPositionForCacheBlock(pQuery, pBlock, &firstCheckSlot);
|
||||
|
||||
TSKEY* primaryKeys = (TSKEY*) pRuntimeEnv->primaryColBuffer->data;
|
||||
|
||||
TSKEY *primaryKeys = (TSKEY *)pRuntimeEnv->primaryColBuffer->data;
|
||||
TSKEY key = primaryKeys[pQuery->pos];
|
||||
|
||||
// in handling file data block, the timestamp range validation is done during fetching candidate file blocks
|
||||
if ((primaryKeys[pQuery->pos] > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
(primaryKeys[pQuery->pos] < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) {
|
||||
if ((key > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
(key < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (pQuery->intervalTime == 0) {
|
||||
setExecutionContext(pSupporter, pRuntimeEnv->windowResInfo.pResult, k, pMeterInfo[k].groupIdx,
|
||||
pMeterQueryInfo);
|
||||
} else {
|
||||
int32_t ret = setIntervalQueryExecutionContext(pSupporter, k, pMeterQueryInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
pQInfo->killed = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
qTrace("QInfo:%p vid:%d sid:%d id:%s, query in cache, qrange:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64, pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery->lastKey);
|
||||
|
||||
// only record the key on last block
|
||||
SET_CACHE_BLOCK_FLAG(pRuntimeEnv->blockStatus);
|
||||
SBlockInfo binfo = getBlockBasicInfo(pRuntimeEnv, pBlock, BLK_CACHE_BLOCK);
|
||||
|
@ -241,7 +230,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
|||
pRuntimeEnv->blockStatus);
|
||||
|
||||
totalBlocks++;
|
||||
queryOnBlock(pSupporter, pRuntimeEnv->blockStatus, &binfo, &pMeterInfo[k], NULL, searchFn);
|
||||
applyIntervalQueryOnBlock(pSupporter, &pMeterInfo[k], &binfo, NULL, searchFn);
|
||||
|
||||
if (ALL_CACHE_BLOCKS_CHECKED(pQuery)) {
|
||||
break;
|
||||
|
@ -266,7 +255,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
|||
|
||||
static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo) {
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
SMeterDataBlockInfoEx *pDataBlockInfoEx = NULL;
|
||||
int32_t nAllocBlocksInfoSize = 0;
|
||||
|
@ -274,9 +263,9 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
SMeterObj * pTempMeter = getMeterObj(pSupporter->pMetersHashTable, pSupporter->pMeterSidExtInfo[0]->sid);
|
||||
__block_search_fn_t searchFn = vnodeSearchKeyFunc[pTempMeter->searchAlgorithm];
|
||||
|
||||
int32_t vnodeId = pTempMeter->vnode;
|
||||
SQueryFilesInfo* pVnodeFileInfo = &pRuntimeEnv->vnodeFileInfo;
|
||||
|
||||
int32_t vnodeId = pTempMeter->vnode;
|
||||
SQueryFilesInfo *pVnodeFileInfo = &pRuntimeEnv->vnodeFileInfo;
|
||||
|
||||
dTrace("QInfo:%p start to check data blocks in %d files", pQInfo, pVnodeFileInfo->numOfFiles);
|
||||
|
||||
int32_t fid = QUERY_IS_ASC_QUERY(pQuery) ? -1 : INT32_MAX;
|
||||
|
@ -304,25 +293,25 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
fid += step;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
int32_t numOfQualifiedMeters = 0;
|
||||
assert(fileIdx == pRuntimeEnv->vnodeFileInfo.current);
|
||||
|
||||
|
||||
SMeterDataInfo **pReqMeterDataInfo = NULL;
|
||||
int32_t ret = vnodeFilterQualifiedMeters(pQInfo, vnodeId, pSupporter->pSidSet, pMeterDataInfo,
|
||||
int32_t ret = vnodeFilterQualifiedMeters(pQInfo, vnodeId, pSupporter->pSidSet, pMeterDataInfo,
|
||||
&numOfQualifiedMeters, &pReqMeterDataInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
dError("QInfo:%p failed to create meterdata struct to perform query processing, abort", pQInfo);
|
||||
|
||||
|
||||
tfree(pReqMeterDataInfo);
|
||||
pQInfo->code = -ret;
|
||||
pQInfo->killed = 1;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
dTrace("QInfo:%p file:%s, %d meters qualified", pQInfo, pVnodeFileInfo->dataFilePath, numOfQualifiedMeters);
|
||||
|
||||
|
||||
// none of meters in query set have pHeaderFileData in this file, try next file
|
||||
if (numOfQualifiedMeters == 0) {
|
||||
fid += step;
|
||||
|
@ -335,17 +324,17 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
pReqMeterDataInfo, &numOfBlocks);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
dError("QInfo:%p failed to get data block before scan data blocks, abort", pQInfo);
|
||||
|
||||
|
||||
tfree(pReqMeterDataInfo);
|
||||
pQInfo->code = -ret;
|
||||
pQInfo->killed = 1;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
dTrace("QInfo:%p file:%s, %d meters contains %d blocks to be checked", pQInfo, pVnodeFileInfo->dataFilePath,
|
||||
numOfQualifiedMeters, numOfBlocks);
|
||||
|
||||
|
||||
if (numOfBlocks == 0) {
|
||||
fid += step;
|
||||
tfree(pReqMeterDataInfo);
|
||||
|
@ -353,7 +342,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
}
|
||||
|
||||
ret = createDataBlocksInfoEx(pReqMeterDataInfo, numOfQualifiedMeters, &pDataBlockInfoEx, numOfBlocks,
|
||||
&nAllocBlocksInfoSize, (int64_t)pQInfo);
|
||||
&nAllocBlocksInfoSize, (int64_t)pQInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS) { // failed to create data blocks
|
||||
dError("QInfo:%p build blockInfoEx failed, abort", pQInfo);
|
||||
tfree(pReqMeterDataInfo);
|
||||
|
@ -383,8 +372,8 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
stimeUnit = taosGetTimestampMs();
|
||||
} else if ((j % TRACE_OUTPUT_BLOCK_CNT) == 0) {
|
||||
etimeUnit = taosGetTimestampMs();
|
||||
dTrace("QInfo:%p load and check %" PRId64 " blocks, and continue. elapsed:%" PRId64 " ms", pQInfo, TRACE_OUTPUT_BLOCK_CNT,
|
||||
etimeUnit - stimeUnit);
|
||||
dTrace("QInfo:%p load and check %" PRId64 " blocks, and continue. elapsed:%" PRId64 " ms", pQInfo,
|
||||
TRACE_OUTPUT_BLOCK_CNT, etimeUnit - stimeUnit);
|
||||
stimeUnit = taosGetTimestampMs();
|
||||
}
|
||||
|
||||
|
@ -398,27 +387,14 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
|
||||
restoreIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
|
||||
|
||||
if (pQuery->intervalTime == 0) { // normal query
|
||||
if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
(pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
|
||||
qTrace(
|
||||
"QInfo:%p vid:%d sid:%d id:%s, query completed, no need to scan this data block. qrange:%" PRId64 "-%" PRId64 ", "
|
||||
"lastKey:%" PRId64,
|
||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey,
|
||||
pQuery->lastKey);
|
||||
if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||
(pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
|
||||
qTrace("QInfo:%p vid:%d sid:%d id:%s, query completed, no need to scan this data block. qrange:%" PRId64
|
||||
"-%" PRId64 ", lastKey:%" PRId64,
|
||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey,
|
||||
pQuery->lastKey);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
setExecutionContext(pSupporter, pRuntimeEnv->windowResInfo.pResult, pOneMeterDataInfo->meterOrderIdx,
|
||||
pOneMeterDataInfo->groupIdx, pMeterQueryInfo);
|
||||
} else if (pQuery->intervalTime > 0 && pQuery->slidingTime == -1){ // interval query
|
||||
ret = setIntervalQueryExecutionContext(pSupporter, pOneMeterDataInfo->meterOrderIdx, pMeterQueryInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
tfree(pReqMeterDataInfo); // error code has been set
|
||||
pQInfo->killed = 1;
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
SCompBlock *pBlock = pInfoEx->pBlock.compBlock;
|
||||
|
@ -431,14 +407,17 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
}
|
||||
|
||||
SBlockInfo binfo = getBlockBasicInfo(pRuntimeEnv, pBlock, BLK_FILE_BLOCK);
|
||||
int64_t nextKey = -1;
|
||||
|
||||
int64_t nextKey = -1;
|
||||
|
||||
assert(pQuery->pos >= 0 && pQuery->pos < pBlock->numOfPoints);
|
||||
TSKEY *primaryKeys = (TSKEY *)pRuntimeEnv->primaryColBuffer->data;
|
||||
|
||||
if (IS_DATA_BLOCK_LOADED(pRuntimeEnv->blockStatus) && needPrimaryTimestampCol(pQuery, &binfo)) {
|
||||
nextKey = primaryKeys[pQuery->pos];
|
||||
if (!doCheckWithPrevQueryRange(pQInfo, nextKey, pOneMeterDataInfo)) {
|
||||
|
||||
if (!doCheckWithPrevQueryRange(pQuery, nextKey)) {
|
||||
qTrace("QInfo:%p vid:%d sid:%d id:%s, no data qualified in data file, lastKey:%" PRId64, pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->numOfBlocks, pQuery->lastKey);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
|
@ -447,9 +426,12 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
(pBlock->keyFirst >= pQuery->ekey && pBlock->keyLast <= pQuery->lastKey && !QUERY_IS_ASC_QUERY(pQuery)));
|
||||
}
|
||||
|
||||
if (pQuery->intervalTime > 0 && pQuery->slidingTime > 0) {
|
||||
if (pQuery->intervalTime == 0) {
|
||||
setExecutionContext(pSupporter, pRuntimeEnv->windowResInfo.pResult, pOneMeterDataInfo->meterOrderIdx,
|
||||
pOneMeterDataInfo->groupIdx, pMeterQueryInfo);
|
||||
} else /* if (pQuery->intervalTime > 0)*/ { // interval query
|
||||
setIntervalQueryRange(pMeterQueryInfo, pSupporter, nextKey);
|
||||
|
||||
|
||||
ret = setIntervalQueryExecutionContext(pSupporter, pOneMeterDataInfo->meterOrderIdx, pMeterQueryInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
tfree(pReqMeterDataInfo); // error code has been set
|
||||
|
@ -457,8 +439,8 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
queryOnBlock(pSupporter, pRuntimeEnv->blockStatus, &binfo, pOneMeterDataInfo, pInfoEx->pBlock.fields, searchFn);
|
||||
|
||||
applyIntervalQueryOnBlock(pSupporter, pOneMeterDataInfo, &binfo, pInfoEx->pBlock.fields, searchFn);
|
||||
}
|
||||
|
||||
tfree(pReqMeterDataInfo);
|
||||
|
@ -481,7 +463,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
|||
|
||||
static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *dataInCache, int32_t index,
|
||||
int32_t start) {
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
|
||||
SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
|
@ -497,13 +479,13 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *
|
|||
|
||||
vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pMeterSidExtInfo[index]);
|
||||
|
||||
dTrace("QInfo:%p query on (%d): vid:%d sid:%d meterId:%s, qrange:%" PRId64 "-%" PRId64, pQInfo, index - start, pMeterObj->vnode,
|
||||
pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey);
|
||||
dTrace("QInfo:%p query on (%d): vid:%d sid:%d meterId:%s, qrange:%" PRId64 "-%" PRId64, pQInfo, index - start,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey);
|
||||
|
||||
pQInfo->pObj = pMeterObj;
|
||||
pQuery->lastKey = pQuery->skey;
|
||||
pRuntimeEnv->pMeterObj = pMeterObj;
|
||||
|
||||
|
||||
vnodeUpdateQueryColumnIndex(pQuery, pRuntimeEnv->pMeterObj);
|
||||
vnodeUpdateFilterColumnIndex(pQuery);
|
||||
|
||||
|
@ -511,8 +493,8 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *
|
|||
|
||||
// data in file or cache is not qualified for the query. abort
|
||||
if (!(dataInCache || dataInDisk)) {
|
||||
dTrace("QInfo:%p vid:%d sid:%d meterId:%s, qrange:%" PRId64 "-%" PRId64 ", nores, %p", pQInfo, pMeterObj->vnode, pMeterObj->sid,
|
||||
pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery);
|
||||
dTrace("QInfo:%p vid:%d sid:%d meterId:%s, qrange:%" PRId64 "-%" PRId64 ", nores, %p", pQInfo, pMeterObj->vnode,
|
||||
pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -536,7 +518,7 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *
|
|||
|
||||
static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start) {
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
|
||||
bool dataInDisk = true;
|
||||
|
@ -567,7 +549,7 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start
|
|||
pointInterpSupporterDestroy(&pointInterpSupporter);
|
||||
|
||||
vnodeScanAllData(pRuntimeEnv);
|
||||
|
||||
|
||||
// first/last_row query, do not invoke the finalize for super table query
|
||||
doFinalizeResult(pRuntimeEnv);
|
||||
|
||||
|
@ -591,7 +573,7 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start
|
|||
* @param pQInfo
|
||||
*/
|
||||
static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
|
||||
SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
|
@ -600,10 +582,10 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
tSidSet *pSids = pSupporter->pSidSet;
|
||||
|
||||
int32_t vid = getMeterObj(pSupporter->pMetersHashTable, pMeterSidExtInfo[0]->sid)->vnode;
|
||||
|
||||
|
||||
if (isPointInterpoQuery(pQuery)) {
|
||||
resetCtxOutputBuf(pRuntimeEnv);
|
||||
|
||||
|
||||
assert(pQuery->limit.offset == 0 && pQuery->limit.limit != 0);
|
||||
|
||||
while (pSupporter->subgroupIdx < pSids->numOfSubSet) {
|
||||
|
@ -611,8 +593,8 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
int32_t end = pSids->starterPos[pSupporter->subgroupIdx + 1] - 1;
|
||||
|
||||
if (isFirstLastRowQuery(pQuery)) {
|
||||
dTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid,
|
||||
pSids->numOfSubSet, pSupporter->subgroupIdx);
|
||||
dTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pSids->numOfSubSet,
|
||||
pSupporter->subgroupIdx);
|
||||
|
||||
TSKEY key = -1;
|
||||
int32_t index = -1;
|
||||
|
@ -644,8 +626,8 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
int64_t num = doCheckMetersInGroup(pQInfo, index, start);
|
||||
assert(num >= 0);
|
||||
} else {
|
||||
dTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid,
|
||||
pSids->numOfSubSet, pSupporter->subgroupIdx);
|
||||
dTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pSids->numOfSubSet,
|
||||
pSupporter->subgroupIdx);
|
||||
|
||||
for (int32_t k = start; k <= end; ++k) {
|
||||
if (isQueryKilled(pQuery)) {
|
||||
|
@ -692,10 +674,10 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
if (pSupporter->meterIdx >= pSids->numOfSids) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
resetCtxOutputBuf(pRuntimeEnv);
|
||||
resetTimeWindowInfo(pRuntimeEnv, &pRuntimeEnv->windowResInfo);
|
||||
|
||||
|
||||
while (pSupporter->meterIdx < pSupporter->numOfMeters) {
|
||||
int32_t k = pSupporter->meterIdx;
|
||||
|
||||
|
@ -703,9 +685,8 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
setQueryStatus(pQuery, QUERY_NO_DATA_TO_CHECK);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
TSKEY skey = pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[k]->key;
|
||||
TSKEY skey = pQInfo->pTableQuerySupporter->pMeterSidExtInfo[k]->key;
|
||||
if (skey > 0) {
|
||||
pQuery->skey = skey;
|
||||
}
|
||||
|
@ -758,10 +739,10 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
pSupporter->meterIdx = pSupporter->pSidSet->numOfSids;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// enable execution for next table, when handling the projection query
|
||||
enableExecutionForNextTable(pRuntimeEnv);
|
||||
|
||||
|
||||
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK | QUERY_COMPLETED)) {
|
||||
/*
|
||||
* query range is identical in terms of all meters involved in query,
|
||||
|
@ -773,7 +754,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
pQuery->ekey = pSupporter->rawEKey;
|
||||
pSupporter->meterIdx++;
|
||||
|
||||
pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[k]->key = pQuery->lastKey;
|
||||
pQInfo->pTableQuerySupporter->pMeterSidExtInfo[k]->key = pQuery->lastKey;
|
||||
|
||||
// if the buffer is full or group by each table, we need to jump out of the loop
|
||||
if (Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL) ||
|
||||
|
@ -781,7 +762,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
break;
|
||||
}
|
||||
|
||||
} else { // forward query range
|
||||
} else { // forward query range
|
||||
pQuery->skey = pQuery->lastKey;
|
||||
|
||||
// all data in the result buffer are skipped due to the offset, continue to retrieve data from current meter
|
||||
|
@ -789,7 +770,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
assert(!Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL));
|
||||
continue;
|
||||
} else {
|
||||
pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[k]->key = pQuery->lastKey;
|
||||
pQInfo->pTableQuerySupporter->pMeterSidExtInfo[k]->key = pQuery->lastKey;
|
||||
// buffer is full, wait for the next round to retrieve data from current meter
|
||||
assert(Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL));
|
||||
break;
|
||||
|
@ -819,19 +800,19 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
|
||||
// todo refactor
|
||||
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
||||
SWindowResInfo* pWindowResInfo = &pRuntimeEnv->windowResInfo;
|
||||
|
||||
SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo;
|
||||
|
||||
for (int32_t i = 0; i < pWindowResInfo->size; ++i) {
|
||||
SWindowStatus* pStatus = &pWindowResInfo->pResult[i].status;
|
||||
pStatus->closed = true; // enable return all results for group by normal columns
|
||||
|
||||
SWindowStatus *pStatus = &pWindowResInfo->pResult[i].status;
|
||||
pStatus->closed = true; // enable return all results for group by normal columns
|
||||
|
||||
SWindowResult *pResult = &pWindowResInfo->pResult[i];
|
||||
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
|
||||
pResult->numOfRows = MAX(pResult->numOfRows, pResult->resultInfo[j].numOfRes);
|
||||
}
|
||||
}
|
||||
|
||||
pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
|
||||
pQInfo->pTableQuerySupporter->subgroupIdx = 0;
|
||||
pQuery->pointsRead = 0;
|
||||
copyFromGroupBuf(pQInfo, pWindowResInfo->pResult);
|
||||
}
|
||||
|
@ -842,12 +823,12 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
|
|||
dTrace(
|
||||
"QInfo %p vid:%d, numOfMeters:%d, index:%d, numOfGroups:%d, %d points returned, totalRead:%d totalReturn:%d,"
|
||||
"next skey:%" PRId64 ", offset:%" PRId64,
|
||||
pQInfo, vid, pSids->numOfSids, pSupporter->meterIdx, pSids->numOfSubSet, pQuery->pointsRead,
|
||||
pQInfo->pointsRead, pQInfo->pointsReturned, pQuery->skey, pQuery->limit.offset);
|
||||
pQInfo, vid, pSids->numOfSids, pSupporter->meterIdx, pSids->numOfSubSet, pQuery->pointsRead, pQInfo->pointsRead,
|
||||
pQInfo->pointsReturned, pQuery->skey, pQuery->limit.offset);
|
||||
}
|
||||
|
||||
static void doOrderedScan(SQInfo *pQInfo) {
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
|
||||
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
||||
|
@ -867,17 +848,16 @@ static void doOrderedScan(SQInfo *pQInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
static void setupMeterQueryInfoForSupplementQuery(SMeterQuerySupportObj *pSupporter) {
|
||||
static void setupMeterQueryInfoForSupplementQuery(STableQuerySupportObj *pSupporter) {
|
||||
for (int32_t i = 0; i < pSupporter->numOfMeters; ++i) {
|
||||
SMeterQueryInfo *pMeterQueryInfo = pSupporter->pMeterDataInfo[i].pMeterQInfo;
|
||||
SQueryDiskbasedResultBuf* pResultBuf = pSupporter->runtimeEnv.pResultBuf;
|
||||
|
||||
SMeterQueryInfo * pMeterQueryInfo = pSupporter->pMeterDataInfo[i].pMeterQInfo;
|
||||
SQueryDiskbasedResultBuf *pResultBuf = pSupporter->runtimeEnv.pResultBuf;
|
||||
changeMeterQueryInfoForSuppleQuery(pResultBuf, pMeterQueryInfo, pSupporter->rawSKey, pSupporter->rawEKey);
|
||||
}
|
||||
}
|
||||
|
||||
static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) {
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
|
||||
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
|
@ -898,7 +878,9 @@ static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) {
|
|||
setupMeterQueryInfoForSupplementQuery(pSupporter);
|
||||
|
||||
int64_t st = taosGetTimestampMs();
|
||||
|
||||
doOrderedScan(pQInfo);
|
||||
|
||||
int64_t et = taosGetTimestampMs();
|
||||
dTrace("QInfo:%p supplementary scan completed, elapsed time: %lldms", pQInfo, et - st);
|
||||
|
||||
|
@ -917,8 +899,8 @@ static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) {
|
|||
}
|
||||
|
||||
static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
SQueryRuntimeEnv* pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
|
||||
if (pSupporter->subgroupIdx > 0) {
|
||||
|
@ -954,8 +936,8 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
|
|||
return;
|
||||
}
|
||||
|
||||
dTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", order:%d, group:%d", pQInfo, pSupporter->rawSKey, pSupporter->rawEKey,
|
||||
pQuery->order.order, pSupporter->pSidSet->numOfSubSet);
|
||||
dTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", order:%d, group:%d", pQInfo, pSupporter->rawSKey,
|
||||
pSupporter->rawEKey, pQuery->order.order, pSupporter->pSidSet->numOfSubSet);
|
||||
|
||||
dTrace("QInfo:%p main query scan start", pQInfo);
|
||||
int64_t st = taosGetTimestampMs();
|
||||
|
@ -965,11 +947,20 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
|
|||
pQuery->order.order ^ 1);
|
||||
|
||||
// failed to save all intermediate results into disk, abort further query processing
|
||||
if (doCloseAllOpenedResults(pSupporter) != TSDB_CODE_SUCCESS) {
|
||||
dError("QInfo:%p failed to save intermediate results, abort further query processing", pQInfo);
|
||||
return;
|
||||
// if (doCloseAllOpenedResults(pSupporter) != TSDB_CODE_SUCCESS) {
|
||||
// dError("QInfo:%p failed to save intermediate results, abort further query processing", pQInfo);
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (pQuery->intervalTime > 0) {
|
||||
for (int32_t i = 0; i < pSupporter->numOfMeters; ++i) {
|
||||
SMeterQueryInfo *pMeterQueryInfo = pSupporter->pMeterDataInfo[i].pMeterQInfo;
|
||||
closeAllTimeWindow(&pMeterQueryInfo->windowResInfo);
|
||||
}
|
||||
} else { // close results for group result
|
||||
closeAllTimeWindow(&pRuntimeEnv->windowResInfo);
|
||||
}
|
||||
|
||||
|
||||
doMultiMeterSupplementaryScan(pQInfo);
|
||||
|
||||
if (isQueryKilled(pQuery)) {
|
||||
|
@ -982,7 +973,7 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
|
|||
|
||||
if (mergeMetersResultToOneGroups(pSupporter) == TSDB_CODE_SUCCESS) {
|
||||
copyResToQueryResultBuf(pSupporter, pQuery);
|
||||
|
||||
|
||||
#ifdef _DEBUG_VIEW
|
||||
displayInterResult(pQuery->sdata, pQuery, pQuery->sdata[0]->len);
|
||||
#endif
|
||||
|
@ -1005,7 +996,7 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
|
|||
*/
|
||||
static void vnodeSingleTableFixedOutputProcessor(SQInfo *pQInfo) {
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv;
|
||||
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
|
||||
|
||||
assert(pQuery->slot >= 0 && pQuery->pos >= 0);
|
||||
|
||||
|
@ -1036,7 +1027,7 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
|
|||
SQuery * pQuery = &pQInfo->query;
|
||||
SMeterObj *pMeterObj = pQInfo->pObj;
|
||||
|
||||
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv;
|
||||
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
|
||||
|
||||
// for ts_comp query, re-initialized is not allowed
|
||||
if (!isTSCompQuery(pQuery)) {
|
||||
|
@ -1067,8 +1058,9 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
|
|||
TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
|
||||
assert(nextTimestamp > 0 || ((nextTimestamp < 0) && Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)));
|
||||
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, skip current result, offset:%" PRId64 ", next qrange:%" PRId64 "-%" PRId64, pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->limit.offset, pQuery->lastKey, pQuery->ekey);
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, skip current result, offset:%" PRId64 ", next qrange:%" PRId64 "-%" PRId64,
|
||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->limit.offset, pQuery->lastKey,
|
||||
pQuery->ekey);
|
||||
|
||||
resetCtxOutputBuf(pRuntimeEnv);
|
||||
}
|
||||
|
@ -1080,8 +1072,8 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
|
|||
TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
|
||||
assert(nextTimestamp > 0 || ((nextTimestamp < 0) && Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)));
|
||||
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, query abort due to buffer limitation, next qrange:%" PRId64 "-%" PRId64, pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->lastKey, pQuery->ekey);
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, query abort due to buffer limitation, next qrange:%" PRId64 "-%" PRId64,
|
||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->lastKey, pQuery->ekey);
|
||||
}
|
||||
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, %d points returned, totalRead:%d totalReturn:%d", pQInfo, pMeterObj->vnode,
|
||||
|
@ -1093,13 +1085,13 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv) {
|
||||
static void vnodeSingleMeterIntervalMainLooper(STableQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv) {
|
||||
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||
|
||||
while (1) {
|
||||
initCtxOutputBuf(pRuntimeEnv);
|
||||
clearClosedTimeWindow(pRuntimeEnv);
|
||||
|
||||
|
||||
vnodeScanAllData(pRuntimeEnv);
|
||||
if (isQueryKilled(pQuery)) {
|
||||
return;
|
||||
|
@ -1113,21 +1105,22 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
|
|||
|
||||
// here we can ignore the records in case of no interpolation
|
||||
if ((pQuery->numOfFilterCols > 0 || pRuntimeEnv->pTSBuf != NULL) && pQuery->limit.offset > 0 &&
|
||||
pQuery->interpoType == TSDB_INTERPO_NONE) { // maxOutput <= 0, means current query does not generate any results
|
||||
pQuery->interpoType == TSDB_INTERPO_NONE) {
|
||||
// maxOutput <= 0, means current query does not generate any results
|
||||
// todo handle offset, in case of top/bottom interval query
|
||||
if (maxOutput > 0) {
|
||||
pQuery->limit.offset--;
|
||||
}
|
||||
} else {
|
||||
// assert(0);
|
||||
// pQuery->pointsRead += maxOutput;
|
||||
// forwardCtxOutputBuf(pRuntimeEnv, maxOutput);
|
||||
// assert(0);
|
||||
// pQuery->pointsRead += maxOutput;
|
||||
// forwardCtxOutputBuf(pRuntimeEnv, maxOutput);
|
||||
}
|
||||
|
||||
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK|QUERY_COMPLETED)) {
|
||||
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK | QUERY_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
|
||||
if (Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL)) {
|
||||
break;
|
||||
|
@ -1151,7 +1144,7 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
|
|||
SQuery * pQuery = &(pQInfo->query);
|
||||
SMeterObj *pMeterObj = pQInfo->pObj;
|
||||
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||
|
||||
int32_t numOfInterpo = 0;
|
||||
|
@ -1159,13 +1152,13 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
|
|||
while (1) {
|
||||
resetCtxOutputBuf(pRuntimeEnv);
|
||||
vnodeSingleMeterIntervalMainLooper(pSupporter, pRuntimeEnv);
|
||||
|
||||
|
||||
if (pQuery->intervalTime > 0) {
|
||||
pSupporter->subgroupIdx = 0;
|
||||
pQuery->pointsRead = 0;
|
||||
copyFromGroupBuf(pQInfo, pRuntimeEnv->windowResInfo.pResult);
|
||||
}
|
||||
|
||||
|
||||
// the offset is handled at prepare stage if no interpolation involved
|
||||
if (pQuery->interpoType == TSDB_INTERPO_NONE) {
|
||||
doRevisedResultsByLimit(pQInfo);
|
||||
|
@ -1192,7 +1185,7 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
|
|||
pQuery->pointsRead = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// all data scanned, the group by normal column can return
|
||||
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
||||
pSupporter->subgroupIdx = 0;
|
||||
|
@ -1211,7 +1204,7 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
|
|||
void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
||||
SQInfo *pQInfo = (SQInfo *)pMsg->ahandle;
|
||||
|
||||
if (pQInfo == NULL || pQInfo->pMeterQuerySupporter == NULL) {
|
||||
if (pQInfo == NULL || pQInfo->pTableQuerySupporter == NULL) {
|
||||
dTrace("%p freed abort query", pQInfo);
|
||||
return;
|
||||
}
|
||||
|
@ -1219,7 +1212,7 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
|||
if (pQInfo->killed) {
|
||||
dTrace("QInfo:%p it is already killed, abort", pQInfo);
|
||||
vnodeDecRefCount(pQInfo);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1231,7 +1224,7 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
|||
dTrace("vid:%d sid:%d id:%s, query thread is created, numOfQueries:%d, QInfo:%p", pMeterObj->vnode, pMeterObj->sid,
|
||||
pMeterObj->meterId, pMeterObj->numOfQueries, pQInfo);
|
||||
|
||||
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv;
|
||||
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
|
||||
assert(pRuntimeEnv->pMeterObj == pMeterObj);
|
||||
|
||||
if (vnodeHasRemainResults(pQInfo)) {
|
||||
|
@ -1267,8 +1260,8 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
|||
// continue to get push data from the group result
|
||||
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
||||
pQuery->pointsRead = 0;
|
||||
if (pQInfo->pMeterQuerySupporter->subgroupIdx > 0) {
|
||||
copyFromGroupBuf(pQInfo, pQInfo->pMeterQuerySupporter->runtimeEnv.windowResInfo.pResult);
|
||||
if (pQInfo->pTableQuerySupporter->subgroupIdx > 0) {
|
||||
copyFromGroupBuf(pQInfo, pQInfo->pTableQuerySupporter->runtimeEnv.windowResInfo.pResult);
|
||||
pQInfo->pointsRead += pQuery->pointsRead;
|
||||
|
||||
if (pQuery->pointsRead > 0) {
|
||||
|
@ -1278,19 +1271,19 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
|||
|
||||
sem_post(&pQInfo->dataReady);
|
||||
vnodeDecRefCount(pQInfo);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pQInfo->over = 1;
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, query over, %d points are returned", pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQInfo->pointsRead);
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, query over, %d points are returned", pQInfo, pMeterObj->vnode, pMeterObj->sid,
|
||||
pMeterObj->meterId, pQInfo->pointsRead);
|
||||
|
||||
vnodePrintQueryStatistics(pQInfo->pMeterQuerySupporter);
|
||||
vnodePrintQueryStatistics(pQInfo->pTableQuerySupporter);
|
||||
sem_post(&pQInfo->dataReady);
|
||||
|
||||
|
||||
vnodeDecRefCount(pQInfo);
|
||||
return;
|
||||
}
|
||||
|
@ -1323,8 +1316,8 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
|||
dTrace("QInfo:%p query is killed", pQInfo);
|
||||
pQInfo->over = 1;
|
||||
} else {
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, meter query thread completed, %d points are returned",
|
||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead);
|
||||
dTrace("QInfo:%p vid:%d sid:%d id:%s, meter query thread completed, %d points are returned", pQInfo,
|
||||
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead);
|
||||
}
|
||||
|
||||
sem_post(&pQInfo->dataReady);
|
||||
|
@ -1334,7 +1327,7 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
|||
void vnodeMultiMeterQuery(SSchedMsg *pMsg) {
|
||||
SQInfo *pQInfo = (SQInfo *)pMsg->ahandle;
|
||||
|
||||
if (pQInfo == NULL || pQInfo->pMeterQuerySupporter == NULL) {
|
||||
if (pQInfo == NULL || pQInfo->pTableQuerySupporter == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1365,10 +1358,10 @@ void vnodeMultiMeterQuery(SSchedMsg *pMsg) {
|
|||
pQInfo->useconds += (taosGetTimestampUs() - st);
|
||||
pQInfo->over = isQueryKilled(pQuery) ? 1 : 0;
|
||||
|
||||
taosInterpoSetStartInfo(&pQInfo->pMeterQuerySupporter->runtimeEnv.interpoInfo, pQuery->pointsRead,
|
||||
taosInterpoSetStartInfo(&pQInfo->pTableQuerySupporter->runtimeEnv.interpoInfo, pQuery->pointsRead,
|
||||
pQInfo->query.interpoType);
|
||||
|
||||
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
|
||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||
|
||||
if (pQuery->pointsRead == 0) {
|
||||
pQInfo->over = 1;
|
||||
|
|
|
@ -648,7 +648,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
|
|||
goto _error;
|
||||
}
|
||||
|
||||
SMeterQuerySupportObj *pSupporter = (SMeterQuerySupportObj *)calloc(1, sizeof(SMeterQuerySupportObj));
|
||||
STableQuerySupportObj *pSupporter = (STableQuerySupportObj *)calloc(1, sizeof(STableQuerySupportObj));
|
||||
pSupporter->numOfMeters = 1;
|
||||
|
||||
pSupporter->pMetersHashTable = taosInitHashTable(pSupporter->numOfMeters, taosIntHash_32, false);
|
||||
|
@ -659,7 +659,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
|
|||
pSupporter->subgroupIdx = -1;
|
||||
pSupporter->pMeterSidExtInfo = NULL;
|
||||
|
||||
pQInfo->pMeterQuerySupporter = pSupporter;
|
||||
pQInfo->pTableQuerySupporter = pSupporter;
|
||||
|
||||
STSBuf *pTSBuf = NULL;
|
||||
if (pQueryMsg->tsLen > 0) {
|
||||
|
@ -670,7 +670,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
|
|||
tsBufNextPos(pTSBuf);
|
||||
}
|
||||
|
||||
if (((*code) = vnodeQuerySingleTablePrepare(pQInfo, pQInfo->pObj, pSupporter, pTSBuf)) != TSDB_CODE_SUCCESS) {
|
||||
if (((*code) = vnodeQueryTablePrepare(pQInfo, pQInfo->pObj, pSupporter, pTSBuf)) != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
@ -739,7 +739,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
|
|||
|
||||
SSchedMsg schedMsg = {0};
|
||||
|
||||
SMeterQuerySupportObj *pSupporter = (SMeterQuerySupportObj *)calloc(1, sizeof(SMeterQuerySupportObj));
|
||||
STableQuerySupportObj *pSupporter = (STableQuerySupportObj *)calloc(1, sizeof(STableQuerySupportObj));
|
||||
pSupporter->numOfMeters = pQueryMsg->numOfSids;
|
||||
|
||||
pSupporter->pMetersHashTable = taosInitHashTable(pSupporter->numOfMeters, taosIntHash_32, false);
|
||||
|
@ -784,7 +784,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
|
|||
(SSchema *)pQueryMsg->pTagSchema, pQueryMsg->numOfTagsCols, NULL, 0);
|
||||
}
|
||||
|
||||
pQInfo->pMeterQuerySupporter = pSupporter;
|
||||
pQInfo->pTableQuerySupporter = pSupporter;
|
||||
|
||||
STSBuf *pTSBuf = NULL;
|
||||
if (pQueryMsg->tsLen > 0) {
|
||||
|
@ -794,7 +794,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
|
|||
tsBufResetPos(pTSBuf);
|
||||
}
|
||||
|
||||
if (((*code) = vnodeMultiMeterQueryPrepare(pQInfo, pQuery, pTSBuf)) != TSDB_CODE_SUCCESS) {
|
||||
if (((*code) = vnodeSTableQueryPrepare(pQInfo, pQuery, pTSBuf)) != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
@ -898,8 +898,8 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
|
|||
|
||||
SSchedMsg schedMsg = {0};
|
||||
|
||||
if (pQInfo->pMeterQuerySupporter != NULL) {
|
||||
if (pQInfo->pMeterQuerySupporter->pSidSet == NULL) {
|
||||
if (pQInfo->pTableQuerySupporter != NULL) {
|
||||
if (pQInfo->pTableQuerySupporter->pSidSet == NULL) {
|
||||
schedMsg.fp = vnodeSingleTableQuery;
|
||||
} else { // group by tag
|
||||
schedMsg.fp = vnodeMultiMeterQuery;
|
||||
|
|
|
@ -446,8 +446,8 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
|
|||
// buffer size for progress information, including meter count,
|
||||
// and for each meter, including 'uid' and 'TSKEY'.
|
||||
int progressSize = 0;
|
||||
if (pQInfo->pMeterQuerySupporter != NULL)
|
||||
progressSize = pQInfo->pMeterQuerySupporter->numOfMeters * (sizeof(int64_t) + sizeof(TSKEY)) + sizeof(int32_t);
|
||||
if (pQInfo->pTableQuerySupporter != NULL)
|
||||
progressSize = pQInfo->pTableQuerySupporter->numOfMeters * (sizeof(int64_t) + sizeof(TSKEY)) + sizeof(int32_t);
|
||||
else if (pQInfo->pObj != NULL)
|
||||
progressSize = sizeof(int64_t) + sizeof(TSKEY) + sizeof(int32_t);
|
||||
|
||||
|
@ -486,13 +486,13 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
|
|||
// write the progress information of each meter to response
|
||||
// this is required by subscriptions
|
||||
if (numOfRows > 0 && code == TSDB_CODE_SUCCESS) {
|
||||
if (pQInfo->pMeterQuerySupporter != NULL && pQInfo->pMeterQuerySupporter->pMeterSidExtInfo != NULL) {
|
||||
*((int32_t *)pMsg) = htonl(pQInfo->pMeterQuerySupporter->numOfMeters);
|
||||
if (pQInfo->pTableQuerySupporter != NULL && pQInfo->pTableQuerySupporter->pMeterSidExtInfo != NULL) {
|
||||
*((int32_t *)pMsg) = htonl(pQInfo->pTableQuerySupporter->numOfMeters);
|
||||
pMsg += sizeof(int32_t);
|
||||
for (int32_t i = 0; i < pQInfo->pMeterQuerySupporter->numOfMeters; i++) {
|
||||
*((int64_t *)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->uid);
|
||||
for (int32_t i = 0; i < pQInfo->pTableQuerySupporter->numOfMeters; i++) {
|
||||
*((int64_t *)pMsg) = htobe64(pQInfo->pTableQuerySupporter->pMeterSidExtInfo[i]->uid);
|
||||
pMsg += sizeof(int64_t);
|
||||
*((TSKEY *)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->key);
|
||||
*((TSKEY *)pMsg) = htobe64(pQInfo->pTableQuerySupporter->pMeterSidExtInfo[i]->key);
|
||||
pMsg += sizeof(TSKEY);
|
||||
}
|
||||
} else if (pQInfo->pObj != NULL) {
|
||||
|
|
Loading…
Reference in New Issue