This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new e96a1ccc33e branch-4.1: [improvement](inverted index) Let explicit
norms override the VARIANT default (#71253)
e96a1ccc33e is described below
commit e96a1ccc33eb6b1f04fe41d7483cf91e7d237ed5
Author: lihangyu <[email protected]>
AuthorDate: Sat Dec 5 21:45:13 2026 +0800
branch-4.1: [improvement](inverted index) Let explicit norms override the
VARIANT default (#71253)
cherry-pick #71163
---
be/src/common/config.cpp | 4 ++--
.../storage/compaction/collection_statistics.cpp | 3 ++-
.../index/inverted/inverted_index_parser.cpp | 13 ++++++++++-
.../storage/index/inverted/inverted_index_parser.h | 10 ++++++---
.../index/inverted/inverted_index_writer.cpp | 13 +----------
.../storage/segment/inverted_index_writer_test.cpp | 26 +++++++++++++++-------
.../doris/analysis/InvertedIndexProperties.java | 4 ++--
.../test_variant_subcolumn_index_norms.out | 3 +++
.../test_variant_subcolumn_index_norms.groovy | 17 +++++++++-----
9 files changed, 59 insertions(+), 34 deletions(-)
diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp
index 38e25b51ea3..b151dbcaacf 100644
--- a/be/src/common/config.cpp
+++ b/be/src/common/config.cpp
@@ -1376,8 +1376,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/compaction/collection_statistics.cpp
b/be/src/storage/compaction/collection_statistics.cpp
index 6e89aa157b2..5aa13537570 100644
--- a/be/src/storage/compaction/collection_statistics.cpp
+++ b/be/src/storage/compaction/collection_statistics.cpp
@@ -681,7 +681,8 @@ Status CollectionStatistics::process_segment(const
RowsetSharedPtr& rowset, int3
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 with no explicit norms setting, when "
+ "inverted_index_skip_norms_for_variant is on",
seg_path, StringHelper::to_string(ws_field_name));
}
// Missing term totals imply one token per row for keyword and
lowercase indexes.
diff --git a/be/src/storage/index/inverted/inverted_index_parser.cpp
b/be/src/storage/index/inverted/inverted_index_parser.cpp
index 2a5ac6119c6..bbf9cade313 100644
--- a/be/src/storage/index/inverted/inverted_index_parser.cpp
+++ b/be/src/storage/index/inverted/inverted_index_parser.cpp
@@ -124,10 +124,21 @@ 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;
}
+ // 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;
+ }
return true;
}
diff --git a/be/src/storage/index/inverted/inverted_index_parser.h
b/be/src/storage/index/inverted/inverted_index_parser.h
index 43a15b1fa4f..d9e91667d6d 100644
--- a/be/src/storage/index/inverted/inverted_index_parser.h
+++ b/be/src/storage/index/inverted/inverted_index_parser.h
@@ -33,6 +33,8 @@ class Analyzer;
namespace doris {
+class TabletIndex;
+
enum class InvertedIndexParserType {
PARSER_UNKNOWN = 0,
PARSER_NONE = 1,
@@ -156,9 +158,11 @@ 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(
const std::map<std::string, std::string>& properties);
diff --git a/be/src/storage/index/inverted/inverted_index_writer.cpp
b/be/src/storage/index/inverted/inverted_index_writer.cpp
index f3f4c1fd7f4..404af9c0ba0 100644
--- a/be/src/storage/index/inverted/inverted_index_writer.cpp
+++ b/be/src/storage/index/inverted/inverted_index_writer.cpp
@@ -162,18 +162,7 @@ Status
InvertedIndexColumnWriter<field_type>::create_field(lucene::document::Fie
(*field)->setOmitTermFreqAndPositions(
!(get_parser_phrase_support_string_from_properties(_index_meta->properties()) ==
INVERTED_INDEX_PARSER_PHRASE_SUPPORT_YES));
- // An analyzed index writes norms unless its "norms" property says
otherwise. Norms cost one byte
- // per segment row, including rows without a value, and 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 their norms can
dwarf the data.
- // inverted_index_skip_norms_for_variant drops norms for those indexes
whatever their property
- // says, so that a cluster can reclaim that space without rewriting its
index definitions.
- const bool variant_path_index =
- !_index_meta->get_index_suffix().empty() ||
!_index_meta->field_pattern().empty();
- const bool skipped_by_config =
- variant_path_index &&
config::inverted_index_skip_norms_for_variant;
- if (_should_analyzer && !skipped_by_config &&
- get_index_norms_from_properties(_index_meta->properties())) {
+ if (_should_analyzer && should_write_index_norms(*_index_meta)) {
(*field)->setOmitNorms(false);
}
DBUG_EXECUTE_IF("InvertedIndexColumnWriter::create_field_v3", {
diff --git a/be/test/storage/segment/inverted_index_writer_test.cpp
b/be/test/storage/segment/inverted_index_writer_test.cpp
index f3f15ad4c9c..363b880def9 100644
--- a/be/test/storage/segment/inverted_index_writer_test.cpp
+++ b/be/test/storage/segment/inverted_index_writer_test.cpp
@@ -1703,8 +1703,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");
@@ -1713,12 +1712,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_*"}});
@@ -1732,6 +1730,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 451e65d9c52..0810776ee7d 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/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/test_variant_subcolumn_index_norms.groovy
b/regression-test/suites/inverted_index_p0/test_variant_subcolumn_index_norms.groovy
index 70e9c612808..56d8cfc4e5b 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]