2014-01-06 06:22:35 +01:00
|
|
|
/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
2010-08-16 14:53:30 +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
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
#ifndef SQL_TABLE_MAINTENANCE_H
|
|
|
|
#define SQL_TABLE_MAINTENANCE_H
|
|
|
|
|
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
|
|
|
/* Must be able to hold ALTER TABLE t PARTITION BY ... KEY ALGORITHM = 1 ... */
|
2015-09-01 11:47:06 +02:00
|
|
|
#define SQL_ADMIN_MSG_TEXT_SIZE (128 * 1024)
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
|
2017-04-23 18:39:57 +02:00
|
|
|
const LEX_CSTRING *key_cache_name);
|
2010-08-16 14:53:30 +02:00
|
|
|
bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
|
|
|
|
int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
|
|
|
|
KEY_CACHE *dst_cache);
|
MDEV-16708: Unsupported commands for prepared statements
Withing this task the following changes were made:
- Added sending of metadata info in prepare phase for the admin related
command (check table, checksum table, repair, optimize, analyze).
- Refactored implmentation of HELP command to support its execution in
PS mode
- Added support for execution of LOAD INTO and XA- related statements
in PS mode
- Modified mysqltest.cc to run statements in PS mode unconditionally
in case the option --ps-protocol is set. Formerly, only those statements
were executed using PS protocol that matched the hard-coded regular expression
- Fixed the following issues:
The statement
explain select (select 2)
executed in regular and PS mode produces different results:
MariaDB [test]> prepare stmt from "explain select (select 2)";
Query OK, 0 rows affected (0,000 sec)
Statement prepared
MariaDB [test]> execute stmt;
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | PRIMARY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
| 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
2 rows in set (0,000 sec)
MariaDB [test]> explain select (select 2);
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0,000 sec)
In case the statement
CREATE TABLE t1 SELECT * FROM (SELECT 1 AS a, (SELECT a+0)) a
is run in PS mode it fails with the error
ERROR 1054 (42S22): Unknown column 'a' in 'field list'.
- Uniform handling of read-only variables both in case the SET var=val
statement is executed as regular or prepared statememt.
- Fixed assertion firing on handling LOAD DATA statement for temporary tables
- Relaxed assert condition in the function lex_end_stage1() by adding
the commands SQLCOM_ALTER_EVENT, SQLCOM_CREATE_PACKAGE,
SQLCOM_CREATE_PACKAGE_BODY to a list of supported command
- Removed raising of the error ER_UNSUPPORTED_PS in the function
check_prepared_statement() for the ALTER VIEW command
- Added initialization of the data memember st_select_lex_unit::last_procedure
(assign NULL value) in the constructor
Without this change the test case main.ctype_utf8 fails with the following
report in case it is run with the optoin --ps-protocol.
mysqltest: At line 2278: query 'VALUES (_latin1 0xDF) UNION VALUES(_utf8'a' COLLATE utf8_bin)' failed: 2013: Lost connection
- The following bug reports were fixed:
MDEV-24460: Multiple rows result set returned from stored
routine over prepared statement binary protocol is
handled incorrectly
CONC-519: mariadb client library doesn't handle server_status and
warnign_count fields received in the packet
COM_STMT_EXECUTE_RESPONSE.
Reasons for these bug reports have the same nature and caused by
missing loop iteration on results sent by server in response to
COM_STMT_EXECUTE packet.
Enclosing of statements for processing of COM_STMT_EXECUTE response
in the construct like
do
{
...
} while (!mysql_stmt_next_result());
fixes the above mentioned bug reports.
2021-04-22 09:52:19 +02:00
|
|
|
void fill_check_table_metadata_fields(THD *thd, List<Item>* fields);
|
2010-08-16 14:53:30 +02:00
|
|
|
/**
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_cmd_analyze_table represents the ANALYZE TABLE statement.
|
2010-08-16 14:53:30 +02:00
|
|
|
*/
|
2019-03-11 16:45:38 +01:00
|
|
|
class Sql_cmd_analyze_table : public Sql_cmd
|
2010-08-16 14:53:30 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor, used to represent a ANALYZE TABLE statement.
|
|
|
|
*/
|
2023-02-07 12:57:20 +01:00
|
|
|
Sql_cmd_analyze_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2023-02-07 12:57:20 +01:00
|
|
|
~Sql_cmd_analyze_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
bool execute(THD *thd);
|
2013-06-15 17:32:08 +02:00
|
|
|
|
|
|
|
virtual enum_sql_command sql_command_code() const
|
|
|
|
{
|
|
|
|
return SQLCOM_ANALYZE;
|
|
|
|
}
|
2010-08-16 14:53:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_cmd_check_table represents the CHECK TABLE statement.
|
2010-08-16 14:53:30 +02:00
|
|
|
*/
|
2019-03-11 16:45:38 +01:00
|
|
|
class Sql_cmd_check_table : public Sql_cmd
|
2010-08-16 14:53:30 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor, used to represent a CHECK TABLE statement.
|
|
|
|
*/
|
2023-02-07 12:57:20 +01:00
|
|
|
Sql_cmd_check_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2023-02-07 12:57:20 +01:00
|
|
|
~Sql_cmd_check_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
bool execute(THD *thd);
|
|
|
|
|
2013-06-15 17:32:08 +02:00
|
|
|
virtual enum_sql_command sql_command_code() const
|
|
|
|
{
|
|
|
|
return SQLCOM_CHECK;
|
|
|
|
}
|
|
|
|
};
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_cmd_optimize_table represents the OPTIMIZE TABLE statement.
|
2010-08-16 14:53:30 +02:00
|
|
|
*/
|
2019-03-11 16:45:38 +01:00
|
|
|
class Sql_cmd_optimize_table : public Sql_cmd
|
2010-08-16 14:53:30 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor, used to represent a OPTIMIZE TABLE statement.
|
|
|
|
*/
|
2023-02-07 12:57:20 +01:00
|
|
|
Sql_cmd_optimize_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2023-02-07 12:57:20 +01:00
|
|
|
~Sql_cmd_optimize_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
bool execute(THD *thd);
|
2013-06-15 17:32:08 +02:00
|
|
|
|
|
|
|
virtual enum_sql_command sql_command_code() const
|
|
|
|
{
|
|
|
|
return SQLCOM_OPTIMIZE;
|
|
|
|
}
|
2010-08-16 14:53:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_cmd_repair_table represents the REPAIR TABLE statement.
|
2010-08-16 14:53:30 +02:00
|
|
|
*/
|
2019-03-11 16:45:38 +01:00
|
|
|
class Sql_cmd_repair_table : public Sql_cmd
|
2010-08-16 14:53:30 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor, used to represent a REPAIR TABLE statement.
|
|
|
|
*/
|
2023-02-07 12:57:20 +01:00
|
|
|
Sql_cmd_repair_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
2023-02-07 12:57:20 +01:00
|
|
|
~Sql_cmd_repair_table() = default;
|
2010-08-16 14:53:30 +02:00
|
|
|
|
|
|
|
bool execute(THD *thd);
|
2013-06-15 17:32:08 +02:00
|
|
|
|
|
|
|
virtual enum_sql_command sql_command_code() const
|
|
|
|
{
|
|
|
|
return SQLCOM_REPAIR;
|
|
|
|
}
|
2010-08-16 14:53:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|