Showing content from https://mariadb.com/docs/server/server-usage/partitioning-tables/partition-maintenance below:
Partition Maintenance | MariaDB Documentation
Partition Maintenance | MariaDB Documentation
- MariaDB Server Documentation
- Quickstart Guides
- Server Usage
- Server Management
- Security
- Architecture
- Clients & Utilities
- HA & Performance
- Reference
- SQL Structure
- SQL Statements
- SQL Functions
- Data Types
- Plugins
- System Tables
- Error Codes
- MariaDB Error Code Reference
- Operating System Error Codes
- MariaDB Error Codes 1000 to 1099
- MariaDB Error Codes 1100 to 1199
- MariaDB Error Codes 1200 to 1299
- MariaDB Error Codes 1300 to 1399
- MariaDB Error Codes 1400 to 1499
- Error 1400: XAER_OUTSIDE: Some work is done outside global transaction
- Error 1401: XAER_RMERR: Fatal error occurred in the transaction branch - check your data for consist
- Error 1402: XA_RBROLLBACK: Transaction branch was rolled back
- Error 1403: There is no such grant defined for user on host on routine
- Error 1404: Failed to grant EXECUTE and ALTER ROUTINE privileges
- Error 1405: Failed to revoke all privileges to dropped routine
- Error 1406: Data too long for column at row
- Error 1407: Bad SQLSTATE
- Error 1408: ready for connections. Version: socket: port:
- Error 1409: Can't load value from file with fixed size rows to variable
- Error 1410: You are not allowed to create a user with GRANT
- Error 1411: Incorrect value for function
- Error 1412: Table definition has changed, please retry transaction
- Error 1413: Duplicate handler declared in the same block
- Error 1414: OUT or INOUT argument for routine is not a variable or NEW pseudo-variable in BEFORE tri
- Error 1415: Not allowed to return a result set from
- Error 1416: Cannot get geometry object from data you send to the GEOMETRY field
- Error 1417: A routine failed and has neither NO SQL nor READS SQL DATA in its declaration
- Error 1418: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration an
- Error 1419: You do not have the SUPER privilege and binary logging is enabled
- Error 1420: You can't execute a prepared statement which has an open cursor associated with it
- Error 1421: The statement has no open cursor
- Error 1422: Explicit or implicit commit is not allowed in stored function or trigger
- Error 1423: Field of view underlying table doesn't have a default value
- Error 1424: Recursive stored functions and triggers are not allowed.
- Error 1425: Too big scale specified for column
- Error 1426: Too big precision specified for column
- Error 1427: For float(M,D, double(M,D or decimal(M,D, M must be >= D
- Error 1428: You can't combine write-locking of system tables with other tables or lock types
- Error 1429: Unable to connect to foreign data source
- Error 1430: There was a problem processing the query on the foreign data source
- Error 1431: The foreign data source you are trying to reference does not exist
- Error 1432: Can't create federated table. The data source connection string is not in the correct fo
- Error 1433: The data source connection string is not in the correct format
- Error 1434: Can't create federated table. Foreign data src error
- Error 1435: Trigger in wrong schema
- Error 1436: Thread stack overrun
- Error 1437: Routine body is too long
- Error 1438: Cannot drop default keycache
- Error 1439: Display width out of range for column
- Error 1440: XAER_DUPID: The XID already exists
- Error 1441: Datetime function: field overflow
- Error 1442: Can't update table in stored function/trigger because it is already used by statement wh
- Error 1443: The definition of table prevents operation on table
- Error 1444: The prepared statement contains a stored routine call that refers to that same statement
- Error 1445: Not allowed to set autocommit from a stored function or trigger
- Error 1446: Definer is not fully qualified
- Error 1447: View has no definer information (old table format)
- Error 1448: You need the SUPER privilege for creation view with definer
- Error 1449: The user specified as a definer does not exist
- Error 1450: Changing schema from is not allowed.
- Error 1451: Cannot delete or update a parent row: a foreign key constraint fails
- Error 1452: Cannot add or update a child row: a foreign key constraint fails
- Error 1453: Variable must be quoted with ..., or renamed
- Error 1454: No definer attribute for trigger
- Error 1455: has an old format, you should re-create the object(s)
- Error 1456: Recursive limit (as set by the max_sp_recursion_depth variable) was exceeded for routine
- Error 1457: Failed to load routine
- Error 1458: Incorrect routine name
- Error 1459: Table upgrade required. Please do "REPAIR TABLE" or dump/reload to fix it!
- Error 1460: AGGREGATE is not supported for stored functions
- Error 1461: Can't create more than max_prepared_stmt_count statements
- Error 1462: contains view recursion
- Error 1463: Non-grouping field is used in clause
- Error 1464: The used table type doesn't support SPATIAL indexes
- Error 1465: Triggers can not be created on system tables
- Error 1466: Leading spaces are removed from name
- Error 1467: Failed to read auto-increment value from storage engine
- Error 1468: user name
- Error 1469: host name
- Error 1470: String is too long for (should be no longer than )
- Error 1471: The target table of the is not insertable-into
- Error 1472: Table is differently defined or of non-MyISAM type or doesn't exist
- Error 1473: Too high level of nesting for select
- Error 1474: Name has become ''
- Error 1475: First character of the FIELDS TERMINATED string is ambiguous
- Error 1476: The foreign server you are trying to create already exists
- Error 1477: The foreign server name you are trying to reference does not exist. Data source error
- Error 1478: Table storage engine does not support the create option
- Error 1479: Syntax error: PARTITIONING requires definition of VALUES for each partition
- Error 1480: Only PARTITIONING can use VALUES in partition definition
- Error 1481: MAXVALUE can only be used in last partition definition
- Error 1482: Subpartitions can only be hash partitions and by key
- Error 1483: Must define subpartitions on all partitions if on one partition
- Error 1484: Wrong number of partitions defined, mismatch with previous setting
- Error 1485: Wrong number of subpartitions defined, mismatch with previous setting
- Error 1486: Constant/Random expression in (sub)partitioning function is not allowed
- Error 1487: Expression in RANGE/LIST VALUES must be constant
- Error 1488: Field in list of fields for partition function not found in table
- Error 1489: List of fields is only allowed in KEY partitions
- Error 1490: The partition info in the frm file is not consistent with what can be written into the f
- Error 1491: The function returns the wrong type
- Error 1492: For partitions each partition must be defined
- Error 1493: VALUES LESS THAN value must be strictly increasing for each partition
- Error 1494: VALUES value must be of same type as partition function
- Error 1495: Multiple definition of same constant in list partitioning
- Error 1496: Partitioning can not be used stand-alone in query
- Error 1497: The mix of handlers in the partitions is not allowed in this version of MariaDB
- Error 1498: For the partitioned engine it is necessary to define all
- Error 1499: Too many partitions (including subpartitions) were defined
- MariaDB Error Codes 1500 to 1599
- MariaDB Error Codes 1600 to 1699
- MariaDB Error Codes 1700 to 1799
- MariaDB Error Codes 1800 to 1899
- MariaDB Error Codes 1900 to 1999
- MariaDB Error Codes 3000 to 3099
- MariaDB Error Codes 4000 to 4099
- MariaDB Error Codes 4100 to 4199
- Error 4100: Field reference can't be used in table value constructor
- Error 4101: Numeric datatype is required for function
- Error 4102: Argument to the function is not a constant for a partition
- Error 4103: Argument to the function does not belong to the range [0,1]
- Error 4104: function only accepts arguments that can be converted to numerical types
- Error 4105: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context
- Error 4106: Aggregate specific instruction(FETCH GROUP NEXT ROW) missing from the aggregate function
- Error 4107: Limit only accepts integer values
- Error 4108: Invisible column must have a default value
- Error 4109: Rows matched: Changed: Inserted: Warnings:
- Error 4110: must be of type for system-versioned table
- Error 4111: Transaction-precise system versioning for is not supported
- Error 4112: You should never see it
- Error 4113: Wrong partitioning type, expected type
- Error 4114: Versioned table last HISTORY partition is out of, need more HISTORY partitions
- Error 4115: Maybe missing parameters
- Error 4116: Can only drop oldest partitions when rotating by INTERVAL
- Error 4117: You should never see it
- Error 4118: Partition contains non-historical data
- Error 4119: Not allowed for system-versioned. Change @@system_versioning_alter_history to proceed wi
- Error 4120: Not allowed for system-versioned. Change to/from native system versioning engine is not
- Error 4121: SYSTEM_TIME range selector is not allowed
- Error 4122: Conflicting FOR SYSTEM_TIME clauses in WITH RECURSIVE
- Error 4123: Table must have at least one versioned column
- Error 4124: Table is not system-versioned
- Error 4125: Wrong parameters for: missing
- Error 4126: PERIOD FOR SYSTEM_TIME must use columns
- Error 4127: Wrong parameters for partitioned: wrong value for
- Error 4128: Wrong partitions for: must have at least one HISTORY and exactly one last CURRENT
- Error 4129: TRX_ID not found in mysql.transaction_registry
- Error 4130: Can not change system versioning field
- Error 4131: Can not DROP SYSTEM VERSIONING for table partitioned BY SYSTEM_TIME
- Error 4132: System-versioned tables in the database are not supported
- Error 4133: Transaction registry is disabled
- Error 4134: Duplicate ROW column
- Error 4135: Table is already system-versioned
- Error 4136: You should never see it
- Error 4137: System-versioned tables do not support
- Error 4138: Transaction-precise system-versioned tables do not support partitioning by ROW START or
- Error 4139: The index file for table is full
- Error 4140: The column cannot be changed more than once in a single UPDATE statement
- Error 4141: Row with no elements is not allowed in table value constructor in this context
- Error 4142: SYSTEM_TIME partitions in table does not support historical query
- Error 4143: index does not support this operation
- Error 4144: Changing table options requires the table to be rebuilt
- Error 4145: Can't execute the command as you have a BACKUP STAGE active
- Error 4146: You must start backup with "BACKUP STAGE START"
- Error 4147: Backup stage is same or before current backup stage
- Error 4148: Backup stage failed
- Error 4149: Unknown backup stage: Stage should be one of START, FLUSH, BLOCK_DDL, BLOCK_COMMIT or EN
- Error 4150: User is blocked because of too many credential errors; unblock with 'FLUSH PRIVILEGES'
- Error 4151: Access denied, this account is locked
- Error 4152: Application-time period table cannot be temporary
- Error 4153: Fields of PERIOD FOR have different types
- Error 4154: Cannot specify more than one application-time period
- Error 4155: Period field cannot be
- Error 4156: Period is not found in table
- Error 4157: Column used in period specified in update SET list
- Error 4158: Can't DROP CONSTRAINT. Use DROP PERIOD for this
- Error 4159: Specified key part was too long; max key part length is
- Error 4160: Comment for database is too long
- Error 4161: Unknown data type
- Error 4162: Operator does not exists
- Error 4163: Table history row start is later than row end
- Error 4164: STARTS is later than query time, first history partition may exceed INTERVAL value
- Error 4165: DDL-statement is forbidden as table storage engine does not support Galera replication
- Error 4166: The used command is not allowed because the MariaDB server or client has disabled the lo
- Error 4167: No secure transports are configured, unable to set --require_secure_transport=ON
- Error 4168: Slave SQL thread ignored the '%s' because table is shared
- Error 4169: AUTO_INCREMENT column cannot be used in the UNIQUE index
- Error 4170: Key cannot explicitly include column
- Error 4171: Key cannot have WITHOUT OVERLAPS
- Error 4172: is not allowed in this context
- Error 4173: Engine does not support rollback. Changes where commited during rollback call
- Error 4174: A primary key cannot be marked as IGNORE
- Error 4175: SKIP LOCKED makes this statement unsafe
- Error 4176: Field can't be set for JSON_TABLE
- Error 4177: Every table function must have an alias
- Error 4178: Can't store an array or an object in the scalar column of JSON_TABLE
- Error 4179: Can't store multiple matches of the path in the column of JSON_TABLE
- Error 4180: FETCH ... WITH TIES requires ORDER BY clause to be present
- Error 4181: Dropped orphan trigger, originally created for table
- Error 4182: Storage engine is disabled
- Error 4183: SFORMAT error
- Error 4184: Convert partition is not supported for subpartitioned table
- Error 4185: MariaDB tried to use the %s, but its provider plugin is not loaded
- Error 4186: Failed to parse histogram for table at offset
- Error 4187: OUT or INOUT argument for function is not allowed here
- Error 4188: Replicated query table can not be temporary
- Error 4189: Versioned table: adding HISTORY partition(s) failed
- Error 4190: is implicitly changing the value of from to
- Error 4191: CHANGE MASTER TO option is missing requirement
- Error 4192: Slave log event execution was interrupted (slave_max_statement_time exceeded)
- Error 4193: Invalid value for keyword
- Error 4194: keyword is not supported
- Error 4195: Variable schema is not supported
- Error 4196: Pseudo thread id should not be modified by the client as it will be overwritten
- Error 4197: Wrong number of columns
- Error 4198: Sequence tables cannot have any keys
- Error 4199: Sequence tables cannot have any constraints
- MariaDB Error Codes 4200 to 4299
- Client/Server Protocol
- Server Usage
- Partitioning Tables
Partition Maintenance
This article covers
First, my Opinions on PARTITIONing
Taken from Rick's RoTs - Rules of Thumb
-
#1: Don't use PARTITIONing until you know how and why it will help.
-
Don't use PARTITION unless you will have >1M rows
-
No more than 50 PARTITIONs on a table (open, show table status, etc, are impacted) (fixed in MySQL 5.6.6?; a better fix coming eventually in 5.7)
-
PARTITION BY RANGE is the only useful method.
-
SUBPARTITIONs are not useful.
-
The partition field should not be the field first in any key.
-
It is OK to have an AUTO_INCREMENT as the first part of a compound key, or in a non-UNIQUE index.
It is so tempting to believe that PARTITIONing will solve performance problems. But it is so often wrong.
PARTITIONing splits up one table into several smaller tables. But table size is rarely a performance issue. Instead, I/O time and indexes are the issues.
A common fallacy: "Partitioning will make my queries run faster". It won't. Ponder what it takes for a 'point query'. Without partitioning, but with an appropriate index, there is a BTree (the index) to drill down to find the desired row. For a billion rows, this might be 5 levels deep. With partitioning, first the partition is chosen and "opened", then a smaller BTree (of say 4 levels) is drilled down. Well, the savings of the shallower BTree is consumed by having to open the partition. Similarly, if you look at the disk blocks that need to be touched, and which of those are likely to be cached, you come to the conclusion that about the same number of disk hits is likely. Since disk hits are the main cost in a query, Partitioning does not gain any performance (at least for this typical case). The 2D case (below) gives the main contradiction to this discussion.
Use Cases for PARTITIONing
Use case #1 -- time series. Perhaps the most common use case where PARTITIONing shines is in a dataset where "old" data is periodically deleted from the table. RANGE PARTITIONing by day (or other unit of time) lets you do a nearly instantaneous DROP PARTITION plus REORGANIZE PARTITION instead of a much slower DELETE. Much of this blog is focused on this use case. This use case is also discussed in Big DELETEs
The big win for Case #1: DROP PARTITION is a lot faster than DELETEing a lot of rows.
Use case #2 -- 2-D index. INDEXes are inherently one-dimensional. If you need two "ranges" in the WHERE clause, try to migrate one of them to PARTITIONing.
Finding the nearest 10 pizza parlors on a map needs a 2D index. Partition pruning sort of gives a second dimension. See Latitude/Longitude Indexing That uses PARTITION BY RANGE(latitude) together with PRIMARY KEY(longitude, ...)
The big win for Case #2: Scanning fewer rows.
Use case #3 -- hot spot. This is a bit complicated to explain. Given this combination:
-
A table's index is too big to be cached, but the index for one partition is cacheable, and
-
The index is randomly accessed, and
-
Data ingestion would normally be I/O bound due to updating the index Partitioning can keep all the index "hot" in RAM, thereby avoiding a lot of I/O.
The big win for Case #3: Improving caching to decrease I/O to speed up operations.
AUTO_INCREMENT in PARTITION
-
For AUTO_INCREMENT to work (in any table), it must be the first field in some index. Period. There are no other requirements on indexing it.
-
Being the first field in some index lets the engine find the 'next' value when opening the table.
-
AUTO_INCREMENT need not be UNIQUE. What you lose: prevention of explicitly inserting a duplicate id. (This is rarely needed, anyway.)
Examples (where id is AUTO_INCREMENT):
-
PRIMARY KEY (...), INDEX(id)
-
PRIMARY KEY (...), UNIQUE(id, partition_key) -- not useful
-
INDEX(id), INDEX(...) (but no UNIQUE keys)
-
PRIMARY KEY(id), ... -- works only if id is the partition key (not very useful)
PARTITION maintenance for the time-series case
Let's focus on the maintenance task involved in Case #1, as described above.
You have a large table that is growing on one end and being pruned on the other. Examples include news, logs, and other transient information. PARTITION BY RANGE is an excellent vehicle for such a table.
-
DROP PARTITION is much faster than DELETE. (This is the big reason for doing this flavor of partitioning.)
-
Queries often limit themselves to 'recent' data, thereby taking advantage of "partition pruning".
Depending on the type of data, and how long before it expires, you might have daily or weekly or hourly (etc) partitions.
There is no simple SQL statement to "drop partitions older than 30 days" or "add a new partition for tomorrow". It would be tedious to do this by hand every day.
High level view of the code
ALTER TABLE tbl
DROP PARTITION from20120314;
ALTER TABLE tbl
REORGANIZE PARTITION future INTO (
PARTITION from20120415 VALUES LESS THAN (TO_DAYS('2012-04-16')),
PARTITION future VALUES LESS THAN MAXVALUE);
After which you have...
CREATE TABLE tbl (
dt DATETIME NOT NULL, -- or DATE
...
PRIMARY KEY (..., dt),
UNIQUE KEY (..., dt),
...
)
PARTITION BY RANGE (TO_DAYS(dt)) (
PARTITION START VALUES LESS THAN (0),
PARTITION from20120315 VALUES LESS THAN (TO_DAYS('2012-03-16')),
PARTITION from20120316 VALUES LESS THAN (TO_DAYS('2012-03-17')),
...
PARTITION from20120414 VALUES LESS THAN (TO_DAYS('2012-04-15')),
PARTITION from20120415 VALUES LESS THAN (TO_DAYS('2012-04-16')),
PARTITION future VALUES LESS THAN MAXVALUE
);
Perhaps you noticed some odd things in the example. Let me explain them.
-
Partition naming: Make them useful.
-
from20120415 ... 04-16: Note that the LESS THAN is the next day's date
-
The "start" partition: See paragraph below.
-
The "future" partition: This is normally empty, but it can catch overflows; more later.
-
The range key (dt) must be included in any PRIMARY or UNIQUE key.
-
The range key (dt) should be last in any keys it is in -- You have already "pruned" with it; it is almost useless in the index, especially at the beginning.
-
DATETIME, etc -- I picked this datatype because it is typical for a time series. Newer MySQL versions allow TIMESTAMP. INT could be used; etc.
-
There is an extra day (03-16 thru 04-16): The latest day is only partially full.
Why the bogus "start" partition? If an invalid datetime (Feb 31) were to be used, the datetime would turn into NULL. NULLs are put into the first partition. Since any SELECT could have an invalid date (yeah, this stretching things), the partition pruner always includes the first partition in the resulting set of partitions to search. So, if the SELECT must scan the first partition, it would be slightly more efficient if that partition were empty. Hence the bogus "start" partition. Longer discussion, by The Data Charmer 5.5 eliminates the bogus check, but only if you switch to a new syntax:
PARTITION BY RANGE COLUMNS(dt) (
PARTITION day_20100226 VALUES LESS THAN ('2010-02-27'), ...
More on the "future" partition. Sooner or later the cron/EVENT to add tomorrow's partition will fail to run. The worst that could happen is for tomorrow's data to be lost. The easiest way to prevent that is to have a partition ready to catch it, even if this partition is normally always empty.
Having the "future" partition makes the ADD PARTITION script a little more complex. Instead, it needs to take tomorrow's data from "future" and put it into a new partition. This is done with the REORGANIZE command shown. Normally nothing need be moved, and the ALTER takes virtually zero time.
-
DROP if the oldest partition is "too old".
-
Add 'tomorrow' near the end of today, but don't try to add it twice.
-
Do not count partitions -- there are two extra ones. Use the partition names or information_schema.PARTITIONS.PARTITION_DESCRIPTION.
-
DROP/Add only once in the script. Rerun the script if you need more.
-
Run the script more often than necessary. For daily partitions, run the script twice a day, or even hourly. Why? Automatic repair.
As I have said many times, in many places, BY RANGE is perhaps the only useful variant. And a time series is the most common use for PARTITIONing.
-
(as discussed here) DATETIME/DATE with TO_DAYS()
-
DATETIME/DATE with TO_DAYS(), but with 7-day intervals
-
TIMESTAMP with TO_DAYS(). (version 5.1.43 or later)
-
PARTITION BY RANGE COLUMNS(DATETIME) (5.5.0)
-
PARTITION BY RANGE(TIMESTAMP) (version 5.5.15 / 5.6.3)
-
PARTITION BY RANGE(TO_SECONDS()) (5.6.0)
-
INT UNSIGNED with constants computed as unix timestamps.
-
INT UNSIGNED with constants for some non-time-based series.
-
MEDIUMINT UNSIGNED containing an "hour id": FLOOR(FROM_UNIXTIME(timestamp) / 3600)
-
Months, Quarters, etc: Concoct a notation that works.
How many partitions?
-
Under, say, 5 partitions -- you get very little of the benefits.
-
Over, say, 50 partitions, and you hit inefficiencies elsewhere.
-
Certain operations (SHOW TABLE STATUS, opening the table, etc) open every partition.
-
MyISAM, before version 5.6.6, would lock all partitions before pruning!
-
Partition pruning does not happen on INSERTs (until Version 5.6.7), so INSERT needs to open all the partitions.
-
Before "native partitions" (5.7.6), each partition consumed a chunk of memory.
Reference implementation, in Perl, with demo of daily partitions
The complexity of the code is in the discovery of the PARTITION names, especially of the oldest and the 'next'.
To run the demo,
-
Install Perl and DBIx::DWIW (from CPAN).
-
copy the txt file (link above) to demo_part_maint.pl
-
execute perl demo_part_maint.pl to get the rest of the instructions
The program will generate and execute (when needed) either of these:
ALTER TABLE tbl REORGANIZE PARTITION
future
INTO (
PARTITION from20150606 VALUES LESS THAN (736121),
PARTITION future VALUES LESS THAN MAXVALUE
)
ALTER TABLE tbl
DROP PARTITION from20150603
Original writing -- Oct, 2012; Use cases added: Oct, 2014; Refreshed: June, 2015; 8.0: Sep, 2016
Slides from Percona Amsterdam 2015
PARTITIONing requires at least MySQL 5.1
The tips in this document apply to MySQL, MariaDB, and Percona.
Future (as envisioned in 2016):
-
MySQL 5.7.6 has "native partitioning for InnoDB".
-
FOREIGN KEY support, perhaps in a later 8.0.xx.
-
"GLOBAL INDEX" -- this would avoid the need for putting the partition key in every unique index, but make DROP PARTITION costly. This is farther into the future.
MySQL 8.0, released Sep, 2016, not yet GA)
-
Only InnoDB tables can be partitioned -- MariaDB is likely to continue maintaining Partitioning on non-InnoDB tables, but Oracle is clearly not.
-
Some of the problems having lots of partitions are lessened by the Data-Dictionary-in-a-table.
Native partitioning will give:
-
This will improve performance slightly by combining two "handlers" into one.
-
Decreased memory usage, especially when using a large number of partitions.
Rick James graciously allowed us to use this article in the documentation.
Rick James' site has other useful tips, how-tos, optimizations, and debugging tips.
Original source: partitionmaint
This page is licensed: CC BY-SA / Gnu FDL
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4