Skip to content

[improvement](be) Prune rowsets by TSO before row binlog scans - #68050

Merged
morningman merged 1 commit into
apache:masterfrom
HappenLee:improvement/rowset-tso-pruning-master
Sep 16, 2026
Merged

morningman merged 1 commit into
apache:masterfrom
HappenLee:improvement/rowset-tso-pruning-master

Conversation

@HappenLee

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: #68012 (merged into branch-incremental-computation); this PR ports the same change to master.

Problem Summary:

Bounded ROW binlog queries initialize rowset readers and open segment footers before their TSO predicates reject historical data. A narrow time window can therefore pay initialization costs proportional to the retained history.

Prune the captured read source before cloning readers or creating scanners. For query [100, 200), a rowset with inclusive commit TSO range [10, 99] can be skipped using its metadata alone.

  • Preserve rowsets with unknown TSO endpoints and those that overlap the query window, including compacted rowsets. Existing segment/row predicates handle the remaining data.
  • Preserve the captured visible-version snapshot and separately captured delete predicates.
  • Skip a tablet when only empty rowsets remain, including bootstrap rowsets with no TSO. This also prevents a fully pruned source from being recaptured during scanner initialization.
  • Add RowsetTsoPruneTime, RowsetsPrunedByTso, SegmentsPrunedByTso, and TabletsPrunedByTso to the query profile.

The filtering uses std::erase_if on the existing rowset vector and std::all_of for the empty-tablet check. It adds no storage-format or protocol changes.

Release note

Reduce reader initialization and segment footer IO for bounded ROW binlog queries.

Check List (For Author)

  • Test
    • Regression test
    • Unit Test
    • Manual test (steps and results below)
    • No need to test or manual test.

Validation:

Current master port (base 060c7dbe81758fb0d673567fb361234d06b9a1b1):

  • Applied commit 93a3ceced9c4518d527c2b2d58ee328bb5960d03 without conflicts. Stable patch IDs match the source PR exactly.
  • Repository build-support/check-format.sh passed with clang-format 16.0.6.
  • build-support/check-build-hygiene.sh passed.
  • Source whitespace checks passed. The original, runner-generated regression .out is preserved unchanged, including its trailing blank line.
  • Builds, unit tests, regression tests, and clang-tidy have not been rerun on this master base.

Historical validation reported in #68012 for the original master-based implementation (cb73d23c873, based on 96d0ac68e84):

  • BE (ASAN) and FE built successfully with build.sh --be --fe -j 48.
  • All 8 tests in OlapScanOperatorTsoPruningTest and OlapScanOperatorBinlogPushDownTest passed under ASAN. Coverage includes half-open boundaries, single/no bounds, unknown metadata, overlapping compaction output, delete predicates, and empty-source EOS.
  • test_binlog_rowset_tso_pruning and test_binlog_changes_syntax passed. The new output was generated by the regression runner and then checked in a second run. Before-images, deletes, empty windows, and compaction results were verified.
  • clang-format 16, header hygiene, and clang-tidy passed.

Manual profile check: create a one-bucket UNIQUE KEY table with ROW binlog, historical values, and automatic compaction disabled; insert two rows in two separate transactions. Enable profiling and query @incr('startTimestamp'='2099-01-01 00:00:00', 'incrementType'='MIN_DELTA'). The empty result reported:

RowsetsPrunedByTso: 2
SegmentsPrunedByTso: 2
TabletsPrunedByTso: 1
NumScanners: 0
RowsRead: 0

This verifies that scanner initialization is skipped. No production latency improvement is claimed; rowset metadata synchronization and version capture still occur.

  • Behavior changed:

    • No. Query results are unchanged; profile counters are added.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: None

Related PR: apache#68012

Problem Summary: Bounded ROW binlog queries initialize readers and open segment
footers for historical rowsets before TSO predicates reject them. Prune the
captured version-consistent read source using inclusive rowset TSO metadata
and the query's half-open window. Preserve unknown metadata, overlapping
compaction output, and separately captured delete predicates. Skip scanners
when only empty rowsets remain, and expose pruning counters in the profile.

Port commit 93a3cec to master without conflicts;
the stable patch ID is unchanged.

### Release note

Reduce reader initialization and segment footer IO for bounded ROW binlog queries.

### Check List (For Author)

- Test: Manual test (port validation)
    - clang-format 16.0.6 repository check and BE header hygiene passed.
    - Source whitespace checks and stable patch-ID comparison passed.
    - Existing unit tests and generated regression fixtures are carried over.
    - Build, unit/regression tests, and clang-tidy were not rerun on this base.
    - Original PR records ASAN build, 8 unit tests, regression and profile validation.
- Behavior changed: No (query results unchanged; profile counters added)
- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@HappenLee

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review summary for exact head 6caf5fda1ed033214cf0642bc805904e7081da6c

Verdict: no actionable findings; I would approve this change.

  • Goal and scope: the patch is narrowly focused on pruning captured ROW-binlog rowsets by their inclusive commit-TSO envelope before reader cloning and segment-footer I/O. It also adds targeted profile counters and focused unit/regression coverage.
  • Correctness and lifecycle: the rowset disjointness test correctly coarse-filters the downstream half-open [start_tso, end_tso) predicate. Unknown legacy endpoints are retained. Pruning preserves separately captured delete predicates/bitmap and materialized before images; empty/bootstrap-only sources skip scanner construction and reach EOS correctly, while mixed-tablet scans retain their remaining scanners.
  • Compatibility and special paths: no configuration, FE-BE protocol, persisted format, or write/transaction behavior changes. Local/cloud publish paths, protobuf conversion, and normal/ordered compaction preserve conservative metadata envelopes. NONE, APPEND_ONLY, MIN_DELTA, and DETAIL use the same TSO coordinate and bounds.
  • Concurrency, performance, and observability: pruning is synchronous before scanner workers start and introduces no shared-state or lock-order change. The added work is linear in captured rowsets and can avoid reader clones/footer I/O; the timer and rowset/segment/tablet counters make the optimization visible.
  • Tests/results: the unit tests cover exact and one-sided boundaries, compacted overlaps, unknown metadata, captured delete state, and all-pruned EOS/bootstrap behavior. The regression covers DETAIL/MIN_DELTA before images and deletes, one-sided/empty windows, snapshots, and local compaction with deterministic ordered output. No additional user review focus was provided.

Validation note: this was a static-only review under the supplied contract; I did not run builds or tests. The PR reports validation for the original patch, but current-base execution was not independently rerun in this review.

@HappenLee

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.03% (29325/46524)
Line Coverage 47.95% (305865/637901)
Region Coverage 43.63% (247065/566300)
Branch Coverage 45.15% (114752/254166)

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 16866 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 6caf5fda1ed033214cf0642bc805904e7081da6c, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17570	3041	3068	3041
q2	2089	254	224	224
q3	10222	872	525	525
q4	4676	258	203	203
q5	7669	578	390	390
q6	139	120	95	95
q7	530	491	391	391
q8	9246	964	914	914
q9	3515	2398	2377	2377
q10	6536	867	709	709
q11	393	205	185	185
q12	610	261	201	201
q13	18117	1517	1168	1168
q14	158	154	140	140
q15	q16	443	392	366	366
q17	1418	881	790	790
q18	3114	2307	2259	2259
q19	1303	935	750	750
q20	397	285	202	202
q21	5740	1703	1854	1703
q22	328	272	233	233
Total cold run time: 94213 ms
Total hot run time: 16866 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3387	3326	3312	3312
q2	511	399	371	371
q3	2198	2345	2176	2176
q4	1200	1181	902	902
q5	2201	2115	2110	2110
q6	170	123	90	90
q7	1032	946	885	885
q8	1598	1405	1388	1388
q9	3154	3117	3128	3117
q10	1850	1789	1646	1646
q11	355	268	254	254
q12	453	437	351	351
q13	1490	1537	1169	1169
q14	176	179	156	156
q15	q16	400	394	358	358
q17	3570	3285	3213	3213
q18	4851	4501	4705	4501
q19	905	906	889	889
q20	996	983	819	819
q21	3833	3244	3155	3155
q22	402	344	318	318
Total cold run time: 34732 ms
Total hot run time: 31180 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 81681 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 6caf5fda1ed033214cf0642bc805904e7081da6c, data reload: false

