2011-06-30 17:31:31 +02:00
/*
2016-02-19 20:31:10 +01:00
Copyright ( c ) 2001 , 2016 , Oracle and / or its affiliates . All rights reserved .
2001-04-20 00:12:10 +02: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-23 20:17:15 +01:00
the Free Software Foundation ; version 2 of the License .
2001-04-20 00:12:10 +02: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
2011-06-30 17:31:31 +02:00
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*/
2001-04-20 00:12:10 +02:00
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
# define CHECK_VERSION "2.5.1"
2001-04-20 00:12:10 +02:00
2001-09-12 22:53:31 +02:00
# include "client_priv.h"
2001-04-20 00:12:10 +02:00
# include <m_ctype.h>
2002-09-17 22:46:53 +02:00
# include <mysql_version.h>
# include <mysqld_error.h>
# include <sslopt-vars.h>
2010-10-06 17:06:13 +02:00
# include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
2001-04-20 00:12:10 +02:00
/* Exit codes */
# define EX_USAGE 1
# define EX_MYSQLERR 2
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
/* ALTER instead of repair. */
# define MAX_ALTER_STR_SIZE 128 * 1024
# define KEY_PARTITIONING_CHANGED_STR "KEY () partitioning changed"
2001-04-20 00:12:10 +02:00
static MYSQL mysql_connection , * sock = 0 ;
static my_bool opt_alldbs = 0 , opt_check_only_changed = 0 , opt_extended = 0 ,
opt_compress = 0 , opt_databases = 0 , opt_fast = 0 ,
opt_medium_check = 0 , opt_quick = 0 , opt_all_in_1 = 0 ,
2002-04-02 19:29:53 +02:00
opt_silent = 0 , opt_auto_repair = 0 , ignore_errors = 0 ,
2007-08-01 21:59:05 +02:00
tty_password = 0 , opt_frm = 0 , debug_info_flag = 0 , debug_check_flag = 0 ,
2007-03-28 18:19:10 +02:00
opt_fix_table_names = 0 , opt_fix_db_names = 0 , opt_upgrade = 0 ,
opt_write_binlog = 1 ;
2001-04-20 00:12:10 +02:00
static uint verbose = 0 , opt_mysql_port = 0 ;
2015-10-14 08:30:39 +02:00
static uint opt_enable_cleartext_plugin = 0 ;
static my_bool using_opt_enable_cleartext_plugin = 0 ;
2007-08-01 21:59:05 +02:00
static int my_end_arg ;
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
static char * opt_mysql_unix_port = 0 ;
2003-03-16 08:20:45 +01:00
static char * opt_password = 0 , * current_user = 0 ,
2009-01-14 15:50:51 +01:00
* default_charset = 0 , * current_host = 0 ;
2011-01-16 04:59:05 +01:00
static char * opt_plugin_dir = 0 , * opt_default_auth = 0 ;
2001-04-20 00:12:10 +02:00
static int first_error = 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
DYNAMIC_ARRAY tables4repair , tables4rebuild , alter_table_cmds ;
2002-11-14 20:16:30 +01:00
# ifdef HAVE_SMEM
static char * shared_memory_base_name = 0 ;
# endif
static uint opt_protocol = 0 ;
2001-04-20 00:12:10 +02:00
2010-10-08 09:09:47 +02:00
enum operations { DO_CHECK = 1 , DO_REPAIR , DO_ANALYZE , DO_OPTIMIZE , DO_UPGRADE } ;
2001-04-20 00:12:10 +02:00
2002-04-02 19:29:53 +02:00
static struct my_option my_long_options [ ] =
2001-04-20 00:12:10 +02:00
{
2002-04-02 19:29:53 +02:00
{ " all-databases " , ' A ' ,
2010-02-04 13:39:42 +01:00
" Check all the databases. This is the same as --databases with all databases selected. " ,
2010-06-10 22:16:43 +02:00
& opt_alldbs , & opt_alldbs , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 , 0 } ,
{ " analyze " , ' a ' , " Analyze given tables. " , 0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 ,
0 , 0 , 0 , 0 } ,
{ " all-in-1 " , ' 1 ' ,
2002-08-28 12:14:11 +02:00
" Instead of issuing one query for each table, use one query per database, naming all tables in the database in a comma-separated list. " ,
2010-06-10 22:16:43 +02:00
& opt_all_in_1 , & opt_all_in_1 , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 } ,
{ " auto-repair " , OPT_AUTO_REPAIR ,
" If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found. " ,
2010-06-10 22:16:43 +02:00
& opt_auto_repair , & opt_auto_repair , 0 , GET_BOOL , NO_ARG , 0 ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 , 0 , 0 } ,
{ " character-sets-dir " , OPT_CHARSETS_DIR ,
2010-06-10 22:16:43 +02:00
" Directory for character set files. " , & charsets_dir ,
& charsets_dir , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2003-06-13 10:59:02 +02:00
{ " check " , ' c ' , " Check table for errors. " , 0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 , 0 } ,
{ " check-only-changed " , ' C ' ,
" Check only tables that have changed since last check or haven't been closed properly. " ,
0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2006-02-17 07:52:32 +01:00
{ " check-upgrade " , ' g ' ,
2006-02-17 15:32:52 +01:00
" Check tables for version-dependent changes. May be used with --auto-repair to correct tables requiring version-dependent updates. " ,
2006-02-17 07:52:32 +01:00
0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2002-04-02 19:29:53 +02:00
{ " compress " , OPT_COMPRESS , " Use compression in server/client protocol. " ,
2010-06-10 22:16:43 +02:00
& opt_compress , & opt_compress , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 } ,
{ " databases " , ' B ' ,
2010-02-04 13:39:42 +01:00
" Check several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names. " ,
2010-06-10 22:16:43 +02:00
& opt_databases , & opt_databases , 0 , GET_BOOL , NO_ARG ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 , 0 , 0 , 0 } ,
2004-11-02 10:14:07 +01:00
# ifdef DBUG_OFF
{ " debug " , ' # ' , " This is a non-debug version. Catch this and exit. " ,
0 , 0 , 0 , GET_DISABLED , OPT_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
# else
2003-06-13 10:59:02 +02:00
{ " debug " , ' # ' , " Output debug log. Often this is 'd:t:o,filename'. " ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 , GET_STR , OPT_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2004-11-02 10:14:07 +01:00
# endif
2007-10-01 14:32:07 +02:00
{ " debug-check " , OPT_DEBUG_CHECK , " Check memory and open file usage at exit. " ,
2010-06-10 22:16:43 +02:00
& debug_check_flag , & debug_check_flag , 0 ,
2007-08-01 21:59:05 +02:00
GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ " debug-info " , OPT_DEBUG_INFO , " Print some debug info at exit. " ,
2010-06-10 22:16:43 +02:00
& debug_info_flag , & debug_info_flag ,
2007-08-01 21:59:05 +02:00
0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2002-04-02 19:29:53 +02:00
{ " default-character-set " , OPT_DEFAULT_CHARSET ,
2010-06-10 22:16:43 +02:00
" Set the default character set. " , & default_charset ,
& default_charset , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2011-01-16 04:59:05 +01:00
{ " default_auth " , OPT_DEFAULT_AUTH ,
" Default authentication client-side plugin to use. " ,
2011-06-06 12:27:05 +02:00
& opt_default_auth , & opt_default_auth , 0 ,
2011-01-16 04:59:05 +01:00
GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2015-10-14 08:30:39 +02:00
{ " enable_cleartext_plugin " , OPT_ENABLE_CLEARTEXT_PLUGIN ,
" Enable/disable the clear text authentication plugin. " ,
& opt_enable_cleartext_plugin , & opt_enable_cleartext_plugin ,
0 , GET_BOOL , OPT_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2003-06-13 10:59:02 +02:00
{ " fast " , ' F ' , " Check only tables that haven't been closed properly. " ,
2010-06-10 22:16:43 +02:00
& opt_fast , & opt_fast , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 } ,
2006-02-17 09:10:36 +01:00
{ " fix-db-names " , OPT_FIX_DB_NAMES , " Fix database names. " ,
2010-06-10 22:16:43 +02:00
& opt_fix_db_names , & opt_fix_db_names ,
2006-02-17 09:10:36 +01:00
0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ " fix-table-names " , OPT_FIX_TABLE_NAMES , " Fix table names. " ,
2010-06-10 22:16:43 +02:00
& opt_fix_table_names , & opt_fix_table_names ,
2006-02-17 09:10:36 +01:00
0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2010-02-04 13:39:42 +01:00
{ " force " , ' f ' , " Continue even if we get an SQL error. " ,
2010-06-10 22:16:43 +02:00
& ignore_errors , & ignore_errors , 0 , GET_BOOL , NO_ARG , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 , 0 } ,
{ " extended " , ' e ' ,
2002-08-27 02:20:25 +02:00
" If you are using this option with CHECK TABLE, it will ensure that the table is 100 percent consistent, but will take a long time. If you are using this option with REPAIR TABLE, it will force using old slow repair with keycache method, instead of much faster repair by sorting. " ,
2010-06-10 22:16:43 +02:00
& opt_extended , & opt_extended , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 } ,
{ " help " , ' ? ' , " Display this help message and exit. " , 0 , 0 , 0 , GET_NO_ARG ,
NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2010-06-10 22:16:43 +02:00
{ " host " , ' h ' , " Connect to host. " , & current_host ,
& current_host , 0 , GET_STR_ALLOC , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2002-04-02 19:29:53 +02:00
{ " medium-check " , ' m ' ,
" Faster than extended-check, but only finds 99.99 percent of all errors. Should be good enough for most cases. " ,
0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2007-03-28 18:19:10 +02:00
{ " write-binlog " , OPT_WRITE_BINLOG ,
2010-06-11 03:30:49 +02:00
" Log ANALYZE, OPTIMIZE and REPAIR TABLE commands. Use --skip-write-binlog "
" when commands should not be sent to replication slaves. " ,
2010-06-10 22:16:43 +02:00
& opt_write_binlog , & opt_write_binlog , 0 , GET_BOOL , NO_ARG ,
2007-03-28 18:19:10 +02:00
1 , 0 , 0 , 0 , 0 , 0 } ,
2002-04-02 19:29:53 +02:00
{ " optimize " , ' o ' , " Optimize table. " , 0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 ,
0 , 0 } ,
{ " password " , ' p ' ,
2010-02-04 13:39:42 +01:00
" Password to use when connecting to server. If password is not given, it's solicited on the tty. " ,
2002-04-02 19:29:53 +02:00
0 , 0 , 0 , GET_STR , OPT_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2001-04-20 00:12:10 +02:00
# ifdef __WIN__
2002-04-02 19:29:53 +02:00
{ " pipe " , ' W ' , " Use named pipes to connect to server. " , 0 , 0 , 0 , GET_NO_ARG ,
NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2001-04-20 00:12:10 +02:00
# endif
2011-01-16 04:59:05 +01:00
{ " plugin_dir " , OPT_PLUGIN_DIR , " Directory for client-side plugins. " ,
2011-06-06 12:27:05 +02:00
& opt_plugin_dir , & opt_plugin_dir , 0 ,
2011-01-16 04:59:05 +01:00
GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2007-09-13 16:19:46 +02:00
{ " port " , ' P ' , " Port number to use for connection or 0 for default to, in "
" order of preference, my.cnf, $MYSQL_TCP_PORT, "
# if MYSQL_PORT_DEFAULT == 0
" /etc/services, "
# endif
" built-in default ( " STRINGIFY_ARG ( MYSQL_PORT ) " ). " ,
2010-06-11 03:30:49 +02:00
& opt_mysql_port , & opt_mysql_port , 0 , GET_UINT , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 ,
2002-05-11 13:36:34 +02:00
0 } ,
2010-02-04 13:39:42 +01:00
{ " protocol " , OPT_MYSQL_PROTOCOL , " The protocol to use for connection (tcp, socket, pipe, memory). " ,
2002-11-14 20:16:30 +01:00
0 , 0 , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2002-04-02 19:29:53 +02:00
{ " quick " , ' q ' ,
" If you are using this option with CHECK TABLE, it prevents the check from scanning the rows to check for wrong links. This is the fastest check. If you are using this option with REPAIR TABLE, it will try to repair only the index tree. This is the fastest repair method for a table. " ,
2010-06-10 22:16:43 +02:00
& opt_quick , & opt_quick , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 ,
2002-04-02 19:29:53 +02:00
0 } ,
{ " repair " , ' r ' ,
" Can fix almost anything except unique keys that aren't unique. " ,
0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2002-11-14 20:16:30 +01:00
# ifdef HAVE_SMEM
2004-08-30 18:11:10 +02:00
{ " shared-memory-base-name " , OPT_SHARED_MEMORY_BASE_NAME ,
2010-06-10 22:16:43 +02:00
" Base name of shared memory. " , & shared_memory_base_name , & shared_memory_base_name ,
2002-11-14 20:16:30 +01:00
0 , GET_STR_ALLOC , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
# endif
2010-06-10 22:16:43 +02:00
{ " silent " , ' s ' , " Print only error messages. " , & opt_silent ,
& opt_silent , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2010-02-04 13:39:42 +01:00
{ " socket " , ' S ' , " The socket file to use for connection. " ,
2010-06-10 22:16:43 +02:00
& opt_mysql_unix_port , & opt_mysql_unix_port , 0 , GET_STR ,
2002-04-02 19:29:53 +02:00
REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2002-09-17 22:46:53 +02:00
# include <sslopt-longopts.h>
2002-04-02 19:29:53 +02:00
{ " tables " , OPT_TABLES , " Overrides option --databases (-B). " , 0 , 0 , 0 ,
GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2002-11-08 20:57:36 +01:00
{ " use-frm " , OPT_FRM ,
" When used with REPAIR, get table structure from .frm file, so the table can be repaired even if .MYI header is corrupted. " ,
2010-06-10 22:16:43 +02:00
& opt_frm , & opt_frm , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 ,
2002-11-08 20:57:36 +01:00
0 } ,
2006-02-16 17:00:14 +01:00
# ifndef DONT_ALLOW_USER_CHANGE
2010-06-10 22:16:43 +02:00
{ " user " , ' u ' , " User for login if not current user. " , & current_user ,
& current_user , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
2006-02-16 17:00:14 +01:00
# endif
2002-04-02 19:29:53 +02:00
{ " verbose " , ' v ' , " Print info about the various stages. " , 0 , 0 , 0 , GET_NO_ARG ,
NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ " version " , ' V ' , " Output version information and exit. " , 0 , 0 , 0 , GET_NO_ARG ,
NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 0 , 0 , 0 , 0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 }
2001-04-20 00:12:10 +02:00
} ;
2002-11-08 20:57:36 +01:00
2001-04-20 00:12:10 +02:00
static const char * load_default_groups [ ] = { " mysqlcheck " , " client " , 0 } ;
static void print_version ( void ) ;
static void usage ( void ) ;
static int get_options ( int * argc , char * * * argv ) ;
static int process_all_databases ( ) ;
static int process_databases ( char * * db_names ) ;
static int process_selected_tables ( char * db , char * * table_names , int tables ) ;
static int process_all_tables_in_db ( char * database ) ;
2006-02-17 09:10:36 +01:00
static int process_one_db ( char * database ) ;
2001-04-20 00:12:10 +02:00
static int use_db ( char * database ) ;
static int handle_request_for_tables ( char * tables , uint length ) ;
static int dbConnect ( char * host , char * user , char * passwd ) ;
static void dbDisconnect ( char * host ) ;
static void DBerror ( MYSQL * mysql , const char * when ) ;
static void safe_exit ( int error ) ;
static void print_result ( ) ;
2007-10-30 09:51:57 +01:00
static uint fixed_name_length ( const char * name ) ;
2003-01-28 22:29:59 +01:00
static char * fix_table_name ( char * dest , char * src ) ;
2001-04-20 00:12:10 +02:00
int what_to_do = 0 ;
2004-05-25 21:00:14 +02:00
2001-04-20 00:12:10 +02:00
static void print_version ( void )
{
printf ( " %s Ver %s Distrib %s, for %s (%s) \n " , my_progname , CHECK_VERSION ,
MYSQL_SERVER_VERSION , SYSTEM_TYPE , MACHINE_TYPE ) ;
} /* print_version */
static void usage ( void )
{
print_version ( ) ;
2012-08-07 15:28:19 +02:00
puts ( ORACLE_WELCOME_COPYRIGHT_NOTICE ( " 2000 " ) ) ;
2010-02-04 13:39:42 +01:00
puts ( " This program can be used to CHECK (-c, -m, -C), REPAIR (-r), ANALYZE (-a), " ) ;
2001-04-20 00:12:10 +02:00
puts ( " or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be " ) ;
2005-02-03 00:03:34 +01:00
puts ( " used at the same time. Not all options are supported by all storage engines. " ) ;
2001-04-20 00:12:10 +02:00
puts ( " Please consult the MySQL manual for latest information about the " ) ;
2010-02-04 13:39:42 +01:00
puts ( " above. The options -c, -r, -a, and -o are exclusive to each other, which " ) ;
2001-04-23 22:29:53 +02:00
puts ( " means that the last option will be used, if several was specified. \n " ) ;
puts ( " The option -c will be used by default, if none was specified. You " ) ;
puts ( " can change the default behavior by making a symbolic link, or " ) ;
puts ( " copying this file somewhere with another name, the alternatives are: " ) ;
puts ( " mysqlrepair: The default option will be -r " ) ;
puts ( " mysqlanalyze: The default option will be -a " ) ;
puts ( " mysqloptimize: The default option will be -o \n " ) ;
2001-04-20 00:12:10 +02:00
printf ( " Usage: %s [OPTIONS] database [tables] \n " , my_progname ) ;
printf ( " OR %s [OPTIONS] --databases DB1 [DB2 DB3...] \n " ,
my_progname ) ;
printf ( " OR %s [OPTIONS] --all-databases \n " , my_progname ) ;
print_defaults ( " my " , load_default_groups ) ;
2002-04-02 19:29:53 +02:00
my_print_help ( my_long_options ) ;
my_print_variables ( my_long_options ) ;
2001-04-20 00:12:10 +02:00
} /* usage */
2001-12-06 13:10:51 +01:00
2002-04-02 19:29:53 +02:00
static my_bool
get_one_option ( int optid , const struct my_option * opt __attribute__ ( ( unused ) ) ,
char * argument )
{
2010-10-08 09:09:47 +02:00
int orig_what_to_do = what_to_do ;
2002-04-02 19:29:53 +02:00
switch ( optid ) {
case ' a ' :
what_to_do = DO_ANALYZE ;
break ;
case ' c ' :
what_to_do = DO_CHECK ;
break ;
case ' C ' :
what_to_do = DO_CHECK ;
opt_check_only_changed = 1 ;
break ;
case ' I ' : /* Fall through */
case ' ? ' :
usage ( ) ;
exit ( 0 ) ;
case ' m ' :
what_to_do = DO_CHECK ;
opt_medium_check = 1 ;
break ;
case ' o ' :
what_to_do = DO_OPTIMIZE ;
break ;
2006-02-17 09:10:36 +01:00
case OPT_FIX_DB_NAMES :
what_to_do = DO_UPGRADE ;
opt_databases = 1 ;
break ;
case OPT_FIX_TABLE_NAMES :
what_to_do = DO_UPGRADE ;
break ;
2002-04-02 19:29:53 +02:00
case ' p ' :
2009-05-07 19:51:55 +02:00
if ( argument = = disabled_my_option )
2009-06-03 13:18:12 +02:00
argument = ( char * ) " " ; /* Don't require password */
2002-04-02 19:29:53 +02:00
if ( argument )
{
char * start = argument ;
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
my_free ( opt_password ) ;
2002-04-02 19:29:53 +02:00
opt_password = my_strdup ( argument , MYF ( MY_FAE ) ) ;
while ( * argument ) * argument + + = ' x ' ; /* Destroy argument */
if ( * start )
2002-11-08 20:57:36 +01:00
start [ 1 ] = 0 ; /* Cut length of argument */
2004-10-07 21:08:17 +02:00
tty_password = 0 ;
2002-04-02 19:29:53 +02:00
}
else
tty_password = 1 ;
break ;
case ' r ' :
what_to_do = DO_REPAIR ;
break ;
2006-02-17 07:52:32 +01:00
case ' g ' :
what_to_do = DO_CHECK ;
opt_upgrade = 1 ;
break ;
2002-04-02 19:29:53 +02:00
case ' W ' :
# ifdef __WIN__
2002-11-14 20:16:30 +01:00
opt_protocol = MYSQL_PROTOCOL_PIPE ;
2002-04-02 19:29:53 +02:00
# endif
break ;
case ' # ' :
DBUG_PUSH ( argument ? argument : " d:t:o " ) ;
2007-08-02 06:49:29 +02:00
debug_check_flag = 1 ;
2002-04-02 19:29:53 +02:00
break ;
2002-09-17 22:46:53 +02:00
# include <sslopt-case.h>
2002-04-02 19:29:53 +02:00
case OPT_TABLES :
opt_databases = 0 ;
break ;
case ' v ' :
verbose + + ;
break ;
case ' V ' : print_version ( ) ; exit ( 0 ) ;
2015-10-14 08:30:39 +02:00
case OPT_ENABLE_CLEARTEXT_PLUGIN :
using_opt_enable_cleartext_plugin = TRUE ;
break ;
2002-11-14 20:16:30 +01:00
case OPT_MYSQL_PROTOCOL :
2007-03-19 10:19:51 +01:00
opt_protocol = find_type_or_exit ( argument , & sql_protocol_typelib ,
opt - > name ) ;
2002-11-14 20:16:30 +01:00
break ;
}
2010-10-08 09:09:47 +02:00
if ( orig_what_to_do & & ( what_to_do ! = orig_what_to_do ) )
{
fprintf ( stderr , " Error: %s doesn't support multiple contradicting commands. \n " ,
my_progname ) ;
return 1 ;
}
2002-04-02 19:29:53 +02:00
return 0 ;
}
2001-04-20 00:12:10 +02:00
static int get_options ( int * argc , char * * * argv )
{
2002-04-02 19:29:53 +02:00
int ho_error ;
2001-04-20 00:12:10 +02:00
2001-04-23 22:29:53 +02:00
if ( * argc = = 1 )
{
usage ( ) ;
exit ( 0 ) ;
}
2009-10-09 16:44:22 +02:00
if ( ( ho_error = load_defaults ( " my " , load_default_groups , argc , argv ) ) | |
( ho_error = handle_options ( argc , argv , my_long_options , get_one_option ) ) )
2002-05-29 14:07:30 +02:00
exit ( ho_error ) ;
2002-04-02 19:29:53 +02:00
2001-04-20 00:12:10 +02:00
if ( ! what_to_do )
2001-04-23 22:29:53 +02:00
{
2009-02-10 23:47:54 +01:00
size_t pnlen = strlen ( my_progname ) ;
2001-04-23 22:29:53 +02:00
2001-05-29 12:46:17 +02:00
if ( pnlen < 6 ) /* name too short */
2001-04-23 22:29:53 +02:00
what_to_do = DO_CHECK ;
else if ( ! strcmp ( " repair " , my_progname + pnlen - 6 ) )
what_to_do = DO_REPAIR ;
else if ( ! strcmp ( " analyze " , my_progname + pnlen - 7 ) )
what_to_do = DO_ANALYZE ;
else if ( ! strcmp ( " optimize " , my_progname + pnlen - 8 ) )
what_to_do = DO_OPTIMIZE ;
else
what_to_do = DO_CHECK ;
}
2003-11-21 00:53:01 +01:00
2009-01-14 15:50:51 +01:00
/*
If there ' s no - - default - character - set option given with
- - fix - table - name or - - fix - db - name set the default character set to " utf8 " .
*/
2009-10-21 14:59:47 +02:00
if ( ! default_charset )
2009-01-14 15:50:51 +01:00
{
2009-10-21 14:59:47 +02:00
if ( opt_fix_db_names | | opt_fix_table_names )
default_charset = ( char * ) " utf8 " ;
else
default_charset = ( char * ) MYSQL_AUTODETECT_CHARSET_NAME ;
2009-01-14 15:50:51 +01:00
}
2009-10-21 14:59:47 +02:00
if ( strcmp ( default_charset , MYSQL_AUTODETECT_CHARSET_NAME ) & &
! get_charset_by_csname ( default_charset , MY_CS_PRIMARY , MYF ( MY_WME ) ) )
2009-01-14 15:50:51 +01:00
{
printf ( " Unsupported character set: %s \n " , default_charset ) ;
return 1 ;
}
2001-04-20 00:12:10 +02:00
if ( * argc > 0 & & opt_alldbs )
{
printf ( " You should give only options, no arguments at all, with option \n " ) ;
printf ( " --all-databases. Please see %s --help for more information. \n " ,
my_progname ) ;
return 1 ;
}
if ( * argc < 1 & & ! opt_alldbs )
{
printf ( " You forgot to give the arguments! Please see %s --help \n " ,
my_progname ) ;
printf ( " for more information. \n " ) ;
return 1 ;
}
if ( tty_password )
opt_password = get_tty_password ( NullS ) ;
2007-08-01 21:59:05 +02:00
if ( debug_info_flag )
my_end_arg = MY_CHECK_ERROR | MY_GIVE_INFO ;
if ( debug_check_flag )
my_end_arg = MY_CHECK_ERROR ;
2001-04-20 00:12:10 +02:00
return ( 0 ) ;
} /* get_options */
static int process_all_databases ( )
{
MYSQL_ROW row ;
MYSQL_RES * tableres ;
int result = 0 ;
if ( mysql_query ( sock , " SHOW DATABASES " ) | |
! ( tableres = mysql_store_result ( sock ) ) )
{
my_printf_error ( 0 , " Error: Couldn't execute 'SHOW DATABASES': %s " ,
MYF ( 0 ) , mysql_error ( sock ) ) ;
return 1 ;
}
while ( ( row = mysql_fetch_row ( tableres ) ) )
{
2006-02-17 09:10:36 +01:00
if ( process_one_db ( row [ 0 ] ) )
2001-04-20 00:12:10 +02:00
result = 1 ;
}
return result ;
}
/* process_all_databases */
static int process_databases ( char * * db_names )
{
int result = 0 ;
for ( ; * db_names ; db_names + + )
{
2006-02-17 09:10:36 +01:00
if ( process_one_db ( * db_names ) )
2001-04-20 00:12:10 +02:00
result = 1 ;
}
return result ;
} /* process_databases */
static int process_selected_tables ( char * db , char * * table_names , int tables )
{
if ( use_db ( db ) )
return 1 ;
2009-05-21 03:31:10 +02:00
if ( opt_all_in_1 & & what_to_do ! = DO_UPGRADE )
2001-04-20 00:12:10 +02:00
{
2002-11-12 15:09:33 +01:00
/*
We need table list in form ` a ` , ` b ` , ` c `
2007-10-30 09:51:57 +01:00
that ' s why we need 2 more chars added to to each table name
2002-11-12 15:09:33 +01:00
space is for more readable output in logs and in case of error
*/
2001-04-20 00:12:10 +02:00
char * table_names_comma_sep , * end ;
2009-02-10 23:47:54 +01:00
size_t tot_length = 0 ;
int i = 0 ;
2001-04-20 00:12:10 +02:00
for ( i = 0 ; i < tables ; i + + )
2007-10-30 09:51:57 +01:00
tot_length + = fixed_name_length ( * ( table_names + i ) ) + 2 ;
2001-12-06 13:10:51 +01:00
2001-04-20 00:12:10 +02:00
if ( ! ( table_names_comma_sep = ( char * )
2002-11-12 15:09:33 +01:00
my_malloc ( ( sizeof ( char ) * tot_length ) + 4 , MYF ( MY_WME ) ) ) )
2001-04-20 00:12:10 +02:00
return 1 ;
for ( end = table_names_comma_sep + 1 ; tables > 0 ;
tables - - , table_names + + )
{
2003-01-28 22:29:59 +01:00
end = fix_table_name ( end , * table_names ) ;
* end + + = ' , ' ;
2001-04-20 00:12:10 +02:00
}
* - - end = 0 ;
2009-02-10 23:47:54 +01:00
handle_request_for_tables ( table_names_comma_sep + 1 , ( uint ) ( tot_length - 1 ) ) ;
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
my_free ( table_names_comma_sep ) ;
2001-04-20 00:12:10 +02:00
}
else
for ( ; tables > 0 ; tables - - , table_names + + )
2007-10-30 09:51:57 +01:00
handle_request_for_tables ( * table_names , fixed_name_length ( * table_names ) ) ;
2001-04-20 00:12:10 +02:00
return 0 ;
} /* process_selected_tables */
2007-10-30 09:51:57 +01:00
static uint fixed_name_length ( const char * name )
2003-01-28 22:29:59 +01:00
{
2007-10-30 09:51:57 +01:00
const char * p ;
uint extra_length = 2 ; /* count the first/last backticks */
for ( p = name ; * p ; p + + )
{
if ( * p = = ' ` ' )
extra_length + + ;
else if ( * p = = ' . ' )
extra_length + = 2 ;
}
2009-02-10 23:47:54 +01:00
return ( uint ) ( ( p - name ) + extra_length ) ;
2007-10-30 09:51:57 +01:00
}
2003-01-28 22:29:59 +01:00
2007-10-30 09:51:57 +01:00
static char * fix_table_name ( char * dest , char * src )
{
2003-01-28 22:29:59 +01:00
* dest + + = ' ` ' ;
2007-10-30 09:51:57 +01:00
for ( ; * src ; src + + )
2003-01-28 22:29:59 +01:00
{
2007-10-30 09:51:57 +01:00
switch ( * src ) {
case ' . ' : /* add backticks around '.' */
* dest + + = ' ` ' ;
* dest + + = ' . ' ;
* dest + + = ' ` ' ;
break ;
case ' ` ' : /* escape backtick character */
* dest + + = ' ` ' ;
/* fall through */
default :
* dest + + = * src ;
}
2003-01-28 22:29:59 +01:00
}
2007-10-30 09:51:57 +01:00
* dest + + = ' ` ' ;
2003-01-28 22:29:59 +01:00
return dest ;
}
2001-04-20 00:12:10 +02:00
static int process_all_tables_in_db ( char * database )
{
MYSQL_RES * res ;
MYSQL_ROW row ;
2007-04-04 00:12:31 +02:00
uint num_columns ;
2001-04-20 00:12:10 +02:00
LINT_INIT ( res ) ;
if ( use_db ( database ) )
return 1 ;
2008-11-14 08:40:46 +01:00
if ( ( mysql_query ( sock , " SHOW /*!50002 FULL*/ TABLES " ) & &
mysql_query ( sock , " SHOW TABLES " ) ) | |
! ( res = mysql_store_result ( sock ) ) )
{
my_printf_error ( 0 , " Error: Couldn't get table list for database %s: %s " ,
MYF ( 0 ) , database , mysql_error ( sock ) ) ;
2001-04-20 00:12:10 +02:00
return 1 ;
2008-11-14 08:40:46 +01:00
}
2001-12-06 13:10:51 +01:00
2007-04-04 00:12:31 +02:00
num_columns = mysql_num_fields ( res ) ;
2009-05-21 03:31:10 +02:00
if ( opt_all_in_1 & & what_to_do ! = DO_UPGRADE )
2001-04-20 00:12:10 +02:00
{
2004-09-06 22:48:42 +02:00
/*
2002-11-12 15:09:33 +01:00
We need table list in form ` a ` , ` b ` , ` c `
2007-10-30 09:51:57 +01:00
that ' s why we need 2 more chars added to to each table name
2002-11-12 15:09:33 +01:00
space is for more readable output in logs and in case of error
*/
2004-09-06 22:48:42 +02:00
2001-04-20 00:12:10 +02:00
char * tables , * end ;
uint tot_length = 0 ;
while ( ( row = mysql_fetch_row ( res ) ) )
2007-10-30 09:51:57 +01:00
tot_length + = fixed_name_length ( row [ 0 ] ) + 2 ;
2001-04-20 00:12:10 +02:00
mysql_data_seek ( res , 0 ) ;
2001-12-06 13:10:51 +01:00
2002-11-12 15:09:33 +01:00
if ( ! ( tables = ( char * ) my_malloc ( sizeof ( char ) * tot_length + 4 , MYF ( MY_WME ) ) ) )
2001-04-20 00:12:10 +02:00
{
mysql_free_result ( res ) ;
return 1 ;
}
for ( end = tables + 1 ; ( row = mysql_fetch_row ( res ) ) ; )
{
2007-04-04 00:12:31 +02:00
if ( ( num_columns = = 2 ) & & ( strcmp ( row [ 1 ] , " VIEW " ) = = 0 ) )
continue ;
end = fix_table_name ( end , row [ 0 ] ) ;
* end + + = ' , ' ;
2001-04-20 00:12:10 +02:00
}
* - - end = 0 ;
if ( tot_length )
handle_request_for_tables ( tables + 1 , tot_length - 1 ) ;
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
my_free ( tables ) ;
2001-04-20 00:12:10 +02:00
}
else
{
while ( ( row = mysql_fetch_row ( res ) ) )
2007-04-04 00:12:31 +02:00
{
2007-12-14 19:42:09 +01:00
/* Skip views if we don't perform renaming. */
if ( ( what_to_do ! = DO_UPGRADE ) & & ( num_columns = = 2 ) & & ( strcmp ( row [ 1 ] , " VIEW " ) = = 0 ) )
2007-04-04 00:12:31 +02:00
continue ;
2007-12-14 19:42:09 +01:00
handle_request_for_tables ( row [ 0 ] , fixed_name_length ( row [ 0 ] ) ) ;
2007-04-04 00:12:31 +02:00
}
2001-04-20 00:12:10 +02:00
}
mysql_free_result ( res ) ;
return 0 ;
} /* process_all_tables_in_db */
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
static int run_query ( const char * query )
{
if ( mysql_query ( sock , query ) )
{
fprintf ( stderr , " Failed to %s \n " , query ) ;
fprintf ( stderr , " Error: %s \n " , mysql_error ( sock ) ) ;
return 1 ;
}
return 0 ;
}
2006-02-17 09:10:36 +01:00
2007-09-11 00:10:37 +02:00
static int fix_table_storage_name ( const char * name )
2006-02-17 09:10:36 +01:00
{
char qbuf [ 100 + NAME_LEN * 4 ] ;
int rc = 0 ;
if ( strncmp ( name , " #mysql50# " , 9 ) )
return 1 ;
2007-09-11 00:10:37 +02:00
sprintf ( qbuf , " RENAME TABLE `%s` TO `%s` " , name , name + 9 ) ;
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
rc = run_query ( qbuf ) ;
2006-02-17 09:10:36 +01:00
if ( verbose )
printf ( " %-50s %s \n " , name , rc ? " FAILED " : " OK " ) ;
return rc ;
}
2007-09-11 00:10:37 +02:00
static int fix_database_storage_name ( const char * name )
{
char qbuf [ 100 + NAME_LEN * 4 ] ;
int rc = 0 ;
if ( strncmp ( name , " #mysql50# " , 9 ) )
return 1 ;
sprintf ( qbuf , " ALTER DATABASE `%s` UPGRADE DATA DIRECTORY NAME " , name ) ;
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
rc = run_query ( qbuf ) ;
2007-09-11 00:10:37 +02:00
if ( verbose )
printf ( " %-50s %s \n " , name , rc ? " FAILED " : " OK " ) ;
return rc ;
}
2006-02-17 09:10:36 +01:00
2011-03-08 09:41:57 +01:00
static int rebuild_table ( char * name )
{
char * query , * ptr ;
int rc = 0 ;
query = ( char * ) my_malloc ( sizeof ( char ) * ( 12 + fixed_name_length ( name ) + 6 + 1 ) ,
MYF ( MY_WME ) ) ;
if ( ! query )
return 1 ;
ptr = strmov ( query , " ALTER TABLE " ) ;
ptr = fix_table_name ( ptr , name ) ;
ptr = strxmov ( ptr , " FORCE " , NullS ) ;
if ( mysql_real_query ( sock , query , ( uint ) ( ptr - query ) ) )
{
fprintf ( stderr , " Failed to %s \n " , query ) ;
fprintf ( stderr , " Error: %s \n " , mysql_error ( sock ) ) ;
rc = 1 ;
}
my_free ( query ) ;
return rc ;
}
2006-02-17 09:10:36 +01:00
static int process_one_db ( char * database )
{
if ( what_to_do = = DO_UPGRADE )
{
int rc = 0 ;
if ( opt_fix_db_names & & ! strncmp ( database , " #mysql50# " , 9 ) )
{
2007-09-11 00:10:37 +02:00
rc = fix_database_storage_name ( database ) ;
2006-02-17 09:10:36 +01:00
database + = 9 ;
}
if ( rc | | ! opt_fix_table_names )
return rc ;
}
return process_all_tables_in_db ( database ) ;
}
2001-04-20 00:12:10 +02:00
static int use_db ( char * database )
{
2009-12-10 04:19:51 +01:00
if ( mysql_get_server_version ( sock ) > = FIRST_INFORMATION_SCHEMA_VERSION & &
! my_strcasecmp ( & my_charset_latin1 , database , INFORMATION_SCHEMA_DB_NAME ) )
return 1 ;
if ( mysql_get_server_version ( sock ) > = FIRST_PERFORMANCE_SCHEMA_VERSION & &
! my_strcasecmp ( & my_charset_latin1 , database , PERFORMANCE_SCHEMA_DB_NAME ) )
2005-10-18 11:25:03 +02:00
return 1 ;
2001-04-20 00:12:10 +02:00
if ( mysql_select_db ( sock , database ) )
{
DBerror ( sock , " when selecting the database " ) ;
return 1 ;
}
return 0 ;
} /* use_db */
2009-09-28 08:24:19 +02:00
static int disable_binlog ( )
{
const char * stmt = " SET SQL_LOG_BIN=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
return run_query ( stmt ) ;
2009-09-28 08:24:19 +02:00
}
2001-04-20 00:12:10 +02:00
static int handle_request_for_tables ( char * tables , uint length )
{
2001-06-19 13:30:12 +02:00
char * query , * end , options [ 100 ] , message [ 100 ] ;
2003-01-28 22:29:59 +01:00
uint query_length = 0 ;
2001-04-20 00:12:10 +02:00
const char * op = 0 ;
options [ 0 ] = 0 ;
2001-06-19 13:30:12 +02:00
end = options ;
2001-04-20 00:12:10 +02:00
switch ( what_to_do ) {
case DO_CHECK :
op = " CHECK " ;
2001-06-19 13:30:12 +02:00
if ( opt_quick ) end = strmov ( end , " QUICK " ) ;
if ( opt_fast ) end = strmov ( end , " FAST " ) ;
if ( opt_medium_check ) end = strmov ( end , " MEDIUM " ) ; /* Default */
if ( opt_extended ) end = strmov ( end , " EXTENDED " ) ;
if ( opt_check_only_changed ) end = strmov ( end , " CHANGED " ) ;
2006-02-17 07:52:32 +01:00
if ( opt_upgrade ) end = strmov ( end , " FOR UPGRADE " ) ;
2001-04-20 00:12:10 +02:00
break ;
case DO_REPAIR :
2007-03-28 18:19:10 +02:00
op = ( opt_write_binlog ) ? " REPAIR " : " REPAIR NO_WRITE_TO_BINLOG " ;
2001-06-19 13:30:12 +02:00
if ( opt_quick ) end = strmov ( end , " QUICK " ) ;
if ( opt_extended ) end = strmov ( end , " EXTENDED " ) ;
2002-11-08 20:57:36 +01:00
if ( opt_frm ) end = strmov ( end , " USE_FRM " ) ;
2001-04-20 00:12:10 +02:00
break ;
case DO_ANALYZE :
2007-03-28 18:19:10 +02:00
op = ( opt_write_binlog ) ? " ANALYZE " : " ANALYZE NO_WRITE_TO_BINLOG " ;
2001-04-20 00:12:10 +02:00
break ;
case DO_OPTIMIZE :
2007-03-28 18:19:10 +02:00
op = ( opt_write_binlog ) ? " OPTIMIZE " : " OPTIMIZE NO_WRITE_TO_BINLOG " ;
2001-04-20 00:12:10 +02:00
break ;
2006-02-17 09:10:36 +01:00
case DO_UPGRADE :
2007-09-11 00:10:37 +02:00
return fix_table_storage_name ( tables ) ;
2001-04-20 00:12:10 +02:00
}
if ( ! ( query = ( char * ) my_malloc ( ( sizeof ( char ) * ( length + 110 ) ) , MYF ( MY_WME ) ) ) )
return 1 ;
2002-11-12 15:09:33 +01:00
if ( opt_all_in_1 )
2003-01-28 22:29:59 +01:00
{
2002-11-12 15:09:33 +01:00
/* No backticks here as we added them before */
2010-07-09 14:00:17 +02:00
query_length = sprintf ( query , " %s TABLE %s %s " , op , tables , options ) ;
2003-01-28 22:29:59 +01:00
}
2002-11-12 15:09:33 +01:00
else
2003-01-28 22:29:59 +01:00
{
char * ptr ;
ptr = strmov ( strmov ( query , op ) , " TABLE " ) ;
ptr = fix_table_name ( ptr , tables ) ;
ptr = strxmov ( ptr , " " , options , NullS ) ;
query_length = ( uint ) ( ptr - query ) ;
}
if ( mysql_real_query ( sock , query , query_length ) )
2001-04-20 00:12:10 +02:00
{
2002-11-12 15:09:33 +01:00
sprintf ( message , " when executing '%s TABLE ... %s' " , op , options ) ;
2001-06-19 13:30:12 +02:00
DBerror ( sock , message ) ;
2001-04-20 00:12:10 +02:00
return 1 ;
}
print_result ( ) ;
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
my_free ( query ) ;
2001-04-20 00:12:10 +02:00
return 0 ;
}
static void print_result ( )
{
MYSQL_RES * res ;
MYSQL_ROW row ;
2001-04-23 22:29:53 +02:00
char prev [ NAME_LEN * 2 + 2 ] ;
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
char prev_alter [ MAX_ALTER_STR_SIZE ] ;
2001-06-19 13:30:12 +02:00
uint i ;
2011-03-08 09:41:57 +01:00
my_bool found_error = 0 , table_rebuild = 0 ;
2001-04-20 00:12:10 +02:00
res = mysql_use_result ( sock ) ;
2005-03-31 21:43:39 +02:00
2001-04-20 00:12:10 +02:00
prev [ 0 ] = ' \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
prev_alter [ 0 ] = 0 ;
2001-04-20 00:12:10 +02:00
for ( i = 0 ; ( row = mysql_fetch_row ( res ) ) ; i + + )
{
2001-04-20 12:21:35 +02:00
int changed = strcmp ( prev , row [ 0 ] ) ;
2001-06-19 13:30:12 +02:00
my_bool status = ! strcmp ( row [ 2 ] , " status " ) ;
if ( status )
{
2005-08-10 23:37:17 +02:00
/*
if there was an error with the table , we have - - auto - repair set ,
and this isn ' t a repair op , then add the table to the tables4repair
list
*/
2002-10-17 18:34:02 +02:00
if ( found_error & & opt_auto_repair & & what_to_do ! = DO_REPAIR & &
2005-08-10 23:37:17 +02:00
strcmp ( row [ 3 ] , " OK " ) )
2011-03-08 09:41:57 +01:00
{
if ( table_rebuild )
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
{
if ( prev_alter [ 0 ] )
insert_dynamic ( & alter_table_cmds , ( uchar * ) prev_alter ) ;
else
insert_dynamic ( & tables4rebuild , ( uchar * ) prev ) ;
}
2011-03-08 09:41:57 +01:00
else
insert_dynamic ( & tables4repair , ( uchar * ) prev ) ;
}
2001-06-19 13:30:12 +02:00
found_error = 0 ;
2011-03-08 09:41:57 +01:00
table_rebuild = 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
prev_alter [ 0 ] = 0 ;
2001-06-19 13:30:12 +02:00
if ( opt_silent )
continue ;
}
2001-04-20 00:12:10 +02:00
if ( status & & changed )
printf ( " %-50s %s " , row [ 0 ] , row [ 3 ] ) ;
else if ( ! status & & changed )
2001-04-23 22:29:53 +02:00
{
2001-04-20 00:12:10 +02:00
printf ( " %s \n %-9s: %s " , row [ 0 ] , row [ 2 ] , row [ 3 ] ) ;
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
if ( opt_auto_repair & & strcmp ( row [ 2 ] , " note " ) )
2011-03-08 09:41:57 +01:00
{
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
const char * alter_txt = strstr ( row [ 3 ] , " ALTER TABLE " ) ;
found_error = 1 ;
if ( alter_txt )
{
2011-03-08 09:41:57 +01:00
table_rebuild = 1 ;
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
if ( ! strncmp ( row [ 3 ] , KEY_PARTITIONING_CHANGED_STR ,
strlen ( KEY_PARTITIONING_CHANGED_STR ) ) & &
strstr ( alter_txt , " PARTITION BY " ) )
{
if ( strlen ( alter_txt ) > = MAX_ALTER_STR_SIZE )
{
printf ( " Error: Alter command too long (>= %d), "
" please do \" %s \" or dump/reload to fix it! \n " ,
MAX_ALTER_STR_SIZE ,
alter_txt ) ;
table_rebuild = 0 ;
prev_alter [ 0 ] = 0 ;
}
else
strcpy ( prev_alter , alter_txt ) ;
}
}
2011-03-08 09:41:57 +01:00
}
2001-04-23 22:29:53 +02:00
}
2001-04-20 00:12:10 +02:00
else
printf ( " %-9s: %s " , row [ 2 ] , row [ 3 ] ) ;
strmov ( prev , row [ 0 ] ) ;
2001-04-20 12:21:35 +02:00
putchar ( ' \n ' ) ;
2001-04-20 00:12:10 +02:00
}
2005-08-10 23:37:17 +02:00
/* add the last table to be repaired to the list */
if ( found_error & & opt_auto_repair & & what_to_do ! = DO_REPAIR )
2011-03-08 09:41:57 +01:00
{
if ( table_rebuild )
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
{
if ( prev_alter [ 0 ] )
insert_dynamic ( & alter_table_cmds , ( uchar * ) prev_alter ) ;
else
insert_dynamic ( & tables4rebuild , ( uchar * ) prev ) ;
}
2011-03-08 09:41:57 +01:00
else
insert_dynamic ( & tables4repair , ( uchar * ) prev ) ;
}
2001-04-20 00:12:10 +02:00
mysql_free_result ( res ) ;
}
2001-04-20 12:21:35 +02:00
static int dbConnect ( char * host , char * user , char * passwd )
2001-04-20 00:12:10 +02:00
{
DBUG_ENTER ( " dbConnect " ) ;
if ( verbose )
{
fprintf ( stderr , " # Connecting to %s... \n " , host ? host : " localhost " ) ;
}
mysql_init ( & mysql_connection ) ;
if ( opt_compress )
mysql_options ( & mysql_connection , MYSQL_OPT_COMPRESS , NullS ) ;
# ifdef HAVE_OPENSSL
if ( opt_use_ssl )
mysql_ssl_set ( & mysql_connection , opt_ssl_key , opt_ssl_cert , opt_ssl_ca ,
2001-09-30 04:46:20 +02:00
opt_ssl_capath , opt_ssl_cipher ) ;
2002-11-14 20:16:30 +01:00
# endif
if ( opt_protocol )
mysql_options ( & mysql_connection , MYSQL_OPT_PROTOCOL , ( char * ) & opt_protocol ) ;
# ifdef HAVE_SMEM
if ( shared_memory_base_name )
mysql_options ( & mysql_connection , MYSQL_SHARED_MEMORY_BASE_NAME , shared_memory_base_name ) ;
2001-04-20 00:12:10 +02:00
# endif
2011-01-16 04:59:05 +01:00
if ( opt_plugin_dir & & * opt_plugin_dir )
mysql_options ( & mysql_connection , MYSQL_PLUGIN_DIR , opt_plugin_dir ) ;
if ( opt_default_auth & & * opt_default_auth )
mysql_options ( & mysql_connection , MYSQL_DEFAULT_AUTH , opt_default_auth ) ;
2015-10-14 08:30:39 +02:00
if ( using_opt_enable_cleartext_plugin )
mysql_options ( & mysql_connection , MYSQL_ENABLE_CLEARTEXT_PLUGIN ,
( char * ) & opt_enable_cleartext_plugin ) ;
2009-10-21 14:59:47 +02:00
mysql_options ( & mysql_connection , MYSQL_SET_CHARSET_NAME , default_charset ) ;
2016-02-19 20:31:10 +01:00
if ( ! ( sock = mysql_connect_ssl_check ( & mysql_connection , host , user , passwd ,
NULL , opt_mysql_port ,
opt_mysql_unix_port , 0 ,
opt_ssl_required ) ) )
2001-04-20 00:12:10 +02:00
{
DBerror ( & mysql_connection , " when trying to connect " ) ;
return 1 ;
}
2004-12-09 14:44:10 +01:00
mysql_connection . reconnect = 1 ;
2001-04-20 00:12:10 +02:00
return 0 ;
} /* dbConnect */
static void dbDisconnect ( char * host )
{
if ( verbose )
fprintf ( stderr , " # Disconnecting from %s... \n " , host ? host : " localhost " ) ;
mysql_close ( sock ) ;
} /* dbDisconnect */
static void DBerror ( MYSQL * mysql , const char * when )
{
DBUG_ENTER ( " DBerror " ) ;
my_printf_error ( 0 , " Got error: %d: %s %s " , MYF ( 0 ) ,
mysql_errno ( mysql ) , mysql_error ( mysql ) , when ) ;
safe_exit ( EX_MYSQLERR ) ;
DBUG_VOID_RETURN ;
} /* DBerror */
static void safe_exit ( int error )
{
if ( ! first_error )
first_error = error ;
if ( ignore_errors )
return ;
if ( sock )
mysql_close ( sock ) ;
exit ( error ) ;
}
int main ( int argc , char * * argv )
{
MY_INIT ( argv [ 0 ] ) ;
/*
* * Check out the args
*/
if ( get_options ( & argc , & argv ) )
{
2007-08-01 21:59:05 +02:00
my_end ( my_end_arg ) ;
2001-04-20 00:12:10 +02:00
exit ( EX_USAGE ) ;
}
if ( dbConnect ( current_host , current_user , opt_password ) )
exit ( EX_MYSQLERR ) ;
2009-09-28 08:24:19 +02:00
if ( ! opt_write_binlog )
{
if ( disable_binlog ( ) ) {
first_error = 1 ;
goto end ;
}
}
2002-04-28 23:22:37 +02:00
if ( opt_auto_repair & &
2011-03-08 09:41:57 +01:00
( my_init_dynamic_array ( & tables4repair , sizeof ( char ) * ( NAME_LEN * 2 + 2 ) , 16 , 64 ) | |
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
my_init_dynamic_array ( & tables4rebuild , sizeof ( char ) * ( NAME_LEN * 2 + 2 ) , 16 , 64 ) | |
my_init_dynamic_array ( & alter_table_cmds , MAX_ALTER_STR_SIZE , 0 , 1 ) ) )
2001-04-23 22:29:53 +02:00
{
first_error = 1 ;
goto end ;
}
2001-04-20 00:12:10 +02:00
if ( opt_alldbs )
process_all_databases ( ) ;
/* Only one database and selected table(s) */
else if ( argc > 1 & & ! opt_databases )
process_selected_tables ( * argv , ( argv + 1 ) , ( argc - 1 ) ) ;
/* One or more databases, all tables */
else
process_databases ( argv ) ;
2001-04-23 22:29:53 +02:00
if ( opt_auto_repair )
{
uint i ;
2011-03-08 09:41:57 +01:00
if ( ! opt_silent & & ( tables4repair . elements | | tables4rebuild . elements ) )
2001-04-23 22:29:53 +02:00
puts ( " \n Repairing tables " ) ;
what_to_do = DO_REPAIR ;
for ( i = 0 ; i < tables4repair . elements ; i + + )
{
char * name = ( char * ) dynamic_array_ptr ( & tables4repair , i ) ;
2007-10-30 09:51:57 +01:00
handle_request_for_tables ( name , fixed_name_length ( name ) ) ;
2001-04-23 22:29:53 +02:00
}
2011-03-08 09:41:57 +01:00
for ( i = 0 ; i < tables4rebuild . elements ; i + + )
rebuild_table ( ( char * ) dynamic_array_ptr ( & tables4rebuild , i ) ) ;
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
for ( i = 0 ; i < alter_table_cmds . elements ; i + + )
run_query ( ( char * ) dynamic_array_ptr ( & alter_table_cmds , i ) ) ;
2001-04-23 22:29:53 +02:00
}
end :
2001-04-20 00:12:10 +02:00
dbDisconnect ( current_host ) ;
2001-04-23 22:29:53 +02:00
if ( opt_auto_repair )
2011-03-08 09:41:57 +01:00
{
2001-04-23 22:29:53 +02:00
delete_dynamic ( & tables4repair ) ;
2011-03-08 09:41:57 +01:00
delete_dynamic ( & tables4rebuild ) ;
}
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
my_free ( opt_password ) ;
2002-11-14 20:16:30 +01:00
# ifdef HAVE_SMEM
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
my_free ( shared_memory_base_name ) ;
2002-11-14 20:16:30 +01:00
# endif
2007-08-01 21:59:05 +02:00
my_end ( my_end_arg ) ;
2001-04-23 22:29:53 +02:00
return ( first_error ! = 0 ) ;
2001-04-20 00:12:10 +02:00
} /* main */