Skip to content

[fix](infer-predicate) Preserve datetime precision in predicate inference - #67653

Merged
924060929 merged 2 commits into
apache:masterfrom
feiniaofeiafei:codex/fix-datetimev2-infer-precision
Sep 11, 2026
Merged

924060929 merged 2 commits into
apache:masterfrom
feiniaofeiafei:codex/fix-datetimev2-infer-precision

Conversation

@feiniaofeiafei

@feiniaofeiafei feiniaofeiafei commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Related PR: #41731

Problem Summary:
Predicate inference unwraps narrowing DATETIMEV2 casts and incorrectly treats distinct raw join keys as equal. An IN predicate on one side can then filter valid matches on the other side. Require injective DATETIMEV2 casts before unwrapping, including nested casts, while preserving same-scale and widening inference. Add one unit test and a regression case comparing inference enabled and disabled.

Fix missing join results caused by predicate inference across narrowing DATETIMEV2 casts.

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?

@feiniaofeiafei

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

Problem Summary: Predicate inference unwraps narrowing DATETIMEV2 casts and
incorrectly treats distinct raw join keys as equal. An IN predicate on one
side can then filter valid matches on the other side. Require injective
DATETIMEV2 casts before unwrapping, including nested casts, while preserving
same-scale and widening inference. Add one unit test and a regression case
comparing inference enabled and disabled.

Fix missing join results caused by predicate inference across narrowing
DATETIMEV2 casts.

- Test: Checkstyle passed; remote unit and regression validation pending
- Behavior changed: Yes, preserve valid matches for narrowing datetime casts
- Does this need documentation: No
### What problem does this PR solve?

Problem Summary: Record generated regression output proving that narrowing
DATETIMEV2 join casts preserve matching rows with predicate inference both
enabled and disabled. Match unit-test literal precision to the source slots
so expression comparisons test inference without unrelated type coercion.

### Release note

None

### Check List (For Author)

- Test: Unit Test / Regression test / Manual test
    - Checkstyle passed
    - DISABLE_BUILD_UI=ON ./build.sh --fe passed on dev
    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.InferPredicateByReplaceTest: 11 passed
    - infer_datetimev2_cast_precision regression suite: 1 passed
    - Old FE returned 0 rows with inference enabled; updated FE returns the expected match
    - EXPLAIN confirms the right scan has no incorrect raw IN predicate
- Behavior changed: No, test-only changes
- Does this need documentation: No
@feiniaofeiafei
feiniaofeiafei force-pushed the codex/fix-datetimev2-infer-precision branch from 846f879 to db0ed53 Compare September 10, 2026 01:58
@feiniaofeiafei

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@feiniaofeiafei

Copy link
Copy Markdown
Collaborator Author

run performance

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17567	3069	3071	3069
q2	2073	276	213	213
q3	10258	873	540	540
q4	4674	251	201	201
q5	7675	568	383	383
q6	138	112	91	91
q7	542	505	389	389
q8	9231	913	838	838
q9	3428	2386	2352	2352
q10	6498	850	702	702
q11	389	194	180	180
q12	624	255	198	198
q13	18140	1511	1166	1166
q14	164	149	138	138
q15	q16	437	392	362	362
q17	1388	864	794	794
q18	3059	2263	2243	2243
q19	1255	880	775	775
q20	376	292	204	204
q21	5656	1646	1883	1646
q22	326	262	226	226
Total cold run time: 93898 ms
Total hot run time: 16710 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3434	3397	3368	3368
q2	494	394	363	363
q3	2196	2605	2198	2198
q4	1175	1155	883	883
q5	2186	2110	2092	2092
q6	158	117	89	89
q7	1013	920	859	859
q8	1590	1401	1405	1401
q9	3099	3089	3049	3049
q10	1844	1784	1600	1600
q11	354	269	246	246
q12	450	425	337	337
q13	1476	1534	1147	1147
q14	176	159	151	151
q15	q16	392	396	373	373
q17	3622	3233	3182	3182
q18	4797	4396	4693	4396
q19	842	815	939	815
q20	1026	965	815	815
q21	3844	3110	3310	3110
q22	398	342	323	323
Total cold run time: 34566 ms
Total hot run time: 30797 ms

@hello-stephen

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

