Skip to content

[fix](be) Normalize constant nullable TopN predicate results - #66442

Open
HappenLee wants to merge 2 commits into
apache:masterfrom
HappenLee:fix-topn-const-nullable-filter
Open

[fix](be) Normalize constant nullable TopN predicate results#66442
HappenLee wants to merge 2 commits into
apache:masterfrom
HappenLee:fix-topn-const-nullable-filter

Conversation

@HappenLee

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Nullable TopN comparisons can return a ColumnConst that wraps a ColumnNullable result, especially when an input batch is entirely NULL. The previous normalization only handled a top-level ColumnNullable, so the constant nullable result could reach filter execution without converting SQL NULL into the NULLS FIRST or NULLS LAST filter decision.

This change recursively normalizes constant wrappers, collapses nullable Boolean results according to the TopN null ordering, preserves the constant shape, and aligns the unit-test expression metadata with production nullability. The new unit test covers both NULLS FIRST and NULLS LAST through execute_column and execute_filter.

Release note

Fix nullable TopN runtime predicate filtering for constant NULL comparison results.

Check List (For Author)

  • Test: Unit Test
    • GLIBC_COMPATIBILITY=OFF ./run-be-ut.sh -j 48 --run --filter=RuntimePredicateTest.*
    • build-support/run-clang-tidy.sh --base apache/master --build-dir be/ut_build_ASAN
  • Behavior changed: Yes, constant nullable TopN predicate results now follow NULLS FIRST/LAST semantics
  • 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

@HappenLee

Copy link
Copy Markdown
Contributor Author

run buildall

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

Automated review conclusion: changes requested.

One blocking correctness issue is reported inline: nullable TopN normalization can produce a physically non-nullable constant Boolean while the expression remains declared nullable, and FileScannerV2's strict constant-filter execution rejects that result.

Critical checkpoint conclusions:

  • Goal and proof: The change targets the real all-NULL ColumnConst(ColumnNullable(...)) failure, and the new unit test proves the intended NULLS FIRST/LAST behavior through the relaxed column/filter APIs. It does not prove the strict block-execution integration where the accepted issue occurs.
  • Scope and design: The two-file change is small and focused, and its recursion preserves constant cardinality and COW ownership. It is not end-to-end complete because it strips a nullable physical wrapper without keeping every caller's declared/physical type contract consistent.
  • Concurrency: Runtime-predicate bound access remains protected by the existing shared mutex, null ordering is immutable, and the change adds no thread, lock, atomic, or deadlock concern.
  • Lifecycle: The existing RuntimePredicate observer lifetime and expression prepare/open/clone lifecycle remain valid; no new static initialization or ownership cycle is introduced.
  • Configuration and compatibility: No configuration, serialized format, symbol, FE-BE protocol, storage, or rolling-upgrade contract changes are involved. Raw fixed/binary, dictionary, and external min-max paths retain consistent ASC/DESC and NULL ordering semantics.
  • Test coverage and results: The added BE unit test has sound assertions for its path, including both NULL order modes, but misses VExprContext::execute(Block*, int*) on a constant nullable result. A regression test for that strict API is required. This review was static as required by the runner contract; no build or test command was run here.
  • Observability: No new logging or metric is required for this localized expression normalization, but the current type-mismatch status would fail a valid external scan rather than preserve query semantics.
  • Transactions, persistence, data writes, and transmitted variables: Not applicable; this is a read-side expression/filter change with no EditLog, transaction, storage mutation, or new FE-BE variable.
  • Performance: The wrapper recursion is bounded by ColumnConst invariants and operates on the one-row nested payload for constants; no additional hot-path performance defect was found.
  • Other reviewed paths: Empty/selected batches, partial/all/no NULL inputs, bound/no-bound states, ASC/DESC, NULLS FIRST/LAST, generic filtering, raw fixed/binary evaluation, dictionary pruning, and external min-max generation were checked. No second actionable issue was substantiated.

User review focus: No additional focus was supplied, so the whole PR was reviewed.

