diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 3590703695ea5f03f237d3dd36f7b1ebc8dc73d9..207222f79e3a950a170005577b64efd4fc24ba72 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -565,15 +565,23 @@ int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) { return (int64_t)(mktime(&tm) * TSDB_TICK_PER_SECOND(precision)); } - int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) { if (ekey < skey) { int64_t tmp = ekey; ekey = skey; skey = tmp; } + +#ifdef _MSC_VER +#if _MSC_VER >= 1900 + int64_t timezone = _timezone; +#endif +#endif + + int64_t tz_offset = -1 * timezone * TSDB_TICK_PER_SECOND(precision); + if (unit != 'n' && unit != 'y') { - return (int32_t)((ekey - skey) / interval); + return (int32_t)((ekey+tz_offset)/interval - (skey+tz_offset)/interval) + 1; } skey /= (int64_t)(TSDB_TICK_PER_SECOND(precision)); @@ -592,7 +600,7 @@ int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char interval *= 12; } - return (emon - smon) / (int32_t)interval; + return (int32_t)(emon/interval - smon/interval) + 1; } int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision) { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 28d3d6072782b06299190c4d2174f173b0269f51..3edd19e016cd08e2ef1e8f7f3a5dfbc7c3252e79 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5320,15 +5320,17 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr } static void doTableQueryInfoTimeWindowCheck(SQueryAttr* pQueryAttr, STableQueryInfo* pTableQueryInfo) { + // + // current subscribe can not ensure pTableQueryInfo->lastKey >= pTableQueryInfo->win.skey, so remove this condition check + // reason is subscribe calc query windows skey is all child table smallest skey, so bigest child table block->skey maybe large than this table's pTableQueryInfo->win.skey + // if (QUERY_IS_ASC_QUERY(pQueryAttr)) { assert( (pTableQueryInfo->win.skey <= pTableQueryInfo->win.ekey) && - (pTableQueryInfo->lastKey >= pTableQueryInfo->win.skey) && (pTableQueryInfo->win.skey >= pQueryAttr->window.skey && pTableQueryInfo->win.ekey <= pQueryAttr->window.ekey)); } else { assert( (pTableQueryInfo->win.skey >= pTableQueryInfo->win.ekey) && - (pTableQueryInfo->lastKey <= pTableQueryInfo->win.skey) && (pTableQueryInfo->win.skey <= pQueryAttr->window.skey && pTableQueryInfo->win.ekey >= pQueryAttr->window.ekey)); } } @@ -5430,6 +5432,28 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) { break; } + // check windows condition + if (pBlock->info.window.skey != INT64_MIN && pBlock->info.window.skey != INT64_MAX && + pBlock->info.window.ekey != INT64_MIN && pBlock->info.window.ekey != INT64_MAX) { + // normal block not specail block like last_row + int64_t skey = (*pTableQueryInfo)->win.skey; + if (QUERY_IS_ASC_QUERY(pQueryAttr)) { + // ASC + if ( skey > pBlock->info.window.ekey ) { + qWarn(" pTableQueryInfo skey(%" PRId64 ") > pBlock ekey(%" PRId64 "), so remove this block. pBlock skey=%" PRId64 " tid=%d", + skey, pBlock->info.window.ekey, pBlock->info.window.skey, pBlock->info.tid); + continue; + } + } else { + // DESC + if ( skey < pBlock->info.window.skey ) { + qWarn(" pTableQueryInfo skey(%" PRId64 ") < pBlock skey(%" PRId64 "), so remove this block. pBlock ekey=%" PRId64 "tid=%d", + skey, pBlock->info.window.skey, pBlock->info.window.ekey, pBlock->info.tid); + continue; + } + } + } + pRuntimeEnv->current = *pTableQueryInfo; doTableQueryInfoTimeWindowCheck(pQueryAttr, *pTableQueryInfo); diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 1f4bbed831952ab8c1f9c822defc97149742e4c7..9a90a27daf12450476942ba9463475b230bbc03f 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -463,7 +463,6 @@ void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const SSDataBlock* pInput) pFillInfo->interval.sliding, pFillInfo->interval.slidingUnit, pFillInfo->precision); - numOfRes += 1; if(numOfRes < numOfRows || pFillInfo->currentKey < lastKey) { // set currentKey max pFillInfo->currentKey = tsList[0]; @@ -504,7 +503,6 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma pFillInfo->interval.sliding, pFillInfo->interval.slidingUnit, pFillInfo->precision); - numOfRes += 1; assert(numOfRes >= numOfRows); } else { // reach the end of data if ((ekey1 < pFillInfo->currentKey && FILL_IS_ASC_FILL(pFillInfo)) || @@ -517,7 +515,6 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma pFillInfo->interval.sliding, pFillInfo->interval.slidingUnit, pFillInfo->precision); - numOfRes += 1; } return (numOfRes > maxNumOfRows) ? maxNumOfRows : numOfRes;