Skip to content

Storages: introduce trim min-max index for DATE/DATETIME/TIMESTAMP rough set filtering#10982

Open
JaySon-Huang wants to merge 15 commits into
pingcap:feature/release-8.5-materialized-viewfrom
JaySon-Huang:jayson/trim_datetime_minmax_index_mv
Open

Storages: introduce trim min-max index for DATE/DATETIME/TIMESTAMP rough set filtering#10982
JaySon-Huang wants to merge 15 commits into
pingcap:feature/release-8.5-materialized-viewfrom
JaySon-Huang:jayson/trim_datetime_minmax_index_mv

Conversation

@JaySon-Huang

@JaySon-Huang JaySon-Huang commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #10989

Problem Summary:

What is changed and how it works?


Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added optional trim min-max indexing and query-aware temporal handling for DATE, DATETIME, and TIMESTAMP to improve rough-set filtering.
    • Introduced dt_enable_trim_minmax setting (default false) to control trim min-max generation and usage.
  • Bug Fixes

    • Corrected DeltaMerge metadata discovery/open so trim min-max .idx files aren’t treated as standard min-max indexes.
  • Tests

    • Added unit and end-to-end coverage for trim metadata persistence, eligibility, fallback behavior, and filtering correctness.
  • Documentation

    • Added a design specification for temporal trim min-max indexes and rollout.

Signed-off-by: JaySon-Huang <tshent@qq.com>
Add ColumnStat field 105, pack-mark accessors, trim subfile naming, and
default-off read/write settings so Readers can safely ignore or fall back
without changing ordinary min-max behavior.
Build ordinary and trim indexes in one pack scan for V3 MyDate/MyDateTime
columns, and persist .trim.idx only when trimmed outliers exist.
Normalize temporal ranges into DateRange, select trim indexes per DMFile stored E, and apply conservative low/high flag corrections in roughCheck.
@ti-chi-bot

ti-chi-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. labels Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

DeltaMerge adds optional temporal trim min-max indexes for date-like columns, including metadata persistence, DMFile writing and reading, query-domain planning, rough-check correction, configuration propagation, compatibility handling, tests, metrics, and a design specification.

Changes

Temporal trim min-max indexing