query5	4262	408	344	344
query6	383	146	125	125
query7	4935	423	226	226
query8	288	125	118	118
query9	8690	2876	2911	2876
query10	410	220	200	200
query11	5377	1050	921	921
query12	116	69	69	69
query13	1187	457	323	323
query14	5982	2196	2071	2071
query14_1	1964	1938	1942	1938
query15	173	116	108	108
query16	908	336	335	335
query17	771	419	331	331
query18	2318	321	227	227
query19	156	132	109	109
query20	70	67	66	66
query21	207	99	93	93
query22	5432	5391	5329	5329
query23	6549	6237	6035	6035
query23_1	6029	6116	6207	6116
query24	7363	1084	739	739
query24_1	753	763	773	763
query25	401	272	220	220
query26	1229	235	120	120
query27	2795	406	241	241
query28	4724	1491	1497	1491
query29	902	412	322	322
query30	250	152	128	128
query31	820	402	330	330
query32	123	77	73	73
query33	450	209	175	175
query34	994	817	483	483
query35	404	406	342	342
query36	554	585	518	518
query37	124	76	69	69
query38	1003	831	825	825
query39	474	474	484	474
query39_1	459	476	465	465
query40	201	87	73	73
query41	53	51	51	51
query42	77	71	75	71
query43	253	244	213	213
query44	999	542	537	537
query45	111	101	103	101
query46	774	837	530	530
query47	741	781	714	714
query48	307	317	219	219
query49	543	247	186	186
query50	745	260	197	197
query51	8283	8074	8096	8074
query52	76	82	74	74
query53	195	199	154	154
query54	233	179	174	174
query55	79	65	61	61
query56	203	174	167	167
query57	720	648	662	648
query58	209	240	173	173
query59	1223	1222	1090	1090
query60	245	187	189	187
query61	181	120	105	105
query62	411	201	183	183
query63	172	145	142	142
query64	2654	652	578	578
query65	1697	1615	1603	1603
query66	1941	334	220	220
query67	9838	9875	9476	9476
query68	3059	1174	648	648
query69	346	223	200	200
query70	675	620	629	620
query71	238	179	157	157
query72	2233	1662	1471	1471
query73	657	579	336	336
query74	2016	1226	1143	1143
query75	1180	1099	959	959
query76	2379	718	541	541
query77	259	252	218	218
query78	4178	3770	3299	3299
query79	1258	860	581	581
query80	1221	322	264	264
query81	486	157	129	129
query82	648	131	92	92
query83	314	210	184	184
query84	290	110	89	89
query85	797	340	276	276
query86	410	174	168	168
query87	1029	991	910	910
query88	2795	2088	2116	2088
query89	293	193	176	176
query90	1933	126	137	126
query91	131	111	95	95
query92	80	67	70	67
query93	1367	1094	711	711
query94	663	255	229	229
query95	531	313	217	217
query96	848	592	276	276
query97	1080	1030	1054	1030
query98	142	138	132	132
query99	427	354	309	309
Total cold run time: 176602 ms
Total hot run time: 81681 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.67 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 6caf5fda1ed033214cf0642bc805904e7081da6c, data reload: false

query1	0.00	0.00	0.01
query2	0.08	0.04	0.04
query3	0.26	0.11	0.11
query4	1.63	0.10	0.11
query5	0.18	0.15	0.15
query6	1.24	0.68	0.70
query7	0.03	0.00	0.01
query8	0.04	0.03	0.04
query9	0.29	0.22	0.21
query10	0.35	0.37	0.33
query11	0.17	0.12	0.11
query12	0.14	0.12	0.12
query13	0.30	0.30	0.31
query14	0.46	0.45	0.43
query15	0.36	0.36	0.35
query16	0.22	0.22	0.22
query17	0.67	0.75	0.70
query18	0.18	0.18	0.17
query19	1.23	1.18	1.11
query20	0.02	0.01	0.01
query21	15.49	0.16	0.11
query22	5.08	0.04	0.04
query23	16.17	0.25	0.11
query24	3.03	0.29	0.28
query25	0.12	0.05	0.03
query26	0.81	0.16	0.13
query27	0.03	0.03	0.03
query28	3.62	0.57	0.28
query29	12.46	3.18	2.58
query30	0.26	0.13	0.13
query31	2.76	0.37	0.17
query32	3.53	0.33	0.22
query33	1.34	1.39	1.46
query34	15.38	2.28	1.75
query35	1.72	1.73	1.74
query36	0.45	0.29	0.29
query37	0.06	0.04	0.03
query38	0.04	0.03	0.03
query39	0.03	0.02	0.02
query40	0.12	0.08	0.08
query41	0.09	0.02	0.02
query42	0.04	0.02	0.02
query43	0.03	0.03	0.03
Total cold run time: 90.51 s
Total hot run time: 14.67 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.21% (34340/45059)
Line Coverage 61.02% (384796/630658)
Region Coverage 57.41% (323885/564134)
Branch Coverage 58.19% (147452/253404)

@morningman
morningman merged commit 387e1a9 into apache:master Sep 16, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants