2014-05-07 22:36:25 +02:00
|
|
|
/* Copyright (c) 2006, 2014, Oracle and/or its affiliates.
|
2017-03-01 08:27:39 +02:00
|
|
|
Copyright (c) 2011, 2017, MariaDB Corporation.
|
2010-03-31 16:05:33 +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 21:29:06 +03:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
#ifndef SQL_TABLE_INCLUDED
|
|
|
|
#define SQL_TABLE_INCLUDED
|
|
|
|
|
2017-06-18 06:42:16 +03:00
|
|
|
#include <my_sys.h> // pthread_mutex_t
|
2014-02-25 16:04:35 +01:00
|
|
|
#include "m_string.h" // LEX_CUSTRING
|
2022-05-17 12:52:23 +04:00
|
|
|
#include "lex_charset.h"
|
2023-04-26 15:27:01 +04:00
|
|
|
#include "lex_ident.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
|
2021-09-12 19:06:18 +02:00
|
|
|
#define ERROR_INJECT(code) \
|
|
|
|
((DBUG_IF("crash_" code) && (DBUG_SUICIDE(), 0)) || \
|
|
|
|
(DBUG_IF("fail_" code) && (my_error(ER_UNKNOWN_ERROR, MYF(0)), 1)))
|
2021-09-09 11:58:46 +03:00
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
class Alter_info;
|
2013-06-15 18:32:08 +03:00
|
|
|
class Alter_table_ctx;
|
2015-11-25 11:22:10 +04:00
|
|
|
class Column_definition;
|
2010-03-31 16:05:33 +02:00
|
|
|
class Create_field;
|
2010-04-12 17:17:37 +04:00
|
|
|
struct TABLE_LIST;
|
2010-03-31 16:05:33 +02:00
|
|
|
class THD;
|
|
|
|
struct TABLE;
|
|
|
|
struct handlerton;
|
2013-04-09 16:07:17 +02:00
|
|
|
class handler;
|
2019-12-30 13:56:19 +02:00
|
|
|
class String;
|
2010-03-31 16:05:33 +02:00
|
|
|
typedef struct st_ha_check_opt HA_CHECK_OPT;
|
2013-04-07 15:35:39 +02:00
|
|
|
struct HA_CREATE_INFO;
|
2014-12-08 10:56:08 +04:00
|
|
|
struct Table_specification_st;
|
2010-08-16 14:53:30 +02:00
|
|
|
typedef struct st_key KEY;
|
2010-03-31 16:05:33 +02:00
|
|
|
typedef struct st_key_cache KEY_CACHE;
|
|
|
|
typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE;
|
|
|
|
typedef struct st_order ORDER;
|
2020-12-20 17:44:11 +02:00
|
|
|
typedef struct st_ddl_log_state DDL_LOG_STATE;
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
enum enum_explain_filename_mode
|
|
|
|
{
|
|
|
|
EXPLAIN_ALL_VERBOSE= 0,
|
|
|
|
EXPLAIN_PARTITIONS_VERBOSE,
|
|
|
|
EXPLAIN_PARTITIONS_AS_COMMENT
|
|
|
|
};
|
|
|
|
|
2014-06-25 18:06:28 +05:30
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
/* depends on errmsg.txt Database `db`, Table `t` ... */
|
|
|
|
#define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63
|
|
|
|
|
|
|
|
#define WFRM_WRITE_SHADOW 1
|
|
|
|
#define WFRM_INSTALL_SHADOW 2
|
2014-08-21 18:11:46 +02:00
|
|
|
#define WFRM_KEEP_SHARE 4
|
2021-09-09 11:58:46 +03:00
|
|
|
#define WFRM_WRITE_CONVERTED_TO 8
|
|
|
|
#define WFRM_BACKUP_ORIGINAL 16
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
/* Flags for conversion functions. */
|
2013-06-15 18:32:08 +03:00
|
|
|
static const uint FN_FROM_IS_TMP= 1 << 0;
|
|
|
|
static const uint FN_TO_IS_TMP= 1 << 1;
|
|
|
|
static const uint FN_IS_TMP= FN_FROM_IS_TMP | FN_TO_IS_TMP;
|
|
|
|
static const uint NO_FRM_RENAME= 1 << 2;
|
|
|
|
static const uint FRM_ONLY= 1 << 3;
|
|
|
|
/** Don't remove table in engine. Remove only .FRM and maybe .PAR files. */
|
|
|
|
static const uint NO_HA_TABLE= 1 << 4;
|
|
|
|
/** Don't resolve MySQL's fake "foo.sym" symbolic directory names. */
|
|
|
|
static const uint SKIP_SYMDIR_ACCESS= 1 << 5;
|
2013-06-12 09:35:33 +02:00
|
|
|
/** Don't check foreign key constraints while renaming table */
|
2013-09-21 10:14:42 +02:00
|
|
|
static const uint NO_FK_CHECKS= 1 << 6;
|
2019-05-08 23:39:29 +03:00
|
|
|
/* Don't delete .par table in quick_rm_table() */
|
|
|
|
static const uint NO_PAR_TABLE= 1 << 7;
|
2010-03-31 16:05:33 +02:00
|
|
|
|
2018-02-06 12:55:58 +00:00
|
|
|
uint filename_to_tablename(const char *from, char *to, size_t to_length,
|
2013-11-04 13:40:20 +01:00
|
|
|
bool stay_quiet = false);
|
2018-02-06 12:55:58 +00:00
|
|
|
uint tablename_to_filename(const char *from, char *to, size_t to_length);
|
|
|
|
uint check_n_cut_mysql50_prefix(const char *from, char *to, size_t to_length);
|
2010-05-24 00:41:18 +04:00
|
|
|
bool check_mysql50_prefix(const char *name);
|
2010-03-31 16:05:33 +02:00
|
|
|
uint build_table_filename(char *buff, size_t bufflen, const char *db,
|
|
|
|
const char *table, const char *ext, uint flags);
|
|
|
|
uint build_table_shadow_filename(char *buff, size_t bufflen,
|
2021-09-09 11:58:46 +03:00
|
|
|
ALTER_PARTITION_PARAM_TYPE *lpt,
|
|
|
|
bool backup= false);
|
2020-10-15 02:25:57 +03:00
|
|
|
void build_lower_case_table_filename(char *buff, size_t bufflen,
|
|
|
|
const LEX_CSTRING *db,
|
|
|
|
const LEX_CSTRING *table,
|
|
|
|
uint flags);
|
2013-06-15 18:32:08 +03:00
|
|
|
uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen);
|
2019-12-30 13:56:19 +02:00
|
|
|
bool add_keyword_to_query(THD *thd, String *result, const LEX_CSTRING *keyword,
|
|
|
|
const LEX_CSTRING *add);
|
2013-04-09 16:18:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
mysql_create_table_no_lock can be called in one of the following
|
|
|
|
mutually exclusive situations:
|
|
|
|
|
|
|
|
- Just a normal ordinary CREATE TABLE statement that explicitly
|
|
|
|
defines the table structure.
|
|
|
|
|
|
|
|
- CREATE TABLE ... SELECT. It is special, because only in this case,
|
|
|
|
the list of fields is allowed to have duplicates, as long as one of the
|
|
|
|
duplicates comes from the select list, and the other doesn't. For
|
|
|
|
example in
|
|
|
|
|
|
|
|
CREATE TABLE t1 (a int(5) NOT NUL) SELECT b+10 as a FROM t2;
|
|
|
|
|
|
|
|
the list in alter_info->create_list will have two fields `a`.
|
|
|
|
|
|
|
|
- ALTER TABLE, that creates a temporary table #sql-xxx, which will be later
|
|
|
|
renamed to replace the original table.
|
|
|
|
|
2013-04-09 16:19:01 +02:00
|
|
|
- ALTER TABLE as above, but which only modifies the frm file, it only
|
|
|
|
creates an frm file for the #sql-xxx, the table in the engine is not
|
|
|
|
created.
|
|
|
|
|
2013-04-09 16:19:14 +02:00
|
|
|
- Assisted discovery, CREATE TABLE statement without the table structure.
|
|
|
|
|
2013-04-09 16:18:44 +02:00
|
|
|
These situations are distinguished by the following "create table mode"
|
|
|
|
values, where a CREATE ... SELECT is denoted by any non-negative number
|
|
|
|
(which should be the number of fields in the SELECT ... part), and other
|
|
|
|
cases use constants as defined below.
|
|
|
|
*/
|
|
|
|
#define C_CREATE_SELECT(X) ((X) > 0 ? (X) : 0)
|
|
|
|
#define C_ORDINARY_CREATE 0
|
|
|
|
#define C_ALTER_TABLE -1
|
2013-04-09 16:19:01 +02:00
|
|
|
#define C_ALTER_TABLE_FRM_ONLY -2
|
2013-04-09 16:19:14 +02:00
|
|
|
#define C_ASSISTED_DISCOVERY -3
|
2013-04-09 16:18:44 +02:00
|
|
|
|
2021-01-17 16:06:43 +02:00
|
|
|
int mysql_create_table_no_lock(THD *thd,
|
|
|
|
DDL_LOG_STATE *ddl_log_state,
|
|
|
|
DDL_LOG_STATE *ddl_log_state_rm,
|
2014-12-08 10:56:08 +04:00
|
|
|
Table_specification_st *create_info,
|
2014-01-29 15:37:17 +02:00
|
|
|
Alter_info *alter_info, bool *is_trans,
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 23:36:56 +02:00
|
|
|
int create_table_mode, TABLE_LIST *table);
|
2013-04-09 16:18:44 +02:00
|
|
|
|
2023-06-29 16:24:50 +02:00
|
|
|
handler *mysql_create_frm_image(THD *thd, HA_CREATE_INFO *create_info,
|
|
|
|
Alter_info *alter_info, int create_table_mode,
|
|
|
|
KEY **key_info, uint *key_count,
|
2013-07-21 16:39:19 +02:00
|
|
|
LEX_CUSTRING *frm);
|
|
|
|
|
2023-06-29 16:24:50 +02:00
|
|
|
int mysql_discard_or_import_tablespace(THD *thd, TABLE_LIST *table_list,
|
2013-06-15 18:32:08 +03:00
|
|
|
bool discard);
|
2013-07-21 16:39:19 +02:00
|
|
|
|
2010-08-16 14:53:30 +02:00
|
|
|
bool mysql_prepare_alter_table(THD *thd, TABLE *table,
|
2022-05-17 12:52:23 +04:00
|
|
|
Table_specification_st *create_info,
|
2013-06-15 18:32:08 +03:00
|
|
|
Alter_info *alter_info,
|
|
|
|
Alter_table_ctx *alter_ctx);
|
2010-08-20 19:15:48 +02:00
|
|
|
bool mysql_trans_prepare_alter_copy_data(THD *thd);
|
|
|
|
bool mysql_trans_commit_alter_copy_data(THD *thd);
|
2019-12-30 13:34:28 +02:00
|
|
|
bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
|
|
|
|
const LEX_CSTRING *new_name,
|
2022-05-17 12:52:23 +04:00
|
|
|
Table_specification_st *create_info,
|
2010-03-31 16:05:33 +02:00
|
|
|
TABLE_LIST *table_list,
|
2022-10-28 13:43:51 +04:00
|
|
|
class Recreate_info *recreate_info,
|
2010-03-31 16:05:33 +02:00
|
|
|
Alter_info *alter_info,
|
2019-12-30 13:34:28 +02:00
|
|
|
uint order_num, ORDER *order, bool ignore,
|
|
|
|
bool if_exists);
|
2010-08-16 14:53:30 +02:00
|
|
|
bool mysql_compare_tables(TABLE *table,
|
|
|
|
Alter_info *alter_info,
|
|
|
|
HA_CREATE_INFO *create_info,
|
2013-06-15 18:32:08 +03:00
|
|
|
bool *metadata_equal);
|
2022-10-28 13:43:51 +04:00
|
|
|
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list,
|
MDEV-33449 improving repair of tables
This task is to ensure we have a clear definition and rules of how to
repair or optimize a table.
The rules are:
- REPAIR should be used with tables that are crashed and are
unreadable (hardware issues with not readable blocks, blocks with
'unexpected data' etc)
- OPTIMIZE table should be used to optimize the storage layout for the
table (recover space for delete rows and optimize the index
structure.
- ALTER TABLE table_name FORCE should be used to rebuild the .frm file
(the table definition) and the table (with the original table row
format). If the table is from and older MariaDB/MySQL release with a
different storage format, it will convert the data to the new
format. ALTER TABLE ... FORCE is used as part of mariadb-upgrade
Here follows some more background:
The 3 ways to repair a table are:
1) ALTER TABLE table_name FORCE" (not other options).
As an alias we allow: "ALTER TABLE table_name ENGINE=original_engine"
2) "REPAIR TABLE" (without FORCE)
3) "OPTIMIZE TABLE"
All of the above commands will optimize row space usage (which means that
space will be needed to hold a temporary copy of the table) and
re-generate all indexes. They will also try to replicate the original
table definition as exact as possible.
For ALTER TABLE and "REPAIR TABLE without FORCE", the following will hold:
If the table is from an older MariaDB version and data conversion is
needed (for example for old type HASH columns, MySQL JSON type or new
TIMESTAMP format) "ALTER TABLE table_name FORCE, algorithm=COPY" will be
used.
The differences between the algorithms are
1) Will use the fastest algorithm the engine supports to do a full repair
of the table (except if data conversions are is needed).
2) Will use the storage engine internal REPAIR facility (MyISAM, Aria).
If the engine does not support REPAIR then
"ALTER TABLE FORCE, ALGORITHM=COPY" will be used.
If there was data incompatibilities (which means that FORCE was used)
then there will be a warning after REPAIR that ALTER TABLE FORCE is
still needed.
The reason for this is that REPAIR may be able to go around data
errors (wrong incompatible data, crashed or unreadable sectors) that
ALTER TABLE cannot do.
3) Will use the storage engine internal OPTIMIZE. If engine does not
support optimize, then "ALTER TABLE FORCE" is used.
The above will ensure that ALTER TABLE FORCE is able to
correct almost any errors in the row or index data. In case of
corrupted blocks then REPAIR possible followed by ALTER TABLE is needed.
This is important as mariadb-upgrade executes ALTER TABLE table_name
FORCE for any table that must be re-created.
Bugs fixed with InnoDB tables when using ALTER TABLE FORCE:
- No error for INNODB_DEFAULT_ROW_FORMAT=COMPACT even if row length
would be too wide. (Independent of innodb_strict_mode).
- Tables using symlinks will be symlinked after any of the above commands
(Independent of the setting of --symbolic-links)
If one specifies an algorithm together with ALTER TABLE FORCE, things
will work as before (except if data conversion is required as then
the COPY algorithm is enforced).
ALTER TABLE .. OPTIMIZE ALL PARTITIONS will work as before.
Other things:
- FORCE argument added to REPAIR to allow one to first run internal
repair to fix damaged blocks and then follow it with ALTER TABLE.
- REPAIR will not update frm_version if ha_check_for_upgrade() finds
that table is still incompatible with current version. In this case the
REPAIR will end with an error.
- REPAIR for storage engines that does not have native repair, like InnoDB,
is now using ALTER TABLE FORCE.
- REPAIR csv-table USE_FRM now works.
- It did not work before as CSV tables had extension list in wrong
order.
- Default error messages length for %M increased from 128 to 256 to not
cut information from REPAIR.
- Documented HA_ADMIN_XX variables related to repair.
- Added HA_ADMIN_NEEDS_DATA_CONVERSION to signal that we have to
do data conversions when converting the table (and thus ALTER TABLE
copy algorithm is needed).
- Fixed typo in error message (caused test changes).
2024-01-29 11:52:44 +02:00
|
|
|
class Recreate_info *recreate_info,
|
|
|
|
bool table_copy);
|
2018-01-07 18:03:44 +02:00
|
|
|
bool mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db,
|
|
|
|
const LEX_CSTRING *old_name, const LEX_CSTRING *new_db,
|
2023-04-26 15:27:01 +04:00
|
|
|
const LEX_CSTRING *new_name, const LEX_CUSTRING *id,
|
2021-03-30 17:06:55 +03:00
|
|
|
uint flags);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool mysql_backup_table(THD* thd, TABLE_LIST* table_list);
|
|
|
|
bool mysql_restore_table(THD* thd, TABLE_LIST* table_list);
|
|
|
|
|
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 14:52:19 +07:00
|
|
|
template<typename T> class List;
|
|
|
|
void fill_checksum_table_metadata_fields(THD *thd, List<Item> *fields);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
|
|
|
|
HA_CHECK_OPT* check_opt);
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 23:36:56 +02:00
|
|
|
bool mysql_rm_table(THD *thd,TABLE_LIST *tables, bool if_exists,
|
2019-12-30 13:56:19 +02:00
|
|
|
bool drop_temporary, bool drop_sequence,
|
|
|
|
bool dont_log_query);
|
2020-12-20 17:44:11 +02:00
|
|
|
int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables,
|
|
|
|
const LEX_CSTRING *db,
|
|
|
|
DDL_LOG_STATE *ddl_log_state,
|
|
|
|
bool if_exists,
|
2010-11-16 11:00:12 +01:00
|
|
|
bool drop_temporary, bool drop_view,
|
MDEV-10139 Support for SEQUENCE objects
Working features:
CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE ]
[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]
ENGINE=xxx COMMENT=".."
SELECT NEXT VALUE FOR sequence_name;
SELECT NEXTVAL(sequence_name);
SELECT PREVIOUS VALUE FOR sequence_name;
SELECT LASTVAL(sequence_name);
SHOW CREATE SEQUENCE sequence_name;
SHOW CREATE TABLE sequence_name;
CREATE TABLE sequence-structure ... SEQUENCE=1
ALTER TABLE sequence RENAME TO sequence2;
RENAME TABLE sequence TO sequence2;
DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names
Missing features
- SETVAL(value,sequence_name), to be used with replication.
- Check replication, including checking that sequence tables are marked
not transactional.
- Check that a commit happens for NEXT VALUE that changes table data (may
already work)
- ALTER SEQUENCE. ANSI SQL version of setval.
- Share identical sequence entries to not add things twice to table list.
- testing insert/delete/update/truncate/load data
- Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence)
- Write documentation for NEXT VALUE / PREVIOUS_VALUE
- NEXTVAL in DEFAULT
- Ensure that NEXTVAL in DEFAULT uses database from base table
- Two NEXTVAL for same row should give same answer.
- Oracle syntax sequence_table.nextval, without any FOR or FROM.
- Sequence tables are treated as 'not read constant tables' by SELECT; Would
be better if we would have a separate list for sequence tables so that
select doesn't know about them, except if refereed to with FROM.
Other things done:
- Improved output for safemalloc backtrack
- frm_type_enum changed to Table_type
- Removed lex->is_view and replaced with lex->table_type. This allows
use to more easy check if item is view, sequence or table.
- Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers
that want's to support sequences
- Added handler calls:
- engine_name(), to simplify getting engine name for partition and sequences
- update_first_row(), to be able to do efficient sequence implementations.
- Made binlog_log_row() global to be able to call it from ha_sequence.cc
- Added handler variable: row_already_logged, to be able to flag that the
changed row is already logging to replication log.
- Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify
deny_updates_if_read_only_option()
- Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy
- Moved code for add_table_options() out from sql_show.cc::show_create_table()
- Added String::append_longlong() and used it in sql_show.cc to simplify code.
- Added extra option to dd_frm_type() and ha_table_exists to indicate if
the table is a sequence. Needed by DROP SQUENCE to not drop a table.
2017-03-25 23:36:56 +02:00
|
|
|
bool drop_sequence,
|
2019-12-30 13:34:28 +02:00
|
|
|
bool dont_log_query, bool dont_free_locks);
|
2018-01-07 18:03:44 +02:00
|
|
|
bool log_drop_table(THD *thd, const LEX_CSTRING *db_name,
|
2021-03-30 17:06:55 +03:00
|
|
|
const LEX_CSTRING *table_name, const LEX_CSTRING *handler,
|
|
|
|
bool partitioned, const LEX_CUSTRING *id,
|
|
|
|
bool temporary_table);
|
2018-01-07 18:03:44 +02:00
|
|
|
bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db,
|
|
|
|
const LEX_CSTRING *table_name, uint flags,
|
2016-07-18 11:50:08 +04:00
|
|
|
const char *table_path=0);
|
2010-03-31 16:05:33 +02:00
|
|
|
void close_cached_table(THD *thd, TABLE *table);
|
2015-11-25 11:22:10 +04:00
|
|
|
void sp_prepare_create_field(THD *thd, Column_definition *sql_field);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
|
|
|
|
int write_bin_log(THD *thd, bool clear_error,
|
|
|
|
char const *query, ulong query_length,
|
|
|
|
bool is_trans= FALSE);
|
2020-03-30 14:50:03 +03:00
|
|
|
int write_bin_log_with_if_exists(THD *thd, bool clear_error,
|
MDEV-11675 Lag Free Alter On Slave
This commit implements two phase binloggable ALTER.
When a new
@@session.binlog_alter_two_phase = YES
ALTER query gets logged in two parts, the START ALTER and the COMMIT
or ROLLBACK ALTER. START Alter is written in binlog as soon as
necessary locks have been acquired for the table. The timing is
such that any concurrent DML:s that update the same table are either
committed, thus logged into binary log having done work on the old
version of the table, or will be queued for execution on its new
version.
The "COMPLETE" COMMIT or ROLLBACK ALTER are written at the very point
of a normal "single-piece" ALTER that is after the most of
the query work is done. When its result is positive COMMIT ALTER is
written, otherwise ROLLBACK ALTER is written with specific error
happened after START ALTER phase.
Replication of two-phase binloggable ALTER is
cross-version safe. Specifically the OLD slave merely does not
recognized the start alter part, still being able to process and
memorize its gtid.
Two phase logged ALTER is read from binlog by mysqlbinlog to produce
BINLOG 'string', where 'string' contains base64 encoded
Query_log_event containing either the start part of ALTER, or a
completion part. The Query details can be displayed with `-v` flag,
similarly to ROW format events. Notice, mysqlbinlog output containing
parts of two-phase binloggable ALTER is processable correctly only by
binlog_alter_two_phase server.
@@log_warnings > 2 can reveal details of binlogging and slave side
processing of the ALTER parts.
The current commit also carries fixes to the following list of
reported bugs:
MDEV-27511, MDEV-27471, MDEV-27349, MDEV-27628, MDEV-27528.
Thanks to all people involved into early discussion of the feature
including Kristian Nielsen, those who helped to design, implement and
test: Sergei Golubchik, Andrei Elkin who took the burden of the
implemenation completion, Sujatha Sivakumar, Brandon
Nesterenko, Alice Sherepa, Ramesh Sivaraman, Jan Lindstrom.
2021-01-29 11:59:14 +00:00
|
|
|
bool is_trans, bool add_if_exists,
|
|
|
|
bool commit_alter= false);
|
2010-03-31 16:05:33 +02:00
|
|
|
|
2012-10-17 15:43:56 +03:00
|
|
|
void promote_first_timestamp_column(List<Create_field> *column_definitions);
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
/*
|
|
|
|
These prototypes where under INNODB_COMPATIBILITY_HOOKS.
|
|
|
|
*/
|
|
|
|
uint explain_filename(THD* thd, const char *from, char *to, uint to_length,
|
|
|
|
enum_explain_filename_mode explain_mode);
|
|
|
|
|
|
|
|
|
2023-04-26 15:27:01 +04:00
|
|
|
extern MYSQL_PLUGIN_IMPORT const Lex_ident_column primary_key_name;
|
2010-03-31 16:05:33 +02:00
|
|
|
|
2015-10-01 20:36:25 -04:00
|
|
|
bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *);
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#endif /* SQL_TABLE_INCLUDED */
|