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 452aeb76b20 branch-4.2: [improvement](inverted index) Let explicit
norms override the VARIANT default (#71254)
452aeb76b20 is described below
commit 452aeb76b20bd3fcad4383232adc881dc66811b8
Author: lihangyu <[email protected]>
AuthorDate: Sat Dec 5 21:46:41 2026 +0800
branch-4.2: [improvement](inverted index) Let explicit norms override the
VARIANT default (#71254)
cherry-pick #71163
---
be/src/common/config.cpp | 4 ++--
.../inverted/analysis/inverted_index_parser.cpp | 18 +++++++++------
.../inverted/analysis/inverted_index_parser.h | 8 +++----
.../inverted/reader/collection_statistics.cpp | 7 +++---
.../snii_compaction_eligibility_test.cpp | 16 ++++++++++---
.../index/inverted/snii/snii_writer_test.cpp | 10 ++++++---
.../storage/segment/inverted_index_writer_test.cpp | 26 +++++++++++++++-------
.../doris/analysis/InvertedIndexProperties.java | 4 ++--
.../test_storage_format_snii_norms.out | 4 ++++
.../test_variant_subcolumn_index_norms.out | 3 +++
.../test_storage_format_snii_norms.groovy | 17 ++++++--------
.../test_variant_subcolumn_index_norms.groovy | 17 +++++++++-----
12 files changed, 87 insertions(+), 47 deletions(-)
diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp
index 78eb7c84c15..764e5718eb9 100644
--- a/be/src/common/config.cpp
+++ b/be/src/common/config.cpp
@@ -1531,8 +1531,8 @@ DEFINE_mBool(inverted_index_ram_dir_enable, "true");
DEFINE_mBool(inverted_index_ram_dir_enable_when_base_compaction, "true");
// Norms cost one byte per segment row, including rows that hold no value for
the field. A segment
// holds one index per variant path, so writing norms for them costs rows *
paths bytes. Turn this on
-// to leave norms out of every index on a variant path, whatever its "norms"
property says; BM25
-// scoring (score()) on those indexes then fails.
+// to omit norms by default on variant paths; an explicit index "norms"
property takes precedence.
+// BM25 scoring (score()) on analyzed indexes written without norms then fails.
DEFINE_mBool(inverted_index_skip_norms_for_variant, "false");
// use num_broadcast_buffer blocks as buffer to do broadcast
DEFINE_Int32(num_broadcast_buffer, "32");
diff --git a/be/src/storage/index/inverted/analysis/inverted_index_parser.cpp
b/be/src/storage/index/inverted/analysis/inverted_index_parser.cpp
index ef2b34120c3..65fbe5cd378 100644
--- a/be/src/storage/index/inverted/analysis/inverted_index_parser.cpp
+++ b/be/src/storage/index/inverted/analysis/inverted_index_parser.cpp
@@ -124,18 +124,22 @@ std::string
get_parser_phrase_support_string_from_properties(
return INVERTED_INDEX_PARSER_PHRASE_SUPPORT_NO;
}
-bool get_index_norms_from_properties(const std::map<std::string, std::string>&
properties) {
+bool should_write_index_norms(const TabletIndex& index_meta) {
+ // An explicit index policy takes precedence: a cluster can skip norms by
default while
+ // retaining BM25 on variant paths that set "norms" = "true".
+ const auto& properties = index_meta.properties();
if (auto it = properties.find(INVERTED_INDEX_NORMS_KEY); it !=
properties.end()) {
return it->second == INVERTED_INDEX_PARSER_TRUE;
}
- return true;
-}
-
-bool should_write_index_norms(const TabletIndex& index_meta) {
+ // A field_pattern index, or a subcolumn copy carrying its path as the
index suffix, is one
+ // of possibly thousands in a segment. Without an explicit policy, let the
config save the
+ // rows * paths bytes that norms would otherwise occupy.
const bool variant_path_index =
!index_meta.get_index_suffix().empty() ||
!index_meta.field_pattern().empty();
- return !(variant_path_index &&
config::inverted_index_skip_norms_for_variant) &&
- get_index_norms_from_properties(index_meta.properties());
+ if (variant_path_index && config::inverted_index_skip_norms_for_variant) {
+ return false;
+ }
+ return true;
}
CharFilterMap get_parser_char_filter_map_from_properties(
diff --git a/be/src/storage/index/inverted/analysis/inverted_index_parser.h
b/be/src/storage/index/inverted/analysis/inverted_index_parser.h
index 80a9d6c0480..6ee6a564740 100644
--- a/be/src/storage/index/inverted/analysis/inverted_index_parser.h
+++ b/be/src/storage/index/inverted/analysis/inverted_index_parser.h
@@ -153,10 +153,10 @@ std::string get_parser_mode_string_from_properties(
std::string get_parser_phrase_support_string_from_properties(
const std::map<std::string, std::string>& properties);
-// Whether this index writes BM25 norms, which it does unless "norms" =
"false" says otherwise.
-// Norms cost one byte per row of the segment, including rows that have no
value for the field.
-bool get_index_norms_from_properties(const std::map<std::string, std::string>&
properties);
-
+// Whether an analyzed index writes BM25 norms: the one policy shared by every
index storage format
+// and by index compaction. Norms cost one byte per row of the segment,
including rows that have no
+// value for the field. An explicit "norms" property takes precedence. Without
it, an index writes
+// norms unless it is on a variant path while
inverted_index_skip_norms_for_variant is on.
bool should_write_index_norms(const TabletIndex& index_meta);
CharFilterMap get_parser_char_filter_map_from_properties(
diff --git a/be/src/storage/index/inverted/reader/collection_statistics.cpp
b/be/src/storage/index/inverted/reader/collection_statistics.cpp
index 8b121d52ad6..39ae233130c 100644
--- a/be/src/storage/index/inverted/reader/collection_statistics.cpp
+++ b/be/src/storage/index/inverted/reader/collection_statistics.cpp
@@ -127,8 +127,8 @@ Result<SniiScoringSegmentStats>
resolve_snii_scoring_segment(uint64_t index_doc_
return
ResultError(Status::Error<ErrorCode::INVERTED_INDEX_NOT_SUPPORTED, false>(
"SNII scoring requires positions and norms; this segment was
written without "
"positions or without norms. Norms are left out when the index
sets \"norms\" = "
- "\"false\" or, for a variant path, when
inverted_index_skip_norms_for_variant is "
- "on"));
+ "\"false\" or, for a variant path without an explicit norms
property, when "
+ "inverted_index_skip_norms_for_variant is on"));
}
return SniiScoringSegmentStats {.doc_count = index_doc_count,
.token_count = sum_total_term_freq};
@@ -761,7 +761,8 @@ Status CollectionStatistics::process_segment(const
RowsetSharedPtr& rowset, int6
return Status::Error<ErrorCode::INVERTED_INDEX_NOT_SUPPORTED>(
"BM25 scoring requires norms, but segment {} was written
without norms for "
"field {}. Norms are left out when the index sets
\"norms\" = \"false\" or, "
- "for a variant path, when
inverted_index_skip_norms_for_variant is on",
+ "for a variant path without an explicit norms property,
when "
+ "inverted_index_skip_norms_for_variant is on",
seg_path,
segment_v2::inverted_index::StringHelper::to_string(ws_field_name));
}
_total_num_tokens[ws_field_name] +=
diff --git
a/be/test/storage/index/inverted/snii/compaction/snii_compaction_eligibility_test.cpp
b/be/test/storage/index/inverted/snii/compaction/snii_compaction_eligibility_test.cpp
index 8d6641b13f7..73d24174d70 100644
---
a/be/test/storage/index/inverted/snii/compaction/snii_compaction_eligibility_test.cpp
+++
b/be/test/storage/index/inverted/snii/compaction/snii_compaction_eligibility_test.cpp
@@ -326,8 +326,8 @@ TEST(SniiCompactionEligibilityTest,
RespectsExplicitPhrasePolicyForDocsOnlySourc
"position shape");
}
-// The destination follows the norms policy shared with fresh writes: the
"norms" property, and on
-// a variant path inverted_index_skip_norms_for_variant, which wins over the
property.
+// The destination shares the fresh-write policy: an explicit "norms" property
takes precedence
+// over the default for variant paths supplied by
inverted_index_skip_norms_for_variant.
TEST(SniiCompactionEligibilityTest,
DestinationWritesNormsFollowSharedNormsPolicy) {
const bool original_skip_norms_for_variant =
doris::config::inverted_index_skip_norms_for_variant;
@@ -357,7 +357,17 @@ TEST(SniiCompactionEligibilityTest,
DestinationWritesNormsFollowSharedNormsPolic
doris::config::inverted_index_skip_norms_for_variant = true;
EXPECT_TRUE(writes_norms(plain_properties(), ""));
EXPECT_FALSE(writes_norms(plain_properties(), "v.s_host"));
- EXPECT_FALSE(writes_norms(norms_on, "v.s_host"));
+ EXPECT_TRUE(writes_norms(norms_on, "v.s_host"));
+ EXPECT_FALSE(writes_norms(norms_off, "v.s_host"));
+ EXPECT_FALSE(writes_norms(norms_off, ""));
+
+ auto pattern = plain_properties();
+ pattern["field_pattern"] = "s_*";
+ EXPECT_FALSE(writes_norms(pattern, ""));
+ pattern["norms"] = "true";
+ EXPECT_TRUE(writes_norms(pattern, ""));
+ pattern["norms"] = "false";
+ EXPECT_FALSE(writes_norms(pattern, ""));
doris::config::inverted_index_skip_norms_for_variant =
original_skip_norms_for_variant;
}
diff --git a/be/test/storage/index/inverted/snii/snii_writer_test.cpp
b/be/test/storage/index/inverted/snii/snii_writer_test.cpp
index 3cb36d89cd8..e98180a6f8b 100644
--- a/be/test/storage/index/inverted/snii/snii_writer_test.cpp
+++ b/be/test/storage/index/inverted/snii/snii_writer_test.cpp
@@ -669,8 +669,8 @@ TEST(SniiWriterAnalysis, MissingChineseDictionaryFailsInit)
{
}
// The writer follows the norms policy it shares with the CLucene writer and
SNII compaction: the
-// "norms" property, and on a variant path
inverted_index_skip_norms_for_variant, which wins over
-// the property.
+// explicit "norms" property takes precedence over the default for variant
paths supplied by
+// inverted_index_skip_norms_for_variant.
TEST(SniiWriterNorms, WritesNormsFollowSharedNormsPolicy) {
const bool original_skip_norms_for_variant =
doris::config::inverted_index_skip_norms_for_variant;
@@ -706,8 +706,12 @@ TEST(SniiWriterNorms, WritesNormsFollowSharedNormsPolicy) {
doris::config::inverted_index_skip_norms_for_variant = true;
EXPECT_TRUE(writes_norms({}, ""));
EXPECT_FALSE(writes_norms({}, "v.s_host"));
- EXPECT_FALSE(writes_norms({{"norms", "true"}}, "v.s_host"));
+ EXPECT_TRUE(writes_norms({{"norms", "true"}}, "v.s_host"));
+ EXPECT_FALSE(writes_norms({{"norms", "false"}}, "v.s_host"));
+ EXPECT_FALSE(writes_norms({{"norms", "false"}}, ""));
EXPECT_FALSE(writes_norms({{"field_pattern", "s_*"}}, ""));
+ EXPECT_TRUE(writes_norms({{"field_pattern", "s_*"}, {"norms", "true"}},
""));
+ EXPECT_FALSE(writes_norms({{"field_pattern", "s_*"}, {"norms", "false"}},
""));
doris::config::inverted_index_skip_norms_for_variant =
original_skip_norms_for_variant;
}
diff --git a/be/test/storage/segment/inverted_index_writer_test.cpp
b/be/test/storage/segment/inverted_index_writer_test.cpp
index f9f61527beb..74c64c1a0f7 100644
--- a/be/test/storage/segment/inverted_index_writer_test.cpp
+++ b/be/test/storage/segment/inverted_index_writer_test.cpp
@@ -1934,8 +1934,7 @@ TEST_F(InvertedIndexWriterTest,
NormsFollowIndexNormsProperty) {
&field_pattern_default))
<< "a field_pattern index must write .nrm by default too";
- // the config drops norms for a variant path index whatever its property
says, and leaves every
- // other index alone
+ // The config supplies the default for variant paths; an explicit property
takes precedence.
config::inverted_index_skip_norms_for_variant = true;
create_tokenized_index("variant_subcolumn_skipped", 5, true, "v.s_host");
@@ -1944,12 +1943,11 @@ TEST_F(InvertedIndexWriterTest,
NormsFollowIndexNormsProperty) {
&subcolumn_skipped))
<< "the config must drop .nrm for a variant subcolumn index";
- create_tokenized_index("variant_subcolumn_norms_on_skipped", 6, true,
"v.s_host",
- {{"norms", "true"}});
- TabletIndex subcolumn_norms_on_skipped = make_index_meta("v.s_host",
{{"norms", "true"}});
-
EXPECT_FALSE(check_norms_file_exists(path_prefix("variant_subcolumn_norms_on_skipped",
6),
- &subcolumn_norms_on_skipped))
- << "the config must win over norms = true on a variant subcolumn
index";
+ create_tokenized_index("variant_subcolumn_norms_on", 6, true, "v.s_host",
{{"norms", "true"}});
+ TabletIndex subcolumn_norms_on = make_index_meta("v.s_host", {{"norms",
"true"}});
+
EXPECT_TRUE(check_norms_file_exists(path_prefix("variant_subcolumn_norms_on",
6),
+ &subcolumn_norms_on))
+ << "norms = true must win over the config on a variant subcolumn
index";
create_tokenized_index("field_pattern_skipped", 7, true, "",
{{"field_pattern", "s_*"}});
TabletIndex field_pattern_skipped = make_index_meta("", {{"field_pattern",
"s_*"}});
@@ -1963,6 +1961,18 @@ TEST_F(InvertedIndexWriterTest,
NormsFollowIndexNormsProperty) {
check_norms_file_exists(path_prefix("plain_column_not_skipped",
8), &plain_not_skipped))
<< "the config must leave an ordinary column index alone";
+ create_tokenized_index("field_pattern_norms_on", 9, true, "",
+ {{"field_pattern", "s_*"}, {"norms", "true"}});
+ TabletIndex field_pattern_norms_on =
+ make_index_meta("", {{"field_pattern", "s_*"}, {"norms", "true"}});
+ EXPECT_TRUE(check_norms_file_exists(path_prefix("field_pattern_norms_on",
9),
+ &field_pattern_norms_on));
+
+ create_tokenized_index("variant_subcolumn_norms_off_config", 10, true,
"v.s_host",
+ {{"norms", "false"}});
+
EXPECT_FALSE(check_norms_file_exists(path_prefix("variant_subcolumn_norms_off_config",
10),
+ &subcolumn_norms_off));
+
config::inverted_index_skip_norms_for_variant =
original_skip_norms_for_variant;
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/InvertedIndexProperties.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/InvertedIndexProperties.java
index bac638e08e1..bb1fde8704d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/InvertedIndexProperties.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/InvertedIndexProperties.java
@@ -55,8 +55,8 @@ public class InvertedIndexProperties {
// Whether an analyzed index stores BM25 norms, which default to being
stored. Norms cost one
// byte per row of the segment for every indexed path, so the BE config
- // inverted_index_skip_norms_for_variant (off by default) can leave them
out for every index on
- // a variant path, which it does whatever this property says.
+ // inverted_index_skip_norms_for_variant (off by default) can omit them by
default on variant
+ // paths. An explicit norms property takes precedence over that BE default.
public static String INVERTED_INDEX_NORMS_KEY = "norms";
public static String INVERTED_INDEX_PARSER_IGNORE_ABOVE_KEY =
"ignore_above";
diff --git
a/regression-test/data/inverted_index_p0/storage_format/test_storage_format_snii_norms.out
b/regression-test/data/inverted_index_p0/storage_format/test_storage_format_snii_norms.out
index 069e7fc05ab..00d9aa0a028 100644
---
a/regression-test/data/inverted_index_p0/storage_format/test_storage_format_snii_norms.out
+++
b/regression-test/data/inverted_index_p0/storage_format/test_storage_format_snii_norms.out
@@ -19,6 +19,10 @@
1 0.3541
2 0.562
+-- !snii_config_explicit_norms_score --
+1 0.311
+2 0.5235
+
-- !snii_mixed_match --
1
2
diff --git
a/regression-test/data/inverted_index_p0/test_variant_subcolumn_index_norms.out
b/regression-test/data/inverted_index_p0/test_variant_subcolumn_index_norms.out
index a22a1151ed2..a5cfc27e1e2 100644
---
a/regression-test/data/inverted_index_p0/test_variant_subcolumn_index_norms.out
+++
b/regression-test/data/inverted_index_p0/test_variant_subcolumn_index_norms.out
@@ -11,6 +11,9 @@
1 0.5754
3 0.8714
+-- !config_explicit_norms_score --
+1 0.6931
+
-- !mixed_match --
1
2
diff --git
a/regression-test/suites/inverted_index_p0/storage_format/test_storage_format_snii_norms.groovy
b/regression-test/suites/inverted_index_p0/storage_format/test_storage_format_snii_norms.groovy
index 5b42a68e069..aae8c35276f 100644
---
a/regression-test/suites/inverted_index_p0/storage_format/test_storage_format_snii_norms.groovy
+++
b/regression-test/suites/inverted_index_p0/storage_format/test_storage_format_snii_norms.groovy
@@ -17,7 +17,7 @@
// SNII follows the same norms policy as the CLucene formats: an analyzed
index writes BM25 norms
// unless "norms" = "false", and inverted_index_skip_norms_for_variant drops
them for every index on
-// a variant path whatever the property says. BM25 scoring needs norms, so
score() on an index
+// a variant path only when "norms" is not specified. BM25 scoring needs
norms, so score() on an index
// without them fails, while MATCH filtering keeps working. Norms are not
visible from outside a
// SNII file, so this suite reads them off the queries: with norms, rows 1 and
2 match "alpha" once
// each and the three-token row 1 scores lower than the one-token row 2;
without norms, score()
@@ -117,8 +117,8 @@ suite("test_storage_format_snii_norms", "p0,nonConcurrent")
{
exception "written without"
}
- // with the config on, every index on a variant path leaves norms out,
even one that asks for
- // them, while an ordinary column index keeps them
+ // With the config on, variant paths omit norms by default. Explicit
norms=true keeps them,
+ // as does an ordinary column index without the property.
setBeConfigTemporary([inverted_index_skip_norms_for_variant: true]) {
sql "DROP TABLE IF EXISTS test_storage_format_snii_norms_config"
sql """
@@ -176,13 +176,10 @@ suite("test_storage_format_snii_norms",
"p0,nonConcurrent") {
"""
exception "written without"
}
- test {
- sql """
- select id, score() from test_storage_format_snii_norms_config
- where cast(vf["c_note"] as string) match_any "alpha" order by
score() desc limit 10
- """
- exception "written without"
- }
+ order_qt_snii_config_explicit_norms_score """
+ select id, round(score(), 4) from test_storage_format_snii_norms_config
+ where cast(vf["c_note"] as string) match_any "alpha" order by score()
desc limit 10
+ """
// segments with and without norms side by side, as while the config is
being turned on:
// MATCH still filters, and score() is refused rather than ranking the two
kinds differently
diff --git
a/regression-test/suites/inverted_index_p0/test_variant_subcolumn_index_norms.groovy
b/regression-test/suites/inverted_index_p0/test_variant_subcolumn_index_norms.groovy
index c0c37179e43..8d363aef954 100644
---
a/regression-test/suites/inverted_index_p0/test_variant_subcolumn_index_norms.groovy
+++
b/regression-test/suites/inverted_index_p0/test_variant_subcolumn_index_norms.groovy
@@ -17,7 +17,7 @@
// An analyzed index writes dense BM25 norms (.nrm, one byte per segment row),
on a variant path as
// on any other column, and "norms" = "false" drops them. Norms on a variant
path cost rows * paths
-// bytes, so inverted_index_skip_norms_for_variant leaves them out there
whatever the property says.
+// bytes, so inverted_index_skip_norms_for_variant leaves them out when
"norms" is not specified.
// This covers both an index declared with a field_pattern and a whole-column
// index on a VARIANT column, whose per-subcolumn copies inherit the
properties of the index they
// come from. BM25 scoring needs norms: score() on an index without them
fails, also while only
@@ -172,8 +172,8 @@ suite("test_variant_subcolumn_index_norms",
"p0,nonConcurrent") {
assertEquals(true, normsOf(normsBySuffix, "a_host"))
assertEquals(false, normsOf(normsBySuffix, "b_host"))
- // the skip is a dynamic BE config: with it turned on, every index on a
variant path leaves norms
- // out, even one that asks for them, while an ordinary column index is
untouched
+ // The dynamic BE config skips norms by default on variant paths. An
explicit norms=true
+ // overrides it, including on the subcolumn copies of a whole-column
VARIANT index.
setBeConfigTemporary([inverted_index_skip_norms_for_variant: true]) {
sql "DROP TABLE IF EXISTS test_variant_subcolumn_index_norms_config"
sql """
@@ -220,14 +220,21 @@ suite("test_variant_subcolumn_index_norms",
"p0,nonConcurrent") {
def configNorms =
normsBySuffixOf("test_variant_subcolumn_index_norms_config")
assertEquals(false, normsOf(configNorms, "s_host"))
- assertEquals(false, normsOf(configNorms, "c_host"))
+ assertEquals(true, normsOf(configNorms, "c_host"))
assertEquals(true, configNorms[""])
}
+ order_qt_config_explicit_norms_score """
+ select id, round(score(), 4)
+ from test_variant_subcolumn_index_norms_config
+ where cast(vf["c_host"] as string) match_phrase "alpha"
+ order by score() desc
+ limit 10
+ """
test {
sql """
select id, score()
from test_variant_subcolumn_index_norms_config
- where cast(vf["c_host"] as string) match_phrase "alpha"
+ where cast(v["s_host"] as string) match_phrase "alpha"
order by score() desc
limit 10
"""
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]