diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 960cc7d7251d95c37e7011e68bc47b0c6ae012e0..965a548d26429432ac45d3e05376e61e02f72cc3 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -105,7 +105,10 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in return startTime; } - int64_t start = ((startTime - intervalTime) / slidingTime + 1) * slidingTime; + int64_t delta = startTime - intervalTime; + int32_t factor = delta > 0? 1:-1; + + int64_t start = (delta / slidingTime + factor) * slidingTime; if (!(timeUnit == 'u' || timeUnit == 'a' || timeUnit == 'm' || timeUnit == 's' || timeUnit == 'h')) { /* * here we revised the start time of day according to the local time zone, diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 7604a619afa859ccad4a670b25659f9a80b1cea4..6d74583a2cd82eceffa6df41685119b6343f4276 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1909,6 +1909,15 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, bool stableQuery) { return; } + if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) { + pQuery->order.order = TSDB_ORDER_ASC; + if (pQuery->window.skey > pQuery->window.ekey) { + SWAP(pQuery->window.skey, pQuery->window.ekey, TSKEY); + } + + return; + } + if (isPointInterpoQuery(pQuery) && pQuery->intervalTime == 0) { if (!QUERY_IS_ASC_QUERY(pQuery)) { qDebug(msg, GET_QINFO_ADDR(pQuery), "interp", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey, @@ -4387,7 +4396,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo // NOTE: pTableCheckInfo need to update the query time range and the lastKey info // TODO fixme - changeExecuteScanOrder(pQInfo, false); + changeExecuteScanOrder(pQInfo, isSTableQuery); code = setupQueryHandle(tsdb, pQInfo, isSTableQuery); if (code != TSDB_CODE_SUCCESS) { @@ -6095,6 +6104,9 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, goto _cleanup; } + // NOTE: pTableCheckInfo need to update the query time range and the lastKey info + changeExecuteScanOrder(pQInfo, isSTableQuery); + int32_t index = 0; for(int32_t i = 0; i < numOfGroups; ++i) {