Skip to content

[fix](be) Prevent DST timestamp statistics mispruning#65497

Closed
Gabriel39 wants to merge 2 commits into
apache:masterfrom
Gabriel39:codex/fix-dst-timestamp-statistics
Closed

[fix](be) Prevent DST timestamp statistics mispruning#65497
Gabriel39 wants to merge 2 commits into
apache:masterfrom
Gabriel39:codex/fix-dst-timestamp-statistics

Conversation

@Gabriel39

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Related PR: #64456

Problem Summary: FileScannerV2 converts UTC timestamp statistics into session-local DATETIMEV2 values before ZoneMap evaluation. Across a daylight-saving time rollback, that conversion is not monotonic, so converted metadata endpoints may exclude local values that occur inside the UTC interval. Parquet row-group and page-index pruning, and ORC statistics pruning, could therefore skip matching data. Detect backward timezone transitions within UTC statistics ranges and conservatively disable min/max pruning for those ranges while retaining statistics for monotonic ranges and TIMESTAMPTZ mappings.

Release note

Fix incorrect Parquet and ORC file scan pruning for UTC timestamps across daylight-saving time rollbacks.

Check List (For Author)

  • Test: Unit Test
    • Remote ASAN BE UT: TimestampStatisticsTest., ParquetStatisticsTransformTest., and NewOrcReaderTest.AggregatePushdownTimestamp* (7 passed)
  • Behavior changed: Yes. Non-monotonic local timestamp statistics no longer prune rows or pages.
  • Does this need documentation: No

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

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

### What problem does this PR solve?

Issue Number: N/A

Related PR: apache#64456

Problem Summary: FileScannerV2 converts UTC timestamp statistics into session-local DATETIMEV2 values before ZoneMap evaluation. Across a daylight-saving time rollback, that conversion is not monotonic, so converted metadata endpoints may exclude local values that occur inside the UTC interval. Parquet row-group and page-index pruning, and ORC statistics pruning, could therefore skip matching data. Detect backward timezone transitions within UTC statistics ranges and conservatively disable min/max pruning for those ranges while retaining statistics for monotonic ranges and TIMESTAMPTZ mappings.

### Release note

Fix incorrect Parquet and ORC file scan pruning for UTC timestamps across daylight-saving time rollbacks.

### Check List (For Author)

- Test: Unit Test
    - Remote ASAN BE UT: TimestampStatisticsTest.*, ParquetStatisticsTransformTest.*, and NewOrcReaderTest.AggregatePushdownTimestamp* (7 passed)
- Behavior changed: Yes. Non-monotonic local timestamp statistics no longer prune rows or pages.
- Does this need documentation: No
@Gabriel39 Gabriel39 requested a review from yiguolei as a code owner July 12, 2026 06:44
@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?

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@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 result: request changes.

Critical checkpoint conclusions:

  • Goal and tests: the PR addresses DST rollback mispruning for converted timestamp statistics and adds focused BE unit tests, but it misses the ORC scan-time SARG pruning path and the Parquet TIMESTAMPTZ mapping/config path.
  • Scope: the change is small and focused, but the implementation does not cover all parallel timestamp statistics consumers.
  • Concurrency/lifecycle/config: no new concurrency or lifecycle risk found. The existing enable_mapping_timestamp_tz configuration path is affected by the Parquet guard.
  • Compatibility/persistence/data writes: no storage format, persistence, FE/BE protocol, or write-transaction changes found.
  • Parallel paths: ORC aggregate min/max is guarded, but normal ORC SearchArgument stripe pruning is not; Parquet DATETIMEV2 is guarded, but TIMESTAMPTZ mapping should keep safe UTC min/max.
  • Test coverage: helper and Parquet DATETIMEV2 rollback coverage were added. Missing coverage remains for ORC rollback scan pruning and Parquet enable_mapping_timestamp_tz statistics. I could not run local BE UTs because this checkout lacks thirdparty/installed and thirdparty/installed/bin/protoc.
  • Performance: the Parquet guard unnecessarily disables safe pruning and min/max aggregate pushdown for TIMESTAMPTZ-mapped UTC timestamps.

User focus: no additional user-provided focus points.

Subagent conclusions: FS-1 became inline comment M-1; OR-1 became inline comment M-2; TSC-1 and TSC-2 were duplicates of those accepted candidates. Convergence round 1 ended with optimizer-rewrite, tests-session-config, and format-statistics all reporting NO_NEW_VALUABLE_FINDINGS for the same final ledger/comment set.

