This is an automated email from the ASF dual-hosted git repository.
eldenmoon 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 0716a101cc3 [improvement](inverted index) Let explicit norms override
the VARIANT default (#71163)
0716a101cc3 is described below
commit 0716a101cc370f386faad45483a3bbf5cda158f7
Author: lihangyu <[email protected]>
AuthorDate: Tue Dec 1 14:16:47 2026 +0800
[improvement](inverted index) Let explicit norms override the VARIANT
default (#71163)
---
be/src/common/config.cpp | 4 ++--
.../inverted/analysis/inverted_index_parser.cpp | 17 +++++++-------
.../inverted/analysis/inverted_index_parser.h | 5 ++---
.../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, 83 insertions(+), 47 deletions(-)
diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp
index 7e1fb1eb928..2a395568f0b 100644
--- a/be/src/common/config.cpp
+++ b/be/src/common/config.cpp
@@ -1529,8 +1529,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 c3bbc90447f..65fbe5cd378 100644
--- a/be/src/storage/index/inverted/analysis/inverted_index_parser.cpp
+++ b/be/src/storage/index/inverted/analysis/inverted_index_parser.cpp
@@ -125,19 +125,20 @@ std::string
get_parser_phrase_support_string_from_properties(
}
bool should_write_index_norms(const TabletIndex& index_meta) {
- // A variant path index (a field_pattern index, or the copy inherited by
one extracted
- // subcolumn, which carries the path as its index suffix) is one of
possibly thousands in a
- // segment, so its norms can dwarf the data. The config drops them
whatever the property says,
- // so that a cluster can reclaim that space without rewriting its index
definitions.
+ // 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;
+ }
+ // 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();
if (variant_path_index && config::inverted_index_skip_norms_for_variant) {
return false;
}
- 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;
}
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 9d7a766e59c..6ee6a564740 100644
--- a/be/src/storage/index/inverted/analysis/inverted_index_parser.h
+++ b/be/src/storage/index/inverted/analysis/inverted_index_parser.h
@@ -155,9 +155,8 @@ std::string
get_parser_phrase_support_string_from_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 index writes them unless its "norms" property is
"false", or unless it
-// is on a variant path while inverted_index_skip_norms_for_variant is on,
which wins over the
-// property.
+// 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 2e70c7cdbf4..4ba7099443b 100644
--- a/be/src/storage/index/inverted/reader/collection_statistics.cpp
+++ b/be/src/storage/index/inverted/reader/collection_statistics.cpp
@@ -128,8 +128,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};
@@ -757,7 +757,8 @@ Status CollectionStatistics::process_segment(const
RowsetSharedPtr& rowset,
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 8bda00f53cd..a8e6ed7e354 100644
--- a/be/test/storage/index/inverted/snii/snii_writer_test.cpp
+++ b/be/test/storage/index/inverted/snii/snii_writer_test.cpp
@@ -823,8 +823,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;
@@ -860,8 +860,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 c622e6c80a2..2f1b069c9d2 100644
--- a/be/test/storage/segment/inverted_index_writer_test.cpp
+++ b/be/test/storage/segment/inverted_index_writer_test.cpp
@@ -2269,8 +2269,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");
@@ -2279,12 +2278,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_*"}});
@@ -2298,6 +2296,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-catalog/src/main/java/org/apache/doris/analysis/InvertedIndexProperties.java
b/fe/fe-catalog/src/main/java/org/apache/doris/analysis/InvertedIndexProperties.java
index bac638e08e1..bb1fde8704d 100644
---
a/fe/fe-catalog/src/main/java/org/apache/doris/analysis/InvertedIndexProperties.java
+++
b/fe/fe-catalog/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 5f52500503f..02e4355a5ba 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 9b2cf745293..81fe752962b 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 57f3fc13f16..ee469ffa764 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()
@@ -116,8 +116,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 """
@@ -175,13 +175,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 edceac59aaf..00019d25c19 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
@@ -171,8 +171,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 """
@@ -219,14 +219,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]