From 4d78ba991ea2f16d06a916d32a1774ceb5fc7dea Mon Sep 17 00:00:00 2001 From: qiye Date: Thu, 7 Nov 2024 11:29:34 +0800 Subject: [PATCH] [fix](build index)Fix build index empty index file on renamed column (#43336) ### What problem does this PR solve? This PR is a followup repair on the basis of #42882. Building index on renamed column will produce an empty index file, when `column_idx` is not found. The query is successful because match without inverted index. Move test_match_without_index to fault_injection folder and make it non-concurrent to avoid concurrency issues. --- be/src/olap/task/index_builder.cpp | 27 ++++++++++++++----- ...atch_without_index_fault_injection.groovy} | 4 +-- ...test_index_change_on_renamed_column.groovy | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) rename regression-test/suites/{inverted_index_p0/test_match_without_index.groovy => fault_injection_p0/test_match_without_index_fault_injection.groovy} (96%) diff --git a/be/src/olap/task/index_builder.cpp b/be/src/olap/task/index_builder.cpp index ea7ca76551b9be..5ea94a213811e1 100644 --- a/be/src/olap/task/index_builder.cpp +++ b/be/src/olap/task/index_builder.cpp @@ -94,10 +94,16 @@ Status IndexBuilder::update_inverted_index_info() { auto column_name = t_inverted_index.columns[0]; auto column_idx = output_rs_tablet_schema->field_index(column_name); if (column_idx < 0) { - LOG(WARNING) << "referenced column was missing. " - << "[column=" << column_name << " referenced_column=" << column_idx - << "]"; - continue; + if (!t_inverted_index.column_unique_ids.empty()) { + auto column_unique_id = t_inverted_index.column_unique_ids[0]; + column_idx = output_rs_tablet_schema->field_index(column_unique_id); + } + if (column_idx < 0) { + LOG(WARNING) << "referenced column was missing. " + << "[column=" << column_name + << " referenced_column=" << column_idx << "]"; + continue; + } } auto column = output_rs_tablet_schema->column(column_idx); const auto* index_meta = output_rs_tablet_schema->get_inverted_index(column); @@ -498,9 +504,16 @@ Status IndexBuilder::_write_inverted_index_data(TabletSchemaSPtr tablet_schema, auto column_name = inverted_index.columns[0]; auto column_idx = tablet_schema->field_index(column_name); if (column_idx < 0) { - LOG(WARNING) << "referenced column was missing. " - << "[column=" << column_name << " referenced_column=" << column_idx << "]"; - continue; + if (!inverted_index.column_unique_ids.empty()) { + auto column_unique_id = inverted_index.column_unique_ids[0]; + column_idx = tablet_schema->field_index(column_unique_id); + } + if (column_idx < 0) { + LOG(WARNING) << "referenced column was missing. " + << "[column=" << column_name << " referenced_column=" << column_idx + << "]"; + continue; + } } auto column = tablet_schema->column(column_idx); auto writer_sign = std::make_pair(segment_idx, index_id); diff --git a/regression-test/suites/inverted_index_p0/test_match_without_index.groovy b/regression-test/suites/fault_injection_p0/test_match_without_index_fault_injection.groovy similarity index 96% rename from regression-test/suites/inverted_index_p0/test_match_without_index.groovy rename to regression-test/suites/fault_injection_p0/test_match_without_index_fault_injection.groovy index a008cf703d865b..db03b75bee6976 100644 --- a/regression-test/suites/inverted_index_p0/test_match_without_index.groovy +++ b/regression-test/suites/fault_injection_p0/test_match_without_index_fault_injection.groovy @@ -16,9 +16,9 @@ // under the License. -suite("test_match_without_index", "p0") { +suite("test_match_without_index_fault_injection", "nonConcurrent") { - def testTable = "test_match_without_index" + def testTable = "test_match_without_index_fault_injection" sql "DROP TABLE IF EXISTS ${testTable}" sql """ CREATE TABLE ${testTable} ( diff --git a/regression-test/suites/inverted_index_p0/index_change/test_index_change_on_renamed_column.groovy b/regression-test/suites/inverted_index_p0/index_change/test_index_change_on_renamed_column.groovy index 6c8b8c4e0d8fbc..2d92c560cf1a9d 100644 --- a/regression-test/suites/inverted_index_p0/index_change/test_index_change_on_renamed_column.groovy +++ b/regression-test/suites/inverted_index_p0/index_change/test_index_change_on_renamed_column.groovy @@ -103,7 +103,7 @@ suite("test_index_change_on_renamed_column") { assertEquals(show_result[0][2], "idx_s") qt_select2 """ SELECT * FROM ${tableName} order by id; """ - qt_select3 """ SELECT * FROM ${tableName} where s1 match 'welcome'; """ + qt_select3 """ SELECT /*+ SET_VAR(enable_inverted_index_query = true) */ * FROM ${tableName} where s1 match 'welcome'; """ def tablets = sql_return_maparray """ show tablets from ${tableName}; """ String tablet_id = tablets[0].TabletId