[Enhancement] Constant LIKE/REGEXP pattern is recompiled for every clone of the expression (per scanner and per segment iterator)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- databases, performance
調査の方向性
Start from FunctionLike and FunctionRegexpLike in the backend expr code, where THREAD_LOCAL open compiles the pattern. Read VExprContext::clone and SegmentIterator::_construct_compound_expr_context to see per-clone opens. Implement FRAGMENT_LOCAL compilation storing state in FunctionContext, then reuse via hs_clone_scratch. Validate with the provided REGEXP SQL on a many-segment table; done when open phase no longer scales with segments.
索引モデルが issue の本文から書いたものです。
説明
Search before asking
- I had searched in the issues and found no similar issues.
Version
master (checked at 5b2c066b4d), branch-4.1, 4.1.5
What's wrong?
FunctionLike and FunctionRegexpLike build their state, including the Hyperscan database (hs_compile) or the RE2/Boost regex for a constant pattern, only in their THREAD_LOCAL open. VExprContext::clone opens THREAD_LOCAL again for every clone, and a pushed-down predicate is cloned once per scanner and once per segment iterator (SegmentIterator::_construct_compound_expr_context). A scan over N segments therefore compiles the same constant pattern about N times.
A case-insensitive alternation such as (?i)(alpha|bravo|...|juliet)[.](exe|dll)$ takes milliseconds to compile. On a table with about ten thousand segments, the open phase (SegmentIteratorInitTimer in the profile) dominates the query and costs minutes of CPU. Matching itself (ExprFilterEvalTime) stays in the tens of milliseconds.
LikeSearchState::clone, used by LikeColumnPredicate, also runs hs_prepare again for each clone.
What you expected to happen
A constant pattern is compiled once per fragment, and its clones reuse it.
How to reproduce
CREATE TABLE t (k BIGINT, s STRING) DUPLICATE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 64
PROPERTIES ('replication_num' = '1', 'disable_auto_compaction' = 'true');
-- 60 times:
INSERT INTO t SELECT number, concat('file', cast(number AS STRING), '.exe') FROM numbers('number' = '5000');
SELECT count(*) FROM t WHERE s REGEXP 'file1[.]exe$';
SELECT count(*) FROM t WHERE s REGEXP '(?i)(alpha|bravo|charlie|delta|echo|foxtrot|golf|hotel|india|juliet|file1)[.](exe|dll)$';
With about 3.9k rowsets on one BE, the second query takes about 150 ms against about 72 ms for the first: about 77 ms of compiling. With the change below, both take about 47 ms. The gap grows linearly with the segment count.
Anything else?
Proposed change:
- In the
FRAGMENT_LOCALopen, compile a constant pattern and store it as fragment state.FunctionContext::clone()already shares that state. - In the
THREAD_LOCALopen, share the fragment's Hyperscan database, which is read-only once compiled, and give each state its own scratch throughhs_clone_scratch. - Keep compiling RE2 and Boost per state, because RE2 locks its lazily built DFA cache on every search, so one shared RE2 would serialise matching across scanner threads.
- Non-constant patterns keep the current per-call path.
LikeSearchState::cloneshares the database the same way.
Scope: this applies to LIKE/REGEXP, the only functions that compile a single pattern with Hyperscan. regexp_count, regexp_replace, regexp_extract and split_by_regexp also compile per THREAD_LOCAL open, but they use RE2. Building an RE2 is much cheaper than hs_compile, and sharing one RE2 across clones would contend on its DFA cache lock, so they are better left compiling per clone.
Related: #68977
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
- 主要言語
- Java
- スター
- 16.2k
- フォーク
- 4k
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 679
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/doris のほかの issue
-
[Bug] array_sort's second comparator argument takes the first argument's name: a nested lambda reads the wrong argument, and alias functions sort nothing対応中かも @adarshomrey が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
apache/doris#69919 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/doris#69863 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] Upper-case hex in cloud initial rowset id is mis-parsed by BE from_hex (lossy, non-unique RowsetId)対応中かも @siddiqueirshad が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/doris#69371 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[Doc] 官方文档中 S3 路径风格访问参数错误 (s3.use_path_style)対応中かも @wy471x が 9 日前に担当しました。 オープン
難易度 2/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
[Bug] 资源包列表 与 模组/数据包/世界 列表排列顺序不一致対応中かも @fishdry1000 が 4 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
AtlasOfLivingAustralia/species-lists#882 ·
メンテナーはふだん 1 日以内に返信
-
Type/Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
ballerina-platform/ballerina-library#9458 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
winder/Universal-G-Code-Sender#3242 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
PCL-Community/PCL-CE#3767 ·
メンテナーはふだん 1 日以内に返信