Repository navigation
fix(plan): skip unselective aggregate membership joins for match-all LIKE - #33222
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 7a070d336febfbea48f8a377b52d6e9fdd62d0a1
Assessment: request_changes
The change reuses the existing membership cost gate and preserves the original predicates. It resolves the earlier unconditional rejection of profitable small full-domain joins, but still loses a useful restriction when a match-all LIKE predicate is selective because its input contains NULLs. The copied estimate tree and integer bounds otherwise remain local to costing.
Model: gpt-6.1-terra / max
Session: 01a21136-dc54-7ba1-aace-4039c02570be · slot 2 · generation 3
- P2
pkg/sql/plan/aggregate_membership_domain.go:319: An otherwise eligible aggregate-membership domain has only a nullable column predicate such as name LIKE '%', and published statistics record a substantial NULL fraction.
Impact: The predicate rejects NULLs, but pricing it as the entire table can reject a profitable early semijoin and leave substantially more rows and groups for the aggregate. In the retained example, the prior rule selects the restriction and the new rule rejects it; a relational control reduces aggregate input from 100,000 to 40,000 rows while preserving the 20,000 resulting groups. This establishes extra work for that input, not a measured MatrixOne latency regression.
Evidence: For 10,000 domain rows with 8,000 NULL names, 4,500 total key values and 2,000 matching distinct keys, and 100,000 fact rows with 5,000 key values, the ordinary LIKE estimate is 2,000 rows (stats.go:1088), whereas this branch returns 10,000 despite the available NullCntMap. The base-rule and head planner overlays select and reject the semijoin respectively (base-nullable-planner.log and head-nullable-planner-retry.log; checks/1795599702453198953-2.json and checks/1795599704579025292-2.json). The independent SQLite input and result control is nullable-domain-probe.log (checks/1795598506930035496-2.json); the existing cost formula's saved/extra comparison is nullable-cost-model.log. Preserve the reliable non-NULL selectivity for a direct match-all LIKE, while keeping missing-statistics and more complex boolean cases conservative, and let the existing cost gate decide.
Validation:
-
Reviewed the full frozen diff, aggregate membership eligibility and costing, shared integer-span and outer-count consumers, SQL result fixtures, the linked issue, and all five discussion entries. The discussion ledger is discussion-assessment.json.
-
Private /tmp and loopback preflight passed (preflight.log; checks/1795598215801070229-2.json). The frozen diff passed git diff --check (diff-check.log; checks/1795598902746790231-2.json).
-
The focused planner fixture passed both with head production code and with the base aggregate-membership implementation overlaid on the same head checkout; their logs and receipts are named in the finding. The base overlay and head checkout provenance were verified separately (overlay-provenance.log; checks/1795599764355534585-2.json). Matching native inputs and builds are recorded in native-inputs.log, native-thirdparties.log and native-cgo.log.
-
The standalone SQLite relational control and the cost-formula calculation passed (nullable-domain-probe.log, nullable-cost-model.log; checks/1795598506930035496-2.json, checks/1795598884167409204-2.json).
-
The supplied head CI snapshot reports successful shared build, Ubuntu/x86 unit and coverage jobs, and multi-CN pessimistic BVT. The PR body separately reports SF0.1 service and BVT checks.
Limitations:
-
The planner check uses synthetic statistics and a base-rule overlay, not an independently built base release or a MatrixOne service benchmark. The SQLite control demonstrates relational work and result equality, not MatrixOne elapsed time or CPU.
-
The test receipts could not fingerprint the symlinked staging checkout because git diff timed out; the separate overlay-provenance check verified the head checkout, symlinked product source, overlay mappings and exact base rule. The native inputs were checked against the frozen head before building.
-
An initial probe failed because its directly replaced literal was not bound like a real predicate; it is retained in head-nullable-planner.log and is not a product failure. An earlier go list timed out during dependency downloads; the subsequent focused tests completed successfully. Broader SF10/SF100 qualification and the PR author's reported service runs were not independently reproduced.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 644ce25fee65e0327ab9fd9b84c940f9c069c9cd
Assessment: approve
The costing change retains the original SQL predicates, reuses the existing membership cost gate, and keeps integer-range re-estimation local to copied predicates. The shared integer-span helper preserves the outer-count type boundary. The prior small-domain and nullable match-all concerns are addressed; no actionable unresolved finding was identified. The linked issue remains open for broader performance qualification.
Model: gpt-6.1-terra / max
Session: 01a21136-dc54-7ba1-aace-4039c02570be · slot 2 · generation 3
Validation:
-
Private /tmp and loopback preflight passed. The frozen-source audit matched the complete patch and all discussion keys; 195 native inputs matched the diagnostic build (review-audit.stdout.log and corresponding checks receipts).
-
Sixteen selected Go planner tests passed with the assigned isolated executor, covering match-all and nullable costing, SQL plan reachability, integer range boundaries, ordinary filter ordering, and outer-count controls (planner-retry.stdout.log; checks/1795613675452203462-2.json).
-
The supplied exact-head CI snapshot reports successful Ubuntu/x86 unit tests and multi-CN pessimistic BVT; the snapshot does not include per-case logs.
Limitations:
-
The SF10/SF100 RAM and mixed-I/O performance qualification in issue #30843 was not reproduced and remains open. The author-reported SF0.1 service and mo-tester comparisons were not independently rerun here.
-
Initial Go setup attempts failed before testing because of a proxy timeout and a disabled toolchain checksum database; the Go 1.27.1 and focused-test retries succeeded.
🚫 Left the queue · pull request dequeued30 min in the queue, with no time running CI. So far
Reason Pull request #33222 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
To get back in the queue
Merge conditions not met when it left the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
Which issue(s) this PR fixes:
Related to #30843. The SF10/SF100 performance qualification remains open.
What this PR does / why we need it:
Q20 can benefit from restricting lineitem to qualifying part keys before SUM. With
p_name LIKE '%'on the TPC-H non-null column, every part qualifies. The generic LIKE estimate still credits an 80% reduction. The aggregate membership rule uses this discounted row count both to cap candidate key NDV and to price the hash build. A fixed-statistics Q20 plan estimated 4,000 surviving parts out of 20,000 and copied the part scan below SUM.The rule withholds the LIKE discount only for a conjunct proven true when its all-percent LIKE inputs are non-null. The cost model charges the full candidate scan. For a direct all-percent LIKE on a nullable column, a usable published NULL count can reduce the estimated rows entering the hash build. The rule uses the tightest row bound among top-level conjuncts without assuming their NULLs are independent. With missing or unusable statistics, or for more complex boolean expressions, it keeps the conservative estimate. A small table can eliminate fact keys even if every candidate row qualifies. For a single-column primary key, each surviving candidate row contributes one distinct key. If that primary key lacks usable NDV, the rule prices the build using the row bound supported by the direct LIKE statistics, or the whole table when no such bound is available. Whenever the rule removes a match-all discount, it caps the fact-key estimate by the usable integer range in the published statistics. This includes BIGINT ranges whose endpoints and inclusive width are exactly representable. Only while repricing the copied residual predicates, the rule handles one-sided comparisons on integer columns with usable statistics. It counts the covered integer values, respects open and closed endpoints, and scales nullable columns by their observed non-NULL fraction. The existing savings-versus-work comparison makes the final decision. SQL predicates and evaluation stay intact.
Local operator and result checks used separately built baseline and candidate services, the same dbgen SF0.1 input (600,572 lineitems), and full-scan statistics. The counts below come from the direct input to SUM and the aggregate output in native EXPLAIN ANALYZE.
LIKE 'forest%'LIKE '%'TRUEThe removed baseline join reported 11.08 MiB of operator memory. All six complete result sets matched an independent reference over the input files (9 rows for the selective pattern and 37 for each control).
Independent review found an overcorrection in the first revision. The final revision also preserves useful joins for nested boolean predicates. On identical copies of the persisted SF0.1 image, both baseline and candidate produced 473 aggregate input rows / 277 groups for
NOT (p_name LIKE '%') OR p_partkey < 100, 852 / 523 for(p_name LIKE '%' AND p_name LIKE 'forest%') IS TRUE, and 888 / 543 forp_name LIKE 'forest%' OR (p_name LIKE '%' AND p_partkey < 10). All result rows matched the reference. On the same image, a double negation of the all-percent pattern and a disjunction with that positive pattern both avoided the unproductive join.A follow-up review identified a missed opportunity when the complete candidate table itself is small. An additional native SF0.1 A/B ran the same Q20 against the full 20,000-key part table and a physical 1,000-key subset. With
LIKE '%'on the small table, the pre-fix planner sent 92,040 rows to SUM and formed 54,539 groups. The revised SEMI join sent 4,579 rows and formed 2,729 groups, and both returned the same 36 suppliers. Adding a covering key range gave the same reduction. This held both immediately after restart and after FULLSCAN. In the cold snapshot, the object statistics estimated 60,144 fact keys in the integer interval [1, 20,000] and supplied no key NDV for the small table. All eight plans per statistics state were run on both binaries. Their complete result bags matched an independent reference, and the six control plans kept their baseline aggregate input and output counts within each state.A post-push review exercised domains on the edge of the cost threshold. With two of 20,000 INT keys excluded, the previous revision built an 11.08 MiB SEMI join to avoid only 10 aggregate input rows. Equivalent one-sided predicates covering all keys avoided zero rows. With the same data stored as BIGINT, the full-domain cold plan built an 11.15 MiB SEMI join and eliminated zero rows. The revised plans scan directly for all three cases and keep the useful SEMI join on the 1,000-key subset. Validation covers full, near-full and narrow ranges, inclusive and exclusive endpoints, and a nested disjunction. All 22 queries matched the independent result reference under both INT and BIGINT schemas, in cold and FULLSCAN states (88 executions).
A subsequent review found an ordinary scan could evaluate an invalid regular expression on a row that its range predicate had excluded on earlier versions. The revised range estimate is local to a deep copy used by the aggregate cost calculation. A normal scan keeps its original filter order for either SQL conjunct order. Both forms return rows 2 and 20, and a control that admits the invalid pattern still reports the expected error.
A further review found a direct all-percent LIKE can be selective on a nullable column. A native SF0.1 comparison used a 20,000-row candidate table with 16,000 NULL names, including 500 empty strings among the 4,000 non-NULL names. Before this fix the aggregate received 92,040 rows and produced 54,539 groups. The revised SEMI join delivered 18,248 rows and produced 10,888 groups, matching the equivalent IS NOT NULL control. Both returned the same 37 supplier rows. The same holds when the candidate table contains duplicate qualifying keys. A zero-NULL control kept the direct scan. All 11 queries matched the independent result reference on both binaries immediately after restart and after FULLSCAN.
%and%%. The selective and TRUE controls passed.The local Darwin/arm64 run measures operator work and checks results. SF10/SF100 RAM and mixed-I/O, balanced whole-query latency and CPU, and the full Q1–Q22 comparison require the matching Linux benchmark environments.