Review completion: All candidate points were independently verified and deduplicated. The final set contains one blocking inline issue and no unresolved suspicious points.

Comment thread be/src/exprs/vtopn_pred.h
@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17708	4061	3949	3949
q2	2009	321	201	201
q3	10312	1427	827	827
q4	4719	471	339	339
q5	7740	833	554	554
q6	199	167	134	134
q7	765	802	597	597
q8	9556	1588	1683	1588
q9	5467	4175	4060	4060
q10	6641	1626	1382	1382
q11	501	361	317	317
q12	734	567	458	458
q13	18105	3246	2779	2779
q14	261	267	242	242
q15	q16	739	737	671	671
q17	987	912	990	912
q18	6645	5619	5593	5593
q19	1286	1172	1055	1055
q20	797	684	603	603
q21	6031	2713	2435	2435
q22	431	358	300	300
Total cold run time: 101633 ms
Total hot run time: 28996 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4238	4196	4250	4196
q2	283	314	208	208
q3	4531	4929	4394	4394
q4	2167	2258	1411	1411
q5	4256	4096	4111	4096
q6	226	180	124	124
q7	1676	1622	1366	1366
q8	2180	1912	1883	1883
q9	6730	6735	6699	6699
q10	4273	4244	3818	3818
q11	514	394	352	352
q12	714	731	499	499
q13	3010	3280	2701	2701
q14	275	285	261	261
q15	q16	663	699	609	609
q17	1230	1221	1204	1204
q18	12122	10993	11811	10993
q19	1102	1106	1051	1051
q20	2218	2222	1949	1949
q21	5268	4504	4534	4504
q22	535	464	416	416
Total cold run time: 58211 ms
Total hot run time: 52734 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 166877 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 3951df275863cea76be01314904262cb0c49d779, data reload: false

query5	4140	593	481	481
query6	461	231	206	206
query7	4868	581	342	342
query8	316	167	147	147
query9	8757	4068	4039	4039
query10	455	363	311	311
query11	5824	2192	2033	2033
query12	161	102	98	98
query13	1261	588	455	455
query14	4863	4248	3971	3971
query14_1	3818	3736	3745	3736
query15	197	188	180	180
query16	897	492	479	479
query17	898	677	548	548
query18	2208	466	337	337
query19	203	189	144	144
query20	104	102	101	101
query21	195	157	131	131
query22	13054	13012	12874	12874
query23	15973	15076	14454	14454
query23_1	14583	14685	14740	14685
query24	7442	1692	1226	1226
query24_1	1237	1242	1222	1222
query25	459	429	401	401
query26	1119	345	214	214
query27	2628	597	384	384
query28	4503	2036	2041	2036
query29	835	595	462	462
query30	346	260	224	224
query31	1173	1119	1054	1054
query32	126	62	68	62
query33	538	311	234	234
query34	1190	1114	638	638
query35	736	747	635	635
query36	786	815	708	708
query37	153	105	93	93
query38	1830	1774	1672	1672
query39	830	814	803	803
query39_1	788	790	791	790
query40	251	165	144	144
query41	64	68	65	65
query42	94	92	95	92
query43	317	322	283	283
query44	1443	766	777	766
query45	182	175	168	168
query46	1112	1172	724	724
query47	1575	1562	1477	1477
query48	408	404	295	295
query49	578	399	294	294
query50	1084	434	323	323
query51	10524	10513	10385	10385
query52	86	84	75	75
query53	250	283	199	199
query54	309	245	229	229
query55	76	73	68	68
query56	310	292	292	292
query57	1042	1030	948	948
query58	297	285	269	269
query59	1575	1579	1384	1384
query60	322	280	264	264
query61	176	168	175	168
query62	397	319	274	274
query63	250	201	206	201
query64	2970	991	826	826
query65	3843	3818	3854	3818
query66	1875	480	361	361
query67	28450	27995	27949	27949
query68	3149	1520	1072	1072
query69	395	300	268	268
query70	886	824	764	764
query71	377	345	322	322
query72	2986	2651	2425	2425
query73	833	826	457	457
query74	4654	4504	4291	4291
query75	2376	2349	2002	2002
query76	2324	1126	791	791
query77	352	365	279	279
query78	11380	11185	10690	10690
query79	1212	1191	764	764
query80	635	584	483	483
query81	475	334	295	295
query82	274	176	144	144
query83	410	331	306	306
query84	325	162	139	139
query85	1009	691	611	611
query86	291	237	227	227
query87	1948	1988	1837	1837
query88	3714	2814	2788	2788
query89	354	323	278	278
query90	1892	192	190	190
query91	210	200	161	161
query92	64	58	54	54
query93	1508	1577	1026	1026
query94	544	358	315	315
query95	777	623	458	458
query96	1142	826	342	342
query97	2469	2447	2372	2372
query98	201	192	180	180
query99	739	737	612	612
Total cold run time: 243358 ms
Total hot run time: 166877 ms

