Skip to content

[Exec](cache) condition cache digest error in runtime filter in and add debug log#58857

Merged
zhangstar333 merged 1 commit intoapache:masterfrom
HappenLee:pip
Dec 10, 2025
Merged

[Exec](cache) condition cache digest error in runtime filter in and add debug log#58857
zhangstar333 merged 1 commit intoapache:masterfrom
HappenLee:pip

Conversation

@HappenLee
Copy link
Contributor

@HappenLee HappenLee commented Dec 9, 2025

What problem does this PR solve?

Overview

This pull request (authored by HappenLee) focuses on performance optimization (via sorting algorithm replacement) and observability enhancement (via logging expansion) for Apache Doris, along with a critical fix to ensure accurate digest calculation in predicate expressions. The changes span core data structure handling, segment iteration, and vectorized expression logic.

Key Changes

1. Performance: Replace std::sort with pdqsort for Faster Set Sorting

  • File: be/src/exprs/hybrid_set.h

  • Modifications

    :

    • Added #include <pdqsort.h> to enable the pdqsort algorithm (a fast, adaptive quicksort variant optimized for real-world data).

    • Replaced

      std::sort(elems.begin(), elems.end())
      

      with

      pdqsort(elems.begin(), elems.end())
      

      in three set classes:

      • HybridSet: For generic element type sets.
      • StringSet: For string reference (StringRef) sets.
      • StringValueSet: For string value-based sets.
  • Purpose: pdqsort outperforms std::sort in most practical scenarios (e.g., partially sorted data, duplicate values), reducing the time to sort elements during digest calculation for set-based operations.

2. Observability: Add Debug Logs for Condition Cache Operations

  • File: be/src/olap/rowset/segment_v2/segment_iterator.cpp

  • Modifications

    :

    • Cache Hit Logging

      (Line 132-138): Added

      VLOG_DEBUG
      

      output when a condition cache hit occurs, including:

      • Query ID (from _opts.runtime_state->query_id()).
      • Segment ID (_segment->id()).
      • Cache digest (_opts.condition_cache_digest).
      • Rowset ID (_opts.rowset_id.to_string()).
    • Cache Insert Logging (Line 2379-2383): Added VLOG_DEBUG output when inserting data into the condition cache, including the same fields as the hit log.

  • Purpose: Improve debuggability for cache-related issues (e.g., false misses, incorrect cache entries) by linking cache events to specific queries and data segments.

3. Correctness: Fix Digest Calculation for VDirectInPredicate

  • File: be/src/vec/exprs/vdirect_in_predicate.h

  • Modifications

    :

    • Updated the

      get_digest(uint64_t seed)
      

      method to:

      1. First incorporate the digest of the predicate’s child expression (_children[0]->get_digest(seed)).
      2. Only propagate the filter’s digest (_filter->get_digest(seed)) if the child digest is non-zero; otherwise, return the original seed.
    • Replaced the previous implementation (which directly returned _filter->get_digest(seed) without including the child expression).

  • Purpose: Ensure the digest uniquely identifies the full predicate logic (including both the child expression and the filter), preventing hash collisions that could lead to incorrect cache lookups or data processing.

Impact

  • Performance: Faster sorting for set-based digest calculations may reduce latency in query operations involving IN predicates or set comparisons.
  • Debuggability: Detailed cache logs enable quicker diagnosis of cache performance issues.
  • Correctness: Fixes a potential source of incorrect digest values, improving the reliability of cache-dependent features (e.g., condition cache, query result caching).

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

@Thearas
Copy link
Contributor

Thearas commented Dec 9, 2025

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 HappenLee force-pushed the pip branch 2 times, most recently from 3aaccd2 to 936cf17 Compare December 9, 2025 12:00
@HappenLee
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17623	5064	4936	4936
q2	2058	365	253	253
q3	10130	1348	750	750
q4	10229	843	328	328
q5	7466	2166	1953	1953
q6	205	171	135	135
q7	1002	874	709	709
q8	9365	1651	1229	1229
q9	7277	5336	5329	5329
q10	6864	2386	1999	1999
q11	538	306	288	288
q12	670	745	573	573
q13	17790	3673	3064	3064
q14	298	293	284	284
q15	589	514	506	506
q16	921	922	860	860
q17	698	808	509	509
q18	7469	7170	7107	7107
q19	1089	967	614	614
q20	388	365	240	240
q21	4256	3954	3640	3640
q22	1062	980	981	980
Total cold run time: 107987 ms
Total hot run time: 36286 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5207	5132	4861	4861
q2	352	399	337	337
q3	2142	2707	2292	2292
q4	1344	1743	1367	1367
q5	5095	4709	4501	4501
q6	220	173	132	132
q7	2083	1934	1811	1811
q8	2656	2784	2514	2514
q9	7506	7559	7706	7559
q10	2971	3331	2840	2840
q11	575	512	514	512
q12	712	716	604	604
q13	3717	3976	3347	3347
q14	283	287	282	282
q15	559	514	503	503
q16	924	944	998	944
q17	1195	1471	1424	1424
q18	7720	7664	7512	7512
q19	901	856	877	856
q20	2023	2147	1894	1894
q21	4795	4224	4163	4163
q22	1074	1032	969	969
Total cold run time: 54054 ms
Total hot run time: 51224 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 180605 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 1d97476ca3265bc01763f3b9f51e4ce1bb9e4fbf, data reload: false

query5	4840	628	487	487
query6	338	221	210	210
query7	4214	465	276	276
query8	309	260	233	233
query9	8780	2589	2635	2589
query10	524	365	318	318
query11	15284	15125	14553	14553
query12	182	116	109	109
query13	1242	495	381	381
query14	6417	3234	2961	2961
query14_1	3037	2848	2879	2848
query15	216	199	175	175
query16	780	457	478	457
query17	1110	704	612	612
query18	2620	424	329	329
query19	234	225	204	204
query20	121	112	108	108
query21	221	145	116	116
query22	3863	3897	3831	3831
query23	16633	16251	15873	15873
query23_1	16111	16132	16004	16004
query24	7365	1656	1211	1211
query24_1	1213	1217	1222	1217
query25	586	475	421	421
query26	1246	280	157	157
query27	2770	465	306	306
query28	4499	2141	2147	2141
query29	825	550	441	441
query30	319	240	212	212
query31	805	687	635	635
query32	81	64	75	64
query33	528	327	285	285
query34	905	904	532	532
query35	784	830	726	726
query36	875	905	835	835
query37	130	89	77	77
query38	3863	3865	3670	3670
query39	751	752	710	710
query39_1	715	721	687	687
query40	218	134	119	119
query41	69	67	64	64
query42	108	108	104	104
query43	437	411	407	407
query44	1326	778	757	757
query45	195	194	185	185
query46	881	997	616	616
query47	1737	1721	1637	1637
query48	327	341	274	274
query49	679	450	369	369
query50	673	300	223	223
query51	3873	3833	3762	3762
query52	108	115	102	102
query53	323	351	300	300
query54	336	271	279	271
query55	81	74	74	74
query56	329	325	322	322
query57	1146	1152	1093	1093
query58	272	260	263	260
query59	2284	2427	2306	2306
query60	336	342	307	307
query61	191	191	184	184
query62	722	669	634	634
query63	329	295	302	295
query64	5172	1421	1105	1105
query65	4032	3933	3970	3933
query66	1428	468	349	349
query67	15126	15072	14738	14738
query68	6363	1032	745	745
query69	500	361	335	335
query70	1095	1027	954	954
query71	382	309	290	290
query72	6124	4978	5088	4978
query73	681	607	312	312
query74	8830	8813	8567	8567
query75	3554	3535	3129	3129
query76	3812	1139	756	756
query77	513	399	289	289
query78	9498	9748	8958	8958
query79	1738	826	616	616
query80	732	650	571	571
query81	527	264	239	239
query82	410	128	103	103
query83	260	254	238	238
query84	263	115	95	95
query85	911	509	471	471
query86	391	318	282	282
query87	4053	4104	3929	3929
query88	3230	2263	2248	2248
query89	470	419	392	392
query90	2023	154	141	141
query91	180	169	145	145
query92	77	66	61	61
query93	1233	922	576	576
query94	488	308	293	293
query95	570	333	366	333
query96	601	458	209	209
query97	2592	2626	2547	2547
query98	208	194	188	188
query99	1274	1318	1228	1228
Total cold run time: 261655 ms
Total hot run time: 180605 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 27.17 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 1d97476ca3265bc01763f3b9f51e4ce1bb9e4fbf, data reload: false

query1	0.05	0.04	0.04
query2	0.10	0.05	0.05
query3	0.26	0.09	0.08
query4	1.61	0.11	0.10
query5	0.29	0.24	0.25
query6	1.16	0.64	0.63
query7	0.03	0.02	0.02
query8	0.05	0.03	0.04
query9	0.57	0.50	0.51
query10	0.55	0.56	0.55
query11	0.17	0.10	0.12
query12	0.14	0.11	0.12
query13	0.63	0.59	0.61
query14	1.00	0.99	0.97
query15	0.81	0.79	0.81
query16	0.41	0.42	0.38
query17	1.06	1.03	0.99
query18	0.23	0.22	0.22
query19	1.89	1.87	1.86
query20	0.02	0.02	0.01
query21	15.51	0.29	0.14
query22	4.91	0.05	0.05
query23	16.17	0.28	0.10
query24	1.60	0.25	0.19
query25	0.08	0.05	0.05
query26	0.14	0.13	0.13
query27	0.08	0.07	0.04
query28	4.20	1.24	1.02
query29	12.57	4.03	3.27
query30	0.28	0.14	0.12
query31	2.82	0.62	0.38
query32	3.23	0.55	0.46
query33	3.04	3.04	3.02
query34	16.88	5.20	4.53
query35	4.51	4.56	4.56
query36	0.67	0.52	0.49
query37	0.10	0.06	0.06
query38	0.07	0.05	0.04
query39	0.05	0.03	0.03
query40	0.18	0.14	0.13
query41	0.09	0.03	0.04
query42	0.05	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 98.3 s
Total hot run time: 27.17 s

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 22.73% (5/22) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.36% (18715/35070)
Line Coverage 39.07% (173063/442940)
Region Coverage 33.77% (134340/397822)
Branch Coverage 34.67% (57698/166440)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 95.45% (21/22) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.15% (25144/34372)
Line Coverage 60.29% (266760/442462)
Region Coverage 55.84% (224790/402545)
Branch Coverage 57.12% (95570/167315)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 95.45% (21/22) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.15% (25143/34372)
Line Coverage 60.29% (266751/442462)
Region Coverage 55.85% (224807/402545)
Branch Coverage 57.12% (95569/167315)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 95.45% (21/22) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 72.22% (24822/34372)
Line Coverage 58.95% (260846/442462)
Region Coverage 53.80% (216576/402545)
Branch Coverage 55.36% (92631/167315)

