Repository navigation
[4.2-dev] Reduce tombstone-heavy COUNT reads and prefer cache-local execution - #33307
Conversation
(cherry picked from commit ba7ce35)
(cherry picked from commit 8e3535a)
(cherry picked from commit 8a51afb)
(cherry picked from commit 4a07963)
(cherry picked from commit 5326a1c)
(cherry picked from commit 8eeb632)
(cherry picked from commit 3c2603e)
(cherry picked from commit 85fbc2a)
(cherry picked from commit 86e2b1e)
(cherry picked from commit b148ff5)
(cherry picked from commit d73896b)
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? |
|
This pull request is merged. |
|
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: c6fd4d86aaf49d8789bfa176c5daeaed81386a63
Assessment: approve
The backport reuses the existing snapshot, tombstone, cache and query-service owners for sealed-block counting and optional cache-aware placement. The prior probe-lifetime, accounting, integration-test and design-record concerns are resolved. No actionable defects were found.
Model: gpt-6.1-terra / max
Session: 01a21d47-1533-7fb1-84e0-377223542f45 · slot 0 · generation 25
Validation:
-
Twelve focused tests passed across the query client, storage engine, compiler, file service, object I/O and CN service: focused-tests.log and checks/1795795843178899065-3.json.
-
The public mixed-range SQL test passed on the current head, matching an ordinary scan with two sealed rows and three reader rows: public-starcount.log and checks/1795795908729381415-3.json.
-
The blocked-writer probe ownership test passed 100 race-detector repetitions: probe-race.log and checks/1795796077156315325-3.json.
-
Three accounting export and clone tests passed: accounting-clone-tests.log and checks/1795796149471695378-3.json.
-
Isolation preflight, native-input provenance verification and git diff --check passed. The final evidence and discussion audit passed after correcting its test selector: review-audit-retry.log and checks/1795796210240107892-3.json.
-
The frozen CI snapshot reports successful x86 unit-test and multi-CN BVT jobs; case-level selection was not available.
Limitations:
-
The author’s two-CN performance measurements and the original billion-row workload were not independently repeated.
-
The added distributed SQL case was not independently run with mo-tester; the focused public SQL integration test used one CN.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #33274. Backports #33293 to 4.2-dev.
What this PR does / why we need it:
When a heavy, unfiltered COUNT falls back to a per-block scan, sealed blocks can be counted from their metadata and the distinct deleted rows visible to the transaction. This avoids loading ordinary columns just to count surviving rows. The existing reader handles the other ranges.
A cold CN can run the scan on an eligible CN that has more of the sampled tombstone objects in its whole-file disk cache. Light queries skip peer discovery for cache probes. Sampling, node discovery and probing share a 100 ms budget. An inconclusive probe keeps the existing placement. Plans that need coordinator state, such as FOUND_ROWS() or a named-lock function, also keep their original placement.
The backport uses the 4.2 snapshot admission path, FIFO cache index and scheduler. The optional RPC uses the same wire identifiers as main. The original eleven commits retain their cherry-pick references. This PR is independent of the write-path and asynchronous-cache changes in #33295.
Design revision 1
This 4.2-dev backport addresses #33274. Both optimizations must return the row count that an ordinary scan would see in the same transaction. Implementation at 20c80f4171
Where the scan runs. The coordinator considers moving an otherwise local, single-table scalar count only when the transaction workspace is read-only and the plan can run remotely. Queries with uncommitted writes or coordinator-only expressions keep their original placement. The coordinator samples committed tombstone objects visible at the transaction snapshot. A selected peer restores the shipped transaction snapshot, waits for its local logtail, opens the relation and owns the complete scan. Final projection and output remain on the coordinator. Scan placement · Snapshot restoration
How the rows add up. For an unfiltered, ungrouped count, the existing fast path applies up to 5,000,000 estimated committed tombstone rows. Above that threshold, a singleton scope that owns the matching scan and aggregate can count sealed blocks from metadata. For each supported block, DistTAE reads the exact header row count and subtracts distinct, visible deleted offsets using the ordinary data source and the statement’s transaction offset. Memory, appendable and other ineligible ranges stay with the reader. Only after all sealed-block reads succeed does the scope replace the input ranges and give their subtotal to its
MergeGroup, which adds the remaining reader’s count once. An unsupported relation retains its existing execution path. A read error or cancellation discards the unfinished subtotal. Sealed-block count · Aggregate handoffWhat a cache probe owns. After ordinary snapshot admission, sampling, cache lookups and peer discovery share a 100 ms deadline. For a heavy count the coordinator compares at most 16 sampled object IDs against the whole-file disk-cache index on the local CN and up to three eligible peers. A unique best score above the local score wins. A tie for best, a missing reply, a busy or unsupported peer, or an expired probe budget keeps the original placement. Query cancellation propagates. Each query client allows one outstanding write per peer address for these probes. Before enqueue, the client recycles a rejected request and releases any slot it acquired. After enqueue, the writer owns both until the write completes, fails or is skipped. The caller can stop waiting as soon as its context expires. Selection · Request ownership
What happens if the selected CN fails. Once the scheduler selects a peer, the ordinary remote pipeline owns execution. Connection, send, execution and receive failures use its cleanup and error path. A peer failure does not trigger a local rerun or reuse a partial count. Only the existing statement retry policy can start a fresh execution attempt. The optional internal RPC uses the same method and request/response field numbers as main (47, 49 and 50). Cache eviction after a probe can cost extra reads, but transaction visibility still determines the result. Remote execution · Retry policy
Acceptance. The mixed-range SQL regression checks two sealed rows plus three workspace rows against an ordinary scan. The blocked-writer regression cancels one probe and verifies that 16 further probes to the same peer leave the queue bounded. The two-CN measurements below check placement and object-store reads on the same data. SQL regression · Blocked-writer regression
Local design review accepted revision 1 for this backport.
Local verification on 4.2-dev
Two CNs used separate local caches and the same MinIO bucket. The fixture had 6,291,456 source rows and 6,285,165 visible rows after updates and deletion. The table reports median COUNT latency across three runs per case. Both CNs restarted for each measurement with A's warm disk cache restored and B's cache empty. The billion-row nightly workload was not run.
For cold ingress, shared object-store reads across both CNs fell from 79.2 MiB to 3.7 KiB. Scan metrics confirmed that B placed the eligible COUNT on A.