@hello-stephen

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

query1	0.00	0.00	0.01
query2	0.10	0.05	0.05
query3	0.25	0.13	0.14
query4	1.60	0.15	0.15
query5	0.23	0.22	0.21
query6	1.15	0.81	0.80
query7	0.04	0.00	0.00
query8	0.05	0.04	0.04
query9	0.36	0.32	0.31
query10	0.55	0.55	0.59
query11	0.19	0.13	0.13
query12	0.17	0.14	0.14
query13	0.46	0.46	0.46
query14	1.00	0.98	1.00
query15	0.60	0.56	0.58
query16	0.32	0.32	0.33
query17	1.10	1.03	1.09
query18	0.21	0.20	0.20
query19	2.04	1.94	1.96
query20	0.02	0.02	0.01
query21	15.45	0.20	0.14
query22	4.96	0.05	0.05
query23	16.14	0.32	0.12
query24	2.97	0.41	0.33
query25	0.11	0.05	0.04
query26	0.73	0.20	0.14
query27	0.04	0.03	0.03
query28	3.54	0.77	0.36
query29	12.51	4.08	3.23
query30	0.27	0.17	0.16
query31	2.76	0.54	0.30
query32	3.22	0.58	0.49
query33	3.11	3.20	3.16
query34	15.68	3.90	3.27
query35	3.24	3.20	3.20
query36	0.55	0.45	0.40
query37	0.09	0.06	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.15	0.15
query41	0.09	0.04	0.03
query42	0.04	0.02	0.03
query43	0.04	0.03	0.03
Total cold run time: 96.24 s
Total hot run time: 23.79 s

@HappenLee

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review context preparation failed before Codex ran; inspect the 'Prepare authoritative PR context and required AGENTS guides' step.
Workflow run: https://github.com/apache/doris/actions/runs/30923823305

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@HappenLee

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/30971152248

Please trigger /review again after that time.

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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

@HappenLee

Copy link
Copy Markdown
Contributor Author

run buildall

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Nullable TopN comparisons can return a ColumnConst that wraps a ColumnNullable result, especially when an input batch is entirely NULL. The previous normalization only handled a top-level ColumnNullable, so the constant nullable result could reach filter execution without converting SQL NULL into the NULLS FIRST or NULLS LAST filter decision. Recursively normalize constant wrappers, collapse nullable Boolean results according to the TopN null ordering, preserve the constant shape, and align the unit-test expression metadata with production nullability.

### Release note

Fix nullable TopN runtime predicate filtering for constant NULL comparison results.

### Check List (For Author)

- Test: Unit Test
    - `GLIBC_COMPATIBILITY=OFF ./run-be-ut.sh -j 48 --run --filter=RuntimePredicateTest.*`
- Behavior changed: Yes, constant nullable TopN predicate results now follow NULLS FIRST/LAST semantics
- Does this need documentation: No
@HappenLee
HappenLee force-pushed the fix-topn-const-nullable-filter branch from 0b42c4e to cbc9866 Compare August 5, 2026 13:38
@HappenLee

Copy link
Copy Markdown
Contributor Author

run buildall

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants