fix bugs found in regression test.
This commit is contained in:
parent
8928dea534
commit
e9dc2db741
|
@ -2818,10 +2818,13 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
pElem->tableCond = htonl(offset);
|
pElem->tableCond = htonl(offset);
|
||||||
|
|
||||||
uint32_t len = strlen(pTagCond->tbnameCond.cond);
|
uint32_t len = 0;
|
||||||
pElem->tableCondLen = htonl(len);
|
if (pTagCond->tbnameCond.cond != NULL) {
|
||||||
|
len = strlen(pTagCond->tbnameCond.cond);
|
||||||
memcpy(pMsg, pTagCond->tbnameCond.cond, len);
|
memcpy(pMsg, pTagCond->tbnameCond.cond, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
pElem->tableCondLen = htonl(len);
|
||||||
pMsg += len;
|
pMsg += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,6 @@ void doSkipResults(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv);
|
void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
int64_t getNumOfResult(SQueryRuntimeEnv* pRuntimeEnv);
|
int64_t getNumOfResult(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
|
|
||||||
void forwardIntervalQueryRange(STableQuerySupportObj* pSupporter, SQueryRuntimeEnv* pRuntimeEnv);
|
|
||||||
void forwardQueryStartPosition(SQueryRuntimeEnv* pRuntimeEnv);
|
void forwardQueryStartPosition(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
|
|
||||||
bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, STableQuerySupportObj* pSupporter,
|
bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, STableQuerySupportObj* pSupporter,
|
||||||
|
@ -171,12 +170,10 @@ void enableFunctForMasterScan(SQueryRuntimeEnv* pRuntimeEnv, int32_t order);
|
||||||
int32_t mergeMetersResultToOneGroups(STableQuerySupportObj* pSupporter);
|
int32_t mergeMetersResultToOneGroups(STableQuerySupportObj* pSupporter);
|
||||||
void copyFromWindowResToSData(SQInfo* pQInfo, SWindowResult* result);
|
void copyFromWindowResToSData(SQInfo* pQInfo, SWindowResult* result);
|
||||||
|
|
||||||
SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv* pRuntimeEnv, void* pBlock, int32_t blockType);
|
SBlockInfo getBlockInfo(SQueryRuntimeEnv *pRuntimeEnv);
|
||||||
SCacheBlock* getCacheDataBlock(SMeterObj* pMeterObj, SQueryRuntimeEnv* pRuntimeEnv, int32_t slot);
|
SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv *pRuntimeEnv, void* pBlock, int32_t type);
|
||||||
|
|
||||||
// void queryOnBlock(STableQuerySupportObj* pSupporter, int32_t blockStatus, SBlockInfo* pBlockBasicInfo,
|
SCacheBlock* getCacheDataBlock(SMeterObj* pMeterObj, SQueryRuntimeEnv* pRuntimeEnv, int32_t slot);
|
||||||
// SMeterDataInfo* pDataHeadInfoEx, SField* pFields,
|
|
||||||
// __block_search_fn_t searchFn);
|
|
||||||
|
|
||||||
void stableApplyFunctionsOnBlock(STableQuerySupportObj* pSupporter, SMeterDataInfo* pMeterDataInfo,
|
void stableApplyFunctionsOnBlock(STableQuerySupportObj* pSupporter, SMeterDataInfo* pMeterDataInfo,
|
||||||
SBlockInfo* pBlockInfo, SField* pFields, __block_search_fn_t searchFn);
|
SBlockInfo* pBlockInfo, SField* pFields, __block_search_fn_t searchFn);
|
||||||
|
@ -190,14 +187,13 @@ 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(STableQuerySupportObj* pSupporter, SWindowResult* outputRes, int32_t meterIdx,
|
void setExecutionContext(STableQuerySupportObj* pSupporter, SMeterQueryInfo* pMeterQueryInfo, int32_t meterIdx,
|
||||||
int32_t groupIdx, SMeterQueryInfo* sqinfo);
|
int32_t groupIdx, TSKEY nextKey);
|
||||||
int32_t setIntervalQueryExecutionContext(STableQuerySupportObj* pSupporter, int32_t meterIdx, SMeterQueryInfo* sqinfo);
|
int32_t setAdditionalInfo(STableQuerySupportObj *pSupporter, int32_t meterIdx, SMeterQueryInfo *pMeterQueryInfo);
|
||||||
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);
|
|
||||||
|
|
||||||
int32_t getDataBlocksForMeters(STableQuerySupportObj* 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);
|
||||||
|
|
|
@ -169,19 +169,16 @@ typedef struct SQueryRuntimeEnv {
|
||||||
STSBuf* pTSBuf;
|
STSBuf* pTSBuf;
|
||||||
STSCursor cur;
|
STSCursor cur;
|
||||||
SQueryCostSummary summary;
|
SQueryCostSummary summary;
|
||||||
|
bool stableQuery; // is super table query or not
|
||||||
STimeWindow intervalWindow; // the complete time window, not affected by the actual data distribution
|
SQueryDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Temporarily hold the in-memory cache block info during scan cache blocks
|
* Temporarily hold the in-memory cache block info during scan cache blocks
|
||||||
* Here we do not use the cacheblock info from pMeterObj, simple because it may change anytime
|
* Here we do not use the cache block info from pMeterObj, simple because it may change anytime
|
||||||
* during the query by the subumit/insert handling threads.
|
* during the query by the submit/insert handling threads.
|
||||||
* So we keep a copy of the support structure as well as the cache block data itself.
|
* So we keep a copy of the support structure as well as the cache block data itself.
|
||||||
*/
|
*/
|
||||||
SCacheBlock cacheBlock;
|
SCacheBlock cacheBlock;
|
||||||
|
|
||||||
SQueryDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
|
||||||
bool stableQuery; // is super table query or not
|
|
||||||
} SQueryRuntimeEnv;
|
} SQueryRuntimeEnv;
|
||||||
|
|
||||||
/* intermediate pos during multimeter query involves interval */
|
/* intermediate pos during multimeter query involves interval */
|
||||||
|
@ -222,13 +219,11 @@ typedef struct STableQuerySupportObj {
|
||||||
* rows may be generated by a specific subgroup. When query on all subgroups is executed,
|
* rows may be generated by a specific subgroup. When query on all subgroups is executed,
|
||||||
* the result is copy to output buffer. This attribution is not used during single meter query processing.
|
* the result is copy to output buffer. This attribution is not used during single meter query processing.
|
||||||
*/
|
*/
|
||||||
// SWindowResult* pResult;
|
|
||||||
SQueryRuntimeEnv runtimeEnv;
|
SQueryRuntimeEnv runtimeEnv;
|
||||||
int64_t rawSKey;
|
int64_t rawSKey;
|
||||||
int64_t rawEKey;
|
int64_t rawEKey;
|
||||||
int32_t subgroupIdx;
|
int32_t subgroupIdx;
|
||||||
int32_t offset; /* offset in group result set of subgroup */
|
int32_t offset; /* offset in group result set of subgroup */
|
||||||
|
|
||||||
tSidSet* pSidSet;
|
tSidSet* pSidSet;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -70,7 +70,7 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
|
||||||
static void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx);
|
static void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx);
|
||||||
static int32_t flushFromResultBuf(STableQuerySupportObj *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);
|
||||||
static TSKEY getQueryPositionForCacheInvalid(SQueryRuntimeEnv *pRuntimeEnv, __block_search_fn_t searchFn);
|
static TSKEY getQueryPositionForCacheInvalid(SQueryRuntimeEnv *pRuntimeEnv, __block_search_fn_t searchFn);
|
||||||
static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int32_t functionId);
|
static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int32_t functionId);
|
||||||
|
@ -984,7 +984,6 @@ static int32_t loadDataBlockIntoMem(SCompBlock *pBlock, SField **pField, SQueryR
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo ignore the blockType, pass the pQuery into this function
|
|
||||||
SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv *pRuntimeEnv, void *pBlock, int32_t blockType) {
|
SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv *pRuntimeEnv, void *pBlock, int32_t blockType) {
|
||||||
SBlockInfo blockInfo = {0};
|
SBlockInfo blockInfo = {0};
|
||||||
if (IS_FILE_BLOCK(blockType)) {
|
if (IS_FILE_BLOCK(blockType)) {
|
||||||
|
@ -1247,11 +1246,10 @@ static void *getGenericDataBlock(SMeterObj *pMeterObj, SQueryRuntimeEnv *pRuntim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SBlockInfo getBlockInfo(SQueryRuntimeEnv *pRuntimeEnv) {
|
SBlockInfo getBlockInfo(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
SQuery * pQuery = pRuntimeEnv->pQuery;
|
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||||
SMeterObj *pMeterObj = pRuntimeEnv->pMeterObj;
|
|
||||||
|
|
||||||
void *pBlock = getGenericDataBlock(pMeterObj, pRuntimeEnv, pQuery->slot);
|
void *pBlock = getGenericDataBlock(pRuntimeEnv->pMeterObj, pRuntimeEnv, pQuery->slot);
|
||||||
assert(pBlock != NULL);
|
assert(pBlock != NULL);
|
||||||
|
|
||||||
int32_t blockType = IS_DISK_DATA_BLOCK(pQuery) ? BLK_FILE_BLOCK : BLK_CACHE_BLOCK;
|
int32_t blockType = IS_DISK_DATA_BLOCK(pQuery) ? BLK_FILE_BLOCK : BLK_CACHE_BLOCK;
|
||||||
|
@ -1444,16 +1442,15 @@ static char *getDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sa
|
||||||
return dataBlock;
|
return dataBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
static SWindowResult *getWindowResult(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||||
assert(pWindowResInfo != NULL && slot >= 0 && slot < pWindowResInfo->size);
|
|
||||||
return (pWindowResInfo->pResult[slot].status.closed == true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static SWindowResult* getWindowResult(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
|
||||||
assert(pWindowResInfo != NULL && slot >= 0 && slot < pWindowResInfo->size);
|
assert(pWindowResInfo != NULL && slot >= 0 && slot < pWindowResInfo->size);
|
||||||
return &pWindowResInfo->pResult[slot];
|
return &pWindowResInfo->pResult[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||||
|
return (getWindowResult(pWindowResInfo, slot)->status.closed == true);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t curTimeWindow(SWindowResInfo *pWindowResInfo) {
|
static int32_t curTimeWindow(SWindowResInfo *pWindowResInfo) {
|
||||||
assert(pWindowResInfo->curIndex >= 0 && pWindowResInfo->curIndex < pWindowResInfo->size);
|
assert(pWindowResInfo->curIndex >= 0 && pWindowResInfo->curIndex < pWindowResInfo->size);
|
||||||
return pWindowResInfo->curIndex;
|
return pWindowResInfo->curIndex;
|
||||||
|
@ -1491,7 +1488,7 @@ static SWindowResult *doSetTimeWindowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin
|
||||||
taosAddToHashTable(pWindowResInfo->hashList, pData, bytes, (char *)&pWindowResInfo->curIndex, sizeof(int32_t));
|
taosAddToHashTable(pWindowResInfo->hashList, pData, bytes, (char *)&pWindowResInfo->curIndex, sizeof(int32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
return &pWindowResInfo->pResult[pWindowResInfo->curIndex];
|
return getWindowResult(pWindowResInfo, pWindowResInfo->curIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the correct time window according to the handled timestamp
|
// get the correct time window according to the handled timestamp
|
||||||
|
@ -1503,7 +1500,7 @@ static STimeWindow getActiveTimeWindow(SWindowResInfo *pWindowResInfo, int64_t t
|
||||||
w.ekey = w.skey + pQuery->intervalTime - 1;
|
w.ekey = w.skey + pQuery->intervalTime - 1;
|
||||||
} else {
|
} else {
|
||||||
int32_t slot = curTimeWindow(pWindowResInfo);
|
int32_t slot = curTimeWindow(pWindowResInfo);
|
||||||
w = pWindowResInfo->pResult[slot].window;
|
w = getWindowResult(pWindowResInfo, slot)->window;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w.skey > ts || w.ekey < ts) {
|
if (w.skey > ts || w.ekey < ts) {
|
||||||
|
@ -1522,18 +1519,15 @@ static STimeWindow getActiveTimeWindow(SWindowResInfo *pWindowResInfo, int64_t t
|
||||||
w.ekey = w.skey + pQuery->intervalTime - 1;
|
w.ekey = w.skey + pQuery->intervalTime - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// query border check
|
/*
|
||||||
|
* query border check, skey should not be bounded by the query time range, since the value skey will
|
||||||
|
* be used as the time window index value. So we only change ekey of time window accordingly.
|
||||||
|
*/
|
||||||
if (w.ekey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) {
|
if (w.ekey > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) {
|
||||||
w.ekey = pQuery->ekey;
|
w.ekey = pQuery->ekey;
|
||||||
}
|
}
|
||||||
if (w.skey < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery)) {
|
|
||||||
w.skey = pQuery->ekey;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(ts >= w.skey && ts <= w.ekey && w.skey != 0);
|
assert(ts >= w.skey && ts <= w.ekey && w.skey != 0);
|
||||||
if (w.skey == 1542597000000) {
|
|
||||||
int32_t k = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -1568,9 +1562,6 @@ static int32_t addNewWindowResultBuf(SWindowResult *pWindowRes, SQueryDiskbasedR
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageId == 153 && pData->numOfElems >= 138) {
|
|
||||||
int32_t k = 1;
|
|
||||||
}
|
|
||||||
// set the number of rows in current disk page
|
// set the number of rows in current disk page
|
||||||
if (pWindowRes->pos.pageId == -1) { // not allocated yet, allocate new buffer
|
if (pWindowRes->pos.pageId == -1) { // not allocated yet, allocate new buffer
|
||||||
pWindowRes->pos.pageId = pageId;
|
pWindowRes->pos.pageId = pageId;
|
||||||
|
@ -1725,10 +1716,6 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SBlockInfo *pBlockInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pQuery->lastKey == 1542597000001) {
|
|
||||||
int32_t k = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(num >= 0);
|
assert(num >= 0);
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
@ -1752,7 +1739,8 @@ static void doBlockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SWindowStat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doRowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SWindowStatus *pStatus, STimeWindow *pWin, int32_t offset) {
|
static void doRowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SWindowStatus *pStatus, STimeWindow *pWin,
|
||||||
|
int32_t offset) {
|
||||||
SQuery * pQuery = pRuntimeEnv->pQuery;
|
SQuery * pQuery = pRuntimeEnv->pQuery;
|
||||||
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
||||||
|
|
||||||
|
@ -1854,9 +1842,8 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TSKEY ts = QUERY_IS_ASC_QUERY(pQuery) ? pRuntimeEnv->intervalWindow.skey : pRuntimeEnv->intervalWindow.ekey;
|
setExecParams(pQuery, &pCtx[k], pQuery->skey, dataBlock, (char *)primaryKeyCol, forwardStep, functionId, tpField,
|
||||||
setExecParams(pQuery, &pCtx[k], ts, dataBlock, (char *)primaryKeyCol, forwardStep, functionId, tpField, hasNull,
|
hasNull, pRuntimeEnv->blockStatus, &sasArray[k], pRuntimeEnv->scanFlag);
|
||||||
pRuntimeEnv->blockStatus, &sasArray[k], pRuntimeEnv->scanFlag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
||||||
|
@ -1865,19 +1852,23 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
|
||||||
TSKEY ts = primaryKeyCol[offset];
|
TSKEY ts = primaryKeyCol[offset];
|
||||||
|
|
||||||
STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery);
|
STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery);
|
||||||
if (win.skey >= 1542597000000 && pRuntimeEnv->pMeterObj->sid == 9 && IS_MASTER_SCAN(pRuntimeEnv)) {
|
|
||||||
int32_t k = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (win.skey >= 1542597000000 && pRuntimeEnv->pMeterObj->sid == 9 && !IS_MASTER_SCAN(pRuntimeEnv)) {
|
|
||||||
int32_t k = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pRuntimeEnv->pMeterObj->sid, &win) != TSDB_CODE_SUCCESS) {
|
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pRuntimeEnv->pMeterObj->sid, &win) != TSDB_CODE_SUCCESS) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TSKEY ekey = QUERY_IS_ASC_QUERY(pQuery) ? win.ekey : win.skey;
|
TSKEY ekey = -1;
|
||||||
|
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
||||||
|
ekey = win.ekey;
|
||||||
|
if (ekey > pQuery->ekey) {
|
||||||
|
ekey = pQuery->ekey;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ekey = win.skey;
|
||||||
|
if (ekey < pQuery->ekey) {
|
||||||
|
ekey = pQuery->ekey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
forwardStep = getNumOfRowsInTimeWindow(pQuery, pBlockInfo, primaryKeyCol, pQuery->pos, ekey, searchFn, true);
|
forwardStep = getNumOfRowsInTimeWindow(pQuery, pBlockInfo, primaryKeyCol, pQuery->pos, ekey, searchFn, true);
|
||||||
|
|
||||||
SWindowStatus *pStatus = getTimeWindowResStatus(pWindowResInfo, curTimeWindow(pWindowResInfo));
|
SWindowStatus *pStatus = getTimeWindowResStatus(pWindowResInfo, curTimeWindow(pWindowResInfo));
|
||||||
|
@ -1893,17 +1884,25 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextWin.skey >= 1542597000000 && pRuntimeEnv->pMeterObj->sid == 9 && IS_MASTER_SCAN(pRuntimeEnv)) {
|
|
||||||
int32_t k = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// null data, failed to allocate more memory buffer
|
// null data, failed to allocate more memory buffer
|
||||||
int32_t sid = pRuntimeEnv->pMeterObj->sid;
|
int32_t sid = pRuntimeEnv->pMeterObj->sid;
|
||||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, sid, &nextWin) != TSDB_CODE_SUCCESS) {
|
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, sid, &nextWin) != TSDB_CODE_SUCCESS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ekey = QUERY_IS_ASC_QUERY(pQuery) ? nextWin.ekey : nextWin.skey;
|
ekey = -1;
|
||||||
|
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
||||||
|
ekey = nextWin.ekey;
|
||||||
|
if (ekey > pQuery->ekey) {
|
||||||
|
ekey = pQuery->ekey;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ekey = nextWin.skey;
|
||||||
|
if (ekey < pQuery->ekey) {
|
||||||
|
ekey = pQuery->ekey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
forwardStep = getNumOfRowsInTimeWindow(pQuery, pBlockInfo, primaryKeyCol, startPos, ekey, searchFn, true);
|
forwardStep = getNumOfRowsInTimeWindow(pQuery, pBlockInfo, primaryKeyCol, startPos, ekey, searchFn, true);
|
||||||
|
|
||||||
pStatus = getTimeWindowResStatus(pWindowResInfo, curTimeWindow(pWindowResInfo));
|
pStatus = getTimeWindowResStatus(pWindowResInfo, curTimeWindow(pWindowResInfo));
|
||||||
|
@ -1934,8 +1933,6 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
|
||||||
num = getNumOfResult(pRuntimeEnv) - prevNumOfRes;
|
num = getNumOfResult(pRuntimeEnv) - prevNumOfRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
validateTimestampForSupplementResult(pRuntimeEnv, num);
|
|
||||||
|
|
||||||
tfree(sasArray);
|
tfree(sasArray);
|
||||||
return (int32_t)num;
|
return (int32_t)num;
|
||||||
}
|
}
|
||||||
|
@ -2137,8 +2134,7 @@ int32_t numOfClosedTimeWindow(SWindowResInfo *pWindowResInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeTimeWindow(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
void closeTimeWindow(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||||
assert(slot >= 0 && slot < pWindowResInfo->size);
|
getWindowResult(pWindowResInfo, slot)->status.closed = true;
|
||||||
pWindowResInfo->pResult[slot].status.closed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeAllTimeWindow(SWindowResInfo *pWindowResInfo) {
|
void closeAllTimeWindow(SWindowResInfo *pWindowResInfo) {
|
||||||
|
@ -2283,7 +2279,8 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t *
|
||||||
bool hasNull = hasNullVal(pQuery, k, pBlockInfo, pFields, isDiskFileBlock);
|
bool hasNull = hasNullVal(pQuery, k, pBlockInfo, pFields, isDiskFileBlock);
|
||||||
char *dataBlock = getDataBlocks(pRuntimeEnv, &sasArray[k], k, *forwardStep);
|
char *dataBlock = getDataBlocks(pRuntimeEnv, &sasArray[k], k, *forwardStep);
|
||||||
|
|
||||||
TSKEY ts = QUERY_IS_ASC_QUERY(pQuery) ? pRuntimeEnv->intervalWindow.skey : pRuntimeEnv->intervalWindow.ekey;
|
TSKEY ts = pQuery->skey; // QUERY_IS_ASC_QUERY(pQuery) ? pRuntimeEnv->intervalWindow.skey :
|
||||||
|
// pRuntimeEnv->intervalWindow.ekey;
|
||||||
setExecParams(pQuery, &pCtx[k], ts, dataBlock, (char *)primaryKeyCol, (*forwardStep), functionId, pFields, hasNull,
|
setExecParams(pQuery, &pCtx[k], ts, dataBlock, (char *)primaryKeyCol, (*forwardStep), functionId, pFields, hasNull,
|
||||||
pRuntimeEnv->blockStatus, &sasArray[k], pRuntimeEnv->scanFlag);
|
pRuntimeEnv->blockStatus, &sasArray[k], pRuntimeEnv->scanFlag);
|
||||||
}
|
}
|
||||||
|
@ -2408,7 +2405,7 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t *
|
||||||
* requires checking buffer during loop
|
* requires checking buffer during loop
|
||||||
*/
|
*/
|
||||||
if ((pQuery->checkBufferInLoop == 1) && (++numOfRes) >= pQuery->pointsOffset) {
|
if ((pQuery->checkBufferInLoop == 1) && (++numOfRes) >= pQuery->pointsOffset) {
|
||||||
pQuery->lastKey = primaryKeyCol[pQuery->pos + j * step] + step;
|
pQuery->lastKey = lastKey + step;
|
||||||
*forwardStep = j + 1;
|
*forwardStep = j + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2473,9 +2470,9 @@ static void validateQueryRangeAndData(SQueryRuntimeEnv *pRuntimeEnv, const TSKEY
|
||||||
!QUERY_IS_ASC_QUERY(pQuery)));
|
!QUERY_IS_ASC_QUERY(pQuery)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SBlockInfo *pBlockInfo, int64_t *pPrimaryColumn,
|
static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SBlockInfo *pBlockInfo,
|
||||||
SField *pFields, __block_search_fn_t searchFn, int32_t *numOfRes,
|
int64_t *pPrimaryColumn, SField *pFields, __block_search_fn_t searchFn,
|
||||||
SWindowResInfo *pWindowResInfo) {
|
int32_t *numOfRes, SWindowResInfo *pWindowResInfo) {
|
||||||
SQuery *pQuery = pRuntimeEnv->pQuery;
|
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||||
validateQueryRangeAndData(pRuntimeEnv, pPrimaryColumn, pBlockInfo);
|
validateQueryRangeAndData(pRuntimeEnv, pPrimaryColumn, pBlockInfo);
|
||||||
|
|
||||||
|
@ -2502,7 +2499,8 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SBlockI
|
||||||
doCheckQueryCompleted(pRuntimeEnv, lastKey, pWindowResInfo);
|
doCheckQueryCompleted(pRuntimeEnv, lastKey, pWindowResInfo);
|
||||||
|
|
||||||
// interval query with limit applied
|
// interval query with limit applied
|
||||||
if (pQuery->intervalTime > 0 && pQuery->limit.limit > 0 && pQuery->limit.limit <= numOfClosedTimeWindow(pWindowResInfo)) {
|
if (pQuery->intervalTime > 0 && pQuery->limit.limit > 0 &&
|
||||||
|
pQuery->limit.limit <= numOfClosedTimeWindow(pWindowResInfo)) {
|
||||||
setQueryStatus(pQuery, QUERY_COMPLETED);
|
setQueryStatus(pQuery, QUERY_COMPLETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3417,7 +3415,6 @@ static bool doGetQueryPos(TSKEY key, STableQuerySupportObj *pSupporter, SPointIn
|
||||||
if (isPointInterpoQuery(pQuery)) { /* no qualified data in this query range */
|
if (isPointInterpoQuery(pQuery)) { /* no qualified data in this query range */
|
||||||
return getNeighborPoints(pSupporter, pMeterObj, pPointInterpSupporter);
|
return getNeighborPoints(pSupporter, pMeterObj, pPointInterpSupporter);
|
||||||
} else {
|
} else {
|
||||||
// getAlignedIntervalQueryRange(pRuntimeEnv, key, pQuery->skey, pQuery->ekey);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else { // key > pQuery->ekey, abort for normal query, continue for interp query
|
} else { // key > pQuery->ekey, abort for normal query, continue for interp query
|
||||||
|
@ -3449,7 +3446,6 @@ static bool doSetDataInfo(STableQuerySupportObj *pSupporter, SPointInterpoSuppor
|
||||||
|
|
||||||
return getNeighborPoints(pSupporter, pMeterObj, pPointInterpSupporter);
|
return getNeighborPoints(pSupporter, pMeterObj, pPointInterpSupporter);
|
||||||
} else {
|
} else {
|
||||||
// getAlignedIntervalQueryRange(pRuntimeEnv, nextKey, pQuery->skey, pQuery->ekey);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3554,69 +3550,6 @@ static int64_t getGreaterEqualTimestamp(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getActualRange(STableQuerySupportObj *pSupporter, STimeWindow *pTimeWindow) {
|
|
||||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
|
||||||
SQuery * pQuery = pRuntimeEnv->pQuery;
|
|
||||||
SMeterObj * pMeterObj = pRuntimeEnv->pMeterObj;
|
|
||||||
__block_search_fn_t searchFn = vnodeSearchKeyFunc[pMeterObj->searchAlgorithm];
|
|
||||||
|
|
||||||
int32_t order = pQuery->order.order;
|
|
||||||
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
|
|
||||||
pQuery->lastKey = pQuery->skey;
|
|
||||||
|
|
||||||
if (QUERY_IS_ASC_QUERY(pQuery)) { // do the desc check first for asc query
|
|
||||||
pQuery->order.order ^= 1u;
|
|
||||||
|
|
||||||
TSKEY t = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false);
|
|
||||||
if (t > 0) {
|
|
||||||
pTimeWindow->ekey = t;
|
|
||||||
} else if (getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_LESS_EQUAL, searchFn)) {
|
|
||||||
pTimeWindow->ekey = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
pQuery->order.order = order;
|
|
||||||
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
|
|
||||||
pQuery->lastKey = pQuery->skey;
|
|
||||||
|
|
||||||
if (getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_GREATER_EQUAL, searchFn)) {
|
|
||||||
pTimeWindow->skey = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos);
|
|
||||||
} else { // set no data in file
|
|
||||||
pQuery->fileId = -1;
|
|
||||||
pTimeWindow->skey = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
pQuery->skey = pTimeWindow->skey;
|
|
||||||
pQuery->ekey = pTimeWindow->ekey;
|
|
||||||
} else {
|
|
||||||
pQuery->order.order ^= 1u;
|
|
||||||
|
|
||||||
if (getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_GREATER_EQUAL, searchFn)) {
|
|
||||||
pTimeWindow->skey = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos);
|
|
||||||
} else { // set no data in file
|
|
||||||
pTimeWindow->skey = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reverse check for maxValue in query range
|
|
||||||
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
|
|
||||||
pQuery->order.order ^= 1u;
|
|
||||||
|
|
||||||
// set no data in file
|
|
||||||
pQuery->lastKey = pQuery->skey;
|
|
||||||
|
|
||||||
TSKEY t = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false);
|
|
||||||
if (t > 0) {
|
|
||||||
pTimeWindow->ekey = t;
|
|
||||||
} else if (getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_LESS_EQUAL, searchFn)) {
|
|
||||||
pTimeWindow->ekey = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
pQuery->ekey = pTimeWindow->skey;
|
|
||||||
pQuery->skey = pTimeWindow->ekey;
|
|
||||||
}
|
|
||||||
|
|
||||||
pQuery->order.order = order;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* determine the first query range, according to raw query range [skey, ekey] and group-by interval.
|
* determine the first query range, according to raw query range [skey, ekey] and group-by interval.
|
||||||
* 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
|
||||||
|
@ -5213,11 +5146,9 @@ static void doHandleDataBlockImpl(SQueryRuntimeEnv *pRuntimeEnv, SBlockInfo *pbl
|
||||||
|
|
||||||
TSKEY * primaryKeys = (TSKEY *)pRuntimeEnv->primaryColBuffer->data;
|
TSKEY * primaryKeys = (TSKEY *)pRuntimeEnv->primaryColBuffer->data;
|
||||||
int64_t start = taosGetTimestampUs();
|
int64_t start = taosGetTimestampUs();
|
||||||
|
*pblockInfo = getBlockInfo(pRuntimeEnv);
|
||||||
|
|
||||||
if (IS_DISK_DATA_BLOCK(pQuery)) {
|
if (IS_DISK_DATA_BLOCK(pQuery)) {
|
||||||
SCompBlock *pBlock = getDiskDataBlock(pQuery, pQuery->slot);
|
|
||||||
*pblockInfo = getBlockBasicInfo(pRuntimeEnv, pBlock, BLK_FILE_BLOCK);
|
|
||||||
|
|
||||||
if (blockLoadStatus == DISK_DATA_LOADED) {
|
if (blockLoadStatus == DISK_DATA_LOADED) {
|
||||||
*forwardStep = tableApplyFunctionsOnBlock(pRuntimeEnv, pblockInfo, primaryKeys, pQuery->pFields[pQuery->slot],
|
*forwardStep = tableApplyFunctionsOnBlock(pRuntimeEnv, pblockInfo, primaryKeys, pQuery->pFields[pQuery->slot],
|
||||||
searchFn, numOfRes, &pRuntimeEnv->windowResInfo);
|
searchFn, numOfRes, &pRuntimeEnv->windowResInfo);
|
||||||
|
@ -5228,10 +5159,6 @@ static void doHandleDataBlockImpl(SQueryRuntimeEnv *pRuntimeEnv, SBlockInfo *pbl
|
||||||
pSummary->fileTimeUs += (taosGetTimestampUs() - start);
|
pSummary->fileTimeUs += (taosGetTimestampUs() - start);
|
||||||
} else {
|
} else {
|
||||||
assert(vnodeIsDatablockLoaded(pRuntimeEnv, pRuntimeEnv->pMeterObj, -1, true) == DISK_BLOCK_NO_NEED_TO_LOAD);
|
assert(vnodeIsDatablockLoaded(pRuntimeEnv, pRuntimeEnv->pMeterObj, -1, true) == DISK_BLOCK_NO_NEED_TO_LOAD);
|
||||||
|
|
||||||
SCacheBlock *pBlock = getCacheDataBlock(pRuntimeEnv->pMeterObj, pRuntimeEnv, pQuery->slot);
|
|
||||||
*pblockInfo = getBlockBasicInfo(pRuntimeEnv, pBlock, BLK_CACHE_BLOCK);
|
|
||||||
|
|
||||||
*forwardStep = tableApplyFunctionsOnBlock(pRuntimeEnv, pblockInfo, primaryKeys, NULL, searchFn, numOfRes,
|
*forwardStep = tableApplyFunctionsOnBlock(pRuntimeEnv, pblockInfo, primaryKeys, NULL, searchFn, numOfRes,
|
||||||
&pRuntimeEnv->windowResInfo);
|
&pRuntimeEnv->windowResInfo);
|
||||||
|
|
||||||
|
@ -5404,7 +5331,7 @@ void vnodeSetTagValueInParam(tSidSet *pSidSet, SQueryRuntimeEnv *pRuntimeEnv, SM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doMerge(SQueryRuntimeEnv *pRuntimeEnv, int64_t timestamp, tFilePage *inputSrc, int32_t inputIdx,
|
static void doMerge(SQueryRuntimeEnv *pRuntimeEnv, int64_t timestamp, SWindowResult* pWindowRes, /*int32_t inputIdx,*/
|
||||||
bool mergeFlag) {
|
bool mergeFlag) {
|
||||||
SQuery * pQuery = pRuntimeEnv->pQuery;
|
SQuery * pQuery = pRuntimeEnv->pQuery;
|
||||||
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
||||||
|
@ -5421,9 +5348,10 @@ static void doMerge(SQueryRuntimeEnv *pRuntimeEnv, int64_t timestamp, tFilePage
|
||||||
|
|
||||||
pCtx[i].hasNull = true;
|
pCtx[i].hasNull = true;
|
||||||
pCtx[i].nStartQueryTimestamp = timestamp;
|
pCtx[i].nStartQueryTimestamp = timestamp;
|
||||||
pCtx[i].aInputElemBuf = ((char *)inputSrc->data) +
|
pCtx[i].aInputElemBuf = getPosInResultPage(pRuntimeEnv, i, pWindowRes);
|
||||||
((int32_t)pRuntimeEnv->offset[i] * pRuntimeEnv->numOfRowsPerPage) +
|
// pCtx[i].aInputElemBuf = ((char *)inputSrc->data) +
|
||||||
pCtx[i].outputBytes * inputIdx;
|
// ((int32_t)pRuntimeEnv->offset[i] * pRuntimeEnv->numOfRowsPerPage) +
|
||||||
|
// pCtx[i].outputBytes * inputIdx;
|
||||||
|
|
||||||
// in case of tag column, the tag information should be extracted from input buffer
|
// in case of tag column, the tag information should be extracted from input buffer
|
||||||
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TAG) {
|
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TAG) {
|
||||||
|
@ -5578,7 +5506,7 @@ int64_t getCurrentTimestamp(SCompSupporter *pSupportor, int32_t meterIdx) {
|
||||||
return *(int64_t *)(pPage->data + TSDB_KEYSIZE * pPos->rowIdx);
|
return *(int64_t *)(pPage->data + TSDB_KEYSIZE * pPos->rowIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t meterResultComparator(const void *pLeft, const void *pRight, void *param) {
|
int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *param) {
|
||||||
int32_t left = *(int32_t *)pLeft;
|
int32_t left = *(int32_t *)pLeft;
|
||||||
int32_t right = *(int32_t *)pRight;
|
int32_t right = *(int32_t *)pRight;
|
||||||
|
|
||||||
|
@ -5598,6 +5526,7 @@ int32_t meterResultComparator(const void *pLeft, const void *pRight, void *param
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!!!!!
|
||||||
tFilePage *pPageLeft = getMeterDataPage(pResultBuf, supporter->pMeterDataInfo[left]->pMeterQInfo, leftPos.pageIdx);
|
tFilePage *pPageLeft = getMeterDataPage(pResultBuf, supporter->pMeterDataInfo[left]->pMeterQInfo, leftPos.pageIdx);
|
||||||
int64_t leftTimestamp = *(int64_t *)(pPageLeft->data + TSDB_KEYSIZE * leftPos.rowIdx);
|
int64_t leftTimestamp = *(int64_t *)(pPageLeft->data + TSDB_KEYSIZE * leftPos.rowIdx);
|
||||||
|
|
||||||
|
@ -5695,6 +5624,32 @@ void copyResToQueryResultBuf(STableQuerySupportObj *pSupporter, SQuery *pQuery)
|
||||||
pSupporter->offset += 1;
|
pSupporter->offset += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t getNumOfResultWindowRes(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult* pWindowRes) {
|
||||||
|
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||||
|
// bool hasMainFunction = hasMainOutput(pQuery);
|
||||||
|
|
||||||
|
int64_t maxOutput = 0;
|
||||||
|
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
|
||||||
|
int32_t functionId = pQuery->pSelectExpr[j].pBase.functionId;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ts, tag, tagprj function can not decide the output number of current query
|
||||||
|
* the number of output result is decided by main output
|
||||||
|
*/
|
||||||
|
if (/*hasMainFunction &&*/
|
||||||
|
(functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SResultInfo *pResultInfo = &pWindowRes->resultInfo[j];
|
||||||
|
if (pResultInfo != NULL && maxOutput < pResultInfo->numOfRes) {
|
||||||
|
maxOutput = pResultInfo->numOfRes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxOutput;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *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
|
||||||
|
@ -5708,6 +5663,7 @@ int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery
|
||||||
Position * posList = calloc(1, sizeof(Position) * (end - start));
|
Position * posList = calloc(1, sizeof(Position) * (end - start));
|
||||||
SMeterDataInfo **pTableList = malloc(POINTER_BYTES * (end - start));
|
SMeterDataInfo **pTableList = malloc(POINTER_BYTES * (end - start));
|
||||||
|
|
||||||
|
//todo opt for the case of one table per group
|
||||||
int32_t numOfMeters = 0;
|
int32_t numOfMeters = 0;
|
||||||
for (int32_t i = start; i < end; ++i) {
|
for (int32_t i = start; i < end; ++i) {
|
||||||
int32_t sid = pMeterDataInfo[i].pMeterQInfo->sid;
|
int32_t sid = pMeterDataInfo[i].pMeterQInfo->sid;
|
||||||
|
@ -5717,7 +5673,9 @@ int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery
|
||||||
pTableList[numOfMeters] = &pMeterDataInfo[i];
|
pTableList[numOfMeters] = &pMeterDataInfo[i];
|
||||||
// set the merge start position: page:0, index:0
|
// set the merge start position: page:0, index:0
|
||||||
posList[numOfMeters].pageIdx = 0;
|
posList[numOfMeters].pageIdx = 0;
|
||||||
posList[numOfMeters++].rowIdx = 0;
|
posList[numOfMeters].rowIdx = 0;
|
||||||
|
|
||||||
|
numOfMeters += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5731,7 +5689,7 @@ int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery
|
||||||
SCompSupporter cs = {pTableList, posList, pSupporter};
|
SCompSupporter cs = {pTableList, posList, pSupporter};
|
||||||
SLoserTreeInfo *pTree = NULL;
|
SLoserTreeInfo *pTree = NULL;
|
||||||
|
|
||||||
tLoserTreeCreate(&pTree, numOfMeters, &cs, meterResultComparator);
|
tLoserTreeCreate(&pTree, numOfMeters, &cs, tableResultComparFn);
|
||||||
|
|
||||||
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
||||||
resetMergeResultBuf(pQuery, pCtx);
|
resetMergeResultBuf(pQuery, pCtx);
|
||||||
|
@ -5740,17 +5698,36 @@ int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery
|
||||||
|
|
||||||
int64_t startt = taosGetTimestampMs();
|
int64_t startt = taosGetTimestampMs();
|
||||||
|
|
||||||
while (1) {
|
while (1) {//todo add iterator
|
||||||
int32_t pos = pTree->pNode[0].index;
|
int32_t pos = pTree->pNode[0].index;
|
||||||
Position * position = &cs.pPosition[pos];
|
Position * position = &cs.pPosition[pos];
|
||||||
SQueryDiskbasedResultBuf *pResultBuf = cs.pSupporter->runtimeEnv.pResultBuf;
|
|
||||||
tFilePage * pPage = getMeterDataPage(pResultBuf, pTableList[pos]->pMeterQInfo, position->pageIdx);
|
|
||||||
|
|
||||||
int64_t ts = getCurrentTimestamp(&cs, pos);
|
// SQueryDiskbasedResultBuf *pResultBuf = cs.pSupporter->runtimeEnv.pResultBuf;
|
||||||
assert(ts > 0);
|
// tFilePage *pPage = getMeterDataPage(pResultBuf, pTableList[pos]->pMeterQInfo, position->pageIdx);
|
||||||
|
SWindowResInfo* pWindowResInfo = &pTableList[pos]->pMeterQInfo->windowResInfo;
|
||||||
|
SWindowResult* pWindowRes = getWindowResult(pWindowResInfo, position->rowIdx);
|
||||||
|
|
||||||
|
char* b = getPosInResultPage(pRuntimeEnv, PRIMARYKEY_TIMESTAMP_COL_INDEX, pWindowRes);
|
||||||
|
TSKEY ts = GET_INT64_VAL(b);
|
||||||
|
|
||||||
|
// int64_t ts = getCurrentTimestamp(&cs, pos);
|
||||||
|
assert(ts > 0 && ts == pWindowRes->window.skey);
|
||||||
|
|
||||||
|
int64_t num = getNumOfResultWindowRes(pRuntimeEnv, pWindowRes);
|
||||||
|
if (num <= 0) {
|
||||||
|
cs.pPosition[pos].rowIdx += 1;
|
||||||
|
|
||||||
|
if (cs.pPosition[pos].rowIdx >= pWindowResInfo->size) {
|
||||||
|
cs.pPosition[pos].rowIdx = -1;
|
||||||
|
|
||||||
|
// all input sources are exhausted
|
||||||
|
if (--numOfMeters == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (ts == lastTimestamp) { // merge with the last one
|
if (ts == lastTimestamp) { // merge with the last one
|
||||||
doMerge(pRuntimeEnv, ts, pPage, position->rowIdx, true);
|
doMerge(pRuntimeEnv, ts, pWindowRes, /*position->rowIdx,*/ true);
|
||||||
} else {
|
} else {
|
||||||
// copy data to disk buffer
|
// copy data to disk buffer
|
||||||
if (buffer[0]->numOfElems == pQuery->pointsToRead) {
|
if (buffer[0]->numOfElems == pQuery->pointsToRead) {
|
||||||
|
@ -5761,46 +5738,54 @@ int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery
|
||||||
resetMergeResultBuf(pQuery, pCtx);
|
resetMergeResultBuf(pQuery, pCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pPage = getMeterDataPage(pResultBuf, pTableList[pos]->pMeterQInfo, position->pageIdx);
|
// pPage = getMeterDataPage(pResultBuf, pTableList[pos]->pMeterQInfo, position->pageIdx);
|
||||||
if (pPage->numOfElems <= 0) { // current source data page is empty
|
// if (pPage->numOfElems <= 0) { // current source data page is empty
|
||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
// } else {
|
||||||
doMerge(pRuntimeEnv, ts, pPage, position->rowIdx, false);
|
doMerge(pRuntimeEnv, ts, pWindowRes, /*position->rowIdx,*/ false);
|
||||||
buffer[0]->numOfElems += 1;
|
buffer[0]->numOfElems += 1;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTimestamp = ts;
|
lastTimestamp = ts;
|
||||||
|
|
||||||
if (cs.pPosition[pos].rowIdx >= pPage->numOfElems - 1) {
|
if (cs.pPosition[pos].rowIdx >= pWindowResInfo->size) {
|
||||||
cs.pPosition[pos].rowIdx = 0;
|
|
||||||
cs.pPosition[pos].pageIdx += 1; // try next page
|
|
||||||
|
|
||||||
// check if current page is empty or not. if it is empty, ignore it and try next
|
|
||||||
SIDList list = getDataBufPagesIdList(pRuntimeEnv->pResultBuf, cs.pMeterDataInfo[pos]->pMeterQInfo->sid);
|
|
||||||
if (cs.pPosition[pos].pageIdx <= list.size - 1) {
|
|
||||||
tFilePage *newPage = getMeterDataPage(pResultBuf, pTableList[pos]->pMeterQInfo, position->pageIdx);
|
|
||||||
|
|
||||||
// if current source data page is null, it must be the last page of source output page
|
|
||||||
if (newPage->numOfElems <= 0) {
|
|
||||||
cs.pPosition[pos].pageIdx += 1;
|
|
||||||
assert(cs.pPosition[pos].pageIdx >= list.size - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the following code must be executed if current source pages are exhausted
|
|
||||||
if (cs.pPosition[pos].pageIdx >= list.size) {
|
|
||||||
cs.pPosition[pos].pageIdx = -1;
|
|
||||||
cs.pPosition[pos].rowIdx = -1;
|
cs.pPosition[pos].rowIdx = -1;
|
||||||
|
|
||||||
// all input sources are exhausted
|
// all input sources are exhausted
|
||||||
if (--numOfMeters == 0) {
|
if (--numOfMeters == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
// if (cs.pPosition[pos].rowIdx >= pPage->numOfElems - 1) {
|
||||||
|
// cs.pPosition[pos].rowIdx = 0;
|
||||||
|
// cs.pPosition[pos].pageIdx += 1; // try next page
|
||||||
|
//
|
||||||
|
// // check if current page is empty or not. if it is empty, ignore it and try next
|
||||||
|
// SIDList list = getDataBufPagesIdList(pRuntimeEnv->pResultBuf, cs.pMeterDataInfo[pos]->pMeterQInfo->sid);
|
||||||
|
// if (cs.pPosition[pos].pageIdx <= list.size - 1) {
|
||||||
|
// tFilePage *newPage = getMeterDataPage(pResultBuf, pTableList[pos]->pMeterQInfo, position->pageIdx);
|
||||||
|
//
|
||||||
|
// // if current source data page is null, it must be the last page of source output page
|
||||||
|
// if (newPage->numOfElems <= 0) {
|
||||||
|
// cs.pPosition[pos].pageIdx += 1;
|
||||||
|
// assert(cs.pPosition[pos].pageIdx >= list.size - 1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // the following code must be executed if current source pages are exhausted
|
||||||
|
// if (cs.pPosition[pos].pageIdx >= list.size) {
|
||||||
|
// cs.pPosition[pos].pageIdx = -1;
|
||||||
|
// cs.pPosition[pos].rowIdx = -1;
|
||||||
|
//
|
||||||
|
// // all input sources are exhausted
|
||||||
|
// if (--numOfMeters == 0) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
cs.pPosition[pos].rowIdx += 1;
|
cs.pPosition[pos].rowIdx += 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tLoserTreeAdjust(pTree, pos + pTree->numOfEntries);
|
tLoserTreeAdjust(pTree, pos + pTree->numOfEntries);
|
||||||
}
|
}
|
||||||
|
@ -5901,7 +5886,7 @@ void disableFunctForSuppleScan(SQueryRuntimeEnv *pRuntimeEnv, int32_t order) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SWindowResult *buf = &pWindowResInfo->pResult[i];
|
SWindowResult *buf = getWindowResult(pWindowResInfo, i);
|
||||||
|
|
||||||
// open/close the specified query for each group result
|
// open/close the specified query for each group result
|
||||||
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
|
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
|
||||||
|
@ -6165,14 +6150,11 @@ static void queryStatusSave(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatus *pStatus
|
||||||
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
|
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
|
||||||
pQuery->lastKey = pQuery->skey;
|
pQuery->lastKey = pQuery->skey;
|
||||||
pRuntimeEnv->startPos = pRuntimeEnv->endPos;
|
pRuntimeEnv->startPos = pRuntimeEnv->endPos;
|
||||||
|
|
||||||
SWAP(pRuntimeEnv->intervalWindow.skey, pRuntimeEnv->intervalWindow.ekey, TSKEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queryStatusRestore(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatus *pStatus) {
|
static void queryStatusRestore(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatus *pStatus) {
|
||||||
SQuery *pQuery = pRuntimeEnv->pQuery;
|
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||||
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
|
SWAP(pQuery->skey, pQuery->ekey, TSKEY);
|
||||||
SWAP(pRuntimeEnv->intervalWindow.skey, pRuntimeEnv->intervalWindow.ekey, TSKEY);
|
|
||||||
|
|
||||||
pQuery->lastKey = pStatus->lastKey;
|
pQuery->lastKey = pStatus->lastKey;
|
||||||
pQuery->skey = pStatus->skey;
|
pQuery->skey = pStatus->skey;
|
||||||
|
@ -6249,7 +6231,7 @@ void vnodeScanAllData(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
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) {
|
||||||
SWindowResult *pResult = &pWindowResInfo->pResult[i];
|
SWindowResult *pResult = getWindowResult(pWindowResInfo, i);
|
||||||
if (!pResult->status.closed) {
|
if (!pResult->status.closed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -6587,13 +6569,12 @@ void destroyMeterQueryInfo(SMeterQueryInfo *pMeterQueryInfo, int32_t numOfCols)
|
||||||
free(pMeterQueryInfo);
|
free(pMeterQueryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeMeterQueryInfoForSuppleQuery(SQuery* pQuery, SMeterQueryInfo *pMeterQueryInfo,
|
void changeMeterQueryInfoForSuppleQuery(SQuery *pQuery, SMeterQueryInfo *pMeterQueryInfo, TSKEY skey, TSKEY ekey) {
|
||||||
TSKEY skey, TSKEY ekey) {
|
|
||||||
if (pMeterQueryInfo == NULL) {
|
if (pMeterQueryInfo == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//order has change already!
|
// order has change already!
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
||||||
if (!QUERY_IS_ASC_QUERY(pQuery)) {
|
if (!QUERY_IS_ASC_QUERY(pQuery)) {
|
||||||
assert(pMeterQueryInfo->ekey >= pMeterQueryInfo->lastKey + step);
|
assert(pMeterQueryInfo->ekey >= pMeterQueryInfo->lastKey + step);
|
||||||
|
@ -7009,23 +6990,24 @@ int32_t createDataBlocksInfoEx(SMeterDataInfo **pMeterDataInfo, int32_t numOfMet
|
||||||
* @param pRuntimeEnv
|
* @param pRuntimeEnv
|
||||||
* @param pDataBlockInfoEx
|
* @param pDataBlockInfoEx
|
||||||
*/
|
*/
|
||||||
void setExecutionContext(STableQuerySupportObj *pSupporter, SWindowResult *outputRes, int32_t meterIdx,
|
void setExecutionContext(STableQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo, int32_t meterIdx,
|
||||||
int32_t groupIdx, SMeterQueryInfo *pMeterQueryInfo) {
|
int32_t groupIdx, TSKEY nextKey) {
|
||||||
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||||
int32_t GROUP_RES_ID = 1;
|
SWindowResInfo * pWindowResInfo = &pRuntimeEnv->windowResInfo;
|
||||||
|
int32_t GROUPRESULTID = 1;
|
||||||
|
|
||||||
SWindowResult *pWindowRes =
|
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&groupIdx, sizeof(groupIdx));
|
||||||
doSetTimeWindowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, (char *)&groupIdx, sizeof(groupIdx));
|
|
||||||
if (pWindowRes == NULL) {
|
if (pWindowRes == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
* 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) {
|
if (pWindowRes->pos.pageId == -1) {
|
||||||
int32_t ret =
|
if (addNewWindowResultBuf(pWindowRes, pRuntimeEnv->pResultBuf, GROUPRESULTID, pRuntimeEnv->numOfRowsPerPage) !=
|
||||||
addNewWindowResultBuf(pWindowRes, pRuntimeEnv->pResultBuf, GROUP_RES_ID, pRuntimeEnv->numOfRowsPerPage);
|
TSDB_CODE_SUCCESS) {
|
||||||
if (ret != 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7033,18 +7015,8 @@ void setExecutionContext(STableQuerySupportObj *pSupporter, SWindowResult *outpu
|
||||||
setWindowResOutputBuf(pRuntimeEnv, pWindowRes);
|
setWindowResOutputBuf(pRuntimeEnv, pWindowRes);
|
||||||
initCtxOutputBuf(pRuntimeEnv);
|
initCtxOutputBuf(pRuntimeEnv);
|
||||||
|
|
||||||
vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pSupporter->pMeterSidExtInfo[meterIdx]);
|
pMeterQueryInfo->lastKey = nextKey;
|
||||||
|
setAdditionalInfo(pSupporter, meterIdx, pMeterQueryInfo);
|
||||||
// set the right cursor position for ts buffer
|
|
||||||
if (pSupporter->runtimeEnv.pTSBuf != NULL) {
|
|
||||||
if (pMeterQueryInfo->cur.vnodeIndex == -1) {
|
|
||||||
pMeterQueryInfo->tag = pRuntimeEnv->pCtx[0].tag.i64Key;
|
|
||||||
|
|
||||||
tsBufGetElemStartPos(pSupporter->runtimeEnv.pTSBuf, 0, pMeterQueryInfo->tag);
|
|
||||||
} else {
|
|
||||||
tsBufSetCursor(pSupporter->runtimeEnv.pTSBuf, &pMeterQueryInfo->cur);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult) {
|
static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult) {
|
||||||
|
@ -7072,101 +7044,43 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *getOutputResPos(SQueryRuntimeEnv *pRuntimeEnv, tFilePage *pData, int32_t row, int32_t col) {
|
int32_t setAdditionalInfo(STableQuerySupportObj *pSupporter, int32_t meterIdx, SMeterQueryInfo *pMeterQueryInfo) {
|
||||||
// the output for each record should be less than the DEFAULT_INTERN_BUF_SIZE
|
|
||||||
assert(pRuntimeEnv->pCtx[col].outputBytes <= DEFAULT_INTERN_BUF_SIZE);
|
|
||||||
|
|
||||||
return (char *)pData->data + pRuntimeEnv->offset[col] * pRuntimeEnv->numOfRowsPerPage +
|
|
||||||
pRuntimeEnv->pCtx[col].outputBytes * row;
|
|
||||||
}
|
|
||||||
|
|
||||||
void validateTimestampForSupplementResult(SQueryRuntimeEnv *pRuntimeEnv, int64_t numOfIncrementRes) {
|
|
||||||
SQuery * pQuery = pRuntimeEnv->pQuery;
|
|
||||||
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
|
||||||
|
|
||||||
if (pRuntimeEnv->scanFlag == SUPPLEMENTARY_SCAN && numOfIncrementRes > 0) {
|
|
||||||
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
|
|
||||||
int32_t functionId = pQuery->pSelectExpr[i].pBase.functionId;
|
|
||||||
if (functionId == TSDB_FUNC_TS) {
|
|
||||||
assert(*(TSKEY *)pCtx[i].aOutputBuf == pCtx[i].nStartQueryTimestamp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t setOutputBufferForIntervalQuery(SQueryRuntimeEnv *pRuntimeEnv, SMeterQueryInfo *pMeterQueryInfo) {
|
|
||||||
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
|
||||||
SWindowResInfo * pWindowResInfo = &pMeterQueryInfo->windowResInfo;
|
|
||||||
|
|
||||||
STimeWindow win = getActiveTimeWindow(pWindowResInfo, pMeterQueryInfo->lastKey, pRuntimeEnv->pQuery);
|
|
||||||
|
|
||||||
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&win.skey, TSDB_KEYSIZE);
|
|
||||||
if (pWindowRes == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// not allocated yet, allocate new buffer
|
|
||||||
if (pWindowRes->pos.pageId == -1) {
|
|
||||||
int32_t ret = addNewWindowResultBuf(pWindowRes, pResultBuf, pMeterQueryInfo->sid, pRuntimeEnv->numOfRowsPerPage);
|
|
||||||
if (ret != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pWindowRes->window = win;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfOutputCols; ++i) {
|
|
||||||
pRuntimeEnv->pCtx[i].resultInfo = &pWindowRes->resultInfo[i];
|
|
||||||
pRuntimeEnv->pCtx[i].aOutputBuf = getPosInResultPage(pRuntimeEnv, i, pWindowRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t setIntervalQueryExecutionContext(STableQuerySupportObj *pSupporter, int32_t meterIdx,
|
|
||||||
SMeterQueryInfo *pMeterQueryInfo) {
|
|
||||||
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||||
assert(pMeterQueryInfo->lastKey > 0);
|
assert(pMeterQueryInfo->lastKey > 0);
|
||||||
|
|
||||||
// not enough disk space or memory buffer for intermediate results
|
|
||||||
if (setOutputBufferForIntervalQuery(pRuntimeEnv, pMeterQueryInfo) != TSDB_CODE_SUCCESS) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
initCtxOutputBuf(pRuntimeEnv);
|
|
||||||
vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pSupporter->pMeterSidExtInfo[meterIdx]);
|
vnodeSetTagValueInParam(pSupporter->pSidSet, pRuntimeEnv, pSupporter->pMeterSidExtInfo[meterIdx]);
|
||||||
|
|
||||||
// both the master and supplement scan needs to set the correct ts comp start position
|
// both the master and supplement scan needs to set the correct ts comp start position
|
||||||
if (pSupporter->runtimeEnv.pTSBuf != NULL) {
|
if (pRuntimeEnv->pTSBuf != NULL) {
|
||||||
if (pMeterQueryInfo->cur.vnodeIndex == -1) {
|
if (pMeterQueryInfo->cur.vnodeIndex == -1) {
|
||||||
pMeterQueryInfo->tag = pRuntimeEnv->pCtx[0].tag.i64Key;
|
pMeterQueryInfo->tag = pRuntimeEnv->pCtx[0].tag.i64Key;
|
||||||
|
|
||||||
tsBufGetElemStartPos(pSupporter->runtimeEnv.pTSBuf, 0, pMeterQueryInfo->tag);
|
tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, 0, pMeterQueryInfo->tag);
|
||||||
|
|
||||||
// keep the cursor info of current meter
|
// keep the cursor info of current meter
|
||||||
pMeterQueryInfo->cur = pSupporter->runtimeEnv.pTSBuf->cur;
|
pMeterQueryInfo->cur = pRuntimeEnv->pTSBuf->cur;
|
||||||
} else {
|
} else {
|
||||||
tsBufSetCursor(pSupporter->runtimeEnv.pTSBuf, &pMeterQueryInfo->cur);
|
tsBufSetCursor(pRuntimeEnv->pTSBuf, &pMeterQueryInfo->cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
//
|
||||||
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;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
assert((key >= pQuery->skey && QUERY_IS_ASC_QUERY(pQuery)) || (key <= pQuery->skey && !QUERY_IS_ASC_QUERY(pQuery)));
|
// assert((key >= pQuery->skey && QUERY_IS_ASC_QUERY(pQuery)) || (key <= pQuery->skey && !QUERY_IS_ASC_QUERY(pQuery)));
|
||||||
return key;
|
// return key;
|
||||||
}
|
//}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There are two cases to handle:
|
* There are two cases to handle:
|
||||||
|
@ -7227,14 +7141,6 @@ void setIntervalQueryRange(SMeterQueryInfo *pMeterQueryInfo, STableQuerySupportO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
win = getActiveTimeWindow(pWindowResInfo, pQuery->skey, pQuery);
|
|
||||||
SWindowResult *pWindowRes =
|
|
||||||
doSetTimeWindowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&pQuery->skey, TSDB_KEYSIZE);
|
|
||||||
if (pWindowRes == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pWindowRes->window = win;
|
|
||||||
pMeterQueryInfo->queryRangeSet = 1;
|
pMeterQueryInfo->queryRangeSet = 1;
|
||||||
pMeterQueryInfo->lastKey = pQuery->skey;
|
pMeterQueryInfo->lastKey = pQuery->skey;
|
||||||
pMeterQueryInfo->skey = pQuery->skey;
|
pMeterQueryInfo->skey = pQuery->skey;
|
||||||
|
@ -7297,7 +7203,7 @@ int32_t LoadDatablockOnDemand(SCompBlock *pBlock, SField **pFields, uint8_t *blk
|
||||||
if (((pQuery->lastKey <= pBlock->keyFirst && pQuery->ekey >= pBlock->keyLast && QUERY_IS_ASC_QUERY(pQuery)) ||
|
if (((pQuery->lastKey <= pBlock->keyFirst && pQuery->ekey >= pBlock->keyLast && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||||
(pQuery->ekey <= pBlock->keyFirst && pQuery->lastKey >= pBlock->keyLast && !QUERY_IS_ASC_QUERY(pQuery))) &&
|
(pQuery->ekey <= pBlock->keyFirst && pQuery->lastKey >= pBlock->keyLast && !QUERY_IS_ASC_QUERY(pQuery))) &&
|
||||||
onDemand) {
|
onDemand) {
|
||||||
int32_t req = 0;
|
uint32_t req = 0;
|
||||||
if (pQuery->numOfFilterCols > 0) {
|
if (pQuery->numOfFilterCols > 0) {
|
||||||
req = BLK_DATA_ALL_NEEDED;
|
req = BLK_DATA_ALL_NEEDED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -7369,9 +7275,8 @@ int32_t LoadDatablockOnDemand(SCompBlock *pBlock, SField **pFields, uint8_t *blk
|
||||||
|
|
||||||
/* find first qualified record position in this block */
|
/* find first qualified record position in this block */
|
||||||
if (loadTS) {
|
if (loadTS) {
|
||||||
/* find first qualified record position in this block */
|
pQuery->pos = searchFn((char *)primaryKeys, pBlock->numOfPoints, pQuery->lastKey, pQuery->order.order);
|
||||||
pQuery->pos =
|
|
||||||
searchFn(pRuntimeEnv->primaryColBuffer->data, pBlock->numOfPoints, pQuery->lastKey, pQuery->order.order);
|
|
||||||
/* boundary timestamp check */
|
/* boundary timestamp check */
|
||||||
assert(pBlock->keyFirst == primaryKeys[0] && pBlock->keyLast == primaryKeys[pBlock->numOfPoints - 1]);
|
assert(pBlock->keyFirst == primaryKeys[0] && pBlock->keyLast == primaryKeys[pBlock->numOfPoints - 1]);
|
||||||
}
|
}
|
||||||
|
@ -7394,20 +7299,6 @@ 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(STableQuerySupportObj *pSupporter, SMeterQueryInfo *pMeterQueryInfo) {
|
|
||||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
|
||||||
SQuery * pQuery = pSupporter->runtimeEnv.pQuery;
|
|
||||||
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
|
||||||
|
|
||||||
SIDList list = getDataBufPagesIdList(pResultBuf, pMeterQueryInfo->sid);
|
|
||||||
int32_t id = getLastPageId(&list);
|
|
||||||
|
|
||||||
tFilePage *newOutput = getResultBufferPageById(pResultBuf, id);
|
|
||||||
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
|
|
||||||
assert(pRuntimeEnv->pCtx[i].aOutputBuf - newOutput->data < DEFAULT_INTERN_BUF_SIZE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t getNumOfSubset(STableQuerySupportObj *pSupporter) {
|
static int32_t getNumOfSubset(STableQuerySupportObj *pSupporter) {
|
||||||
SQuery *pQuery = pSupporter->runtimeEnv.pQuery;
|
SQuery *pQuery = pSupporter->runtimeEnv.pQuery;
|
||||||
|
|
||||||
|
@ -7506,6 +7397,21 @@ void copyFromWindowResToSData(SQInfo *pQInfo, SWindowResult *result) {
|
||||||
assert(pQuery->pointsRead <= pQuery->pointsToRead);
|
assert(pQuery->pointsRead <= pQuery->pointsToRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv, SMeterDataInfo *pMeterDataInfo) {
|
||||||
|
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||||
|
|
||||||
|
// update the number of result for each, only update the number of rows for the corresponding window result.
|
||||||
|
if (pQuery->intervalTime == 0) {
|
||||||
|
int32_t g = pMeterDataInfo->groupIdx;
|
||||||
|
assert(pRuntimeEnv->windowResInfo.size > 0);
|
||||||
|
|
||||||
|
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, (char *)&g, sizeof(g));
|
||||||
|
if (pWindowRes->numOfRows == 0) {
|
||||||
|
pWindowRes->numOfRows = getNumOfResult(pRuntimeEnv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void stableApplyFunctionsOnBlock(STableQuerySupportObj *pSupporter, SMeterDataInfo *pMeterDataInfo,
|
void stableApplyFunctionsOnBlock(STableQuerySupportObj *pSupporter, SMeterDataInfo *pMeterDataInfo,
|
||||||
SBlockInfo *pBlockInfo, SField *pFields, __block_search_fn_t searchFn) {
|
SBlockInfo *pBlockInfo, SField *pFields, __block_search_fn_t searchFn) {
|
||||||
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||||
|
@ -7525,17 +7431,10 @@ void stableApplyFunctionsOnBlock(STableQuerySupportObj *pSupporter, SMeterDataIn
|
||||||
numOfRes = blockwiseApplyAllFunctions(pRuntimeEnv, forwardStep, pFields, pBlockInfo, pWindowResInfo, searchFn);
|
numOfRes = blockwiseApplyAllFunctions(pRuntimeEnv, forwardStep, pFields, pBlockInfo, pWindowResInfo, searchFn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the number of result for each
|
assert(numOfRes >= 0);
|
||||||
if (pQuery->intervalTime == 0) { // todo refactor
|
|
||||||
SWindowResInfo *p1 = &pRuntimeEnv->windowResInfo;
|
|
||||||
for (int32_t i = 0; i < p1->size; ++i) {
|
|
||||||
SWindowResult* pResult = getWindowResult(p1, i);
|
|
||||||
if (isWindowResClosed(p1, i) && pResult->numOfRows == 0) {
|
|
||||||
pResult->numOfRows = getNumOfResult(pRuntimeEnv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// todo merge refactor
|
||||||
|
updateWindowResNumOfRes(pRuntimeEnv, pMeterDataInfo);
|
||||||
updatelastkey(pQuery, pMeterQueryInfo);
|
updatelastkey(pQuery, pMeterQueryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo) {
|
||||||
SQuery * pQuery = &pQInfo->query;
|
SQuery * pQuery = &pQInfo->query;
|
||||||
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||||
SQueryRuntimeEnv * pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
|
SQueryRuntimeEnv * pRuntimeEnv = &pQInfo->pTableQuerySupporter->runtimeEnv;
|
||||||
|
@ -119,18 +119,18 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
||||||
pQInfo->pObj = pMeterObj;
|
pQInfo->pObj = pMeterObj;
|
||||||
pRuntimeEnv->pMeterObj = pMeterObj;
|
pRuntimeEnv->pMeterObj = pMeterObj;
|
||||||
|
|
||||||
if (pMeterInfo[k].pMeterQInfo == NULL) {
|
if (pMeterDataInfo[k].pMeterQInfo == NULL) {
|
||||||
pMeterInfo[k].pMeterQInfo =
|
pMeterDataInfo[k].pMeterQInfo =
|
||||||
createMeterQueryInfo(pSupporter, pMeterObj->sid, pSupporter->rawSKey, pSupporter->rawEKey);
|
createMeterQueryInfo(pSupporter, pMeterObj->sid, pSupporter->rawSKey, pSupporter->rawEKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMeterInfo[k].pMeterObj == NULL) { // no data in disk for this meter, set its pointer
|
if (pMeterDataInfo[k].pMeterObj == NULL) { // no data in disk for this meter, set its pointer
|
||||||
setMeterDataInfo(&pMeterInfo[k], pMeterObj, k, groupIdx);
|
setMeterDataInfo(&pMeterDataInfo[k], pMeterObj, k, groupIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pMeterInfo[k].meterOrderIdx == k && pMeterObj == pMeterInfo[k].pMeterObj);
|
assert(pMeterDataInfo[k].meterOrderIdx == k && pMeterObj == pMeterDataInfo[k].pMeterObj);
|
||||||
|
|
||||||
SMeterQueryInfo *pMeterQueryInfo = pMeterInfo[k].pMeterQInfo;
|
SMeterQueryInfo *pMeterQueryInfo = pMeterDataInfo[k].pMeterQInfo;
|
||||||
restoreIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
|
restoreIntervalQueryRange(pRuntimeEnv, pMeterQueryInfo);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -208,11 +208,10 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pQuery->intervalTime == 0) {
|
if (pQuery->intervalTime == 0) {
|
||||||
setExecutionContext(pSupporter, pRuntimeEnv->windowResInfo.pResult, k, pMeterInfo[k].groupIdx,
|
setExecutionContext(pSupporter, pMeterQueryInfo, k, pMeterDataInfo[k].groupIdx, key);
|
||||||
pMeterQueryInfo);
|
|
||||||
} else {
|
} else {
|
||||||
setIntervalQueryRange(pMeterQueryInfo, pSupporter, key);
|
setIntervalQueryRange(pMeterQueryInfo, pSupporter, key);
|
||||||
int32_t ret = setIntervalQueryExecutionContext(pSupporter, k, pMeterQueryInfo);
|
int32_t ret = setAdditionalInfo(pSupporter, k, pMeterQueryInfo);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
pQInfo->killed = 1;
|
pQInfo->killed = 1;
|
||||||
return;
|
return;
|
||||||
|
@ -224,14 +223,14 @@ static void queryOnMultiDataCache(SQInfo *pQInfo, SMeterDataInfo *pMeterInfo) {
|
||||||
|
|
||||||
// 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 = getBlockInfo(pRuntimeEnv);
|
||||||
|
|
||||||
dTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", fileId:%d, slot:%d, pos:%d, bstatus:%d",
|
dTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", fileId:%d, slot:%d, pos:%d, bstatus:%d",
|
||||||
GET_QINFO_ADDR(pQuery), binfo.keyFirst, binfo.keyLast, pQuery->fileId, pQuery->slot, pQuery->pos,
|
GET_QINFO_ADDR(pQuery), binfo.keyFirst, binfo.keyLast, pQuery->fileId, pQuery->slot, pQuery->pos,
|
||||||
pRuntimeEnv->blockStatus);
|
pRuntimeEnv->blockStatus);
|
||||||
|
|
||||||
totalBlocks++;
|
totalBlocks++;
|
||||||
stableApplyFunctionsOnBlock(pSupporter, &pMeterInfo[k], &binfo, NULL, searchFn);
|
stableApplyFunctionsOnBlock(pSupporter, &pMeterDataInfo[k], &binfo, NULL, searchFn);
|
||||||
|
|
||||||
if (ALL_CACHE_BLOCKS_CHECKED(pQuery)) {
|
if (ALL_CACHE_BLOCKS_CHECKED(pQuery)) {
|
||||||
break;
|
break;
|
||||||
|
@ -400,8 +399,8 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
||||||
|
|
||||||
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,
|
ret = LoadDatablockOnDemand(pBlock, &pInfoEx->pBlock.fields, &pRuntimeEnv->blockStatus, pRuntimeEnv, fileIdx,
|
||||||
fileIdx, pInfoEx->blockIndex, searchFn, ondemandLoad);
|
pInfoEx->blockIndex, searchFn, ondemandLoad);
|
||||||
if (ret != DISK_DATA_LOADED) {
|
if (ret != DISK_DATA_LOADED) {
|
||||||
pSummary->skippedFileBlocks++;
|
pSummary->skippedFileBlocks++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -425,14 +424,15 @@ static void queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMeterDataInfo
|
||||||
// if data block is not loaded, it must be the intermediate blocks
|
// if data block is not loaded, it must be the intermediate blocks
|
||||||
assert((pBlock->keyFirst >= pQuery->lastKey && pBlock->keyLast <= pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
assert((pBlock->keyFirst >= pQuery->lastKey && pBlock->keyLast <= pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
|
||||||
(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)));
|
||||||
|
nextKey = QUERY_IS_ASC_QUERY(pQuery)? pBlock->keyFirst:pBlock->keyLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pQuery->intervalTime == 0) {
|
if (pQuery->intervalTime == 0) {
|
||||||
setExecutionContext(pSupporter, pRuntimeEnv->windowResInfo.pResult, pOneMeterDataInfo->meterOrderIdx,
|
setExecutionContext(pSupporter, pMeterQueryInfo, pOneMeterDataInfo->meterOrderIdx, pOneMeterDataInfo->groupIdx,
|
||||||
pOneMeterDataInfo->groupIdx, pMeterQueryInfo);
|
nextKey);
|
||||||
} else /* if (pQuery->intervalTime > 0)*/ { // interval query
|
} else { // interval query
|
||||||
setIntervalQueryRange(pMeterQueryInfo, pSupporter, nextKey);
|
setIntervalQueryRange(pMeterQueryInfo, pSupporter, nextKey);
|
||||||
ret = setIntervalQueryExecutionContext(pSupporter, pOneMeterDataInfo->meterOrderIdx, pMeterQueryInfo);
|
ret = setAdditionalInfo(pSupporter, pOneMeterDataInfo->meterOrderIdx, pMeterQueryInfo);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
tfree(pReqMeterDataInfo); // error code has been set
|
tfree(pReqMeterDataInfo); // error code has been set
|
||||||
pQInfo->killed = 1;
|
pQInfo->killed = 1;
|
||||||
|
@ -849,7 +849,7 @@ static void doOrderedScan(SQInfo *pQInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupMeterQueryInfoForSupplementQuery(STableQuerySupportObj *pSupporter) {
|
static void setupMeterQueryInfoForSupplementQuery(STableQuerySupportObj *pSupporter) {
|
||||||
SQuery* pQuery = pSupporter->runtimeEnv.pQuery;
|
SQuery *pQuery = pSupporter->runtimeEnv.pQuery;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -1101,7 +1101,7 @@ static void vnodeSingleMeterIntervalMainLooper(STableQuerySupportObj *pSupporter
|
||||||
|
|
||||||
doFinalizeResult(pRuntimeEnv);
|
doFinalizeResult(pRuntimeEnv);
|
||||||
|
|
||||||
// int64_t maxOutput = getNumOfResult(pRuntimeEnv);
|
// int64_t maxOutput = getNumOfResult(pRuntimeEnv);
|
||||||
|
|
||||||
// here we can ignore the records in case of no interpolation
|
// here we can ignore the records in case of no interpolation
|
||||||
// todo handle offset, in case of top/bottom interval query
|
// todo handle offset, in case of top/bottom interval query
|
||||||
|
@ -1127,16 +1127,16 @@ static void vnodeSingleMeterIntervalMainLooper(STableQuerySupportObj *pSupporter
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /*
|
// /*
|
||||||
// * the scan limitation mechanism is upon here,
|
// * the scan limitation mechanism is upon here,
|
||||||
// * 1. since there is only one(k) record is generated in one scan operation
|
// * 1. since there is only one(k) record is generated in one scan operation
|
||||||
// * 2. remain space is not sufficient for next query output, abort
|
// * 2. remain space is not sufficient for next query output, abort
|
||||||
// */
|
// */
|
||||||
// if ((pQuery->pointsRead % pQuery->pointsToRead == 0 && pQuery->pointsRead != 0) ||
|
// if ((pQuery->pointsRead % pQuery->pointsToRead == 0 && pQuery->pointsRead != 0) ||
|
||||||
// ((pQuery->pointsRead + maxOutput) > pQuery->pointsToRead)) {
|
// ((pQuery->pointsRead + maxOutput) > pQuery->pointsToRead)) {
|
||||||
// setQueryStatus(pQuery, QUERY_RESBUF_FULL);
|
// setQueryStatus(pQuery, QUERY_RESBUF_FULL);
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1222,9 +1222,9 @@ void vnodeSingleTableQuery(SSchedMsg *pMsg) {
|
||||||
assert(pQInfo->refCount >= 1);
|
assert(pQInfo->refCount >= 1);
|
||||||
|
|
||||||
SQuery * pQuery = &pQInfo->query;
|
SQuery * pQuery = &pQInfo->query;
|
||||||
SMeterObj *pMeterObj = pQInfo->pObj;
|
SMeterObj * pMeterObj = pQInfo->pObj;
|
||||||
STableQuerySupportObj* pSupporter = pQInfo->pTableQuerySupporter;
|
STableQuerySupportObj *pSupporter = pQInfo->pTableQuerySupporter;
|
||||||
SQueryRuntimeEnv *pRuntimeEnv = &pSupporter->runtimeEnv;
|
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||||
|
|
||||||
assert(pRuntimeEnv->pMeterObj == pMeterObj);
|
assert(pRuntimeEnv->pMeterObj == pMeterObj);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue