Skip to content

[Enhancement] Enable zone-map pruning for date_trunc predicates - #79021

Open
zhangyaqi1989 wants to merge 1 commit into
StarRocks:mainfrom
zhangyaqi1989:yz/date-trunc-zone-map-pruning
Open

[Enhancement] Enable zone-map pruning for date_trunc predicates#79021
zhangyaqi1989 wants to merge 1 commit into
StarRocks:mainfrom
zhangyaqi1989:yz/date-trunc-zone-map-pruning

Conversation

@zhangyaqi1989

@zhangyaqi1989 zhangyaqi1989 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

Predicates such as date_trunc('day', ts) = '2026-09-10' reach the scan as expression predicates, but DATE_TRUNC is missing from the FE's monotonic-function allowlist. The BE therefore cannot use the expression for zone-map pruning.

What I'm doing:

Add DATE_TRUNC to the existing allowlist. Its unit is already required to be a constant by function analysis, and truncation preserves timestamp ordering. The existing recursive check still rejects non-monotonic child expressions; the BE already handles equality by deriving >= and <= zone-map predicates.

Add a serialization regression test covering DATE/DATETIME units, nullable and non-nullable columns, equality and range predicates, and a non-monotonic CASE input.

Related issue: none.

Validation

  • Confirmed the new regression fails on unmodified upstream: DATE: day ==> expected: <true> but was: <false>.

  • With the fix, ExprToThriftTest passes: 2 tests, 0 failures/errors. Run in a Linux ARM64 container with JDK 17:

    cd fe
    FE_UT_PARALLEL=1 PYTHON=python3 mvn -B -ntp -pl fe-core -am \
      -Dtest=ExprToThriftTest -Dsurefire.failIfNoSpecifiedTests=false \
      -DfailIfNoTests=false -Djacoco.skip=true -Dmaven.clean.skip=true test
  • Checked truncation ordering with synthetic NULL, minimum/maximum date, leap-day, and subsecond inputs on a local StarRocks instance. These are boundary sanity checks; the regression above verifies the changed upstream serialization path.

  • mvn -B -ntp -pl fe-core checkstyle:check: passed with 0 violations.

Reproducer

CREATE TABLE date_trunc_pruning (ts DATETIME NOT NULL)
DUPLICATE KEY(ts)
DISTRIBUTED BY HASH(ts) BUCKETS 1
PROPERTIES ('replication_num' = '1');

INSERT INTO date_trunc_pruning
SELECT minutes_add('2025-01-01 00:00:00', generate_series)
FROM TABLE(generate_series(0, 999999));

SET enable_query_cache = false;
EXPLAIN ANALYZE
SELECT count(*) FROM date_trunc_pruning
WHERE date_trunc('day', ts) = '2026-09-10';

DROP TABLE date_trunc_pruning;

Observability: reviewed the existing RawRowsRead, ReadPagesNum, and ZoneMapIndexFilterRows scan-profile counters. They already expose the pruning improvement and remain unchanged; no new metrics are needed.

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Eligible DATE_TRUNC predicates can prune additional pages. SQL results and configuration interfaces are unchanged.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5

Signed-off-by: Yaqi Zhang <y.zhang@celonis.com>
@zhangyaqi1989
zhangyaqi1989 force-pushed the yz/date-trunc-zone-map-pruning branch from 4236d52 to 9ec1796 Compare September 11, 2026 22:52
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 9ec179629d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T22:56:49.180704Z 9ec1796 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[FE Incremental Coverage Report]

pass : 1 / 1 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/ast/expression/FunctionCallExpr.java 1 1 100.00% []

@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants