You can create a hybrid partitioned table to access data stored in different storage engines.
The following diagram illustrates how hybrid partition works.
Hybrid partition separates hot and cold data by storing a table's partitions on different storage media. This reduces storage costs for cold data without affecting query performance or DML operations on hot data.
To archive a partitioned table as a hybrid partitioned table, the following conditions must be met:
-
MySQL 8.0.2 and the minor version is 8.0.2.2.34.1 or later. You must set the
loose_polar_allow_create_hybrid_partitionparameter toON. -
MySQL 8.0.2 and the minor version is earlier than 8.0.2.2.34.1. Upgrade to a later minor version.
Prerequisites
Your cluster must run PolarDB for MySQL 8.0.2 with revision version 8.0.2.2.34.1 or later. You can view the version number to check your cluster version.
The data files for the partitions you want to create must already exist in OSS, and their names must follow these rules:
File extensions and partition markers must be in uppercase.
Table and partition names must match those in the database.
For example, if the
p1partition of tablet1uses the CSV engine, the data file for the partition is namedt1#P#p1.CSV.Partitioned tables archived through cold data archiving can be archived as hybrid partitioned tables.
Limitations
A hybrid partitioned table must contain at least one partition that uses the InnoDB storage engine. The table-level engine must be InnoDB.
When you create a hybrid partitioned table with subpartitions, the first-level partition's engine must match the table's engine, and at least one subpartition must use the InnoDB storage engine.
Hybrid partitioned tables support only
RANGEandLISTpartition types.DML operations (including
INSERT,UPDATE,DELETE, orLOAD) are not supported on OSS partitions in hybrid partitioned tables.
Parameters
When you use hybrid partitioned tables, you can configure the following parameters on the Parameters page of your PolarDB cluster based on your business requirements.
Parameter | Level | Description |
| Global | Specifies the rule for querying hybrid partitioned tables. Valid values:
|
| Global | The switch for the automatic cold data archiving (DLM) feature. Valid values:
Note
|
| Global | Controls whether to allow creating or archiving partitioned tables that contain non-InnoDB engine partitions. Valid values:
Note
|
| Global / Session | Controls whether OSS metadata (meta) management is enabled for OSS tables. The
|
| Global / Session | Controls whether file-level filtering (File Filter) is enabled when querying OSS tables. This feature uses min/max statistics and Bloom filters to skip irrelevant data files and reduce the amount of OSS data scanned. This feature requires the
|
| Global / Session | The switch for automatic pruning of archived OSS partitions by the Data Lifecycle Management (DLM) feature. When DML operations (UPDATE/DELETE) are executed, the system automatically prunes partitions that are being archived to OSS (ORC/CSV) and partitions that have already been archived to OSS. This prevents DML operations from being blocked by archiving and resolves conflicts between DML and DDL. Valid values:
|
| Global / Session | The switch for automatic query pruning. When a SELECT query is executed, the system automatically prunes OSS (ORC/CSV) partitions to prevent slow queries caused by accessing cold data. Valid values:
|
Create a hybrid partition
To create a hybrid partitioned table, you need an OSS server. If you do not have one, use the following syntax to create it:
CREATE SERVER oss_server_name
FOREIGN DATA WRAPPER oss
OPTIONS(EXTRA_SERVER_INFO '{"oss_endpoint": "<my_oss_endpoint>",
"oss_bucket": "<my_oss_bucket>", "oss_access_key_id": "<my_oss_access_key_id>",
"oss_access_key_secret": "<my_oss_access_key_secret>", "oss_prefix":"<my_oss_prefix>", "oss_sts_token": "<my_oss_sts_token>"}');If the cluster version is PolarDB for MySQL 8.0.2 and the revision version is 8.0.2.2.6 or later, the my_oss_sts_token parameter is supported.
The following table describes the parameters.
Parameter | Type | Description |
oss_server_name | string | The name of the OSS server. Note This parameter is global and must be unique. The name is case-insensitive and can be up to 64 characters long. Names longer than 64 characters are truncated. You can specify the OSS server name as a quoted string. |
my_oss_endpoint | string | The endpoint of the OSS region. Note If you access the database from an Alibaba Cloud host, use an internal endpoint to avoid incurring internet traffic. An internal endpoint typically contains the word "internal". |
my_oss_bucket | string | The OSS bucket that contains the data files. This bucket must already exist in OSS. |
my_oss_access_key_id | string | The AccessKey ID for accessing OSS. |
my_oss_access_key_secret | string | The AccessKey Secret for accessing OSS. |
my_oss_prefix | string | The path prefix for data files in OSS. This value cannot be empty or contain special characters. |
my_oss_sts_token | string | OSS temporary access credentials. For details on obtaining OSS temporary access credentials, see Obtain temporary access credentials. Note The |
The following example shows how to create a hybrid partitioned table:
CREATE TABLE t2(a1 INT, a2 VARCHAR(30), a3 VARCHAR(256))
CONNECTION = "oss_server_name"
PARTITION BY RANGE(a1)
(
PARTITION p1 values less than (1000) ENGINE = CSV,
PARTITION p2 values less than (2000) ENGINE = CSV,
PARTITION p3 values less than (3000) ENGINE = INNODB
);Query a hybrid partition
You can query partitions on different storage engines in three ways:
Set the
hybrid_partition_query_mix_engine_enabledparameter to ON. Queries then return data from InnoDB, X-Engine, and OSS partitions. Example:-- t1 is a hybrid partitioned table. SELECT * FROM t1;Set the
hybrid_partition_query_mix_engine_enabledparameter to OFF. Queries then return data only from InnoDB and X-Engine partitions. Example:-- t1 is a hybrid partitioned table. SELECT * FROM t1;Query a specific partition by name. This retrieves data from the specified partition, regardless of its storage engine. Example:
-- t1 is a hybrid partitioned table, and p1 is the name of the partition to query. SELECT * FROM t1 partition (p1);