This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new c3b197eb93c branch-4.2: [fix](variant) Preserve V2 execution for SNII
values indexes (#71141)
c3b197eb93c is described below
commit c3b197eb93c05e2742283d0509ccb6ff091ecf9d
Author: lihangyu <[email protected]>
AuthorDate: Wed Dec 2 10:01:08 2026 +0800
branch-4.2: [fix](variant) Preserve V2 execution for SNII values indexes
(#71141)
### What problem does this PR solve?
Related PRs #70982, #71008, and #71121. [NonConcurrent CI build
#14571](https://doris-ci.com/builds/agent-test/14571/index.html)
reported failures in VARIANT values-index suites and DDL replay.
Schema change and MoW partial updates build execution schemas from
storage or load metadata. On legacy-key tables, this can select VARIANT
V1 and send the VARIANT root to the ordinary SNII index writer, which
rejects it. The schema-change jobs and load writers now make an
execution copy when a writable SNII values index requires V2. The tablet
schema and its storage encoding stay unchanged.
The dotted-key suite enables the escape feature explicitly. The DDL
suite checks the current Decimal256 rejection. The DDL replay suite
enables the required FE features for each affected CREATE and restores
the prior configuration afterward.
### Release note
Fix schema change and MoW partial updates for VARIANT columns with SNII
values indexes and legacy key encoding.
### Validation
- ASAN BE build passed on branch-4.2.
- 38 BE unit tests passed, including the independent execution schema
test.
- 21 values-index regression suites passed with FE P0 fuzzy enabled on a
local-storage cluster.
- `check_before_quit` replayed the tables created by those suites.
### Check List (For Author)
- [x] Regression test
- [x] Unit test
- Documentation needed? No.
---
be/src/cloud/cloud_schema_change_job.cpp | 11 +-
be/src/exec/common/variant_util.cpp | 28 ++--
be/src/storage/schema_change/schema_change.cpp | 30 +++-
be/src/storage/schema_change/schema_change.h | 5 +
be/src/storage/tablet/tablet_schema.cpp | 160 ++++++++++++---------
be/src/storage/tablet/tablet_schema.h | 2 +
be/test/storage/tablet/tablet_schema_test.cpp | 50 +++++++
.../test_variant_values_index_compaction.groovy | 4 +-
.../test_variant_values_index_ddl.groovy | 2 +-
.../test_variant_values_index_dotted_keys.groovy | 2 +-
.../test_variant_values_index_mow.groovy | 2 +-
...ariant_values_index_mow_publish_conflict.groovy | 102 +++++++++++++
.../test_variant_values_index_sc_concurrent.groovy | 2 +-
.../test_variant_values_index_schema_change.groovy | 2 +-
...ariant_values_index_sorted_schema_change.groovy | 61 ++++++++
15 files changed, 361 insertions(+), 102 deletions(-)
diff --git a/be/src/cloud/cloud_schema_change_job.cpp
b/be/src/cloud/cloud_schema_change_job.cpp
index 7654c922061..b473c4f9b40 100644
--- a/be/src/cloud/cloud_schema_change_job.cpp
+++ b/be/src/cloud/cloud_schema_change_job.cpp
@@ -236,10 +236,9 @@ Status CloudSchemaChangeJob::process_alter_tablet(const
TAlterTabletReqV2& reque
// FIXME(cyx): Should trigger compaction on base_tablet if there are too
many rowsets to convert.
- // Create a new tablet schema, should merge with dropped columns in light
weight schema change
- _base_tablet_schema = std::make_shared<TabletSchema>();
- _base_tablet_schema->update_tablet_columns(*_base_tablet->tablet_schema(),
request.columns);
_new_tablet_schema = _new_tablet->tablet_schema();
+ _base_tablet_schema =
SchemaChangeJob::build_read_schema(*_base_tablet->tablet_schema(),
+ request.columns,
*_new_tablet_schema);
std::vector<ColumnId> return_columns;
return_columns.resize(_base_tablet_schema->num_columns());
@@ -345,7 +344,7 @@ Status
CloudSchemaChangeJob::_convert_historical_rowsets(const SchemaChangeParam
// Add filter information in change, and filter column information will be
set in _parse_request
// And filter some data every time the row block changes
- BlockChanger changer(_new_tablet->tablet_schema(), *sc_params.desc_tbl);
+ BlockChanger changer(_new_tablet_schema, *sc_params.desc_tbl);
bool sc_sorting = false;
bool sc_directly = false;
@@ -388,7 +387,7 @@ Status
CloudSchemaChangeJob::_convert_historical_rowsets(const SchemaChangeParam
context.segments_overlap = input_segments_overlap ==
NONOVERLAPPING_WITHIN_GROUP
? OVERLAPPING
: input_segments_overlap;
- context.tablet_schema = _new_tablet->tablet_schema();
+ context.tablet_schema = _new_tablet_schema;
context.newest_write_timestamp = rs_reader->newest_write_timestamp();
context.storage_resource =
_cloud_storage_engine.get_storage_resource(sc_params.vault_id);
context.job_id = _job_id;
@@ -407,7 +406,7 @@ Status
CloudSchemaChangeJob::_convert_historical_rowsets(const SchemaChangeParam
context.write_type = DataWriteType::TYPE_SCHEMA_CHANGE;
// TODO if support VerticalSegmentWriter, also need to handle cluster
key primary key index
bool vertical = false;
- if (sc_sorting &&
!_new_tablet->tablet_schema()->cluster_key_uids().empty()) {
+ if (sc_sorting && !_new_tablet_schema->cluster_key_uids().empty()) {
// see VBaseSchemaChangeWithSorting::_external_sorting
vertical = true;
}
diff --git a/be/src/exec/common/variant_util.cpp
b/be/src/exec/common/variant_util.cpp
index 3cfbb713f20..1fc86ad4632 100644
--- a/be/src/exec/common/variant_util.cpp
+++ b/be/src/exec/common/variant_util.cpp
@@ -1247,7 +1247,13 @@ bool
VariantCompactionUtil::has_writable_values_index(const TabletSchema& schema
Status VariantCompactionUtil::plan_values_index_compaction(
const std::vector<RowsetSharedPtr>& rowsets, bool expand_subcolumns,
const std::set<std::pair<int32_t, int64_t>>& native_indexes,
TabletSchemaSPtr& schema) {
- std::set<int32_t> values_roots;
+ if (!expand_subcolumns) {
+ // Historical schemas may contain extracted children even when
expansion is disabled.
+ schema = schema->copy_without_variant_extracted_columns();
+ schema->set_path_set_info({});
+ return Status::OK();
+ }
+
std::set<int32_t> rebuild_roots;
for (const auto* index : schema->inverted_indexes()) {
// Replayed indexes without column IDs are skipped by index compaction
as well.
@@ -1255,29 +1261,11 @@ Status
VariantCompactionUtil::plan_values_index_compaction(
continue;
}
const int32_t uid = index->col_unique_ids().front();
- values_roots.insert(uid);
if (!native_indexes.contains({uid, index->index_id()})) {
rebuild_roots.insert(uid);
}
}
- if (expand_subcolumns) {
- RETURN_IF_ERROR(get_extended_compaction_schema(rowsets, schema,
rebuild_roots));
- } else {
- // Historical schemas may contain extracted children even when
expansion is disabled.
- schema = schema->copy_without_variant_extracted_columns();
- schema->set_path_set_info({});
- }
- // The rowset schema does not persist the FE's VARIANT execution type.
Compaction owns
- // the newly built schema, so it can select the V2 writer while keeping
legacy key encoding.
- for (size_t i = 0; i < schema->num_columns(); ++i) {
- const auto& column = schema->column(i);
- const int32_t uid =
- column.is_extracted_column() ? column.parent_unique_id() :
column.unique_id();
- if (column.is_variant_type() && values_roots.contains(uid)) {
- schema->mutable_column(i).set_variant_is_v2(true);
- }
- }
- return Status::OK();
+ return get_extended_compaction_schema(rowsets, schema, rebuild_roots);
}
// Build the temporary schema for compaction.
diff --git a/be/src/storage/schema_change/schema_change.cpp
b/be/src/storage/schema_change/schema_change.cpp
index d753acf7c30..513fbf41f70 100644
--- a/be/src/storage/schema_change/schema_change.cpp
+++ b/be/src/storage/schema_change/schema_change.cpp
@@ -887,22 +887,42 @@ Status SchemaChangeJob::process_alter_tablet(const
TAlterTabletReqV2& request) {
return res;
}
+TabletSchemaSPtr SchemaChangeJob::build_read_schema(const TabletSchema&
base_schema,
+ const
std::vector<TColumn>& request_columns,
+ const TabletSchema&
target_schema) {
+ auto read_schema = std::make_shared<TabletSchema>();
+ read_schema->update_tablet_columns(base_schema, request_columns);
+ if (read_schema->num_variant_columns() == 0 ||
target_schema.num_variant_columns() == 0) {
+ return read_schema;
+ }
+ // BlockChanger passes unchanged columns through without converting their
representation.
+ for (const auto& column : target_schema.columns()) {
+ if (!column->is_variant_type() || column->is_extracted_column()) {
+ continue;
+ }
+ const int32_t read_pos = read_schema->field_index(column->name());
+ if (read_pos >= 0 && read_schema->column(read_pos).is_variant_type()) {
+
read_schema->mutable_column(read_pos).set_variant_is_v2(column->variant_is_v2());
+ }
+ }
+ return read_schema;
+}
+
SchemaChangeJob::SchemaChangeJob(StorageEngine& local_storage_engine,
const TAlterTabletReqV2& request, const
std::string& job_id)
: _local_storage_engine(local_storage_engine) {
_base_tablet =
_local_storage_engine.tablet_manager()->get_tablet(request.base_tablet_id);
_new_tablet =
_local_storage_engine.tablet_manager()->get_tablet(request.new_tablet_id);
if (_base_tablet && _new_tablet) {
- _base_tablet_schema = std::make_shared<TabletSchema>();
-
_base_tablet_schema->update_tablet_columns(*_base_tablet->tablet_schema(),
request.columns);
- // The request only include column info, do not include bitmap or
bloomfilter index info,
- // So we also need to copy index info from the real base tablet
-
_base_tablet_schema->update_index_info_from(*_base_tablet->tablet_schema());
// During a schema change, the extracted columns of a variant should
not be included in the tablet schema.
// This is because the schema change for a variant needs to ignore the
extracted columns.
// Otherwise, the schema types in different rowsets might be
inconsistent. When performing a schema change,
// the complete variant is constructed by reading all the sub-columns
of the variant.
_new_tablet_schema =
_new_tablet->tablet_schema()->copy_without_variant_extracted_columns();
+ const auto base_schema = _base_tablet->tablet_schema();
+ _base_tablet_schema = build_read_schema(*base_schema, request.columns,
*_new_tablet_schema);
+ // Restore the base tablet's bloom filter flags after applying the
request columns.
+ _base_tablet_schema->update_index_info_from(*base_schema);
}
_job_id = job_id;
}
diff --git a/be/src/storage/schema_change/schema_change.h
b/be/src/storage/schema_change/schema_change.h
index 61beb10e390..7e6d51186fa 100644
--- a/be/src/storage/schema_change/schema_change.h
+++ b/be/src/storage/schema_change/schema_change.h
@@ -291,6 +291,11 @@ public:
bool tablet_in_converting(int64_t tablet_id);
+ // Keep the base column layout and read matching VARIANT roots in the
target representation.
+ static TabletSchemaSPtr build_read_schema(const TabletSchema& base_schema,
+ const std::vector<TColumn>&
request_columns,
+ const TabletSchema&
target_schema);
+
static Status parse_request(const SchemaChangeParams& sc_params,
TabletSchema* base_tablet_schema,
TabletSchema* new_tablet_schema,
BlockChanger* changer, bool* sc_sorting, bool*
sc_directly);
diff --git a/be/src/storage/tablet/tablet_schema.cpp
b/be/src/storage/tablet/tablet_schema.cpp
index ff6c7434ace..e1b16c8843a 100644
--- a/be/src/storage/tablet/tablet_schema.cpp
+++ b/be/src/storage/tablet/tablet_schema.cpp
@@ -41,6 +41,7 @@
#include "core/data_type/data_type_factory.hpp"
#include "core/string_ref.h"
#include "exec/common/hex.h"
+#include "exec/common/variant_util.h"
#include "exprs/aggregate/aggregate_function_simple_factory.h"
#include "exprs/aggregate/aggregate_function_state_union.h"
#include "storage/index/index_writer.h" //
IndexColumnWriter::check_support_*_index
@@ -874,10 +875,20 @@ int64_t TabletSchema::get_metadata_size() const {
return sizeof(TabletSchema);
}
-void TabletSchema::append_column(TabletColumn column, ColumnType col_type) {
- if (_variant_escape_dots_in_keys && column.is_variant_type()) {
- column.set_variant_is_v2(true);
+bool TabletSchema::_requires_variant_v2(int32_t root_uid) const {
+ if (_variant_escape_dots_in_keys) {
+ return true;
+ }
+ if (root_uid < 0 ||
+
!variant_util::supports_values_index_format(_inverted_index_storage_format)) {
+ return false;
}
+ return std::ranges::any_of(inverted_indexs(root_uid, ""), [](const
TabletIndex* index) {
+ return index->is_variant_values_index();
+ });
+}
+
+void TabletSchema::append_column(TabletColumn column, ColumnType col_type) {
if (column.is_key()) {
_num_key_columns++;
}
@@ -885,6 +896,11 @@ void TabletSchema::append_column(TabletColumn column,
ColumnType col_type) {
_num_null_columns++;
}
if (column.is_variant_type()) {
+ const int32_t root_uid =
+ column.is_extracted_column() ? column.parent_unique_id() :
column.unique_id();
+ if (_requires_variant_v2(root_uid)) {
+ column.set_variant_is_v2(true);
+ }
++_num_variant_columns;
if (!column.has_path_info()) {
const std::string& col_name = column.name_lower_case();
@@ -998,9 +1014,54 @@ void TabletSchema::init_from_pb(const TabletSchemaPB&
schema, bool ignore_extrac
for (const auto& i : schema.cluster_key_uids()) {
_cluster_key_uids.push_back(i);
}
+ // Default to V1 inverted index storage format for backward compatibility
if not specified in schema.
+ if (!schema.has_inverted_index_storage_format()) {
+ _inverted_index_storage_format = InvertedIndexStorageFormatPB::V1;
+ } else {
+ _inverted_index_storage_format =
schema.inverted_index_storage_format();
+ }
+
+ for (const auto& index_pb : schema.index()) {
+ TabletIndexPtr index;
+ if (reuse_cache_column) {
+ auto pair = TabletColumnObjectPool::instance()->insert_index(
+ deterministic_string_serialize(index_pb));
+ index = pair.second;
+ // Only need the value to be cached by the pool, release it
quickly because the handle need
+ // record reference count mannually, or it will core during tablet
schema copy method.
+ TabletColumnObjectPool::instance()->release(pair.first);
+ } else {
+ index = std::make_shared<TabletIndex>();
+ index->init_from_pb(index_pb);
+ }
+ size_t index_pos = _indexes.size();
+ _indexes.emplace_back(std::move(index));
+ for (int32_t col_uid : _indexes.back()->col_unique_ids()) {
+ if (auto field_pattern = _indexes.back()->field_pattern();
!field_pattern.empty()) {
+ auto& pattern_to_index_map =
_index_by_unique_id_with_pattern[col_uid];
+
pattern_to_index_map[field_pattern].emplace_back(_indexes.back());
+ } else {
+ IndexKey key = std::make_tuple(_indexes.back()->index_type(),
col_uid,
+
_indexes.back()->get_index_suffix());
+ _col_id_suffix_to_index[key].push_back(index_pos);
+ }
+ }
+ }
+
for (auto& column_pb : schema.column()) {
TabletColumnPtr column;
- if (reuse_cache_column && !_variant_escape_dots_in_keys) {
+ bool use_variant_v2 = false;
+ if (iequal(column_pb.type(), "VARIANT")) {
+ const auto& path = column_pb.column_path_info();
+ const int32_t parent_uid =
+ path.has_parrent_column_unique_id()
+ ?
static_cast<int32_t>(path.parrent_column_unique_id())
+ : -1;
+ const int32_t root_uid = parent_uid >= 0 ? parent_uid :
column_pb.unique_id();
+ use_variant_v2 = _requires_variant_v2(root_uid);
+ }
+ // The execution type is derived from the tablet schema and is absent
from the pool key.
+ if (reuse_cache_column && !_variant_escape_dots_in_keys &&
!use_variant_v2) {
auto pair = TabletColumnObjectPool::instance()->insert(
deterministic_string_serialize(column_pb));
column = pair.second;
@@ -1012,7 +1073,7 @@ void TabletSchema::init_from_pb(const TabletSchemaPB&
schema, bool ignore_extrac
column = std::make_shared<TabletColumn>();
column->init_from_pb(column_pb);
}
- if (_variant_escape_dots_in_keys && column->is_variant_type()) {
+ if (use_variant_v2) {
column->set_variant_is_v2(true);
}
if (ignore_extracted_columns && column->is_extracted_column()) {
@@ -1035,32 +1096,6 @@ void TabletSchema::init_from_pb(const TabletSchemaPB&
schema, bool ignore_extrac
}
_num_columns++;
}
- for (const auto& index_pb : schema.index()) {
- TabletIndexPtr index;
- if (reuse_cache_column) {
- auto pair = TabletColumnObjectPool::instance()->insert_index(
- deterministic_string_serialize(index_pb));
- index = pair.second;
- // Only need the value to be cached by the pool, release it
quickly because the handle need
- // record reference count mannually, or it will core during tablet
schema copy method.
- TabletColumnObjectPool::instance()->release(pair.first);
- } else {
- index = std::make_shared<TabletIndex>();
- index->init_from_pb(index_pb);
- }
- size_t index_pos = _indexes.size();
- _indexes.emplace_back(std::move(index));
- for (int32_t col_uid : _indexes.back()->col_unique_ids()) {
- if (auto field_pattern = _indexes.back()->field_pattern();
!field_pattern.empty()) {
- auto& pattern_to_index_map =
_index_by_unique_id_with_pattern[col_uid];
-
pattern_to_index_map[field_pattern].emplace_back(_indexes.back());
- } else {
- IndexKey key = std::make_tuple(_indexes.back()->index_type(),
col_uid,
-
_indexes.back()->get_index_suffix());
- _col_id_suffix_to_index[key].push_back(index_pos);
- }
- }
- }
_num_short_key_columns = schema.num_short_key_columns();
_num_rows_per_row_block = schema.num_rows_per_row_block();
_compress_kind = schema.compress_kind();
@@ -1087,13 +1122,6 @@ void TabletSchema::init_from_pb(const TabletSchemaPB&
schema, bool ignore_extrac
_storage_page_size = schema.storage_page_size();
_storage_dict_page_size = schema.storage_dict_page_size();
_schema_version = schema.schema_version();
- // Default to V1 inverted index storage format for backward compatibility
if not specified in schema.
- if (!schema.has_inverted_index_storage_format()) {
- _inverted_index_storage_format = InvertedIndexStorageFormatPB::V1;
- } else {
- _inverted_index_storage_format =
schema.inverted_index_storage_format();
- }
-
_row_store_column_unique_ids.assign(schema.row_store_column_unique_ids().begin(),
schema.row_store_column_unique_ids().end());
_deprecated_enable_variant_flatten_nested =
schema.enable_variant_flatten_nested();
@@ -1163,6 +1191,7 @@ void TabletSchema::build_current_tablet_schema(int64_t
index_id, int32_t version
// copy from ori_tablet_schema
_keys_type = ori_tablet_schema.keys_type();
_variant_escape_dots_in_keys =
ori_tablet_schema.variant_escape_dots_in_keys();
+ _inverted_index_storage_format =
ori_tablet_schema.get_inverted_index_storage_format();
_num_short_key_columns = ori_tablet_schema.num_short_key_columns();
_num_rows_per_row_block = ori_tablet_schema.num_rows_per_row_block();
_compress_kind = ori_tablet_schema.compress_kind();
@@ -1201,6 +1230,30 @@ void TabletSchema::build_current_tablet_schema(int64_t
index_id, int32_t version
for (const auto& i : ori_tablet_schema._cluster_key_uids) {
_cluster_key_uids.push_back(i);
}
+ for (const auto& i : index->indexes) {
+ size_t index_pos = _indexes.size();
+ // Reuse TabletIndex object from pool to reduce memory consumption
+ TabletIndexPtr new_index;
+ TabletIndexPB index_pb;
+ i->to_schema_pb(&index_pb);
+ auto pair = TabletColumnObjectPool::instance()->insert_index(
+ deterministic_string_serialize(index_pb));
+ new_index = pair.second;
+ // Release the handle quickly, because we use shared ptr to manage
index
+ TabletColumnObjectPool::instance()->release(pair.first);
+ _indexes.emplace_back(std::move(new_index));
+ for (int32_t col_uid : _indexes.back()->col_unique_ids()) {
+ if (auto field_pattern = _indexes.back()->field_pattern();
!field_pattern.empty()) {
+ auto& pattern_to_index_map =
_index_by_unique_id_with_pattern[col_uid];
+
pattern_to_index_map[field_pattern].emplace_back(_indexes.back());
+ } else {
+ IndexKey key = std::make_tuple(_indexes.back()->index_type(),
col_uid,
+
_indexes.back()->get_index_suffix());
+ _col_id_suffix_to_index[key].push_back(index_pos);
+ }
+ }
+ }
+
for (auto& column : index->columns) {
if (column->is_key()) {
_num_key_columns++;
@@ -1224,10 +1277,13 @@ void TabletSchema::build_current_tablet_schema(int64_t
index_id, int32_t version
_skip_bitmap_col_idx = _num_columns;
}
TabletColumnPtr new_column;
- if (_variant_escape_dots_in_keys) {
+ const int32_t root_uid =
+ column->is_extracted_column() ? column->parent_unique_id() :
column->unique_id();
+ const bool use_variant_v2 = column->is_variant_type() &&
_requires_variant_v2(root_uid);
+ if (_variant_escape_dots_in_keys || use_variant_v2) {
// ColumnPB and the shared pool key do not contain the V2
execution flag.
new_column = std::make_shared<TabletColumn>(*column);
- if (new_column->is_variant_type()) {
+ if (use_variant_v2) {
new_column->set_variant_is_v2(true);
}
} else {
@@ -1244,30 +1300,6 @@ void TabletSchema::build_current_tablet_schema(int64_t
index_id, int32_t version
_num_columns++;
}
- for (const auto& i : index->indexes) {
- size_t index_pos = _indexes.size();
- // Reuse TabletIndex object from pool to reduce memory consumption
- TabletIndexPtr new_index;
- TabletIndexPB index_pb;
- i->to_schema_pb(&index_pb);
- auto pair = TabletColumnObjectPool::instance()->insert_index(
- deterministic_string_serialize(index_pb));
- new_index = pair.second;
- // Release the handle quickly, because we use shared ptr to manage
index
- TabletColumnObjectPool::instance()->release(pair.first);
- _indexes.emplace_back(std::move(new_index));
- for (int32_t col_uid : _indexes.back()->col_unique_ids()) {
- if (auto field_pattern = _indexes.back()->field_pattern();
!field_pattern.empty()) {
- auto& pattern_to_index_map =
_index_by_unique_id_with_pattern[col_uid];
-
pattern_to_index_map[field_pattern].emplace_back(_indexes.back());
- } else {
- IndexKey key = std::make_tuple(_indexes.back()->index_type(),
col_uid,
-
_indexes.back()->get_index_suffix());
- _col_id_suffix_to_index[key].push_back(index_pos);
- }
- }
- }
-
if (has_bf_columns) {
_has_bf_fpp = true;
_bf_fpp = ori_tablet_schema.bloom_filter_fpp();
diff --git a/be/src/storage/tablet/tablet_schema.h
b/be/src/storage/tablet/tablet_schema.h
index fc190ed948a..eeb76e7e7cb 100644
--- a/be/src/storage/tablet/tablet_schema.h
+++ b/be/src/storage/tablet/tablet_schema.h
@@ -795,6 +795,8 @@ private:
friend bool operator!=(const TabletSchema& a, const TabletSchema& b);
TabletSchema(const TabletSchema&) = default;
+ bool _requires_variant_v2(int32_t root_uid) const;
+
KeysType _keys_type = DUP_KEYS;
SortType _sort_type = SortType::LEXICAL;
size_t _sort_col_num = 0;
diff --git a/be/test/storage/tablet/tablet_schema_test.cpp
b/be/test/storage/tablet/tablet_schema_test.cpp
index ccc8685e006..95c8b32f8d3 100644
--- a/be/test/storage/tablet/tablet_schema_test.cpp
+++ b/be/test/storage/tablet/tablet_schema_test.cpp
@@ -1156,4 +1156,54 @@ TEST_F(TabletSchemaTest,
CurrentSchemaKeepsPersistedTablePolicy) {
EXPECT_TRUE(current.column(0).variant_is_v2());
}
+TEST_F(TabletSchemaTest, SniiValuesIndexSelectsV2WithLegacyKeys) {
+ TabletSchemaPB pb;
+ pb.set_inverted_index_storage_format(InvertedIndexStorageFormatPB::SNII);
+ for (int32_t uid : {7, 8}) {
+ auto* column = pb.add_column();
+ column->set_name(uid == 7 ? "indexed" : "unindexed");
+ column->set_unique_id(uid);
+ column->set_type("VARIANT");
+ }
+ TabletSchema plain;
+ plain.init_from_pb(pb, false, true);
+
+ auto* values_index = pb.add_index();
+ values_index->set_index_id(70);
+ values_index->set_index_type(IndexType::INVERTED);
+ values_index->add_col_unique_id(7);
+ (*values_index->mutable_properties())["variant_index_scope"] = "values";
+
+ TabletSchema indexed;
+ indexed.init_from_pb(pb, false, true);
+ EXPECT_FALSE(indexed.variant_escape_dots_in_keys());
+ EXPECT_TRUE(indexed.column(0).variant_is_v2());
+ EXPECT_FALSE(indexed.column(1).variant_is_v2());
+ EXPECT_FALSE(plain.column(0).variant_is_v2());
+ EXPECT_EQ(&plain.column(1), &indexed.column(1));
+
+ TabletSchema copied;
+ copied.copy_from(indexed);
+ EXPECT_TRUE(copied.column(0).variant_is_v2());
+ auto rewrite = indexed.copy_without_variant_extracted_columns();
+ EXPECT_TRUE(rewrite->column(0).variant_is_v2());
+
+ TabletColumn indexed_column(pb.column(0));
+ TabletColumn other_column(pb.column(1));
+ TabletIndex incoming_index;
+ incoming_index.init_from_pb(*values_index);
+ OlapTableIndexSchema index_schema;
+ index_schema.columns = {&indexed_column, &other_column};
+ index_schema.indexes = {&incoming_index};
+ TabletSchema current;
+ current.build_current_tablet_schema(1, 2, &index_schema, plain);
+ EXPECT_TRUE(current.column(0).variant_is_v2());
+ EXPECT_FALSE(current.column(1).variant_is_v2());
+
+ pb.set_inverted_index_storage_format(InvertedIndexStorageFormatPB::V2);
+ TabletSchema old_format;
+ old_format.init_from_pb(pb, false, true);
+ EXPECT_FALSE(old_format.column(0).variant_is_v2());
+}
+
} // namespace doris
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_compaction.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_compaction.groovy
index 893f46aa82f..a354326f7b1 100644
---
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_compaction.groovy
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_compaction.groovy
@@ -46,7 +46,7 @@ suite("test_variant_values_index_compaction",
"p0,nonConcurrent") {
INDEX values_idx(v) USING INVERTED
PROPERTIES("variant_index_scope"="values","parser"="english"))
DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES("replication_num"="1","disable_auto_compaction"="true",
- "inverted_index_storage_format"="SNII")"""
+
"inverted_index_storage_format"="SNII","variant_escape_dots_in_keys"="false")"""
// Separate inserts create multiple rowsets. n promotes INT ->
DOUBLE -> STRING;
// stable wins the first rowset's one-subcolumn budget; n wins
the second.
// Rare paths also change across rowsets, exercising mixed
sparse/materialized input.
@@ -114,7 +114,7 @@ suite("test_variant_values_index_compaction",
"p0,nonConcurrent") {
INDEX path_idx(v) USING INVERTED
PROPERTIES("parser"="english"))
DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES("replication_num"="1","disable_auto_compaction"="true",
- "inverted_index_storage_format"="SNII")"""
+
"inverted_index_storage_format"="SNII","variant_escape_dots_in_keys"="false")"""
sql """INSERT INTO vvi_compaction_paths VALUES
(1,parse_to_variant('{"s":"hello"}'))"""
sql """INSERT INTO vvi_compaction_paths VALUES
(2,parse_to_variant('{"s":"other"}'))"""
sql """INSERT INTO vvi_compaction_paths VALUES
(3,parse_to_variant('{"s":"hello world"}'))"""
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
index 0971a7ec773..36c1dda9363 100644
---
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
@@ -87,7 +87,7 @@ suite("test_variant_values_index_ddl", "p0,nonConcurrent") {
rejected('VARIANT<PROPERTIES("variant_enable_nested_group"="true")>',
english, "SNII", "DUPLICATE", "",
"VARIANT values index does not support NestedGroup")
rejected("VARIANT<'wide':DECIMAL(76,2)>", english, "SNII", "DUPLICATE", "",
- "VARIANT values index does not support declared Decimal256 paths")
+ "Decimal256 is not supported in VARIANT templates")
rejected("VARIANT", english, "SNII", "UNIQUE",
',"enable_unique_key_merge_on_write"="false"',
"INVERTED index with parser can NOT be used in value columns of
UNIQUE_KEYS table with merge_on_write disable")
rejected("VARIANT", ',"analyzer"="english"', "SNII", "UNIQUE",
',"enable_unique_key_merge_on_write"="false"',
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_dotted_keys.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_dotted_keys.groovy
index 4aea2196c2a..444bb4efb19 100644
---
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_dotted_keys.groovy
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_dotted_keys.groovy
@@ -16,7 +16,7 @@
// under the License.
suite("test_variant_values_index_dotted_keys", "p0,nonConcurrent") {
- setFeConfigTemporary([enable_variant_v2: true]) {
+ setFeConfigTemporary([enable_variant_v2: true,
enable_variant_escape_dots_in_keys: true]) {
sql "SET enable_sql_cache=false"
sql "SET enable_query_cache=false"
sql "SET enable_condition_cache=false"
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_mow.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_mow.groovy
index 293c11338e7..91998830f83 100644
---
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_mow.groovy
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_mow.groovy
@@ -36,7 +36,7 @@ suite("test_variant_values_index_mow", "p0,nonConcurrent") {
INDEX values_idx(v) USING INVERTED
PROPERTIES("variant_index_scope"="values","parser"="english"))
UNIQUE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES("replication_num"="1","disable_auto_compaction"="true",
-
"enable_unique_key_merge_on_write"="true","inverted_index_storage_format"="SNII")"""
+
"enable_unique_key_merge_on_write"="true","inverted_index_storage_format"="SNII",
"variant_escape_dots_in_keys"="false")"""
def check = { String phase, List queries, boolean emit = true ->
sql "SYNC"
def results = []
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_mow_publish_conflict.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_mow_publish_conflict.groovy
new file mode 100644
index 00000000000..a2073505c85
--- /dev/null
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_mow_publish_conflict.groovy
@@ -0,0 +1,102 @@
+// 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.
+
+import org.awaitility.Awaitility
+import java.util.concurrent.TimeUnit
+
+suite("test_variant_values_index_mow_publish_conflict", "p0,nonConcurrent") {
+ // The local tablet metadata endpoint exposes the rowsets and their
segment counts.
+ if (isCloudMode()) {
+ return
+ }
+ setFeConfigTemporary([enable_variant_v2: true]) {
+ sql "SET debug_variant_enable_nested_group=false"
+ sql "SET debug_variant_enable_doc_mode=false"
+ sql "SET enable_sql_cache=false"
+ sql "SET enable_query_cache=false"
+ sql "SET enable_condition_cache=false"
+ sql "SET enable_match_without_inverted_index=false"
+ def tableName = "vvi_mow_publish"
+ def dbName = context.config.getDbNameByFile(context.file)
+ sql "DROP TABLE IF EXISTS ${tableName}"
+ sql """CREATE TABLE ${tableName}(id INT, a INT, b INT, v VARIANT,
+ INDEX values_idx(v) USING INVERTED
PROPERTIES("variant_index_scope"="values","parser"="english"))
+ UNIQUE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES("replication_num"="1","disable_auto_compaction"="true",
+ "enable_unique_key_merge_on_write"="true",
+
"inverted_index_storage_format"="SNII","variant_escape_dots_in_keys"="false")"""
+ sql """INSERT INTO ${tableName}
VALUES(1,0,0,parse_to_variant('{"s":"initial"}'))"""
+
+ def prepare = { String field, int value, String token ->
+ long txnId
+ streamLoad {
+ table tableName
+ set "format", "csv"
+ set "column_separator", "|"
+ set "columns", "id,${field},raw_v,v=parse_to_variant(raw_v)"
+ set "partial_columns", "true"
+ set "strict_mode", "false"
+ set "two_phase_commit", "true"
+ inputText """1|${value}|{"s":"${token}"}
+"""
+ time 10000
+ check { response, ex, start, end ->
+ assertNull(ex)
+ def result = parseJson(response)
+ assertEquals("Success", result.Status, response)
+ assertEquals(1L, result.NumberLoadedRows.toLong())
+ txnId = result.TxnId.toLong()
+ }
+ }
+ txnId
+ }
+ def commit = { long txnId ->
+ streamLoad {
+ table tableName
+ set "txn_id", txnId.toString()
+ set "txn_operation", "commit"
+ twoPhaseCommit true
+ inputText ""
+ time 10000
+ check { response, ex, start, end ->
+ assertNull(ex)
+ assertEquals("success",
parseJson(response).status.toLowerCase(), response)
+ }
+ }
+ Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(200,
TimeUnit.MILLISECONDS).until {
+ sql_return_maparray("SHOW TRANSACTION FROM ${dbName} WHERE ID
= ${txnId}")[0]
+ .TransactionStatus == "VISIBLE"
+ }
+ }
+
+ // Both loads flush before either is visible. The second publish has
to merge a from
+ // the first rowset with b and v from the second rowset and write a
replacement segment.
+ long first = prepare("a", 10, "first")
+ long second = prepare("b", 20, "second")
+ commit(first)
+ commit(second)
+ assertEquals([[10, 20]], sql("SELECT a,b FROM ${tableName} WHERE v
MATCH_ANY 'second'"))
+ assertEquals([], sql("SELECT id FROM ${tableName} WHERE v MATCH_ANY
'first'"))
+
+ def tablet = sql_return_maparray("SHOW TABLETS FROM ${tableName}")[0]
+ def (code, out, err) = curl("GET", tablet.MetaUrl +
"?byte_to_base64=true")
+ assertEquals(0, code, err)
+ def rewritten = parseJson(out).rs_metas.find { it.txn_id?.toLong() ==
second }
+ assertNotNull(rewritten, "rowset for transaction ${second}")
+ assertEquals(2L, rewritten.num_segments.toLong())
+ }
+}
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_sc_concurrent.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_sc_concurrent.groovy
index 4aae0253a03..39082e7eaab 100644
---
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_sc_concurrent.groovy
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_sc_concurrent.groovy
@@ -33,7 +33,7 @@ suite("test_variant_values_index_sc_concurrent",
"p0,nonConcurrent") {
INDEX tag_idx(v) USING INVERTED
PROPERTIES("field_pattern"="tag*","parser"="unicode"))
UNIQUE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES("replication_num"="1","disable_auto_compaction"="true","enable_unique_key_merge_on_write"="true",
- "inverted_index_storage_format"="SNII")"""
+ "inverted_index_storage_format"="SNII",
"variant_escape_dots_in_keys"="false")"""
sql """INSERT INTO vvi_sc_concurrent
VALUES(1,1,parse_to_variant('{"s":"old","tagA":"alpha"}')),
(2,2,parse_to_variant('{"s":"retained","tagA":"alpha"}'))"""
def point = isCloudMode() ?
"CloudSchemaChangeJob::_convert_historical_rowsets.block" :
"SchemaChangeJob::_convert_historical_rowsets.block"
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_schema_change.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_schema_change.groovy
index 382bfd80a4d..9d277d10c84 100644
---
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_schema_change.groovy
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_schema_change.groovy
@@ -122,7 +122,7 @@ suite("test_variant_values_index_schema_change",
"p0,nonConcurrent") {
INDEX path_idx(v) USING INVERTED
PROPERTIES("parser"="english","lower_case"="false"),
INDEX tag_idx(v) USING INVERTED
PROPERTIES("field_pattern"="tag*","parser"="unicode"))
DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
-
PROPERTIES("replication_num"="1","disable_auto_compaction"="true","inverted_index_storage_format"="SNII")"""
+
PROPERTIES("replication_num"="1","disable_auto_compaction"="true","inverted_index_storage_format"="SNII",
"variant_escape_dots_in_keys"="false")"""
sql """INSERT INTO vvi_sc_shape
VALUES(1,11,'old',parse_to_variant('{"s":"HELLO world","tagA":"alpha"}'))"""
def original = metadata("vvi_sc_shape")
def changes = [
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_sorted_schema_change.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_sorted_schema_change.groovy
new file mode 100644
index 00000000000..ca486574018
--- /dev/null
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_sorted_schema_change.groovy
@@ -0,0 +1,61 @@
+// 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_variant_values_index_sorted_schema_change", "p0,nonConcurrent") {
+ setFeConfigTemporary([enable_variant_v2: true]) {
+ sql "SET debug_variant_enable_nested_group=false"
+ sql "SET debug_variant_enable_doc_mode=false"
+ sql "SET enable_sql_cache=false"
+ sql "SET enable_query_cache=false"
+ sql "SET enable_condition_cache=false"
+ sql "SET enable_match_without_inverted_index=false"
+ sql "DROP TABLE IF EXISTS vvi_sorted_sc"
+ sql """CREATE TABLE vvi_sorted_sc(k1 INT, k2 INT, v VARIANT,
+ INDEX values_idx(v) USING INVERTED
PROPERTIES("variant_index_scope"="values","parser"="english"))
+ DUPLICATE KEY(k1,k2) DISTRIBUTED BY HASH(k1) BUCKETS 1
+ PROPERTIES("replication_num"="1","disable_auto_compaction"="true",
+
"inverted_index_storage_format"="SNII","variant_escape_dots_in_keys"="false")"""
+ sql """INSERT INTO vvi_sorted_sc VALUES
+ (1,2,parse_to_variant('{"s":"hello"}')),
+ (2,1,parse_to_variant('{"s":"other"}'))"""
+ assertEquals([[1, 2]], sql("SELECT k1,k2 FROM vvi_sorted_sc WHERE v
MATCH_ANY 'hello'"))
+
+ // Changing the key order runs the sorting rewrite, including the
intermediate rowset.
+ sql "ALTER TABLE vvi_sorted_sc ORDER BY (k2,k1,v)"
+ waitForSchemaChangeDone {
+ sql "SHOW ALTER TABLE COLUMN WHERE TableName='vvi_sorted_sc' ORDER
BY CreateTime DESC LIMIT 1"
+ time 120
+ }
+ assertTrue(sql("SHOW CREATE TABLE
vvi_sorted_sc")[0][1].contains("DUPLICATE KEY(`k2`, `k1`)"))
+ assertEquals([[1, 2]], sql("SELECT k1,k2 FROM vvi_sorted_sc WHERE v
MATCH_ANY 'hello'"))
+ assertEquals([[2, 1]], sql("SELECT k1,k2 FROM vvi_sorted_sc WHERE v
MATCH_ANY 'other'"))
+
+ // Removing the index and changing the key order in one rewrite leaves
the target
+ // without the V2 requirement. The read block must match that target
representation.
+ setFeConfigTemporary([enable_light_index_change: false]) {
+ sql "ALTER TABLE vvi_sorted_sc DROP INDEX values_idx, ORDER BY
(k1,k2,v)"
+ waitForSchemaChangeDone {
+ sql "SHOW ALTER TABLE COLUMN WHERE TableName='vvi_sorted_sc'
ORDER BY CreateTime DESC LIMIT 1"
+ time 120
+ }
+ assertEquals([], sql("SHOW INDEX FROM vvi_sorted_sc"))
+ assertEquals([[1, 2, "hello"], [2, 1, "other"]], sql("""
+ SELECT k1,k2,CAST(v['s'] AS STRING) FROM vvi_sorted_sc ORDER
BY k1,k2
+ """))
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]