Skip to content

MDEV-25529 Auto-create: Pre-existing historical data is not partitioned as specified by ALTER#5294

Open
midenok wants to merge 8 commits into
mainfrom
main-midenok-MDEV-25529
Open

MDEV-25529 Auto-create: Pre-existing historical data is not partitioned as specified by ALTER#5294
midenok wants to merge 8 commits into
mainfrom
main-midenok-MDEV-25529

Conversation

@midenok

@midenok midenok commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Please, review.

* get_next_time() comment
* THD::used comment
Copilot AI review requested due to automatic review settings June 29, 2026 11:01
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request improves the ALTER TABLE FORCE syntax and implements automatic partitioning of pre-existing historical data for system-versioned tables (MDEV-25529). Key changes include adding high-precision timestamp helpers, updating parser rules to allow flexible ordering of partitioning clauses, and introducing logic to calculate the required history partitions based on the table's actual historical time range. The feedback suggests renaming the generic cmp function in my_time.h to avoid global namespace collisions, removing a temporary TODO comment, initializing best_idx to prevent compiler warnings, and simplifying the partition calculation logic in vers_calc_hist_parts.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread include/my_time.h
Comment thread sql/partition_info.cc
Comment thread sql/sql_table.cc
Comment thread sql/sql_partition.cc Outdated

Copilot AI 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.

Pull request overview

This PR addresses MDEV-25529 by ensuring that when ALTER TABLE ... PARTITION BY SYSTEM_TIME ... AUTO is used on a system-versioned table, pre-existing historical rows are accounted for when auto-creating history partitions (including adjusting STARTS when needed). It also expands ALTER TABLE grammar around FORCE + partitioning clauses and adds supporting timestamp/time utilities plus new regression tests.

Changes:

  • Derive historical ROW END timestamp range (index-first, scan fallback) and use it during versioning partition auto-setup on ALTER to size partitions and/or adjust STARTS.
  • Add my_timespec_t and session-timezone timestamp formatting helpers used in warnings/debug paths.
  • Extend parser grammar for more ALTER TABLE clause orderings and add/refresh mysql-test coverage for both MDEV-25529 behavior and FORCE syntax.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sql/table.h Declares TABLE::vers_get_history_range() for versioned-table history range discovery.
sql/sql_yacc.yy Extends ALTER TABLE grammar to allow additional orderings for partitioning/remove partitioning with other alter clauses.
sql/sql_type.h Declares Temporal_hybrid(THD*, my_timespec_t) ctor for high-precision timestamps.
sql/sql_type.cc Implements Temporal_hybrid(THD*, my_timespec_t) conversion via session time zone.
sql/sql_time.h Adds interval2sec() / interval2usec() helpers to replace macro-based interval math.
sql/sql_time.cc Switches interval microsecond calculations to the new helpers.
sql/sql_table.cc Minor refactor in duplicate-key check predicate naming; adds include needed for key utilities.
sql/sql_partition.cc Main logic: on relevant ALTER, compute history range, adjust STARTS, and compute needed history partitions (incl. month/year stepping).
sql/sql_class.h Adds THD::timestamp_to_string() overloads and TimestampString helper for lazy formatting.
sql/sql_class.cc Implements THD::timestamp_to_string() using Temporal_hybrid and marks TIME_ZONE_USED.
sql/share/errmsg-utf8.txt Reworks/introduces warnings related to STARTS and slow history scanning; adds new warning messages.
sql/partition_info.h Tracks whether STARTS was explicitly provided; adds vers_set_starts() API.
sql/partition_info.cc Implements vers_set_starts() rounding; improves interval warning message; adds OOM error on default partition element allocation.
sql/field.h Adds Field_vers_trx_id::get_timestamp() override declaration.
sql/field.cc Implements transaction-registry timestamp lookup for TRX_ID-versioned fields.
sql/event_data_objects.cc Expands documentation comment for interval scheduling behavior.
mysql-test/suite/versioning/t/partition2.test Adds comprehensive regression test for MDEV-25529 (index vs scan paths, STARTS adjustments, month/year intervals, etc.).
mysql-test/suite/versioning/r/partition2.result Expected output for the new versioning partition regression test.
mysql-test/suite/versioning/r/partition.result Updates expected warnings text for STARTS-beyond-query messages.
mysql-test/main/partition.test Adds FORCE syntax regression coverage for ALTER TABLE partitioning/remove partitioning.
mysql-test/main/partition.result Expected output for new FORCE syntax test cases.
include/my_time.h Introduces my_timespec_t, ordering operators, and min/max constants for high-precision timestamps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sql/share/errmsg-utf8.txt
Comment thread sql/share/errmsg-utf8.txt
Comment thread include/my_time.h

Copilot AI 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.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Comment thread sql/sql_class.cc
Comment thread sql/field.cc
midenok added 7 commits June 29, 2026 15:12
Improves ALTER TABLE syntax when alter_list can be supplied alongside a
partitioning expression, so that they can appear in any order. This is
particularly useful for the FORCE clause when adding it to an existing
command.

Also improves handling of AUTO with FORCE, so that AUTO FORCE
specified together provides more consistent syntax, which is used by
this task in further commits.
…ed as specified by ALTER

Adds logic into prep_alter_part_table() for AUTO to check the history
range (vers_get_history_range()) and based on (max_ts - min_ts)
difference compute the number of created partitions and set STARTS
value to round down min_ts value (vers_set_starts()) if it was not
specified by user or if the user specified it incorrectly. In the
latter case it will print warning about wrongly specified user value.

In case of fast ALTER TABLE, f.ex. when partitioning already exists,
the above logic is ignored unless FORCE clause is specified. When user
specifies partition list explicitly the above logic is ignored even
with FORCE clause.

vers_get_history_range() detects if the index can be used for row_end
min/max stats and if so it gets it with ha_index_first() and
HA_READ_BEFORE_KEY (as it must ignore current data). Otherwise it does
table scan to read the stats. There is test_mdev-25529 debug keyword
to check the both and compare results. A warning is printed if the
algorithm uses slow scan.

Field_vers_trx_id::get_timestamp() is implemented for TRX_ID based
versioning to get epoch value. It works in vers_get_history_range()
but since partitioning is not enabled for TRX_ID versioning create
temporary table fails with error, requiring timestamp-based system
fields. This method will be useful when partitioning will be enabled
for TRX_ID which is mostly performance problems to solve.

Static key_cmp was renamed to key_eq to resolve compilation after
key.h was included as key_cmp was already declared there.

Copilot AI 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.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Comment thread sql/sql_partition.cc
Comment on lines +6164 to +6166
if (table->versioned() &&
(alter_info->partition_flags & ALTER_PARTITION_INFO) &&
part_info->part_type == VERSIONING_PARTITION &&
Comment thread sql/sql_table.cc
Comment on lines +13966 to +13970
DBUG_ASSERT(versioned());
// Find best key
KEY *key= key_info, *best_key= NULL;
uint best_idx;
Field *end_field= vers_end_field();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants