提交 08df5bf9 编写于 作者: H hjxilinx

refactor codes.

上级 08854f86
...@@ -112,7 +112,7 @@ typedef struct SLimitVal { ...@@ -112,7 +112,7 @@ typedef struct SLimitVal {
} SLimitVal; } SLimitVal;
typedef struct SOrderVal { typedef struct SOrderVal {
int32_t order; uint32_t order;
int32_t orderColId; int32_t orderColId;
} SOrderVal; } SOrderVal;
......
...@@ -697,12 +697,15 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY ...@@ -697,12 +697,15 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes); // result buffer has not been set yet.
if (pInfo->hasResult != DATA_SET_FLAG) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} else { // data in current block is not earlier than current result //todo optimize the filter info
return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_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;
// }
} }
static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId, static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId,
...@@ -1416,6 +1419,8 @@ static void stddev_next_step(SQLFunctionCtx *pCtx) { ...@@ -1416,6 +1419,8 @@ static void stddev_next_step(SQLFunctionCtx *pCtx) {
pStd->stage++; pStd->stage++;
avg_finalizer(pCtx); avg_finalizer(pCtx);
pResInfo->initialized = true; // set it initialized to avoid re-initialization
// save average value into tmpBuf, for second stage scan // save average value into tmpBuf, for second stage scan
SAvgInfo *pAvg = pResInfo->interResultBuf; SAvgInfo *pAvg = pResInfo->interResultBuf;
...@@ -2078,6 +2083,7 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) { ...@@ -2078,6 +2083,7 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) {
TSKEY *output = pCtx->ptsOutputBuf; TSKEY *output = pCtx->ptsOutputBuf;
for (int32_t i = 0; i < len; ++i, output += step) { for (int32_t i = 0; i < len; ++i, output += step) {
*output = tvp[i]->timestamp; *output = tvp[i]->timestamp;
printf("-------------%lld\n", *output);
} }
// set the corresponding tag data for each record // set the corresponding tag data for each record
......
...@@ -765,22 +765,22 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo* ...@@ -765,22 +765,22 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo*
} }
// todo merge with following function // todo merge with following function
static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) { //static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) {
//
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) { // for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i); // TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
//
int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i); // int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
char * src = pFinalDataPage->data + (pRes->numOfRows - 1) * pField->bytes + pRes->numOfRows * offset; // char * src = pFinalDataPage->data + (pRes->numOfRows - 1) * pField->bytes + pRes->numOfRows * offset;
char * dst = pRes->data + pRes->numOfRows * offset; // char * dst = pRes->data + pRes->numOfRows * offset;
//
for (int32_t j = 0; j < pRes->numOfRows; ++j) { // for (int32_t j = 0; j < pRes->numOfRows; ++j) {
memcpy(dst, src, (size_t)pField->bytes); // memcpy(dst, src, (size_t)pField->bytes);
dst += pField->bytes; // dst += pField->bytes;
src -= pField->bytes; // src -= pField->bytes;
} // }
} // }
} //}
static void reversedCopyFromInterpolationToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage **pResPages, SLocalReducer *pLocalReducer) { static void reversedCopyFromInterpolationToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage **pResPages, SLocalReducer *pLocalReducer) {
assert(0); assert(0);
......
...@@ -120,7 +120,7 @@ typedef enum { ...@@ -120,7 +120,7 @@ typedef enum {
typedef int (*__block_search_fn_t)(char* data, int num, int64_t key, int order); 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) { 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); bool isQueryKilled(SQuery* pQuery);
...@@ -129,7 +129,7 @@ bool isPointInterpoQuery(SQuery* pQuery); ...@@ -129,7 +129,7 @@ bool isPointInterpoQuery(SQuery* pQuery);
bool isTopBottomQuery(SQuery* pQuery); bool isTopBottomQuery(SQuery* pQuery);
bool isFirstLastRowQuery(SQuery* pQuery); bool isFirstLastRowQuery(SQuery* pQuery);
bool isTSCompQuery(SQuery* pQuery); bool isTSCompQuery(SQuery* pQuery);
bool notHasQueryTimeRange(SQuery *pQuery); bool notHasQueryTimeRange(SQuery* pQuery);
bool needSupplementaryScan(SQuery* pQuery); bool needSupplementaryScan(SQuery* pQuery);
bool onDemandLoadDatablock(SQuery* pQuery, int16_t queryRangeSet); bool onDemandLoadDatablock(SQuery* pQuery, int16_t queryRangeSet);
...@@ -148,16 +148,16 @@ void vnodeScanAllData(SQueryRuntimeEnv* pRuntimeEnv); ...@@ -148,16 +148,16 @@ void vnodeScanAllData(SQueryRuntimeEnv* pRuntimeEnv);
int32_t vnodeQueryResultInterpolate(SQInfo* pQInfo, tFilePage** pDst, tFilePage** pDataSrc, int32_t numOfRows, int32_t vnodeQueryResultInterpolate(SQInfo* pQInfo, tFilePage** pDst, tFilePage** pDataSrc, int32_t numOfRows,
int32_t* numOfInterpo); int32_t* numOfInterpo);
void copyResToQueryResultBuf(SMeterQuerySupportObj* pSupporter, SQuery* pQuery); void copyResToQueryResultBuf(STableQuerySupportObj* pSupporter, SQuery* pQuery);
void doSkipResults(SQueryRuntimeEnv* pRuntimeEnv); void doSkipResults(SQueryRuntimeEnv* pRuntimeEnv);
void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv); void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv);
int64_t getNumOfResult(SQueryRuntimeEnv* pRuntimeEnv); int64_t getNumOfResult(SQueryRuntimeEnv* pRuntimeEnv);
void forwardIntervalQueryRange(SMeterQuerySupportObj* pSupporter, SQueryRuntimeEnv* pRuntimeEnv); void forwardIntervalQueryRange(STableQuerySupportObj* pSupporter, SQueryRuntimeEnv* pRuntimeEnv);
void forwardQueryStartPosition(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); SPointInterpoSupporter* pPointInterpSupporter, int64_t* key);
void pointInterpSupporterInit(SQuery* pQuery, SPointInterpoSupporter* pInterpoSupport); void pointInterpSupporterInit(SQuery* pQuery, SPointInterpoSupporter* pInterpoSupport);
...@@ -165,21 +165,25 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter* pPointInterpSupport); ...@@ -165,21 +165,25 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter* pPointInterpSupport);
void pointInterpSupporterSetData(SQInfo* pQInfo, SPointInterpoSupporter* pPointInterpSupport); void pointInterpSupporterSetData(SQInfo* pQInfo, SPointInterpoSupporter* pPointInterpSupport);
int64_t loadRequiredBlockIntoMem(SQueryRuntimeEnv* pRuntimeEnv, SPositionInfo* position); int64_t loadRequiredBlockIntoMem(SQueryRuntimeEnv* pRuntimeEnv, SPositionInfo* position);
int32_t doCloseAllOpenedResults(SMeterQuerySupportObj* pSupporter); int32_t doCloseAllOpenedResults(STableQuerySupportObj* pSupporter);
void disableFunctForSuppleScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order); void disableFunctForSuppleScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
void enableFunctForMasterScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order); void enableFunctForMasterScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
int32_t mergeMetersResultToOneGroups(SMeterQuerySupportObj* pSupporter); int32_t mergeMetersResultToOneGroups(STableQuerySupportObj* pSupporter);
void copyFromGroupBuf(SQInfo* pQInfo, SWindowResult* result); 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); SCacheBlock* getCacheDataBlock(SMeterObj* pMeterObj, SQueryRuntimeEnv* pRuntimeEnv, int32_t slot);
void queryOnBlock(SMeterQuerySupportObj* pSupporter, int32_t blockStatus, SBlockInfo* pBlockBasicInfo, SMeterDataInfo* pDataHeadInfoEx, SField* pFields, // void queryOnBlock(STableQuerySupportObj* pSupporter, int32_t blockStatus, SBlockInfo* pBlockBasicInfo,
__block_search_fn_t searchFn); // SMeterDataInfo* pDataHeadInfoEx, SField* pFields,
// __block_search_fn_t searchFn);
int32_t vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, tSidSet *pSidSet, SMeterDataInfo *pMeterDataInfo, void applyIntervalQueryOnBlock(STableQuerySupportObj* pSupporter, SMeterDataInfo* pMeterDataInfo,
int32_t *numOfMeters, SMeterDataInfo ***pReqMeterDataInfo); 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 vnodeGetVnodeHeaderFileIndex(int32_t* fid, SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
int32_t createDataBlocksInfoEx(SMeterDataInfo** pMeterDataInfo, int32_t numOfMeters, int32_t createDataBlocksInfoEx(SMeterDataInfo** pMeterDataInfo, int32_t numOfMeters,
...@@ -187,20 +191,20 @@ int32_t createDataBlocksInfoEx(SMeterDataInfo** pMeterDataInfo, int32_t numOfMet ...@@ -187,20 +191,20 @@ int32_t createDataBlocksInfoEx(SMeterDataInfo** pMeterDataInfo, int32_t numOfMet
int32_t* nAllocBlocksInfoSize, int64_t addr); 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, void setExecutionContext(STableQuerySupportObj* pSupporter, SWindowResult* outputRes, int32_t meterIdx,
SMeterQueryInfo* sqinfo); int32_t groupIdx, SMeterQueryInfo* sqinfo);
int32_t setIntervalQueryExecutionContext(SMeterQuerySupportObj* pSupporter, int32_t meterIdx, 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, 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* 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); int64_t getNextAccessedKeyInData(SQuery* pQuery, int64_t* pPrimaryCol, SBlockInfo* pBlockInfo, int32_t blockStatus);
int32_t getDataBlocksForMeters(SMeterQuerySupportObj* pSupporter, SQuery* pQuery, int32_t numOfMeters, int32_t getDataBlocksForMeters(STableQuerySupportObj* pSupporter, SQuery* pQuery, int32_t numOfMeters,
const char* filePath, SMeterDataInfo** pMeterDataInfo, uint32_t* numOfBlocks); const char* filePath, SMeterDataInfo** pMeterDataInfo, uint32_t* numOfBlocks);
int32_t LoadDatablockOnDemand(SCompBlock* pBlock, SField** pFields, uint8_t* blkStatus, SQueryRuntimeEnv* pRuntimeEnv, 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 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. * Create SMeterQueryInfo.
...@@ -210,14 +214,14 @@ int32_t vnodeGetHeaderFile(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex); ...@@ -210,14 +214,14 @@ int32_t vnodeGetHeaderFile(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex);
* @param ekey * @param ekey
* @return * @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 * Destroy meter query info
* @param pMeterQInfo * @param pMeterQInfo
* @param numOfCols * @param numOfCols
*/ */
void destroyMeterQueryInfo(SMeterQueryInfo *pMeterQueryInfo, int32_t numOfCols); void destroyMeterQueryInfo(SMeterQueryInfo* pMeterQueryInfo, int32_t numOfCols);
/** /**
* change the meter query info for supplement scan * change the meter query info for supplement scan
...@@ -225,7 +229,8 @@ void destroyMeterQueryInfo(SMeterQueryInfo *pMeterQueryInfo, int32_t numOfCols); ...@@ -225,7 +229,8 @@ void destroyMeterQueryInfo(SMeterQueryInfo *pMeterQueryInfo, int32_t numOfCols);
* @param skey * @param skey
* @param ekey * @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 * add the new allocated disk page to meter query info
...@@ -234,7 +239,8 @@ void changeMeterQueryInfoForSuppleQuery(SQueryDiskbasedResultBuf* pResultBuf, SM ...@@ -234,7 +239,8 @@ void changeMeterQueryInfoForSuppleQuery(SQueryDiskbasedResultBuf* pResultBuf, SM
* @param pMeterQueryInfo * @param pMeterQueryInfo
* @param pSupporter * @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 * save the query range data into SMeterQueryInfo
...@@ -258,7 +264,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv* pRuntimeEnv, SMeterQueryInfo* p ...@@ -258,7 +264,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv* pRuntimeEnv, SMeterQueryInfo* p
* @param pSupporter * @param pSupporter
* @param key * @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 * set the meter data information
...@@ -275,15 +281,16 @@ void vnodeCheckIfDataExists(SQueryRuntimeEnv* pRuntimeEnv, SMeterObj* pMeterObj, ...@@ -275,15 +281,16 @@ void vnodeCheckIfDataExists(SQueryRuntimeEnv* pRuntimeEnv, SMeterObj* pMeterObj,
void displayInterResult(SData** pdata, SQuery* pQuery, int32_t numOfRows); void displayInterResult(SData** pdata, SQuery* pQuery, int32_t numOfRows);
void vnodePrintQueryStatistics(SMeterQuerySupportObj* pSupporter); void vnodePrintQueryStatistics(STableQuerySupportObj* pSupporter);
void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pOneOutputRes); void clearTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* pOneOutputRes);
void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult* dst, const SWindowResult* src); 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 cleanupTimeWindowInfo(SWindowResInfo* pWindowResInfo, SQueryRuntimeEnv* pRuntimeEnv);
void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo* pWindowResInfo); void resetTimeWindowInfo(SQueryRuntimeEnv* pRuntimeEnv, SWindowResInfo* pWindowResInfo);
void clearClosedTimeWindow(SQueryRuntimeEnv* pRuntimeEnv); void clearClosedTimeWindow(SQueryRuntimeEnv* pRuntimeEnv);
int32_t numOfClosedTimeWindow(SWindowResInfo* pWindowResInfo); int32_t numOfClosedTimeWindow(SWindowResInfo* pWindowResInfo);
void closeTimeWindow(SWindowResInfo* pWindowResInfo, int32_t slot); void closeTimeWindow(SWindowResInfo* pWindowResInfo, int32_t slot);
......
...@@ -101,7 +101,6 @@ typedef struct SWindowStatus { ...@@ -101,7 +101,6 @@ typedef struct SWindowStatus {
typedef struct SWindowResult { typedef struct SWindowResult {
uint16_t numOfRows; uint16_t numOfRows;
int16_t nAlloc;
SPosInfo pos; // Position of current result in disk-based output buffer SPosInfo pos; // Position of current result in disk-based output buffer
SResultInfo* resultInfo; // For each result column, there is a resultInfo SResultInfo* resultInfo; // For each result column, there is a resultInfo
STimeWindow window; // The time window that current result covers. STimeWindow window; // The time window that current result covers.
...@@ -191,8 +190,8 @@ typedef struct SMeterQueryInfo { ...@@ -191,8 +190,8 @@ typedef struct SMeterQueryInfo {
int64_t skey; int64_t skey;
int64_t ekey; int64_t ekey;
int32_t numOfRes; int32_t numOfRes;
int32_t reverseIndex; // reversed output indicator, start from (numOfRes-1) // 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 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 queryRangeSet; // denote if the query range is set, only available for interval query
int16_t lastResRows; int16_t lastResRows;
int64_t tag; int64_t tag;
...@@ -213,7 +212,7 @@ typedef struct SMeterDataInfo { ...@@ -213,7 +212,7 @@ typedef struct SMeterDataInfo {
SMeterQueryInfo* pMeterQInfo; SMeterQueryInfo* pMeterQInfo;
} SMeterDataInfo; } SMeterDataInfo;
typedef struct SMeterQuerySupportObj { typedef struct STableQuerySupportObj {
void* pMetersHashTable; // meter table hash list void* pMetersHashTable; // meter table hash list
SMeterSidExtInfo** pMeterSidExtInfo; SMeterSidExtInfo** pMeterSidExtInfo;
...@@ -248,7 +247,7 @@ typedef struct SMeterQuerySupportObj { ...@@ -248,7 +247,7 @@ typedef struct SMeterQuerySupportObj {
SMeterDataInfo* pMeterDataInfo; SMeterDataInfo* pMeterDataInfo;
TSKEY* tsList; TSKEY* tsList;
} SMeterQuerySupportObj; } STableQuerySupportObj;
typedef struct _qinfo { typedef struct _qinfo {
uint64_t signature; uint64_t signature;
...@@ -274,18 +273,18 @@ typedef struct _qinfo { ...@@ -274,18 +273,18 @@ typedef struct _qinfo {
SMeterObj* pObj; SMeterObj* pObj;
sem_t dataReady; sem_t dataReady;
SMeterQuerySupportObj* pMeterQuerySupporter; STableQuerySupportObj* pTableQuerySupporter;
int (*fp)(SMeterObj*, SQuery*); int (*fp)(SMeterObj*, SQuery*);
} SQInfo; } SQInfo;
int32_t vnodeQuerySingleTablePrepare(SQInfo* pQInfo, SMeterObj* pMeterObj, SMeterQuerySupportObj* pSMultiMeterObj, int32_t vnodeQueryTablePrepare(SQInfo* pQInfo, SMeterObj* pMeterObj, STableQuerySupportObj* pSMultiMeterObj,
void* param); void* param);
void vnodeQueryFreeQInfoEx(SQInfo* pQInfo); void vnodeQueryFreeQInfoEx(SQInfo* pQInfo);
bool vnodeParametersSafetyCheck(SQuery* pQuery); 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 * decrease the numofQuery of each table that is queried, enable the
......
...@@ -55,7 +55,7 @@ static int32_t readDataFromDiskFile(int fd, SQInfo *pQInfo, SQueryFilesInfo *pQu ...@@ -55,7 +55,7 @@ static int32_t readDataFromDiskFile(int fd, SQInfo *pQInfo, SQueryFilesInfo *pQu
static void vnodeInitLoadCompBlockInfo(SLoadCompBlockInfo *pCompBlockLoadInfo); static void vnodeInitLoadCompBlockInfo(SLoadCompBlockInfo *pCompBlockLoadInfo);
static int32_t moveToNextBlock(SQueryRuntimeEnv *pRuntimeEnv, int32_t step, __block_search_fn_t searchFn, static int32_t moveToNextBlock(SQueryRuntimeEnv *pRuntimeEnv, int32_t step, __block_search_fn_t searchFn,
bool loadData); bool loadData);
static int32_t doMergeMetersResultsToGroupRes(SMeterQuerySupportObj *pSupporter, SQuery *pQuery, static int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery *pQuery,
SQueryRuntimeEnv *pRuntimeEnv, SMeterDataInfo *pMeterDataInfo, SQueryRuntimeEnv *pRuntimeEnv, SMeterDataInfo *pMeterDataInfo,
int32_t start, int32_t end); int32_t start, int32_t end);
...@@ -67,15 +67,12 @@ static int32_t getNextDataFileCompInfo(SQueryRuntimeEnv *pRuntimeEnv, SMeterObj ...@@ -67,15 +67,12 @@ static int32_t getNextDataFileCompInfo(SQueryRuntimeEnv *pRuntimeEnv, SMeterObj
static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult); static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult);
static void getAlignedIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY keyInData, TSKEY skey, TSKEY ekey); // static void getAlignedIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY keyInData, TSKEY skey, TSKEY ekey);
static int32_t saveResult(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo, int32_t numOfResult); // static int32_t saveResult(STableQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo, int32_t numOfResult);
static void applyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterDataInfo *pMeterDataInfo,
SBlockInfo *pBlockInfo, int32_t blockStatus, SField *pFields,
__block_search_fn_t searchFn);
static void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx); static void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx);
static int32_t flushFromResultBuf(SMeterQuerySupportObj *pSupporter, const SQuery *pQuery, static int32_t flushFromResultBuf(STableQuerySupportObj *pSupporter, const SQuery *pQuery,
const SQueryRuntimeEnv *pRuntimeEnv); const SQueryRuntimeEnv *pRuntimeEnv);
static void validateTimestampForSupplementResult(SQueryRuntimeEnv *pRuntimeEnv, int64_t numOfIncrementRes); static void validateTimestampForSupplementResult(SQueryRuntimeEnv *pRuntimeEnv, int64_t numOfIncrementRes);
static void getBasicCacheInfoSnapshot(SQuery *pQuery, SCacheInfo *pCacheInfo, int32_t vid); static void getBasicCacheInfoSnapshot(SQuery *pQuery, SCacheInfo *pCacheInfo, int32_t vid);
...@@ -85,6 +82,11 @@ void doGetAlignedIntervalQueryRangeImpl(SQuery *pQuery, int64_t pKey, ...@@ -85,6 +82,11 @@ void doGetAlignedIntervalQueryRangeImpl(SQuery *pQuery, int64_t pKey,
int64_t *actualSkey, int64_t *actualEkey, int64_t *skey, int64_t *ekey); int64_t *actualSkey, int64_t *actualEkey, int64_t *skey, int64_t *ekey);
static void getNextTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow *pTimeWindow); static void getNextTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow *pTimeWindow);
static int32_t getGroupResultId(int32_t groupIndex) {
int32_t base = 200000;
return base + (groupIndex * 10000);
}
// check the offset value integrity // check the offset value integrity
static FORCE_INLINE int32_t validateHeaderOffsetSegment(SQInfo *pQInfo, char *filePath, int32_t vid, char *data, static FORCE_INLINE int32_t validateHeaderOffsetSegment(SQInfo *pQInfo, char *filePath, int32_t vid, char *data,
int32_t size) { int32_t size) {
...@@ -1010,15 +1012,15 @@ SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv *pRuntimeEnv, void *pBlock, int32_ ...@@ -1010,15 +1012,15 @@ SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv *pRuntimeEnv, void *pBlock, int32_
return blockInfo; return blockInfo;
} }
static bool checkQueryRangeAgainstNextBlock(SBlockInfo *pBlockInfo, SQuery *pQuery) { // static bool checkQueryRangeAgainstNextBlock(SBlockInfo *pBlockInfo, SQuery *pQuery) {
if ((QUERY_IS_ASC_QUERY(pQuery) && pBlockInfo->keyFirst > pQuery->ekey) || // if ((QUERY_IS_ASC_QUERY(pQuery) && pBlockInfo->keyFirst > pQuery->ekey) ||
(!QUERY_IS_ASC_QUERY(pQuery) && pBlockInfo->keyLast < pQuery->ekey)) { // (!QUERY_IS_ASC_QUERY(pQuery) && pBlockInfo->keyLast < pQuery->ekey)) {
setQueryStatus(pQuery, QUERY_COMPLETED); // setQueryStatus(pQuery, QUERY_COMPLETED);
return false; // return false;
} // }
//
return true; // return true;
} //}
/** /**
* *
...@@ -1492,19 +1494,19 @@ static STimeWindow getActiveTimeWindow(SWindowResInfo *pWindowResInfo, int64_t t ...@@ -1492,19 +1494,19 @@ static STimeWindow getActiveTimeWindow(SWindowResInfo *pWindowResInfo, int64_t t
int64_t st = w.skey; int64_t st = w.skey;
if (st > ts) { if (st > ts) {
st -= ((st - ts + pQuery->slidingTime - 1)/pQuery->slidingTime) * pQuery->slidingTime; st -= ((st - ts + pQuery->slidingTime - 1) / pQuery->slidingTime) * pQuery->slidingTime;
} }
int64_t et = st + pQuery->intervalTime - 1; int64_t et = st + pQuery->intervalTime - 1;
if (et < ts) { if (et < ts) {
st += ((ts - et + pQuery->slidingTime - 1)/pQuery->slidingTime) * pQuery->slidingTime; st += ((ts - et + pQuery->slidingTime - 1) / pQuery->slidingTime) * pQuery->slidingTime;
} }
w.skey = st; w.skey = st;
w.ekey = w.skey + pQuery->intervalTime - 1; w.ekey = w.skey + pQuery->intervalTime - 1;
} }
assert(ts >= w.skey && ts <= w.ekey); assert(ts >= w.skey && ts <= w.ekey && w.skey != 0);
return w; return w;
} }
...@@ -1858,7 +1860,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t ...@@ -1858,7 +1860,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
* because the results of group by normal column is put into intermediate buffer. * because the results of group by normal column is put into intermediate buffer.
*/ */
int32_t num = 0; int32_t num = 0;
if (pQuery->intervalTime == 0 && pQuery->slidingTime == 0) { if (pQuery->intervalTime == 0) {
num = getNumOfResult(pRuntimeEnv) - prevNumOfRes; num = getNumOfResult(pRuntimeEnv) - prevNumOfRes;
} }
...@@ -2231,7 +2233,7 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t * ...@@ -2231,7 +2233,7 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t *
} }
int32_t j = 0; int32_t j = 0;
int64_t lastKey = 0; TSKEY lastKey = -1;
for (j = 0; j < (*forwardStep); ++j) { for (j = 0; j < (*forwardStep); ++j) {
int32_t offset = GET_COL_DATA_POS(pQuery, j, step); int32_t offset = GET_COL_DATA_POS(pQuery, j, step);
...@@ -3211,41 +3213,41 @@ void doGetAlignedIntervalQueryRangeImpl(SQuery *pQuery, int64_t pKey, int64_t ke ...@@ -3211,41 +3213,41 @@ void doGetAlignedIntervalQueryRangeImpl(SQuery *pQuery, int64_t pKey, int64_t ke
} }
} }
static void getAlignedIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key, TSKEY skey, TSKEY ekey) { // static void getAlignedIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key, TSKEY skey, TSKEY ekey) {
SQuery *pQuery = pRuntimeEnv->pQuery; // SQuery *pQuery = pRuntimeEnv->pQuery;
if (pQuery->intervalTime == 0 /* || (pQuery->intervalTime > 0 && pQuery->slidingTime > 0)*/) { // if (pQuery->intervalTime == 0 /* || (pQuery->intervalTime > 0 && pQuery->slidingTime > 0)*/) {
return; // return;
} // }
//
TSKEY skey2 = MIN(skey, ekey); // TSKEY skey2 = MIN(skey, ekey);
TSKEY ekey2 = MAX(skey, ekey); // TSKEY ekey2 = MAX(skey, ekey);
//
// the actual first query range in skey1 and ekey1 // // the actual first query range in skey1 and ekey1
TSKEY skey1, ekey1; // TSKEY skey1, ekey1;
//
TSKEY windowSKey = 0, windowEKey = 0; // TSKEY windowSKey = 0, windowEKey = 0;
doGetAlignedIntervalQueryRangeImpl(pQuery, key, skey2, ekey2, &skey1, &ekey1, &windowSKey, &windowEKey); // doGetAlignedIntervalQueryRangeImpl(pQuery, key, skey2, ekey2, &skey1, &ekey1, &windowSKey, &windowEKey);
//
if (QUERY_IS_ASC_QUERY(pQuery)) { // if (QUERY_IS_ASC_QUERY(pQuery)) {
pQuery->skey = skey1; // pQuery->skey = skey1;
pQuery->ekey = ekey1; // pQuery->ekey = ekey1;
//
pRuntimeEnv->intervalWindow = (STimeWindow){.skey = windowSKey, .ekey = windowEKey}; // pRuntimeEnv->intervalWindow = (STimeWindow){.skey = windowSKey, .ekey = windowEKey};
//
assert(pQuery->skey <= pQuery->ekey && // assert(pQuery->skey <= pQuery->ekey &&
pRuntimeEnv->intervalWindow.skey + (pQuery->intervalTime - 1) == pRuntimeEnv->intervalWindow.ekey); // pRuntimeEnv->intervalWindow.skey + (pQuery->intervalTime - 1) == pRuntimeEnv->intervalWindow.ekey);
} else { // } else {
pQuery->skey = ekey1; // pQuery->skey = ekey1;
pQuery->ekey = skey1; // pQuery->ekey = skey1;
//
pRuntimeEnv->intervalWindow = (STimeWindow){.skey = windowEKey, .ekey = windowSKey}; // pRuntimeEnv->intervalWindow = (STimeWindow){.skey = windowEKey, .ekey = windowSKey};
//
assert(pQuery->skey >= pQuery->ekey && // assert(pQuery->skey >= pQuery->ekey &&
pRuntimeEnv->intervalWindow.skey - (pQuery->intervalTime - 1) == pRuntimeEnv->intervalWindow.ekey); // pRuntimeEnv->intervalWindow.skey - (pQuery->intervalTime - 1) == pRuntimeEnv->intervalWindow.ekey);
} // }
//
pQuery->lastKey = pQuery->skey; // pQuery->lastKey = pQuery->skey;
} //}
static void getOneRowFromDataBlock(SQueryRuntimeEnv *pRuntimeEnv, char **dst, int32_t pos) { static void getOneRowFromDataBlock(SQueryRuntimeEnv *pRuntimeEnv, char **dst, int32_t pos) {
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
...@@ -3256,7 +3258,7 @@ static void getOneRowFromDataBlock(SQueryRuntimeEnv *pRuntimeEnv, char **dst, in ...@@ -3256,7 +3258,7 @@ static void getOneRowFromDataBlock(SQueryRuntimeEnv *pRuntimeEnv, char **dst, in
} }
} }
static bool getNeighborPoints(SMeterQuerySupportObj *pSupporter, SMeterObj *pMeterObj, static bool getNeighborPoints(STableQuerySupportObj *pSupporter, SMeterObj *pMeterObj,
SPointInterpoSupporter *pPointInterpSupporter) { SPointInterpoSupporter *pPointInterpSupporter) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -3361,7 +3363,7 @@ static bool getNeighborPoints(SMeterQuerySupportObj *pSupporter, SMeterObj *pMet ...@@ -3361,7 +3363,7 @@ static bool getNeighborPoints(SMeterQuerySupportObj *pSupporter, SMeterObj *pMet
return true; return true;
} }
static bool doGetQueryPos(TSKEY key, SMeterQuerySupportObj *pSupporter, SPointInterpoSupporter *pPointInterpSupporter) { static bool doGetQueryPos(TSKEY key, STableQuerySupportObj *pSupporter, SPointInterpoSupporter *pPointInterpSupporter) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
SMeterObj * pMeterObj = pRuntimeEnv->pMeterObj; SMeterObj * pMeterObj = pRuntimeEnv->pMeterObj;
...@@ -3383,7 +3385,7 @@ static bool doGetQueryPos(TSKEY key, SMeterQuerySupportObj *pSupporter, SPointIn ...@@ -3383,7 +3385,7 @@ static bool doGetQueryPos(TSKEY key, SMeterQuerySupportObj *pSupporter, SPointIn
} }
} }
static bool doSetDataInfo(SMeterQuerySupportObj *pSupporter, SPointInterpoSupporter *pPointInterpSupporter, static bool doSetDataInfo(STableQuerySupportObj *pSupporter, SPointInterpoSupporter *pPointInterpSupporter,
SMeterObj *pMeterObj, TSKEY nextKey) { SMeterObj *pMeterObj, TSKEY nextKey) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -3409,7 +3411,7 @@ static bool doSetDataInfo(SMeterQuerySupportObj *pSupporter, SPointInterpoSuppor ...@@ -3409,7 +3411,7 @@ static bool doSetDataInfo(SMeterQuerySupportObj *pSupporter, SPointInterpoSuppor
} }
// TODO refactor code, the best way to implement the last_row is utilizing the iterator // TODO refactor code, the best way to implement the last_row is utilizing the iterator
bool normalizeUnBoundLastRowQuery(SMeterQuerySupportObj *pSupporter, SPointInterpoSupporter *pPointInterpSupporter) { bool normalizeUnBoundLastRowQuery(STableQuerySupportObj *pSupporter, SPointInterpoSupporter *pPointInterpSupporter) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -3471,7 +3473,44 @@ bool normalizeUnBoundLastRowQuery(SMeterQuerySupportObj *pSupporter, SPointInter ...@@ -3471,7 +3473,44 @@ bool normalizeUnBoundLastRowQuery(SMeterQuerySupportObj *pSupporter, SPointInter
return getNeighborPoints(pSupporter, pMeterObj, pPointInterpSupporter); return getNeighborPoints(pSupporter, pMeterObj, pPointInterpSupporter);
} }
static void getActualRange(SMeterQuerySupportObj *pSupporter, STimeWindow *pTimeWindow) { static int64_t getGreaterEqualTimestamp(SQueryRuntimeEnv *pRuntimeEnv) {
SQuery * pQuery = pRuntimeEnv->pQuery;
SMeterObj * pMeterObj = pRuntimeEnv->pMeterObj;
__block_search_fn_t searchFn = vnodeSearchKeyFunc[pMeterObj->searchAlgorithm];
if (QUERY_IS_ASC_QUERY(pQuery)) {
return -1;
}
TSKEY key = -1;
SPositionInfo p = {0};
{ // todo refactor save the context
savePointPosition(&p, pQuery->fileId, pQuery->slot, pQuery->pos);
}
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
pQuery->lastKey = pQuery->skey;
pQuery->order.order ^= 1u;
if (getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_GREATER_EQUAL, searchFn)) {
key = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos);
} else { // set no data in file
key = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false);
}
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
pQuery->order.order ^= 1u;
pQuery->lastKey = pQuery->skey;
pQuery->fileId = p.fileId;
pQuery->pos = p.pos;
pQuery->slot = p.slot;
return key;
}
static void getActualRange(STableQuerySupportObj *pSupporter, STimeWindow *pTimeWindow) {
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
SMeterObj * pMeterObj = pRuntimeEnv->pMeterObj; SMeterObj * pMeterObj = pRuntimeEnv->pMeterObj;
...@@ -3482,7 +3521,7 @@ static void getActualRange(SMeterQuerySupportObj *pSupporter, STimeWindow *pTime ...@@ -3482,7 +3521,7 @@ static void getActualRange(SMeterQuerySupportObj *pSupporter, STimeWindow *pTime
pQuery->lastKey = pQuery->skey; pQuery->lastKey = pQuery->skey;
if (QUERY_IS_ASC_QUERY(pQuery)) { // do the desc check first for asc query if (QUERY_IS_ASC_QUERY(pQuery)) { // do the desc check first for asc query
pQuery->order.order ^= 1; pQuery->order.order ^= 1u;
TSKEY t = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false); TSKEY t = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false);
if (t > 0) { if (t > 0) {
...@@ -3505,18 +3544,17 @@ static void getActualRange(SMeterQuerySupportObj *pSupporter, STimeWindow *pTime ...@@ -3505,18 +3544,17 @@ static void getActualRange(SMeterQuerySupportObj *pSupporter, STimeWindow *pTime
pQuery->skey = pTimeWindow->skey; pQuery->skey = pTimeWindow->skey;
pQuery->ekey = pTimeWindow->ekey; pQuery->ekey = pTimeWindow->ekey;
} else { } else {
pQuery->order.order ^= 1; pQuery->order.order ^= 1u;
if (getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_GREATER_EQUAL, searchFn)) { if (getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_GREATER_EQUAL, searchFn)) {
pTimeWindow->skey = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos); pTimeWindow->skey = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos);
} else { // set no data in file } else { // set no data in file
pQuery->fileId = -1;
pTimeWindow->skey = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false); pTimeWindow->skey = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false);
} }
// reverse check for maxValue in query range // reverse check for maxValue in query range
SWAP(pQuery->skey, pQuery->ekey, TSKEY); SWAP(pQuery->skey, pQuery->ekey, TSKEY);
pQuery->order.order ^= 1; pQuery->order.order ^= 1u;
// set no data in file // set no data in file
pQuery->lastKey = pQuery->skey; pQuery->lastKey = pQuery->skey;
...@@ -3540,7 +3578,7 @@ static void getActualRange(SMeterQuerySupportObj *pSupporter, STimeWindow *pTime ...@@ -3540,7 +3578,7 @@ static void getActualRange(SMeterQuerySupportObj *pSupporter, STimeWindow *pTime
* the time interval for aggregating is not enforced to check its validation, the minimum interval is not less than * the time interval for aggregating is not enforced to check its validation, the minimum interval is not less than
* 10ms, which is guaranteed by parser at client-side * 10ms, which is guaranteed by parser at client-side
*/ */
bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, SMeterQuerySupportObj *pSupporter, bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, STableQuerySupportObj *pSupporter,
SPointInterpoSupporter *pPointInterpSupporter, int64_t *key) { SPointInterpoSupporter *pPointInterpSupporter, int64_t *key) {
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -3746,7 +3784,7 @@ static void vnodeRecordAllFiles(SQInfo *pQInfo, int32_t vnodeId) { ...@@ -3746,7 +3784,7 @@ static void vnodeRecordAllFiles(SQInfo *pQInfo, int32_t vnodeId) {
struct dirent *pEntry = NULL; struct dirent *pEntry = NULL;
size_t alloc = 4; // default allocated size size_t alloc = 4; // default allocated size
SQueryFilesInfo *pVnodeFilesInfo = &(pQInfo->pMeterQuerySupporter->runtimeEnv.vnodeFileInfo); SQueryFilesInfo *pVnodeFilesInfo = &(pQInfo->pTableQuerySupporter->runtimeEnv.vnodeFileInfo);
pVnodeFilesInfo->vnodeId = vnodeId; pVnodeFilesInfo->vnodeId = vnodeId;
sprintf(pVnodeFilesInfo->dbFilePathPrefix, "%s/vnode%d/db/", tsDirectory, vnodeId); sprintf(pVnodeFilesInfo->dbFilePathPrefix, "%s/vnode%d/db/", tsDirectory, vnodeId);
...@@ -4036,18 +4074,20 @@ void forwardQueryStartPosition(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -4036,18 +4074,20 @@ void forwardQueryStartPosition(SQueryRuntimeEnv *pRuntimeEnv) {
updateOffsetVal(pRuntimeEnv, &blockInfo, pBlock); updateOffsetVal(pRuntimeEnv, &blockInfo, pBlock);
} else { } else {
pQuery->limit.offset -= maxReads; pQuery->limit.offset -= maxReads;
// update the lastkey, since the following skip operation may traverse to another media. update the lastkey first. // update the lastkey, since the following skip operation may traverse to another media. update the lastkey first.
pQuery->lastKey = (QUERY_IS_ASC_QUERY(pQuery)) ? blockInfo.keyLast + 1 : blockInfo.keyFirst - 1; pQuery->lastKey = (QUERY_IS_ASC_QUERY(pQuery)) ? blockInfo.keyLast + 1 : blockInfo.keyFirst - 1;
doSkipDataBlock(pRuntimeEnv); doSkipDataBlock(pRuntimeEnv);
} }
} }
static bool forwardQueryStartPosIfNeeded(SQInfo *pQInfo, SMeterQuerySupportObj *pSupporter, bool dataInDisk, static bool forwardQueryStartPosIfNeeded(SQInfo *pQInfo, STableQuerySupportObj *pSupporter, bool dataInDisk,
bool dataInCache) { bool dataInCache) {
SQuery *pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
/* if queried with value filter, do NOT forward query start position */ /* if queried with value filter, do NOT forward query start position */
if (pQuery->numOfFilterCols > 0 || pSupporter->runtimeEnv.pTSBuf != NULL) { if (pQuery->numOfFilterCols > 0 || pRuntimeEnv->pTSBuf != NULL) {
return true; return true;
} }
...@@ -4059,48 +4099,121 @@ static bool forwardQueryStartPosIfNeeded(SQInfo *pQInfo, SMeterQuerySupportObj * ...@@ -4059,48 +4099,121 @@ static bool forwardQueryStartPosIfNeeded(SQInfo *pQInfo, SMeterQuerySupportObj *
* not valid. otherwise, we only forward pQuery->limit.offset number of points * not valid. otherwise, we only forward pQuery->limit.offset number of points
*/ */
if (pQuery->intervalTime > 0) { if (pQuery->intervalTime > 0) {
while (1) { // while (1) {
/* // /*
* the skey may not be the aligned start time // * the skey may not be the aligned start time
* 1. it is the value of first existed data point, therefore, the range // * 1. it is the value of first existed data point, therefore, the range
* between skey and ekey may be less than the interval value. // * between skey and ekey may be less than the interval value.
* 2. the ekey may not be the actual end value of time interval, in case of the // * 2. the ekey may not be the actual end value of time interval, in case of the
*/ // */
if (QUERY_IS_ASC_QUERY(pQuery)) { // if (QUERY_IS_ASC_QUERY(pQuery)) {
pQuery->skey = pQuery->ekey + 1; // pQuery->skey = pQuery->ekey + 1;
} else { // } else {
pQuery->skey = pQuery->ekey - 1; // pQuery->skey = pQuery->ekey - 1;
// }
//
// // boundary check
// if ((pQuery->skey > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
// (pQuery->skey < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) {
// setQueryStatus(pQuery, QUERY_COMPLETED);
//
// sem_post(&pQInfo->dataReady);
// pQInfo->over = 1;
// return false;
// }
//
// /*
// * NOTE: the end key must be set the last value, to cover all possible
// * data. Otherwise, it may contain no data with only one interval time range
// */
// pQuery->ekey = pSupporter->rawEKey;
// pQuery->lastKey = pQuery->skey;
//
// // todo opt performance
// if (normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, NULL, NULL) == false) {
// sem_post(&pQInfo->dataReady); // hack for next read for empty return
// pQInfo->over = 1;
// return false;
// }
//
// if (--pQuery->limit.offset == 0) {
// break;
// }
// }
int16_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
__block_search_fn_t searchFn = vnodeSearchKeyFunc[pRuntimeEnv->pMeterObj->searchAlgorithm];
STimeWindow win = getActiveTimeWindow(&pRuntimeEnv->windowResInfo, pRuntimeEnv->windowResInfo.prevSKey, pQuery);
while (pQuery->limit.offset > 0) {
void *pBlock = getGenericDataBlock(pRuntimeEnv->pMeterObj, pRuntimeEnv, pQuery->slot);
int32_t blockType = (IS_DISK_DATA_BLOCK(pQuery)) ? BLK_FILE_BLOCK : BLK_CACHE_BLOCK;
SBlockInfo blockInfo = getBlockBasicInfo(pRuntimeEnv, pBlock, blockType);
if (pQuery->ekey < blockInfo.keyLast) {
break;
} }
// boundary check if (win.ekey <= blockInfo.keyLast) {
if ((pQuery->skey > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) || while(1) {
(pQuery->skey < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) { getNextTimeWindow(pRuntimeEnv, &win);
setQueryStatus(pQuery, QUERY_COMPLETED);
sem_post(&pQInfo->dataReady); if ((win.skey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
pQInfo->over = 1; (win.ekey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
return false; break;
} }
TSKEY startKey = QUERY_IS_ASC_QUERY(pQuery) ? win.skey : win.ekey;
int32_t startPos = searchFn((char *)primaryKeyCol, blockInfo.size, startKey, pQuery->order.order);
/* /*
* NOTE: the end key must be set the last value, to cover all possible * This time window does not cover any data, try next time window
* data. Otherwise, it may contain no data with only one interval time range * when the time window is too small, this case may happen
*/ */
pQuery->ekey = pSupporter->rawEKey; if ((primaryKeyCol[startPos] > win.ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
pQuery->lastKey = pQuery->skey; (primaryKeyCol[startPos] < win.skey && !QUERY_IS_ASC_QUERY(pQuery))) {
continue;
}
// todo opt performance break;
if (normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, NULL, NULL) == false) { }
sem_post(&pQInfo->dataReady); // hack for next read for empty return
pQInfo->over = 1; if ((win.skey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
return false; (win.ekey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
break;
}
pQuery->limit.offset -= 1;
if (win.ekey == blockInfo.keyLast) {
moveToNextBlock(pRuntimeEnv, step, searchFn, false);
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) {
break;
}
} }
if (--pQuery->limit.offset == 0) { continue;
}
moveToNextBlock(pRuntimeEnv, step, searchFn, false);
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) {
break; break;
} }
} }
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK) || pQuery->limit.offset > 0) {
setQueryStatus(pQuery, QUERY_COMPLETED);
sem_post(&pQInfo->dataReady); // hack for next read for empty return;
pQInfo->over = 1;
return false;
} else { } else {
}
} else { // forward the start position for projection query
forwardQueryStartPosition(&pSupporter->runtimeEnv); forwardQueryStartPosition(&pSupporter->runtimeEnv);
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) { if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) {
setQueryStatus(pQuery, QUERY_COMPLETED); setQueryStatus(pQuery, QUERY_COMPLETED);
...@@ -4186,7 +4299,7 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI ...@@ -4186,7 +4299,7 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI
} }
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
int32_t count = 1; int32_t count = 1;
...@@ -4317,7 +4430,7 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter *pPointInterpSupport) { ...@@ -4317,7 +4430,7 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter *pPointInterpSupport) {
pPointInterpSupport->numOfCols = 0; pPointInterpSupport->numOfCols = 0;
} }
static void allocMemForInterpo(SMeterQuerySupportObj *pSupporter, SQuery *pQuery, SMeterObj *pMeterObj) { static void allocMemForInterpo(STableQuerySupportObj *pSupporter, SQuery *pQuery, SMeterObj *pMeterObj) {
if (pQuery->interpoType != TSDB_INTERPO_NONE) { if (pQuery->interpoType != TSDB_INTERPO_NONE) {
assert(pQuery->intervalTime > 0 || (pQuery->intervalTime == 0 && isPointInterpoQuery(pQuery))); assert(pQuery->intervalTime > 0 || (pQuery->intervalTime == 0 && isPointInterpoQuery(pQuery)));
...@@ -4332,18 +4445,22 @@ static void allocMemForInterpo(SMeterQuerySupportObj *pSupporter, SQuery *pQuery ...@@ -4332,18 +4445,22 @@ static void allocMemForInterpo(SMeterQuerySupportObj *pSupporter, SQuery *pQuery
} }
} }
static int32_t initialNumOfRows(SMeterQuerySupportObj *pSupporter) { static int32_t getInitialPageNum(STableQuerySupportObj *pSupporter) {
SQuery *pQuery = pSupporter->runtimeEnv.pQuery; SQuery *pQuery = pSupporter->runtimeEnv.pQuery;
int32_t numOfRows = 0; int32_t num = 0;
if (isGroupbyNormalCol(pQuery->pGroupbyExpr) || (pQuery->intervalTime > 0 && pQuery->slidingTime > 0)) { if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
numOfRows = 128; num = 128;
} else { } else if (pQuery->intervalTime > 0) { // time window query, allocate one page for each table
numOfRows = pSupporter->pSidSet->numOfSubSet; num = pSupporter->numOfMeters;
} else { // for super table query, one page for each subset
num = pSupporter->pSidSet->numOfSubSet;
} }
return numOfRows; assert(num > 0);
return num;
} }
static int32_t allocateRuntimeEnvBuf(SQueryRuntimeEnv *pRuntimeEnv, SMeterObj *pMeterObj) { static int32_t allocateRuntimeEnvBuf(SQueryRuntimeEnv *pRuntimeEnv, SMeterObj *pMeterObj) {
...@@ -4418,6 +4535,8 @@ static int32_t getNumOfRowsInResultPage(SQuery *pQuery, bool isSTableQuery) { ...@@ -4418,6 +4535,8 @@ static int32_t getNumOfRowsInResultPage(SQuery *pQuery, bool isSTableQuery) {
} }
static char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWindowResult *pResult) { static char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWindowResult *pResult) {
assert(pResult != NULL && pRuntimeEnv != NULL);
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
tFilePage *page = getResultBufferPageById(pRuntimeEnv->pResultBuf, pResult->pos.pageId); tFilePage *page = getResultBufferPageById(pRuntimeEnv->pResultBuf, pResult->pos.pageId);
...@@ -4428,8 +4547,7 @@ static char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnInd ...@@ -4428,8 +4547,7 @@ static char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnInd
pQuery->pSelectExpr[columnIndex].resBytes * realRowId; pQuery->pSelectExpr[columnIndex].resBytes * realRowId;
} }
int32_t vnodeQuerySingleTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMeterQuerySupportObj *pSupporter, int32_t vnodeQueryTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, STableQuerySupportObj *pSupporter, void *param) {
void *param) {
SQuery *pQuery = &pQInfo->query; SQuery *pQuery = &pQInfo->query;
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
...@@ -4500,7 +4618,7 @@ int32_t vnodeQuerySingleTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete ...@@ -4500,7 +4618,7 @@ int32_t vnodeQuerySingleTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete
pRuntimeEnv->numOfRowsPerPage = getNumOfRowsInResultPage(pQuery, false); pRuntimeEnv->numOfRowsPerPage = getNumOfRowsInResultPage(pQuery, false);
if (isGroupbyNormalCol(pQuery->pGroupbyExpr) || (pQuery->intervalTime > 0 && pQuery->slidingTime > 0)) { if (isGroupbyNormalCol(pQuery->pGroupbyExpr) || (pQuery->intervalTime > 0 && pQuery->slidingTime > 0)) {
int32_t rows = initialNumOfRows(pSupporter); int32_t rows = getInitialPageNum(pSupporter);
code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, rows, pQuery->rowSize); code = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, rows, pQuery->rowSize);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
...@@ -4543,15 +4661,33 @@ int32_t vnodeQuerySingleTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete ...@@ -4543,15 +4661,33 @@ int32_t vnodeQuerySingleTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete
} else { // find the skey and ekey in case of sliding query } else { // find the skey and ekey in case of sliding query
if (pQuery->slidingTime > 0 && pQuery->intervalTime > 0) { if (pQuery->slidingTime > 0 && pQuery->intervalTime > 0) {
STimeWindow win = {0}; STimeWindow win = {0};
getActualRange(pSupporter, &win); // getActualRange(pSupporter, &win);
//
// there is no qualified data with respect to the primary timestamp // // there is no qualified data with respect to the primary timestamp
if (win.skey > win.ekey) { // if (win.skey > win.ekey) {
// sem_post(&pQInfo->dataReady);
// pQInfo->over = 1;
// return TSDB_CODE_SUCCESS;
// }
int64_t skey = 0;
if ((normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, &interpInfo, &skey) == false) ||
(isFixedOutputQuery(pQuery) && !isTopBottomQuery(pQuery) && (pQuery->limit.offset > 0)) ||
(isTopBottomQuery(pQuery) && pQuery->limit.offset >= pQuery->pSelectExpr[1].pBase.arg[0].argValue.i64)) {
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
pQInfo->over = 1; pQInfo->over = 1;
pointInterpSupporterDestroy(&interpInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (!QUERY_IS_ASC_QUERY(pQuery)) {
win.skey = getGreaterEqualTimestamp(pRuntimeEnv);
win.ekey = skey;
} else {
win.skey = skey;
win.ekey = pQuery->ekey;
}
TSKEY skey1, ekey1; TSKEY skey1, ekey1;
TSKEY windowSKey = 0, windowEKey = 0; TSKEY windowSKey = 0, windowEKey = 0;
...@@ -4609,12 +4745,12 @@ int32_t vnodeQuerySingleTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete ...@@ -4609,12 +4745,12 @@ int32_t vnodeQuerySingleTablePrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete
} }
void vnodeQueryFreeQInfoEx(SQInfo *pQInfo) { void vnodeQueryFreeQInfoEx(SQInfo *pQInfo) {
if (pQInfo == NULL || pQInfo->pMeterQuerySupporter == NULL) { if (pQInfo == NULL || pQInfo->pTableQuerySupporter == NULL) {
return; return;
} }
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
teardownQueryRuntimeEnv(&pSupporter->runtimeEnv); teardownQueryRuntimeEnv(&pSupporter->runtimeEnv);
tfree(pSupporter->pMeterSidExtInfo); tfree(pSupporter->pMeterSidExtInfo);
...@@ -4649,11 +4785,11 @@ void vnodeQueryFreeQInfoEx(SQInfo *pQInfo) { ...@@ -4649,11 +4785,11 @@ void vnodeQueryFreeQInfoEx(SQInfo *pQInfo) {
tfree(pSupporter->pMeterDataInfo); tfree(pSupporter->pMeterDataInfo);
tfree(pQInfo->pMeterQuerySupporter); tfree(pQInfo->pTableQuerySupporter);
} }
int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) { int32_t vnodeSTableQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
if ((QUERY_IS_ASC_QUERY(pQuery) && (pQuery->skey > pQuery->ekey)) || if ((QUERY_IS_ASC_QUERY(pQuery) && (pQuery->skey > pQuery->ekey)) ||
(!QUERY_IS_ASC_QUERY(pQuery) && (pQuery->ekey > pQuery->skey))) { (!QUERY_IS_ASC_QUERY(pQuery) && (pQuery->ekey > pQuery->skey))) {
...@@ -4716,22 +4852,28 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) ...@@ -4716,22 +4852,28 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param)
tSidSetSort(pSupporter->pSidSet); tSidSetSort(pSupporter->pSidSet);
vnodeRecordAllFiles(pQInfo, pMeter->vnode); vnodeRecordAllFiles(pQInfo, pMeter->vnode);
if (pQuery->intervalTime == 0 && pQuery->slidingTime <= 0) { int32_t size = getInitialPageNum(pSupporter);
ret = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, 3, pQuery->rowSize); ret = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, size, pQuery->rowSize);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
if (pQuery->intervalTime == 0) {
int16_t type = TSDB_DATA_TYPE_NULL;
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) { // group by columns not tags; if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) { // group by columns not tags;
int16_t type = getGroupbyColumnType(pQuery, pQuery->pGroupbyExpr); type = getGroupbyColumnType(pQuery, pQuery->pGroupbyExpr);
initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, 128, 4096, type);
}
} else { } else {
// one page for each table at least type = TSDB_DATA_TYPE_INT; // group id
ret = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, pSupporter->numOfMeters, pQuery->rowSize);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
} }
initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, 512, 4096, type);
// }
// } else {
// ret = createDiskbasedResultBuffer(&pRuntimeEnv->pResultBuf, pSupporter->numOfMeters, pQuery->rowSize);
// if (ret != TSDB_CODE_SUCCESS) {
// return ret;
// }
} }
pRuntimeEnv->numOfRowsPerPage = getNumOfRowsInResultPage(pQuery, true); pRuntimeEnv->numOfRowsPerPage = getNumOfRowsInResultPage(pQuery, true);
...@@ -4754,7 +4896,7 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) ...@@ -4754,7 +4896,7 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param)
* @param pQInfo * @param pQInfo
*/ */
void vnodeDecMeterRefcnt(SQInfo *pQInfo) { void vnodeDecMeterRefcnt(SQInfo *pQInfo) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
if (pSupporter == NULL || pSupporter->numOfMeters == 1) { if (pSupporter == NULL || pSupporter->numOfMeters == 1) {
atomic_fetch_sub_32(&pQInfo->pObj->numOfQueries, 1); atomic_fetch_sub_32(&pQInfo->pObj->numOfQueries, 1);
...@@ -5204,40 +5346,38 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -5204,40 +5346,38 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
static void updatelastkey(SQuery *pQuery, SMeterQueryInfo *pMeterQInfo) { pMeterQInfo->lastKey = pQuery->lastKey; } static void updatelastkey(SQuery *pQuery, SMeterQueryInfo *pMeterQInfo) { pMeterQInfo->lastKey = pQuery->lastKey; }
void queryOnBlock(SMeterQuerySupportObj *pSupporter, int32_t blockStatus, SBlockInfo *pBlockBasicInfo, // void queryOnBlock(STableQuerySupportObj *pSupporter, int32_t blockStatus, SBlockInfo *pBlockBasicInfo,
SMeterDataInfo *pMeterDataInfo, SField *pFields, __block_search_fn_t searchFn) { // SMeterDataInfo *pMeterDataInfo, SField *pFields, __block_search_fn_t searchFn) {
/* cache blocks may be assign to other meter, abort */ // /* cache blocks may be assign to other meter, abort */
if (pBlockBasicInfo->size <= 0) { //
return; //
} //// SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
//// SQuery * pQuery = pRuntimeEnv->pQuery;
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; //
SQuery * pQuery = pRuntimeEnv->pQuery; //// TSKEY *primaryKeys = (TSKEY *)pRuntimeEnv->primaryColBuffer->data;
//
TSKEY* primaryKeys = (TSKEY*) pRuntimeEnv->primaryColBuffer->data; // // if (pQuery->intervalTime == 0) { // not interval query
// // assert(0);
if (pQuery->intervalTime == 0) { // not interval query // //
assert(0); // // int32_t numOfRes = 0;
// // applyFunctionsOnBlock(pRuntimeEnv, pBlockBasicInfo, primaryKeys, pFields, searchFn, &numOfRes,
int32_t numOfRes = 0; // // &pMeterDataInfo->pMeterQInfo->windowResInfo); ///????bug
applyFunctionsOnBlock(pRuntimeEnv, pBlockBasicInfo, primaryKeys, pFields, searchFn, &numOfRes, // //
&pMeterDataInfo->pMeterQInfo->windowResInfo);///????bug // // // note: only fixed number of output for each group by operation
// // if (numOfRes > 0) { //???
// note: only fixed number of output for each group by operation // // pRuntimeEnv->windowResInfo.pResult[pMeterDataInfo->groupIdx].numOfRows = numOfRes; ////????bug
if (numOfRes > 0) {//??? // // }
pRuntimeEnv->windowResInfo.pResult[pMeterDataInfo->groupIdx].numOfRows = numOfRes;////????bug // //
} // // // used to decide the correct start position in cache after check all data in files
// // updatelastkey(pQuery, pMeterDataInfo->pMeterQInfo);
// used to decide the correct start position in cache after check all data in files // // if (pRuntimeEnv->pTSBuf != NULL) {
updatelastkey(pQuery, pMeterDataInfo->pMeterQInfo); // // pMeterDataInfo->pMeterQInfo->cur = tsBufGetCursor(pRuntimeEnv->pTSBuf);
if (pRuntimeEnv->pTSBuf != NULL) { // // }
pMeterDataInfo->pMeterQInfo->cur = tsBufGetCursor(pRuntimeEnv->pTSBuf); // //
} // // } else {
// applyIntervalQueryOnBlock(pSupporter, pMeterDataInfo, pBlockBasicInfo, pFields, searchFn);
} else { // // }
applyIntervalQueryOnBlock(pSupporter, pMeterDataInfo, pBlockBasicInfo, blockStatus, pFields, searchFn); //}
}
}
/* /*
* set tag value in SQLFunctionCtx * set tag value in SQLFunctionCtx
...@@ -5455,7 +5595,7 @@ typedef struct Position { ...@@ -5455,7 +5595,7 @@ typedef struct Position {
typedef struct SCompSupporter { typedef struct SCompSupporter {
SMeterDataInfo ** pMeterDataInfo; SMeterDataInfo ** pMeterDataInfo;
Position * pPosition; Position * pPosition;
SMeterQuerySupportObj *pSupporter; STableQuerySupportObj *pSupporter;
} SCompSupporter; } SCompSupporter;
int64_t getCurrentTimestamp(SCompSupporter *pSupportor, int32_t meterIdx) { int64_t getCurrentTimestamp(SCompSupporter *pSupportor, int32_t meterIdx) {
...@@ -5499,7 +5639,7 @@ int32_t meterResultComparator(const void *pLeft, const void *pRight, void *param ...@@ -5499,7 +5639,7 @@ int32_t meterResultComparator(const void *pLeft, const void *pRight, void *param
return leftTimestamp > rightTimestamp ? 1 : -1; return leftTimestamp > rightTimestamp ? 1 : -1;
} }
int32_t mergeMetersResultToOneGroups(SMeterQuerySupportObj *pSupporter) { int32_t mergeMetersResultToOneGroups(STableQuerySupportObj *pSupporter) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -5532,7 +5672,7 @@ int32_t mergeMetersResultToOneGroups(SMeterQuerySupportObj *pSupporter) { ...@@ -5532,7 +5672,7 @@ int32_t mergeMetersResultToOneGroups(SMeterQuerySupportObj *pSupporter) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void copyResToQueryResultBuf(SMeterQuerySupportObj *pSupporter, SQuery *pQuery) { void copyResToQueryResultBuf(STableQuerySupportObj *pSupporter, SQuery *pQuery) {
if (pSupporter->offset == pSupporter->numOfGroupResultPages) { if (pSupporter->offset == pSupporter->numOfGroupResultPages) {
pSupporter->numOfGroupResultPages = 0; pSupporter->numOfGroupResultPages = 0;
...@@ -5551,7 +5691,8 @@ void copyResToQueryResultBuf(SMeterQuerySupportObj *pSupporter, SQuery *pQuery) ...@@ -5551,7 +5691,8 @@ void copyResToQueryResultBuf(SMeterQuerySupportObj *pSupporter, SQuery *pQuery)
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf; SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
SIDList list = getDataBufPagesIdList(pResultBuf, 200000 + pSupporter->offset + (pSupporter->subgroupIdx - 1) * 10000); int32_t id = getGroupResultId(pSupporter->subgroupIdx - 1);
SIDList list = getDataBufPagesIdList(pResultBuf, pSupporter->offset + id);
int32_t total = 0; int32_t total = 0;
for (int32_t i = 0; i < list.size; ++i) { for (int32_t i = 0; i < list.size; ++i) {
...@@ -5582,7 +5723,7 @@ void copyResToQueryResultBuf(SMeterQuerySupportObj *pSupporter, SQuery *pQuery) ...@@ -5582,7 +5723,7 @@ void copyResToQueryResultBuf(SMeterQuerySupportObj *pSupporter, SQuery *pQuery)
pSupporter->offset += 1; pSupporter->offset += 1;
} }
int32_t doMergeMetersResultsToGroupRes(SMeterQuerySupportObj *pSupporter, SQuery *pQuery, SQueryRuntimeEnv *pRuntimeEnv, int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery *pQuery, SQueryRuntimeEnv *pRuntimeEnv,
SMeterDataInfo *pMeterDataInfo, int32_t start, int32_t end) { SMeterDataInfo *pMeterDataInfo, int32_t start, int32_t end) {
// calculate the maximum required space // calculate the maximum required space
if (pSupporter->groupResultSize == 0) { if (pSupporter->groupResultSize == 0) {
...@@ -5718,13 +5859,12 @@ int32_t doMergeMetersResultsToGroupRes(SMeterQuerySupportObj *pSupporter, SQuery ...@@ -5718,13 +5859,12 @@ int32_t doMergeMetersResultsToGroupRes(SMeterQuerySupportObj *pSupporter, SQuery
return pSupporter->numOfGroupResultPages; return pSupporter->numOfGroupResultPages;
} }
int32_t flushFromResultBuf(SMeterQuerySupportObj *pSupporter, const SQuery *pQuery, int32_t flushFromResultBuf(STableQuerySupportObj *pSupporter, const SQuery *pQuery,
const SQueryRuntimeEnv *pRuntimeEnv) { const SQueryRuntimeEnv *pRuntimeEnv) {
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf; SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
int32_t capacity = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / pQuery->rowSize; int32_t capacity = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / pQuery->rowSize;
// the base value for group result, since the maximum number of table for each vnode will not exceed 100,000. // the base value for group result, since the maximum number of table for each vnode will not exceed 100,000.
int32_t base = 200000;
int32_t pageId = -1; int32_t pageId = -1;
int32_t remain = pQuery->sdata[0]->len; int32_t remain = pQuery->sdata[0]->len;
...@@ -5736,8 +5876,8 @@ int32_t flushFromResultBuf(SMeterQuerySupportObj *pSupporter, const SQuery *pQue ...@@ -5736,8 +5876,8 @@ int32_t flushFromResultBuf(SMeterQuerySupportObj *pSupporter, const SQuery *pQue
r = capacity; r = capacity;
} }
tFilePage *buf = int32_t id = getGroupResultId(pSupporter->subgroupIdx) + pSupporter->numOfGroupResultPages;
getNewDataBuf(pResultBuf, base + pSupporter->subgroupIdx * 10000 + pSupporter->numOfGroupResultPages, &pageId); tFilePage *buf = getNewDataBuf(pResultBuf, id, &pageId);
// pagewise copy to dest buffer // pagewise copy to dest buffer
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
...@@ -5771,35 +5911,35 @@ void setMeterDataInfo(SMeterDataInfo *pMeterDataInfo, SMeterObj *pMeterObj, int3 ...@@ -5771,35 +5911,35 @@ void setMeterDataInfo(SMeterDataInfo *pMeterDataInfo, SMeterObj *pMeterObj, int3
pMeterDataInfo->meterOrderIdx = meterIdx; pMeterDataInfo->meterOrderIdx = meterIdx;
} }
int32_t doCloseAllOpenedResults(SMeterQuerySupportObj *pSupporter) { // int32_t doCloseAllOpenedResults(STableQuerySupportObj *pSupporter) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; // SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; // SQuery * pQuery = pRuntimeEnv->pQuery;
//
/* for interval query, close all unclosed results */ // /* for interval query, close all unclosed results */
if (pQuery->intervalTime > 0) { // if (pQuery->intervalTime > 0) {
SMeterDataInfo *pMeterInfo = pSupporter->pMeterDataInfo; // SMeterDataInfo *pMeterInfo = pSupporter->pMeterDataInfo;
for (int32_t i = 0; i < pSupporter->numOfMeters; ++i) { // for (int32_t i = 0; i < pSupporter->numOfMeters; ++i) {
if (pMeterInfo[i].pMeterQInfo != NULL && pMeterInfo[i].pMeterQInfo->lastResRows > 0) { // if (pMeterInfo[i].pMeterQInfo != NULL && pMeterInfo[i].pMeterQInfo->lastResRows > 0) {
int32_t index = pMeterInfo[i].meterOrderIdx; // int32_t index = pMeterInfo[i].meterOrderIdx;
//
pRuntimeEnv->pMeterObj = getMeterObj(pSupporter->pMetersHashTable, pSupporter->pSidSet->pSids[index]->sid); // pRuntimeEnv->pMeterObj = getMeterObj(pSupporter->pMetersHashTable, pSupporter->pSidSet->pSids[index]->sid);
assert(pRuntimeEnv->pMeterObj == pMeterInfo[i].pMeterObj); // assert(pRuntimeEnv->pMeterObj == pMeterInfo[i].pMeterObj);
//
int32_t ret = setIntervalQueryExecutionContext(pSupporter, i, pMeterInfo[i].pMeterQInfo); // int32_t ret = setIntervalQueryExecutionContext(pSupporter, i, pMeterInfo[i].pMeterQInfo);
if (ret != TSDB_CODE_SUCCESS) { // if (ret != TSDB_CODE_SUCCESS) {
return ret; // return ret;
} // }
//
ret = saveResult(pSupporter, pMeterInfo[i].pMeterQInfo, pMeterInfo[i].pMeterQInfo->lastResRows); // ret = saveResult(pSupporter, pMeterInfo[i].pMeterQInfo, pMeterInfo[i].pMeterQInfo->lastResRows);
if (ret != TSDB_CODE_SUCCESS) { // if (ret != TSDB_CODE_SUCCESS) {
return ret; // return ret;
} // }
} // }
} // }
} // }
//
return TSDB_CODE_SUCCESS; // return TSDB_CODE_SUCCESS;
} //}
void disableFunctForSuppleScan(SQueryRuntimeEnv *pRuntimeEnv, int32_t order) { void disableFunctForSuppleScan(SQueryRuntimeEnv *pRuntimeEnv, int32_t order) {
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
...@@ -5890,7 +6030,7 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow ...@@ -5890,7 +6030,7 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow
} }
pWindowRes->numOfRows = 0; pWindowRes->numOfRows = 0;
pWindowRes->nAlloc = 0; // pWindowRes->nAlloc = 0;
pWindowRes->pos = (SPosInfo){-1, -1}; pWindowRes->pos = (SPosInfo){-1, -1};
pWindowRes->status.closed = false; pWindowRes->status.closed = false;
pWindowRes->window = (STimeWindow){0, 0}; pWindowRes->window = (STimeWindow){0, 0};
...@@ -5903,7 +6043,7 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow ...@@ -5903,7 +6043,7 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow
*/ */
void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, const SWindowResult *src) { void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, const SWindowResult *src) {
dst->numOfRows = src->numOfRows; dst->numOfRows = src->numOfRows;
dst->nAlloc = src->nAlloc; // dst->nAlloc = src->nAlloc;
dst->window = src->window; dst->window = src->window;
dst->status = src->status; dst->status = src->status;
...@@ -5922,7 +6062,7 @@ void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, con ...@@ -5922,7 +6062,7 @@ void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, con
// copy the output buffer data from src to dst, the position info keep unchanged // copy the output buffer data from src to dst, the position info keep unchanged
char * dstBuf = getPosInResultPage(pRuntimeEnv, i, dst); char * dstBuf = getPosInResultPage(pRuntimeEnv, i, dst);
char * srcBuf = getPosInResultPage(pRuntimeEnv, i, src); char * srcBuf = getPosInResultPage(pRuntimeEnv, i, (SWindowResult *)src);
size_t s = pRuntimeEnv->pQuery->pSelectExpr[i].resBytes; size_t s = pRuntimeEnv->pQuery->pSelectExpr[i].resBytes;
memcpy(dstBuf, srcBuf, s); memcpy(dstBuf, srcBuf, s);
...@@ -6290,88 +6430,88 @@ int64_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -6290,88 +6430,88 @@ int64_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv) {
return maxOutput; return maxOutput;
} }
static int32_t getNextIntervalQueryRange(SMeterQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv, // static int32_t getNextIntervalQueryRange(STableQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv,
int64_t *skey, int64_t *ekey) { // int64_t *skey, int64_t *ekey) {
SQuery *pQuery = pRuntimeEnv->pQuery; // SQuery *pQuery = pRuntimeEnv->pQuery;
//
int32_t factor = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); // int32_t factor = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
//
// *skey = pRuntimeEnv->intervalWindow.skey + (pQuery->slidingTime * factor);
// *ekey = pRuntimeEnv->intervalWindow.ekey + (pQuery->slidingTime * factor);
//
// if (pQuery->slidingTime > 0) {
// if (QUERY_IS_ASC_QUERY(pQuery)) {
// // the next sliding window is not contained in the query time range
// if (*skey < pSupporter->rawSKey) {
// *skey = pSupporter->rawSKey;
// }
//
// if (*skey > pSupporter->rawEKey) {
// return QUERY_COMPLETED;
// }
//
// if (*ekey > pSupporter->rawEKey) {
// *ekey = pSupporter->rawEKey;
// }
// } else {
// if (*skey > pSupporter->rawSKey) {
// *skey = pSupporter->rawSKey;
// }
//
// if (*skey < pSupporter->rawEKey) {
// return QUERY_COMPLETED;
// }
//
// if (*ekey < pSupporter->rawEKey) {
// *ekey = pSupporter->rawEKey;
// }
// }
// }
//
// return QUERY_NOT_COMPLETED;
//}
*skey = pRuntimeEnv->intervalWindow.skey + (pQuery->slidingTime * factor); /*
*ekey = pRuntimeEnv->intervalWindow.ekey + (pQuery->slidingTime * factor); * forward the query range for next interval query
*/
if (pQuery->slidingTime > 0) { // void forwardIntervalQueryRange(STableQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv) {
if (QUERY_IS_ASC_QUERY(pQuery)) { // SQuery *pQuery = pRuntimeEnv->pQuery;
// the next sliding window is not contained in the query time range // if (pQuery->slidingTime > 0 && pQuery->intervalTime > 0) {
if (*skey < pSupporter->rawSKey) { // if ((QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey >= pQuery->ekey) ||
*skey = pSupporter->rawSKey; // (!QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey <= pQuery->ekey)) {
} // setQueryStatus(pQuery, QUERY_COMPLETED);
// } else {
if (*skey > pSupporter->rawEKey) { // /*TSKEY nextTimestamp =*/loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
return QUERY_COMPLETED; // }
} //
// return;
if (*ekey > pSupporter->rawEKey) { // }
*ekey = pSupporter->rawEKey; //
} // // int32_t r = getNextIntervalQueryRange(pSupporter, pRuntimeEnv, &pQuery->skey, &pQuery->ekey);
} else { // // if (r == QUERY_COMPLETED) {
if (*skey > pSupporter->rawSKey) { // // setQueryStatus(pQuery, QUERY_COMPLETED);
*skey = pSupporter->rawSKey; // // return;
} // // }
// //
if (*skey < pSupporter->rawEKey) { // // getNextTimeWindow(pRuntimeEnv, &pRuntimeEnv->intervalWindow);
return QUERY_COMPLETED; // //
} // // /* ensure the search in cache will return right position */
// // pQuery->lastKey = pQuery->skey;
if (*ekey < pSupporter->rawEKey) { // //
*ekey = pSupporter->rawEKey; // // TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
} // // if ((nextTimestamp > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
} // // (nextTimestamp < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery)) ||
} // // Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) {
// // setQueryStatus(pQuery, QUERY_COMPLETED);
return QUERY_NOT_COMPLETED; // // return;
} // // }
// //
/* // // // bridge the gap in group by time function
* forward the query range for next interval query // // if ((nextTimestamp > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
*/ // // (nextTimestamp < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
void forwardIntervalQueryRange(SMeterQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv) { // // getAlignedIntervalQueryRange(pRuntimeEnv, nextTimestamp, pSupporter->rawSKey, pSupporter->rawEKey);
SQuery *pQuery = pRuntimeEnv->pQuery; // // }
if (pQuery->slidingTime > 0 && pQuery->intervalTime > 0) { //}
if ((QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey >= pQuery->ekey) ||
(!QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey <= pQuery->ekey)) {
setQueryStatus(pQuery, QUERY_COMPLETED);
} else {
/*TSKEY nextTimestamp =*/loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
}
return;
}
// int32_t r = getNextIntervalQueryRange(pSupporter, pRuntimeEnv, &pQuery->skey, &pQuery->ekey);
// if (r == QUERY_COMPLETED) {
// setQueryStatus(pQuery, QUERY_COMPLETED);
// return;
// }
//
// getNextTimeWindow(pRuntimeEnv, &pRuntimeEnv->intervalWindow);
//
// /* ensure the search in cache will return right position */
// pQuery->lastKey = pQuery->skey;
//
// TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
// if ((nextTimestamp > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
// (nextTimestamp < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery)) ||
// Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) {
// setQueryStatus(pQuery, QUERY_COMPLETED);
// return;
// }
//
// // bridge the gap in group by time function
// if ((nextTimestamp > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
// (nextTimestamp < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
// getAlignedIntervalQueryRange(pRuntimeEnv, nextTimestamp, pSupporter->rawSKey, pSupporter->rawEKey);
// }
}
static int32_t offsetComparator(const void *pLeft, const void *pRight) { static int32_t offsetComparator(const void *pLeft, const void *pRight) {
SMeterDataInfo **pLeft1 = (SMeterDataInfo **)pLeft; SMeterDataInfo **pLeft1 = (SMeterDataInfo **)pLeft;
...@@ -6398,7 +6538,7 @@ int32_t vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, tSidSet *pSidSet ...@@ -6398,7 +6538,7 @@ int32_t vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, tSidSet *pSidSet
int32_t *numOfMeters, SMeterDataInfo ***pReqMeterDataInfo) { int32_t *numOfMeters, SMeterDataInfo ***pReqMeterDataInfo) {
SQuery *pQuery = &pQInfo->query; SQuery *pQuery = &pQInfo->query;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SMeterSidExtInfo ** pMeterSidExtInfo = pSupporter->pMeterSidExtInfo; SMeterSidExtInfo ** pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
...@@ -6514,7 +6654,7 @@ int32_t vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, tSidSet *pSidSet ...@@ -6514,7 +6654,7 @@ int32_t vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, tSidSet *pSidSet
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
SMeterQueryInfo *createMeterQueryInfo(SMeterQuerySupportObj *pSupporter, int32_t sid, TSKEY skey, TSKEY ekey) { SMeterQueryInfo *createMeterQueryInfo(STableQuerySupportObj *pSupporter, int32_t sid, TSKEY skey, TSKEY ekey) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SMeterQueryInfo *pMeterQueryInfo = calloc(1, sizeof(SMeterQueryInfo)); SMeterQueryInfo *pMeterQueryInfo = calloc(1, sizeof(SMeterQueryInfo));
...@@ -6551,25 +6691,22 @@ void changeMeterQueryInfoForSuppleQuery(SQueryDiskbasedResultBuf *pResultBuf, SM ...@@ -6551,25 +6691,22 @@ void changeMeterQueryInfoForSuppleQuery(SQueryDiskbasedResultBuf *pResultBuf, SM
return; return;
} }
// pMeterQueryInfo->skey = skey;
// pMeterQueryInfo->ekey = ekey;
SWAP(pMeterQueryInfo->skey, pMeterQueryInfo->ekey, TSKEY); SWAP(pMeterQueryInfo->skey, pMeterQueryInfo->ekey, TSKEY);
pMeterQueryInfo->lastKey = pMeterQueryInfo->skey; pMeterQueryInfo->lastKey = pMeterQueryInfo->skey;
// pMeterQueryInfo->queryRangeSet = 0; // pMeterQueryInfo->queryRangeSet = 0;
pMeterQueryInfo->cur.order = pMeterQueryInfo->cur.order ^ 1; pMeterQueryInfo->cur.order = pMeterQueryInfo->cur.order ^ 1;
pMeterQueryInfo->cur.vnodeIndex = -1; pMeterQueryInfo->cur.vnodeIndex = -1;
// previous does not generate any results // previous does not generate any results
SIDList list = getDataBufPagesIdList(pResultBuf, pMeterQueryInfo->sid); // SIDList list = getDataBufPagesIdList(pResultBuf, pMeterQueryInfo->sid);
//
if (list.size == 0) { // if (list.size == 0) {
pMeterQueryInfo->reverseFillRes = 0; // pMeterQueryInfo->reverseFillRes = 0;
} else { // } else {
pMeterQueryInfo->reverseIndex = pMeterQueryInfo->numOfRes; // pMeterQueryInfo->reverseIndex = pMeterQueryInfo->numOfRes;
pMeterQueryInfo->reverseFillRes = 1; // pMeterQueryInfo->reverseFillRes = 1;
} // }
} }
void saveIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, SMeterQueryInfo *pMeterQueryInfo) { void saveIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, SMeterQueryInfo *pMeterQueryInfo) {
...@@ -6698,7 +6835,7 @@ static bool setCurrentQueryRange(SMeterDataInfo *pMeterDataInfo, SQuery *pQuery, ...@@ -6698,7 +6835,7 @@ static bool setCurrentQueryRange(SMeterDataInfo *pMeterDataInfo, SQuery *pQuery,
* @param pMeterDataInfo * @param pMeterDataInfo
* @return * @return
*/ */
int32_t getDataBlocksForMeters(SMeterQuerySupportObj *pSupporter, SQuery *pQuery, int32_t numOfMeters, int32_t getDataBlocksForMeters(STableQuerySupportObj *pSupporter, SQuery *pQuery, int32_t numOfMeters,
const char *filePath, SMeterDataInfo **pMeterDataInfo, uint32_t *numOfBlocks) { const char *filePath, SMeterDataInfo **pMeterDataInfo, uint32_t *numOfBlocks) {
SQInfo * pQInfo = (SQInfo *)GET_QINFO_ADDR(pQuery); SQInfo * pQInfo = (SQInfo *)GET_QINFO_ADDR(pQuery);
SQueryCostSummary *pSummary = &pSupporter->runtimeEnv.summary; SQueryCostSummary *pSummary = &pSupporter->runtimeEnv.summary;
...@@ -6960,11 +7097,28 @@ int32_t createDataBlocksInfoEx(SMeterDataInfo **pMeterDataInfo, int32_t numOfMet ...@@ -6960,11 +7097,28 @@ int32_t createDataBlocksInfoEx(SMeterDataInfo **pMeterDataInfo, int32_t numOfMet
* @param pRuntimeEnv * @param pRuntimeEnv
* @param pDataBlockInfoEx * @param pDataBlockInfoEx
*/ */
void setExecutionContext(SMeterQuerySupportObj *pSupporter, SWindowResult *outputRes, int32_t meterIdx, void setExecutionContext(STableQuerySupportObj *pSupporter, SWindowResult *outputRes, int32_t meterIdx,
int32_t groupIdx, SMeterQueryInfo *pMeterQueryInfo) { int32_t groupIdx, SMeterQueryInfo *pMeterQueryInfo) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
int32_t GROUP_RES_ID = 1;
SWindowResult *pWindowRes =
doSetTimeWindowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, (char *)&groupIdx, sizeof(groupIdx));
if (pWindowRes == NULL) {
return;
}
setWindowResOutputBuf(pRuntimeEnv, &outputRes[groupIdx]); // not assign result buffer yet, add new result buffer
// all group belong to one result set, and each group result has different group id so set the id to be one
if (pWindowRes->pos.pageId == -1) {
int32_t ret =
addNewWindowResultBuf(pWindowRes, pRuntimeEnv->pResultBuf, GROUP_RES_ID, pRuntimeEnv->numOfRowsPerPage);
if (ret != 0) {
return;
}
}
setWindowResOutputBuf(pRuntimeEnv, pWindowRes);
initCtxOutputBuf(pRuntimeEnv); initCtxOutputBuf(pRuntimeEnv);
vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pSupporter->pMeterSidExtInfo[meterIdx]); vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pSupporter->pMeterSidExtInfo[meterIdx]);
...@@ -7002,9 +7156,7 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult * ...@@ -7002,9 +7156,7 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
// set super table query flag // set super table query flag
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
// if (!isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
pResInfo->superTableQ = pRuntimeEnv->stableQuery; pResInfo->superTableQ = pRuntimeEnv->stableQuery;
// }
} }
} }
...@@ -7016,66 +7168,66 @@ static char *getOutputResPos(SQueryRuntimeEnv *pRuntimeEnv, tFilePage *pData, in ...@@ -7016,66 +7168,66 @@ static char *getOutputResPos(SQueryRuntimeEnv *pRuntimeEnv, tFilePage *pData, in
pRuntimeEnv->pCtx[col].outputBytes * row; pRuntimeEnv->pCtx[col].outputBytes * row;
} }
void setCtxOutputPointerForSupplementScan(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo) { // void setCtxOutputPointerForSupplementScan(STableQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; // SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; // SQuery * pQuery = pRuntimeEnv->pQuery;
//
int32_t index = pMeterQueryInfo->reverseIndex; // int32_t index = pMeterQueryInfo->reverseIndex;
tFilePage *pData = NULL; // tFilePage *pData = NULL;
int32_t i = 0; // int32_t i = 0;
//
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf; // SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
//
// find the position for this output result // // find the position for this output result
SIDList list = getDataBufPagesIdList(pResultBuf, pMeterQueryInfo->sid); // SIDList list = getDataBufPagesIdList(pResultBuf, pMeterQueryInfo->sid);
for (; i < list.size; ++i) { // for (; i < list.size; ++i) {
pData = getResultBufferPageById(pResultBuf, list.pData[i]); // pData = getResultBufferPageById(pResultBuf, list.pData[i]);
if (index <= pData->numOfElems) { // if (index <= pData->numOfElems) {
break; // break;
} // }
//
index -= pData->numOfElems; // index -= pData->numOfElems;
} // }
//
assert(index >= 0); // assert(index >= 0);
//
/* // /*
* if it is the first records in master scan, no next results exist, so no need to init the result buffer // * if it is the first records in master scan, no next results exist, so no need to init the result buffer
* all data are processed and save to buffer during supplementary scan. // * all data are processed and save to buffer during supplementary scan.
*/ // */
if (index == 0) { // if (index == 0) {
return; // return;
} // }
//
for (int32_t k = 0; k < pQuery->numOfOutputCols; ++k) { // for (int32_t k = 0; k < pQuery->numOfOutputCols; ++k) {
SQLFunctionCtx *pCtx = &pRuntimeEnv->pCtx[k]; // SQLFunctionCtx *pCtx = &pRuntimeEnv->pCtx[k];
//
pCtx->aOutputBuf = getOutputResPos(pRuntimeEnv, pData, index - 1, k); // pCtx->aOutputBuf = getOutputResPos(pRuntimeEnv, pData, index - 1, k);
SResultInfo *pResInfo = GET_RES_INFO(pCtx); // SResultInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->complete) { // if (pResInfo->complete) {
continue; // continue;
} // }
//
int32_t functId = pQuery->pSelectExpr[k].pBase.functionId; // int32_t functId = pQuery->pSelectExpr[k].pBase.functionId;
//
// setup runtime environment // // setup runtime environment
if ((QUERY_IS_ASC_QUERY(pQuery) && functId == TSDB_FUNC_FIRST_DST) || // if ((QUERY_IS_ASC_QUERY(pQuery) && functId == TSDB_FUNC_FIRST_DST) ||
(!QUERY_IS_ASC_QUERY(pQuery) && functId == TSDB_FUNC_LAST_DST)) { // (!QUERY_IS_ASC_QUERY(pQuery) && functId == TSDB_FUNC_LAST_DST)) {
if (pMeterQueryInfo->lastResRows == 0) { // if (pMeterQueryInfo->lastResRows == 0) {
pCtx->currentStage = 0; // pCtx->currentStage = 0;
//
resetResultInfo(pResInfo); // resetResultInfo(pResInfo);
aAggs[functId].init(pCtx); // aAggs[functId].init(pCtx);
} // }
} // }
} // }
//
// the first column is always the timestamp for interval query // // the first column is always the timestamp for interval query
TSKEY ts = *(TSKEY *)pRuntimeEnv->pCtx[0].aOutputBuf; // TSKEY ts = *(TSKEY *)pRuntimeEnv->pCtx[0].aOutputBuf;
SMeterObj *pMeterObj = pRuntimeEnv->pMeterObj; // SMeterObj *pMeterObj = pRuntimeEnv->pMeterObj;
qTrace("QInfo:%p vid:%d sid:%d id:%s, set output result pointer, ts:%" PRId64 ", index:%d", GET_QINFO_ADDR(pQuery), // qTrace("QInfo:%p vid:%d sid:%d id:%s, set output result pointer, ts:%" PRId64 ", index:%d", GET_QINFO_ADDR(pQuery),
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, ts, pMeterQueryInfo->reverseIndex); // pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, ts, pMeterQueryInfo->reverseIndex);
} //}
void validateTimestampForSupplementResult(SQueryRuntimeEnv *pRuntimeEnv, int64_t numOfIncrementRes) { void validateTimestampForSupplementResult(SQueryRuntimeEnv *pRuntimeEnv, int64_t numOfIncrementRes) {
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -7120,35 +7272,36 @@ int32_t setOutputBufferForIntervalQuery(SQueryRuntimeEnv *pRuntimeEnv, SMeterQue ...@@ -7120,35 +7272,36 @@ int32_t setOutputBufferForIntervalQuery(SQueryRuntimeEnv *pRuntimeEnv, SMeterQue
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t setIntervalQueryExecutionContext(SMeterQuerySupportObj *pSupporter, int32_t meterIdx, int32_t setIntervalQueryExecutionContext(STableQuerySupportObj *pSupporter, int32_t meterIdx,
SMeterQueryInfo *pMeterQueryInfo) { SMeterQueryInfo *pMeterQueryInfo) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
assert(pMeterQueryInfo->lastKey > 0);
if (IS_MASTER_SCAN(pRuntimeEnv)) { // if (IS_MASTER_SCAN(pRuntimeEnv)) {
// not enough disk space or memory buffer for intermediate results // not enough disk space or memory buffer for intermediate results
if (setOutputBufferForIntervalQuery(pRuntimeEnv, pMeterQueryInfo) != TSDB_CODE_SUCCESS) { if (setOutputBufferForIntervalQuery(pRuntimeEnv, pMeterQueryInfo) != TSDB_CODE_SUCCESS) {
return -1; return -1;
} }
if (pMeterQueryInfo->lastResRows == 0) { // if (pMeterQueryInfo->lastResRows == 0) {
initCtxOutputBuf(pRuntimeEnv); initCtxOutputBuf(pRuntimeEnv);
} // }
} else { // } else {
if (pMeterQueryInfo->reverseFillRes) { // if (pMeterQueryInfo->reverseFillRes) {
setCtxOutputPointerForSupplementScan(pSupporter, pMeterQueryInfo); // setCtxOutputPointerForSupplementScan(pSupporter, pMeterQueryInfo);
} else { // } else {
/* // /*
* set output buffer for reverse scan data blocks // * set output buffer for reverse scan data blocks
* find the correct output position of existed results during // * find the correct output position of existed results during
* // *
* If the master scan does not produce any results, new spaces needed to be allocated during supplement scan // * If the master scan does not produce any results, new spaces needed to be allocated during supplement scan
*/ // */
if (setOutputBufferForIntervalQuery(pRuntimeEnv, pMeterQueryInfo) != TSDB_CODE_SUCCESS) { // if (setOutputBufferForIntervalQuery(pRuntimeEnv, pMeterQueryInfo) != TSDB_CODE_SUCCESS) {
return -1; // return -1;
} // }
} // }
} // }
vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pSupporter->pMeterSidExtInfo[meterIdx]); vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pSupporter->pMeterSidExtInfo[meterIdx]);
...@@ -7169,107 +7322,107 @@ int32_t setIntervalQueryExecutionContext(SMeterQuerySupportObj *pSupporter, int3 ...@@ -7169,107 +7322,107 @@ int32_t setIntervalQueryExecutionContext(SMeterQuerySupportObj *pSupporter, int3
return 0; return 0;
} }
static void doApplyIntervalQueryOnBlock_rv(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo, // static void doApplyIntervalQueryOnBlock_rv(STableQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo,
SBlockInfo *pBlockInfo, int64_t *pPrimaryCol, SField *pFields, // SBlockInfo *pBlockInfo, int64_t *pPrimaryCol, SField *pFields,
__block_search_fn_t searchFn) { // __block_search_fn_t searchFn) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; // SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; // SQuery * pQuery = pRuntimeEnv->pQuery;
int32_t factor = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); // int32_t factor = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
//
while (1) { // while (1) {
int64_t nextKey = -1; // int64_t nextKey = -1;
int32_t numOfRes = 0; // int32_t numOfRes = 0;
//
int32_t steps = applyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, pPrimaryCol, pFields, searchFn, &numOfRes, // int32_t steps = applyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, pPrimaryCol, pFields, searchFn, &numOfRes,
&pMeterQueryInfo->windowResInfo); // &pMeterQueryInfo->windowResInfo);
assert(steps > 0); // assert(steps > 0);
//
// NOTE: in case of stable query, only ONE(or ZERO) row of result generated for each query range // // NOTE: in case of stable query, only ONE(or ZERO) row of result generated for each query range
if (pMeterQueryInfo->lastResRows == 0) { // if (pMeterQueryInfo->lastResRows == 0) {
pMeterQueryInfo->lastResRows = numOfRes; // pMeterQueryInfo->lastResRows = numOfRes;
} else { // } else {
assert(pMeterQueryInfo->lastResRows == 1); // assert(pMeterQueryInfo->lastResRows == 1);
} // }
//
int32_t pos = pQuery->pos + steps * factor; // int32_t pos = pQuery->pos + steps * factor;
//
// query does not reach the end of current block // // query does not reach the end of current block
if ((pos < pBlockInfo->size && QUERY_IS_ASC_QUERY(pQuery)) || (pos >= 0 && !QUERY_IS_ASC_QUERY(pQuery))) { // if ((pos < pBlockInfo->size && QUERY_IS_ASC_QUERY(pQuery)) || (pos >= 0 && !QUERY_IS_ASC_QUERY(pQuery))) {
nextKey = pPrimaryCol[pos]; // nextKey = pPrimaryCol[pos];
} else { // } else {
assert((pQuery->lastKey > pBlockInfo->keyLast && QUERY_IS_ASC_QUERY(pQuery)) || // assert((pQuery->lastKey > pBlockInfo->keyLast && QUERY_IS_ASC_QUERY(pQuery)) ||
(pQuery->lastKey < pBlockInfo->keyFirst && !QUERY_IS_ASC_QUERY(pQuery))); // (pQuery->lastKey < pBlockInfo->keyFirst && !QUERY_IS_ASC_QUERY(pQuery)));
} // }
//
// all data satisfy current query are checked, query completed // // all data satisfy current query are checked, query completed
bool completed = false; // bool completed = false;
if (QUERY_IS_ASC_QUERY(pQuery)) { // if (QUERY_IS_ASC_QUERY(pQuery)) {
completed = (pQuery->lastKey > pQuery->ekey); // completed = (pQuery->lastKey > pQuery->ekey);
} else { // } else {
completed = (pQuery->lastKey < pQuery->ekey); // completed = (pQuery->lastKey < pQuery->ekey);
} // }
//
/* // /*
* 1. there may be more date that satisfy current query interval, other than // * 1. there may be more date that satisfy current query interval, other than
* current block, we need to try next data blocks // * current block, we need to try next data blocks
* 2. query completed, since it reaches the upper bound of the main query range // * 2. query completed, since it reaches the upper bound of the main query range
*/ // */
if (!completed) { // if (!completed) {
/* // /*
* Data that satisfy current query range may locate in current block and blocks that are directly right // * Data that satisfy current query range may locate in current block and blocks that are directly right
* next to current block. Therefore, we need to keep the query range(interval) unchanged until reaching // * next to current block. Therefore, we need to keep the query range(interval) unchanged until reaching
* the direct next data block, while only forwards the pQuery->lastKey. // * the direct next data block, while only forwards the pQuery->lastKey.
* // *
* With the information of the directly next data block, whether locates in cache or disk, // * With the information of the directly next data block, whether locates in cache or disk,
* current interval query being completed or not can be decided. // * current interval query being completed or not can be decided.
*/ // */
saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo); // saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
//
if (QUERY_IS_ASC_QUERY(pQuery)) { // if (QUERY_IS_ASC_QUERY(pQuery)) {
assert(pQuery->lastKey > pBlockInfo->keyLast && pQuery->lastKey <= pQuery->ekey); // assert(pQuery->lastKey > pBlockInfo->keyLast && pQuery->lastKey <= pQuery->ekey);
} else { // } else {
assert(pQuery->lastKey < pBlockInfo->keyFirst && pQuery->lastKey >= pQuery->ekey); // assert(pQuery->lastKey < pBlockInfo->keyFirst && pQuery->lastKey >= pQuery->ekey);
} // }
//
break; // break;
} // }
//
assert(completed); // assert(completed);
//
// while the interval time window is less than the time range gap between two points, nextKey may be greater than // // while the interval time window is less than the time range gap between two points, nextKey may be greater than
// pSupporter->rawEKey // // pSupporter->rawEKey
if (pQuery->ekey == pSupporter->rawEKey || (nextKey > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) || // if (pQuery->ekey == pSupporter->rawEKey || (nextKey > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
(nextKey < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) { // (nextKey < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) {
/* whole query completed, save result and abort */ // /* whole query completed, save result and abort */
saveResult(pSupporter, pMeterQueryInfo, pMeterQueryInfo->lastResRows); // saveResult(pSupporter, pMeterQueryInfo, pMeterQueryInfo->lastResRows);
//
// save the pQuery->lastKey for retrieve data in cache, actually, there will be no qualified data in cache. // // save the pQuery->lastKey for retrieve data in cache, actually, there will be no qualified data in cache.
saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo); // saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
//
return; // return;
} else if ((QUERY_IS_ASC_QUERY(pQuery) && pQuery->ekey == pBlockInfo->keyLast) || // } else if ((QUERY_IS_ASC_QUERY(pQuery) && pQuery->ekey == pBlockInfo->keyLast) ||
(!QUERY_IS_ASC_QUERY(pQuery) && pQuery->ekey == pBlockInfo->keyFirst)) { // (!QUERY_IS_ASC_QUERY(pQuery) && pQuery->ekey == pBlockInfo->keyFirst)) {
/* current interval query is completed, set the next query range on other data blocks if exist */ // /* current interval query is completed, set the next query range on other data blocks if exist */
saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo); // saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
return; // return;
} // }
//
saveResult(pSupporter, pMeterQueryInfo, pMeterQueryInfo->lastResRows); // saveResult(pSupporter, pMeterQueryInfo, pMeterQueryInfo->lastResRows);
//
assert(pos >= 0 && pos < pBlockInfo->size); // assert(pos >= 0 && pos < pBlockInfo->size);
assert((nextKey >= pQuery->lastKey && QUERY_IS_ASC_QUERY(pQuery)) || // assert((nextKey >= pQuery->lastKey && QUERY_IS_ASC_QUERY(pQuery)) ||
(nextKey <= pQuery->lastKey && !QUERY_IS_ASC_QUERY(pQuery))); // (nextKey <= pQuery->lastKey && !QUERY_IS_ASC_QUERY(pQuery)));
//
/* still in the same block to query */ // /* still in the same block to query */
getAlignedIntervalQueryRange(pRuntimeEnv, nextKey, pSupporter->rawSKey, pSupporter->rawEKey); // getAlignedIntervalQueryRange(pRuntimeEnv, nextKey, pSupporter->rawSKey, pSupporter->rawEKey);
saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo); // saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
//
int32_t newPos = searchFn((char *)pPrimaryCol, pBlockInfo->size, pQuery->skey, pQuery->order.order); // int32_t newPos = searchFn((char *)pPrimaryCol, pBlockInfo->size, pQuery->skey, pQuery->order.order);
assert(newPos == pQuery->pos + steps * factor); // assert(newPos == pQuery->pos + steps * factor);
//
pQuery->pos = newPos; // pQuery->pos = newPos;
} // }
} //}
int64_t getNextAccessedKeyInData(SQuery *pQuery, int64_t *pPrimaryCol, SBlockInfo *pBlockInfo, int32_t blockStatus) { int64_t getNextAccessedKeyInData(SQuery *pQuery, int64_t *pPrimaryCol, SBlockInfo *pBlockInfo, int32_t blockStatus) {
assert(pQuery->pos >= 0 && pQuery->pos <= pBlockInfo->size - 1); assert(pQuery->pos >= 0 && pQuery->pos <= pBlockInfo->size - 1);
...@@ -7277,7 +7430,7 @@ int64_t getNextAccessedKeyInData(SQuery *pQuery, int64_t *pPrimaryCol, SBlockInf ...@@ -7277,7 +7430,7 @@ int64_t getNextAccessedKeyInData(SQuery *pQuery, int64_t *pPrimaryCol, SBlockInf
TSKEY key = -1; TSKEY key = -1;
if (IS_DATA_BLOCK_LOADED(blockStatus)) { if (IS_DATA_BLOCK_LOADED(blockStatus)) {
key = pPrimaryCol[pQuery->pos]; key = pPrimaryCol[pQuery->pos];
} else {// while the data block is not loaded, the position must be the first or last position } else { // while the data block is not loaded, the position must be the first or last position
assert(pQuery->pos == pBlockInfo->size - 1 || pQuery->pos == 0); assert(pQuery->pos == pBlockInfo->size - 1 || pQuery->pos == 0);
key = QUERY_IS_ASC_QUERY(pQuery) ? pBlockInfo->keyFirst : pBlockInfo->keyLast; key = QUERY_IS_ASC_QUERY(pQuery) ? pBlockInfo->keyFirst : pBlockInfo->keyLast;
} }
...@@ -7295,31 +7448,36 @@ int64_t getNextAccessedKeyInData(SQuery *pQuery, int64_t *pPrimaryCol, SBlockInf ...@@ -7295,31 +7448,36 @@ int64_t getNextAccessedKeyInData(SQuery *pQuery, int64_t *pPrimaryCol, SBlockInf
* merged during merge stage. In this case, we need the pMeterQueryInfo->lastResRows to decide if there * merged during merge stage. In this case, we need the pMeterQueryInfo->lastResRows to decide if there
* is a previous result generated or not. * is a previous result generated or not.
*/ */
void setIntervalQueryRange(SMeterQueryInfo *pMeterQueryInfo, SMeterQuerySupportObj *pSupporter, TSKEY key) { void setIntervalQueryRange(SMeterQueryInfo *pMeterQueryInfo, STableQuerySupportObj *pSupporter, TSKEY key) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
if (pMeterQueryInfo->queryRangeSet) { if (pMeterQueryInfo->queryRangeSet) {
// assert((QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey >= pQuery->skey) || // assert((QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey >= pQuery->skey) ||
// (!QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey <= pQuery->skey)); // (!QUERY_IS_ASC_QUERY(pQuery) && pQuery->lastKey <= pQuery->skey));
// //
// if ((pQuery->ekey < key && QUERY_IS_ASC_QUERY(pQuery)) || (pQuery->ekey > key && !QUERY_IS_ASC_QUERY(pQuery))) { // if ((pQuery->ekey < key && QUERY_IS_ASC_QUERY(pQuery)) || (pQuery->ekey > key && !QUERY_IS_ASC_QUERY(pQuery)))
// /* // {
// * last query on this block of the meter is done, start next interval on this block // /*
// * otherwise, keep the previous query range and proceed // * last query on this block of the meter is done, start next interval on this block
// */ // * otherwise, keep the previous query range and proceed
// getAlignedIntervalQueryRange(pRuntimeEnv, key, pSupporter->rawSKey, pSupporter->rawEKey); // */
// saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo); // getAlignedIntervalQueryRange(pRuntimeEnv, key, pSupporter->rawSKey, pSupporter->rawEKey);
// // saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
// // previous query does not be closed, save the results and close it //
// if (pMeterQueryInfo->lastResRows > 0) { // // previous query does not be closed, save the results and close it
// saveResult(pSupporter, pMeterQueryInfo, pMeterQueryInfo->lastResRows); // if (pMeterQueryInfo->lastResRows > 0) {
// } // saveResult(pSupporter, pMeterQueryInfo, pMeterQueryInfo->lastResRows);
// } else { // }
// /* current query not completed, continue. do nothing with respect to query range, */ // } else {
// } // /* current query not completed, continue. do nothing with respect to query range, */
// }
// pQuery->lastKey = key;
// pMeterQueryInfo->lastKey = key;
} else { } else {
pQuery->skey = key; pQuery->skey = key;
STimeWindow win = {.skey = key, pSupporter->rawEKey};
assert(pMeterQueryInfo->lastResRows == 0); assert(pMeterQueryInfo->lastResRows == 0);
// for too small query range, no data in this interval. // for too small query range, no data in this interval.
...@@ -7335,31 +7493,45 @@ void setIntervalQueryRange(SMeterQueryInfo *pMeterQueryInfo, SMeterQuerySupportO ...@@ -7335,31 +7493,45 @@ void setIntervalQueryRange(SMeterQueryInfo *pMeterQueryInfo, SMeterQuerySupportO
* operations involve. * operations involve.
*/ */
if (!QUERY_IS_ASC_QUERY(pQuery)) { if (!QUERY_IS_ASC_QUERY(pQuery)) {
TSKEY k = getGreaterEqualTimestamp(pRuntimeEnv);
win.skey = k;
win.ekey = key; // current key is the last timestamp value that are contained in query time window
SPositionInfo p = {.fileId = pQuery->fileId, .slot = pQuery->slot, .pos = pQuery->pos};
loadRequiredBlockIntoMem(pRuntimeEnv, &p);
} }
TSKEY skey1, ekey1; TSKEY skey1, ekey1;
TSKEY windowSKey = 0, windowEKey = 0; TSKEY windowSKey = 0, windowEKey = 0;
STimeWindow win = {.skey = key, pSupporter->rawEKey};
SWindowResInfo* pWindowResInfo = &pMeterQueryInfo->windowResInfo; SWindowResInfo *pWindowResInfo = &pMeterQueryInfo->windowResInfo;
doGetAlignedIntervalQueryRangeImpl(pQuery, win.skey, win.skey, win.ekey, &skey1, &ekey1, &windowSKey, &windowEKey); doGetAlignedIntervalQueryRangeImpl(pQuery, win.skey, win.skey, win.ekey, &skey1, &ekey1, &windowSKey, &windowEKey);
pWindowResInfo->startTime = windowSKey; pWindowResInfo->startTime = windowSKey;
assert(pWindowResInfo->startTime > 0);
if (pWindowResInfo->prevSKey == 0) { if (pWindowResInfo->prevSKey == 0) {
if (QUERY_IS_ASC_QUERY(pQuery)) {
pWindowResInfo->prevSKey = windowSKey; pWindowResInfo->prevSKey = windowSKey;
} else {
assert(win.ekey == pQuery->skey);
pWindowResInfo->prevSKey = windowSKey + ((win.ekey - windowSKey) / pQuery->slidingTime) * pQuery->slidingTime;
}
} }
win = getActiveTimeWindow(pWindowResInfo, key, pQuery); win = getActiveTimeWindow(pWindowResInfo, pQuery->skey, pQuery);
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&win.skey, TSDB_KEYSIZE); SWindowResult *pWindowRes =
doSetTimeWindowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&pQuery->skey, TSDB_KEYSIZE);
if (pWindowRes == NULL) { if (pWindowRes == NULL) {
return; return;
} }
pWindowRes->window = win; pWindowRes->window = win;
pMeterQueryInfo->queryRangeSet = 1; pMeterQueryInfo->queryRangeSet = 1;
pMeterQueryInfo->lastKey = win.skey; pMeterQueryInfo->lastKey = pQuery->skey;
pMeterQueryInfo->skey = win.skey; pMeterQueryInfo->skey = pQuery->skey;
pQuery->lastKey = pQuery->skey;
} }
} }
...@@ -7514,7 +7686,7 @@ bool onDemandLoadDatablock(SQuery *pQuery, int16_t queryRangeSet) { ...@@ -7514,7 +7686,7 @@ bool onDemandLoadDatablock(SQuery *pQuery, int16_t queryRangeSet) {
return (pQuery->intervalTime == 0) || ((queryRangeSet == 1) && (pQuery->intervalTime > 0)); return (pQuery->intervalTime == 0) || ((queryRangeSet == 1) && (pQuery->intervalTime > 0));
} }
static void validateResultBuf(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo) { static void validateResultBuf(STableQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo) {
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pSupporter->runtimeEnv.pQuery; SQuery * pQuery = pSupporter->runtimeEnv.pQuery;
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf; SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
...@@ -7528,99 +7700,99 @@ static void validateResultBuf(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo ...@@ -7528,99 +7700,99 @@ static void validateResultBuf(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo
} }
} }
int32_t saveResult(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo, int32_t numOfResult) { // int32_t saveResult(STableQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo, int32_t numOfResult) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; // SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; // SQuery * pQuery = pRuntimeEnv->pQuery;
//
// no results generated, do nothing for master scan // // no results generated, do nothing for master scan
if (numOfResult <= 0) { // if (numOfResult <= 0) {
if (IS_MASTER_SCAN(pRuntimeEnv)) { // if (IS_MASTER_SCAN(pRuntimeEnv)) {
return TSDB_CODE_SUCCESS; // return TSDB_CODE_SUCCESS;
} else { // } else {
/* // /*
* There is a case that no result generated during the the supplement scan, and during the main // * There is a case that no result generated during the the supplement scan, and during the main
* scan also no result generated. The index can be backwards moved. // * scan also no result generated. The index can be backwards moved.
* // *
* However, if during the main scan, there is a result generated, such as applies count to timestamp, which // * However, if during the main scan, there is a result generated, such as applies count to timestamp, which
* always generates a result, but applies last query to a NULL column may fail to generate results during the // * always generates a result, but applies last query to a NULL column may fail to generate results during the
* supplement scan. // * supplement scan.
* // *
* NOTE: // * NOTE:
* nStartQueryTimestamp is the actually timestamp of current interval, if the actually interval timestamp // * nStartQueryTimestamp is the actually timestamp of current interval, if the actually interval timestamp
* equals to the recorded timestamp that is acquired during the master scan, backwards one step even // * equals to the recorded timestamp that is acquired during the master scan, backwards one step even
* there is no results during the supplementary scan. // * there is no results during the supplementary scan.
*/ // */
TSKEY ts = *(TSKEY *)pRuntimeEnv->pCtx[0].aOutputBuf; // TSKEY ts = *(TSKEY *)pRuntimeEnv->pCtx[0].aOutputBuf;
if (ts == pRuntimeEnv->pCtx[0].nStartQueryTimestamp && pMeterQueryInfo->reverseIndex > 0) { // if (ts == pRuntimeEnv->pCtx[0].nStartQueryTimestamp && pMeterQueryInfo->reverseIndex > 0) {
assert(pMeterQueryInfo->numOfRes >= 0 && pMeterQueryInfo->reverseIndex > 0 && // assert(pMeterQueryInfo->numOfRes >= 0 && pMeterQueryInfo->reverseIndex > 0 &&
pMeterQueryInfo->reverseIndex <= pMeterQueryInfo->numOfRes); // pMeterQueryInfo->reverseIndex <= pMeterQueryInfo->numOfRes);
//
// backward one step from the previous position, the start position is (pMeterQueryInfo->numOfRows-1); // // backward one step from the previous position, the start position is (pMeterQueryInfo->numOfRows-1);
pMeterQueryInfo->reverseIndex -= 1; // pMeterQueryInfo->reverseIndex -= 1;
setCtxOutputPointerForSupplementScan(pSupporter, pMeterQueryInfo); // setCtxOutputPointerForSupplementScan(pSupporter, pMeterQueryInfo);
} // }
//
return TSDB_CODE_SUCCESS; // return TSDB_CODE_SUCCESS;
} // }
} // }
//
assert(pMeterQueryInfo->lastResRows == 1); // assert(pMeterQueryInfo->lastResRows == 1);
numOfResult = 1; // numOfResult = 1;
pMeterQueryInfo->lastResRows = 0; // pMeterQueryInfo->lastResRows = 0;
//
if (IS_SUPPLEMENT_SCAN(pRuntimeEnv) && pMeterQueryInfo->reverseFillRes == 1) { // if (IS_SUPPLEMENT_SCAN(pRuntimeEnv) && pMeterQueryInfo->reverseFillRes == 1) {
assert(pMeterQueryInfo->numOfRes > 0 && pMeterQueryInfo->reverseIndex > 0 && // assert(pMeterQueryInfo->numOfRes > 0 && pMeterQueryInfo->reverseIndex > 0 &&
pMeterQueryInfo->reverseIndex <= pMeterQueryInfo->numOfRes); // pMeterQueryInfo->reverseIndex <= pMeterQueryInfo->numOfRes);
// backward one step from the previous position, the start position is (pMeterQueryInfo->numOfRows-1); // // backward one step from the previous position, the start position is (pMeterQueryInfo->numOfRows-1);
pMeterQueryInfo->reverseIndex -= 1; // pMeterQueryInfo->reverseIndex -= 1;
setCtxOutputPointerForSupplementScan(pSupporter, pMeterQueryInfo); // setCtxOutputPointerForSupplementScan(pSupporter, pMeterQueryInfo);
} else { // } else {
SIDList list = getDataBufPagesIdList(pRuntimeEnv->pResultBuf, pMeterQueryInfo->sid); // SIDList list = getDataBufPagesIdList(pRuntimeEnv->pResultBuf, pMeterQueryInfo->sid);
//
int32_t pageId = getLastPageId(&list); // int32_t pageId = getLastPageId(&list);
tFilePage *pData = getResultBufferPageById(pRuntimeEnv->pResultBuf, pageId); // tFilePage *pData = getResultBufferPageById(pRuntimeEnv->pResultBuf, pageId);
//
// in handling records occuring around '1970-01-01', the aligned start timestamp may be 0. // // in handling records occuring around '1970-01-01', the aligned start timestamp may be 0.
TSKEY ts = *(TSKEY *)getOutputResPos(pRuntimeEnv, pData, pData->numOfElems, 0); // TSKEY ts = *(TSKEY *)getOutputResPos(pRuntimeEnv, pData, pData->numOfElems, 0);
//
SMeterObj *pMeterObj = pRuntimeEnv->pMeterObj; // SMeterObj *pMeterObj = pRuntimeEnv->pMeterObj;
qTrace("QInfo:%p vid:%d sid:%d id:%s, save results, ts:%" PRId64 ", total:%d", GET_QINFO_ADDR(pQuery), // qTrace("QInfo:%p vid:%d sid:%d id:%s, save results, ts:%" PRId64 ", total:%d", GET_QINFO_ADDR(pQuery),
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, ts, pMeterQueryInfo->numOfRes + 1); // pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, ts, pMeterQueryInfo->numOfRes + 1);
//
pData->numOfElems += numOfResult; // pData->numOfElems += numOfResult;
pMeterQueryInfo->numOfRes += numOfResult; // pMeterQueryInfo->numOfRes += numOfResult;
assert(pData->numOfElems <= pRuntimeEnv->numOfRowsPerPage); // assert(pData->numOfElems <= pRuntimeEnv->numOfRowsPerPage);
//
if (setOutputBufferForIntervalQuery(pRuntimeEnv, pMeterQueryInfo) != TSDB_CODE_SUCCESS) { // if (setOutputBufferForIntervalQuery(pRuntimeEnv, pMeterQueryInfo) != TSDB_CODE_SUCCESS) {
return -1; // return -1;
} // }
//
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { // for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
// resetResultInfo(&pMeterQueryInfo->resultInfo[i]); // // resetResultInfo(&pMeterQueryInfo->resultInfo[i]);
} // }
//
validateResultBuf(pSupporter, pMeterQueryInfo); // validateResultBuf(pSupporter, pMeterQueryInfo);
initCtxOutputBuf(pRuntimeEnv); // initCtxOutputBuf(pRuntimeEnv);
#if 0 //#if 0
SSchema sc[TSDB_MAX_COLUMNS] = {0}; // SSchema sc[TSDB_MAX_COLUMNS] = {0};
sc[0].type = TSDB_DATA_TYPE_BIGINT; // sc[0].type = TSDB_DATA_TYPE_BIGINT;
sc[0].bytes = 8; // sc[0].bytes = 8;
//
sc[1].type = TSDB_DATA_TYPE_BIGINT; // sc[1].type = TSDB_DATA_TYPE_BIGINT;
sc[1].bytes = 8; // sc[1].bytes = 8;
//
UNUSED(sc); // UNUSED(sc);
SColumnModel *cm = createColumnModel(sc, pQuery->numOfOutputCols, pRuntimeEnv->numOfRowsPerPage); // SColumnModel *cm = createColumnModel(sc, pQuery->numOfOutputCols, pRuntimeEnv->numOfRowsPerPage);
//
// if (outputPage->numOfElems + numOfResult >= pRuntimeEnv->numOfRowsPerPage) //// if (outputPage->numOfElems + numOfResult >= pRuntimeEnv->numOfRowsPerPage)
tColModelDisplay(cm, outputPage->data, outputPage->numOfElems, pRuntimeEnv->numOfRowsPerPage); // tColModelDisplay(cm, outputPage->data, outputPage->numOfElems, pRuntimeEnv->numOfRowsPerPage);
#endif //#endif
} // }
//
return TSDB_CODE_SUCCESS; // return TSDB_CODE_SUCCESS;
} //}
static int32_t getNumOfSubset(SMeterQuerySupportObj *pSupporter) { static int32_t getNumOfSubset(STableQuerySupportObj *pSupporter) {
SQuery *pQuery = pSupporter->runtimeEnv.pQuery; SQuery *pQuery = pSupporter->runtimeEnv.pQuery;
int32_t totalSubset = 0; int32_t totalSubset = 0;
...@@ -7633,7 +7805,7 @@ static int32_t getNumOfSubset(SMeterQuerySupportObj *pSupporter) { ...@@ -7633,7 +7805,7 @@ static int32_t getNumOfSubset(SMeterQuerySupportObj *pSupporter) {
return totalSubset; return totalSubset;
} }
static int32_t doCopyFromGroupBuf(SMeterQuerySupportObj *pSupporter, SWindowResult *result, int32_t orderType) { static int32_t doCopyFromGroupBuf(STableQuerySupportObj *pSupporter, SWindowResult *result, int32_t orderType) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -7701,7 +7873,7 @@ static int32_t doCopyFromGroupBuf(SMeterQuerySupportObj *pSupporter, SWindowResu ...@@ -7701,7 +7873,7 @@ static int32_t doCopyFromGroupBuf(SMeterQuerySupportObj *pSupporter, SWindowResu
*/ */
void copyFromGroupBuf(SQInfo *pQInfo, SWindowResult *result) { void copyFromGroupBuf(SQInfo *pQInfo, SWindowResult *result) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
int32_t orderType = (pQuery->pGroupbyExpr != NULL) ? pQuery->pGroupbyExpr->orderType : TSQL_SO_ASC; int32_t orderType = (pQuery->pGroupbyExpr != NULL) ? pQuery->pGroupbyExpr->orderType : TSQL_SO_ASC;
int32_t numOfResult = doCopyFromGroupBuf(pSupporter, result, orderType); int32_t numOfResult = doCopyFromGroupBuf(pSupporter, result, orderType);
...@@ -7710,22 +7882,25 @@ void copyFromGroupBuf(SQInfo *pQInfo, SWindowResult *result) { ...@@ -7710,22 +7882,25 @@ void copyFromGroupBuf(SQInfo *pQInfo, SWindowResult *result) {
assert(pQuery->pointsRead <= pQuery->pointsToRead); assert(pQuery->pointsRead <= pQuery->pointsToRead);
} }
static void applyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterDataInfo *pMeterDataInfo, void applyIntervalQueryOnBlock(STableQuerySupportObj *pSupporter, SMeterDataInfo *pMeterDataInfo,
SBlockInfo *pBlockInfo, int32_t blockStatus, SField *pFields, SBlockInfo *pBlockInfo, SField *pFields, __block_search_fn_t searchFn) {
__block_search_fn_t searchFn) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
SMeterQueryInfo * pMeterQueryInfo = pMeterDataInfo->pMeterQInfo; SMeterQueryInfo * pMeterQueryInfo = pMeterDataInfo->pMeterQInfo;
SWindowResInfo* pWindowResInfo = &pMeterQueryInfo->windowResInfo; SWindowResInfo * pWindowResInfo = &pMeterQueryInfo->windowResInfo;
int64_t *pPrimaryKey = (int64_t *)pRuntimeEnv->primaryColBuffer->data; int64_t *pPrimaryKey = (int64_t *)pRuntimeEnv->primaryColBuffer->data;
int32_t blockStatus = pRuntimeEnv->blockStatus;
/* /*
* for each block, we need to handle the previous query, since the determination of previous query being completed * for each block, we need to handle the previous query, since the determination of previous query being completed
* or not is based on the start key of current block. * or not is based on the start key of current block.
*/ */
TSKEY key = getNextAccessedKeyInData(pQuery, pPrimaryKey, pBlockInfo, blockStatus); TSKEY key = getNextAccessedKeyInData(pQuery, pPrimaryKey, pBlockInfo, blockStatus);
if (pQuery->intervalTime > 0) {
setIntervalQueryRange(pMeterQueryInfo, pSupporter, key); setIntervalQueryRange(pMeterQueryInfo, pSupporter, key);
}
int32_t forwardStep = int32_t forwardStep =
getNumOfRowsInTimeWindow(pQuery, pBlockInfo, pPrimaryKey, pQuery->pos, pQuery->ekey, searchFn, true); getNumOfRowsInTimeWindow(pQuery, pBlockInfo, pPrimaryKey, pQuery->pos, pQuery->ekey, searchFn, true);
...@@ -7738,8 +7913,16 @@ static void applyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterD ...@@ -7738,8 +7913,16 @@ static void applyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterD
numOfRes = blockwiseApplyAllFunctions(pRuntimeEnv, forwardStep, pFields, pBlockInfo, pWindowResInfo, searchFn); numOfRes = blockwiseApplyAllFunctions(pRuntimeEnv, forwardStep, pFields, pBlockInfo, pWindowResInfo, searchFn);
} }
// update the number of result for each
if (pQuery->intervalTime == 0) { // todo refactor
SWindowResInfo *p1 = &pRuntimeEnv->windowResInfo;
for (int32_t i = 0; i < p1->size; ++i) {
p1->pResult[i].numOfRows = p1->pResult->resultInfo->numOfRes;
}
}
int64_t e = taosGetTimestampUs() - st; int64_t e = taosGetTimestampUs() - st;
printf("-------------------------------%lld\n", e); printf("-------------------------------total result:%d\n", pRuntimeEnv->windowResInfo.size);
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
if ((pQuery->lastKey > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) || if ((pQuery->lastKey > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
...@@ -7747,30 +7930,7 @@ static void applyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterD ...@@ -7747,30 +7930,7 @@ static void applyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterD
pMeterQueryInfo->ekey = pQuery->lastKey - step; pMeterQueryInfo->ekey = pQuery->lastKey - step;
} }
// doCheckQueryCompleted(pRuntimeEnv, pQuery->lastKey, pWindowResInfo); updatelastkey(pQuery, pMeterQueryInfo);
//
// if (((pQuery->skey > pQuery->ekey) && QUERY_IS_ASC_QUERY(pQuery)) ||
// ((pQuery->skey < pQuery->ekey) && !QUERY_IS_ASC_QUERY(pQuery))) {
// return;
// }
// if (((pBlockInfo->keyLast < pQuery->ekey) && QUERY_IS_ASC_QUERY(pQuery)) ||
// ((pBlockInfo->keyFirst > pQuery->ekey) && !QUERY_IS_ASC_QUERY(pQuery))) {
// int32_t numOfRes = 0;
// /* current block is included in this interval */
// int32_t steps = applyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, pPrimaryKey, pFields, searchFn, &numOfRes,
// &pMeterQueryInfo->windowResInfo); assert(numOfRes <= 1 && numOfRes >= 0 && steps > 0);
//
// if (pMeterQueryInfo->lastResRows == 0) {
// pMeterQueryInfo->lastResRows = numOfRes;
// }
//
// assert(pMeterQueryInfo->lastResRows == 1 || pMeterQueryInfo->lastResRows == 0);
// saveIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
// } else {
// doApplyIntervalQueryOnBlock_rv(pSupporter, pMeterQueryInfo, pBlockInfo, pPrimaryKey, pFields, searchFn);
// }
} }
// we need to split the refstatsult into different packages. // we need to split the refstatsult into different packages.
...@@ -7784,7 +7944,7 @@ int32_t vnodeGetResultSize(void *thandle, int32_t *numOfRows) { ...@@ -7784,7 +7944,7 @@ int32_t vnodeGetResultSize(void *thandle, int32_t *numOfRows) {
* *
* TODO handle the case that the file is too large to send back one time * TODO handle the case that the file is too large to send back one time
*/ */
if (pQInfo->pMeterQuerySupporter != NULL && isTSCompQuery(pQuery) && (*numOfRows) > 0) { if (pQInfo->pTableQuerySupporter != NULL && isTSCompQuery(pQuery) && (*numOfRows) > 0) {
struct stat fstat; struct stat fstat;
if (stat(pQuery->sdata[0]->data, &fstat) == 0) { if (stat(pQuery->sdata[0]->data, &fstat) == 0) {
*numOfRows = fstat.st_size; *numOfRows = fstat.st_size;
...@@ -7805,7 +7965,7 @@ int64_t vnodeGetOffsetVal(void *thandle) { ...@@ -7805,7 +7965,7 @@ int64_t vnodeGetOffsetVal(void *thandle) {
bool vnodeHasRemainResults(void *handle) { bool vnodeHasRemainResults(void *handle) {
SQInfo * pQInfo = (SQInfo *)handle; SQInfo * pQInfo = (SQInfo *)handle;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
if (pSupporter == NULL || pQInfo->query.interpoType == TSDB_INTERPO_NONE) { if (pSupporter == NULL || pQInfo->query.interpoType == TSDB_INTERPO_NONE) {
return false; return false;
...@@ -7843,7 +8003,7 @@ bool vnodeHasRemainResults(void *handle) { ...@@ -7843,7 +8003,7 @@ bool vnodeHasRemainResults(void *handle) {
static int32_t resultInterpolate(SQInfo *pQInfo, tFilePage **data, tFilePage **pDataSrc, int32_t numOfRows, static int32_t resultInterpolate(SQInfo *pQInfo, tFilePage **data, tFilePage **pDataSrc, int32_t numOfRows,
int32_t outputRows) { int32_t outputRows) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
assert(pRuntimeEnv->pCtx[0].outputBytes == TSDB_KEYSIZE); assert(pRuntimeEnv->pCtx[0].outputBytes == TSDB_KEYSIZE);
...@@ -7933,7 +8093,7 @@ int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows) { ...@@ -7933,7 +8093,7 @@ int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows) {
int32_t vnodeQueryResultInterpolate(SQInfo *pQInfo, tFilePage **pDst, tFilePage **pDataSrc, int32_t numOfRows, int32_t vnodeQueryResultInterpolate(SQInfo *pQInfo, tFilePage **pDst, tFilePage **pDataSrc, int32_t numOfRows,
int32_t *numOfInterpo) { int32_t *numOfInterpo) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
...@@ -7974,7 +8134,7 @@ int32_t vnodeQueryResultInterpolate(SQInfo *pQInfo, tFilePage **pDst, tFilePage ...@@ -7974,7 +8134,7 @@ int32_t vnodeQueryResultInterpolate(SQInfo *pQInfo, tFilePage **pDst, tFilePage
} }
} }
void vnodePrintQueryStatistics(SMeterQuerySupportObj *pSupporter) { void vnodePrintQueryStatistics(STableQuerySupportObj *pSupporter) {
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
#include "vnodeQueryImpl.h" #include "vnodeQueryImpl.h"
#define ALL_CACHE_BLOCKS_CHECKED(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)))) (((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); #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) ...@@ -47,23 +48,10 @@ static bool isGroupbyEachTable(SSqlGroupbyExpr *pGroupbyExpr, tSidSet *pSidset)
return false; return false;
} }
static bool doCheckWithPrevQueryRange(SQInfo *pQInfo, TSKEY nextKey, SMeterDataInfo *pMeterInfo) { static bool doCheckWithPrevQueryRange(SQuery *pQuery, TSKEY nextKey) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
SQuery * pQuery = &pQInfo->query;
SMeterObj * pMeterObj = pMeterInfo->pMeterObj;
/* no data for current query */
if ((nextKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) || if ((nextKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
(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; return false;
} else { // in case of interval query, forward the query range
setIntervalQueryRange(pMeterInfo->pMeterQInfo, pSupporter, nextKey);
}
} }
return true; return true;
...@@ -86,7 +74,7 @@ static void setStartPositionForCacheBlock(SQuery *pQuery, SCacheBlock *pBlock, b ...@@ -86,7 +74,7 @@ static void setStartPositionForCacheBlock(SQuery *pQuery, SCacheBlock *pBlock, b
} }
static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) { static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
SQuery* pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
SResultInfo *pResInfo = GET_RES_INFO(&pRuntimeEnv->pCtx[i]); SResultInfo *pResInfo = GET_RES_INFO(&pRuntimeEnv->pCtx[i]);
...@@ -98,8 +86,8 @@ static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -98,8 +86,8 @@ static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) { static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv * pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo; SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
...@@ -132,7 +120,8 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) { ...@@ -132,7 +120,8 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
pRuntimeEnv->pMeterObj = pMeterObj; pRuntimeEnv->pMeterObj = pMeterObj;
if (pMeterInfo[k].pMeterQInfo == NULL) { 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 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) { ...@@ -154,29 +143,18 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
vnodeUpdateQueryColumnIndex(pQuery, pMeterObj); vnodeUpdateQueryColumnIndex(pQuery, pMeterObj);
vnodeUpdateFilterColumnIndex(pQuery); vnodeUpdateFilterColumnIndex(pQuery);
if (pQuery->intervalTime == 0) {
if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) || if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
(pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) { (pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
dTrace( dTrace("QInfo:%p vid:%d sid:%d id:%s, query completed, ignore data in cache. qrange:%" PRId64 "-%" PRId64
"QInfo:%p vid:%d sid:%d id:%s, query completed, ignore data in cache. qrange:%" PRId64 "-%" PRId64 ", " ", lastKey:%" PRId64,
"lastKey:%" PRId64,
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey,
pQuery->lastKey); pQuery->lastKey);
continue; continue;
} }
setExecutionContext(pSupporter, pRuntimeEnv->windowResInfo.pResult, k, pMeterInfo[k].groupIdx, pMeterQueryInfo); qTrace("QInfo:%p vid:%d sid:%d id:%s, query in cache, qrange:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64, pQInfo,
} else { pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery->lastKey);
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);
/* /*
* find the appropriated start position in cache * find the appropriated start position in cache
...@@ -186,7 +164,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) { ...@@ -186,7 +164,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
* should be ignored (the fourth parameter). * should be ignored (the fourth parameter).
*/ */
TSKEY nextKey = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, true); 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, 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); pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->numOfBlocks, pQuery->lastKey);
continue; continue;
...@@ -199,10 +177,6 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) { ...@@ -199,10 +177,6 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
continue; continue;
} }
if (!doCheckWithPrevQueryRange(pQInfo, nextKey, &pMeterInfo[k])) {
continue;
}
bool firstCheckSlot = true; bool firstCheckSlot = true;
SCacheInfo *pCacheInfo = (SCacheInfo *)pMeterObj->pCache; SCacheInfo *pCacheInfo = (SCacheInfo *)pMeterObj->pCache;
...@@ -224,14 +198,29 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) { ...@@ -224,14 +198,29 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
setStartPositionForCacheBlock(pQuery, pBlock, &firstCheckSlot); 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 // 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)) || if ((key > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
(primaryKeys[pQuery->pos] < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) { (key < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery))) {
break; 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 // only record the key on last block
SET_CACHE_BLOCK_FLAG(pRuntimeEnv->blockStatus); SET_CACHE_BLOCK_FLAG(pRuntimeEnv->blockStatus);
SBlockInfo binfo = getBlockBasicInfo(pRuntimeEnv, pBlock, BLK_CACHE_BLOCK); SBlockInfo binfo = getBlockBasicInfo(pRuntimeEnv, pBlock, BLK_CACHE_BLOCK);
...@@ -241,7 +230,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) { ...@@ -241,7 +230,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
pRuntimeEnv->blockStatus); pRuntimeEnv->blockStatus);
totalBlocks++; totalBlocks++;
queryOnBlock(pSupporter, pRuntimeEnv->blockStatus, &binfo, &pMeterInfo[k], NULL, searchFn); applyIntervalQueryOnBlock(pSupporter, &pMeterInfo[k], &binfo, NULL, searchFn);
if (ALL_CACHE_BLOCKS_CHECKED(pQuery)) { if (ALL_CACHE_BLOCKS_CHECKED(pQuery)) {
break; break;
...@@ -266,7 +255,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) { ...@@ -266,7 +255,7 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo) { static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
SMeterDataBlockInfoEx *pDataBlockInfoEx = NULL; SMeterDataBlockInfoEx *pDataBlockInfoEx = NULL;
int32_t nAllocBlocksInfoSize = 0; int32_t nAllocBlocksInfoSize = 0;
...@@ -275,7 +264,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo ...@@ -275,7 +264,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
__block_search_fn_t searchFn = vnodeSearchKeyFunc[pTempMeter->searchAlgorithm]; __block_search_fn_t searchFn = vnodeSearchKeyFunc[pTempMeter->searchAlgorithm];
int32_t vnodeId = pTempMeter->vnode; int32_t vnodeId = pTempMeter->vnode;
SQueryFilesInfo* pVnodeFileInfo = &pRuntimeEnv->vnodeFileInfo; SQueryFilesInfo *pVnodeFileInfo = &pRuntimeEnv->vnodeFileInfo;
dTrace("QInfo:%p start to check data blocks in %d files", pQInfo, pVnodeFileInfo->numOfFiles); dTrace("QInfo:%p start to check data blocks in %d files", pQInfo, pVnodeFileInfo->numOfFiles);
...@@ -383,8 +372,8 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo ...@@ -383,8 +372,8 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
stimeUnit = taosGetTimestampMs(); stimeUnit = taosGetTimestampMs();
} else if ((j % TRACE_OUTPUT_BLOCK_CNT) == 0) { } else if ((j % TRACE_OUTPUT_BLOCK_CNT) == 0) {
etimeUnit = taosGetTimestampMs(); etimeUnit = taosGetTimestampMs();
dTrace("QInfo:%p load and check %" PRId64 " blocks, and continue. elapsed:%" PRId64 " ms", pQInfo, TRACE_OUTPUT_BLOCK_CNT, dTrace("QInfo:%p load and check %" PRId64 " blocks, and continue. elapsed:%" PRId64 " ms", pQInfo,
etimeUnit - stimeUnit); TRACE_OUTPUT_BLOCK_CNT, etimeUnit - stimeUnit);
stimeUnit = taosGetTimestampMs(); stimeUnit = taosGetTimestampMs();
} }
...@@ -398,29 +387,16 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo ...@@ -398,29 +387,16 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
restoreIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo); restoreIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
if (pQuery->intervalTime == 0) { // normal query
if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) || if ((pQuery->lastKey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
(pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) { (pQuery->lastKey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
qTrace( qTrace("QInfo:%p vid:%d sid:%d id:%s, query completed, no need to scan this data block. qrange:%" PRId64
"QInfo:%p vid:%d sid:%d id:%s, query completed, no need to scan this data block. qrange:%" PRId64 "-%" PRId64 ", " "-%" PRId64 ", lastKey:%" PRId64,
"lastKey:%" PRId64,
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey,
pQuery->lastKey); pQuery->lastKey);
continue; 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;
}
}
SCompBlock *pBlock = pInfoEx->pBlock.compBlock; SCompBlock *pBlock = pInfoEx->pBlock.compBlock;
bool ondemandLoad = onDemandLoadDatablock(pQuery, pMeterQueryInfo->queryRangeSet); bool ondemandLoad = onDemandLoadDatablock(pQuery, pMeterQueryInfo->queryRangeSet);
int32_t ret = LoadDatablockOnDemand(pBlock, &pInfoEx->pBlock.fields, &pRuntimeEnv->blockStatus, pRuntimeEnv, int32_t ret = LoadDatablockOnDemand(pBlock, &pInfoEx->pBlock.fields, &pRuntimeEnv->blockStatus, pRuntimeEnv,
...@@ -438,7 +414,10 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo ...@@ -438,7 +414,10 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
if (IS_DATA_BLOCK_LOADED(pRuntimeEnv->blockStatus) && needPrimaryTimestampCol(pQuery, &binfo)) { if (IS_DATA_BLOCK_LOADED(pRuntimeEnv->blockStatus) && needPrimaryTimestampCol(pQuery, &binfo)) {
nextKey = primaryKeys[pQuery->pos]; 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; continue;
} }
} else { } else {
...@@ -447,7 +426,10 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo ...@@ -447,7 +426,10 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
(pBlock->keyFirst >= pQuery->ekey && pBlock->keyLast <= pQuery->lastKey && !QUERY_IS_ASC_QUERY(pQuery))); (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); setIntervalQueryRange(pMeterQueryInfo, pSupporter, nextKey);
ret = setIntervalQueryExecutionContext(pSupporter, pOneMeterDataInfo->meterOrderIdx, pMeterQueryInfo); ret = setIntervalQueryExecutionContext(pSupporter, pOneMeterDataInfo->meterOrderIdx, pMeterQueryInfo);
...@@ -458,7 +440,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo ...@@ -458,7 +440,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
} }
} }
queryOnBlock(pSupporter, pRuntimeEnv->blockStatus, &binfo, pOneMeterDataInfo, pInfoEx->pBlock.fields, searchFn); applyIntervalQueryOnBlock(pSupporter, pOneMeterDataInfo, &binfo, pInfoEx->pBlock.fields, searchFn);
} }
tfree(pReqMeterDataInfo); tfree(pReqMeterDataInfo);
...@@ -481,7 +463,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo ...@@ -481,7 +463,7 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *dataInCache, int32_t index, static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *dataInCache, int32_t index,
int32_t start) { int32_t start) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo; SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
...@@ -497,8 +479,8 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool * ...@@ -497,8 +479,8 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *
vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pMeterSidExtInfo[index]); 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, dTrace("QInfo:%p query on (%d): vid:%d sid:%d meterId:%s, qrange:%" PRId64 "-%" PRId64, pQInfo, index - start,
pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey); pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey);
pQInfo->pObj = pMeterObj; pQInfo->pObj = pMeterObj;
pQuery->lastKey = pQuery->skey; pQuery->lastKey = pQuery->skey;
...@@ -511,8 +493,8 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool * ...@@ -511,8 +493,8 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *
// data in file or cache is not qualified for the query. abort // data in file or cache is not qualified for the query. abort
if (!(dataInCache || dataInDisk)) { if (!(dataInCache || dataInDisk)) {
dTrace("QInfo:%p vid:%d sid:%d meterId:%s, qrange:%" PRId64 "-%" PRId64 ", nores, %p", pQInfo, pMeterObj->vnode, pMeterObj->sid, dTrace("QInfo:%p vid:%d sid:%d meterId:%s, qrange:%" PRId64 "-%" PRId64 ", nores, %p", pQInfo, pMeterObj->vnode,
pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery); pMeterObj->sid, pMeterObj->meterId, pQuery->skey, pQuery->ekey, pQuery);
return false; return false;
} }
...@@ -536,7 +518,7 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool * ...@@ -536,7 +518,7 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *
static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start) { static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
bool dataInDisk = true; bool dataInDisk = true;
...@@ -591,7 +573,7 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start ...@@ -591,7 +573,7 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start
* @param pQInfo * @param pQInfo
*/ */
static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo; SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
...@@ -611,8 +593,8 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -611,8 +593,8 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
int32_t end = pSids->starterPos[pSupporter->subgroupIdx + 1] - 1; int32_t end = pSids->starterPos[pSupporter->subgroupIdx + 1] - 1;
if (isFirstLastRowQuery(pQuery)) { if (isFirstLastRowQuery(pQuery)) {
dTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, dTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pSids->numOfSubSet,
pSids->numOfSubSet, pSupporter->subgroupIdx); pSupporter->subgroupIdx);
TSKEY key = -1; TSKEY key = -1;
int32_t index = -1; int32_t index = -1;
...@@ -644,8 +626,8 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -644,8 +626,8 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
int64_t num = doCheckMetersInGroup(pQInfo, index, start); int64_t num = doCheckMetersInGroup(pQInfo, index, start);
assert(num >= 0); assert(num >= 0);
} else { } else {
dTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, dTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pSids->numOfSubSet,
pSids->numOfSubSet, pSupporter->subgroupIdx); pSupporter->subgroupIdx);
for (int32_t k = start; k <= end; ++k) { for (int32_t k = start; k <= end; ++k) {
if (isQueryKilled(pQuery)) { if (isQueryKilled(pQuery)) {
...@@ -704,8 +686,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -704,8 +686,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
return; return;
} }
TSKEY skey = pQInfo->pTableQuerySupporter->pMeterSidExtInfo[k]->key;
TSKEY skey = pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[k]->key;
if (skey > 0) { if (skey > 0) {
pQuery->skey = skey; pQuery->skey = skey;
} }
...@@ -773,7 +754,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -773,7 +754,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
pQuery->ekey = pSupporter->rawEKey; pQuery->ekey = pSupporter->rawEKey;
pSupporter->meterIdx++; 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 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) || if (Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL) ||
...@@ -789,7 +770,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -789,7 +770,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
assert(!Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL)); assert(!Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL));
continue; continue;
} else { } 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 // buffer is full, wait for the next round to retrieve data from current meter
assert(Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL)); assert(Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL));
break; break;
...@@ -819,10 +800,10 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -819,10 +800,10 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
// todo refactor // todo refactor
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) { if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
SWindowResInfo* pWindowResInfo = &pRuntimeEnv->windowResInfo; SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo;
for (int32_t i = 0; i < pWindowResInfo->size; ++i) { for (int32_t i = 0; i < pWindowResInfo->size; ++i) {
SWindowStatus* pStatus = &pWindowResInfo->pResult[i].status; SWindowStatus *pStatus = &pWindowResInfo->pResult[i].status;
pStatus->closed = true; // enable return all results for group by normal columns pStatus->closed = true; // enable return all results for group by normal columns
SWindowResult *pResult = &pWindowResInfo->pResult[i]; SWindowResult *pResult = &pWindowResInfo->pResult[i];
...@@ -831,7 +812,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -831,7 +812,7 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
} }
} }
pQInfo->pMeterQuerySupporter->subgroupIdx = 0; pQInfo->pTableQuerySupporter->subgroupIdx = 0;
pQuery->pointsRead = 0; pQuery->pointsRead = 0;
copyFromGroupBuf(pQInfo, pWindowResInfo->pResult); copyFromGroupBuf(pQInfo, pWindowResInfo->pResult);
} }
...@@ -842,12 +823,12 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) { ...@@ -842,12 +823,12 @@ static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
dTrace( dTrace(
"QInfo %p vid:%d, numOfMeters:%d, index:%d, numOfGroups:%d, %d points returned, totalRead:%d totalReturn:%d," "QInfo %p vid:%d, numOfMeters:%d, index:%d, numOfGroups:%d, %d points returned, totalRead:%d totalReturn:%d,"
"next skey:%" PRId64 ", offset:%" PRId64, "next skey:%" PRId64 ", offset:%" PRId64,
pQInfo, vid, pSids->numOfSids, pSupporter->meterIdx, pSids->numOfSubSet, pQuery->pointsRead, pQInfo, vid, pSids->numOfSids, pSupporter->meterIdx, pSids->numOfSubSet, pQuery->pointsRead, pQInfo->pointsRead,
pQInfo->pointsRead, pQInfo->pointsReturned, pQuery->skey, pQuery->limit.offset); pQInfo->pointsReturned, pQuery->skey, pQuery->limit.offset);
} }
static void doOrderedScan(SQInfo *pQInfo) { static void doOrderedScan(SQInfo *pQInfo) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
if (QUERY_IS_ASC_QUERY(pQuery)) { if (QUERY_IS_ASC_QUERY(pQuery)) {
...@@ -867,17 +848,16 @@ static void doOrderedScan(SQInfo *pQInfo) { ...@@ -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) { for (int32_t i = 0; i < pSupporter->numOfMeters; ++i) {
SMeterQueryInfo *pMeterQueryInfo = pSupporter->pMeterDataInfo[i].pMeterQInfo; SMeterQueryInfo * pMeterQueryInfo = pSupporter->pMeterDataInfo[i].pMeterQInfo;
SQueryDiskbasedResultBuf* pResultBuf = pSupporter->runtimeEnv.pResultBuf; SQueryDiskbasedResultBuf *pResultBuf = pSupporter->runtimeEnv.pResultBuf;
changeMeterQueryInfoForSuppleQuery(pResultBuf, pMeterQueryInfo, pSupporter->rawSKey, pSupporter->rawEKey); changeMeterQueryInfoForSuppleQuery(pResultBuf, pMeterQueryInfo, pSupporter->rawSKey, pSupporter->rawEKey);
} }
} }
static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) { static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
...@@ -898,7 +878,9 @@ static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) { ...@@ -898,7 +878,9 @@ static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) {
setupMeterQueryInfoForSupplementQuery(pSupporter); setupMeterQueryInfoForSupplementQuery(pSupporter);
int64_t st = taosGetTimestampMs(); int64_t st = taosGetTimestampMs();
doOrderedScan(pQInfo); doOrderedScan(pQInfo);
int64_t et = taosGetTimestampMs(); int64_t et = taosGetTimestampMs();
dTrace("QInfo:%p supplementary scan completed, elapsed time: %lldms", pQInfo, et - st); dTrace("QInfo:%p supplementary scan completed, elapsed time: %lldms", pQInfo, et - st);
...@@ -917,8 +899,8 @@ static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) { ...@@ -917,8 +899,8 @@ static void doMultiMeterSupplementaryScan(SQInfo *pQInfo) {
} }
static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) { static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv* pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
if (pSupporter->subgroupIdx > 0) { if (pSupporter->subgroupIdx > 0) {
...@@ -954,8 +936,8 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) { ...@@ -954,8 +936,8 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
return; return;
} }
dTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", order:%d, group:%d", pQInfo, pSupporter->rawSKey, pSupporter->rawEKey, dTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", order:%d, group:%d", pQInfo, pSupporter->rawSKey,
pQuery->order.order, pSupporter->pSidSet->numOfSubSet); pSupporter->rawEKey, pQuery->order.order, pSupporter->pSidSet->numOfSubSet);
dTrace("QInfo:%p main query scan start", pQInfo); dTrace("QInfo:%p main query scan start", pQInfo);
int64_t st = taosGetTimestampMs(); int64_t st = taosGetTimestampMs();
...@@ -965,9 +947,18 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) { ...@@ -965,9 +947,18 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
pQuery->order.order ^ 1); pQuery->order.order ^ 1);
// failed to save all intermediate results into disk, abort further query processing // failed to save all intermediate results into disk, abort further query processing
if (doCloseAllOpenedResults(pSupporter) != TSDB_CODE_SUCCESS) { // if (doCloseAllOpenedResults(pSupporter) != TSDB_CODE_SUCCESS) {
dError("QInfo:%p failed to save intermediate results, abort further query processing", pQInfo); // dError("QInfo:%p failed to save intermediate results, abort further query processing", pQInfo);
return; // 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); doMultiMeterSupplementaryScan(pQInfo);
...@@ -1005,7 +996,7 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) { ...@@ -1005,7 +996,7 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
*/ */
static void vnodeSingleTableFixedOutputProcessor(SQInfo *pQInfo) { static void vnodeSingleTableFixedOutputProcessor(SQInfo *pQInfo) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
assert(pQuery->slot >= 0 && pQuery->pos >= 0); assert(pQuery->slot >= 0 && pQuery->pos >= 0);
...@@ -1036,7 +1027,7 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -1036,7 +1027,7 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterObj *pMeterObj = pQInfo->pObj; SMeterObj *pMeterObj = pQInfo->pObj;
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
// for ts_comp query, re-initialized is not allowed // for ts_comp query, re-initialized is not allowed
if (!isTSCompQuery(pQuery)) { if (!isTSCompQuery(pQuery)) {
...@@ -1067,8 +1058,9 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -1067,8 +1058,9 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos); TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
assert(nextTimestamp > 0 || ((nextTimestamp < 0) && Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK))); 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, dTrace("QInfo:%p vid:%d sid:%d id:%s, skip current result, offset:%" PRId64 ", next qrange:%" PRId64 "-%" PRId64,
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->limit.offset, pQuery->lastKey, pQuery->ekey); pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->limit.offset, pQuery->lastKey,
pQuery->ekey);
resetCtxOutputBuf(pRuntimeEnv); resetCtxOutputBuf(pRuntimeEnv);
} }
...@@ -1080,8 +1072,8 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -1080,8 +1072,8 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos); TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
assert(nextTimestamp > 0 || ((nextTimestamp < 0) && Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK))); 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, dTrace("QInfo:%p vid:%d sid:%d id:%s, query abort due to buffer limitation, next qrange:%" PRId64 "-%" PRId64,
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->lastKey, pQuery->ekey); 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, dTrace("QInfo:%p vid:%d sid:%d id:%s, %d points returned, totalRead:%d totalReturn:%d", pQInfo, pMeterObj->vnode,
...@@ -1093,7 +1085,7 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -1093,7 +1085,7 @@ static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
} }
} }
static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv) { static void vnodeSingleMeterIntervalMainLooper(STableQuerySupportObj *pSupporter, SQueryRuntimeEnv *pRuntimeEnv) {
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
while (1) { while (1) {
...@@ -1113,18 +1105,19 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter ...@@ -1113,18 +1105,19 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
// here we can ignore the records in case of no interpolation // here we can ignore the records in case of no interpolation
if ((pQuery->numOfFilterCols > 0 || pRuntimeEnv->pTSBuf != NULL) && pQuery->limit.offset > 0 && 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 // todo handle offset, in case of top/bottom interval query
if (maxOutput > 0) { if (maxOutput > 0) {
pQuery->limit.offset--; pQuery->limit.offset--;
} }
} else { } else {
// assert(0); // assert(0);
// pQuery->pointsRead += maxOutput; // pQuery->pointsRead += maxOutput;
// forwardCtxOutputBuf(pRuntimeEnv, 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; break;
} }
...@@ -1151,7 +1144,7 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) { ...@@ -1151,7 +1144,7 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
SQuery * pQuery = &(pQInfo->query); SQuery * pQuery = &(pQInfo->query);
SMeterObj *pMeterObj = pQInfo->pObj; SMeterObj *pMeterObj = pQInfo->pObj;
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
int32_t numOfInterpo = 0; int32_t numOfInterpo = 0;
...@@ -1211,7 +1204,7 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) { ...@@ -1211,7 +1204,7 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
void vnodeSingleTableQuery(SSchedMsg *pMsg) { void vnodeSingleTableQuery(SSchedMsg *pMsg) {
SQInfo *pQInfo = (SQInfo *)pMsg->ahandle; SQInfo *pQInfo = (SQInfo *)pMsg->ahandle;
if (pQInfo == NULL || pQInfo->pMeterQuerySupporter == NULL) { if (pQInfo == NULL || pQInfo->pTableQuerySupporter == NULL) {
dTrace("%p freed abort query", pQInfo); dTrace("%p freed abort query", pQInfo);
return; return;
} }
...@@ -1231,7 +1224,7 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) { ...@@ -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, dTrace("vid:%d sid:%d id:%s, query thread is created, numOfQueries:%d, QInfo:%p", pMeterObj->vnode, pMeterObj->sid,
pMeterObj->meterId, pMeterObj->numOfQueries, pQInfo); pMeterObj->meterId, pMeterObj->numOfQueries, pQInfo);
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
assert(pRuntimeEnv->pMeterObj == pMeterObj); assert(pRuntimeEnv->pMeterObj == pMeterObj);
if (vnodeHasRemainResults(pQInfo)) { if (vnodeHasRemainResults(pQInfo)) {
...@@ -1267,8 +1260,8 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) { ...@@ -1267,8 +1260,8 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
// continue to get push data from the group result // continue to get push data from the group result
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) { if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
pQuery->pointsRead = 0; pQuery->pointsRead = 0;
if (pQInfo->pMeterQuerySupporter->subgroupIdx > 0) { if (pQInfo->pTableQuerySupporter->subgroupIdx > 0) {
copyFromGroupBuf(pQInfo, pQInfo->pMeterQuerySupporter->runtimeEnv.windowResInfo.pResult); copyFromGroupBuf(pQInfo, pQInfo->pTableQuerySupporter->runtimeEnv.windowResInfo.pResult);
pQInfo->pointsRead += pQuery->pointsRead; pQInfo->pointsRead += pQuery->pointsRead;
if (pQuery->pointsRead > 0) { if (pQuery->pointsRead > 0) {
...@@ -1285,10 +1278,10 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) { ...@@ -1285,10 +1278,10 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
} }
pQInfo->over = 1; pQInfo->over = 1;
dTrace("QInfo:%p vid:%d sid:%d id:%s, query over, %d points are returned", pQInfo, dTrace("QInfo:%p vid:%d sid:%d id:%s, query over, %d points are returned", pQInfo, pMeterObj->vnode, pMeterObj->sid,
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQInfo->pointsRead); pMeterObj->meterId, pQInfo->pointsRead);
vnodePrintQueryStatistics(pQInfo->pMeterQuerySupporter); vnodePrintQueryStatistics(pQInfo->pTableQuerySupporter);
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
vnodeDecRefCount(pQInfo); vnodeDecRefCount(pQInfo);
...@@ -1323,8 +1316,8 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) { ...@@ -1323,8 +1316,8 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
dTrace("QInfo:%p query is killed", pQInfo); dTrace("QInfo:%p query is killed", pQInfo);
pQInfo->over = 1; pQInfo->over = 1;
} else { } else {
dTrace("QInfo:%p vid:%d sid:%d id:%s, meter query thread completed, %d points are returned", dTrace("QInfo:%p vid:%d sid:%d id:%s, meter query thread completed, %d points are returned", pQInfo,
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead); pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead);
} }
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
...@@ -1334,7 +1327,7 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) { ...@@ -1334,7 +1327,7 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
void vnodeMultiMeterQuery(SSchedMsg *pMsg) { void vnodeMultiMeterQuery(SSchedMsg *pMsg) {
SQInfo *pQInfo = (SQInfo *)pMsg->ahandle; SQInfo *pQInfo = (SQInfo *)pMsg->ahandle;
if (pQInfo == NULL || pQInfo->pMeterQuerySupporter == NULL) { if (pQInfo == NULL || pQInfo->pTableQuerySupporter == NULL) {
return; return;
} }
...@@ -1365,10 +1358,10 @@ void vnodeMultiMeterQuery(SSchedMsg *pMsg) { ...@@ -1365,10 +1358,10 @@ void vnodeMultiMeterQuery(SSchedMsg *pMsg) {
pQInfo->useconds += (taosGetTimestampUs() - st); pQInfo->useconds += (taosGetTimestampUs() - st);
pQInfo->over = isQueryKilled(pQuery) ? 1 : 0; pQInfo->over = isQueryKilled(pQuery) ? 1 : 0;
taosInterpoSetStartInfo(&pQInfo->pMeterQuerySupporter->runtimeEnv.interpoInfo, pQuery->pointsRead, taosInterpoSetStartInfo(&pQInfo->pTableQuerySupporter->runtimeEnv.interpoInfo, pQuery->pointsRead,
pQInfo->query.interpoType); pQInfo->query.interpoType);
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
if (pQuery->pointsRead == 0) { if (pQuery->pointsRead == 0) {
pQInfo->over = 1; pQInfo->over = 1;
......
...@@ -648,7 +648,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE ...@@ -648,7 +648,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
goto _error; goto _error;
} }
SMeterQuerySupportObj *pSupporter = (SMeterQuerySupportObj *)calloc(1, sizeof(SMeterQuerySupportObj)); STableQuerySupportObj *pSupporter = (STableQuerySupportObj *)calloc(1, sizeof(STableQuerySupportObj));
pSupporter->numOfMeters = 1; pSupporter->numOfMeters = 1;
pSupporter->pMetersHashTable = taosInitHashTable(pSupporter->numOfMeters, taosIntHash_32, false); pSupporter->pMetersHashTable = taosInitHashTable(pSupporter->numOfMeters, taosIntHash_32, false);
...@@ -659,7 +659,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE ...@@ -659,7 +659,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
pSupporter->subgroupIdx = -1; pSupporter->subgroupIdx = -1;
pSupporter->pMeterSidExtInfo = NULL; pSupporter->pMeterSidExtInfo = NULL;
pQInfo->pMeterQuerySupporter = pSupporter; pQInfo->pTableQuerySupporter = pSupporter;
STSBuf *pTSBuf = NULL; STSBuf *pTSBuf = NULL;
if (pQueryMsg->tsLen > 0) { if (pQueryMsg->tsLen > 0) {
...@@ -670,7 +670,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE ...@@ -670,7 +670,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
tsBufNextPos(pTSBuf); 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; goto _error;
} }
...@@ -739,7 +739,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE ...@@ -739,7 +739,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
SSchedMsg schedMsg = {0}; SSchedMsg schedMsg = {0};
SMeterQuerySupportObj *pSupporter = (SMeterQuerySupportObj *)calloc(1, sizeof(SMeterQuerySupportObj)); STableQuerySupportObj *pSupporter = (STableQuerySupportObj *)calloc(1, sizeof(STableQuerySupportObj));
pSupporter->numOfMeters = pQueryMsg->numOfSids; pSupporter->numOfMeters = pQueryMsg->numOfSids;
pSupporter->pMetersHashTable = taosInitHashTable(pSupporter->numOfMeters, taosIntHash_32, false); pSupporter->pMetersHashTable = taosInitHashTable(pSupporter->numOfMeters, taosIntHash_32, false);
...@@ -784,7 +784,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE ...@@ -784,7 +784,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
(SSchema *)pQueryMsg->pTagSchema, pQueryMsg->numOfTagsCols, NULL, 0); (SSchema *)pQueryMsg->pTagSchema, pQueryMsg->numOfTagsCols, NULL, 0);
} }
pQInfo->pMeterQuerySupporter = pSupporter; pQInfo->pTableQuerySupporter = pSupporter;
STSBuf *pTSBuf = NULL; STSBuf *pTSBuf = NULL;
if (pQueryMsg->tsLen > 0) { if (pQueryMsg->tsLen > 0) {
...@@ -794,7 +794,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE ...@@ -794,7 +794,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
tsBufResetPos(pTSBuf); tsBufResetPos(pTSBuf);
} }
if (((*code) = vnodeMultiMeterQueryPrepare(pQInfo, pQuery, pTSBuf)) != TSDB_CODE_SUCCESS) { if (((*code) = vnodeSTableQueryPrepare(pQInfo, pQuery, pTSBuf)) != TSDB_CODE_SUCCESS) {
goto _error; goto _error;
} }
...@@ -898,8 +898,8 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) { ...@@ -898,8 +898,8 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
SSchedMsg schedMsg = {0}; SSchedMsg schedMsg = {0};
if (pQInfo->pMeterQuerySupporter != NULL) { if (pQInfo->pTableQuerySupporter != NULL) {
if (pQInfo->pMeterQuerySupporter->pSidSet == NULL) { if (pQInfo->pTableQuerySupporter->pSidSet == NULL) {
schedMsg.fp = vnodeSingleTableQuery; schedMsg.fp = vnodeSingleTableQuery;
} else { // group by tag } else { // group by tag
schedMsg.fp = vnodeMultiMeterQuery; schedMsg.fp = vnodeMultiMeterQuery;
......
...@@ -446,8 +446,8 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) { ...@@ -446,8 +446,8 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
// buffer size for progress information, including meter count, // buffer size for progress information, including meter count,
// and for each meter, including 'uid' and 'TSKEY'. // and for each meter, including 'uid' and 'TSKEY'.
int progressSize = 0; int progressSize = 0;
if (pQInfo->pMeterQuerySupporter != NULL) if (pQInfo->pTableQuerySupporter != NULL)
progressSize = pQInfo->pMeterQuerySupporter->numOfMeters * (sizeof(int64_t) + sizeof(TSKEY)) + sizeof(int32_t); progressSize = pQInfo->pTableQuerySupporter->numOfMeters * (sizeof(int64_t) + sizeof(TSKEY)) + sizeof(int32_t);
else if (pQInfo->pObj != NULL) else if (pQInfo->pObj != NULL)
progressSize = sizeof(int64_t) + sizeof(TSKEY) + sizeof(int32_t); progressSize = sizeof(int64_t) + sizeof(TSKEY) + sizeof(int32_t);
...@@ -486,13 +486,13 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) { ...@@ -486,13 +486,13 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
// write the progress information of each meter to response // write the progress information of each meter to response
// this is required by subscriptions // this is required by subscriptions
if (numOfRows > 0 && code == TSDB_CODE_SUCCESS) { if (numOfRows > 0 && code == TSDB_CODE_SUCCESS) {
if (pQInfo->pMeterQuerySupporter != NULL && pQInfo->pMeterQuerySupporter->pMeterSidExtInfo != NULL) { if (pQInfo->pTableQuerySupporter != NULL && pQInfo->pTableQuerySupporter->pMeterSidExtInfo != NULL) {
*((int32_t *)pMsg) = htonl(pQInfo->pMeterQuerySupporter->numOfMeters); *((int32_t *)pMsg) = htonl(pQInfo->pTableQuerySupporter->numOfMeters);
pMsg += sizeof(int32_t); pMsg += sizeof(int32_t);
for (int32_t i = 0; i < pQInfo->pMeterQuerySupporter->numOfMeters; i++) { for (int32_t i = 0; i < pQInfo->pTableQuerySupporter->numOfMeters; i++) {
*((int64_t *)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->uid); *((int64_t *)pMsg) = htobe64(pQInfo->pTableQuerySupporter->pMeterSidExtInfo[i]->uid);
pMsg += sizeof(int64_t); pMsg += sizeof(int64_t);
*((TSKEY *)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->key); *((TSKEY *)pMsg) = htobe64(pQInfo->pTableQuerySupporter->pMeterSidExtInfo[i]->key);
pMsg += sizeof(TSKEY); pMsg += sizeof(TSKEY);
} }
} else if (pQInfo->pObj != NULL) { } else if (pQInfo->pObj != NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册