Skip to content

[refine](storage) remove mock column workaround in segment iterator common expr evaluation#62561

Open
Mryange wants to merge 2 commits into
apache:masterfrom
Mryange:remove-mock-col-in-segment-iter
Open

[refine](storage) remove mock column workaround in segment iterator common expr evaluation#62561
Mryange wants to merge 2 commits into
apache:masterfrom
Mryange:remove-mock-col-in-segment-iter

Conversation

@Mryange
Copy link
Copy Markdown
Contributor

@Mryange Mryange commented Apr 16, 2026

What problem does this PR solve?

Previously, _process_common_expr in SegmentIterator had a workaround that temporarily replaced column 0 with a const default column of selected_size rows. This was necessary because execute_conjuncts_and_filter_block internally used block->rows() to determine the filter size, but during lazy materialization the block columns could have different row counts than the actual selected_size.

Now that VExpr::execute_filter and VExpr::execute_column accept an explicit count/num_rows parameter, this mock column trick is no longer needed. The filter size can be driven by selected_size directly.

Changes

  1. Removed mock column logic from _process_common_expr — deleted the need_mock_col / col0 save/restore code and the associated comment.

  2. Added new execute_conjuncts_and_filter_block overload with explicit num_rows — a new 6-argument overload in VExprContext that uses num_rows instead of block->rows() for the filter size. Internally it calls execute_filter with the explicit row count.

  3. Deleted old 5-argument overload — the previous execute_conjuncts_and_filter_block(ctxs, block, columns_to_filter, column_to_keep, filter) overload (which used block->rows()) was removed. Its only external caller (table_function_operator.cpp) was migrated to the new 6-arg overload with output_block->rows().

  4. Replaced block->rows() with select_size in _output_index_result_column — the early return check, vec_match_pred.resize, null_map_vec.resize, and DCHECK all now use the select_size parameter instead of block->rows().

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • 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

@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?

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented Apr 16, 2026

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Found 1 blocking issue.

  1. be/src/exprs/vexpr_context.h: this change removes the 5-arg execute_conjuncts_and_filter_block(..., filter) overload, but be/src/exec/operator/table_function_operator.cpp:718 still calls it. Since only the 4-arg overload and the new 6-arg overload remain, the branch no longer builds.

Critical checkpoints:

  • Goal of the task: remove the mock-column workaround in SegmentIterator by driving common-expression filtering with selected_size. After tracing SegmentIterator -> VExprContext::execute_filter -> VExpr::execute_column, that path looks directionally correct, but the task is not fully accomplished because the helper API change was not propagated to all callers, and there is no test proving the lazy-materialization row-count mismatch case.
  • Change size/focus: mostly focused, but the shared helper change missed another caller, so the refactor is not self-contained.
  • Concurrency: no new concurrency, locking, or lifecycle risks in the touched code.
  • Lifecycle/static initialization: no special lifecycle or static initialization concerns introduced.
  • Configuration: no new config items.
  • Compatibility: no FE/BE protocol or storage-format compatibility change, but there is an internal API compatibility break inside BE that currently leaves the tree uncompilable.
  • Parallel code paths: not fully covered. table_function_operator.cpp still uses the removed 5-arg helper.
  • Special conditions/checks: the new explicit num_rows contract is reasonable for lazy materialization, but it must be applied consistently to every caller.
  • Test coverage: no new regression or unit test was added for this row-count mismatch path, so there is still no automated proof for the targeted scenario.
  • Test result files: none changed.
  • Observability: no additional observability appears necessary for this refactor.
  • Transaction, persistence, and data-write concerns: not applicable.
  • FE-BE variable propagation: not applicable.
  • Performance: expected to be neutral or slightly better by removing the temporary mock column.
  • Other issues: I did not find another concrete runtime bug in the traced SegmentIterator common-expression path beyond the compile blocker above.

std::vector<uint32_t>& columns_to_filter,
int column_to_keep, IColumn::Filter& filter);
int column_to_keep, IColumn::Filter& filter,
size_t num_rows);
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.

This signature change removes the previous 5-arg overload, but be/src/exec/operator/table_function_operator.cpp:718 still calls execute_conjuncts_and_filter_block(..., filter) without the new num_rows argument. With only the 4-arg and 6-arg overloads left, this PR no longer builds. Please either update that caller (likely with output_block->rows()) or keep a wrapper overload here.

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented Apr 16, 2026

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

No blocking findings.

Critical checkpoints:

  • Goal / correctness: The PR removes the mock-column workaround and drives common-expr filtering from an explicit row count. I traced SegmentIterator::_next_batch_internal -> _process_common_expr -> _execute_common_expr -> VExprContext::execute_conjuncts_and_filter_block -> VExpr::execute_filter; the new selected_size plumbing matches the lazy-materialization case, and the table-function caller was updated consistently.
  • Scope: The change is small and focused to the helper signature, its affected call sites, and the index-result column sizing logic.
  • Concurrency: No new concurrent state, locks, or lifecycle interactions are introduced in the modified flow.
  • Lifecycle / static init: No special lifecycle or static-initialization risk is introduced here.
  • Config / compatibility / FE-BE protocol / persistence / transaction or data-write semantics: Not applicable for this change.
  • Parallel code paths: The only non-segment caller (table_function_operator.cpp) was updated; I did not find any remaining callers of the removed overload.
  • Conditional logic: Switching the DCHECK and the filter sizing to selected_size matches the actual invariant of this path better than block->rows().
  • Observability: No additional logging or metrics look necessary for this refactor.
  • Tests: No dedicated test was added in this PR, so the remaining risk is coverage for the exact selected_size != block->rows() lazy-materialization path. I did not run build or regression tests as part of review.
  • Test result changes: None.

