Skip to content

Support commit ts in TiFlash#10723

Open
xzhangxian1008 wants to merge 1 commit intopingcap:masterfrom
xzhangxian1008:commit-ts2
Open

Support commit ts in TiFlash#10723
xzhangxian1008 wants to merge 1 commit intopingcap:masterfrom
xzhangxian1008:commit-ts2

Conversation

@xzhangxian1008
Copy link
Contributor

@xzhangxian1008 xzhangxian1008 commented Feb 13, 2026

What problem does this PR solve?

Issue Number: ref #10715

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

  • New Features

    • Added support for commit timestamp column aliasing and automatic type casting in storage operations to ensure data type consistency across queries and filters.
  • Tests

    • Introduced comprehensive test suite covering commit timestamp column handling, including aliasing behavior, type conversion, filter mapping, and rough set operations to validate proper column identification and data transformation.

@ti-chi-bot ti-chi-bot bot added the release-note-none Denotes a PR that doesn't merit a release note. label Feb 13, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 13, 2026

[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 schrodingerzhu 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

@pantheon-ai
Copy link

pantheon-ai bot commented Feb 13, 2026

Review Completed ✅

Status: 4 issues identified and posted as PR review comments

Findings Summary:

  • 1 P0 issue (build blocker)
  • 1 P1 issue (test build blocker)
  • 2 P2 issues (runtime issues)

Review Links:

Issues Found:

  1. P0 - Undefined ExtraCommitTSColumnID breaks build

    • Location: dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp:1261
    • Impact: Production code will not compile
  2. P1 - New gtest does not compile

    • Location: dbms/src/Storages/tests/gtest_hidden_commit_ts_column.cpp:23
    • Impact: Test builds fail
  3. P2 - Rough set filter commit_ts alias uses wrong map key

    • Location: dbms/src/Storages/DeltaMerge/Filter/RSOperator.cpp:76
    • Impact: Queries with commit_ts filters will throw std::out_of_range
  4. P2 - Disaggregated read rejects commit_ts

    • Location: dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp:137
    • Impact: Commit_ts support incomplete for disaggregated mode

Recommendation: Address the P0 and P1 issues before merging to ensure the code builds successfully.

@ti-chi-bot ti-chi-bot bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 13, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

This PR introduces support for a hidden commit timestamp column (ID -5) by adding aliasing and casting logic across the TiFlash query execution pipeline. The column ID is mapped to the internal version column throughout storage access, filtering, and expression analysis components, with comprehensive tests validating the aliasing and type casting behavior.

Changes

Cohort / File(s) Summary
Core Column ID Definition
dbms/src/Storages/MutableSupport.h
Adds new constant extra_commit_ts_col_id = -5 to the MutSup class for identifying TiDB's hidden commit timestamp column.
Query Execution Pipeline
dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp, dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp, dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp, dbms/src/Flash/Coprocessor/RemoteRequest.cpp
Maps the hidden commit timestamp column ID to the version column name/ID during schema generation, storage interpreter column resolution, and expression analysis casting logic.
Filter Execution Components
dbms/src/Storages/DeltaMerge/Filter/PushDownExecutor.cpp, dbms/src/Storages/DeltaMerge/Filter/RSOperator.cpp, dbms/src/Storages/DeltaMerge/FilterParser/FilterParser.cpp
Adds remapping logic to translate the hidden commit timestamp column ID to the version column ID during filter attribute creation and column selection for rough set and push-down filters.
Test Suite
dbms/src/Storages/tests/gtest_hidden_commit_ts_column.cpp
Introduces comprehensive test fixture with three test cases validating hidden commit_ts column aliasing, type casting after table scan, and rough set filter mapping behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/L

Suggested reviewers

  • gengliqi
  • JinheLin
  • kolafish

Poem

🐰 A hidden column hops into view,
Extra commit_ts mapped just right and true,
Version and filters align in the dance,
Through DAG and storage, they all take their chance,
Five tests hop along to ensure it's all well! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete; it lacks problem summary, implementation details in the commit-message block, and does not explain the changes made despite having a substantial changeset. Add a detailed problem summary explaining the issue being solved, fill the commit-message block with implementation details, and describe how the changes enable commit ts support in TiFlash.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Support commit ts in TiFlash' directly aligns with the main change: adding support for handling commit timestamp columns across multiple TiFlash components.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp`:
- Around line 136-138: The throw in the switch case for
MutSup::extra_commit_ts_col_id in GenSchemaAndColumn.cpp omits an ErrorCodes
value; update the throw to include a DB::ErrorCodes enum (e.g.,
ErrorCodes::NOT_IMPLEMENTED) so it follows the pattern throw Exception("Not
supported in disaggregated read now", ErrorCodes::NOT_IMPLEMENTED); — locate the
case handling MutSup::extra_commit_ts_col_id and replace the current throw
Exception(...) with one that passes the appropriate ErrorCodes::... constant.

In `@dbms/src/Storages/MutableSupport.h`:
- Line 46: Rename the snake_case constant extra_commit_ts_col_id to camelCase
extraCommitTsColId and update every usage and reference accordingly; locate the
declaration inline static constexpr ColumnID extra_commit_ts_col_id in
MutableSupport.h and change the identifier, then update all call sites, static
casts, comments, and any tests or documentation that use extra_commit_ts_col_id
so they reference extraCommitTsColId to comply with the project's naming
guideline.

In `@dbms/src/Storages/tests/gtest_hidden_commit_ts_column.cpp`:
- Line 46: Update the inline comment that reads "Maybe another test has already
registed, ignore exception here." to correct the typo: change "registed" to
"registered" so it reads "Maybe another test has already registered, ignore
exception here." — edit this comment in gtest_hidden_commit_ts_column.cpp (the
comment string above the exception-handling block) to fix the spelling only.

Comment on lines +136 to 138
case MutSup::extra_commit_ts_col_id:
throw Exception("Not supported in disaggregated read now");
default:
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add an ErrorCodes value to this Exception.

The current throw omits an error code, which makes error handling inconsistent.

🔧 Suggested fix
-        case MutSup::extra_commit_ts_col_id:
-            throw Exception("Not supported in disaggregated read now");
+        case MutSup::extra_commit_ts_col_id:
+            throw Exception("Not supported in disaggregated read now", ErrorCodes::NOT_IMPLEMENTED);
As per coding guidelines, "Use DB::Exception for error handling in C++. Pattern: throw Exception("Message", ErrorCodes::SOME_CODE);"
🤖 Prompt for AI Agents
In `@dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp` around lines 136 - 138,
The throw in the switch case for MutSup::extra_commit_ts_col_id in
GenSchemaAndColumn.cpp omits an ErrorCodes value; update the throw to include a
DB::ErrorCodes enum (e.g., ErrorCodes::NOT_IMPLEMENTED) so it follows the
pattern throw Exception("Not supported in disaggregated read now",
ErrorCodes::NOT_IMPLEMENTED); — locate the case handling
MutSup::extra_commit_ts_col_id and replace the current throw Exception(...) with
one that passes the appropriate ErrorCodes::... constant.


inline static constexpr ColumnID extra_handle_id = -1;
inline static constexpr ColumnID extra_table_id_col_id = -3;
inline static constexpr ColumnID extra_commit_ts_col_id = -5;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Rename to camelCase to match naming guideline.

extra_commit_ts_col_id introduces a new snake_case identifier.

🔧 Suggested rename (plus update all usages)
-    inline static constexpr ColumnID extra_commit_ts_col_id = -5;
+    inline static constexpr ColumnID extraCommitTsColId = -5;
As per coding guidelines, "Method and variable names in C++ must use camelCase (e.g., readBlock, totalBytes)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
inline static constexpr ColumnID extra_commit_ts_col_id = -5;
inline static constexpr ColumnID extraCommitTsColId = -5;
🤖 Prompt for AI Agents
In `@dbms/src/Storages/MutableSupport.h` at line 46, Rename the snake_case
constant extra_commit_ts_col_id to camelCase extraCommitTsColId and update every
usage and reference accordingly; locate the declaration inline static constexpr
ColumnID extra_commit_ts_col_id in MutableSupport.h and change the identifier,
then update all call sites, static casts, comments, and any tests or
documentation that use extra_commit_ts_col_id so they reference
extraCommitTsColId to comply with the project's naming guideline.

}
catch (DB::Exception &)
{
// Maybe another test has already registed, ignore exception here.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo: "registed" → "registered".

-            // Maybe another test has already registed, ignore exception here.
+            // Maybe another test has already registered, ignore exception here.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Maybe another test has already registed, ignore exception here.
// Maybe another test has already registered, ignore exception here.
🤖 Prompt for AI Agents
In `@dbms/src/Storages/tests/gtest_hidden_commit_ts_column.cpp` at line 46, Update
the inline comment that reads "Maybe another test has already registed, ignore
exception here." to correct the typo: change "registed" to "registered" so it
reads "Maybe another test has already registered, ignore exception here." — edit
this comment in gtest_hidden_commit_ts_column.cpp (the comment string above the
exception-handling block) to fix the spelling only.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 13, 2026

@xzhangxian1008: 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-next-gen 3a03090 link true /test pull-integration-next-gen
pull-integration-test 3a03090 link true /test pull-integration-test
pull-unit-next-gen 3a03090 link true /test pull-unit-next-gen
pull-unit-test 3a03090 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.

has_cast = true;
}

if (may_need_add_cast_column[i] && table_scan_columns[i].id == ExtraCommitTSColumnID)
Copy link

Choose a reason for hiding this comment

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

P0 - Undefined ExtraCommitTSColumnID breaks build

ExtraCommitTSColumnID is referenced but not defined anywhere in the codebase, causing build failure.

Evidence: This file is part of the default flash_service library build. A repo-wide search shows only uses (no definition) at line 1261 and in test file.

Likely fix: Use MutSup::extra_commit_ts_col_id (defined in Storages/MutableSupport.h:46).

ColumnID col_id = col_info.id;
// TiDB may request a hidden commit_ts column in TableScan with a special ColumnID.
// In TiFlash it is stored in `_INTERNAL_VERSION` (VersionColumnID), so create an alias mapping.
if (unlikely(col_id == MutSup::extra_commit_ts_col_id))
Copy link

Choose a reason for hiding this comment

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

P2 - Rough set filter commit_ts alias uses wrong map key

RSOperator::build intends to alias TiDB's hidden commit_ts ColumnID (-5) to TiFlash's internal version ColumnID (-1024), but only populates the map under key -1024. Later, FilterParser resolves ColumnRef to the original ColumnID (-5) and calls id_to_attr.at(-5), which will throw std::out_of_range if a filter references commit_ts.

Evidence: Line 76 rewrites col_id from -5 to -1024, but map insertion at line 89 uses column_id_to_attr[cd.id], creating key -1024 only. Later lookup at FilterParser.cpp:168 uses the original -5.

Suggested fix: Populate the map under both keys, or adjust the lookup to use the aliased key.

#include <IO/Buffer/WriteBufferFromString.h>
#include <Interpreters/Context.h>
#include <Storages/DeltaMerge/DeltaMergeDefines.h>
#include <Storages/DeltaMerge/Filter/PushDownFilter.h>
Copy link

Choose a reason for hiding this comment

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

P1 - New gtest does not compile (multiple issues)

This test file has several compilation errors that block the gtests_dbms build:

  1. Line 23: Includes non-existent header <Storages/DeltaMerge/Filter/PushDownFilter.h> (directory contains PushDownExecutor.* instead)
  2. Lines 63, 92, 94, 225: References undefined constants ExtraCommitTSColumnID, VERSION_COLUMN_ID, VERSION_COLUMN_NAME, VERSION_COLUMN_TYPE, and non-existent DM::PushDownFilter::build(...) API
  3. Line 215: Calls DAGQueryInfo constructor with wrong signature (missing fts_query_info parameter)

Evidence: Current code uses DB::MutSup::{extra_commit_ts_col_id, version_col_id, version_column_name, getVersionColumnType()} and DM::getVersionColumnDefine() instead.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 13, 2026

@pantheon-ai[bot]: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

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.

break;
}
case MutSup::extra_commit_ts_col_id:
throw Exception("Not supported in disaggregated read now");
Copy link

Choose a reason for hiding this comment

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

P2 - Disaggregated read rejects commit_ts

Disaggregated compute mode's TableScan path unconditionally throws when it encounters the hidden commit_ts ColumnID (MutSup::extra_commit_ts_col_id, -5), so any DAG request that includes that column will fail in disaggregated mode.

Evidence:

  • Line 137: case MutSup::extra_commit_ts_col_id: throw Exception(\"Not supported in disaggregated read now\");
  • Called from StorageDisaggregatedRemote.cpp:759 and :833
  • Non-disaggregated paths map -5 to _INTERNAL_VERSION instead of rejecting it

Suggested fix: Implement the same aliasing behavior (-5 → version column) for disaggregated mode instead of throwing.

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant