Repository navigation
fix: normalize per-column IN/NOT IN/=/<> domains in scan filters - #24229
8 commits merged into
Conversation
Generalize the single-table scan filter rewrite into `normalizeColumnDomain`: merge positive points (IN / =), negative points (NOT IN / <>), and IS NULL per column, then emit a single canonical IN / = / FALSE. The outer domain is also propagated into OR branches and nested NOT(IN), which is the main bigsql optimization case. BETWEEN is left as-is; list-with-NULL and cross-column predicates are skipped to preserve 3-valued logic. Fixes: matrixorigin#24227 Co-Authored-By: Claude Opus 4.7 <[email protected]>
PR #24229 测试覆盖分析变更摘要本次 PR 对 SQL 优化器的单表扫描过滤条件(scan filters)进行了归一化处理,主要在 6 类测试覆盖情况
图例: ✅ 已覆盖 建议BVT 测试建议: -- IN + NOT IN
SELECT * FROM t1 WHERE col IN (1,2,3) AND col NOT IN (2);
-- IN + <>
SELECT * FROM t1 WHERE col IN (1,2,3) AND col <> 3;
-- IN + IN
SELECT * FROM t1 WHERE col IN (1,2,3) AND col IN (2,3,4);
-- IN + IS NULL
SELECT * FROM t1 WHERE col IN (1,2) AND col IS NULL;
-- IN + OR + NOT IN
SELECT * FROM t1 WHERE col IN (1,2,3) AND (col = 1 OR col NOT IN (2));每个 case 需验证结果与预期一致,建议对比 MySQL 行为。 大数据测试建议: SELECT COUNT(*) FROM big_table WHERE col IN (100,200,300,400,500) AND col NOT IN (200,400);
SELECT COUNT(*) FROM big_table WHERE col IN (100,200,300) AND col <> 300;用于验证大数据下谓词规约的正确性和执行效率。 🤖 自动生成的测试 PR❌ BVT PR 提交失败:command failed (exit 1): gh pr create --repo matrixorigin/matrixone --base main --head Ariznawlll:auto/bvt-scan_filter_in_notin_domain_normalization-pr24229 --title test(bvt): 验证 Table Scan filter IN/NOT IN/<> 组合的 domain 归一化优化效果 (from PR #24229) --body Auto-generated BVT cases for matrixone PR #24229. 说明: 验证 Table Scan filter IN/NOT IN/<> 组合的 domain 归一化优化效果 新增文件:
由 auto-test-pr bot 自动生成,请人工 review 后合并 由 AI Test Analyzer 自动生成 · workflow run |
- UT: outer IN(..,NULL) must not collapse `<>`/NOT IN against the nullable domain; cast(uint8 as int64) <> 256 must not shrink the uint8 IN domain; cast(uint8 as int64) = -1 must not poison the point set. - BVT: make the cross-column case actually exercise `b <> v` (previous data could not distinguish the predicate being dropped); add `NOT IN (..,NULL)` variants (top-level and under OR) to lock 3-valued-logic semantics end-to-end. Co-Authored-By: Claude Opus 4.7 <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
issue #24227
What this PR does / why we need it:
Generalize the single-table scan filter rewrite into
normalizeColumnDomain(
pkg/sql/plan/expr_opt.go). For each column referenced by a scan'sFilterList, we now collect constant-domain predicates and merge them into onecanonical expression:
col IN S1 AND col IN S2→col IN (S1 ∩ S2)col = v AND col IN S→col = v(orFALSE)col IN S1 AND col NOT IN S2→col IN (S1 \ S2)col IN S1 AND col <> v1 AND col <> v2 ...→col IN (S1 \ {v1, v2, ...})col IN S AND col IS NULL→FALSEFALSEINdomain is also propagated into OR branches and nestedNOT(IN)so that
col IN S1 AND (col = 'x' OR col NOT IN S2)collapses the innerNOT INintoIN (S1 \ S2)— the main bigsql scenario.Preserves 3-valued logic:
NOT IN/<>rewrites only kick in when they situnder an outer
col IN S, since the outerINalready excludes NULL.Lists containing NULL, non-constant lists,
BETWEEN, and cross-columnpredicates are left untouched.
UT:
pkg/sql/plan/filter_domain_test.gocovers<>→ difference IN=+ IN → single=Local checks:
go test ./pkg/sql/plan/ -count=1,make,make static-checkall pass.