airborne12 opened a new pull request, #70968:
URL: https://github.com/apache/doris/pull/70968
### Background
SNII writes BM25 norms, one byte per row, for every analyzed index with
positions
(`support_phrase`). Since #70883 an index can instead hold a sparse norms
section that stores
the norms of the non-NULL rows only, or one norm that all of them share, and
every reader reads
back the bytes a dense section holds. The writer chose that form only behind
a debug point. A
VARIANT column has one logical index per indexed path, so a segment stores
one byte per row for
each path, also where the path is NULL.
### What problem does this PR solve?
Issue Number: None
Related PR: #70883 (adds the sparse norms format and reader), #68039 (lets
users drop norms on VARIANT paths, at the cost of score())
PR Type: Performance
Problem Summary:
On a VARIANT column with sparse paths, the norms of the NULL rows make up
most of an SNII index.
This PR makes the writer keep the smaller of the dense and sparse norms for
every SNII index, so
loads and compactions write sparse norms when they are smaller; BM25 scores
do not change. It
also charges the memory that the first load of sparse norms reads to the
loading task, which
the review of #70883 found untracked. After an upgrade, existing segments
keep their dense norms
and new segments of such indexes are smaller.
### Details
- **Change map:** 405 changed lines: 41 of production code, 80 of unit
tests, 119 of a
regression test, and 165 of its generated `.out` file.
- Writer (7): `LogicalIndexWriter::build_norms_section` compares the two
forms for every
index, not only behind a debug point. The debug point
`LogicalIndexWriter::build_norms_section.dense_norms` keeps dense norms,
for tests that
compare both forms.
- Reader (34): `read_sparse_norms` charges the section and the null bitmap
(its frame and its
decoded form) to the current task while the load runs, with a small RAII
helper
`TaskMemoryCharge`.
- **Why it was slow:** each SNII index with norms stores `doc_count` bytes,
NULL rows included,
and a segment holds one such index per indexed VARIANT path. A path
present in 2% of the rows
still stores a byte for every row.
- **Optimization:** the writer computes the size of the dense and the sparse
section and writes
the sparse one only when it is strictly smaller; a tie keeps the dense
form. The sparse section
and the null bitmap that the reader reads before expanding the norms are
plain allocations,
and the searcher cache charge covers only the expanded bytes, so the
reader now charges them
to the task with `CONSUME_THREAD_MEM_TRACKER`, as
`collection_statistics.cpp` does for the null
docids it reads from SNII.
- **Results:** on a local RELEASE build of this branch, 1,000,000 rows of a
VARIANT column with
50 text paths, each present in 2% of the rows, under one SNII index
(`english`,
`support_phrase`), in one segment:
| | dense norms forced | this PR |
|---|---|---|
| index file (`INDEX_DISK_SIZE`) | 57,578,333 B | 8,578,470 B (-85.1%) |
| `stats_bytes` of the 50 paths (`index_disk_usage`) | 50,004,640 B |
1,004,787 B |
| data file | 113,005 B | 113,005 B |
`score()` of `MATCH_ANY` on one path returns the same 13,333 rows with the
same scores on both
tables.
- **Applicability and cost:** only SNII indexes that write norms change, and
only when the sparse
section is smaller: enough NULL rows, or one norm shared by every non-NULL
row. Any other index
keeps its dense section byte for byte. Writing costs one more scan over
the norms of each index.
The first scoring load of a sparse index expands it once, as before, and
now charges up to the
section and null bitmap sizes to the task during that load.
- **Behavior change:** new segments of the indexes above store their norms in
`SniiSectionRefsPB.sparse_norms` (field 6). A BE that predates #70883 sees
such an index as
having no norms: `MATCH` works and `score()` returns an error. Such a BE
also rewrites a
segment by copying the physical sections it knows, so it can drop a sparse
section placed
last in the container (an index without NULL rows and without a bloom
filter section). No
released version has SNII norms without #70883, provided #70883 is in
4.2.0.
### Testing
All BE unit tests ran on a local ASAN BE UT build of this branch with
`GLIBC_COMPATIBILITY=OFF`
(see Notes for Reviewers):
- With the tests switched to the writer's default path and before the writer
change, 8 cases
failed on their assertions (`SniiSparseNormsTest` 6, the
`IndexDiskUsageCollectorTest` and
`SniiIndexReaderAnalyzedQueryTest` sparse cases); they pass after it.
- `SniiSparseNormsTest.SparseNormsLoadIsChargedWhileItRuns` failed before
the reader change (a
peak charge of 0 bytes while the load read 53) and passes after it; the
charge returns to 0
once the load ends.
- `SniiWriterGoldenBytes.EnglishPhrase` and `UnicodePhrase` now pin both
forms: the default
digests moved (the corpus has 4 NULL rows among 12), and with dense norms
forced the digests
are the ones before this PR.
- Filter
`*Snii*:*snii*:*CollectionStatistic*:IndexDiskUsage*:*InvertedIndexWriter*:*NormsPod*:*NullBitmap*:*CoreMetadata*`:
1749 tests from 217 suites passed.
- Regression test
`inverted_index_p0/storage_format/test_storage_format_snii_sparse_norms` on a
local RELEASE cluster of this branch, `.out` generated by
`run-regression-test.sh -forceGenOut`:
a table written with dense norms forced and one written by default return
the same rows and
scores (30 rows, 3 different scores) on a text column and on a VARIANT
path, and the second
has smaller `stats_bytes` on both indexes (468 to 108 and 470 to 110
bytes).
- The size measurement in Details, on the same cluster.
- `build-support/check-format.sh` and `build-support/check-build-hygiene.sh`
passed.
`build-support/run-clang-tidy.sh` reports no finding on the changed lines;
the local clang-tidy
could not fully analyze the files.
- Not run: a cluster that mixes this BE with one that predates #70883.
### Notes for Reviewers
- Rollout: branch-4.2 has SNII norms (field 5) but not #70883, and 4.2.0 is
not released. If
4.2.0 shipped without #70883, a rolling upgrade from it would meet the two
cases in Behavior
change, so #70883 should be picked into branch-4.2 before 4.2.0.
- `snii/writer/memory_reporter.h` says the jemalloc hook already charges
SNII allocations to the
task. That hook was removed in #53794, so plain allocations are not
charged; this PR does not
change the writer side.
- Local environment: with `GLIBC_COMPATIBILITY=ON`, the unmodified base
fails to link
`doris_be_test` with the local ldb toolchain (duplicate `preadv` and
others from
`lance_symbol_versions.c`); the option changes link libraries only. The
regression cluster is
a RELEASE build because this worktree's `custom_env.sh` sets
`BUILD_TYPE=RELEASE`. The local
clang-tidy rejects `-Wno-c2y-extensions` from the clang 20 compile
database and misses
`sanitizer/asan_interface.h`.
### Release note
SNII inverted indexes that store BM25 norms (analyzed with `support_phrase`)
now store them only
for the non-NULL rows, or once when every row shares one, whenever that is
smaller. Indexes on
VARIANT paths that most rows lack become much smaller, for example 57.6 MB
to 8.6 MB for 50
paths each present in 2% of 1,000,000 rows. Scores do not change. A BE
without #70883 cannot
compute `score()` on segments written this way.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified: clang-tidy could not fully
analyze the changed
files with the local toolchain, BE UT ran with `GLIBC_COMPATIBILITY=OFF`,
the regression test
ran on a RELEASE build, and no mixed-version cluster was tested
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: code, tests, this description
- Human review: TODO(author)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]