[Enhancement] Constant LIKE/REGEXP pattern is recompiled for every clone of the expression (per scanner and per segment iterator)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- databases, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Java
- Star
- 16.2k
- Fork
- 4k
- Merge trung bình
- 1 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 640
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/doris
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
apache/doris#70013 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/doris#70000 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] array_sort's second comparator argument takes the first argument's name: a nested lambda reads the wrong argument, and alias functions sort nothingCó thể đã có người làm @adarshomrey đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
apache/doris#69919 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/doris#69863 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Upper-case hex in cloud initial rowset id is mis-parsed by BE from_hex (lossy, non-unique RowsetId)Có thể đã có người làm @siddiqueirshad đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/doris#69371 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
MCP add-on: JSON responses with non-ASCII characters are truncated (wrong Content-Length)Có thể đã có người làm @dhanushbs10 đã nhận hôm nay. Đang mởadd-on bug in:mcp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Map.Coordinate does not implement proper equalsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởvaadin-map
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
vaadin/flow-components#10586 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
WeReadInstaller writes the launcher database on the main thread at handover (Activity pause timeout)Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
wpilibsuite/SystemcoreTesting#446 ·
Maintainer thường phản hồi trong vòng 1 ngày