@HappenLee HappenLee changed the title log digest [Exec](cache) condition cache digest error in runtime filter in and add debug log Dec 10, 2025
@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Dec 10, 2025
@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@zhangstar333 zhangstar333 merged commit cf940bc into apache:master Dec 10, 2025
27 of 30 checks passed
nagisa-kunhah pushed a commit to nagisa-kunhah/doris that referenced this pull request Dec 14, 2025
…dd debug log (apache#58857)

### What problem does this PR solve?

## Overview

This pull request (authored by HappenLee) focuses on **performance
optimization** (via sorting algorithm replacement) and **observability
enhancement** (via logging expansion) for Apache Doris, along with a
critical fix to ensure accurate digest calculation in predicate
expressions. The changes span core data structure handling, segment
iteration, and vectorized expression logic.

## Key Changes

### 1. Performance: Replace `std::sort` with `pdqsort` for Faster Set
Sorting

- **File**: `be/src/exprs/hybrid_set.h`

- Modifications

  :

- Added `#include <pdqsort.h>` to enable the pdqsort algorithm (a fast,
adaptive quicksort variant optimized for real-world data).

  - Replaced

     

    ```
    std::sort(elems.begin(), elems.end())
    ```

     

    with

     

    ```
    pdqsort(elems.begin(), elems.end())
    ```

     

    in three set classes:

    - `HybridSet`: For generic element type sets.
    - `StringSet`: For string reference (`StringRef`) sets.
    - `StringValueSet`: For string value-based sets.

- **Purpose**: pdqsort outperforms `std::sort` in most practical
scenarios (e.g., partially sorted data, duplicate values), reducing the
time to sort elements during digest calculation for set-based
operations.

### 2. Observability: Add Debug Logs for Condition Cache Operations

- **File**: `be/src/olap/rowset/segment_v2/segment_iterator.cpp`

- Modifications

  :

  - Cache Hit Logging

     

    (Line 132-138): Added

     

    ```
    VLOG_DEBUG
    ```

     

    output when a condition cache hit occurs, including:

    - Query ID (from `_opts.runtime_state->query_id()`).
    - Segment ID (`_segment->id()`).
    - Cache digest (`_opts.condition_cache_digest`).
    - Rowset ID (`_opts.rowset_id.to_string()`).

- **Cache Insert Logging** (Line 2379-2383): Added `VLOG_DEBUG` output
when inserting data into the condition cache, including the same fields
as the hit log.

- **Purpose**: Improve debuggability for cache-related issues (e.g.,
false misses, incorrect cache entries) by linking cache events to
specific queries and data segments.

### 3. Correctness: Fix Digest Calculation for `VDirectInPredicate`

- **File**: `be/src/vec/exprs/vdirect_in_predicate.h`

- Modifications

  :

  - Updated the

     

    ```
    get_digest(uint64_t seed)
    ```

     

    method to:

1. First incorporate the digest of the predicate’s child expression
(`_children[0]->get_digest(seed)`).
2. Only propagate the filter’s digest (`_filter->get_digest(seed)`) if
the child digest is non-zero; otherwise, return the original seed.

- Replaced the previous implementation (which directly returned
`_filter->get_digest(seed)` without including the child expression).

- **Purpose**: Ensure the digest uniquely identifies the full predicate
logic (including both the child expression and the filter), preventing
hash collisions that could lead to incorrect cache lookups or data
processing.

## Impact

- **Performance**: Faster sorting for set-based digest calculations may
reduce latency in query operations involving `IN` predicates or set
comparisons.
- **Debuggability**: Detailed cache logs enable quicker diagnosis of
cache performance issues.
- **Correctness**: Fixes a potential source of incorrect digest values,
improving the reliability of cache-dependent features (e.g., condition
cache, query result caching).
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. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants