diff --git a/src/query/inc/qUtil.h b/src/query/inc/qUtil.h index 93dca42fdcfd85b8e11fde205392a15caaa59416..4cd0e60ebed3bc01c40fa8bee1a255fe9d0b132f 100644 --- a/src/query/inc/qUtil.h +++ b/src/query/inc/qUtil.h @@ -34,7 +34,7 @@ int32_t initWindowResInfo(SWindowResInfo* pWindowResInfo, int32_t size, int32_t void cleanupTimeWindowInfo(SWindowResInfo* pWindowResInfo); void resetTimeWindowInfo(SQueryRuntimeEnv* pRuntimeEnv, SWindowResInfo* pWindowResInfo); -void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num); +void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num); void clearClosedTimeWindow(SQueryRuntimeEnv* pRuntimeEnv); int32_t numOfClosedTimeWindow(SWindowResInfo* pWindowResInfo); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 27327348eb09ae2584c1be740677d5bc051e977c..664ee5ce7b0ba2d859a5a4827e838ad9af08f3f1 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -3342,12 +3342,9 @@ int32_t initResultRow(SResultRow *pResultRow) { void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; - SResultRow* pRow = NULL; -// if (pRuntimeEnv->windowResInfo.size == 0) { - int32_t groupIndex = 0; - int32_t uid = 0; - pRow = doPrepareResultRowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, (char *)&groupIndex, sizeof(groupIndex), true, uid); - + int32_t groupIndex = 0; + int32_t uid = 0; + SResultRow* pRow = doPrepareResultRowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, (char *)&groupIndex, sizeof(groupIndex), true, uid); for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { SQLFunctionCtx *pCtx = &pRuntimeEnv->pCtx[i]; @@ -5528,7 +5525,7 @@ static void tableIntervalProcessImpl(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) int32_t numOfClosed = numOfClosedTimeWindow(&pRuntimeEnv->windowResInfo); int32_t c = (int32_t)(MIN(numOfClosed, pQuery->limit.offset)); - clearFirstNTimeWindow(pRuntimeEnv, c); + clearFirstNWindowRes(pRuntimeEnv, c); pQuery->limit.offset -= c; } @@ -5565,7 +5562,7 @@ static void tableIntervalProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) { pQuery->rec.rows = 0; copyFromWindowResToSData(pQInfo, &pRuntimeEnv->windowResInfo); - clearFirstNTimeWindow(pRuntimeEnv, pQInfo->groupIndex); + clearFirstNWindowRes(pRuntimeEnv, pQInfo->groupIndex); } // no result generated, abort @@ -5602,12 +5599,12 @@ static void tableIntervalProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) { if ((pQuery->limit.offset > 0 && pQuery->limit.offset < numOfClosed) || pQuery->limit.offset == 0) { // skip offset result rows - clearFirstNTimeWindow(pRuntimeEnv, (int32_t) pQuery->limit.offset); + clearFirstNWindowRes(pRuntimeEnv, (int32_t) pQuery->limit.offset); pQuery->rec.rows = 0; pQInfo->groupIndex = 0; copyFromWindowResToSData(pQInfo, &pRuntimeEnv->windowResInfo); - clearFirstNTimeWindow(pRuntimeEnv, pQInfo->groupIndex); + clearFirstNWindowRes(pRuntimeEnv, pQInfo->groupIndex); doSecondaryArithmeticProcess(pQuery); limitResults(pRuntimeEnv); @@ -5641,7 +5638,7 @@ static void tableQueryImpl(SQInfo *pQInfo) { if (pRuntimeEnv->windowResInfo.size > 0) { copyFromWindowResToSData(pQInfo, &pRuntimeEnv->windowResInfo); - clearFirstNTimeWindow(pRuntimeEnv, pQInfo->groupIndex); + clearFirstNWindowRes(pRuntimeEnv, pQInfo->groupIndex); if (pQuery->rec.rows > 0) { qDebug("QInfo:%p %"PRId64" rows returned from group results, total:%"PRId64"", pQInfo, pQuery->rec.rows, pQuery->rec.total); diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index 61d080bb6c2c973e4a5e4b04c4bf8acff201c31f..c5317226c7c9a8113395a5ae9502ff1835043acb 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -64,10 +64,18 @@ void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowR if (pWindowResInfo == NULL || pWindowResInfo->capacity == 0) { return; } - + +// assert(pWindowResInfo->size == 1); + for (int32_t i = 0; i < pWindowResInfo->size; ++i) { SResultRow *pWindowRes = pWindowResInfo->pResult[i]; clearResultRow(pRuntimeEnv, pWindowRes); + + int32_t groupIndex = 0; + int64_t uid = 0; + + SET_RES_WINDOW_KEY(pRuntimeEnv->keyBuf, &groupIndex, sizeof(groupIndex), uid); + taosHashRemove(pRuntimeEnv->pResultRowHashTable, (const char *)pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(sizeof(groupIndex))); } pWindowResInfo->curIndex = -1; @@ -77,7 +85,7 @@ void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowR pWindowResInfo->prevSKey = TSKEY_INITIAL_VAL; } -void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) { +void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) { SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo; if (pWindowResInfo == NULL || pWindowResInfo->capacity == 0 || pWindowResInfo->size == 0 || num == 0) { return; @@ -163,7 +171,7 @@ void clearClosedTimeWindow(SQueryRuntimeEnv *pRuntimeEnv) { } int32_t numOfClosed = numOfClosedTimeWindow(pWindowResInfo); - clearFirstNTimeWindow(pRuntimeEnv, numOfClosed); + clearFirstNWindowRes(pRuntimeEnv, numOfClosed); } int32_t numOfClosedTimeWindow(SWindowResInfo *pWindowResInfo) { diff --git a/tests/script/general/parser/projection_limit_offset.sim b/tests/script/general/parser/projection_limit_offset.sim index 92ebb6fd79627f2e655178df2c031cd77675d1d6..bc22bd6da9194d9798f4744dea84d999beaf6a43 100644 --- a/tests/script/general/parser/projection_limit_offset.sim +++ b/tests/script/general/parser/projection_limit_offset.sim @@ -28,11 +28,19 @@ sql use $db sql create table $mt (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(12)) $i = 0 -while $i < $tbNum +$half = $tbNum / 2 + +while $i < $half $tb = $tbPrefix . $i $tg2 = ' . abc $tg2 = $tg2 . ' + + $tbId = $i + $half + + $tb1 = $tbPrefix . $tbId + sql create table $tb using $mt tags( $i , $tg2 ) + sql create table $tb1 using $mt tags( $i , $tg2 ) $x = 0 while $x < $rowNum @@ -49,7 +57,7 @@ while $i < $tbNum $nchar = $nchar . $c $nchar = $nchar . ' - sql insert into $tb values ($tstart , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar ) + sql insert into $tb values ($tstart , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar ) $tb1 values ($tstart , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar ) $tstart = $tstart + 1 $x = $x + 1 endw diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index 7c9dd2b6b5f0192bc29fd076acfd0a3a71f9ab76..34290d123cd953a2601fe5bc1f4632fc7b40656f 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -1,53 +1,53 @@ -sleep 500 -run general/parser/alter.sim -sleep 500 -run general/parser/alter1.sim -sleep 500 -run general/parser/alter_stable.sim -sleep 500 -run general/parser/auto_create_tb.sim -sleep 500 -run general/parser/auto_create_tb_drop_tb.sim -sleep 500 -run general/parser/col_arithmetic_operation.sim -sleep 500 -run general/parser/columnValue.sim -sleep 500 -run general/parser/commit.sim -sleep 500 -run general/parser/create_db.sim -sleep 500 -run general/parser/create_mt.sim -sleep 500 -run general/parser/create_tb.sim -sleep 500 -run general/parser/dbtbnameValidate.sim -sleep 500 -run general/parser/fill.sim -sleep 500 -run general/parser/fill_stb.sim -sleep 500 -#run general/parser/fill_us.sim # -sleep 500 -run general/parser/first_last.sim -sleep 500 -run general/parser/import_commit1.sim -sleep 500 -run general/parser/import_commit2.sim -sleep 500 -run general/parser/import_commit3.sim -sleep 500 -#run general/parser/import_file.sim -sleep 500 -run general/parser/insert_tb.sim -sleep 500 -run general/parser/tags_dynamically_specifiy.sim -sleep 500 -run general/parser/interp.sim -sleep 500 -run general/parser/lastrow.sim -sleep 500 -run general/parser/limit.sim +#sleep 500 +#run general/parser/alter.sim +#sleep 500 +#run general/parser/alter1.sim +#sleep 500 +#run general/parser/alter_stable.sim +#sleep 500 +#run general/parser/auto_create_tb.sim +#sleep 500 +#run general/parser/auto_create_tb_drop_tb.sim +#sleep 500 +#run general/parser/col_arithmetic_operation.sim +#sleep 500 +#run general/parser/columnValue.sim +#sleep 500 +#run general/parser/commit.sim +#sleep 500 +#run general/parser/create_db.sim +#sleep 500 +#run general/parser/create_mt.sim +#sleep 500 +#run general/parser/create_tb.sim +#sleep 500 +#run general/parser/dbtbnameValidate.sim +#sleep 500 +#run general/parser/fill.sim +#sleep 500 +#run general/parser/fill_stb.sim +#sleep 500 +##run general/parser/fill_us.sim # +#sleep 500 +#run general/parser/first_last.sim +#sleep 500 +#run general/parser/import_commit1.sim +#sleep 500 +#run general/parser/import_commit2.sim +#sleep 500 +#run general/parser/import_commit3.sim +#sleep 500 +##run general/parser/import_file.sim +#sleep 500 +#run general/parser/insert_tb.sim +#sleep 500 +#run general/parser/tags_dynamically_specifiy.sim +#sleep 500 +#run general/parser/interp.sim +#sleep 500 +#run general/parser/lastrow.sim +#sleep 500 +#run general/parser/limit.sim sleep 500 run general/parser/limit1.sim sleep 500