This is an automated email from the ASF dual-hosted git repository.
airborne12 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new dc6fed20027 [fix](inverted-index) Build indexes for columns added by
light schema change (#71230)
dc6fed20027 is described below
commit dc6fed200279f5bdaee26a29dcf20e7430e1532e
Author: Jack <[email protected]>
AuthorDate: Sat Dec 5 14:16:51 2026 +0800
[fix](inverted-index) Build indexes for columns added by light schema
change (#71230)
### Background
Light schema change adds a column to the table schema while retaining
existing segments. When a segment predates the column, the segment
reader supplies the column default for its rows. `BUILD INDEX` creates
the requested inverted index for existing local rowsets.
### What problem does this PR solve?
Issue Number: None
Related PR: #32550 (added the missing-column guard)
PR Type: Bugfix
Problem Summary:
A `BUILD INDEX` job can finish after skipping historical segments that
lack the indexed column. For example, load two rows, add a nullable text
column, build its inverted index, and insert row 3 with the value
`searchable`. A query with `multi_match(new_text, 'any', 'searchable')`
can report `only inverted index queries are supported`. With this
change, it returns row 3. A non-NULL column default is also searchable
on the historical rows.
### Details
- **Change map:** 306 added and 56 deleted lines. Production code is
+106 -56 in six BE files, and the regression suite with its generated
output is +200. Read the code in this order:
1. Index binding in `index_builder.cpp` (+49 -34): resolve the indexed
column by unique ID in all three build phases, and append the task's
column definition to an old rowset that lacks it.
2. Constant reader index in `column_reader.h`, `column_reader.cpp` and
`segment.cpp` (+52 -21): give `ConstantColumnReader` the base reader's
type fields, including an ARRAY element type, and open a built index
that the container holds.
3. Build scan in `iterators.h` and `segment_iterator.cpp` (+5 -1): skip
index iterators while `BUILD INDEX` reads column values.
Later commits add one assertion and the cases for a re-added column and
an ARRAY column.
- **Frequency:** Always for the local reproduction with automatic
compaction disabled and a historical rowset that predates the column.
- **Root cause:** `IndexBuilder` resolves the target column against the
old rowset schema, so it skips an index whose column was added later.
- **Why existing tests missed it:**
`IndexBuilderTest.NonExistentColumnIndexTest` exercises a column absent
from the build request schema as well as the rowset.
`MissingIndexedColumnUsesDefaultWithoutPhysicalIndex` covers the scan
before an index file exists. `test_index_change_on_new_column` checks
metadata and uses `MATCH`, which can evaluate the historical NULL
default without an index.
- **Fix:** Build the index from the default that the segment reader
already supplies, and keep the segment files and row IDs, so no data is
rewritten. Queries open the finished index through the constant column
reader.
- **Other paths and branches:** The fix covers the shared-nothing index
builder. Remote rowsets use a separate selection path. The
rowset-schema-only lookup is also present on the inspected 3.1, 4.0,
4.1, and 4.2 branches.
- **Behavior change:** After a successful local build, index-only
queries can use the built index for historical rows whose column value
comes from the schema default.
### Testing
- Ran `test_build_index_on_added_column` on the unmodified `master` BE
at `7a10e10b5dc`. Both index jobs finished, then the first `multi_match`
query failed with `only inverted index queries are supported`. The cases
for the re-added and ARRAY columns, run by hand on the same BE, also
failed their strict `MATCH` and `SEARCH` queries.
- Ran the suite at the head on a local single-BE ASAN cluster, on V2 and
SNII. Both formats returned the expected rows for every query, including
the default of the re-added column after a full compaction.
- Passed `test_index_change_on_new_column`, `test_index_change_4`,
`test_index_change_5`, and `test_add_drop_index_with_delete_data` on the
same cluster.
- Passed `IndexBuilderTest`, `ConstantColumnIteratorTest`,
`IndexStorage*` and `SegmentIteratorExprZoneMap*` in an ASAN UT build.
### Notes for Reviewers
- The constant column reader opens an index only when the container
holds it. Since #65684, a scan of a segment whose schema lists an index
with no file reads the default without a missing-index error, even with
fallback disabled. The check opens the container, so the build scan
skips index iterators to avoid the container it is writing.
- After a column is dropped and added again under the same name, the
built rowset schema holds both columns. Reads bind by unique ID, and the
suite checks the results before and after a full compaction.
---
be/src/storage/iterators.h | 1 +
be/src/storage/segment/column_reader.cpp | 31 +++++
be/src/storage/segment/column_reader.h | 36 +++---
be/src/storage/segment/segment.cpp | 6 +-
be/src/storage/segment/segment_iterator.cpp | 5 +-
be/src/storage/task/index_builder.cpp | 83 ++++++++-----
.../test_build_index_on_added_column.out | 63 ++++++++++
.../test_build_index_on_added_column.groovy | 137 +++++++++++++++++++++
8 files changed, 306 insertions(+), 56 deletions(-)
diff --git a/be/src/storage/iterators.h b/be/src/storage/iterators.h
index d73b0fb257c..c024036b5c6 100644
--- a/be/src/storage/iterators.h
+++ b/be/src/storage/iterators.h
@@ -124,6 +124,7 @@ public:
// Non-owning and initialized to a valid object by the constructor.
OlapReaderStatistics* stats;
bool use_page_cache = false;
+ bool skip_index_iterators = false;
uint32_t block_row_max = 4096 - 32; // see
https://github.com/apache/doris/pull/11816
// Effective adaptive batch size byte budget.
size_t preferred_block_size_bytes = 8388608UL;
diff --git a/be/src/storage/segment/column_reader.cpp
b/be/src/storage/segment/column_reader.cpp
index 8d4021a442f..bfc0f056b29 100644
--- a/be/src/storage/segment/column_reader.cpp
+++ b/be/src/storage/segment/column_reader.cpp
@@ -539,6 +539,9 @@ Status ColumnReader::create(const ColumnReaderOptions&
opts, const ColumnMetaPB&
ColumnReader::ColumnReader() = default;
+ColumnReader::ColumnReader(FieldType type, FieldType item_type)
+ : _meta_type(type), _meta_children_column_type(item_type), _type(type)
{}
+
ColumnReader::ColumnReader(const ColumnReaderOptions& opts, const
ColumnMetaPB& meta,
uint64_t num_rows, io::FileReaderSPtr file_reader)
: _use_index_page_cache(!config::disable_storage_page_cache),
@@ -697,6 +700,34 @@ Status ColumnReader::new_index_iterator(const
std::shared_ptr<IndexFileReader>&
return Status::OK();
}
+Status ConstantColumnReader::new_index_iterator(
+ const std::shared_ptr<IndexFileReader>& index_file_reader, const
TabletIndex* index_meta,
+ const std::string& rowset_id, uint32_t segment_id, size_t
rows_of_segment,
+ std::unique_ptr<IndexIterator>* iterator) {
+ // BUILD INDEX can write an inverted index for a default column without
writing column pages.
+ // A call without an index meta, e.g. new_index_iterator(nullptr, nullptr,
...), asks for no
+ // index and gets no iterator.
+ if (index_meta == nullptr || !index_meta->is_inverted_index()) {
+ return Status::OK();
+ }
+ // Before BUILD INDEX, the segment may have no index container at all.
+ auto status =
index_file_reader->init(config::inverted_index_read_buffer_size);
+ if (status.is<ErrorCode::INVERTED_INDEX_FILE_NOT_FOUND>() ||
+ status.is<ErrorCode::INVERTED_INDEX_BYPASS>()) {
+ return Status::OK();
+ }
+ RETURN_IF_ERROR(status);
+
+ // A container created for another column can exist before this index is
built.
+ bool exists = false;
+ RETURN_IF_ERROR(index_file_reader->index_file_exist(index_meta, &exists));
+ if (!exists) {
+ return Status::OK();
+ }
+ return ColumnReader::new_index_iterator(index_file_reader, index_meta,
rowset_id, segment_id,
+ rows_of_segment, iterator);
+}
+
Status ColumnReader::read_page(const ColumnIteratorOptions& iter_opts, const
PagePointer& pp,
PageHandle* handle, Slice* page_body,
PageFooterPB* footer,
BlockCompressionCodec* codec,
diff --git a/be/src/storage/segment/column_reader.h
b/be/src/storage/segment/column_reader.h
index 54deb040c0d..78512188bb6 100644
--- a/be/src/storage/segment/column_reader.h
+++ b/be/src/storage/segment/column_reader.h
@@ -238,6 +238,9 @@ public:
void check_data_by_zone_map_for_test(const MutableColumnPtr& dst) const;
#endif
+protected:
+ ColumnReader(FieldType type, FieldType item_type);
+
private:
friend class VariantColumnReader;
friend class FileColumnIterator;
@@ -1099,14 +1102,15 @@ private:
// uses [Paris, Paris] as its zonemap and produces "Paris" without caching
that request's reader.
class ConstantColumnReader : public ColumnReader {
public:
- explicit ConstantColumnReader(Field value, FieldType meta_type)
- : _value(std::move(value)), _schema_type(meta_type) {
+ explicit ConstantColumnReader(Field value, FieldType meta_type,
+ FieldType item_type =
FieldType::OLAP_FIELD_TYPE_NONE)
+ : ColumnReader(meta_type, item_type), _value(std::move(value)) {
// A null Field still needs its schema type. For example, an old
segment after adding a
// nullable BIGINT column has value NULL but must report BIGINT to the
read pipeline.
- if (_schema_type == FieldType::OLAP_FIELD_TYPE_UNKNOWN ||
- _schema_type == FieldType::OLAP_FIELD_TYPE_NONE) {
+ if (meta_type == FieldType::OLAP_FIELD_TYPE_UNKNOWN ||
+ meta_type == FieldType::OLAP_FIELD_TYPE_NONE) {
throw Exception(ErrorCode::INTERNAL_ERROR, "constant field type {}
is not valid",
- static_cast<int>(_schema_type));
+ static_cast<int>(meta_type));
}
if (!_value.is_null()) {
const auto field_type =
primitive_type_to_storage_field_type(_value.get_type());
@@ -1114,20 +1118,17 @@ public:
// VARCHAR DEFAULT 'Paris' is represented as STRING even though
the schema remains
// VARCHAR, so validate the compatible string family instead of
exact enum identity.
const bool compatible_string_types =
- is_string_type(field_type) && is_string_type(_schema_type);
- if (field_type != _schema_type && !compatible_string_types) {
+ is_string_type(field_type) && is_string_type(meta_type);
+ if (field_type != meta_type && !compatible_string_types) {
throw Exception(ErrorCode::INTERNAL_ERROR,
"constant field type {} does not match schema
type {}",
- static_cast<int>(_value.get_type()),
- static_cast<int>(_schema_type));
+ static_cast<int>(_value.get_type()),
static_cast<int>(meta_type));
}
}
}
bool has_zone_map() const override { return true; }
- FieldType get_meta_type() override { return _schema_type; }
-
Status match_condition(const AndBlockColumnPredicate* col_predicates,
bool* matched) const override;
@@ -1139,18 +1140,13 @@ public:
Status get_segment_zone_map(segment_v2::ZoneMap* zone_map) const override;
- // For example, an index added together with `city DEFAULT 'Paris'` has no
index file in an old
- // segment; nullptr tells the caller to evaluate the constant value
instead.
- Status new_index_iterator(const std::shared_ptr<IndexFileReader>&, const
TabletIndex*,
- const std::string&, uint32_t, size_t,
- std::unique_ptr<IndexIterator>* iterator)
override {
- *iterator = nullptr;
- return Status::OK();
- }
+ Status new_index_iterator(const std::shared_ptr<IndexFileReader>&
index_file_reader,
+ const TabletIndex* index_meta, const
std::string& rowset_id,
+ uint32_t segment_id, size_t rows_of_segment,
+ std::unique_ptr<IndexIterator>* iterator)
override;
private:
Field _value;
- FieldType _schema_type;
};
} // namespace segment_v2
diff --git a/be/src/storage/segment/segment.cpp
b/be/src/storage/segment/segment.cpp
index e5ceb8264f3..2e68f422b62 100644
--- a/be/src/storage/segment/segment.cpp
+++ b/be/src/storage/segment/segment.cpp
@@ -1094,7 +1094,11 @@ Status Segment::_get_column_reader_for_read(const
TabletColumn& col,
if (!_column_meta_accessor->has_column_uid(col_uid)) {
Field field;
RETURN_IF_ERROR(get_default_value_field(col, &field));
- *column_reader =
std::make_shared<ConstantColumnReader>(std::move(field), col.type());
+ const auto item_type = col.type() == FieldType::OLAP_FIELD_TYPE_ARRAY
+ ? col.get_sub_column(0).type()
+ : FieldType::OLAP_FIELD_TYPE_NONE;
+ *column_reader =
+ std::make_shared<ConstantColumnReader>(std::move(field),
col.type(), item_type);
return Status::OK();
}
diff --git a/be/src/storage/segment/segment_iterator.cpp
b/be/src/storage/segment/segment_iterator.cpp
index 6c11a1fe9d7..580f52ea759 100644
--- a/be/src/storage/segment/segment_iterator.cpp
+++ b/be/src/storage/segment/segment_iterator.cpp
@@ -579,7 +579,10 @@ void SegmentIterator::_initialize_predicate_results() {
Status SegmentIterator::init_iterators() {
RETURN_IF_ERROR(_init_column_iterators());
- RETURN_IF_ERROR(_init_index_iterators());
+ // BUILD INDEX reads column values while the new index container is still
being written.
+ if (!_opts.skip_index_iterators) {
+ RETURN_IF_ERROR(_init_index_iterators());
+ }
return Status::OK();
}
diff --git a/be/src/storage/task/index_builder.cpp
b/be/src/storage/task/index_builder.cpp
index 1eaf10cb848..0faff9776ca 100644
--- a/be/src/storage/task/index_builder.cpp
+++ b/be/src/storage/task/index_builder.cpp
@@ -17,6 +17,7 @@
#include "storage/task/index_builder.h"
+#include <algorithm>
#include <array>
#include <cstring>
#include <mutex>
@@ -50,6 +51,18 @@
namespace doris {
+namespace {
+
+int32_t index_column_ordinal(const TabletSchema& schema, const
TOlapTableIndex& index) {
+ // A dropped and re-added column can have the same name with a different
unique ID.
+ if (!index.column_unique_ids.empty() && index.column_unique_ids[0] >= 0) {
+ return schema.field_index(index.column_unique_ids[0]);
+ }
+ return schema.field_index(index.columns[0]);
+}
+
+} // namespace
+
IndexBuilder::IndexBuilder(StorageEngine& engine, TabletSharedPtr tablet,
const std::vector<TColumn>& columns,
const std::vector<doris::TOlapTableIndex>&
alter_inverted_indexes,
@@ -182,18 +195,12 @@ Status IndexBuilder::update_inverted_index_info() {
for (const auto& t_inverted_index : _alter_inverted_indexes) {
DCHECK_EQ(t_inverted_index.columns.size(), 1);
auto column_name = t_inverted_index.columns[0];
- auto column_idx =
output_rs_tablet_schema->field_index(column_name);
+ auto column_idx =
index_column_ordinal(*output_rs_tablet_schema, t_inverted_index);
if (column_idx < 0) {
- 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;
- }
+ LOG(WARNING) << "referenced column was missing. "
+ << "[column=" << column_name << "
referenced_column=" << column_idx
+ << "]";
+ continue;
}
auto column = output_rs_tablet_schema->column(column_idx);
@@ -260,20 +267,33 @@ Status IndexBuilder::update_inverted_index_info() {
}
})
} else {
- // base on input rowset's tablet_schema to build
- // output rowset's tablet_schema which only add
- // the indexes specified in this build index request
- for (auto t_inverted_index : _alter_inverted_indexes) {
- TabletIndex index;
- index.init_from_thrift(t_inverted_index,
*input_rs_tablet_schema);
- auto column_uid = index.col_unique_ids()[0];
- if (column_uid < 0) {
+ for (const auto& t_inverted_index : _alter_inverted_indexes) {
+ auto column_idx =
index_column_ordinal(*output_rs_tablet_schema, t_inverted_index);
+ // A light ADD COLUMN leaves old segments without column
pages. Add the task's
+ // column definition so the segment reader supplies its
default to the index writer.
+ // Only a table with column unique IDs allows a light ADD
COLUMN. A missing column
+ // with unique ID -1, e.g. one the schema never had, takes the
skip path below.
+ if (column_idx < 0 && t_inverted_index.index_type ==
TIndexType::INVERTED &&
+ !t_inverted_index.column_unique_ids.empty() &&
+ t_inverted_index.column_unique_ids[0] >= 0) {
+ const auto column_uid =
t_inverted_index.column_unique_ids[0];
+ // The task schema is the table's base schema, which holds
every indexed column.
+ const auto column =
+ std::ranges::find(_columns, column_uid,
&TColumn::col_unique_id);
+ DORIS_CHECK(column != _columns.end());
+
output_rs_tablet_schema->append_column(TabletColumn(*column));
+ column_idx =
output_rs_tablet_schema->field_index(column_uid);
+ }
+ if (column_idx < 0) {
LOG(WARNING) << "referenced column was missing. "
<< "[column=" << t_inverted_index.columns[0]
- << " referenced_column=" << column_uid << "]";
+ << " referenced_column=" << column_idx << "]";
continue;
}
- const TabletColumn& col =
output_rs_tablet_schema->column_by_uid(column_uid);
+ const TabletColumn& col =
output_rs_tablet_schema->column(column_idx);
+ const auto column_uid = col.unique_id();
+ TabletIndex index;
+ index.init_from_thrift(t_inverted_index, std::vector<int32_t>
{column_uid});
// inverted index
auto exist_indexs =
output_rs_tablet_schema->inverted_indexs(col);
@@ -618,19 +638,12 @@ Status
IndexBuilder::handle_single_rowset(RowsetMetaSharedPtr output_rowset_meta
DCHECK_EQ(inverted_index.columns.size(), 1);
auto index_id = inverted_index.index_id;
auto column_name = inverted_index.columns[0];
- auto column_idx =
output_rowset_schema->field_index(column_name);
+ auto column_idx = index_column_ordinal(*output_rowset_schema,
inverted_index);
if (column_idx < 0) {
- if (inverted_index.__isset.column_unique_ids &&
- !inverted_index.column_unique_ids.empty()) {
- column_idx = output_rowset_schema->field_index(
- inverted_index.column_unique_ids[0]);
- }
- if (column_idx < 0) {
- LOG(WARNING) << "referenced column was missing. "
- << "[column=" << column_name
- << " referenced_column=" << column_idx <<
"]";
- continue;
- }
+ LOG(WARNING) << "referenced column was missing. "
+ << "[column=" << column_name << "
referenced_column=" << column_idx
+ << "]";
+ continue;
}
auto column = output_rowset_schema->column(column_idx);
// variant column is not support for building index
@@ -724,6 +737,7 @@ Status
IndexBuilder::handle_single_rowset(RowsetMetaSharedPtr output_rowset_meta
// create iterator for each segment
OlapReaderStatistics stats;
StorageReadOptions read_options(stats);
+ read_options.skip_index_iterators = true;
auto schema =
std::make_shared<ReadSchema>(project_columns_by_ordinal(
output_rowset_schema->columns(), return_columns));
std::unique_ptr<RowwiseIterator> iter;
@@ -965,6 +979,7 @@ Status IndexBuilder::_build_snii_indexes_for_segment(const
TabletSchemaSPtr& out
OlapReaderStatistics stats;
StorageReadOptions read_options(stats);
+ read_options.skip_index_iterators = true;
auto schema = std::make_shared<ReadSchema>(
project_columns_by_ordinal(output_rowset_schema->columns(),
return_columns));
std::unique_ptr<RowwiseIterator> iter;
@@ -1030,7 +1045,7 @@ Status
IndexBuilder::_write_inverted_index_data(TabletSchemaSPtr tablet_schema,
auto inverted_index = _alter_inverted_indexes[i];
auto index_id = inverted_index.index_id;
auto column_name = inverted_index.columns[0];
- auto column_idx = tablet_schema->field_index(column_name);
+ auto column_idx = index_column_ordinal(*tablet_schema, inverted_index);
DBUG_EXECUTE_IF("IndexBuilder::_write_inverted_index_data_column_idx_is_negative",
{ column_idx = -1; })
if (column_idx < 0) {
diff --git
a/regression-test/data/inverted_index_p0/index_change/test_build_index_on_added_column.out
b/regression-test/data/inverted_index_p0/index_change/test_build_index_on_added_column.out
new file mode 100644
index 00000000000..059714b67bf
--- /dev/null
+++
b/regression-test/data/inverted_index_p0/index_change/test_build_index_on_added_column.out
@@ -0,0 +1,63 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !V2_multi_match --
+3
+
+-- !V2_search_nullable --
+3
+
+-- !V2_search_default --
+1
+2
+
+-- !V2_match_default --
+1
+2
+
+-- !V2_preserved_index --
+1
+2
+
+-- !V2_readded_default --
+1
+2
+
+-- !V2_readded_dropped --
+
+-- !V2_readded_compacted --
+1
+2
+
+-- !V2_array_match --
+3
+
+-- !SNII_multi_match --
+3
+
+-- !SNII_search_nullable --
+3
+
+-- !SNII_search_default --
+1
+2
+
+-- !SNII_match_default --
+1
+2
+
+-- !SNII_preserved_index --
+1
+2
+
+-- !SNII_readded_default --
+1
+2
+
+-- !SNII_readded_dropped --
+
+-- !SNII_readded_compacted --
+1
+2
+
+-- !SNII_array_match --
+3
+
diff --git
a/regression-test/suites/inverted_index_p0/index_change/test_build_index_on_added_column.groovy
b/regression-test/suites/inverted_index_p0/index_change/test_build_index_on_added_column.groovy
new file mode 100644
index 00000000000..cdcf5e331b8
--- /dev/null
+++
b/regression-test/suites/inverted_index_p0/index_change/test_build_index_on_added_column.groovy
@@ -0,0 +1,137 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_build_index_on_added_column", "inverted_index") {
+ if (isCloudMode()) {
+ return
+ }
+
+ sql "SET enable_common_expr_pushdown = true"
+ sql "SET enable_match_without_inverted_index = false"
+
+ for (String format : ["V2", "SNII"]) {
+ sql "DROP TABLE IF EXISTS build_index_on_added_column"
+ sql """
+ CREATE TABLE build_index_on_added_column (
+ id INT,
+ title TEXT,
+ INDEX idx_title(title) USING INVERTED PROPERTIES("parser" =
"english")
+ )
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1",
+ "light_schema_change" = "true",
+ "disable_auto_compaction" = "true",
+ "inverted_index_storage_format" = "${format}"
+ )
+ """
+
+ sql "INSERT INTO build_index_on_added_column VALUES (1, 'historical'),
(2, 'historical')"
+ sql "ALTER TABLE build_index_on_added_column ADD COLUMN new_text TEXT
NULL"
+ sql "ALTER TABLE build_index_on_added_column ADD COLUMN default_text
STRING NOT NULL DEFAULT 'apple'"
+ sql """
+ CREATE INDEX idx_new_text ON build_index_on_added_column(new_text)
+ USING INVERTED PROPERTIES("parser" = "english")
+ """
+ sql """
+ CREATE INDEX idx_default_text ON
build_index_on_added_column(default_text)
+ USING INVERTED PROPERTIES("parser" = "english")
+ """
+
+ wait_for_last_col_change_finish("build_index_on_added_column", 60000)
+
+ sql "BUILD INDEX idx_new_text ON build_index_on_added_column"
+ wait_for_last_build_index_finish("build_index_on_added_column", 60000)
+ sql "BUILD INDEX idx_default_text ON build_index_on_added_column"
+ wait_for_last_build_index_finish("build_index_on_added_column", 60000)
+
+ sql "INSERT INTO build_index_on_added_column VALUES (3, 'recent',
'searchable', 'banana')"
+
+ "order_qt_${format}_multi_match"("SELECT id FROM
build_index_on_added_column WHERE multi_match(new_text, 'any', 'searchable')")
+ "order_qt_${format}_search_nullable"("SELECT id FROM
build_index_on_added_column WHERE search('new_text:searchable')")
+ "order_qt_${format}_search_default"("SELECT id FROM
build_index_on_added_column WHERE search('default_text:apple')")
+ "order_qt_${format}_match_default"("SELECT id FROM
build_index_on_added_column WHERE default_text MATCH_ANY 'apple'")
+ "order_qt_${format}_preserved_index"("SELECT id FROM
build_index_on_added_column WHERE search('title:historical')")
+
+ // The old segments still store a dropped column with the same name.
The index must cover
+ // the new column's default, also after compaction merges the old
rowsets.
+ sql "DROP TABLE IF EXISTS build_index_on_readded_column"
+ sql """
+ CREATE TABLE build_index_on_readded_column (
+ id INT,
+ c TEXT
+ )
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1",
+ "light_schema_change" = "true",
+ "disable_auto_compaction" = "true",
+ "inverted_index_storage_format" = "${format}"
+ )
+ """
+
+ sql "INSERT INTO build_index_on_readded_column VALUES (1, 'dropped')"
+ sql "INSERT INTO build_index_on_readded_column VALUES (2, 'dropped')"
+ sql "ALTER TABLE build_index_on_readded_column DROP COLUMN c"
+ wait_for_last_col_change_finish("build_index_on_readded_column", 60000)
+ sql "ALTER TABLE build_index_on_readded_column ADD COLUMN c STRING NOT
NULL DEFAULT 'apple'"
+ wait_for_last_col_change_finish("build_index_on_readded_column", 60000)
+ sql """
+ CREATE INDEX idx_readded ON build_index_on_readded_column(c)
+ USING INVERTED PROPERTIES("parser" = "english")
+ """
+ wait_for_last_col_change_finish("build_index_on_readded_column", 60000)
+ sql "BUILD INDEX idx_readded ON build_index_on_readded_column"
+ wait_for_last_build_index_finish("build_index_on_readded_column",
60000)
+
+ "order_qt_${format}_readded_default"("SELECT id FROM
build_index_on_readded_column WHERE c MATCH_ANY 'apple'")
+ "order_qt_${format}_readded_dropped"("SELECT id FROM
build_index_on_readded_column WHERE c MATCH_ANY 'dropped'")
+ trigger_and_wait_compaction("build_index_on_readded_column", "full")
+ "order_qt_${format}_readded_compacted"("SELECT id FROM
build_index_on_readded_column WHERE search('c:apple')")
+
+ // An added ARRAY column needs its element type to open the index
built from the default.
+ sql "DROP TABLE IF EXISTS build_index_on_added_array"
+ sql """
+ CREATE TABLE build_index_on_added_array (
+ id INT,
+ title TEXT
+ )
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1",
+ "light_schema_change" = "true",
+ "disable_auto_compaction" = "true",
+ "inverted_index_storage_format" = "${format}"
+ )
+ """
+
+ sql "INSERT INTO build_index_on_added_array VALUES (1, 'historical'),
(2, 'historical')"
+ sql "ALTER TABLE build_index_on_added_array ADD COLUMN tags
ARRAY<STRING> NOT NULL DEFAULT '[]'"
+ wait_for_last_col_change_finish("build_index_on_added_array", 60000)
+ sql "CREATE INDEX idx_tags ON build_index_on_added_array(tags) USING
INVERTED"
+ wait_for_last_col_change_finish("build_index_on_added_array", 60000)
+ sql "BUILD INDEX idx_tags ON build_index_on_added_array"
+ wait_for_last_build_index_finish("build_index_on_added_array", 60000)
+
+ sql "INSERT INTO build_index_on_added_array VALUES (3, 'recent',
['searchable'])"
+
+ "order_qt_${format}_array_match"("SELECT id FROM
build_index_on_added_array WHERE tags MATCH_ANY 'searchable'")
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]