Repository navigation
Closed
Closed
Feature
Copy link
Labels
kind/performanceseverity/s0Active / top priority for current sprint. Owner has committed to working on it now.
Milestone
Description
Is there an existing issue for performance?
- I have checked the existing issues.
Environment
- Version or commit-id:
7821d21c72 - Branch:
optimize_filter_0711 - OS: Linux
- Scope: partition-state/workspace reads and ranges block-filter compilation
Details of Performance
Three confirmed paths preserve correctness but lose available early filtering and can scan substantially more in-memory rows, blocks, or object metadata than necessary.
-
Partition-state OR/disjunct filters
BasePKFilter.DisjunctsmakesNewMemPKFilterinvalid because the partition-state primary-key iterator accepts only one atomic predicate.- Reads therefore fall back to
NewRowsIterand scan all visible in-memory rows even when every OR branch is individually primary-key-filterable.
-
Large
PREFIX_INin workspace readsMemPKFilter.FilterVectorintentionally returns without filtering whenPREFIX_INcontains more than four prefixes.- This avoids repeated linear matching, but turns a selective prefix set into a full workspace scan.
-
All-or-nothing ranges compilation
readutil.CompileFilterExprsmarks the entire filter list as non-compilable when any one expression lacks a fast compiler implementation.- The supported predicates then also lose object/block-level fast filtering, causing avoidable metadata loads and block scans.
These are performance gaps, not correctness bugs: residual SQL filters still produce correct query results.
Expected Behavior
- OR/disjunct primary-key predicates should use a safe union-capable partition-state iterator, or an equivalent bounded batch filter, whenever all branches are supported.
- Large
PREFIX_INsets should use a scalable representation (for example, sorted prefixes with binary search/trie/range pruning) instead of disabling filtering. - Ranges compilation should retain all independently compilable fast filters and route only unsupported predicates through the slow evaluator.
Steps to Reproduce
- Create a table with a primary key and leave selective rows in the transaction workspace/partition state.
- Execute a predicate that produces
BasePKFilter.Disjuncts, such aspk = 1 OR pk = 1000000; observe that the partition-state path cannot use the primary-key iterator. - Execute
PREFIX_INwith more than four prefixes against workspace rows; observe thatMemPKFilter.FilterVectorskips early filtering. - Construct a
BlockFilterListcontaining both a compiler-supported predicate and one zonemappable but unsupported predicate; observeCompileFilterExprsreturncanCompile=falsefor the whole list.
Proposed Direction and Acceptance Criteria
- Extend the partition-state iterator contract to represent OR safely; do not pass an unsupported synthetic op into existing single-range iterators.
- Add scalable
PREFIX_INfiltering with bounded memory and explicit tests for 0, 1, 4, 5, and large prefix counts. - Split ranges filters into fast-compilable and slow-evaluated subsets while preserving AND semantics and fail-open behavior on compiler/filter errors.
- Add observability/tests for partition-state rows scanned, blocks selected, metadata/object loads, and fast-vs-slow compilation ratio.
- Verify correctness for NULLs, empty lists, overlapping prefixes, mixed OR branches, malformed filter state, and cancellation/error paths.
Additional information
This issue is the follow-up to the composite-key block-filter work in #21740. The current implementation deliberately keeps the three paths conservative to avoid false negatives; the goal is to remove the performance fallback without weakening that safety property.
Metadata
Metadata
Assignees
Labels
kind/performanceseverity/s0Active / top priority for current sprint. Owner has committed to working on it now.
Activity
fix: strengthen filter pushdown and PK pruning (#25596)
Ariznawlll commentedon Jul 13, 2026
已在官方最新
main完成白盒回归验证,结论是:#25588 描述的三项性能降级当前仍然存在,尚未修复。验证环境
matrixorigin/matrixonemain2865ed6cc8a39727b8b274bb52b88fe441d0b30cfix(plan): harden folded IN vectors for composite keys (#25641)de6438665。本轮增加了三个临时白盒复现测试。测试断言记录的是当前的降级行为,因此测试 PASS 表示问题被稳定复现,不表示问题已修复。
1. Partition-state OR/disjunct 退化
构造等价于以下 SQL 条件的 PK filter:
验证结果:
ConstructBasePKFilter可以生成两个BasePKFilter.Disjuncts;仓库现有TestConstructBasePKFilterWithOr也明确覆盖了eq OR eq生成 disjuncts 的真实路径。SortedSearchFunc和UnSortedSearchFunc。NewMemPKFilter时,返回的 filter 为Valid=false。NewRowsIter分支,不能使用 PK iterator 对 OR 分支做选择性读取。该路径不是只在手工构造 filter 时存在;实际 planner 的
eq OR eq会产生Disjuncts。2. Workspace 大
PREFIX_IN阈值退化构造 8192 个全部不匹配的 workspace PK 值,分别使用不同数量的
PREFIX_IN前缀调用MemPKFilter.FilterVector。skipMask提前过滤行数从 4 个前缀增加到 5 个前缀后,提前过滤从 8192 行突变为 0 行;5、64、1024 三种规模都会完整保留全部不匹配行,交给后续执行层继续处理。
Benchmark(每项
20x,重复 5 次)也得到同样结果:5/64 项在这个微基准里表面更快,是因为函数直接放弃了过滤;这不是查询性能提升,后续 workspace reader 会承担放大的扫描和残余表达式处理。
3. Mixed ranges filter 全有或全无
构造以下 AND 条件:
其中
pk = 999999是可快速编译的 PK 条件,abs(v) = 7作为不能由 ranges fast compiler 独立编译的残余条件。验证结果:
pk = 999999:canCompile=trueCompileFilterExprs([pk = 999999, abs(v) = 7]):canCompile=falsenil。[abs(v) = 7, pk = 999999]后结果相同。说明一个不可编译的表达式仍会导致已经可以编译的 PK fast filter 一并丢失,无法保留部分 object/block pruning。
稳定性和回归结果
聚焦复现测试:
Race 测试:
全包回归:
未发现数据竞争或结果正确性错误;确认的是三条 fast-path 的扫描放大问题。
最终判断
当前官方
main@2865ed6cc上:PREFIX_IN > 4仍会完全跳过 workspace 提前过滤;因此建议保持 issue Open。修复后的验收条件应分别为:OR 使用安全的 union/批量选择性 iterator;5+
PREFIX_IN正确生成 skip mask;mixed ranges 保留可独立编译的 fast filters,并由残余 SQL filter 继续保证最终语义。Ariznawlll commentedon Jul 13, 2026
@XuPeng-SH 鹏哥这个问题再看下
perf(readutil): preserve early filtering across fallback paths (#25853)
Ariznawlll commentedon Jul 20, 2026
最新验证结论
该问题已修复,可以关闭。
验证环境:
mainc838d312d7bd2f69c22a9c189d36dfde7a3dc307946427b87本次重新确认了 issue 中的三条路径:
PREFIX_IN > 4已使用排序前缀索引进行提前过滤,不再直接跳过 workspace fast filter。在上述最新 main commit 上执行定向测试:
测试结果:两组用例连续 3 轮均通过。
另外,相关 SQL 黑盒场景已加入 matrixorigin/motr#59,覆盖 OR、重叠范围、
PREFIX_IN > 4、NULL/重复前缀、落盘数据和事务 workspace 数据,连续 3 轮回归通过。fix: strengthen filter pushdown and PK pruning (matrixorigin#25596)
perf(readutil): preserve early filtering across fallback paths (matri…
fix: strengthen filter pushdown and PK pruning (matrixorigin#25596)
perf(readutil): preserve early filtering across fallback paths (matri…
fix: strengthen filter pushdown and PK pruning (matrixorigin#25596)
perf(readutil): preserve early filtering across fallback paths (matri…