Merge pull request #29321 from taosdata/fix/3.0/TD-33336

fix wrong rows returned with sma filtering
This commit is contained in:
Shengliang Guan 2024-12-27 09:26:26 +08:00 committed by GitHub
commit 757fcc70be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 7 deletions

View File

@ -126,6 +126,10 @@ void fetchCallback(void* param, void* res, int32_t numOfRow) {
void queryCallback(void* param, void* res, int32_t code) { void queryCallback(void* param, void* res, int32_t code) {
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
(void)printf("failed to execute, reason:%s\n", taos_errstr(res)); (void)printf("failed to execute, reason:%s\n", taos_errstr(res));
taos_free_result(res);
tsem_t *sem = (tsem_t *)param;
tsem_post(sem);
return;
} }
(void)printf("start to fetch data\n"); (void)printf("start to fetch data\n");
taos_fetch_raw_block_a(res, fetchCallback, param); taos_fetch_raw_block_a(res, fetchCallback, param);

View File

@ -5128,8 +5128,8 @@ static int32_t fltSclCollectOperatorFromNode(SNode *pNode, SArray *sclOpList) {
SOperatorNode *pOper = (SOperatorNode *)pNode; SOperatorNode *pOper = (SOperatorNode *)pNode;
SValueNode *valNode = (SValueNode *)pOper->pRight; SExprNode* pLeft = (SExprNode*)pOper->pLeft;
if (IS_NUMERIC_TYPE(valNode->node.resType.type) || valNode->node.resType.type == TSDB_DATA_TYPE_TIMESTAMP) { if (IS_NUMERIC_TYPE(pLeft->resType.type) || pLeft->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
SNode* pLeft = NULL, *pRight = NULL; SNode* pLeft = NULL, *pRight = NULL;
int32_t code = nodesCloneNode(pOper->pLeft, &pLeft); int32_t code = nodesCloneNode(pOper->pLeft, &pLeft);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {

View File

@ -100,7 +100,7 @@ class TDSql:
if drop: if drop:
s = f'drop database if exists {dbname}' s = f'drop database if exists {dbname}'
self.cursor.execute(s) self.cursor.execute(s)
s = f'create database {dbname}' s = f'create database {dbname} stt_trigger 1'
for k, v in kwargs.items(): for k, v in kwargs.items():
s += f" {k} {v}" s += f" {k} {v}"
if "duration" not in kwargs: if "duration" not in kwargs:

View File

@ -39,6 +39,27 @@ class TDTestCase:
self.create_tables(); self.create_tables();
self.ts = 1500000000000 self.ts = 1500000000000
def test_TD_33336(self):
sql = "flush database db"
tdSql.execute(sql)
time.sleep(5)
sql = f'select last(ts) + 1d, last(ts) - 1d from db.t1'
tdSql.query(sql, queryTimes=1)
lastTs_add1d = tdSql.queryResult[0][0]
lastTs_sub1d = tdSql.queryResult[0][1]
sql = f'select count(*) from db.t1 where ts < "{lastTs_add1d}" and vc1 = 1'
tdSql.query(sql, queryTimes=1)
all_row_count = tdSql.queryResult[0][0]
tdLog.debug(f"all rows: {all_row_count}")
sql = f'select count(*) from db.t1 where ts < "{lastTs_sub1d}" and vc1 = 1'
tdSql.query(sql, queryTimes=1)
row_count_sub1d = tdSql.queryResult[0][0]
tdLog.debug(f"row_count_sub1d: {row_count_sub1d}")
if row_count_sub1d > all_row_count:
tdLog.exit(f' err rows returned for sql: {sql} row_count_sub1d: {row_count_sub1d} > all_row_count: {all_row_count}')
# run case # run case
def run(self): def run(self):
@ -53,6 +74,8 @@ class TDTestCase:
# self.test_case2() # self.test_case2()
tdLog.debug(" LIMIT test_case2 ............ [OK]") tdLog.debug(" LIMIT test_case2 ............ [OK]")
self.test_TD_33336()
# stop # stop
def stop(self): def stop(self):
tdSql.close() tdSql.close()
@ -65,11 +88,11 @@ class TDTestCase:
# create table # create table
def create_tables(self, dbname="db"): def create_tables(self, dbname="db"):
# super table # super table
tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int) tags(area int)") tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int, vc1 varchar(255)) tags(area int)")
# child table # child table
tdSql.execute(f"create table {dbname}.t1 using {dbname}.st tags(1)") tdSql.execute(f"create table {dbname}.t1 using {dbname}.st tags(1)")
tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int) tags(area int) sma(i2) ") tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int, vc1 varchar(255)) tags(area int) sma(i2) ")
tdSql.execute(f"create table {dbname}.t4 using {dbname}.st1 tags(1)") tdSql.execute(f"create table {dbname}.t4 using {dbname}.st1 tags(1)")
return return
@ -98,7 +121,11 @@ class TDTestCase:
sql = pre_insert sql = pre_insert
tdLog.debug("insert table %s rows=%d ..." % (tbname, count)) tdLog.debug("insert table %s rows=%d ..." % (tbname, count))
for i in range(count): for i in range(count):
sql += " (%d,%d,%d)" % (ts_start + i*1000, i, i+1) if random.randint(0, 4) > 2:
tail = ''
else:
tail = 'asd'
sql += " (%d,%d,%d,%s)" % (ts_start + i*1000, i, i+1, '"' + str(random.randint(0,5)) + f'{tail}"')
if i > 0 and i % 20000 == 0: if i > 0 and i % 20000 == 0:
tdLog.info("%d rows inserted" % i) tdLog.info("%d rows inserted" % i)
tdSql.execute(sql) tdSql.execute(sql)