Skip to content

Commit 4837c27

Browse files
authored
fix tag file crash (#34607)
1 parent e036047 commit 4837c27

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

source/libs/index/src/indexFilter.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,16 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx
435435
indexError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight);
436436
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
437437
}
438+
439+
if (nParam == 2 && node->pRight != NULL && (nodeType(node->pRight)) != QUERY_NODE_VALUE) {
440+
indexError("right node should be value, node:%p, type:%d", node->pRight, nodeType(node->pRight));
441+
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
442+
}
443+
438444
if (node->opType == OP_TYPE_JSON_GET_VALUE) {
439445
return code;
440446
}
447+
441448
if ((node->pLeft != NULL && nodeType(node->pLeft) == QUERY_NODE_COLUMN) &&
442449
(node->pRight != NULL && nodeType(node->pRight) == QUERY_NODE_VALUE)) {
443450
SColumnNode *cn = (SColumnNode *)(node->pLeft);
@@ -721,6 +728,11 @@ static int8_t sifShouldUseIndexBasedOnType(SIFParam *left, SIFParam *right) {
721728
// not compress
722729
if (left->colValType == TSDB_DATA_TYPE_FLOAT) return 0;
723730

731+
// Column-to-column comparison cannot use index filter (e.g., tag1=tag2)
732+
// right->condValue is NULL when right operand is a column reference, not a value
733+
if (right->condValue == NULL) return 0;
734+
735+
724736
if (left->colValType == TSDB_DATA_TYPE_GEOMETRY || right->colValType == TSDB_DATA_TYPE_GEOMETRY ||
725737
left->colValType == TSDB_DATA_TYPE_JSON || right->colValType == TSDB_DATA_TYPE_JSON) {
726738
return 0;

test/cases/15-TagIndices/test_index_tag_basic.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def longname_idx(self, stbname):
233233
# ------------------- 2 ----------------
234234
#
235235
def prepareData(self):
236-
self.dbname = 'db'
236+
self.dbname = 'db_ts4403'
237237
self.stbname = 'st'
238238
# db
239239
tdSql.execute("create database {};".format(self.dbname))
@@ -284,6 +284,51 @@ def do_ts4403(self):
284284
# add index for multiple tags(TD-28078)
285285
tdSql.error("create index tt on {} (t2, t3);".format(self.stbname))
286286
tdLog.debug("Verify add index for multiple tags successfully")
287+
288+
def do_tag_column_comparison(self):
289+
"""Test that tag-to-tag comparison does not crash taosd
290+
291+
Bug: When executing query like 'select * from st where tag1=tag2',
292+
the index filter sifSetFltParam would crash because right->condValue is NULL.
293+
The fix skips the index filter for column-to-column comparisons,
294+
allowing the query to execute via fallback path without crash.
295+
"""
296+
tdSql.execute("create database if not exists test_tag_col;")
297+
tdSql.execute("use test_tag_col;")
298+
tdSql.execute("create stable st(ts timestamp, val int) tags(tag1 int, tag2 int);")
299+
tdSql.execute("create table ct1 using st tags(1, 2);")
300+
tdSql.execute("create table ct2 using st tags(3, 3);")
301+
tdSql.execute("create table ct3 using st tags(5, 6);")
302+
tdSql.execute("insert into ct1 values(now, 1);")
303+
tdSql.execute("insert into ct2 values(now, 2);")
304+
tdSql.execute("insert into ct3 values(now, 3);")
305+
306+
# tag1=tag2 should work without crash (fallback to non-index filter path)
307+
tdSql.query("select * from st where tag1=tag2;")
308+
tdSql.checkRows(1) # ct2 where tag1=3, tag2=3
309+
tdLog.info("tag1=tag2 query works correctly (no crash)")
310+
311+
# tag1<tag2 should also work
312+
tdSql.query("select * from st where tag1<tag2;")
313+
tdSql.checkRows(2) # ct1 and ct3
314+
tdLog.info("tag1<tag2 query works correctly (no crash)")
315+
316+
# tag1>tag2 should also work
317+
tdSql.query("select * from st where tag1>tag2;")
318+
tdSql.checkRows(0) # no matching rows
319+
tdLog.info("tag1>tag2 query works correctly (no crash)")
320+
# Normal tag=value queries should still work
321+
tdSql.query("select * from st where tag1=1;")
322+
tdSql.checkRows(1)
323+
tdLog.info("tag1=1 query works correctly")
324+
325+
tdSql.query("select * from st where tag2=3;")
326+
tdSql.checkRows(1)
327+
tdLog.info("tag2=3 query works correctly")
328+
329+
# Cleanup
330+
tdSql.execute("drop database test_tag_col;")
331+
tdLog.info("Tag-to-tag comparison test passed")
287332

288333

289334
#
@@ -304,6 +349,7 @@ def test_index_tag_basic(self):
304349
8. Drop all tag indexes
305350
9. Attempt to create tag index with excessively long name and verify error
306351
10. bug TS-4403: Create/drop tag index on supertable and verify behavior
352+
11. Verify tag-to-tag comparison does not crash taosd
307353
308354
Since: v3.0.0.0
309355
@@ -334,6 +380,7 @@ def test_index_tag_basic(self):
334380
self.longname_idx(stable)
335381

336382
self.do_ts4403()
383+
self.do_tag_column_comparison()
337384

338385

339386

test/ci/cases.task

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@
534534
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_create_drop.py
535535
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_overflow.py
536536
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_perf.py
537+
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_tag_basic.py
537538

538539
# 16-Views
539540
,,y,.,./ci/pytest.sh pytest cases/16-Views/test_view_basic.py

0 commit comments

Comments
 (0)