Layer / File(s) Summary
Trim metadata and file layout
dbms/src/Interpreters/Settings.h, dbms/src/Storages/DeltaMerge/File/..., dbms/src/Storages/DeltaMerge/dtpb/dmfile.proto
Adds trim settings, protobuf metadata, optional ColumnStat fields, trim-index filenames, cache keys, encryption paths, and metadata handling.
Trim index representation and writing
dbms/src/Storages/DeltaMerge/Index/..., dbms/src/Storages/DeltaMerge/File/DMFileWriter.*
Adds pack-mark handling, temporal bounds, trim metadata validation, combined ordinary/trim pack generation, and separate trim index subfiles.
Temporal query-domain planning
dbms/src/Storages/DeltaMerge/Filter/..., dbms/src/Storages/DeltaMerge/FilterParser/...
Adds temporal query domains, DateRange, trim-preferred index requests, predicate normalization, eligibility checks, and conservative rough-check correction.
Trim index loading and setting propagation
dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.*, dbms/src/Storages/DeltaMerge/Segment.*, dbms/src/Storages/StorageDisaggregatedRemote.cpp
Propagates trim-read configuration and loads, validates, caches, or falls back from trim indexes during pack filtering.
Compatibility tests, metrics, and design specification
dbms/src/Storages/DeltaMerge/tests/*, dbms/src/Storages/tests/gtest_filter_parser.cpp, dbms/src/Common/TiFlashMetrics.h, docs/design/*
Adds metadata, serialization, writing, query normalization, rough-check, end-to-end filtering tests, trim metrics, and the trim min-max design specification.

Estimated code review effort: 5 (Critical) | ~120 minutes

Poem

I’m a rabbit with bounds in my den,
Trimming old sentinels again.
Packs mark low, high, and null,
Queries hop through the index hull.
With tests and metadata neatly spun,
Temporal filtering now has fun!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The template is present, but the problem summary and implementation details are empty and no tests are checked. Fill in Problem Summary and What is changed and how it works, add at least one test entry, and use the required close #10989 issue format.
Docstring Coverage ⚠️ Warning Docstring coverage is 13.24% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main feature added: trim min-max index support for temporal rough-set filtering.
Linked Issues check ✅ Passed The changes implement optional trim min-max indexing for DATE/DATETIME/TIMESTAMP with persistence, fallback, eligibility checks, and tests, matching #10989.
Out of Scope Changes check ✅ Passed I don't see unrelated code changes; the diff is centered on the trim min-max feature, supporting tests, metrics, and docs.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ti-chi-bot

ti-chi-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign xuhuaiyu, yudongusa for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 15, 2026
Prevent same-column OR branches from incorrectly sharing a loaded trim
index when only some query domains are trim-eligible, avoiding false
None pack pruning.
Gate trim range normalization behind dt_enable_trim_minmax_read, keep
original operators when bounds cannot be parsed, and never return All
for an empty DateRange domain.
Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang
JaySon-Huang marked this pull request as ready for review July 16, 2026 08:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (6)
dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.h (1)

22-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Include the prescribed explicit-width type header.

Line 22 should use Core/Types.h rather than relying on the legacy type header.

Proposed fix
-#include <common/types.h>
+#include <Core/Types.h>

As per coding guidelines, explicit-width types must come from dbms/src/Core/Types.h.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.h` at line 22, Replace the
legacy common types include in TrimMinMaxIndex.h with the prescribed
Core/Types.h header, ensuring explicit-width types are sourced from the standard
Core type definitions.

Source: Coding guidelines

dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp (1)

784-820: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make this test distinguish trim from ordinary filtering.

The current [2020, 2021] query yields Some with the ordinary min-max index too, so EXPECT_NE(r, All) passes even if trim loading is broken.

Use an in-range gap such as [2050, 2051], then assert:

  • trim read disabled: Some
  • trim read enabled: None
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp` around
lines 784 - 820, The test PackFilterUsesTrimWhenReadEnabled must distinguish
trim behavior from ordinary min-max filtering. Change the query range to an
in-range gap such as [2050, 2051], add or reuse a scan with
enable_trim_minmax_read disabled and assert its pack result is Some, then keep
the enabled scan and assert its result is None rather than merely not All.
dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp (1)

108-147: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Variable naming convention mismatch with guidelines.

While the introduced variables align with the historical snake_case style used heavily throughout this repository, the coding guidelines prescribe camelCase for variables. Consider refactoring the variables in these blocks to camelCase to comply with the project standards.

  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp#L108-L147: Rename pack_mark, has_value, allowed_mask, min_idx, max_idx, and trimmed_mask to camelCase.
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp#L184-L195: Rename pack_mark to camelCase.
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp#L214-L217: Rename pack_marks and has_value_marks to camelCase.
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.h#L35-L38: Rename pack_marks_ and has_value_marks_ to camelCase.
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.h#L169-L171: Rename pack_marks and has_value_marks to camelCase.
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.h#L106-L110: Rename trim_minmaxes, trim_lower, and trim_upper to camelCase.
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.h#L131-L143: Rename enable_trim_minmax_write to camelCase.
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp#L116-L124: Rename can_trim and do_index_stream to camelCase.
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp#L133-L139: Rename do_index_stream to camelCase.
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp#L224-L239: Rename effective_del_mark to camelCase.
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp#L366-L395: Rename trim_index_bytes to camelCase.

As per coding guidelines:

Method and variable names should use camelCase (e.g., readBlock, totalBytes)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp` around lines 108 - 147,
Rename the listed variables and member variables to camelCase while preserving
behavior and updating every declaration, definition, reference, and call site:
in dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp ranges 108-147, 184-195,
and 214-217; dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.h ranges 35-38 and
169-171; dbms/src/Storages/DeltaMerge/File/DMFileWriter.h ranges 106-110 and
131-143; and dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp ranges 116-124,
133-139, 224-239, and 366-395. Specifically convert pack_mark, has_value,
allowed_mask, min_idx, max_idx, trimmed_mask, pack_marks, has_value_marks,
pack_marks_, has_value_marks_, trim_minmaxes, trim_lower, trim_upper,
enable_trim_minmax_write, can_trim, do_index_stream, effective_del_mark, and
trim_index_bytes to camelCase.

Source: Coding guidelines

dbms/src/Storages/tests/gtest_filter_parser.cpp (1)

459-460: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use fmt::format for string construction.

These lines construct queries using string concatenation. As per coding guidelines, C++ code should prefer fmt::format for string construction, similar to the other test cases further down in this file.

  • dbms/src/Storages/tests/gtest_filter_parser.cpp#L459-L460: Refactor this concatenation to use fmt::format.
  • dbms/src/Storages/tests/gtest_filter_parser.cpp#L484-L485: Refactor this concatenation to use fmt::format.
  • dbms/src/Storages/tests/gtest_filter_parser.cpp#L509-L510: Refactor this concatenation to use fmt::format.
♻️ Proposed refactors for all affected sites

For dbms/src/Storages/tests/gtest_filter_parser.cpp#L459-L460:

-        const auto query = String("select * from default.t_111 where col_timestamp > cast_string_datetime('")
-            + datetime + String("')");
+        const auto query = fmt::format("select * from default.t_111 where col_timestamp > cast_string_datetime('{}')", datetime);

For dbms/src/Storages/tests/gtest_filter_parser.cpp#L484-L485:

-        const auto query = String("select * from default.t_111 where col_timestamp > cast_string_datetime('")
-            + datetime + String("')");
+        const auto query = fmt::format("select * from default.t_111 where col_timestamp > cast_string_datetime('{}')", datetime);

For dbms/src/Storages/tests/gtest_filter_parser.cpp#L509-L510:

-        const auto query = String("select * from default.t_111 where col_timestamp > cast_string_datetime('")
-            + datetime + String("')");
+        const auto query = fmt::format("select * from default.t_111 where col_timestamp > cast_string_datetime('{}')", datetime);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/tests/gtest_filter_parser.cpp` around lines 459 - 460,
Replace the query string concatenation in
dbms/src/Storages/tests/gtest_filter_parser.cpp at lines 459-460, 484-485, and
509-510 with fmt::format, preserving each query’s existing text and datetime
substitution.

Source: Coding guidelines

dbms/src/Storages/DeltaMerge/Filter/RSOperator.h (1)

145-155: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Avoid copying elements when appending vectors.

Since child->getIndexRequests() returns RSIndexRequests by value, you can move its elements into reqs instead of copying them. RSIndexRequest contains an std::optional<DateQueryDomain>, which dynamically allocates its std::vector<Field>, so moving avoids unnecessary allocations.

♻️ Proposed refactor
     RSIndexRequests getIndexRequests() override
     {
         RSIndexRequests reqs;
         for (const auto & child : children)
         {
             auto child_reqs = child->getIndexRequests();
-            reqs.insert(reqs.end(), child_reqs.begin(), child_reqs.end());
+            reqs.insert(reqs.end(), std::make_move_iterator(child_reqs.begin()), std::make_move_iterator(child_reqs.end()));
         }
         return reqs;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/Filter/RSOperator.h` around lines 145 - 155,
Update RSOperator::getIndexRequests to move elements from each temporary
child_reqs into reqs when appending, using move-aware range insertion while
preserving the existing aggregation behavior.
docs/design/2026-07-14-trim-minmax-for-date-types.md (1)

513-513: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Escape pipe characters in Markdown tables.

The || operator inside the inline code block is interpreted as a table column delimiter by some Markdown parsers and linters, resulting in "Too many cells" rendering issues. Consider using or instead to ensure the table renders correctly across all tools.

♻️ Proposed refactor
-| Equality / IN / bounded range with `Q ⊆ E` | false | `has_trimmed_low || has_trimmed_high` |
+| Equality / IN / bounded range with `Q ⊆ E` | false | `has_trimmed_low or has_trimmed_high` |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/design/2026-07-14-trim-minmax-for-date-types.md` at line 513, Update the
table entry for “Equality / IN / bounded range with Q ⊆ E” to replace the
inline-code `||` operator with `or`, preserving the existing condition meaning
while preventing Markdown table parsing issues.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@dbms/src/Storages/DeltaMerge/Filter/RSOperator.h`:
- Around line 145-155: Update RSOperator::getIndexRequests to move elements from
each temporary child_reqs into reqs when appending, using move-aware range
insertion while preserving the existing aggregation behavior.

In `@dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp`:
- Around line 108-147: Rename the listed variables and member variables to
camelCase while preserving behavior and updating every declaration, definition,
reference, and call site: in dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp
ranges 108-147, 184-195, and 214-217;
dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.h ranges 35-38 and 169-171;
dbms/src/Storages/DeltaMerge/File/DMFileWriter.h ranges 106-110 and 131-143; and
dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp ranges 116-124, 133-139,
224-239, and 366-395. Specifically convert pack_mark, has_value, allowed_mask,
min_idx, max_idx, trimmed_mask, pack_marks, has_value_marks, pack_marks_,
has_value_marks_, trim_minmaxes, trim_lower, trim_upper,
enable_trim_minmax_write, can_trim, do_index_stream, effective_del_mark, and
trim_index_bytes to camelCase.

In `@dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.h`:
- Line 22: Replace the legacy common types include in TrimMinMaxIndex.h with the
prescribed Core/Types.h header, ensuring explicit-width types are sourced from
the standard Core type definitions.

In `@dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp`:
- Around line 784-820: The test PackFilterUsesTrimWhenReadEnabled must
distinguish trim behavior from ordinary min-max filtering. Change the query
range to an in-range gap such as [2050, 2051], add or reuse a scan with
enable_trim_minmax_read disabled and assert its pack result is Some, then keep
the enabled scan and assert its result is None rather than merely not All.

In `@dbms/src/Storages/tests/gtest_filter_parser.cpp`:
- Around line 459-460: Replace the query string concatenation in
dbms/src/Storages/tests/gtest_filter_parser.cpp at lines 459-460, 484-485, and
509-510 with fmt::format, preserving each query’s existing text and datetime
substitution.

In `@docs/design/2026-07-14-trim-minmax-for-date-types.md`:
- Line 513: Update the table entry for “Equality / IN / bounded range with Q ⊆
E” to replace the inline-code `||` operator with `or`, preserving the existing
condition meaning while preventing Markdown table parsing issues.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 80025a71-60f0-42c1-9527-1cbd354a2b5b

📥 Commits

Reviewing files that changed from the base of the PR and between 4b2815a and c1f3ebd.

📒 Files selected for processing (39)
  • dbms/src/Interpreters/Settings.h
  • dbms/src/Storages/DeltaMerge/File/ColumnStat.h
  • dbms/src/Storages/DeltaMerge/File/DMFile.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFile.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileMeta.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileMetaV2.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileMetaV2.h
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
  • dbms/src/Storages/DeltaMerge/File/DMFileUtil.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileUtil.h
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.h
  • dbms/src/Storages/DeltaMerge/Filter/DateQueryDomain.cpp
  • dbms/src/Storages/DeltaMerge/Filter/DateQueryDomain.h
  • dbms/src/Storages/DeltaMerge/Filter/DateRange.h
  • dbms/src/Storages/DeltaMerge/Filter/Equal.h
  • dbms/src/Storages/DeltaMerge/Filter/In.h
  • dbms/src/Storages/DeltaMerge/Filter/PushDownFilter.cpp
  • dbms/src/Storages/DeltaMerge/Filter/RSOperator.cpp
  • dbms/src/Storages/DeltaMerge/Filter/RSOperator.h
  • dbms/src/Storages/DeltaMerge/FilterParser/FilterParser.cpp
  • dbms/src/Storages/DeltaMerge/FilterParser/FilterParser.h
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.h
  • dbms/src/Storages/DeltaMerge/Index/RSIndex.h
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.h
  • dbms/src/Storages/DeltaMerge/Segment.cpp
  • dbms/src/Storages/DeltaMerge/Segment.h
  • dbms/src/Storages/DeltaMerge/dtpb/dmfile.proto
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_meta_version.cpp
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp
  • dbms/src/Storages/StorageDisaggregatedRemote.cpp
  • dbms/src/Storages/tests/gtest_filter_parser.cpp
  • docs/design/2026-07-14-trim-minmax-for-date-types.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp (1)

29-34: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Propagate dt_enable_trim_minmax into DMFileWriter::Options

DMFileWriter::addStreams only builds trim-minmax indexes when options.enable_trim_minmax_write is true, but this call site leaves it at the default false. Pass context.getSettingsRef().dt_enable_trim_minmax here so writers actually emit the trim artifacts that readers expect.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp` around lines
29 - 34, Update the DMFileWriter::Options construction in
DMFileBlockOutputStream to pass context.getSettingsRef().dt_enable_trim_minmax
as enable_trim_minmax_write, ensuring addStreams creates the expected
trim-minmax indexes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp`:
- Around line 29-34: Update the DMFileWriter::Options construction in
DMFileBlockOutputStream to pass context.getSettingsRef().dt_enable_trim_minmax
as enable_trim_minmax_write, ensuring addStreams creates the expected
trim-minmax indexes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fcd98fa9-8ed4-489c-a453-1fd670a76b11

📥 Commits

Reviewing files that changed from the base of the PR and between c1f3ebd and 73caf04.

📒 Files selected for processing (12)
  • dbms/src/Interpreters/Settings.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
  • dbms/src/Storages/DeltaMerge/Filter/PushDownFilter.cpp
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/Segment.cpp
  • dbms/src/Storages/DeltaMerge/Segment.h
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp
  • dbms/src/Storages/StorageDisaggregatedRemote.cpp
🚧 Files skipped from review as they are similar to previous changes (10)
  • dbms/src/Storages/DeltaMerge/Segment.h
  • dbms/src/Storages/StorageDisaggregatedRemote.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.cpp
  • dbms/src/Storages/DeltaMerge/Filter/PushDownFilter.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.h
  • dbms/src/Storages/DeltaMerge/Segment.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp

@JaySon-Huang
JaySon-Huang force-pushed the jayson/trim_datetime_minmax_index_mv branch from 73caf04 to 3dd7261 Compare July 16, 2026 14:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp`:
- Line 392: Update TrimMinMax::makeDefaultProps to persist the supplied pack
count via set_pack_count before returning the default properties. Ensure the
metadata created by the DMFileWriter call includes dmfile->getPacks(), allowing
readers to validate and load non-empty trim indexes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3746cbc8-080b-4371-87a5-3d60a40b1608

📥 Commits

Reviewing files that changed from the base of the PR and between 73caf04 and 3dd7261.

📒 Files selected for processing (20)
  • dbms/src/Interpreters/Settings.h
  • dbms/src/Storages/DeltaMerge/File/ColumnStat.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
  • dbms/src/Storages/DeltaMerge/File/DMFileUtil.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileUtil.h
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.h
  • dbms/src/Storages/DeltaMerge/Filter/DateRange.h
  • dbms/src/Storages/DeltaMerge/Filter/PushDownFilter.cpp
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/Segment.cpp
  • dbms/src/Storages/DeltaMerge/Segment.h
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_meta_version.cpp
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp
  • dbms/src/Storages/StorageDisaggregatedRemote.cpp
  • dbms/src/Storages/tests/gtest_filter_parser.cpp
🚧 Files skipped from review as they are similar to previous changes (17)
  • dbms/src/Storages/DeltaMerge/File/DMFileUtil.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFileUtil.h
  • dbms/src/Interpreters/Settings.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.cpp
  • dbms/src/Storages/StorageDisaggregatedRemote.cpp
  • dbms/src/Storages/DeltaMerge/Segment.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockInputStream.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
  • dbms/src/Storages/DeltaMerge/Filter/DateRange.h
  • dbms/src/Storages/tests/gtest_filter_parser.cpp
  • dbms/src/Storages/DeltaMerge/Segment.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_meta_version.cpp
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp
  • dbms/src/Storages/DeltaMerge/File/ColumnStat.h

merged_file.file_info.size += trim_index_bytes;
buffer->next();

col_stat.trim_minmax_index = TrimMinMax::makeDefaultProps(*removeNullable(type), dmfile->getPacks());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Persist the trim-index pack count in metadata.

TrimMinMax::makeDefaultProps(..., dmfile->getPacks()) currently ignores pack_count because set_pack_count is commented out. The reader validates this metadata against the actual pack count, so non-empty trim indexes will be rejected as MetadataMismatch and never loaded. Persist pack_count in makeDefaultProps before relying on this call.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp` at line 392, Update
TrimMinMax::makeDefaultProps to persist the supplied pack count via
set_pack_count before returning the default properties. Ensure the metadata
created by the DMFileWriter call includes dmfile->getPacks(), allowing readers
to validate and load non-empty trim indexes.

Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang
JaySon-Huang force-pushed the jayson/trim_datetime_minmax_index_mv branch from 3dd7261 to 99b9016 Compare July 16, 2026 15:10
@JaySon-Huang JaySon-Huang changed the title [WIP] Storages: introduce trim min-max index for DATE/DATETIME/TIMESTAMP rough set filtering Jul 17, 2026
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 17, 2026
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp (1)

158-171: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy lift

Exercise an actual legacy protobuf reader instead of manually clearing the field.

Using the current generated dtpb::ColumnStat and calling clear_trim_minmax_index() does not verify that an old reader can parse and rewrite field 105 or tolerate the additional merged subfile. Add a legacy-schema fixture or serialized old-reader round trip; retain this case separately to test fallback after metadata loss.

Based on PR objectives, old-reader and old-version metadata-rewrite compatibility must be validated.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp` around
lines 158 - 171, Replace the manual clear_trim_minmax_index() simulation in this
test with a legacy-schema fixture or serialized round trip using a protobuf
definition that omits field 105 and the additional merged subfile, then parse
and rewrite the bytes before calling ColumnStat::mergeFromProto. Keep this
scenario separate from the existing metadata-loss fallback test, which should
continue explicitly validating behavior after trim metadata is removed.
dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp (1)

282-282: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use explicit width type UInt8.

For consistency with pack_marks (PaddedPODArray<UInt8>) and to adhere to the coding guidelines, use UInt8 instead of unsigned char.

♻️ Proposed refactor
-    for (unsigned char pack_mark : pack_marks)
+    for (UInt8 pack_mark : pack_marks)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp` at line 282, Update
the range-based loop over pack_marks in the surrounding index logic to declare
pack_mark as UInt8 instead of unsigned char, preserving the existing iteration
behavior and matching pack_marks’ element type.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/design/2026-07-14-trim-minmax-for-date-types.md`:
- Around line 607-615: Replace the single dt_enable_trim_minmax setting with
independent write and read rollout controls: one governing trim-index generation
by writers and one governing trim metadata/subfile consumption by readers.
Update the documented enabled/disabled behavior and rollout sequence to support
write-first/read-later deployment and independent read rollback, including the
corresponding PreferTrim temporal-range normalization behavior.

---

Nitpick comments:
In `@dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp`:
- Line 282: Update the range-based loop over pack_marks in the surrounding index
logic to declare pack_mark as UInt8 instead of unsigned char, preserving the
existing iteration behavior and matching pack_marks’ element type.

In `@dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp`:
- Around line 158-171: Replace the manual clear_trim_minmax_index() simulation
in this test with a legacy-schema fixture or serialized round trip using a
protobuf definition that omits field 105 and the additional merged subfile, then
parse and rewrite the bytes before calling ColumnStat::mergeFromProto. Keep this
scenario separate from the existing metadata-loss fallback test, which should
continue explicitly validating behavior after trim metadata is removed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 171ba54e-0792-44ee-858d-ecadc1fe5944

📥 Commits

Reviewing files that changed from the base of the PR and between 99b9016 and c637776.

📒 Files selected for processing (18)
  • dbms/src/Common/TiFlashMetrics.h
  • dbms/src/Interpreters/Settings.h
  • dbms/src/Storages/DeltaMerge/File/DMFileBlockOutputStream.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.h
  • dbms/src/Storages/DeltaMerge/Filter/DateQueryDomain.cpp
  • dbms/src/Storages/DeltaMerge/Filter/DateQueryDomain.h
  • dbms/src/Storages/DeltaMerge/Filter/DateRange.h
  • dbms/src/Storages/DeltaMerge/Filter/Equal.h
  • dbms/src/Storages/DeltaMerge/Filter/In.h
  • dbms/src/Storages/DeltaMerge/Filter/RSOperator.h
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.cpp
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.h
  • dbms/src/Storages/DeltaMerge/tests/gtest_dm_trim_minmax_index.cpp
  • dbms/src/Storages/tests/gtest_filter_parser.cpp
  • docs/design/2026-07-14-trim-minmax-for-date-types.md
🚧 Files skipped from review as they are similar to previous changes (12)
  • dbms/src/Storages/DeltaMerge/File/DMFileWriter.h
  • dbms/src/Storages/DeltaMerge/Filter/Equal.h
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
  • dbms/src/Storages/DeltaMerge/Filter/DateQueryDomain.h
  • dbms/src/Interpreters/Settings.h
  • dbms/src/Storages/DeltaMerge/Filter/DateRange.h
  • dbms/src/Storages/DeltaMerge/Index/TrimMinMaxIndex.h
  • dbms/src/Storages/DeltaMerge/Filter/In.h
  • dbms/src/Storages/DeltaMerge/Filter/DateQueryDomain.cpp
  • dbms/src/Storages/DeltaMerge/Filter/RSOperator.h
  • dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp
  • dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp

Comment thread docs/design/2026-07-14-trim-minmax-for-date-types.md
Convert missing column types to Unsupported at parse time, and guard getIndexRequests/getRSIndex against empty Attr.type.
Signed-off-by: JaySon-Huang <tshent@qq.com>
…policy.

Cover NULL/delete/empty packs and DATE/DATETIME/TIMESTAMP temporal cases; document that invalid MergedSubFileInfo must throw rather than soft-fallback.
Unify DateRange/Equal/In on shared packs and cover AllNull for {NULL,2021}.
Cover != / NOT / OR / CAST with no PreferTrim, and out-of-E ranges that stay ineligible.
@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@JaySon-Huang: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-integration-test 40f8ef8 link true /test pull-integration-test
pull-unit-test 40f8ef8 link true /test pull-unit-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant