2009-09-23 23:32:31 +02:00
|
|
|
#ifndef PARTITION_INFO_INCLUDED
|
|
|
|
#define PARTITION_INFO_INCLUDED
|
|
|
|
|
2014-01-06 06:22:35 +01:00
|
|
|
/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
|
2006-02-16 17:38:33 +01:00
|
|
|
|
|
|
|
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
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-02-16 17:38:33 +01:00
|
|
|
|
|
|
|
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
|
2006-12-31 02:29:11 +01:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2006-02-28 22:07:14 +01:00
|
|
|
|
2006-02-16 17:38:33 +01:00
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "partition_element.h"
|
|
|
|
|
|
|
|
class partition_info;
|
|
|
|
|
|
|
|
/* Some function typedefs */
|
|
|
|
typedef int (*get_part_id_func)(partition_info *part_info,
|
|
|
|
uint32 *part_id,
|
|
|
|
longlong *func_value);
|
2008-10-06 14:22:38 +02:00
|
|
|
typedef int (*get_subpart_id_func)(partition_info *part_info,
|
|
|
|
uint32 *part_id);
|
|
|
|
|
2006-03-25 00:19:13 +01:00
|
|
|
struct st_ddl_log_memory_entry;
|
2006-02-16 17:38:33 +01:00
|
|
|
|
|
|
|
class partition_info : public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* Here comes a set of definitions needed for partitioned table handlers.
|
|
|
|
*/
|
|
|
|
List<partition_element> partitions;
|
|
|
|
List<partition_element> temp_partitions;
|
|
|
|
|
|
|
|
List<char> part_field_list;
|
|
|
|
List<char> subpart_field_list;
|
|
|
|
|
|
|
|
/*
|
|
|
|
If there is no subpartitioning, use only this func to get partition ids.
|
|
|
|
If there is subpartitioning, use the this func to get partition id when
|
|
|
|
you have both partition and subpartition fields.
|
|
|
|
*/
|
|
|
|
get_part_id_func get_partition_id;
|
|
|
|
|
|
|
|
/* Get partition id when we don't have subpartition fields */
|
|
|
|
get_part_id_func get_part_partition_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get subpartition id when we have don't have partition fields by we do
|
|
|
|
have subpartition ids.
|
|
|
|
Mikael said that for given constant tuple
|
|
|
|
{subpart_field1, ..., subpart_fieldN} the subpartition id will be the
|
|
|
|
same in all subpartitions
|
|
|
|
*/
|
|
|
|
get_subpart_id_func get_subpartition_id;
|
2006-08-02 12:40:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
When we have various string fields we might need some preparation
|
|
|
|
before and clean-up after calling the get_part_id_func's. We need
|
2009-09-15 17:07:52 +02:00
|
|
|
one such method for get_part_partition_id and one for
|
|
|
|
get_subpartition_id.
|
2006-08-02 12:40:25 +02:00
|
|
|
*/
|
|
|
|
get_part_id_func get_part_partition_id_charset;
|
|
|
|
get_subpart_id_func get_subpartition_id_charset;
|
|
|
|
|
2006-02-16 17:38:33 +01:00
|
|
|
/* NULL-terminated array of fields used in partitioned expression */
|
|
|
|
Field **part_field_array;
|
|
|
|
Field **subpart_field_array;
|
2006-09-26 22:30:39 +02:00
|
|
|
Field **part_charset_field_array;
|
|
|
|
Field **subpart_charset_field_array;
|
2006-02-16 17:38:33 +01:00
|
|
|
/*
|
|
|
|
Array of all fields used in partition and subpartition expression,
|
|
|
|
without duplicates, NULL-terminated.
|
|
|
|
*/
|
|
|
|
Field **full_part_field_array;
|
2007-07-04 21:55:26 +02:00
|
|
|
/*
|
|
|
|
Set of all fields used in partition and subpartition expression.
|
|
|
|
Required for testing of partition fields in write_set when
|
|
|
|
updating. We need to set all bits in read_set because the row may
|
|
|
|
need to be inserted in a different [sub]partition.
|
|
|
|
*/
|
|
|
|
MY_BITMAP full_part_field_set;
|
2006-02-16 17:38:33 +01:00
|
|
|
|
2006-08-02 12:40:25 +02:00
|
|
|
/*
|
|
|
|
When we have a field that requires transformation before calling the
|
|
|
|
partition functions we must allocate field buffers for the field of
|
|
|
|
the fields in the partition function.
|
|
|
|
*/
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
uchar **part_field_buffers;
|
|
|
|
uchar **subpart_field_buffers;
|
|
|
|
uchar **restore_part_field_ptrs;
|
|
|
|
uchar **restore_subpart_field_ptrs;
|
2006-08-02 12:40:25 +02:00
|
|
|
|
2006-02-16 17:38:33 +01:00
|
|
|
Item *part_expr;
|
|
|
|
Item *subpart_expr;
|
|
|
|
|
|
|
|
Item *item_free_list;
|
2006-03-22 06:17:22 +01:00
|
|
|
|
2006-03-25 00:19:13 +01:00
|
|
|
struct st_ddl_log_memory_entry *first_log_entry;
|
|
|
|
struct st_ddl_log_memory_entry *exec_log_entry;
|
|
|
|
struct st_ddl_log_memory_entry *frm_log_entry;
|
2006-03-22 06:17:22 +01:00
|
|
|
|
2006-02-16 17:38:33 +01:00
|
|
|
/*
|
|
|
|
A bitmap of partitions used by the current query.
|
|
|
|
Usage pattern:
|
|
|
|
* The handler->extra(HA_EXTRA_RESET) call at query start/end sets all
|
|
|
|
partitions to be unused.
|
|
|
|
* Before index/rnd_init(), partition pruning code sets the bits for used
|
|
|
|
partitions.
|
|
|
|
*/
|
|
|
|
MY_BITMAP used_partitions;
|
|
|
|
|
|
|
|
union {
|
|
|
|
longlong *range_int_array;
|
|
|
|
LIST_PART_ENTRY *list_array;
|
2009-09-15 17:07:52 +02:00
|
|
|
part_column_list_val *range_col_array;
|
|
|
|
part_column_list_val *list_col_array;
|
2006-02-16 17:38:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* INTERVAL ANALYSIS
|
|
|
|
********************************************/
|
|
|
|
/*
|
|
|
|
Partitioning interval analysis function for partitioning, or NULL if
|
|
|
|
interval analysis is not supported for this kind of partitioning.
|
|
|
|
*/
|
|
|
|
get_partitions_in_range_iter get_part_iter_for_interval;
|
|
|
|
/*
|
|
|
|
Partitioning interval analysis function for subpartitioning, or NULL if
|
|
|
|
interval analysis is not supported for this kind of partitioning.
|
|
|
|
*/
|
|
|
|
get_partitions_in_range_iter get_subpart_iter_for_interval;
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* INTERVAL ANALYSIS ENDS
|
|
|
|
********************************************/
|
2006-10-02 21:52:29 +02:00
|
|
|
|
|
|
|
longlong err_value;
|
2006-02-16 17:38:33 +01:00
|
|
|
char* part_info_string;
|
|
|
|
|
|
|
|
char *part_func_string;
|
|
|
|
char *subpart_func_string;
|
|
|
|
|
|
|
|
partition_element *curr_part_elem;
|
|
|
|
partition_element *current_partition;
|
2009-09-15 17:07:52 +02:00
|
|
|
part_elem_value *curr_list_val;
|
|
|
|
uint curr_list_object;
|
|
|
|
uint num_columns;
|
|
|
|
|
2006-02-16 17:38:33 +01:00
|
|
|
/*
|
|
|
|
These key_map's are used for Partitioning to enable quick decisions
|
|
|
|
on whether we can derive more information about which partition to
|
|
|
|
scan just by looking at what index is used.
|
|
|
|
*/
|
|
|
|
key_map all_fields_in_PF, all_fields_in_PPF, all_fields_in_SPF;
|
|
|
|
key_map some_fields_in_PF;
|
|
|
|
|
|
|
|
handlerton *default_engine_type;
|
|
|
|
partition_type part_type;
|
|
|
|
partition_type subpart_type;
|
|
|
|
|
|
|
|
uint part_info_len;
|
|
|
|
uint part_func_len;
|
|
|
|
uint subpart_func_len;
|
|
|
|
|
2009-10-01 15:04:42 +02:00
|
|
|
uint num_parts;
|
|
|
|
uint num_subparts;
|
2006-02-16 17:38:33 +01:00
|
|
|
uint count_curr_subparts;
|
|
|
|
|
|
|
|
uint part_error_code;
|
|
|
|
|
2009-10-01 15:04:42 +02:00
|
|
|
uint num_list_values;
|
2006-02-16 17:38:33 +01:00
|
|
|
|
2009-10-01 15:04:42 +02:00
|
|
|
uint num_part_fields;
|
|
|
|
uint num_subpart_fields;
|
|
|
|
uint num_full_part_fields;
|
2006-02-16 17:38:33 +01:00
|
|
|
|
2006-04-18 04:51:34 +02:00
|
|
|
uint has_null_part_id;
|
2006-02-16 17:38:33 +01:00
|
|
|
/*
|
|
|
|
This variable is used to calculate the partition id when using
|
|
|
|
LINEAR KEY/HASH. This functionality is kept in the MySQL Server
|
|
|
|
but mainly of use to handlers supporting partitioning.
|
|
|
|
*/
|
|
|
|
uint16 linear_hash_mask;
|
Bug#14521864: MYSQL 5.1 TO 5.5 BUGS PARTITIONING
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;
2013-01-30 17:51:52 +01:00
|
|
|
/*
|
|
|
|
PARTITION BY KEY ALGORITHM=N
|
|
|
|
Which algorithm to use for hashing the fields.
|
|
|
|
N = 1 - Use 5.1 hashing (numeric fields are hashed as binary)
|
|
|
|
N = 2 - Use 5.5 hashing (numeric fields are hashed like latin1 bytes)
|
|
|
|
*/
|
|
|
|
enum enum_key_algorithm
|
|
|
|
{
|
|
|
|
KEY_ALGORITHM_NONE= 0,
|
|
|
|
KEY_ALGORITHM_51= 1,
|
|
|
|
KEY_ALGORITHM_55= 2
|
|
|
|
};
|
|
|
|
enum_key_algorithm key_algorithm;
|
2006-02-16 17:38:33 +01:00
|
|
|
|
|
|
|
bool use_default_partitions;
|
2009-10-01 15:04:42 +02:00
|
|
|
bool use_default_num_partitions;
|
2006-02-16 17:38:33 +01:00
|
|
|
bool use_default_subpartitions;
|
2009-10-01 15:04:42 +02:00
|
|
|
bool use_default_num_subpartitions;
|
2006-02-16 17:38:33 +01:00
|
|
|
bool default_partitions_setup;
|
|
|
|
bool defined_max_value;
|
|
|
|
bool list_of_part_fields;
|
|
|
|
bool list_of_subpart_fields;
|
|
|
|
bool linear_hash_ind;
|
|
|
|
bool fixed;
|
2006-05-10 18:53:40 +02:00
|
|
|
bool is_auto_partitioned;
|
2006-02-16 17:38:33 +01:00
|
|
|
bool from_openfrm;
|
2006-03-07 12:25:08 +01:00
|
|
|
bool has_null_value;
|
2009-09-15 17:07:52 +02:00
|
|
|
bool column_list;
|
2006-02-16 17:38:33 +01:00
|
|
|
|
|
|
|
partition_info()
|
|
|
|
: get_partition_id(NULL), get_part_partition_id(NULL),
|
|
|
|
get_subpartition_id(NULL),
|
|
|
|
part_field_array(NULL), subpart_field_array(NULL),
|
2006-09-26 22:30:39 +02:00
|
|
|
part_charset_field_array(NULL),
|
|
|
|
subpart_charset_field_array(NULL),
|
2006-02-16 17:38:33 +01:00
|
|
|
full_part_field_array(NULL),
|
2006-08-02 12:40:25 +02:00
|
|
|
part_field_buffers(NULL), subpart_field_buffers(NULL),
|
|
|
|
restore_part_field_ptrs(NULL), restore_subpart_field_ptrs(NULL),
|
2006-02-16 17:38:33 +01:00
|
|
|
part_expr(NULL), subpart_expr(NULL), item_free_list(NULL),
|
2006-03-22 06:17:22 +01:00
|
|
|
first_log_entry(NULL), exec_log_entry(NULL), frm_log_entry(NULL),
|
2006-10-02 21:52:29 +02:00
|
|
|
list_array(NULL), err_value(0),
|
2006-02-16 17:38:33 +01:00
|
|
|
part_info_string(NULL),
|
|
|
|
part_func_string(NULL), subpart_func_string(NULL),
|
|
|
|
curr_part_elem(NULL), current_partition(NULL),
|
2009-09-15 17:07:52 +02:00
|
|
|
curr_list_object(0), num_columns(0),
|
2006-02-16 17:38:33 +01:00
|
|
|
default_engine_type(NULL),
|
|
|
|
part_type(NOT_A_PARTITION), subpart_type(NOT_A_PARTITION),
|
2010-03-30 22:52:45 +02:00
|
|
|
part_info_len(0),
|
2006-02-16 17:38:33 +01:00
|
|
|
part_func_len(0), subpart_func_len(0),
|
2009-10-01 15:04:42 +02:00
|
|
|
num_parts(0), num_subparts(0),
|
2006-02-16 17:38:33 +01:00
|
|
|
count_curr_subparts(0), part_error_code(0),
|
2009-10-01 15:04:42 +02:00
|
|
|
num_list_values(0), num_part_fields(0), num_subpart_fields(0),
|
|
|
|
num_full_part_fields(0), has_null_part_id(0), linear_hash_mask(0),
|
Bug#14521864: MYSQL 5.1 TO 5.5 BUGS PARTITIONING
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;
2013-01-30 17:51:52 +01:00
|
|
|
key_algorithm(KEY_ALGORITHM_NONE),
|
2009-10-01 15:04:42 +02:00
|
|
|
use_default_partitions(TRUE), use_default_num_partitions(TRUE),
|
|
|
|
use_default_subpartitions(TRUE), use_default_num_subpartitions(TRUE),
|
2006-04-18 04:51:34 +02:00
|
|
|
default_partitions_setup(FALSE), defined_max_value(FALSE),
|
2006-02-16 17:38:33 +01:00
|
|
|
list_of_part_fields(FALSE), list_of_subpart_fields(FALSE),
|
2006-06-14 15:12:07 +02:00
|
|
|
linear_hash_ind(FALSE), fixed(FALSE),
|
|
|
|
is_auto_partitioned(FALSE), from_openfrm(FALSE),
|
2009-09-15 17:07:52 +02:00
|
|
|
has_null_value(FALSE), column_list(FALSE)
|
2006-02-16 17:38:33 +01:00
|
|
|
{
|
|
|
|
all_fields_in_PF.clear_all();
|
|
|
|
all_fields_in_PPF.clear_all();
|
|
|
|
all_fields_in_SPF.clear_all();
|
|
|
|
some_fields_in_PF.clear_all();
|
|
|
|
partitions.empty();
|
|
|
|
temp_partitions.empty();
|
|
|
|
part_field_list.empty();
|
|
|
|
subpart_field_list.empty();
|
|
|
|
}
|
|
|
|
~partition_info() {}
|
2006-02-28 22:07:14 +01:00
|
|
|
|
2006-03-18 15:48:21 +01:00
|
|
|
partition_info *get_clone();
|
2006-02-28 22:07:14 +01:00
|
|
|
/* Answers the question if subpartitioning is used for a certain table */
|
|
|
|
bool is_sub_partitioned()
|
|
|
|
{
|
|
|
|
return (subpart_type == NOT_A_PARTITION ? FALSE : TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the total number of partitions on the leaf level */
|
|
|
|
uint get_tot_partitions()
|
|
|
|
{
|
2009-10-01 15:04:42 +02:00
|
|
|
return num_parts * (is_sub_partitioned() ? num_subparts : 1);
|
2006-02-28 22:07:14 +01:00
|
|
|
}
|
|
|
|
|
2006-06-27 22:19:27 +02:00
|
|
|
bool set_up_defaults_for_partitioning(handler *file, HA_CREATE_INFO *info,
|
2006-02-16 17:38:33 +01:00
|
|
|
uint start_no);
|
2009-10-06 17:01:59 +02:00
|
|
|
char *has_unique_fields();
|
2006-02-16 17:38:33 +01:00
|
|
|
char *has_unique_names();
|
2008-01-09 13:15:50 +01:00
|
|
|
bool check_engine_mix(handlerton *engine_type, bool default_engine);
|
2009-09-15 17:07:52 +02:00
|
|
|
bool check_range_constants(THD *thd);
|
|
|
|
bool check_list_constants(THD *thd);
|
2006-04-18 04:51:34 +02:00
|
|
|
bool check_partition_info(THD *thd, handlerton **eng_type,
|
2006-07-12 17:33:22 +02:00
|
|
|
handler *file, HA_CREATE_INFO *info,
|
2006-06-23 07:21:26 +02:00
|
|
|
bool check_partition_function);
|
2006-06-15 01:40:06 +02:00
|
|
|
void print_no_partition_found(TABLE *table);
|
2009-10-16 16:16:06 +02:00
|
|
|
void print_debug(const char *str, uint*);
|
2009-10-22 16:15:06 +02:00
|
|
|
Item* get_column_item(Item *item, Field *field);
|
2010-08-30 17:33:55 +02:00
|
|
|
int fix_partition_values(THD *thd,
|
|
|
|
part_elem_value *val,
|
|
|
|
partition_element *part_elem,
|
|
|
|
uint part_id);
|
2009-10-16 16:16:06 +02:00
|
|
|
bool fix_column_value_functions(THD *thd,
|
|
|
|
part_elem_value *val,
|
|
|
|
uint part_id);
|
|
|
|
int fix_parser_data(THD *thd);
|
|
|
|
int add_max_value();
|
2009-10-21 12:40:21 +02:00
|
|
|
void init_col_val(part_column_list_val *col_val, Item *item);
|
2009-10-16 16:16:06 +02:00
|
|
|
int reorganize_into_single_field_col_val();
|
2009-09-15 17:07:52 +02:00
|
|
|
part_column_list_val *add_column_value();
|
|
|
|
bool set_part_expr(char *start_token, Item *item_ptr,
|
|
|
|
char *end_token, bool is_subpart);
|
|
|
|
static int compare_column_values(const void *a, const void *b);
|
2006-09-26 22:30:39 +02:00
|
|
|
bool set_up_charset_field_preps();
|
2009-10-28 01:11:17 +01:00
|
|
|
bool check_partition_field_length();
|
2009-10-16 16:16:06 +02:00
|
|
|
bool init_column_part();
|
2009-10-21 12:40:21 +02:00
|
|
|
bool add_column_list_value(THD *thd, Item *item);
|
2009-12-17 18:39:10 +01:00
|
|
|
void set_show_version_string(String *packet);
|
2010-08-30 17:33:55 +02:00
|
|
|
void report_part_expr_error(bool use_subpart_expr);
|
Bug#14521864: MYSQL 5.1 TO 5.5 BUGS PARTITIONING
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;
2013-01-30 17:51:52 +01:00
|
|
|
bool has_same_partitioning(partition_info *new_part_info);
|
2006-02-16 17:38:33 +01:00
|
|
|
private:
|
2006-03-31 19:39:44 +02:00
|
|
|
static int list_part_cmp(const void* a, const void* b);
|
2006-06-27 22:19:27 +02:00
|
|
|
bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info,
|
2006-02-16 17:38:33 +01:00
|
|
|
uint start_no);
|
2006-06-27 22:19:27 +02:00
|
|
|
bool set_up_default_subpartitions(handler *file, HA_CREATE_INFO *info);
|
2009-10-01 15:04:42 +02:00
|
|
|
char *create_default_partition_names(uint part_no, uint num_parts,
|
2006-04-12 05:35:48 +02:00
|
|
|
uint start_no);
|
2006-04-21 14:37:09 +02:00
|
|
|
char *create_subpartition_name(uint subpart_no, const char *part_name);
|
2006-02-28 22:07:14 +01:00
|
|
|
bool has_unique_name(partition_element *element);
|
2006-02-16 17:38:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32 get_next_partition_id_range(struct st_partition_iter* part_iter);
|
2008-02-28 13:46:52 +01:00
|
|
|
bool check_partition_dirs(partition_info *part_info);
|
2006-02-16 17:38:33 +01:00
|
|
|
|
|
|
|
/* Initialize the iterator to return a single partition with given part_id */
|
|
|
|
|
|
|
|
static inline void init_single_partition_iterator(uint32 part_id,
|
|
|
|
PARTITION_ITERATOR *part_iter)
|
|
|
|
{
|
2006-04-06 19:23:33 +02:00
|
|
|
part_iter->part_nums.start= part_iter->part_nums.cur= part_id;
|
2006-02-16 17:38:33 +01:00
|
|
|
part_iter->part_nums.end= part_id+1;
|
2009-08-26 12:59:49 +02:00
|
|
|
part_iter->ret_null_part= part_iter->ret_null_part_orig= FALSE;
|
2006-02-16 17:38:33 +01:00
|
|
|
part_iter->get_next= get_next_partition_id_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the iterator to enumerate all partitions */
|
|
|
|
static inline
|
|
|
|
void init_all_partitions_iterator(partition_info *part_info,
|
|
|
|
PARTITION_ITERATOR *part_iter)
|
|
|
|
{
|
2006-04-06 19:23:33 +02:00
|
|
|
part_iter->part_nums.start= part_iter->part_nums.cur= 0;
|
2009-10-01 15:04:42 +02:00
|
|
|
part_iter->part_nums.end= part_info->num_parts;
|
2009-09-02 17:42:08 +02:00
|
|
|
part_iter->ret_null_part= part_iter->ret_null_part_orig= FALSE;
|
2006-02-16 17:38:33 +01:00
|
|
|
part_iter->get_next= get_next_partition_id_range;
|
|
|
|
}
|
2009-09-23 23:32:31 +02:00
|
|
|
|
|
|
|
#endif /* PARTITION_INFO_INCLUDED */
|