Skip to content

MDEV-15621 Auto add RANGE COLUMNS partitions by interval#5152

Open
mariadb-YuchenPei wants to merge 3 commits into
mainfrom
bb-main-mdev-15621
Open

MDEV-15621 Auto add RANGE COLUMNS partitions by interval#5152
mariadb-YuchenPei wants to merge 3 commits into
mainfrom
bb-main-mdev-15621

Conversation

@mariadb-YuchenPei
Copy link
Copy Markdown
Contributor

@mariadb-YuchenPei mariadb-YuchenPei commented Jun 1, 2026

Reviving #5111

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 introduces range interval partitioning support for DATE, DATETIME, and TIMESTAMP columns, allowing automatic partition creation during DML operations. The changes include parser updates to support interval syntax (including Oracle-style interval functions) and core partitioning logic modifications. The review feedback highlights several critical issues: a missing copy of the interval struct during partition creation that would cause duplicate range values, potential out-of-bounds reads in the parser due to passing non-null-terminated strings to atoi, and multiple potential null-pointer dereferences or crashes in the partitioning and memory allocation paths.

Comment thread sql/partition_info.cc
Comment thread sql/sql_yacc.yy
Comment thread sql/sql_yacc.yy
Comment thread sql/partition_info.cc Outdated
Comment thread sql/sql_partition.cc Outdated
Comment thread sql/sql_partition.cc
@mariadb-YuchenPei mariadb-YuchenPei force-pushed the bb-main-mdev-15621 branch 2 times, most recently from c2470f1 to 4ab6759 Compare June 1, 2026 07:54
Comment thread sql/sql_base.cc Outdated
Comment thread sql/sql_partition.cc Outdated
Comment thread sql/partition_info.cc
Comment thread sql/partition_info.cc Outdated
/*
TODO(MDEV-15621): need to save reprepare observer and
reset_n_backup_query_tables_list like in vers_create_partitions?
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(for the record: I don't have a clear idea why the above would be needed...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed the parts from vers_create_partitions and it did not cause any extra failures on bb, see bb-mdev-15621-demo e181191 and https://buildbot.mariadb.org/#grid?branch=bb-mdev-15621-demo

Comment thread sql/sql_base.cc
case SQLCOM_REPLACE:
case SQLCOM_REPLACE_SELECT:
case SQLCOM_UPDATE_MULTI:
break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also handle SQLCOM_DELETE_MULTI ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another question: do we have coverage for this scenario:
Row-based replication slave.
We execute CREATE TABLE t1 which creates a table with no partition for today.
Then we read an RBR event inserting a row with today's date.
Will we be able to catch the "opening table with no partition for today" and create the partition?

Copy link
Copy Markdown
Contributor Author

@mariadb-YuchenPei mariadb-YuchenPei Jun 2, 2026

Choose a reason for hiding this comment

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

Also handle SQLCOM_DELETE_MULTI ?

@spetrunia Why would a DELETE statement require new partitions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re RBR: yes this could be a problem like https://jira.mariadb.org/browse/MDEV-39808

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread sql/partition_info.cc Outdated
Comment thread sql/partition_info.cc
Comment thread sql/partition_info.cc
@mariadb-YuchenPei mariadb-YuchenPei force-pushed the bb-main-mdev-15621 branch 5 times, most recently from 9f9dcb7 to 2364306 Compare June 3, 2026 07:26
@mariadb-YuchenPei mariadb-YuchenPei force-pushed the bb-main-mdev-15621 branch 2 times, most recently from 9d84af4 to 3955992 Compare June 4, 2026 07:53
change p_column_list_val::fixed to a bool
remove redundant end label in partition_info::fix_column_value_functions
@mariadb-YuchenPei
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 implements range interval partitioning for RANGE COLUMNS on DATE, DATETIME, and TIMESTAMP columns, allowing automatic partition creation during DML operations. It also adds support for Oracle-style NUMTODSINTERVAL and NUMTOYMINTERVAL syntax. The code review comments identify several critical improvements, including adding defensive null checks to prevent potential server crashes when accessing partition expressions, refactoring warning and write-set restoration logic to ensure robust cleanup, and replacing raw malloc/free calls with MariaDB-compliant my_alloca/my_afree memory management.

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 sql/partition_info.cc
Comment thread sql/sql_partition.cc Outdated
Comment thread sql/sql_partition.cc
Comment thread sql/partition_info.h Outdated
Comment thread sql/partition_info.h Outdated
@mariadb-YuchenPei
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 implements auto-creation of RANGE COLUMNS partitions by interval (MDEV-15621), allowing partitions to be automatically added during DML operations when inserted values exceed existing ranges. It also introduces Oracle-compatible interval syntax (NUMTODSINTERVAL and NUMTOYMINTERVAL). The review feedback highlights a critical issue in sql/partition_info.cc where the reprepare observer and query tables list are not saved or restored during partition creation, which could lead to metadata lock conflicts or memory corruption. Additionally, an unrelated change in extra/mariadb_migrate_config_file.c should be moved to a separate pull request.

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 sql/partition_info.cc Outdated
Comment thread extra/mariadb_migrate_config_file.c
@mariadb-YuchenPei
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 implements range interval partitioning for RANGE COLUMNS on date and time columns, enabling automatic partition creation during DML operations. Key feedback includes: reverting the change of fixed to bool in part_column_list_val as it collapses the required three-state logic and breaks partition fixing; adding support for compressed row event types to prevent replication failures when binlog row compression is enabled; explicitly checking for part_id == 0 to avoid an underflow to UINT_MAX when calling partitions.elem(part_id - 1); and checking the return value of List::push_back to handle out-of-memory errors gracefully.

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 sql/partition_element.h
Comment thread sql/sql_base.cc
Comment on lines +1956 to +1960
case UPDATE_ROWS_EVENT:
case UPDATE_ROWS_EVENT_V1:
case WRITE_ROWS_EVENT:
case WRITE_ROWS_EVENT_V1:
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

To fully support replication when binlog row compression is enabled, we must also handle the compressed row event types (WRITE_ROWS_COMPRESSED_EVENT, WRITE_ROWS_COMPRESSED_EVENT_V1, UPDATE_ROWS_COMPRESSED_EVENT, and UPDATE_ROWS_COMPRESSED_EVENT_V1). Otherwise, the slave will fail to auto-create partitions when applying compressed row events, leading to replication failures.

      case UPDATE_ROWS_EVENT:
      case UPDATE_ROWS_EVENT_V1:
      case UPDATE_ROWS_COMPRESSED_EVENT:
      case UPDATE_ROWS_COMPRESSED_EVENT_V1:
      case WRITE_ROWS_EVENT:
      case WRITE_ROWS_EVENT_V1:
      case WRITE_ROWS_COMPRESSED_EVENT:
      case WRITE_ROWS_COMPRESSED_EVENT_V1:
        break;

Comment thread sql/sql_partition.cc
Comment thread sql/sql_partition.cc Outdated
Allow auto partitioning by interval in PARTITION BY RANGE COLUMNS

PARTITION BY RANGE COLUMNS (col_name)
INTERVAL interval [AUTO]
(
  PARTITION partition_name VALUES LESS THAN (value)
  [, PARTITION partition_name VALUES LESS THAN (value) ... ]
)

where

- col_name is the name of one column of type DATE or DATETIME or
  TIMESTAMP

- at least one partition is supplied, and the highest partition cannot
  have MAXVALUE range

- INTERVAL interval is a positive time interval. it can be mariadb
  format or oracle NUMTODSINTERVAL/NUMTOYMINTERVAL format. Like
  versioning, the smallest unit is second, i.e. no subsecond like
  microsecond.

- DATE column cannot have interval with values less than a day

- Subpartitions are allowed, but restricted to existing subpartition
  types, i.e. [LINEAR] (KEY|HASH)

When performing one of the following DML statements on such a table,
it will first add partitions by the specified interval until the
partition covers the current time:

- INSERT
- INSERT ... SELECT
- LOAD
- UPDATE
- REPLACE
- REPLACE ... SELECT

Partition addition will not cause an implicit commit like DDL normally
does.

The partitions are named pN.

Otherwise the table behaves exactly the same as a normal RANGE COLUMNS
partitioned table.

Note that TIMESTAMP is not allowed as a type for PARTITION BY RANGE
COLUMNS otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants