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

change p_column_list_val::fixed to a bool
remove redundant end label in partition_info::fix_column_value_functions
@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
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

When performing DML on such a table, it will first add partitions
by the specified interval until the partition covers the current time.

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.
Comment thread sql/sql_base.cc
table->vers_switch_partition(thd, table_list, ot_ctx))
(table->vers_switch_partition(thd, table_list, ot_ctx) ||
table->range_interval_check_partition(thd, table_list, ot_ctx))
)
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.

Please fix code formatting above.

Comment thread sql/sql_partition.cc
{
err+= str.append(STRING_WITH_LEN(" COLUMNS"));
err+= add_part_field_list(thd, &str, part_info->part_field_list);
err+= str.append(STRING_WITH_LEN("INTERVAL "));
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.

Currently table ddls lack visibly lack space:

 PARTITION BY RANGE  COLUMNS(`c`)INTERVAL 1 DAY

make above " INTERVAL " ?

Comment thread sql/partition_info.cc
if (prep_alter_part_table(thd, table, &alter_info, &create_info,
&partition_changed, &fast_alter_partition))
{
my_error(ER_INTERNAL_ERROR, MYF(ME_WARNING),
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.

Are we going to keep using ER_INTERNAL_ERROR in the final patch (is this what versioning code uses?)

Comment thread sql/partition_info.cc
/*
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...)

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?

Comment thread sql/partition_info.cc
my_error(ER_INTERNAL_ERROR, MYF(0), "no range partition specified");
return true;
}
Item *item= el->get_col_val(0).item_expression;
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.

Can this function get more comments and be made easier to read?
Example 1: so we get an item...
and then... do nothing with it.. only some lines after we use it to get the last partition endpoint.

Image

Comment thread sql/partition_info.cc
part_elem->range_value= val->value;
}
col_val->fixed= 2;
col_val->fixed= TRUE;
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.

What is the reason for this change?
If we no longer assign 'col_val->fixed= 2' , should the comment in part_column_list_val be updated?

Comment thread sql/partition_info.cc
the ORACLE NUMTODSINTERVAL/NUMTOYMINTERVAL format
*/
bool partition_info::set_range_interval(int num, LEX_CSTRING &type,
bool is_ds,
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.

Please add a comment that is_ds is true for days and false for year-month intervals.

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