hello-stephen commented on code in PR #70593:
URL: https://github.com/apache/doris/pull/70593#discussion_r4750589361
##########
be/src/storage/index/inverted/snii/reader/logical_index_reader.cpp:
##########
@@ -1226,6 +1254,38 @@ Status LogicalIndexReader::visit_prefix_terms(
return Status::OK();
}
+Status LogicalIndexReader::dict_gram_candidates(std::string_view text,
+ std::vector<uint64_t>* blocks,
bool* known,
+ bool* any) const {
+ const RegionRef& ref = section_refs().dict_gram_summary;
+ size_t length = 0;
+ RETURN_IF_ERROR(checked_size(ref.length, "dict gram summary: length out of
range", &length));
+ std::vector<uint8_t> section;
+ RETURN_IF_ERROR(reader_->read_at(ref.offset, length, §ion));
Review Comment:
[P2] Preserve bounded expansion before loading the entire summary
A leading wildcard such as `*cache*` uses the default 50-term expansion
limit. If its first 50 matches fit in the first dictionary block, the previous
path stops there, but this call now allocates and reads the entire summary
first; `DictGramSummaryReader::open` also CRC-checks every byte and validates
every gram-table entry. A large retained summary can have a table exceeding 512
KiB, irrespective of how early the visitor stops. The local summary is
discarded on return, so every expansion repeats this work even with a warm file
cache. Keep limited expansions incremental, or reuse/range-read validated
summary data, and cover the bounded case with a test that counts summary bytes
as well as dictionary blocks.
##########
be/src/storage/index/inverted/snii/writer/logical_index_writer.cpp:
##########
@@ -710,6 +744,69 @@ Status
LogicalIndexWriter::build_streamed_dictionary(BlockState* state, PostingB
}
Status LogicalIndexWriter::flush_streamed_block(BlockState* state) {
+ RETURN_IF_ERROR(flush_streamed_block_bytes(state));
+ return fold_block_grams(state);
+}
+
+// Gives the summary up for this index and frees what it held. The summary is
optional: a build
+// that cannot afford it (the gram limit, or a reservation refused under a
memory cap) goes on
+// without it, and the dictionary is walked in full as before.
+void LogicalIndexWriter::abandon_gram_summary(BlockState* state) {
+ dict_gram_summary_enabled_ = false;
+ gram_summary_ = format::DictGramSummaryBuilder {};
+ gram_summary_reservation_.reset();
+ std::vector<uint32_t>().swap(state->gram_codes);
+ state->gram_set = format::DictGramSet {};
+ state->gram_codes_reservation.reset();
+}
+
+Status LogicalIndexWriter::collect_term_grams(std::string_view term,
BlockState* state) {
+ format::collect_dict_gram_codes(term, &state->gram_set,
&state->gram_codes);
Review Comment:
[P2] Reserve gram collection growth before allocating it
During native compaction, this call grows the gram set/vector before the
reservation below, and `fold_block_grams` similarly allocates map rows before
charging them. At the 32,769th distinct gram, `DictGramSet::grow` allocates a
new 512 KiB array while retaining the old 256 KiB array. A shared reporter near
its hard cap can therefore admit the smaller retained increase while the
replacement peak already exceeds the cap. These gram counts fit in an ordinary
64 KiB dictionary block; the cap/64 check and optional-summary fallback both
happen after allocation. Pre-reserve replacement and row-growth storage, and
omit the optional summary before allocating when that reservation fails.
--
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]