1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00
Files
mariadb/sql/partition_element.h
Yuchen Pei e6fc36cfe3 MDEV-15621 Auto add RANGE COLUMNS partitions by interval
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.

Including the following fixes:

1.

MDEV-40088 Disallow subqueries in INTERVAL clause in range interval auto partitioning

This is consistent with system time (versioning) partitioning. Also
consistent is that both allow expressions otherwise.

2.

MDEV-40048 Allow trigger and LOCK TABLES to work with range interval auto partitioning

When a range interval auto partitioned table is the target of a
trigger, the triggering statement is not necessarily one that would
cause the auto-creation of new partitions, so we need to account for
that.

Also added support for LOCK TABLES ... WRITE.

Improved tests coverage by adapting tests from versioning.partition.

3.

MDEV-40467 Improve Y2038/2106 problem error message

When nearing the end times TIMESTAMP_MAX_VALUE, auto-partition
creation may encounter overflow when calculating new partition range.
This patch improves the message of such an overflow
2026-08-04 15:04:06 +10:00

174 lines
5.0 KiB
C++

#ifndef PARTITION_ELEMENT_INCLUDED
#define PARTITION_ELEMENT_INCLUDED
/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include "my_base.h" /* ha_rows */
#include "handler.h" /* UNDEF_NODEGROUP */
/**
* An enum and a struct to handle partitioning and subpartitioning.
*/
enum partition_type {
NOT_A_PARTITION= 0,
RANGE_PARTITION,
HASH_PARTITION,
LIST_PARTITION,
VERSIONING_PARTITION
};
enum partition_state {
PART_NORMAL= 0,
PART_IS_DROPPED= 1,
PART_TO_BE_DROPPED= 2,
PART_TO_BE_ADDED= 3,
PART_TO_BE_REORGED= 4,
PART_REORGED_DROPPED= 5,
PART_CHANGED= 6,
PART_IS_CHANGED= 7,
PART_IS_ADDED= 8,
PART_ADMIN= 9
};
/*
This struct is used to keep track of column expressions as part
of the COLUMNS concept in conjunction with RANGE and LIST partitioning.
The value can be either of MINVALUE, MAXVALUE and an expression that
must be constant and evaluate to the same type as the column it
represents.
The data in this fixed in two steps. The parser will only fill in whether
it is a max_value or provide an expression. Filling in
column_value, part_info, partition_id, null_value is done by the
function fix_column_value_function, and in the case of range
interval partitioning for auto-created partitions,
check_range_interval_constants.
*/
typedef struct p_column_list_val
{
void* column_value;
Item* item_expression;
partition_info *part_info;
uint partition_id;
bool max_value; // MAXVALUE for RANGE type or DEFAULT value for LIST type
bool null_value;
bool fixed;
} part_column_list_val;
/*
This struct is used to contain the value of an element
in the VALUES IN struct. It needs to keep knowledge of
whether it is a signed/unsigned value and whether it is
NULL or not.
*/
typedef struct p_elem_val
{
longlong value;
uint added_items;
bool null_value;
bool unsigned_flag;
part_column_list_val *col_val_array;
} part_elem_value;
struct st_ddl_log_memory_entry;
enum stat_trx_field
{
STAT_TRX_END= 0
};
class partition_element :public Sql_alloc
{
public:
enum elem_type_enum
{
CONVENTIONAL= 0,
CURRENT,
HISTORY
};
List<partition_element> subpartitions;
List<part_elem_value> list_val_list;
ha_rows part_max_rows;
ha_rows part_min_rows;
longlong range_value;
Lex_ident_partition partition_name;
struct st_ddl_log_memory_entry *log_entry;
const char* part_comment;
const char* data_file_name;
const char* index_file_name;
handlerton *engine_type;
enum partition_state part_state;
uint16 nodegroup_id;
bool has_null_value;
bool signed_flag; // Range value signed
bool max_value; // MAXVALUE range
uint32 id;
bool empty;
elem_type_enum type;
engine_option_value *option_list; // create options for partition
ha_table_option_struct *option_struct_part; // structure with parsed options
partition_element()
: part_max_rows(0), part_min_rows(0), range_value(0),
log_entry(NULL), part_comment(NULL),
data_file_name(NULL), index_file_name(NULL),
engine_type(NULL), part_state(PART_NORMAL),
nodegroup_id(UNDEF_NODEGROUP), has_null_value(FALSE),
signed_flag(FALSE), max_value(FALSE),
id(UINT_MAX32),
empty(true),
type(CONVENTIONAL),
option_list(NULL), option_struct_part(NULL)
{}
partition_element(partition_element *part_elem)
: part_max_rows(part_elem->part_max_rows),
part_min_rows(part_elem->part_min_rows),
range_value(0),
log_entry(NULL),
part_comment(part_elem->part_comment),
data_file_name(part_elem->data_file_name),
index_file_name(part_elem->index_file_name),
engine_type(part_elem->engine_type),
part_state(part_elem->part_state),
nodegroup_id(part_elem->nodegroup_id),
has_null_value(FALSE),
signed_flag(part_elem->signed_flag),
max_value(part_elem->max_value),
id(part_elem->id),
empty(part_elem->empty),
type(CONVENTIONAL),
option_list(part_elem->option_list),
option_struct_part(part_elem->option_struct_part)
{}
~partition_element() = default;
part_column_list_val& get_col_val(uint idx)
{
part_elem_value *ev= list_val_list.head();
DBUG_ASSERT(ev);
DBUG_ASSERT(ev->col_val_array);
return ev->col_val_array[idx];
}
};
#endif /* PARTITION_ELEMENT_INCLUDED */