mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
d92a7cb76a
Due to an internal change in the server code in between 5.1 and 5.5 (wl#2649) the hash function used in KEY partitioning changed for numeric and date/time columns (from binary hash calculation to character based hash calculation). Also enum/set changed from latin1 ci based hash calculation to binary hash between 5.1 and 5.5. (bug#11759782). These changes makes KEY [sub]partitioned tables on any of the affected column types incompatible with 5.5 and above, since the calculation of partition id differs. Also since InnoDB asserts that a deleted row was previously read (positioned), the server asserts on delete of a row that is in the wrong partition. The solution for this situation is: 1) The partitioning engine will check that delete/update will go to the partition the row was read from and give an error otherwise, consisting of the rows partitioning fields. This will avoid asserts in InnoDB and also alert the user that there is a misplaced row. A detailed error message will be given, including an entry to the error log consisting of both table name, partition and row content (PK if exists, otherwise all partitioning columns). 2) A new optional syntax for KEY () partitioning in 5.5 is allowed: [SUB]PARTITION BY KEY [ALGORITHM = N] (list_of_cols) Where N = 1 uses the same hashing as 5.1 (Numeric/date/time fields uses binary hashing, ENUM/SET uses charset hashing) N = 2 uses the same hashing as 5.5 (Numeric/date/time fields uses charset hashing, ENUM/SET uses binary hashing). If not set on CREATE/ALTER it will default to 2. This new syntax should probably be ignored by NDB. 3) Since there is a demand for avoiding scanning through the full table, during upgrade the ALTER TABLE t PARTITION BY ... command is considered a no-op (only .frm change) if everything except ALGORITHM is the same and ALGORITHM was not set before, which allows manually upgrading such table by something like: ALTER TABLE t PARTITION BY KEY ALGORITHM = 1 () or ALTER TABLE t PARTITION BY KEY ALGORITHM = 2 () 4) Enhanced partitioning with CHECK/REPAIR to also check for/repair misplaced rows. (Also works for ALTER TABLE t CHECK/REPAIR PARTITION) CHECK FOR UPGRADE: If the .frm version is < 5.5.3 and uses KEY [sub]partitioning and an affected column type then it will fail with an message: KEY () partitioning changed, please run: ALTER TABLE `test`.`t1` PARTITION BY KEY ALGORITHM = 1 (a) PARTITIONS 12 (i.e. current partitioning clause, with the addition of ALGORITHM = 1) CHECK without FOR UPGRADE: if MEDIUM (default) or EXTENDED options are given: Scan all rows and verify that it is in the correct partition. Fail for the first misplaced row. REPAIR: if default or EXTENDED (i.e. not QUICK/USE_FRM): Scan all rows and every misplaced row is moved into its correct partitions. 5) Updated mysqlcheck (called by mysql_upgrade) to handle the new output from CHECK FOR UPGRADE, to run the ALTER statement instead of running REPAIR. This will allow mysql_upgrade (or CHECK TABLE t FOR UPGRADE) to upgrade a KEY [sub]partitioned table that has any affected field type and a .frm version < 5.5.3 to ALGORITHM = 1 without rebuild. Also notice that if the .frm has a version of >= 5.5.3 and ALGORITHM is not set, it is not possible to know if it consists of rows from 5.1 or 5.5! In these cases I suggest that the user does: (optional) LOCK TABLE t WRITE; SHOW CREATE TABLE t; (verify that it has no ALGORITHM = N, and to be safe, I would suggest backing up the .frm file, to be used if one need to change to another ALGORITHM = N, without needing to rebuild/repair) ALTER TABLE t <old partitioning clause, but with ALGORITHM = N>; which should set the ALGORITHM to N (if the table has rows from 5.1 I would suggest N = 1, otherwise N = 2) CHECK TABLE t; (here one could use the backed up .frm instead and change to a new N and run CHECK again and see if it passes) and if there are misplaced rows: REPAIR TABLE t; (optional) UNLOCK TABLES;
134 lines
3.2 KiB
C++
134 lines
3.2 KiB
C++
/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
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-1301 USA */
|
|
|
|
#ifndef SQL_TABLE_MAINTENANCE_H
|
|
#define SQL_TABLE_MAINTENANCE_H
|
|
|
|
/* Must be able to hold ALTER TABLE t PARTITION BY ... KEY ALGORITHM = 1 ... */
|
|
#define SQL_ADMIN_MSG_TEXT_SIZE 128 * 1024
|
|
|
|
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
|
|
LEX_STRING *key_cache_name);
|
|
bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
|
|
int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
|
|
KEY_CACHE *dst_cache);
|
|
|
|
/**
|
|
Analyze_statement represents the ANALYZE TABLE statement.
|
|
*/
|
|
class Analyze_table_statement : public Sql_statement
|
|
{
|
|
public:
|
|
/**
|
|
Constructor, used to represent a ANALYZE TABLE statement.
|
|
@param lex the LEX structure for this statement.
|
|
*/
|
|
Analyze_table_statement(LEX *lex)
|
|
: Sql_statement(lex)
|
|
{}
|
|
|
|
~Analyze_table_statement()
|
|
{}
|
|
|
|
/**
|
|
Execute a ANALYZE TABLE statement at runtime.
|
|
@param thd the current thread.
|
|
@return false on success.
|
|
*/
|
|
bool execute(THD *thd);
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
Check_table_statement represents the CHECK TABLE statement.
|
|
*/
|
|
class Check_table_statement : public Sql_statement
|
|
{
|
|
public:
|
|
/**
|
|
Constructor, used to represent a CHECK TABLE statement.
|
|
@param lex the LEX structure for this statement.
|
|
*/
|
|
Check_table_statement(LEX *lex)
|
|
: Sql_statement(lex)
|
|
{}
|
|
|
|
~Check_table_statement()
|
|
{}
|
|
|
|
/**
|
|
Execute a CHECK TABLE statement at runtime.
|
|
@param thd the current thread.
|
|
@return false on success.
|
|
*/
|
|
bool execute(THD *thd);
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
Optimize_table_statement represents the OPTIMIZE TABLE statement.
|
|
*/
|
|
class Optimize_table_statement : public Sql_statement
|
|
{
|
|
public:
|
|
/**
|
|
Constructor, used to represent a OPTIMIZE TABLE statement.
|
|
@param lex the LEX structure for this statement.
|
|
*/
|
|
Optimize_table_statement(LEX *lex)
|
|
: Sql_statement(lex)
|
|
{}
|
|
|
|
~Optimize_table_statement()
|
|
{}
|
|
|
|
/**
|
|
Execute a OPTIMIZE TABLE statement at runtime.
|
|
@param thd the current thread.
|
|
@return false on success.
|
|
*/
|
|
bool execute(THD *thd);
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
Repair_table_statement represents the REPAIR TABLE statement.
|
|
*/
|
|
class Repair_table_statement : public Sql_statement
|
|
{
|
|
public:
|
|
/**
|
|
Constructor, used to represent a REPAIR TABLE statement.
|
|
@param lex the LEX structure for this statement.
|
|
*/
|
|
Repair_table_statement(LEX *lex)
|
|
: Sql_statement(lex)
|
|
{}
|
|
|
|
~Repair_table_statement()
|
|
{}
|
|
|
|
/**
|
|
Execute a REPAIR TABLE statement at runtime.
|
|
@param thd the current thread.
|
|
@return false on success.
|
|
*/
|
|
bool execute(THD *thd);
|
|
};
|
|
|
|
#endif
|