Overall summary:
The patch looks correct and focused. I do not see a blocking issue in the current implementation, though a targeted regression or BE unit test for the mismatched selected_size path would improve confidence.

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented Apr 16, 2026

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 65.00% (13/20) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.16% (20204/38008)
Line Coverage 36.71% (190254/518288)
Region Coverage 32.94% (147641/448221)
Branch Coverage 34.09% (64662/189698)

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (20/20) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.71% (27433/37217)
Line Coverage 57.35% (296310/516670)
Region Coverage 54.53% (246655/452331)
Branch Coverage 56.19% (106919/190266)

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Apr 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented May 11, 2026

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 29508 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 9aba2f81d1fbcc85e75b4b2b63aefbd25043a728, data reload: false

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17626	3853	3845	3845
q2	q3	10713	890	615	615
q4	4660	460	363	363
q5	7640	1346	1143	1143
q6	284	177	137	137
q7	951	947	790	790
q8	10630	1417	1284	1284
q9	6277	5386	5331	5331
q10	6338	2083	1797	1797
q11	474	261	255	255
q12	685	417	290	290
q13	18240	3343	2723	2723
q14	293	287	262	262
q15	q16	913	875	791	791
q17	1014	1035	701	701
q18	6551	5696	5625	5625
q19	1232	1228	1102	1102
q20	497	391	264	264
q21	4544	2273	1886	1886
q22	419	352	304	304
Total cold run time: 99981 ms
Total hot run time: 29508 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4170	4071	4060	4060
q2	q3	4620	4801	4175	4175
q4	2076	2148	1390	1390
q5	4966	4988	5269	4988
q6	189	166	130	130
q7	2030	2274	1652	1652
q8	3474	3154	3183	3154
q9	8524	8430	8385	8385
q10	4534	4520	4253	4253
q11	659	427	391	391
q12	712	776	539	539
q13	3262	3640	2925	2925
q14	305	311	279	279
q15	q16	798	791	707	707
q17	1375	1306	1406	1306
q18	8122	7056	7159	7056
q19	1158	1171	1157	1157
q20	2279	2256	1956	1956
q21	6149	5365	4928	4928
q22	556	506	449	449
Total cold run time: 59958 ms
Total hot run time: 53880 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 172017 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 9aba2f81d1fbcc85e75b4b2b63aefbd25043a728, data reload: false

query5	4326	654	518	518
query6	334	230	210	210
query7	4222	564	322	322
query8	328	232	214	214
query9	8821	4049	4029	4029
query10	474	372	303	303
query11	5821	2442	2210	2210
query12	187	128	126	126
query13	1293	632	449	449
query14	6592	5415	5048	5048
query14_1	4344	4374	4324	4324
query15	210	210	192	192
query16	1005	467	430	430
query17	1127	744	601	601
query18	2707	489	352	352
query19	216	203	164	164
query20	137	134	133	133
query21	216	143	115	115
query22	13679	13637	13385	13385
query23	17210	16385	16903	16385
query23_1	16379	16352	16326	16326
query24	7789	1807	1424	1424
query24_1	1423	1390	1383	1383
query25	573	542	460	460
query26	1640	335	179	179
query27	2948	583	356	356
query28	4450	2006	1971	1971
query29	1021	641	537	537
query30	320	240	206	206
query31	1336	1087	944	944
query32	96	73	73	73
query33	573	329	289	289
query34	1160	1133	620	620
query35	757	780	661	661
query36	1363	1350	1154	1154
query37	148	102	84	84
query38	3217	3143	3037	3037
query39	927	931	903	903
query39_1	861	871	858	858
query40	248	157	132	132
query41	63	60	59	59
query42	111	107	109	107
query43	323	324	285	285
query44	
query45	212	204	190	190
query46	1065	1239	715	715
query47	2361	2308	2191	2191
query48	408	443	298	298
query49	626	505	427	427
query50	694	290	223	223
query51	4368	4361	4226	4226
query52	105	104	92	92
query53	256	276	199	199
query54	311	279	250	250
query55	93	86	83	83
query56	304	310	289	289
query57	1433	1427	1293	1293
query58	312	276	272	272
query59	1591	1645	1435	1435
query60	344	337	322	322
query61	159	157	153	153
query62	680	616	559	559
query63	252	200	204	200
query64	2402	891	729	729
query65	
query66	1707	531	400	400
query67	29965	30032	29907	29907
query68	
query69	458	337	305	305
query70	1040	1002	965	965
query71	307	271	270	270
query72	2929	2734	2496	2496
query73	843	812	429	429
query74	5104	4899	4758	4758
query75	2817	2634	2337	2337
query76	2294	1111	746	746
query77	413	423	341	341
query78	12889	12946	12305	12305
query79	1504	1000	746	746
query80	669	573	485	485
query81	457	289	240	240
query82	1270	168	126	126
query83	354	275	250	250
query84	254	142	113	113
query85	868	519	437	437
query86	400	334	311	311
query87	3429	3384	3226	3226
query88	3550	2664	2632	2632
query89	448	400	340	340
query90	1878	187	182	182
query91	193	188	155	155
query92	84	75	78	75
query93	959	966	564	564
query94	552	365	322	322
query95	681	482	360	360
query96	1064	795	334	334
query97	2692	2707	2574	2574
query98	244	232	231	231
query99	1147	1136	970	970
Total cold run time: 255333 ms
Total hot run time: 172017 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (20/20) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.60% (27781/37746)
Line Coverage 57.49% (300362/522504)
Region Coverage 54.61% (249964/457684)
Branch Coverage 56.22% (108165/192403)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.1.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants