support the sliding query [tbase-266]
This commit is contained in:
parent
f726178075
commit
c6b0d6b0f9
|
@ -62,7 +62,7 @@ static int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQ
|
||||||
static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnList* pIdList, int16_t bytes,
|
static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnList* pIdList, int16_t bytes,
|
||||||
int8_t type, char* fieldName);
|
int8_t type, char* fieldName);
|
||||||
static int32_t changeFunctionID(int32_t optr, int16_t* functionId);
|
static int32_t changeFunctionID(int32_t optr, int16_t* functionId);
|
||||||
static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isMetric);
|
static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable);
|
||||||
|
|
||||||
static bool validateIpAddress(const char* ip, size_t size);
|
static bool validateIpAddress(const char* ip, size_t size);
|
||||||
static bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo);
|
static bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo);
|
||||||
|
@ -93,6 +93,8 @@ static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
|
||||||
|
|
||||||
static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
|
static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
|
||||||
static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo);
|
static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo);
|
||||||
|
static bool hasDefaultQueryTimeRange(SQueryInfo *pQueryInfo);
|
||||||
|
|
||||||
static void updateTagColumnIndex(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
static void updateTagColumnIndex(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||||
|
|
||||||
static int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t index, SQuerySQL* pQuerySql, SSqlObj* pSql);
|
static int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t index, SQuerySQL* pQuerySql, SSqlObj* pSql);
|
||||||
|
@ -4432,8 +4434,6 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
|
||||||
const char* msg1 = "slimit/soffset only available for STable query";
|
const char* msg1 = "slimit/soffset only available for STable query";
|
||||||
const char* msg2 = "function not supported on table";
|
const char* msg2 = "function not supported on table";
|
||||||
const char* msg3 = "slimit/soffset can not apply to projection query";
|
const char* msg3 = "slimit/soffset can not apply to projection query";
|
||||||
const char* msg4 = "projection on super table requires order by clause along with limitation";
|
|
||||||
const char* msg5 = "ordered projection result too large";
|
|
||||||
|
|
||||||
// handle the limit offset value, validate the limit
|
// handle the limit offset value, validate the limit
|
||||||
pQueryInfo->limit = pQuerySql->limit;
|
pQueryInfo->limit = pQuerySql->limit;
|
||||||
|
@ -5542,28 +5542,6 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set sliding value
|
|
||||||
SSQLToken* pSliding = &pQuerySql->sliding;
|
|
||||||
if (pSliding->n != 0) {
|
|
||||||
if (!tscEmbedded && pCmd->inStream == 0) { // sliding only allowed in stream
|
|
||||||
const char* msg = "not support sliding in query";
|
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
getTimestampInUsFromStr(pSliding->z, pSliding->n, &pQueryInfo->nSlidingTime);
|
|
||||||
if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) {
|
|
||||||
pQueryInfo->nSlidingTime /= 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pQueryInfo->nSlidingTime < tsMinSlidingTime) {
|
|
||||||
return invalidSqlErrMsg(pQueryInfo->msg, msg3);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pQueryInfo->nSlidingTime > pQueryInfo->nAggTimeInterval) {
|
|
||||||
return invalidSqlErrMsg(pQueryInfo->msg, msg4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set order by info
|
// set order by info
|
||||||
if (parseOrderbyClause(pQueryInfo, pQuerySql, tsGetSchema(pMeterMetaInfo->pMeterMeta)) != TSDB_CODE_SUCCESS) {
|
if (parseOrderbyClause(pQueryInfo, pQuerySql, tsGetSchema(pMeterMetaInfo->pMeterMeta)) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
@ -5602,6 +5580,30 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
if (!hasTimestampForPointInterpQuery(pQueryInfo)) {
|
if (!hasTimestampForPointInterpQuery(pQueryInfo)) {
|
||||||
return invalidSqlErrMsg(pQueryInfo->msg, msg2);
|
return invalidSqlErrMsg(pQueryInfo->msg, msg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set sliding value, the query time range needs to be decide in the first place
|
||||||
|
SSQLToken* pSliding = &pQuerySql->sliding;
|
||||||
|
if (pSliding->n != 0) {
|
||||||
|
if (!tscEmbedded && pCmd->inStream == 0 && hasDefaultQueryTimeRange(pQueryInfo)) { // sliding only allowed in stream
|
||||||
|
const char* msg = "time range expected for sliding window query";
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
getTimestampInUsFromStr(pSliding->z, pSliding->n, &pQueryInfo->nSlidingTime);
|
||||||
|
if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) {
|
||||||
|
pQueryInfo->nSlidingTime /= 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pQueryInfo->nSlidingTime < tsMinSlidingTime) {
|
||||||
|
return invalidSqlErrMsg(pQueryInfo->msg, msg3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pQueryInfo->nSlidingTime > pQueryInfo->nAggTimeInterval) {
|
||||||
|
return invalidSqlErrMsg(pQueryInfo->msg, msg4);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pQueryInfo->nSlidingTime = -1;
|
||||||
|
}
|
||||||
|
|
||||||
// in case of join query, time range is required.
|
// in case of join query, time range is required.
|
||||||
if (QUERY_IS_JOIN_QUERY(pQueryInfo->type)) {
|
if (QUERY_IS_JOIN_QUERY(pQueryInfo->type)) {
|
||||||
|
@ -5651,3 +5653,8 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS; // Does not build query message here
|
return TSDB_CODE_SUCCESS; // Does not build query message here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasDefaultQueryTimeRange(SQueryInfo *pQueryInfo) {
|
||||||
|
return (pQueryInfo->stime == 0 && pQueryInfo->etime == INT64_MAX) ||
|
||||||
|
(pQueryInfo->stime == INT64_MAX && pQueryInfo->etime == 0);
|
||||||
|
}
|
|
@ -260,6 +260,7 @@ typedef struct SQuery {
|
||||||
TSKEY skey;
|
TSKEY skey;
|
||||||
TSKEY ekey;
|
TSKEY ekey;
|
||||||
int64_t nAggTimeInterval;
|
int64_t nAggTimeInterval;
|
||||||
|
int64_t slidingTime; // sliding time for sliding window query
|
||||||
char intervalTimeUnit; // interval data type, used for daytime revise
|
char intervalTimeUnit; // interval data type, used for daytime revise
|
||||||
int8_t precision;
|
int8_t precision;
|
||||||
int16_t numOfOutputCols;
|
int16_t numOfOutputCols;
|
||||||
|
|
|
@ -64,7 +64,7 @@ typedef enum {
|
||||||
* the next query.
|
* the next query.
|
||||||
*
|
*
|
||||||
* this status is only exist in group-by clause and
|
* this status is only exist in group-by clause and
|
||||||
* diff/add/division/mulitply/ query.
|
* diff/add/division/multiply/ query.
|
||||||
*/
|
*/
|
||||||
QUERY_RESBUF_FULL = 0x2,
|
QUERY_RESBUF_FULL = 0x2,
|
||||||
|
|
||||||
|
@ -149,7 +149,6 @@ 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(SMeterQuerySupportObj* pSupporter, SQuery* pQuery);
|
||||||
void moveDescOrderResultsToFront(SQueryRuntimeEnv* pRuntimeEnv);
|
|
||||||
|
|
||||||
void doSkipResults(SQueryRuntimeEnv* pRuntimeEnv);
|
void doSkipResults(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv);
|
void doFinalizeResult(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
|
@ -159,7 +158,7 @@ void forwardIntervalQueryRange(SMeterQuerySupportObj* pSupporter, SQueryRuntimeE
|
||||||
void forwardQueryStartPosition(SQueryRuntimeEnv* pRuntimeEnv);
|
void forwardQueryStartPosition(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
|
|
||||||
bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, SMeterQuerySupportObj* pSupporter,
|
bool normalizedFirstQueryRange(bool dataInDisk, bool dataInCache, SMeterQuerySupportObj* pSupporter,
|
||||||
SPointInterpoSupporter* pPointInterpSupporter);
|
SPointInterpoSupporter* pPointInterpSupporter, int64_t* key);
|
||||||
|
|
||||||
void pointInterpSupporterInit(SQuery* pQuery, SPointInterpoSupporter* pInterpoSupport);
|
void pointInterpSupporterInit(SQuery* pQuery, SPointInterpoSupporter* pInterpoSupport);
|
||||||
void pointInterpSupporterDestroy(SPointInterpoSupporter* pPointInterpSupport);
|
void pointInterpSupporterDestroy(SPointInterpoSupporter* pPointInterpSupport);
|
||||||
|
@ -278,6 +277,11 @@ void displayInterResult(SData** pdata, SQuery* pQuery, int32_t numOfRows);
|
||||||
void vnodePrintQueryStatistics(SMeterQuerySupportObj* pSupporter);
|
void vnodePrintQueryStatistics(SMeterQuerySupportObj* pSupporter);
|
||||||
|
|
||||||
void clearGroupResultBuf(SOutputRes* pOneOutputRes, int32_t nOutputCols);
|
void clearGroupResultBuf(SOutputRes* pOneOutputRes, int32_t nOutputCols);
|
||||||
|
void copyGroupResultBuf(SOutputRes* dst, const SOutputRes* src, int32_t nOutputCols);
|
||||||
|
|
||||||
|
void resetResWindowInfo(SSlidingWindowResInfo* pWindowResInfo, int32_t numOfCols);
|
||||||
|
void clearCompletedResWindows(SSlidingWindowResInfo* pWindowResInfo, int32_t numOfCols);
|
||||||
|
int32_t numOfResFromResWindowInfo(SSlidingWindowResInfo* pWindowResInfo);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,31 @@ typedef struct SQueryFilesInfo {
|
||||||
char dbFilePathPrefix[PATH_MAX];
|
char dbFilePathPrefix[PATH_MAX];
|
||||||
} SQueryFilesInfo;
|
} SQueryFilesInfo;
|
||||||
|
|
||||||
typedef struct RuntimeEnvironment {
|
typedef struct STimeWindow {
|
||||||
|
TSKEY skey;
|
||||||
|
TSKEY ekey;
|
||||||
|
} STimeWindow;
|
||||||
|
|
||||||
|
typedef struct SWindowStatus {
|
||||||
|
STimeWindow window;
|
||||||
|
bool closed;
|
||||||
|
} SWindowStatus;
|
||||||
|
|
||||||
|
typedef struct SSlidingWindowResInfo {
|
||||||
|
SOutputRes* pResult; // reference to SQuerySupporter->pResult
|
||||||
|
SWindowStatus* pStatus; // current query window closed or not?
|
||||||
|
void* hashList; // hash list for quick access
|
||||||
|
int16_t type; // data type for hash key
|
||||||
|
int32_t capacity; // max capacity
|
||||||
|
int32_t curIndex; // current start active index
|
||||||
|
int32_t size;
|
||||||
|
|
||||||
|
int64_t startTime; // start time of the first time window for sliding query
|
||||||
|
int64_t prevSKey; // previous (not completed) sliding window start key
|
||||||
|
int64_t threshold; // threshold for return completed results.
|
||||||
|
} SSlidingWindowResInfo;
|
||||||
|
|
||||||
|
typedef struct SQueryRuntimeEnv {
|
||||||
SPositionInfo startPos; /* the start position, used for secondary/third iteration */
|
SPositionInfo startPos; /* the start position, used for secondary/third iteration */
|
||||||
SPositionInfo endPos; /* the last access position in query, served as the start pos of reversed order query */
|
SPositionInfo endPos; /* the last access position in query, served as the start pos of reversed order query */
|
||||||
SPositionInfo nextPos; /* start position of the next scan */
|
SPositionInfo nextPos; /* start position of the next scan */
|
||||||
|
@ -134,13 +158,16 @@ typedef struct RuntimeEnvironment {
|
||||||
int16_t scanFlag; // denotes reversed scan of data or not
|
int16_t scanFlag; // denotes reversed scan of data or not
|
||||||
SInterpolationInfo interpoInfo;
|
SInterpolationInfo interpoInfo;
|
||||||
SData** pInterpoBuf;
|
SData** pInterpoBuf;
|
||||||
SOutputRes* pResult; // reference to SQuerySupporter->pResult
|
|
||||||
void* hashList;
|
SSlidingWindowResInfo swindowResInfo;
|
||||||
int32_t usedIndex; // assigned SOutputRes in list
|
|
||||||
STSBuf* pTSBuf;
|
STSBuf* pTSBuf;
|
||||||
STSCursor cur;
|
STSCursor cur;
|
||||||
SQueryCostSummary summary;
|
SQueryCostSummary summary;
|
||||||
|
|
||||||
|
TSKEY intervalSKey; // skey of the complete time window, not affected by the actual data distribution
|
||||||
|
TSKEY intervalEKey; // ekey of the complete time window
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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 cacheblock info from pMeterObj, simple because it may change anytime
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -535,7 +535,7 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start
|
||||||
SPointInterpoSupporter pointInterpSupporter = {0};
|
SPointInterpoSupporter pointInterpSupporter = {0};
|
||||||
pointInterpSupporterInit(pQuery, &pointInterpSupporter);
|
pointInterpSupporterInit(pQuery, &pointInterpSupporter);
|
||||||
|
|
||||||
if (!normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, &pointInterpSupporter)) {
|
if (!normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, &pointInterpSupporter, NULL)) {
|
||||||
pointInterpSupporterDestroy(&pointInterpSupporter);
|
pointInterpSupporterDestroy(&pointInterpSupporter);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -666,19 +666,10 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
|
||||||
if (pSupporter->meterIdx >= pSids->numOfSids) {
|
if (pSupporter->meterIdx >= pSids->numOfSids) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < pRuntimeEnv->usedIndex; ++i) {
|
resetResWindowInfo(&pRuntimeEnv->swindowResInfo, pQuery->numOfOutputCols);
|
||||||
SOutputRes *pOneRes = &pRuntimeEnv->pResult[i];
|
|
||||||
clearGroupResultBuf(pOneRes, pQuery->numOfOutputCols);
|
while (pSupporter->meterIdx < pSupporter->numOfMeters) {
|
||||||
}
|
|
||||||
|
|
||||||
pRuntimeEnv->usedIndex = 0;
|
|
||||||
taosCleanUpHashTable(pRuntimeEnv->hashList);
|
|
||||||
|
|
||||||
int32_t primeHashSlot = 10039;
|
|
||||||
pRuntimeEnv->hashList = taosInitHashTable(primeHashSlot, taosIntHash_32, false);
|
|
||||||
|
|
||||||
while (pSupporter->meterIdx < pSupporter->numOfMeters) {
|
|
||||||
int32_t k = pSupporter->meterIdx;
|
int32_t k = pSupporter->meterIdx;
|
||||||
|
|
||||||
if (isQueryKilled(pQuery)) {
|
if (isQueryKilled(pQuery)) {
|
||||||
|
@ -703,7 +694,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SPointInterpoSupporter pointInterpSupporter = {0};
|
SPointInterpoSupporter pointInterpSupporter = {0};
|
||||||
if (normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, &pointInterpSupporter) == false) {
|
if (normalizedFirstQueryRange(dataInDisk, dataInCache, pSupporter, &pointInterpSupporter, NULL) == false) {
|
||||||
pQuery->skey = pSupporter->rawSKey;
|
pQuery->skey = pSupporter->rawSKey;
|
||||||
pQuery->ekey = pSupporter->rawEKey;
|
pQuery->ekey = pSupporter->rawEKey;
|
||||||
|
|
||||||
|
@ -778,8 +769,10 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
||||||
for (int32_t i = 0; i < pRuntimeEnv->usedIndex; ++i) {
|
SSlidingWindowResInfo* pWindowResInfo = &pRuntimeEnv->swindowResInfo;
|
||||||
SOutputRes *buf = &pRuntimeEnv->pResult[i];
|
|
||||||
|
for (int32_t i = 0; i < pWindowResInfo->size; ++i) {
|
||||||
|
SOutputRes *buf = &pWindowResInfo->pResult[i];
|
||||||
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
|
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
|
||||||
buf->numOfRows = MAX(buf->numOfRows, buf->resultInfo[j].numOfRes);
|
buf->numOfRows = MAX(buf->numOfRows, buf->resultInfo[j].numOfRes);
|
||||||
}
|
}
|
||||||
|
@ -787,14 +780,12 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
|
||||||
|
|
||||||
pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
|
pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
|
||||||
pQuery->pointsRead = 0;
|
pQuery->pointsRead = 0;
|
||||||
copyFromGroupBuf(pQInfo, pRuntimeEnv->pResult);
|
copyFromGroupBuf(pQInfo, pWindowResInfo->pResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
pQInfo->pointsRead += pQuery->pointsRead;
|
pQInfo->pointsRead += pQuery->pointsRead;
|
||||||
pQuery->pointsOffset = pQuery->pointsToRead;
|
pQuery->pointsOffset = pQuery->pointsToRead;
|
||||||
|
|
||||||
moveDescOrderResultsToFront(pRuntimeEnv);
|
|
||||||
|
|
||||||
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,
|
||||||
|
@ -982,12 +973,11 @@ static void vnodeSingleMeterFixedOutputProcessor(SQInfo *pQInfo) {
|
||||||
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
|
||||||
pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
|
pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
|
||||||
pQuery->pointsRead = 0;
|
pQuery->pointsRead = 0;
|
||||||
copyFromGroupBuf(pQInfo, pRuntimeEnv->pResult);
|
copyFromGroupBuf(pQInfo, pRuntimeEnv->swindowResInfo.pResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
doSkipResults(pRuntimeEnv);
|
doSkipResults(pRuntimeEnv);
|
||||||
doRevisedResultsByLimit(pQInfo);
|
doRevisedResultsByLimit(pQInfo);
|
||||||
moveDescOrderResultsToFront(pRuntimeEnv);
|
|
||||||
|
|
||||||
pQInfo->pointsRead = pQuery->pointsRead;
|
pQInfo->pointsRead = pQuery->pointsRead;
|
||||||
}
|
}
|
||||||
|
@ -1034,8 +1024,6 @@ static void vnodeSingleMeterMultiOutputProcessor(SQInfo *pQInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
doRevisedResultsByLimit(pQInfo);
|
doRevisedResultsByLimit(pQInfo);
|
||||||
moveDescOrderResultsToFront(pRuntimeEnv);
|
|
||||||
|
|
||||||
pQInfo->pointsRead += pQuery->pointsRead;
|
pQInfo->pointsRead += pQuery->pointsRead;
|
||||||
|
|
||||||
if (Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL)) {
|
if (Q_STATUS_EQUAL(pQuery->over, QUERY_RESBUF_FULL)) {
|
||||||
|
@ -1063,7 +1051,8 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
|
||||||
(pQuery->skey >= pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery)));
|
(pQuery->skey >= pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery)));
|
||||||
|
|
||||||
initCtxOutputBuf(pRuntimeEnv);
|
initCtxOutputBuf(pRuntimeEnv);
|
||||||
|
clearCompletedResWindows(&pRuntimeEnv->swindowResInfo, pQuery->numOfOutputCols);
|
||||||
|
|
||||||
vnodeScanAllData(pRuntimeEnv);
|
vnodeScanAllData(pRuntimeEnv);
|
||||||
if (isQueryKilled(pQuery)) {
|
if (isQueryKilled(pQuery)) {
|
||||||
return;
|
return;
|
||||||
|
@ -1094,7 +1083,7 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
|
||||||
}
|
}
|
||||||
|
|
||||||
forwardIntervalQueryRange(pSupporter, pRuntimeEnv);
|
forwardIntervalQueryRange(pSupporter, pRuntimeEnv);
|
||||||
if (Q_STATUS_EQUAL(pQuery->over, QUERY_COMPLETED)) {
|
if (Q_STATUS_EQUAL(pQuery->over, QUERY_COMPLETED|QUERY_RESBUF_FULL)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1133,17 +1122,8 @@ static void vnodeSingleMeterIntervalProcessor(SQInfo *pQInfo) {
|
||||||
taosInterpoSetStartInfo(&pRuntimeEnv->interpoInfo, pQuery->pointsRead, pQuery->interpoType);
|
taosInterpoSetStartInfo(&pRuntimeEnv->interpoInfo, pQuery->pointsRead, pQuery->interpoType);
|
||||||
SData **pInterpoBuf = pRuntimeEnv->pInterpoBuf;
|
SData **pInterpoBuf = pRuntimeEnv->pInterpoBuf;
|
||||||
|
|
||||||
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
|
||||||
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
|
memcpy(pInterpoBuf[i]->data, pQuery->sdata[i]->data, pQuery->pointsRead * pQuery->pSelectExpr[i].resBytes);
|
||||||
memcpy(pInterpoBuf[i]->data, pQuery->sdata[i]->data, pQuery->pointsRead * pQuery->pSelectExpr[i].resBytes);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int32_t size = pMeterObj->pointsPerFileBlock;
|
|
||||||
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
|
|
||||||
memcpy(pInterpoBuf[i]->data,
|
|
||||||
pQuery->sdata[i]->data + (size - pQuery->pointsRead) * pQuery->pSelectExpr[i].resBytes,
|
|
||||||
pQuery->pointsRead * pQuery->pSelectExpr[i].resBytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
numOfInterpo = 0;
|
numOfInterpo = 0;
|
||||||
|
@ -1160,12 +1140,16 @@ static void vnodeSingleMeterIntervalProcessor(SQInfo *pQInfo) {
|
||||||
pQuery->pointsRead = 0;
|
pQuery->pointsRead = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isGroupbyNormalCol(pQuery->pGroupbyExpr) || (pQuery->slidingTime > 0 && pQuery->nAggTimeInterval > 0)) {
|
||||||
|
pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
|
||||||
|
pQuery->pointsRead = 0;
|
||||||
|
copyFromGroupBuf(pQInfo, pRuntimeEnv->swindowResInfo.pResult);
|
||||||
|
}
|
||||||
|
|
||||||
pQInfo->pointsRead += pQuery->pointsRead;
|
pQInfo->pointsRead += pQuery->pointsRead;
|
||||||
pQInfo->pointsInterpo += numOfInterpo;
|
pQInfo->pointsInterpo += numOfInterpo;
|
||||||
|
|
||||||
// moveDescOrderResultsToFront(pRuntimeEnv);
|
|
||||||
|
|
||||||
dTrace("%p vid:%d sid:%d id:%s, %d points returned %d points interpo, totalRead:%d totalInterpo:%d totalReturn:%d",
|
dTrace("%p vid:%d sid:%d id:%s, %d points returned %d points interpo, totalRead:%d totalInterpo:%d totalReturn:%d",
|
||||||
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead, numOfInterpo,
|
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead, numOfInterpo,
|
||||||
pQInfo->pointsRead - pQInfo->pointsInterpo, pQInfo->pointsInterpo, pQInfo->pointsReturned);
|
pQInfo->pointsRead - pQInfo->pointsInterpo, pQInfo->pointsInterpo, pQInfo->pointsReturned);
|
||||||
|
@ -1209,7 +1193,6 @@ void vnodeSingleMeterQuery(SSchedMsg *pMsg) {
|
||||||
(tFilePage **)pRuntimeEnv->pInterpoBuf, remain, &numOfInterpo);
|
(tFilePage **)pRuntimeEnv->pInterpoBuf, remain, &numOfInterpo);
|
||||||
|
|
||||||
doRevisedResultsByLimit(pQInfo);
|
doRevisedResultsByLimit(pQInfo);
|
||||||
moveDescOrderResultsToFront(pRuntimeEnv);
|
|
||||||
|
|
||||||
pQInfo->pointsInterpo += numOfInterpo;
|
pQInfo->pointsInterpo += numOfInterpo;
|
||||||
pQInfo->pointsRead += pQuery->pointsRead;
|
pQInfo->pointsRead += pQuery->pointsRead;
|
||||||
|
|
|
@ -267,6 +267,7 @@ static SQInfo *vnodeAllocateQInfoEx(SQueryMeterMsg *pQueryMsg, SSqlGroupbyExpr *
|
||||||
|
|
||||||
pQuery->pGroupbyExpr = pGroupbyExpr;
|
pQuery->pGroupbyExpr = pGroupbyExpr;
|
||||||
pQuery->nAggTimeInterval = pQueryMsg->nAggTimeInterval;
|
pQuery->nAggTimeInterval = pQueryMsg->nAggTimeInterval;
|
||||||
|
pQuery->slidingTime = pQueryMsg->slidingTime;
|
||||||
pQuery->interpoType = pQueryMsg->interpoType;
|
pQuery->interpoType = pQueryMsg->interpoType;
|
||||||
pQuery->intervalTimeUnit = pQueryMsg->intervalTimeUnit;
|
pQuery->intervalTimeUnit = pQueryMsg->intervalTimeUnit;
|
||||||
|
|
||||||
|
@ -966,6 +967,8 @@ int32_t vnodeConvertQueryMeterMsg(SQueryMeterMsg *pQueryMsg) {
|
||||||
pQueryMsg->queryType = htons(pQueryMsg->queryType);
|
pQueryMsg->queryType = htons(pQueryMsg->queryType);
|
||||||
|
|
||||||
pQueryMsg->nAggTimeInterval = htobe64(pQueryMsg->nAggTimeInterval);
|
pQueryMsg->nAggTimeInterval = htobe64(pQueryMsg->nAggTimeInterval);
|
||||||
|
pQueryMsg->slidingTime = htobe64(pQueryMsg->slidingTime);
|
||||||
|
|
||||||
pQueryMsg->numOfTagsCols = htons(pQueryMsg->numOfTagsCols);
|
pQueryMsg->numOfTagsCols = htons(pQueryMsg->numOfTagsCols);
|
||||||
pQueryMsg->numOfCols = htons(pQueryMsg->numOfCols);
|
pQueryMsg->numOfCols = htons(pQueryMsg->numOfCols);
|
||||||
pQueryMsg->numOfOutputCols = htons(pQueryMsg->numOfOutputCols);
|
pQueryMsg->numOfOutputCols = htons(pQueryMsg->numOfOutputCols);
|
||||||
|
|
|
@ -423,7 +423,8 @@ void taosDeleteFromHashTable(HashObj *pObj, const char *key, uint32_t keyLen) {
|
||||||
__wr_lock(&pObj->lock);
|
__wr_lock(&pObj->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashNode *pNode = doGetNodeFromHashTable(pObj, key, keyLen, NULL);
|
uint32_t val = 0;
|
||||||
|
SHashNode *pNode = doGetNodeFromHashTable(pObj, key, keyLen, &val);
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
if (pObj->multithreadSafe) {
|
if (pObj->multithreadSafe) {
|
||||||
__unlock(&pObj->lock);
|
__unlock(&pObj->lock);
|
||||||
|
@ -434,7 +435,12 @@ void taosDeleteFromHashTable(HashObj *pObj, const char *key, uint32_t keyLen) {
|
||||||
|
|
||||||
SHashNode *pNext = pNode->next;
|
SHashNode *pNext = pNode->next;
|
||||||
if (pNode->prev != NULL) {
|
if (pNode->prev != NULL) {
|
||||||
pNode->prev->next = pNext;
|
int32_t slot = HASH_INDEX(val, pObj->capacity);
|
||||||
|
if (pObj->hashList[slot]->next == pNode) {
|
||||||
|
pObj->hashList[slot]->next = pNext;
|
||||||
|
} else {
|
||||||
|
pNode->prev->next = pNext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pNext != NULL) {
|
if (pNext != NULL) {
|
||||||
|
|
|
@ -93,6 +93,7 @@ uint32_t taosIntHash_64(const char *key, uint32_t UNUSED_PARAM(len)) {
|
||||||
_hash_fn_t taosGetDefaultHashFunction(int32_t type) {
|
_hash_fn_t taosGetDefaultHashFunction(int32_t type) {
|
||||||
_hash_fn_t fn = NULL;
|
_hash_fn_t fn = NULL;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDB_DATA_TYPE_BIGINT: fn = taosIntHash_64;break;
|
case TSDB_DATA_TYPE_BIGINT: fn = taosIntHash_64;break;
|
||||||
case TSDB_DATA_TYPE_BINARY: fn = MurmurHash3_32;break;
|
case TSDB_DATA_TYPE_BINARY: fn = MurmurHash3_32;break;
|
||||||
case TSDB_DATA_TYPE_INT: fn = taosIntHash_32; break;
|
case TSDB_DATA_TYPE_INT: fn = taosIntHash_32; break;
|
||||||
|
|
|
@ -37,7 +37,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t timeRange, char
|
||||||
* here we revised the start time of day according to the local time zone,
|
* here we revised the start time of day according to the local time zone,
|
||||||
* but in case of DST, the start time of one day need to be dynamically decided.
|
* but in case of DST, the start time of one day need to be dynamically decided.
|
||||||
*
|
*
|
||||||
* TODO dynmaically decide the start time of a day
|
* TODO dynamically decide the start time of a day
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(WINDOWS) && _MSC_VER >= 1900
|
#if defined(WINDOWS) && _MSC_VER >= 1900
|
||||||
|
@ -94,7 +94,7 @@ void taosInterpoSetStartInfo(SInterpolationInfo* pInterpoInfo, int32_t numOfRawD
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInterpoInfo->rowIdx = INTERPOL_IS_ASC_INTERPOL(pInterpoInfo) ? 0 : numOfRawDataInRows - 1;
|
pInterpoInfo->rowIdx = 0;//INTERPOL_IS_ASC_INTERPOL(pInterpoInfo) ? 0 : numOfRawDataInRows - 1;
|
||||||
pInterpoInfo->numOfRawDataInRows = numOfRawDataInRows;
|
pInterpoInfo->numOfRawDataInRows = numOfRawDataInRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,14 +118,14 @@ int32_t taosGetNumOfResWithoutLimit(SInterpolationInfo* pInterpoInfo, int64_t* p
|
||||||
if (numOfAvailRawData > 0) {
|
if (numOfAvailRawData > 0) {
|
||||||
int32_t finalNumOfResult = 0;
|
int32_t finalNumOfResult = 0;
|
||||||
|
|
||||||
if (pInterpoInfo->order == TSQL_SO_ASC) {
|
// if (pInterpoInfo->order == TSQL_SO_ASC) {
|
||||||
// get last timestamp, calculate the result size
|
// get last timestamp, calculate the result size
|
||||||
int64_t lastKey = pPrimaryKeyArray[pInterpoInfo->numOfRawDataInRows - 1];
|
int64_t lastKey = pPrimaryKeyArray[pInterpoInfo->numOfRawDataInRows - 1];
|
||||||
finalNumOfResult = (int32_t)((lastKey - pInterpoInfo->startTimestamp) / nInterval) + 1;
|
finalNumOfResult = (int32_t)(labs(lastKey - pInterpoInfo->startTimestamp) / nInterval) + 1;
|
||||||
} else { // todo error less than one!!!
|
// } else { // todo error less than one!!!
|
||||||
TSKEY lastKey = pPrimaryKeyArray[0];
|
// TSKEY lastKey = pPrimaryKeyArray[0];
|
||||||
finalNumOfResult = (int32_t)((pInterpoInfo->startTimestamp - lastKey) / nInterval) + 1;
|
// finalNumOfResult = (int32_t)((pInterpoInfo->startTimestamp - lastKey) / nInterval) + 1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
assert(finalNumOfResult >= numOfAvailRawData);
|
assert(finalNumOfResult >= numOfAvailRawData);
|
||||||
return finalNumOfResult;
|
return finalNumOfResult;
|
||||||
|
@ -198,11 +198,11 @@ int taosDoLinearInterpolation(int32_t type, SPoint* point1, SPoint* point2, SPoi
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* getPos(char* data, int32_t bytes, int32_t order, int32_t capacity, int32_t index) {
|
static char* getPos(char* data, int32_t bytes, int32_t order, int32_t capacity, int32_t index) {
|
||||||
if (order == TSQL_SO_ASC) {
|
// if (order == TSQL_SO_ASC) {
|
||||||
return data + index * bytes;
|
return data + index * bytes;
|
||||||
} else {
|
// } else {
|
||||||
return data + (capacity - index - 1) * bytes;
|
// return data + (capacity - index - 1) * bytes;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTagsValueInInterpolation(tFilePage** data, char** pTags, tColModel* pModel, int32_t order, int32_t start,
|
static void setTagsValueInInterpolation(tFilePage** data, char** pTags, tColModel* pModel, int32_t order, int32_t start,
|
||||||
|
@ -397,7 +397,7 @@ int32_t taosDoInterpoResult(SInterpolationInfo* pInterpoInfo, int16_t interpoTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
pInterpoInfo->startTimestamp += (nInterval * step);
|
pInterpoInfo->startTimestamp += (nInterval * step);
|
||||||
pInterpoInfo->rowIdx += step;
|
pInterpoInfo->rowIdx += 1;
|
||||||
num += 1;
|
num += 1;
|
||||||
|
|
||||||
if ((pInterpoInfo->rowIdx >= pInterpoInfo->numOfRawDataInRows && INTERPOL_IS_ASC_INTERPOL(pInterpoInfo)) ||
|
if ((pInterpoInfo->rowIdx >= pInterpoInfo->numOfRawDataInRows && INTERPOL_IS_ASC_INTERPOL(pInterpoInfo)) ||
|
||||||
|
|
Loading…
Reference in New Issue