query5	4239	413	325	325
query6	378	139	126	126
query7	4960	441	235	235
query8	302	127	115	115
query9	8709	2870	2876	2870
query10	420	247	183	183
query11	5368	1013	909	909
query12	113	69	66	66
query13	1197	428	329	329
query14	6020	2182	2052	2052
query14_1	1966	1963	1934	1934
query15	180	120	119	119
query16	932	358	348	348
query17	789	438	358	358
query18	2365	321	233	233
query19	161	138	107	107
query20	69	71	70	70
query21	206	103	91	91
query22	5438	5346	5383	5346
query23	6696	6095	5882	5882
query23_1	5887	5987	6146	5987
query24	7304	1092	751	751
query24_1	778	760	788	760
query25	424	299	266	266
query26	1236	217	128	128
query27	2838	392	254	254
query28	4694	1484	1503	1484
query29	930	418	347	347
query30	248	153	130	130
query31	838	416	344	344
query32	133	77	73	73
query33	447	224	187	187
query34	997	831	482	482
query35	396	425	343	343
query36	560	555	531	531
query37	121	83	70	70
query38	1007	844	814	814
query39	498	480	470	470
query39_1	452	451	459	451
query40	205	92	76	76
query41	59	56	55	55
query42	73	77	73	73
query43	245	242	211	211
query44	1000	532	540	532
query45	117	109	102	102
query46	811	853	531	531
query47	749	816	694	694
query48	314	295	234	234
query49	542	236	191	191
query50	725	262	186	186
query51	7959	8028	7945	7945
query52	65	65	56	56
query53	190	197	142	142
query54	214	155	154	154
query55	77	58	56	56
query56	191	156	161	156
query57	669	619	649	619
query58	201	223	226	223
query59	1188	1231	1092	1092
query60	248	194	173	173
query61	111	115	114	114
query62	359	211	188	188
query63	172	145	137	137
query64	2658	721	621	621
query65	1628	1576	1620	1576
query66	1927	273	218	218
query67	9818	9656	9691	9656
query68	2735	1251	755	755
query69	347	209	191	191
query70	677	618	615	615
query71	250	169	169	169
query72	2277	1667	1486	1486
query73	621	578	351	351
query74	1579	1232	1133	1133
query75	1157	1083	950	950
query76	2290	732	528	528
query77	253	256	215	215
query78	3981	3730	3216	3216
query79	2848	801	579	579
query80	1561	317	266	266
query81	490	156	131	131
query82	795	123	94	94
query83	274	204	187	187
query84	299	107	90	90
query85	815	335	283	283
query86	389	182	171	171
query87	1009	975	885	885
query88	2762	2116	2107	2107
query89	289	195	175	175
query90	1925	120	129	120
query91	127	119	97	97
query92	81	70	71	70
query93	1743	1113	721	721
query94	619	233	221	221
query95	543	284	278	278
query96	828	587	253	253
query97	1033	1054	1010	1010
query98	163	135	136	135
query99	418	351	302	302
Total cold run time: 177414 ms
Total hot run time: 81523 ms

@hello-stephen

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

query1	0.01	0.00	0.00
query2	0.07	0.03	0.03
query3	0.25	0.11	0.11
query4	1.59	0.10	0.10
query5	0.17	0.17	0.14
query6	1.28	0.70	0.72
query7	0.04	0.01	0.01
query8	0.05	0.03	0.03
query9	0.28	0.22	0.21
query10	0.33	0.35	0.35
query11	0.16	0.12	0.11
query12	0.15	0.12	0.12
query13	0.29	0.30	0.30
query14	0.45	0.45	0.45
query15	0.35	0.36	0.36
query16	0.21	0.24	0.22
query17	0.72	0.67	0.72
query18	0.18	0.16	0.17
query19	1.13	1.16	1.04
query20	0.02	0.01	0.01
query21	15.47	0.14	0.10
query22	5.11	0.05	0.05
query23	16.17	0.26	0.11
query24	2.98	0.34	0.26
query25	0.10	0.04	0.03
query26	0.80	0.17	0.13
query27	0.04	0.03	0.02
query28	3.63	0.52	0.28
query29	12.48	3.13	2.57
query30	0.28	0.12	0.10
query31	2.77	0.37	0.18
query32	3.52	0.32	0.23
query33	1.34	1.36	1.38
query34	15.37	2.21	1.78
query35	1.74	1.72	1.74
query36	0.46	0.29	0.29
query37	0.06	0.04	0.03
query38	0.04	0.04	0.02
query39	0.03	0.03	0.02
query40	0.12	0.07	0.07
query41	0.08	0.03	0.03
query42	0.03	0.02	0.02
query43	0.04	0.03	0.02
Total cold run time: 90.39 s
Total hot run time: 14.54 s

@924060929
924060929 merged commit 0186c8a into apache:master Sep 11, 2026
33 of 35 checks passed
yiguolei pushed a commit that referenced this pull request Nov 3, 2026
…dicate inference #67653 (#70015)

picked from master #67653

Co-authored-by: feiniaofeiafei <[email protected]>
morrySnow pushed a commit to morrySnow/incubator-doris that referenced this pull request Nov 3, 2026
### What problem does this PR solve?

Related PR: apache#67919

Problem Summary: 不等式关系被误记为等式,且等值替换跨越不保值的类型或表示

Backport adaptation: Preserve existing index-dependent MATCH/multi_match/SEARCH exclusions and date-arithmetic pushdown protection while adding non-movable expression guards and injective cast checks. Keep all branch tests alongside the upstream test additions. Include only the common ExpressionTrait non-movable/volatile predicate helper from prerequisite apache#67067; retain its type-bitset fast path and conditional volatile semantics.

Rebase adjustment: Rebase onto branch-4.2 after apache#67653 merged. Keep the generalized isInjectiveCastTo check, which includes DATETIMEV2 precision-loss rejection, and preserve the merged precision regression tests.

### Release note

不等式关系被误记为等式,且等值替换跨越不保值的类型或表示

### Check List (For Author)

- Test: Unit Test — org.apache.doris.nereids.rules.rewrite.InferPredicateByReplaceTest,org.apache.doris.nereids.rules.rewrite.UnequalPredicateInferTest,org.apache.doris.nereids.types.DataTypeTest,org.apache.doris.nereids.util.ExpressionUtilsTraversalTest,org.apache.doris.nereids.util.ExpressionUtilsTest; FE Checkstyle passed. Cluster regression tests were not run for this commit.
- Behavior changed: Yes, fixes the behavior described above.
- Does this need documentation: No

(cherry picked from commit 5f107ef)
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.

4 participants