Repository navigation
[feature](inverted index) approximate gram index for LIKE/REGEXP push-down via ngram tokenizer mode=sparse|dense on SNII #67538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
5a8590e
[chore](be) remove the dangling NOLINTEND in core/types.h
airborne12 c5e5e1f
[feature](index) gram library: scheme, extractor, density solver, reg…
airborne12 789365d
[feature](index) gram-family analyzers and the SNII write path: docs-…
airborne12 6f68406
[feature](index) LIKE/REGEXP push-down through GRAM_BOOLEAN_QUERY wit…
airborne12 2223c91
[feature](fe) validate gram tokenizer properties, gram-family analyze…
airborne12 df58458
[test](regression) gram index suites: parity, recall, policy recovery…
airborne12 6cbfa99
[fix](be) skip analyzed MATCH queries on gram segments cut with a dif…
airborne12 356e0af
[fix](be) adaptive density: solve on the bytes the extractor cuts, fo…
airborne12 91b7021
[fix](be) fence dropped-posting dictionaries behind a required SNII f…
airborne12 098d41d
[test](be,regression) stop-gram suite proves a dropped entry reaches …
airborne12 4d251a8
[test](be,regression) pin which LIKE escape forms the index accelerat…
airborne12 c0d7588
[test](be,regression) drop the operand-order check, and stop the suit…
airborne12 f62da7d
[fix](fe) validate an omitted max_gram against the default the backen…
airborne12 001e556
[fix](be) gram compiler: refuse ill-formed UTF-8, and stop growing a …
airborne12 434df14
[fix](be) gram scheme fence covers MATCH_REGEXP and a segment with no…
airborne12 ab1fccb
[fix](be) record dropped postings per logical index, and charge the d…
airborne12 3c06bd2
[test](regression) give the inheritance suite's sparse column a needl…
airborne12 1eb8259
[test](regression) assert the stopped-posting inheritance phase inste…
airborne12 da80636
[test](regression) wait for a settled index size before comparing dro…
airborne12 55c5f7f
[fix](be) index declaration order no longer decides what LIKE, REGEXP…
airborne12 a88790d
[fix](be) gram scheme fence also covers a gram segment read under a s…
airborne12 801776f
[fix](be) SEARCH is never answered by a gram index, and analyzed EQUA…
airborne12 b6a69a3
[fix](be) numeric escapes that Boost reads differently no longer cons…
airborne12 0d076bf
[chore](be) correct the gram extractor benchmark notes and drop its R…
airborne12 16bd1d9
[test](regression) the stop-gram suite no longer changes a cluster-wi…
airborne12 df1d33e
[fix](be) LIKE and REGEXP hand gram index failures to the scan's fall…
airborne12 20a5df3
[fix](be) gram parser gives up on regex syntax the scalar engines rea…
airborne12 a737cc5
[test](regression) the pattern recall suite drops its engine table be…
airborne12 49fb7d6
[fix](be) gram parser gives up on signed repeat counts that Boost rea…
airborne12 566e62f
[fix](be) an index under a built-in normalizer declines gram queries …
airborne12 8951a98
[test](fe) gram-mode ngram tokenizers stay valid with the max_ngram_d…
airborne12 383d8a5
[chore](be) correct the ngram tokenizer factory comments after the ma…
airborne12 0975168
[fix](be) Preserve gram predicate operands and count final candidates
airborne12 908fcfe
[chore](be) Format SNII integration and simplify gram test setup
airborne12 fb488b9
[test](be) Match dynamic regex fallback expectations
airborne12 e2d34cb
[test](regression) Correct empty regex golden results
airborne12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <benchmark/benchmark.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| #include "storage/index/inverted/gram/gram_extractor.h" | ||
|
|
||
| namespace doris::segment_v2::gram::benchmark_detail { | ||
|
|
||
| // Fixed corpora make repeated builds directly comparable. Corpus 0 has many distinct | ||
| // ASCII grams, 1 represents repetitive log messages, and 2 includes UTF-8 boundaries. | ||
| inline std::string make_row(size_t size, int64_t corpus) { | ||
| std::string row; | ||
| row.reserve(size); | ||
| if (corpus == 0) { | ||
| uint64_t seed = 0x67538; | ||
| constexpr std::string_view alphabet = | ||
| "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :_=/.-"; | ||
| while (row.size() < size) { | ||
| seed = seed * 6364136223846793005ULL + 1442695040888963407ULL; | ||
| row.push_back(alphabet[(seed >> 32) % alphabet.size()]); | ||
| } | ||
| return row; | ||
| } | ||
| const std::string_view chunk = | ||
| corpus == 1 ? "2026-09-06 INFO rpc request completed service=Frontend latency_ms=17 " | ||
| : "2026-09-06 INFO 查询完成 service=Frontend 手机日志 latency_ms=17 "; | ||
| while (row.size() + chunk.size() <= size) { | ||
| row.append(chunk); | ||
| } | ||
| row.append(size - row.size(), 'x'); | ||
| return row; | ||
| } | ||
|
|
||
| inline uint64_t gram_digest(const std::vector<std::string_view>& grams) { | ||
| uint64_t hash = 14695981039346656037ULL; | ||
| for (auto gram : grams) { | ||
| for (unsigned char byte : gram) { | ||
| hash = (hash ^ byte) * 1099511628211ULL; | ||
| } | ||
| hash = (hash ^ 0xFF) * 1099511628211ULL; | ||
| } | ||
| return hash; | ||
| } | ||
|
|
||
| // fresh=0 reuses one extractor and its output buffer across rows, as the index writers do; | ||
| // fresh=1 constructs both for every row, a synthetic measure of per-row construction and | ||
| // allocation cost. Scheme fields other than mode and lower_case keep the GramScheme defaults | ||
| // in gram_scheme.h. This measures tokenization, not SQL throughput. | ||
| inline void GramExtraction(benchmark::State& state) { | ||
| GramScheme scheme; | ||
| scheme.mode = state.range(1) == 0 ? GramMode::DENSE : GramMode::SPARSE; | ||
| scheme.lower_case = state.range(2) != 0; | ||
| const std::string row = make_row(state.range(0), state.range(3)); | ||
| GramExtractor reused(scheme); | ||
| std::vector<std::string_view> grams; | ||
| reused.extract(row, &grams); | ||
| state.SetLabel("digest=" + std::to_string(gram_digest(grams))); | ||
| state.counters["grams_per_row"] = static_cast<double>(grams.size()); | ||
|
|
||
| for ([[maybe_unused]] auto _ : state) { | ||
| if (state.range(4) != 0) { | ||
| GramExtractor fresh(scheme); | ||
| std::vector<std::string_view> fresh_grams; | ||
| fresh.extract(row, &fresh_grams); | ||
| benchmark::DoNotOptimize(fresh_grams); | ||
| benchmark::ClobberMemory(); | ||
| } else { | ||
| reused.extract(row, &grams); | ||
| benchmark::DoNotOptimize(grams); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
| } | ||
| state.SetBytesProcessed(state.iterations() * static_cast<int64_t>(row.size())); | ||
| state.SetItemsProcessed(state.iterations()); | ||
| } | ||
|
|
||
| BENCHMARK(GramExtraction) | ||
| ->ArgsProduct({{128, 4096, 65536, 1048576}, {0, 1}, {0, 1}, {0, 1, 2}, {0, 1}}) | ||
| ->ArgNames({"bytes", "sparse", "lower_case", "corpus", "fresh"}); | ||
|
|
||
| } // namespace doris::segment_v2::gram::benchmark_detail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.