timestamp_statistics->getMaximum(), timestamp_statistics->getMaximumNanos()));
return true;
}
if (!format::utc_timestamp_range_is_monotonic(

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 only disables the ZoneMap conversion path, but ORC scan pruning still builds timestamp SearchArguments in _init_search_argument_from_local_filters() and uses getNeedReadStripes() before row-level filters run. For a TIMESTAMP_INSTANT column decoded as session-local DATETIMEV2, a rollback value such as 2021-11-07 01:30 in America/New_York names two UTC instants; the SARG literal conversion picks a single timestamp and lets ORC compare it to stripe min/max, so a stripe containing the other repeated-hour instant can still be pruned. Please also guard or disable timestamp SARG pruning for non-monotonic local mappings, and add an ORC scan test for that rollback case.


bool timestamp_min_max_is_safe(const ParquetColumnSchema& column_schema, int64_t min_value,
int64_t max_value, const cctz::time_zone* timezone) {
if (!column_schema.type_descriptor.is_timestamp ||

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 also disables min/max for adjusted-to-UTC Parquet timestamps after enable_mapping_timestamp_tz maps the column to TYPE_TIMESTAMPTZ. In that mode the decoded values are TimestampTzValues stored and compared in UTC, so the local DATETIMEV2 monotonicity problem does not apply; ORC handles the analogous path by returning TYPE_TIMESTAMPTZ min/max before running this guard. Since apply_timestamp_tz_mapping() leaves the Parquet timestamp flags set, rollback-spanning row groups/pages lose safe pruning and Parquet min/max aggregate pushdown returns NotSupported. Please skip this guard when the effective Doris type is TYPE_TIMESTAMPTZ, and add coverage for that config path.

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 75.00% (51/68) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 56.91% (23546/41377)
Line Coverage 40.57% (230229/567508)
Region Coverage 36.46% (181872/498791)
Branch Coverage 37.54% (81212/216315)

Disable unsafe ORC timestamp SARG pushdown in civil years with backward timezone transitions, while preserving Parquet min/max pruning for TIMESTAMPTZ values that retain UTC ordering. Add ORC, Parquet, and timezone transition regression coverage.
@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

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

Static review completed for current head 833fbdf. I did not find any additional non-duplicate blocking issue beyond the two existing inline threads, and the current patch appears to address both of those areas.

Critical checkpoint conclusions:

  • Goal and tests: The patch targets unsafe timestamp statistics/SARG pruning across DST rollback and adds focused coverage for ORC repeated-civil-time SARG behavior, Parquet adjusted-to-UTC DATETIMEV2 statistics, TIMESTAMPTZ mapped statistics, and shared transition/flooring helpers.
  • Scope and clarity: The change is limited to timestamp statistics/SARG safety and nearby tests.
  • Concurrency, lifecycle, persistence, transactionality, FE/BE protocol, and configuration: Not involved.
  • Parallel paths: ORC ZoneMap/aggregate min-max, ORC SearchArgument pruning, Parquet row-group statistics, Parquet page-index statistics, and Parquet aggregate min-max were checked. Unsafe local DATETIMEV2 statistics fail open; TIMESTAMPTZ preserves UTC ordering.
  • Error/fail-open behavior: Unsafe statistics clear min/max or return NotSupported instead of pruning; unsafe ORC TIMESTAMP_INSTANT SARG literals become non-buildable and row-level filters remain authoritative.
  • Test coverage: The main changed runtime paths are covered by new BE unit tests. A dedicated Parquet page-index runtime fixture is not added, but the page-index path shares the same safety helper and fails open when it cannot build trustworthy statistics.
  • User focus: No additional user-provided focus was present.
  • Subagent convergence: NORMAL-ORC, NORMAL-PARQUET, RISK-STATS, and RISK-SARG all returned NO_NEW_VALUABLE_FINDINGS in round 1 after reading the current ledger.

Validation was static only. Per the review prompt I did not build or run tests; this checkout also lacks .worktree_initialized, thirdparty/installed, and thirdparty/installed/bin/protoc.

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 76.67% (69/90) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 56.91% (23547/41378)
Line Coverage 40.57% (230241/567537)
Region Coverage 36.48% (181967/498804)
Branch Coverage 37.54% (81206/216327)

@Gabriel39

Copy link
Copy Markdown
Contributor Author

Superseded by #65500, which consolidates and validates the four related fixes.

@Gabriel39 Gabriel39 closed this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants