Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions source/libs/index/src/indexFilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,16 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx
indexError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight);
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
}

if (nParam == 2 && node->pRight != NULL && (nodeType(node->pRight)) != QUERY_NODE_VALUE) {
indexError("right node should be value, node:%p, type:%d", node->pRight, nodeType(node->pRight));
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
}
Comment thread
yihaoDeng marked this conversation as resolved.

Comment thread
yihaoDeng marked this conversation as resolved.
if (node->opType == OP_TYPE_JSON_GET_VALUE) {
return code;
}

if ((node->pLeft != NULL && nodeType(node->pLeft) == QUERY_NODE_COLUMN) &&
(node->pRight != NULL && nodeType(node->pRight) == QUERY_NODE_VALUE)) {
SColumnNode *cn = (SColumnNode *)(node->pLeft);
Expand Down Expand Up @@ -721,6 +728,11 @@ static int8_t sifShouldUseIndexBasedOnType(SIFParam *left, SIFParam *right) {
// not compress
if (left->colValType == TSDB_DATA_TYPE_FLOAT) return 0;

// Column-to-column comparison cannot use index filter (e.g., tag1=tag2)
// right->condValue is NULL when right operand is a column reference, not a value
if (right->condValue == NULL) return 0;


Comment thread
yihaoDeng marked this conversation as resolved.
if (left->colValType == TSDB_DATA_TYPE_GEOMETRY || right->colValType == TSDB_DATA_TYPE_GEOMETRY ||
left->colValType == TSDB_DATA_TYPE_JSON || right->colValType == TSDB_DATA_TYPE_JSON) {
return 0;
Expand Down
49 changes: 48 additions & 1 deletion test/cases/15-TagIndices/test_index_tag_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def longname_idx(self, stbname):
# ------------------- 2 ----------------
#
def prepareData(self):
self.dbname = 'db'
self.dbname = 'db_ts4403'
self.stbname = 'st'
# db
tdSql.execute("create database {};".format(self.dbname))
Expand Down Expand Up @@ -284,6 +284,51 @@ def do_ts4403(self):
# add index for multiple tags(TD-28078)
tdSql.error("create index tt on {} (t2, t3);".format(self.stbname))
tdLog.debug("Verify add index for multiple tags successfully")

def do_tag_column_comparison(self):
"""Test that tag-to-tag comparison does not crash taosd

Bug: When executing query like 'select * from st where tag1=tag2',
the index filter sifSetFltParam would crash because right->condValue is NULL.
The fix skips the index filter for column-to-column comparisons,
allowing the query to execute via fallback path without crash.
"""
tdSql.execute("create database if not exists test_tag_col;")
tdSql.execute("use test_tag_col;")
tdSql.execute("create stable st(ts timestamp, val int) tags(tag1 int, tag2 int);")
tdSql.execute("create table ct1 using st tags(1, 2);")
tdSql.execute("create table ct2 using st tags(3, 3);")
tdSql.execute("create table ct3 using st tags(5, 6);")
tdSql.execute("insert into ct1 values(now, 1);")
tdSql.execute("insert into ct2 values(now, 2);")
tdSql.execute("insert into ct3 values(now, 3);")

# tag1=tag2 should work without crash (fallback to non-index filter path)
tdSql.query("select * from st where tag1=tag2;")
tdSql.checkRows(1) # ct2 where tag1=3, tag2=3
tdLog.info("tag1=tag2 query works correctly (no crash)")

# tag1<tag2 should also work
tdSql.query("select * from st where tag1<tag2;")
tdSql.checkRows(2) # ct1 and ct3
tdLog.info("tag1<tag2 query works correctly (no crash)")

# tag1>tag2 should also work
tdSql.query("select * from st where tag1>tag2;")
tdSql.checkRows(0) # no matching rows
tdLog.info("tag1>tag2 query works correctly (no crash)")
# Normal tag=value queries should still work
tdSql.query("select * from st where tag1=1;")
tdSql.checkRows(1)
tdLog.info("tag1=1 query works correctly")

tdSql.query("select * from st where tag2=3;")
tdSql.checkRows(1)
tdLog.info("tag2=3 query works correctly")

# Cleanup
tdSql.execute("drop database test_tag_col;")
tdLog.info("Tag-to-tag comparison test passed")


#
Expand All @@ -304,6 +349,7 @@ def test_index_tag_basic(self):
8. Drop all tag indexes
9. Attempt to create tag index with excessively long name and verify error
10. bug TS-4403: Create/drop tag index on supertable and verify behavior
11. Verify tag-to-tag comparison does not crash taosd

Since: v3.0.0.0

Expand Down Expand Up @@ -334,6 +380,7 @@ def test_index_tag_basic(self):
self.longname_idx(stable)

self.do_ts4403()
self.do_tag_column_comparison()



1 change: 1 addition & 0 deletions test/ci/cases.task
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_create_drop.py
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_overflow.py
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_perf.py
,,y,.,./ci/pytest.sh pytest cases/15-TagIndices/test_index_tag_basic.py

# 16-Views
,,y,.,./ci/pytest.sh pytest cases/16-Views/test_view_basic.py
Expand Down
Loading