diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index ce2a5019a6..da723e4343 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -6546,7 +6546,7 @@ int32_t createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SR pInfo->mergeLimit = -1; bool hasLimit = pInfo->limitInfo.limit.limit != -1 || pInfo->limitInfo.limit.offset != -1; if (hasLimit) { - pInfo->mergeLimit = pInfo->limitInfo.limit.limit + pInfo->limitInfo.limit.offset; + pInfo->mergeLimit = pInfo->limitInfo.limit.offset != -1 ? pInfo->limitInfo.limit.limit + pInfo->limitInfo.limit.offset : pInfo->limitInfo.limit.limit; pInfo->mSkipTables = NULL; } diff --git a/tests/system-test/2-query/large_data.py b/tests/system-test/2-query/large_data.py index 2279c3ce70..70353fc2d6 100644 --- a/tests/system-test/2-query/large_data.py +++ b/tests/system-test/2-query/large_data.py @@ -43,10 +43,56 @@ class TDTestCase: tdSql.query("select d0.ts from test.d0 left join test.d1 on d0.ts=d1.ts limit 1000000;") tdSql.checkRows(num1) + + def ts6136(self): + start = 1500000000000 + tdSql.execute("drop database if exists test1;") + + tdCases.taosBenchmarkExec(f"-d test1 -t 3 -n 1000000 -s {start} -y") + + while True: + tdSql.query("select count(*) from test1.meters;") + tdSql.checkRowCol(0, 0) + if tdSql.queryResult[0][0] == 3000000: + tdLog.info(f"ts6136 data ready, sum: {tdSql.queryResult[0][0]}") + break + tdLog.info(f"waiting for data ready, sum: {tdSql.queryResult[0][0]}") + time.sleep(1) + + tdSql.query(f"insert into test1.d0 values({start + 962000}, 1, 1, 1);") + tdSql.query(f"insert into test1.d0 values({start + 961000}, 1, 1, 1);") + tdSql.query(f"insert into test1.d0 values({start + 960000}, 1, 1, 1);") + tdSql.query(f"insert into test1.d0 values({start + 602000}, 1, 1, 1);") + tdSql.query(f"insert into test1.d1 values({start + 602000}, 1, 1, 1);") + tdSql.query(f"insert into test1.d0 values({start + 302000}, 1, 1, 1);") + tdSql.query(f"insert into test1.d0 values({start + 2000}, 1, 1, 1);") + tdSql.query(f"insert into test1.d0 values({start + 0}, 1, 1, 1);") + + # Query with limit 20 and store the results + tdSql.query("select tbname, ts, current from test1.meters where current = 1 and voltage = 1 and phase = 1 order by ts desc limit 8;") + tdSql.checkRows(8) + + tbname_list = [row[0] for row in tdSql.queryResult] + ts_list = [row[1] for row in tdSql.queryResult] + + # Test with different limits + for limit in range(1, 10): + row = min(8, limit) + tdSql.query(f"select tbname, ts, current from test1.meters where current = 1 and voltage = 1 and phase = 1 order by ts desc limit {limit};") + tdSql.checkRows(row) + result = tdSql.queryResult[:row] + + for i in range(min(10, len(result))): + tdSql.checkData(i, 0, tbname_list[i]) + tdSql.checkData(i, 1, ts_list[i]) + + tdLog.info("All tests passed for ts6136") + def run(self): self.prepare_data() self.ts5803() + self.ts6136() def stop(self): tdSql.close()