You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13564 lines
394 KiB

17 years ago
16 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
14 years ago
15 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
15 years ago
17 years ago
15 years ago
15 years ago
15 years ago
17 years ago
17 years ago
15 years ago
17 years ago
15 years ago
15 years ago
15 years ago
17 years ago
15 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
Added option "AND DISABLE CHECKPOINT" to "FLUSH TABLES WITH READ LOCK" This makes it possible to do safe multi volume snapshots as long as one snapshots the volume with the transaction logs last. include/mysql_com.h: Added REFRESH_CHECKPOINT mysql-test/r/flush.result: Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls mysql-test/t/flush.test: Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls sql/handler.cc: Added code to call checkpoint_state for all handlertons that supports it sql/handler.h: Added new checkpoint_state() handlerton call to temporarly disable checkpoints. sql/lex.h: Added CHECKPOINT keyword sql/sql_yacc.yy: Added support for FLUSH TABLES WITH READ LOCK AND DISABLE CHECKPOINT storage/maria/ha_maria.cc: Added handlerton call to disable checkpoints. storage/maria/ma_checkpoint.c: Don't do checkpoint if checkpoints are disabled. storage/maria/ma_static.c: Added maria_checkpoint_disabled storage/maria/maria_def.h: Added maria_checkpoint_disabled storage/xtradb/handler/ha_innodb.cc: Added handlerton call to disable checkpoints. storage/xtradb/include/log0log.h: Added option to log_checkpoint() to allow one to ignore not critical checkpoints during the time checkpoints are disabled. storage/xtradb/log/log0log.c: Added code to allow one to disable checkpoints during a FLUSH TABLES ... DISABLE CHECKPOINT This was done by adding a new argument to log_checkpoint() which tells us when the checkpoint is called by srv_master_thread (which are safe to ignore) storage/xtradb/srv/srv0srv.c: Tell log_checkpoint() that checkpoints from srv_master_thread() are safe to ignore (will just delay recovery time a bit).
15 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
17 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
17 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
Fix for lp:711565 "Index Condition Pushdown can make a thread hold MyISAM locks as well as be unKILLable for long time" - In Maria/MyISAM: Release/re-acquire locks to give queries that wait on them a chance to make progress - In Maria/MyISAM: Change from numeric constants to ICP_RES values. - In Maria: Do check index condition in maria_rprev() (was lost in the merge/backport?) - In Maria/MyISAM/XtraDB: Check if the query was killed, and return immediately if it was. Added new storage engine error: HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted Authors: Sergey Petrunia & Monty include/my_base.h: Added HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted include/my_handler.h: Added comment mysql-test/r/myisam_icp.result: Updated test mysql-test/t/myisam_icp.test: Drop used tables at start of test Added test case that can help with manual testing of killing index condition pushdown query. mysys/my_handler_errors.h: Text for new storage engine error sql/handler.cc: If engine got HA_ERR_ABORTED_BY_USER, send kill message. sql/multi_range_read.cc: Return error code storage/maria/ha_maria.cc: Added ma_killed_in_mariadb() to detect kill. Ensure that file->external_ref points to TABLE object. storage/maria/ma_extra.c: Dummy test-if-killed for standalone storage/maria/ma_key.c: If ma_check_index_cond() fails, set my_errno and info->cur_row.lastpos storage/maria/ma_rkey.c: Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was storage/maria/ma_rnext.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rprev.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) and ma_check_index_cond() storage/maria/ma_search.c: Give error message if we find a wrong key storage/maria/ma_static.c: Added pointer to test-if-killed function storage/maria/maria_def.h: New prototypes storage/myisam/ha_myisam.cc: Added mi_killed_in_mariadb() Ensure that file->external_ref points to TABLE object. storage/myisam/mi_extra.c: Dummy test-if-killed for standalone storage/myisam/mi_key.c: If ma_check_index_cond() fails, set my_errno and info->lastpos storage/myisam/mi_rkey.c: Ensure that info->lastpos= HA_OFFSET_ERROR in case of error Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was Reorder code to do less things in case of error. Added missing fast_mi_writeinfo() storage/myisam/mi_rnext.c: Check if the query was killed, and return immediately if it was Simplify old ICP code Added missing fast_ma_writeinfo(info) storage/myisam/mi_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_mi_writeinfo(info) storage/myisam/mi_rprev.c: Check if the query was killed, and return immediately if it was Simplify error handling of ICP Added missing fast_mi_writeinfo(info) storage/myisam/mi_search.c: Give error message if we find a wrong key storage/myisam/mi_static.c: Added pointer to test-if-killed function storage/myisam/myisamdef.h: New prototypes storage/xtradb/handler/ha_innodb.cc: Added DB_SEARCH_ABORTED_BY_USER and ha_innobase::is_thd_killed() Check if the query was killed, and return immediately if it was storage/xtradb/handler/ha_innodb.h: Added prototype storage/xtradb/include/db0err.h: Added DB_SEARCH_ABORTED_BY_USER storage/xtradb/include/row0mysql.h: Added possible ICP errors storage/xtradb/row/row0sel.c: Use ICP errors instead of constants. Detect if killed and return B_SEARCH_ABORTED_BY_USER
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
Fix for MDEV-533: Confusing error code when doing auto-increment insert for out-of-range values create table t1 (a smallint primary key auto_increment); insert into t1 values(32767); insert into t1 values(NULL); ERROR 1062 (23000): Duplicate entry '32767' for key 'PRIMARY Now on always gets error HA_ERR_AUTOINC_RANGE=167 "Out of range value for column", independent of store engine, SQL Mode or number of inserted rows. This is an unique error that is easier to test for in replication. Another bug fix is that we now get an error when trying to insert a too big auto-generated value, even in non-strict mode. Before one get insted the max column value inserted. This patch also fixes some issues with inserting negative numbers in an auto-increment column. Fixed the ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. Added SQLSTATE errors for handler errors Smaller bug fixes: * Added warnings for duplicate key errors when using INSERT IGNORE * Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" * Allow one to see how cmake is called by using --just-print --just-configure BUILD/FINISH.sh: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. cmake/configure.pl: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. include/CMakeLists.txt: Added handler_state.h include/handler_state.h: SQLSTATE for handler error messages. Required for HA_ERR_AUTOINC_ERANGE, but solves also some other cases. mysql-test/extra/binlog_tests/binlog.test: Fixed old wrong behaviour Added more tests mysql-test/extra/binlog_tests/binlog_insert_delayed.test: Reset binary log to only print what's necessary in show_binlog_events mysql-test/extra/rpl_tests/rpl_auto_increment.test: Update to new error codes mysql-test/extra/rpl_tests/rpl_insert_delayed.test: Ignore warnings as this depends on how the test is run mysql-test/include/strict_autoinc.inc: On now gets an error on overflow mysql-test/r/auto_increment.result: Update results after fixing error message mysql-test/r/auto_increment_ranges_innodb.result: Test new behaviour mysql-test/r/auto_increment_ranges_myisam.result: Test new behaviour mysql-test/r/commit_1innodb.result: Added warnings for duplicate key error mysql-test/r/create.result: Added warnings for duplicate key error mysql-test/r/insert.result: Added warnings for duplicate key error mysql-test/r/insert_select.result: Added warnings for duplicate key error mysql-test/r/insert_update.result: Added warnings for duplicate key error mysql-test/r/mix2_myisam.result: Added warnings for duplicate key error mysql-test/r/myisam_mrr.result: Added warnings for duplicate key error mysql-test/r/null_key.result: Added warnings for duplicate key error mysql-test/r/replace.result: Update to new error codes mysql-test/r/strict_autoinc_1myisam.result: Update to new error codes mysql-test/r/strict_autoinc_2innodb.result: Update to new error codes mysql-test/r/strict_autoinc_3heap.result: Update to new error codes mysql-test/r/trigger.result: Added warnings for duplicate key error mysql-test/r/xtradb_mrr.result: Added warnings for duplicate key error mysql-test/suite/binlog/r/binlog_innodb_row.result: Updated result mysql-test/suite/binlog/r/binlog_row_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: Updated result mysql-test/suite/binlog/r/binlog_stm_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_unsafe.result: Updated result mysql-test/suite/innodb/r/innodb-autoinc.result: Update to new error codes mysql-test/suite/innodb/r/innodb-lock.result: Updated results mysql-test/suite/innodb/r/innodb.result: Updated results mysql-test/suite/innodb/r/innodb_bug56947.result: Updated results mysql-test/suite/innodb/r/innodb_mysql.result: Updated results mysql-test/suite/innodb/t/innodb-autoinc.test: Update to new error codes mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/maria/mrr.result: Updated result mysql-test/suite/optimizer_unfixed_bugs/r/bug43617.result: Updated result mysql-test/suite/rpl/r/rpl_auto_increment.result: Update to new error codes mysql-test/suite/rpl/r/rpl_insert_delayed,stmt.rdiff: Updated results mysql-test/suite/rpl/r/rpl_loaddatalocal.result: Updated results mysql-test/t/auto_increment.test: Update to new error codes mysql-test/t/auto_increment_ranges.inc: Test new behaviour mysql-test/t/auto_increment_ranges_innodb.test: Test new behaviour mysql-test/t/auto_increment_ranges_myisam.test: Test new behaviour mysql-test/t/replace.test: Update to new error codes mysys/my_getopt.c: Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" sql/handler.cc: Ignore negative values for signed auto-increment columns Always give an error if we get an overflow for an auto-increment-column (instead of inserting the max value) Ensure that the row number is correct for the out-of-range-value error message. ****** Fixed wrong printing of column namn for "Out of range value" errors Fixed that INSERT_ID is correctly replicated also for out-of-range autoincrement values Fixed that print_keydup_error() can also be used to generate warnings ****** Return HA_ERR_AUTOINC_ERANGE (167) instead of ER_WARN_DATA_OUT_OF_RANGE for auto-increment overflow sql/handler.h: Allow INSERT IGNORE to continue also after out-of-range inserts. Fixed that print_keydup_error() can also be used to generate warnings sql/log_event.cc: Added DBUG_PRINT Fixed the ER_AUTOINC_READ_FAILED, ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. sql/sql_insert.cc: Add warnings for duplicate key errors when using INSERT IGNORE sql/sql_state.c: Added handler errors sql/sql_table.cc: Update call to print_keydup_error() storage/innobase/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB. storage/xtradb/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB.
13 years ago
17 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
16 years ago
15 years ago
16 years ago
17 years ago
17 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
virtual columns: * move a capability from a virtual handler method to table_flags() * rephrase error messages to avoid hard-coded English parts * admit in test cases that they need xtradb, not innodb mysql-test/suite/vcol/t/rpl_vcol.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_blocked_sql_funcs_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_column_def_options_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_handler_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_ins_upd_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_keys_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_non_stored_columns_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_partition_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_select_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_supported_sql_funcs_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_trigger_sp_innodb.test: this test needs xtradb, it will fail with innodb mysql-test/suite/vcol/t/vcol_view_innodb.test: this test needs xtradb, it will fail with innodb sql/ha_partition.h: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS sql/handler.h: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS sql/share/errmsg.txt: no hard-coded english parts in the error messages (ER_UNSUPPORTED_ACTION_ON_VIRTUAL_COLUMN) sql/sql_table.cc: no hard-coded english parts in the error messages sql/table.cc: * check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS * no "csv workaround" is needed * no hard-coded english parts in the error messages storage/maria/ha_maria.cc: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS storage/maria/ha_maria.h: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS storage/myisam/ha_myisam.cc: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS storage/myisam/ha_myisam.h: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS storage/xtradb/handler/ha_innodb.cc: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS storage/xtradb/handler/ha_innodb.h: check_if_supported_virtual_columns() -> HA_CAN_VIRTUAL_COLUMNS
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
Added option "AND DISABLE CHECKPOINT" to "FLUSH TABLES WITH READ LOCK" This makes it possible to do safe multi volume snapshots as long as one snapshots the volume with the transaction logs last. include/mysql_com.h: Added REFRESH_CHECKPOINT mysql-test/r/flush.result: Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls mysql-test/t/flush.test: Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls sql/handler.cc: Added code to call checkpoint_state for all handlertons that supports it sql/handler.h: Added new checkpoint_state() handlerton call to temporarly disable checkpoints. sql/lex.h: Added CHECKPOINT keyword sql/sql_yacc.yy: Added support for FLUSH TABLES WITH READ LOCK AND DISABLE CHECKPOINT storage/maria/ha_maria.cc: Added handlerton call to disable checkpoints. storage/maria/ma_checkpoint.c: Don't do checkpoint if checkpoints are disabled. storage/maria/ma_static.c: Added maria_checkpoint_disabled storage/maria/maria_def.h: Added maria_checkpoint_disabled storage/xtradb/handler/ha_innodb.cc: Added handlerton call to disable checkpoints. storage/xtradb/include/log0log.h: Added option to log_checkpoint() to allow one to ignore not critical checkpoints during the time checkpoints are disabled. storage/xtradb/log/log0log.c: Added code to allow one to disable checkpoints during a FLUSH TABLES ... DISABLE CHECKPOINT This was done by adding a new argument to log_checkpoint() which tells us when the checkpoint is called by srv_master_thread (which are safe to ignore) storage/xtradb/srv/srv0srv.c: Tell log_checkpoint() that checkpoints from srv_master_thread() are safe to ignore (will just delay recovery time a bit).
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
17 years ago
15 years ago
15 years ago
16 years ago
16 years ago
15 years ago
17 years ago
15 years ago
Added extra argument to longlong2str() to make it have same prototype is int2str() Changed to use longlong10_to_str() instead of longlong2str() when base is 10 or -10 as former is much faster than later Changed my_vsnprintf() to use longlong2str instead of int2str() to get rid of warnings and to get support for long pointers even when long is 32 bit. client/mysqltest.cc: longlong2str() -> longlong10_to_str() include/m_string.h: Added extra argument to longlong2str() to make it have same prototype is int2str() mysys/charset.c: Fixed compiler warning mysys/mf_soundex.c: Fixed compiler warning mysys/my_getopt.c: longlong2str() -> longlong10_to_str() sql/create_options.cc: Fixed compiler warning sql/item_strfunc.cc: Added extra argument to longlong2str sql/opt_range.cc: longlong2str() -> longlong10_to_str() sql/partition_info.cc: longlong2str() -> longlong10_to_str() sql/slave.cc: longlong2str() -> longlong10_to_str() sql/sql_bitmap.h: Added extra argument to longlong2str sql/sql_partition.cc: Added extra argument to longlong2str sql/sql_select.cc: longlong2str() -> longlong10_to_str() sql/sql_show.cc: Added extra argument to longlong2str storage/innodb_plugin/handler/ha_innodb.cc: Update to new parameters for longlong2str() storage/maria/ma_dbug.c: longlong2str() -> longlong10_to_str() storage/maria/maria_chk.c: Added extra argument to longlong2str storage/myisam/mi_dbug.c: longlong2str() -> longlong10_to_str() storage/myisam/myisamchk.c: Added extra argument to longlong2str storage/xtradb/handler/ha_innodb.cc: Update to new parameters for longlong2str() strings/longlong2str.c: Added extra argument to longlong2str() to make it have same prototype is int2str() strings/my_vsnprintf.c: Changed my_vsnprintf() to use longlong2str instead of int2str() to get rid of warnings and to get support for long pointers even when long is 32 bit. Added cast to get rid of compiler warnings
15 years ago
Added extra argument to longlong2str() to make it have same prototype is int2str() Changed to use longlong10_to_str() instead of longlong2str() when base is 10 or -10 as former is much faster than later Changed my_vsnprintf() to use longlong2str instead of int2str() to get rid of warnings and to get support for long pointers even when long is 32 bit. client/mysqltest.cc: longlong2str() -> longlong10_to_str() include/m_string.h: Added extra argument to longlong2str() to make it have same prototype is int2str() mysys/charset.c: Fixed compiler warning mysys/mf_soundex.c: Fixed compiler warning mysys/my_getopt.c: longlong2str() -> longlong10_to_str() sql/create_options.cc: Fixed compiler warning sql/item_strfunc.cc: Added extra argument to longlong2str sql/opt_range.cc: longlong2str() -> longlong10_to_str() sql/partition_info.cc: longlong2str() -> longlong10_to_str() sql/slave.cc: longlong2str() -> longlong10_to_str() sql/sql_bitmap.h: Added extra argument to longlong2str sql/sql_partition.cc: Added extra argument to longlong2str sql/sql_select.cc: longlong2str() -> longlong10_to_str() sql/sql_show.cc: Added extra argument to longlong2str storage/innodb_plugin/handler/ha_innodb.cc: Update to new parameters for longlong2str() storage/maria/ma_dbug.c: longlong2str() -> longlong10_to_str() storage/maria/maria_chk.c: Added extra argument to longlong2str storage/myisam/mi_dbug.c: longlong2str() -> longlong10_to_str() storage/myisam/myisamchk.c: Added extra argument to longlong2str storage/xtradb/handler/ha_innodb.cc: Update to new parameters for longlong2str() strings/longlong2str.c: Added extra argument to longlong2str() to make it have same prototype is int2str() strings/my_vsnprintf.c: Changed my_vsnprintf() to use longlong2str instead of int2str() to get rid of warnings and to get support for long pointers even when long is 32 bit. Added cast to get rid of compiler warnings
15 years ago
15 years ago
15 years ago
15 years ago
17 years ago
15 years ago
15 years ago
16 years ago
16 years ago
17 years ago
17 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
15 years ago
15 years ago
Changed SHOW_FUNC variabels that don't return SHOW_ARRAY to SHOW_SIMPLE_FUNC. This allows us to avoid calculating variables (including those involving mutex) that doesn't match the given wildcard in SHOW STATUS LIKE '...' Removed all references to active_mi that could cause problems for multi-source replication. Added START|STOP ALL SLAVES Added SHOW ALL SLAVES STATUS include/mysql/plugin.h: Added SHOW_SIMPLE_FUNC include/mysql/plugin_audit.h.pp: Updated .pp file include/mysql/plugin_auth.h.pp: Updated .pp file include/mysql/plugin_ftparser.h.pp: Updated .pp file mysql-test/suite/multi_source/info_logs.result: New columns in SHOW ALL SLAVES STATUS mysql-test/suite/multi_source/info_logs.test: Test new syntax mysql-test/suite/multi_source/simple.result: New columns in SHOW ALL SLAVES STATUS mysql-test/suite/multi_source/simple.test: test new syntax mysql-test/suite/multi_source/syntax.result: Updated result mysql-test/suite/multi_source/syntax.test: Test new syntax mysql-test/suite/rpl/r/rpl_skip_replication.result: Updated result plugin/semisync/semisync_master_plugin.cc: SHOW_FUNC -> SHOW_SIMPLE_FUNC sql/item_create.cc: Simplify code sql/lex.h: Added SLAVES keyword sql/log.cc: Constant -> define sql/log_event.cc: Added comment sql/mysqld.cc: SHOW_FUNC -> SHOW_SIMPLE_FUNC Made slave_retried_trans, slave_received_heartbeats and heartbeat_period multi-source safe Clear variable denied_connections and slave_retried_transactions on startup sql/mysqld.h: Added slave_retried_transactions sql/rpl_mi.cc: create_signed_file_name -> create_logfile_name_with_suffix Added start_all_slaves() and stop_all_slaves() sql/rpl_mi.h: Added prototypes sql/rpl_rli.cc: create_signed_file_name -> create_logfile_name_with_suffix added executed_entries sql/rpl_rli.h: Added executed_entries sql/share/errmsg-utf8.txt: More and better error messages sql/slave.cc: Added more fields to SHOW ALL SLAVES STATUS Added slave_retried_transactions Changed constants -> defines sql/sql_class.h: Added comment sql/sql_insert.cc: active_mi.rli -> thd->rli_slave sql/sql_lex.h: Added SQLCOM_SLAVE_ALL_START & SQLCOM_SLAVE_ALL_STOP sql/sql_load.cc: active_mi.rli -> thd->rli_slave sql/sql_parse.cc: Added START|STOP ALL SLAVES sql/sql_prepare.cc: Added SQLCOM_SLAVE_ALL_START & SQLCOM_SLAVE_ALL_STOP sql/sql_reload.cc: Made REFRESH RELAY LOG multi-source safe sql/sql_repl.cc: create_signed_file_name -> create_logfile_name_with_suffix Don't send my_ok() from start_slave() or stop_slave() so that we can call it for all master connections sql/sql_show.cc: Compare wild cards early for all variables sql/sql_yacc.yy: Added START|STOP ALL SLAVES Added SHOW ALL SLAVES STATUS sql/sys_vars.cc: Made replicate_events_marked_for_skip,slave_net_timeout and rpl_filter multi-source safe. sql/sys_vars.h: Simplify Sys_var_rpl_filter
13 years ago
15 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
Original idea from Zardosht Kasheff to add HA_CLUSTERED_INDEX - Added a lot of code comments - Updated get_best_ror_intersec() to prefer index scan on not clustered keys before clustered keys. - Use HA_CLUSTERED_INDEX to define if one should use HA_MRR_INDEX_ONLY - For test of using index or filesort to resolve ORDER BY, use HA_CLUSTERED_INDEX flag instead of primary_key_is_clustered() - Use HA_TABLE_SCAN_ON_INDEX instead of primary_key_is_clustered() to decide if ALTER TABLE ... ORDER BY will have any effect. sql/ha_partition.h: Added comment with warning for code unsafe to use with multiple storage engines at the same time sql/handler.h: Added HA_CLUSTERED_INDEX. Documented primary_key_is_clustered() sql/opt_range.cc: Added code comments Updated get_best_ror_intersec() to ignore clustered keys. Optimized away cpk_scan_used and one instance of current_thd (Simpler code) Use HA_CLUSTERED_INDEX to define if one should use HA_MRR_INDEX_ONLY sql/sql_select.cc: Changed comment to #ifdef For test of using index or filesort to resolve ORDER BY, use HA_CLUSTERED_INDEX flag instead of primary_key_is_clustered() (Change is smaller than what it looks beause of indentation change) sql/sql_table.cc: Use HA_TABLE_SCAN_ON_INDEX instead of primary_key_is_clustered() to decide if ALTER TABLE ... ORDER BY will have any effect. storage/innobase/handler/ha_innodb.h: Added support for HA_CLUSTERED_INDEX storage/innodb_plugin/handler/ha_innodb.cc: Added support for HA_CLUSTERED_INDEX storage/xtradb/handler/ha_innodb.cc: Added support for HA_CLUSTERED_INDEX
15 years ago
16 years ago
Original idea from Zardosht Kasheff to add HA_CLUSTERED_INDEX - Added a lot of code comments - Updated get_best_ror_intersec() to prefer index scan on not clustered keys before clustered keys. - Use HA_CLUSTERED_INDEX to define if one should use HA_MRR_INDEX_ONLY - For test of using index or filesort to resolve ORDER BY, use HA_CLUSTERED_INDEX flag instead of primary_key_is_clustered() - Use HA_TABLE_SCAN_ON_INDEX instead of primary_key_is_clustered() to decide if ALTER TABLE ... ORDER BY will have any effect. sql/ha_partition.h: Added comment with warning for code unsafe to use with multiple storage engines at the same time sql/handler.h: Added HA_CLUSTERED_INDEX. Documented primary_key_is_clustered() sql/opt_range.cc: Added code comments Updated get_best_ror_intersec() to ignore clustered keys. Optimized away cpk_scan_used and one instance of current_thd (Simpler code) Use HA_CLUSTERED_INDEX to define if one should use HA_MRR_INDEX_ONLY sql/sql_select.cc: Changed comment to #ifdef For test of using index or filesort to resolve ORDER BY, use HA_CLUSTERED_INDEX flag instead of primary_key_is_clustered() (Change is smaller than what it looks beause of indentation change) sql/sql_table.cc: Use HA_TABLE_SCAN_ON_INDEX instead of primary_key_is_clustered() to decide if ALTER TABLE ... ORDER BY will have any effect. storage/innobase/handler/ha_innodb.h: Added support for HA_CLUSTERED_INDEX storage/innodb_plugin/handler/ha_innodb.cc: Added support for HA_CLUSTERED_INDEX storage/xtradb/handler/ha_innodb.cc: Added support for HA_CLUSTERED_INDEX
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
17 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
Merge with 5.1-microseconds A lot of small fixes and new test cases. client/mysqlbinlog.cc: Cast removed client/mysqltest.cc: Added missing DBUG_RETURN include/my_pthread.h: set_timespec_time_nsec() now only takes one argument mysql-test/t/date_formats.test: Remove --disable_ps_protocl as now also ps supports microseconds mysys/my_uuid.c: Changed to use my_interval_timer() instead of my_getsystime() mysys/waiting_threads.c: Changed to use my_hrtime() sql/field.h: Added bool special_const_compare() for fields that may convert values before compare (like year) sql/field_conv.cc: Added test to get optimal copying of identical temporal values. sql/item.cc: Return that item_int is equal if it's positive, even if unsigned flag is different. Fixed Item_cache_str::save_in_field() to have identical null check as other similar functions Added proper NULL check to Item_cache_int::save_in_field() sql/item_cmpfunc.cc: Don't call convert_constant_item() if there is nothing that is worth converting. Simplified test when years should be converted sql/item_sum.cc: Mark cache values in Item_sum_hybrid as not constants to ensure they are not replaced by other cache values in compare_datetime() sql/item_timefunc.cc: Changed sec_to_time() to take a my_decimal argument to ensure we don't loose any sub seconds. Added Item_temporal_func::get_time() (This simplifies some things) sql/mysql_priv.h: Added Lazy_string_decimal() sql/mysqld.cc: Added my_decimal constants max_seconds_for_time_type, time_second_part_factor sql/table.cc: Changed expr_arena to be of type CONVENTIONAL_EXECUTION to ensure that we don't loose any items that are created by fix_fields() sql/tztime.cc: TIME_to_gmt_sec() now sets *in_dst_time_gap in case of errors This is needed to be able to detect if timestamp is 0 storage/maria/lockman.c: Changed from my_getsystime() to set_timespec_time_nsec() storage/maria/ma_loghandler.c: Changed from my_getsystime() to my_hrtime() storage/maria/ma_recovery.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/maria/unittest/trnman-t.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/xtradb/handler/ha_innodb.cc: Added support for new time,datetime and timestamp unittest/mysys/thr_template.c: my_getsystime() -> my_interval_timer() unittest/mysys/waiting_threads-t.c: my_getsystime() -> my_interval_timer()
15 years ago
Merge with 5.1-microseconds A lot of small fixes and new test cases. client/mysqlbinlog.cc: Cast removed client/mysqltest.cc: Added missing DBUG_RETURN include/my_pthread.h: set_timespec_time_nsec() now only takes one argument mysql-test/t/date_formats.test: Remove --disable_ps_protocl as now also ps supports microseconds mysys/my_uuid.c: Changed to use my_interval_timer() instead of my_getsystime() mysys/waiting_threads.c: Changed to use my_hrtime() sql/field.h: Added bool special_const_compare() for fields that may convert values before compare (like year) sql/field_conv.cc: Added test to get optimal copying of identical temporal values. sql/item.cc: Return that item_int is equal if it's positive, even if unsigned flag is different. Fixed Item_cache_str::save_in_field() to have identical null check as other similar functions Added proper NULL check to Item_cache_int::save_in_field() sql/item_cmpfunc.cc: Don't call convert_constant_item() if there is nothing that is worth converting. Simplified test when years should be converted sql/item_sum.cc: Mark cache values in Item_sum_hybrid as not constants to ensure they are not replaced by other cache values in compare_datetime() sql/item_timefunc.cc: Changed sec_to_time() to take a my_decimal argument to ensure we don't loose any sub seconds. Added Item_temporal_func::get_time() (This simplifies some things) sql/mysql_priv.h: Added Lazy_string_decimal() sql/mysqld.cc: Added my_decimal constants max_seconds_for_time_type, time_second_part_factor sql/table.cc: Changed expr_arena to be of type CONVENTIONAL_EXECUTION to ensure that we don't loose any items that are created by fix_fields() sql/tztime.cc: TIME_to_gmt_sec() now sets *in_dst_time_gap in case of errors This is needed to be able to detect if timestamp is 0 storage/maria/lockman.c: Changed from my_getsystime() to set_timespec_time_nsec() storage/maria/ma_loghandler.c: Changed from my_getsystime() to my_hrtime() storage/maria/ma_recovery.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/maria/unittest/trnman-t.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/xtradb/handler/ha_innodb.cc: Added support for new time,datetime and timestamp unittest/mysys/thr_template.c: my_getsystime() -> my_interval_timer() unittest/mysys/waiting_threads-t.c: my_getsystime() -> my_interval_timer()
15 years ago
Merge with 5.1-microseconds A lot of small fixes and new test cases. client/mysqlbinlog.cc: Cast removed client/mysqltest.cc: Added missing DBUG_RETURN include/my_pthread.h: set_timespec_time_nsec() now only takes one argument mysql-test/t/date_formats.test: Remove --disable_ps_protocl as now also ps supports microseconds mysys/my_uuid.c: Changed to use my_interval_timer() instead of my_getsystime() mysys/waiting_threads.c: Changed to use my_hrtime() sql/field.h: Added bool special_const_compare() for fields that may convert values before compare (like year) sql/field_conv.cc: Added test to get optimal copying of identical temporal values. sql/item.cc: Return that item_int is equal if it's positive, even if unsigned flag is different. Fixed Item_cache_str::save_in_field() to have identical null check as other similar functions Added proper NULL check to Item_cache_int::save_in_field() sql/item_cmpfunc.cc: Don't call convert_constant_item() if there is nothing that is worth converting. Simplified test when years should be converted sql/item_sum.cc: Mark cache values in Item_sum_hybrid as not constants to ensure they are not replaced by other cache values in compare_datetime() sql/item_timefunc.cc: Changed sec_to_time() to take a my_decimal argument to ensure we don't loose any sub seconds. Added Item_temporal_func::get_time() (This simplifies some things) sql/mysql_priv.h: Added Lazy_string_decimal() sql/mysqld.cc: Added my_decimal constants max_seconds_for_time_type, time_second_part_factor sql/table.cc: Changed expr_arena to be of type CONVENTIONAL_EXECUTION to ensure that we don't loose any items that are created by fix_fields() sql/tztime.cc: TIME_to_gmt_sec() now sets *in_dst_time_gap in case of errors This is needed to be able to detect if timestamp is 0 storage/maria/lockman.c: Changed from my_getsystime() to set_timespec_time_nsec() storage/maria/ma_loghandler.c: Changed from my_getsystime() to my_hrtime() storage/maria/ma_recovery.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/maria/unittest/trnman-t.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/xtradb/handler/ha_innodb.cc: Added support for new time,datetime and timestamp unittest/mysys/thr_template.c: my_getsystime() -> my_interval_timer() unittest/mysys/waiting_threads-t.c: my_getsystime() -> my_interval_timer()
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
14 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
15 years ago
15 years ago
Fix for MDEV-533: Confusing error code when doing auto-increment insert for out-of-range values create table t1 (a smallint primary key auto_increment); insert into t1 values(32767); insert into t1 values(NULL); ERROR 1062 (23000): Duplicate entry '32767' for key 'PRIMARY Now on always gets error HA_ERR_AUTOINC_RANGE=167 "Out of range value for column", independent of store engine, SQL Mode or number of inserted rows. This is an unique error that is easier to test for in replication. Another bug fix is that we now get an error when trying to insert a too big auto-generated value, even in non-strict mode. Before one get insted the max column value inserted. This patch also fixes some issues with inserting negative numbers in an auto-increment column. Fixed the ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. Added SQLSTATE errors for handler errors Smaller bug fixes: * Added warnings for duplicate key errors when using INSERT IGNORE * Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" * Allow one to see how cmake is called by using --just-print --just-configure BUILD/FINISH.sh: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. cmake/configure.pl: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. include/CMakeLists.txt: Added handler_state.h include/handler_state.h: SQLSTATE for handler error messages. Required for HA_ERR_AUTOINC_ERANGE, but solves also some other cases. mysql-test/extra/binlog_tests/binlog.test: Fixed old wrong behaviour Added more tests mysql-test/extra/binlog_tests/binlog_insert_delayed.test: Reset binary log to only print what's necessary in show_binlog_events mysql-test/extra/rpl_tests/rpl_auto_increment.test: Update to new error codes mysql-test/extra/rpl_tests/rpl_insert_delayed.test: Ignore warnings as this depends on how the test is run mysql-test/include/strict_autoinc.inc: On now gets an error on overflow mysql-test/r/auto_increment.result: Update results after fixing error message mysql-test/r/auto_increment_ranges_innodb.result: Test new behaviour mysql-test/r/auto_increment_ranges_myisam.result: Test new behaviour mysql-test/r/commit_1innodb.result: Added warnings for duplicate key error mysql-test/r/create.result: Added warnings for duplicate key error mysql-test/r/insert.result: Added warnings for duplicate key error mysql-test/r/insert_select.result: Added warnings for duplicate key error mysql-test/r/insert_update.result: Added warnings for duplicate key error mysql-test/r/mix2_myisam.result: Added warnings for duplicate key error mysql-test/r/myisam_mrr.result: Added warnings for duplicate key error mysql-test/r/null_key.result: Added warnings for duplicate key error mysql-test/r/replace.result: Update to new error codes mysql-test/r/strict_autoinc_1myisam.result: Update to new error codes mysql-test/r/strict_autoinc_2innodb.result: Update to new error codes mysql-test/r/strict_autoinc_3heap.result: Update to new error codes mysql-test/r/trigger.result: Added warnings for duplicate key error mysql-test/r/xtradb_mrr.result: Added warnings for duplicate key error mysql-test/suite/binlog/r/binlog_innodb_row.result: Updated result mysql-test/suite/binlog/r/binlog_row_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: Updated result mysql-test/suite/binlog/r/binlog_stm_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_unsafe.result: Updated result mysql-test/suite/innodb/r/innodb-autoinc.result: Update to new error codes mysql-test/suite/innodb/r/innodb-lock.result: Updated results mysql-test/suite/innodb/r/innodb.result: Updated results mysql-test/suite/innodb/r/innodb_bug56947.result: Updated results mysql-test/suite/innodb/r/innodb_mysql.result: Updated results mysql-test/suite/innodb/t/innodb-autoinc.test: Update to new error codes mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/maria/mrr.result: Updated result mysql-test/suite/optimizer_unfixed_bugs/r/bug43617.result: Updated result mysql-test/suite/rpl/r/rpl_auto_increment.result: Update to new error codes mysql-test/suite/rpl/r/rpl_insert_delayed,stmt.rdiff: Updated results mysql-test/suite/rpl/r/rpl_loaddatalocal.result: Updated results mysql-test/t/auto_increment.test: Update to new error codes mysql-test/t/auto_increment_ranges.inc: Test new behaviour mysql-test/t/auto_increment_ranges_innodb.test: Test new behaviour mysql-test/t/auto_increment_ranges_myisam.test: Test new behaviour mysql-test/t/replace.test: Update to new error codes mysys/my_getopt.c: Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" sql/handler.cc: Ignore negative values for signed auto-increment columns Always give an error if we get an overflow for an auto-increment-column (instead of inserting the max value) Ensure that the row number is correct for the out-of-range-value error message. ****** Fixed wrong printing of column namn for "Out of range value" errors Fixed that INSERT_ID is correctly replicated also for out-of-range autoincrement values Fixed that print_keydup_error() can also be used to generate warnings ****** Return HA_ERR_AUTOINC_ERANGE (167) instead of ER_WARN_DATA_OUT_OF_RANGE for auto-increment overflow sql/handler.h: Allow INSERT IGNORE to continue also after out-of-range inserts. Fixed that print_keydup_error() can also be used to generate warnings sql/log_event.cc: Added DBUG_PRINT Fixed the ER_AUTOINC_READ_FAILED, ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. sql/sql_insert.cc: Add warnings for duplicate key errors when using INSERT IGNORE sql/sql_state.c: Added handler errors sql/sql_table.cc: Update call to print_keydup_error() storage/innobase/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB. storage/xtradb/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB.
13 years ago
17 years ago
17 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
17 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
17 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
16 years ago
17 years ago
17 years ago
17 years ago
16 years ago
16 years ago
16 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
16 years ago
16 years ago
17 years ago
16 years ago
16 years ago
16 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
17 years ago
17 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
16 years ago
15 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
17 years ago
17 years ago
16 years ago
15 years ago
17 years ago
17 years ago
17 years ago
15 years ago
15 years ago
17 years ago
17 years ago
17 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
Fix for MDEV-533: Confusing error code when doing auto-increment insert for out-of-range values create table t1 (a smallint primary key auto_increment); insert into t1 values(32767); insert into t1 values(NULL); ERROR 1062 (23000): Duplicate entry '32767' for key 'PRIMARY Now on always gets error HA_ERR_AUTOINC_RANGE=167 "Out of range value for column", independent of store engine, SQL Mode or number of inserted rows. This is an unique error that is easier to test for in replication. Another bug fix is that we now get an error when trying to insert a too big auto-generated value, even in non-strict mode. Before one get insted the max column value inserted. This patch also fixes some issues with inserting negative numbers in an auto-increment column. Fixed the ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. Added SQLSTATE errors for handler errors Smaller bug fixes: * Added warnings for duplicate key errors when using INSERT IGNORE * Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" * Allow one to see how cmake is called by using --just-print --just-configure BUILD/FINISH.sh: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. cmake/configure.pl: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. include/CMakeLists.txt: Added handler_state.h include/handler_state.h: SQLSTATE for handler error messages. Required for HA_ERR_AUTOINC_ERANGE, but solves also some other cases. mysql-test/extra/binlog_tests/binlog.test: Fixed old wrong behaviour Added more tests mysql-test/extra/binlog_tests/binlog_insert_delayed.test: Reset binary log to only print what's necessary in show_binlog_events mysql-test/extra/rpl_tests/rpl_auto_increment.test: Update to new error codes mysql-test/extra/rpl_tests/rpl_insert_delayed.test: Ignore warnings as this depends on how the test is run mysql-test/include/strict_autoinc.inc: On now gets an error on overflow mysql-test/r/auto_increment.result: Update results after fixing error message mysql-test/r/auto_increment_ranges_innodb.result: Test new behaviour mysql-test/r/auto_increment_ranges_myisam.result: Test new behaviour mysql-test/r/commit_1innodb.result: Added warnings for duplicate key error mysql-test/r/create.result: Added warnings for duplicate key error mysql-test/r/insert.result: Added warnings for duplicate key error mysql-test/r/insert_select.result: Added warnings for duplicate key error mysql-test/r/insert_update.result: Added warnings for duplicate key error mysql-test/r/mix2_myisam.result: Added warnings for duplicate key error mysql-test/r/myisam_mrr.result: Added warnings for duplicate key error mysql-test/r/null_key.result: Added warnings for duplicate key error mysql-test/r/replace.result: Update to new error codes mysql-test/r/strict_autoinc_1myisam.result: Update to new error codes mysql-test/r/strict_autoinc_2innodb.result: Update to new error codes mysql-test/r/strict_autoinc_3heap.result: Update to new error codes mysql-test/r/trigger.result: Added warnings for duplicate key error mysql-test/r/xtradb_mrr.result: Added warnings for duplicate key error mysql-test/suite/binlog/r/binlog_innodb_row.result: Updated result mysql-test/suite/binlog/r/binlog_row_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: Updated result mysql-test/suite/binlog/r/binlog_stm_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_unsafe.result: Updated result mysql-test/suite/innodb/r/innodb-autoinc.result: Update to new error codes mysql-test/suite/innodb/r/innodb-lock.result: Updated results mysql-test/suite/innodb/r/innodb.result: Updated results mysql-test/suite/innodb/r/innodb_bug56947.result: Updated results mysql-test/suite/innodb/r/innodb_mysql.result: Updated results mysql-test/suite/innodb/t/innodb-autoinc.test: Update to new error codes mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/maria/mrr.result: Updated result mysql-test/suite/optimizer_unfixed_bugs/r/bug43617.result: Updated result mysql-test/suite/rpl/r/rpl_auto_increment.result: Update to new error codes mysql-test/suite/rpl/r/rpl_insert_delayed,stmt.rdiff: Updated results mysql-test/suite/rpl/r/rpl_loaddatalocal.result: Updated results mysql-test/t/auto_increment.test: Update to new error codes mysql-test/t/auto_increment_ranges.inc: Test new behaviour mysql-test/t/auto_increment_ranges_innodb.test: Test new behaviour mysql-test/t/auto_increment_ranges_myisam.test: Test new behaviour mysql-test/t/replace.test: Update to new error codes mysys/my_getopt.c: Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" sql/handler.cc: Ignore negative values for signed auto-increment columns Always give an error if we get an overflow for an auto-increment-column (instead of inserting the max value) Ensure that the row number is correct for the out-of-range-value error message. ****** Fixed wrong printing of column namn for "Out of range value" errors Fixed that INSERT_ID is correctly replicated also for out-of-range autoincrement values Fixed that print_keydup_error() can also be used to generate warnings ****** Return HA_ERR_AUTOINC_ERANGE (167) instead of ER_WARN_DATA_OUT_OF_RANGE for auto-increment overflow sql/handler.h: Allow INSERT IGNORE to continue also after out-of-range inserts. Fixed that print_keydup_error() can also be used to generate warnings sql/log_event.cc: Added DBUG_PRINT Fixed the ER_AUTOINC_READ_FAILED, ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. sql/sql_insert.cc: Add warnings for duplicate key errors when using INSERT IGNORE sql/sql_state.c: Added handler errors sql/sql_table.cc: Update call to print_keydup_error() storage/innobase/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB. storage/xtradb/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB.
13 years ago
Fix for MDEV-533: Confusing error code when doing auto-increment insert for out-of-range values create table t1 (a smallint primary key auto_increment); insert into t1 values(32767); insert into t1 values(NULL); ERROR 1062 (23000): Duplicate entry '32767' for key 'PRIMARY Now on always gets error HA_ERR_AUTOINC_RANGE=167 "Out of range value for column", independent of store engine, SQL Mode or number of inserted rows. This is an unique error that is easier to test for in replication. Another bug fix is that we now get an error when trying to insert a too big auto-generated value, even in non-strict mode. Before one get insted the max column value inserted. This patch also fixes some issues with inserting negative numbers in an auto-increment column. Fixed the ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. Added SQLSTATE errors for handler errors Smaller bug fixes: * Added warnings for duplicate key errors when using INSERT IGNORE * Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" * Allow one to see how cmake is called by using --just-print --just-configure BUILD/FINISH.sh: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. cmake/configure.pl: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. include/CMakeLists.txt: Added handler_state.h include/handler_state.h: SQLSTATE for handler error messages. Required for HA_ERR_AUTOINC_ERANGE, but solves also some other cases. mysql-test/extra/binlog_tests/binlog.test: Fixed old wrong behaviour Added more tests mysql-test/extra/binlog_tests/binlog_insert_delayed.test: Reset binary log to only print what's necessary in show_binlog_events mysql-test/extra/rpl_tests/rpl_auto_increment.test: Update to new error codes mysql-test/extra/rpl_tests/rpl_insert_delayed.test: Ignore warnings as this depends on how the test is run mysql-test/include/strict_autoinc.inc: On now gets an error on overflow mysql-test/r/auto_increment.result: Update results after fixing error message mysql-test/r/auto_increment_ranges_innodb.result: Test new behaviour mysql-test/r/auto_increment_ranges_myisam.result: Test new behaviour mysql-test/r/commit_1innodb.result: Added warnings for duplicate key error mysql-test/r/create.result: Added warnings for duplicate key error mysql-test/r/insert.result: Added warnings for duplicate key error mysql-test/r/insert_select.result: Added warnings for duplicate key error mysql-test/r/insert_update.result: Added warnings for duplicate key error mysql-test/r/mix2_myisam.result: Added warnings for duplicate key error mysql-test/r/myisam_mrr.result: Added warnings for duplicate key error mysql-test/r/null_key.result: Added warnings for duplicate key error mysql-test/r/replace.result: Update to new error codes mysql-test/r/strict_autoinc_1myisam.result: Update to new error codes mysql-test/r/strict_autoinc_2innodb.result: Update to new error codes mysql-test/r/strict_autoinc_3heap.result: Update to new error codes mysql-test/r/trigger.result: Added warnings for duplicate key error mysql-test/r/xtradb_mrr.result: Added warnings for duplicate key error mysql-test/suite/binlog/r/binlog_innodb_row.result: Updated result mysql-test/suite/binlog/r/binlog_row_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: Updated result mysql-test/suite/binlog/r/binlog_stm_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_unsafe.result: Updated result mysql-test/suite/innodb/r/innodb-autoinc.result: Update to new error codes mysql-test/suite/innodb/r/innodb-lock.result: Updated results mysql-test/suite/innodb/r/innodb.result: Updated results mysql-test/suite/innodb/r/innodb_bug56947.result: Updated results mysql-test/suite/innodb/r/innodb_mysql.result: Updated results mysql-test/suite/innodb/t/innodb-autoinc.test: Update to new error codes mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/maria/mrr.result: Updated result mysql-test/suite/optimizer_unfixed_bugs/r/bug43617.result: Updated result mysql-test/suite/rpl/r/rpl_auto_increment.result: Update to new error codes mysql-test/suite/rpl/r/rpl_insert_delayed,stmt.rdiff: Updated results mysql-test/suite/rpl/r/rpl_loaddatalocal.result: Updated results mysql-test/t/auto_increment.test: Update to new error codes mysql-test/t/auto_increment_ranges.inc: Test new behaviour mysql-test/t/auto_increment_ranges_innodb.test: Test new behaviour mysql-test/t/auto_increment_ranges_myisam.test: Test new behaviour mysql-test/t/replace.test: Update to new error codes mysys/my_getopt.c: Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" sql/handler.cc: Ignore negative values for signed auto-increment columns Always give an error if we get an overflow for an auto-increment-column (instead of inserting the max value) Ensure that the row number is correct for the out-of-range-value error message. ****** Fixed wrong printing of column namn for "Out of range value" errors Fixed that INSERT_ID is correctly replicated also for out-of-range autoincrement values Fixed that print_keydup_error() can also be used to generate warnings ****** Return HA_ERR_AUTOINC_ERANGE (167) instead of ER_WARN_DATA_OUT_OF_RANGE for auto-increment overflow sql/handler.h: Allow INSERT IGNORE to continue also after out-of-range inserts. Fixed that print_keydup_error() can also be used to generate warnings sql/log_event.cc: Added DBUG_PRINT Fixed the ER_AUTOINC_READ_FAILED, ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. sql/sql_insert.cc: Add warnings for duplicate key errors when using INSERT IGNORE sql/sql_state.c: Added handler errors sql/sql_table.cc: Update call to print_keydup_error() storage/innobase/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB. storage/xtradb/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB.
13 years ago
Fix for MDEV-533: Confusing error code when doing auto-increment insert for out-of-range values create table t1 (a smallint primary key auto_increment); insert into t1 values(32767); insert into t1 values(NULL); ERROR 1062 (23000): Duplicate entry '32767' for key 'PRIMARY Now on always gets error HA_ERR_AUTOINC_RANGE=167 "Out of range value for column", independent of store engine, SQL Mode or number of inserted rows. This is an unique error that is easier to test for in replication. Another bug fix is that we now get an error when trying to insert a too big auto-generated value, even in non-strict mode. Before one get insted the max column value inserted. This patch also fixes some issues with inserting negative numbers in an auto-increment column. Fixed the ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. Added SQLSTATE errors for handler errors Smaller bug fixes: * Added warnings for duplicate key errors when using INSERT IGNORE * Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" * Allow one to see how cmake is called by using --just-print --just-configure BUILD/FINISH.sh: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. cmake/configure.pl: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. include/CMakeLists.txt: Added handler_state.h include/handler_state.h: SQLSTATE for handler error messages. Required for HA_ERR_AUTOINC_ERANGE, but solves also some other cases. mysql-test/extra/binlog_tests/binlog.test: Fixed old wrong behaviour Added more tests mysql-test/extra/binlog_tests/binlog_insert_delayed.test: Reset binary log to only print what's necessary in show_binlog_events mysql-test/extra/rpl_tests/rpl_auto_increment.test: Update to new error codes mysql-test/extra/rpl_tests/rpl_insert_delayed.test: Ignore warnings as this depends on how the test is run mysql-test/include/strict_autoinc.inc: On now gets an error on overflow mysql-test/r/auto_increment.result: Update results after fixing error message mysql-test/r/auto_increment_ranges_innodb.result: Test new behaviour mysql-test/r/auto_increment_ranges_myisam.result: Test new behaviour mysql-test/r/commit_1innodb.result: Added warnings for duplicate key error mysql-test/r/create.result: Added warnings for duplicate key error mysql-test/r/insert.result: Added warnings for duplicate key error mysql-test/r/insert_select.result: Added warnings for duplicate key error mysql-test/r/insert_update.result: Added warnings for duplicate key error mysql-test/r/mix2_myisam.result: Added warnings for duplicate key error mysql-test/r/myisam_mrr.result: Added warnings for duplicate key error mysql-test/r/null_key.result: Added warnings for duplicate key error mysql-test/r/replace.result: Update to new error codes mysql-test/r/strict_autoinc_1myisam.result: Update to new error codes mysql-test/r/strict_autoinc_2innodb.result: Update to new error codes mysql-test/r/strict_autoinc_3heap.result: Update to new error codes mysql-test/r/trigger.result: Added warnings for duplicate key error mysql-test/r/xtradb_mrr.result: Added warnings for duplicate key error mysql-test/suite/binlog/r/binlog_innodb_row.result: Updated result mysql-test/suite/binlog/r/binlog_row_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: Updated result mysql-test/suite/binlog/r/binlog_stm_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_unsafe.result: Updated result mysql-test/suite/innodb/r/innodb-autoinc.result: Update to new error codes mysql-test/suite/innodb/r/innodb-lock.result: Updated results mysql-test/suite/innodb/r/innodb.result: Updated results mysql-test/suite/innodb/r/innodb_bug56947.result: Updated results mysql-test/suite/innodb/r/innodb_mysql.result: Updated results mysql-test/suite/innodb/t/innodb-autoinc.test: Update to new error codes mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/maria/mrr.result: Updated result mysql-test/suite/optimizer_unfixed_bugs/r/bug43617.result: Updated result mysql-test/suite/rpl/r/rpl_auto_increment.result: Update to new error codes mysql-test/suite/rpl/r/rpl_insert_delayed,stmt.rdiff: Updated results mysql-test/suite/rpl/r/rpl_loaddatalocal.result: Updated results mysql-test/t/auto_increment.test: Update to new error codes mysql-test/t/auto_increment_ranges.inc: Test new behaviour mysql-test/t/auto_increment_ranges_innodb.test: Test new behaviour mysql-test/t/auto_increment_ranges_myisam.test: Test new behaviour mysql-test/t/replace.test: Update to new error codes mysys/my_getopt.c: Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" sql/handler.cc: Ignore negative values for signed auto-increment columns Always give an error if we get an overflow for an auto-increment-column (instead of inserting the max value) Ensure that the row number is correct for the out-of-range-value error message. ****** Fixed wrong printing of column namn for "Out of range value" errors Fixed that INSERT_ID is correctly replicated also for out-of-range autoincrement values Fixed that print_keydup_error() can also be used to generate warnings ****** Return HA_ERR_AUTOINC_ERANGE (167) instead of ER_WARN_DATA_OUT_OF_RANGE for auto-increment overflow sql/handler.h: Allow INSERT IGNORE to continue also after out-of-range inserts. Fixed that print_keydup_error() can also be used to generate warnings sql/log_event.cc: Added DBUG_PRINT Fixed the ER_AUTOINC_READ_FAILED, ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. sql/sql_insert.cc: Add warnings for duplicate key errors when using INSERT IGNORE sql/sql_state.c: Added handler errors sql/sql_table.cc: Update call to print_keydup_error() storage/innobase/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB. storage/xtradb/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB.
13 years ago
17 years ago
16 years ago
16 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
16 years ago
16 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
Fix test cases after merge of XtraDB into MariaDB. Manually merge some InnoDB changes into XtraDB. Fix ALTER TABLE bug in XtraDB with wrong comparison of row type. mysql-test/include/varchar.inc: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/mysql-test-run.pl: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. mysql-test/r/innodb.result: Fix in test case that which of several duplicate keys triggers an error is not deterministic. mysql-test/t/innodb-use-sys-malloc.test: InnoDB does not bother to free resources individually during shutdown, but due to using its own memory tracking it nevertheless can free everything at exit. But XtraDB adds an option, on by default, to skip this extra tracking. This causes lots of Valgrind warnings, so needs to be disabled for Valgrind testing. sql/sql_table.cc: Add some useful DBUG while debugging alter table. storage/xtradb/handler/ha_innodb.cc: Fix that check_if_incompatible_data did not realise that ROW_TYPE_DEFAULT is identical to the default row format ROW_TYPE_COMPACT, causing excessive table copying in ALTER TABLE Add some useful DBUG while debugging alter table. Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/pars0pars.h: Manually merge into XtraDB a few small changes for InnoDB from upstream MySQL. storage/xtradb/include/univ.i: Manually merge a MariaDB fix in InnoDB into XtraDB.
17 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
17 years ago
17 years ago
17 years ago
16 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
15 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
15 years ago
14 years ago
16 years ago
17 years ago
17 years ago
14 years ago
15 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
16 years ago
17 years ago
17 years ago
15 years ago
17 years ago
15 years ago
17 years ago
15 years ago
17 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
16 years ago
15 years ago
15 years ago
16 years ago
15 years ago
15 years ago
16 years ago
15 years ago
17 years ago
15 years ago
17 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
Maria WL#61 Interface for maria extensions. Alternative plugin interface with additional info (maturity and string version). CMakeLists.txt: Maria plugin interface used. config/ac-macros/plugins.m4: Maria plugin interface used. configure.in: Maria plugin interface used. include/mysql/plugin.h: Maria plugin interface added. include/mysql/plugin_auth.h.pp: Maria plugin interface added. plugin/auth/auth_socket.c: Maria plugin interface added. plugin/auth/dialog.c: Maria plugin interface added. plugin/daemon_example/daemon_example.cc: Maria plugin interface added. plugin/fulltext/plugin_example.c: Maria plugin interface added. sql/ha_ndbcluster.cc: Maria plugin interface added. sql/ha_partition.cc: Maria plugin interface added. sql/log.cc: Maria plugin interface added. sql/sql_acl.cc: Maria plugin interface added. sql/sql_builtin.cc.in: Maria plugin interface used. sql/sql_plugin.cc: Maria plugin interface added. sql/sql_plugin.h: Maria plugin interface used. sql/sql_show.cc: Maria plugin interface added. storage/archive/ha_archive.cc: Maria plugin interface added. storage/blackhole/ha_blackhole.cc: Maria plugin interface added. storage/csv/ha_tina.cc: Maria plugin interface added. storage/example/ha_example.cc: Maria plugin interface added. storage/federated/ha_federated.cc: Maria plugin interface added. storage/federatedx/ha_federatedx.cc: Maria plugin interface added. storage/heap/ha_heap.cc: Maria plugin interface added. storage/ibmdb2i/ha_ibmdb2i.cc: Maria plugin interface added. storage/innobase/handler/ha_innodb.cc: Maria plugin interface added. storage/innodb_plugin/handler/i_s.cc: Maria plugin interface added. storage/maria/ha_maria.cc: Maria plugin interface added. storage/myisam/ha_myisam.cc: Maria plugin interface added. storage/myisammrg/ha_myisammrg.cc: Maria plugin interface added. storage/pbxt/src/ha_pbxt.cc: Maria plugin interface added. storage/xtradb/handler/ha_innodb.cc: Maria plugin interface added. storage/xtradb/handler/i_s.cc: Maria plugin interface added. storage/xtradb/handler/i_s.h: Maria plugin interface added.
16 years ago
Maria WL#61 Interface for maria extensions. Alternative plugin interface with additional info (maturity and string version). CMakeLists.txt: Maria plugin interface used. config/ac-macros/plugins.m4: Maria plugin interface used. configure.in: Maria plugin interface used. include/mysql/plugin.h: Maria plugin interface added. include/mysql/plugin_auth.h.pp: Maria plugin interface added. plugin/auth/auth_socket.c: Maria plugin interface added. plugin/auth/dialog.c: Maria plugin interface added. plugin/daemon_example/daemon_example.cc: Maria plugin interface added. plugin/fulltext/plugin_example.c: Maria plugin interface added. sql/ha_ndbcluster.cc: Maria plugin interface added. sql/ha_partition.cc: Maria plugin interface added. sql/log.cc: Maria plugin interface added. sql/sql_acl.cc: Maria plugin interface added. sql/sql_builtin.cc.in: Maria plugin interface used. sql/sql_plugin.cc: Maria plugin interface added. sql/sql_plugin.h: Maria plugin interface used. sql/sql_show.cc: Maria plugin interface added. storage/archive/ha_archive.cc: Maria plugin interface added. storage/blackhole/ha_blackhole.cc: Maria plugin interface added. storage/csv/ha_tina.cc: Maria plugin interface added. storage/example/ha_example.cc: Maria plugin interface added. storage/federated/ha_federated.cc: Maria plugin interface added. storage/federatedx/ha_federatedx.cc: Maria plugin interface added. storage/heap/ha_heap.cc: Maria plugin interface added. storage/ibmdb2i/ha_ibmdb2i.cc: Maria plugin interface added. storage/innobase/handler/ha_innodb.cc: Maria plugin interface added. storage/innodb_plugin/handler/i_s.cc: Maria plugin interface added. storage/maria/ha_maria.cc: Maria plugin interface added. storage/myisam/ha_myisam.cc: Maria plugin interface added. storage/myisammrg/ha_myisammrg.cc: Maria plugin interface added. storage/pbxt/src/ha_pbxt.cc: Maria plugin interface added. storage/xtradb/handler/ha_innodb.cc: Maria plugin interface added. storage/xtradb/handler/i_s.cc: Maria plugin interface added. storage/xtradb/handler/i_s.h: Maria plugin interface added.
16 years ago
Maria WL#61 Interface for maria extensions. Alternative plugin interface with additional info (maturity and string version). CMakeLists.txt: Maria plugin interface used. config/ac-macros/plugins.m4: Maria plugin interface used. configure.in: Maria plugin interface used. include/mysql/plugin.h: Maria plugin interface added. include/mysql/plugin_auth.h.pp: Maria plugin interface added. plugin/auth/auth_socket.c: Maria plugin interface added. plugin/auth/dialog.c: Maria plugin interface added. plugin/daemon_example/daemon_example.cc: Maria plugin interface added. plugin/fulltext/plugin_example.c: Maria plugin interface added. sql/ha_ndbcluster.cc: Maria plugin interface added. sql/ha_partition.cc: Maria plugin interface added. sql/log.cc: Maria plugin interface added. sql/sql_acl.cc: Maria plugin interface added. sql/sql_builtin.cc.in: Maria plugin interface used. sql/sql_plugin.cc: Maria plugin interface added. sql/sql_plugin.h: Maria plugin interface used. sql/sql_show.cc: Maria plugin interface added. storage/archive/ha_archive.cc: Maria plugin interface added. storage/blackhole/ha_blackhole.cc: Maria plugin interface added. storage/csv/ha_tina.cc: Maria plugin interface added. storage/example/ha_example.cc: Maria plugin interface added. storage/federated/ha_federated.cc: Maria plugin interface added. storage/federatedx/ha_federatedx.cc: Maria plugin interface added. storage/heap/ha_heap.cc: Maria plugin interface added. storage/ibmdb2i/ha_ibmdb2i.cc: Maria plugin interface added. storage/innobase/handler/ha_innodb.cc: Maria plugin interface added. storage/innodb_plugin/handler/i_s.cc: Maria plugin interface added. storage/maria/ha_maria.cc: Maria plugin interface added. storage/myisam/ha_myisam.cc: Maria plugin interface added. storage/myisammrg/ha_myisammrg.cc: Maria plugin interface added. storage/pbxt/src/ha_pbxt.cc: Maria plugin interface added. storage/xtradb/handler/ha_innodb.cc: Maria plugin interface added. storage/xtradb/handler/i_s.cc: Maria plugin interface added. storage/xtradb/handler/i_s.h: Maria plugin interface added.
16 years ago
15 years ago
Maria WL#61 Interface for maria extensions. Alternative plugin interface with additional info (maturity and string version). CMakeLists.txt: Maria plugin interface used. config/ac-macros/plugins.m4: Maria plugin interface used. configure.in: Maria plugin interface used. include/mysql/plugin.h: Maria plugin interface added. include/mysql/plugin_auth.h.pp: Maria plugin interface added. plugin/auth/auth_socket.c: Maria plugin interface added. plugin/auth/dialog.c: Maria plugin interface added. plugin/daemon_example/daemon_example.cc: Maria plugin interface added. plugin/fulltext/plugin_example.c: Maria plugin interface added. sql/ha_ndbcluster.cc: Maria plugin interface added. sql/ha_partition.cc: Maria plugin interface added. sql/log.cc: Maria plugin interface added. sql/sql_acl.cc: Maria plugin interface added. sql/sql_builtin.cc.in: Maria plugin interface used. sql/sql_plugin.cc: Maria plugin interface added. sql/sql_plugin.h: Maria plugin interface used. sql/sql_show.cc: Maria plugin interface added. storage/archive/ha_archive.cc: Maria plugin interface added. storage/blackhole/ha_blackhole.cc: Maria plugin interface added. storage/csv/ha_tina.cc: Maria plugin interface added. storage/example/ha_example.cc: Maria plugin interface added. storage/federated/ha_federated.cc: Maria plugin interface added. storage/federatedx/ha_federatedx.cc: Maria plugin interface added. storage/heap/ha_heap.cc: Maria plugin interface added. storage/ibmdb2i/ha_ibmdb2i.cc: Maria plugin interface added. storage/innobase/handler/ha_innodb.cc: Maria plugin interface added. storage/innodb_plugin/handler/i_s.cc: Maria plugin interface added. storage/maria/ha_maria.cc: Maria plugin interface added. storage/myisam/ha_myisam.cc: Maria plugin interface added. storage/myisammrg/ha_myisammrg.cc: Maria plugin interface added. storage/pbxt/src/ha_pbxt.cc: Maria plugin interface added. storage/xtradb/handler/ha_innodb.cc: Maria plugin interface added. storage/xtradb/handler/i_s.cc: Maria plugin interface added. storage/xtradb/handler/i_s.h: Maria plugin interface added.
16 years ago
16 years ago
Fix for lp:711565 "Index Condition Pushdown can make a thread hold MyISAM locks as well as be unKILLable for long time" - In Maria/MyISAM: Release/re-acquire locks to give queries that wait on them a chance to make progress - In Maria/MyISAM: Change from numeric constants to ICP_RES values. - In Maria: Do check index condition in maria_rprev() (was lost in the merge/backport?) - In Maria/MyISAM/XtraDB: Check if the query was killed, and return immediately if it was. Added new storage engine error: HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted Authors: Sergey Petrunia & Monty include/my_base.h: Added HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted include/my_handler.h: Added comment mysql-test/r/myisam_icp.result: Updated test mysql-test/t/myisam_icp.test: Drop used tables at start of test Added test case that can help with manual testing of killing index condition pushdown query. mysys/my_handler_errors.h: Text for new storage engine error sql/handler.cc: If engine got HA_ERR_ABORTED_BY_USER, send kill message. sql/multi_range_read.cc: Return error code storage/maria/ha_maria.cc: Added ma_killed_in_mariadb() to detect kill. Ensure that file->external_ref points to TABLE object. storage/maria/ma_extra.c: Dummy test-if-killed for standalone storage/maria/ma_key.c: If ma_check_index_cond() fails, set my_errno and info->cur_row.lastpos storage/maria/ma_rkey.c: Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was storage/maria/ma_rnext.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rprev.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) and ma_check_index_cond() storage/maria/ma_search.c: Give error message if we find a wrong key storage/maria/ma_static.c: Added pointer to test-if-killed function storage/maria/maria_def.h: New prototypes storage/myisam/ha_myisam.cc: Added mi_killed_in_mariadb() Ensure that file->external_ref points to TABLE object. storage/myisam/mi_extra.c: Dummy test-if-killed for standalone storage/myisam/mi_key.c: If ma_check_index_cond() fails, set my_errno and info->lastpos storage/myisam/mi_rkey.c: Ensure that info->lastpos= HA_OFFSET_ERROR in case of error Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was Reorder code to do less things in case of error. Added missing fast_mi_writeinfo() storage/myisam/mi_rnext.c: Check if the query was killed, and return immediately if it was Simplify old ICP code Added missing fast_ma_writeinfo(info) storage/myisam/mi_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_mi_writeinfo(info) storage/myisam/mi_rprev.c: Check if the query was killed, and return immediately if it was Simplify error handling of ICP Added missing fast_mi_writeinfo(info) storage/myisam/mi_search.c: Give error message if we find a wrong key storage/myisam/mi_static.c: Added pointer to test-if-killed function storage/myisam/myisamdef.h: New prototypes storage/xtradb/handler/ha_innodb.cc: Added DB_SEARCH_ABORTED_BY_USER and ha_innobase::is_thd_killed() Check if the query was killed, and return immediately if it was storage/xtradb/handler/ha_innodb.h: Added prototype storage/xtradb/include/db0err.h: Added DB_SEARCH_ABORTED_BY_USER storage/xtradb/include/row0mysql.h: Added possible ICP errors storage/xtradb/row/row0sel.c: Use ICP errors instead of constants. Detect if killed and return B_SEARCH_ABORTED_BY_USER
15 years ago
Fix for lp:711565 "Index Condition Pushdown can make a thread hold MyISAM locks as well as be unKILLable for long time" - In Maria/MyISAM: Release/re-acquire locks to give queries that wait on them a chance to make progress - In Maria/MyISAM: Change from numeric constants to ICP_RES values. - In Maria: Do check index condition in maria_rprev() (was lost in the merge/backport?) - In Maria/MyISAM/XtraDB: Check if the query was killed, and return immediately if it was. Added new storage engine error: HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted Authors: Sergey Petrunia & Monty include/my_base.h: Added HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted include/my_handler.h: Added comment mysql-test/r/myisam_icp.result: Updated test mysql-test/t/myisam_icp.test: Drop used tables at start of test Added test case that can help with manual testing of killing index condition pushdown query. mysys/my_handler_errors.h: Text for new storage engine error sql/handler.cc: If engine got HA_ERR_ABORTED_BY_USER, send kill message. sql/multi_range_read.cc: Return error code storage/maria/ha_maria.cc: Added ma_killed_in_mariadb() to detect kill. Ensure that file->external_ref points to TABLE object. storage/maria/ma_extra.c: Dummy test-if-killed for standalone storage/maria/ma_key.c: If ma_check_index_cond() fails, set my_errno and info->cur_row.lastpos storage/maria/ma_rkey.c: Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was storage/maria/ma_rnext.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rprev.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) and ma_check_index_cond() storage/maria/ma_search.c: Give error message if we find a wrong key storage/maria/ma_static.c: Added pointer to test-if-killed function storage/maria/maria_def.h: New prototypes storage/myisam/ha_myisam.cc: Added mi_killed_in_mariadb() Ensure that file->external_ref points to TABLE object. storage/myisam/mi_extra.c: Dummy test-if-killed for standalone storage/myisam/mi_key.c: If ma_check_index_cond() fails, set my_errno and info->lastpos storage/myisam/mi_rkey.c: Ensure that info->lastpos= HA_OFFSET_ERROR in case of error Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was Reorder code to do less things in case of error. Added missing fast_mi_writeinfo() storage/myisam/mi_rnext.c: Check if the query was killed, and return immediately if it was Simplify old ICP code Added missing fast_ma_writeinfo(info) storage/myisam/mi_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_mi_writeinfo(info) storage/myisam/mi_rprev.c: Check if the query was killed, and return immediately if it was Simplify error handling of ICP Added missing fast_mi_writeinfo(info) storage/myisam/mi_search.c: Give error message if we find a wrong key storage/myisam/mi_static.c: Added pointer to test-if-killed function storage/myisam/myisamdef.h: New prototypes storage/xtradb/handler/ha_innodb.cc: Added DB_SEARCH_ABORTED_BY_USER and ha_innobase::is_thd_killed() Check if the query was killed, and return immediately if it was storage/xtradb/handler/ha_innodb.h: Added prototype storage/xtradb/include/db0err.h: Added DB_SEARCH_ABORTED_BY_USER storage/xtradb/include/row0mysql.h: Added possible ICP errors storage/xtradb/row/row0sel.c: Use ICP errors instead of constants. Detect if killed and return B_SEARCH_ABORTED_BY_USER
15 years ago
Fix for lp:711565 "Index Condition Pushdown can make a thread hold MyISAM locks as well as be unKILLable for long time" - In Maria/MyISAM: Release/re-acquire locks to give queries that wait on them a chance to make progress - In Maria/MyISAM: Change from numeric constants to ICP_RES values. - In Maria: Do check index condition in maria_rprev() (was lost in the merge/backport?) - In Maria/MyISAM/XtraDB: Check if the query was killed, and return immediately if it was. Added new storage engine error: HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted Authors: Sergey Petrunia & Monty include/my_base.h: Added HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted include/my_handler.h: Added comment mysql-test/r/myisam_icp.result: Updated test mysql-test/t/myisam_icp.test: Drop used tables at start of test Added test case that can help with manual testing of killing index condition pushdown query. mysys/my_handler_errors.h: Text for new storage engine error sql/handler.cc: If engine got HA_ERR_ABORTED_BY_USER, send kill message. sql/multi_range_read.cc: Return error code storage/maria/ha_maria.cc: Added ma_killed_in_mariadb() to detect kill. Ensure that file->external_ref points to TABLE object. storage/maria/ma_extra.c: Dummy test-if-killed for standalone storage/maria/ma_key.c: If ma_check_index_cond() fails, set my_errno and info->cur_row.lastpos storage/maria/ma_rkey.c: Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was storage/maria/ma_rnext.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rprev.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) and ma_check_index_cond() storage/maria/ma_search.c: Give error message if we find a wrong key storage/maria/ma_static.c: Added pointer to test-if-killed function storage/maria/maria_def.h: New prototypes storage/myisam/ha_myisam.cc: Added mi_killed_in_mariadb() Ensure that file->external_ref points to TABLE object. storage/myisam/mi_extra.c: Dummy test-if-killed for standalone storage/myisam/mi_key.c: If ma_check_index_cond() fails, set my_errno and info->lastpos storage/myisam/mi_rkey.c: Ensure that info->lastpos= HA_OFFSET_ERROR in case of error Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was Reorder code to do less things in case of error. Added missing fast_mi_writeinfo() storage/myisam/mi_rnext.c: Check if the query was killed, and return immediately if it was Simplify old ICP code Added missing fast_ma_writeinfo(info) storage/myisam/mi_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_mi_writeinfo(info) storage/myisam/mi_rprev.c: Check if the query was killed, and return immediately if it was Simplify error handling of ICP Added missing fast_mi_writeinfo(info) storage/myisam/mi_search.c: Give error message if we find a wrong key storage/myisam/mi_static.c: Added pointer to test-if-killed function storage/myisam/myisamdef.h: New prototypes storage/xtradb/handler/ha_innodb.cc: Added DB_SEARCH_ABORTED_BY_USER and ha_innobase::is_thd_killed() Check if the query was killed, and return immediately if it was storage/xtradb/handler/ha_innodb.h: Added prototype storage/xtradb/include/db0err.h: Added DB_SEARCH_ABORTED_BY_USER storage/xtradb/include/row0mysql.h: Added possible ICP errors storage/xtradb/row/row0sel.c: Use ICP errors instead of constants. Detect if killed and return B_SEARCH_ABORTED_BY_USER
15 years ago
  1. /*****************************************************************************
  2. Copyright (c) 2000, 2012, Oracle and/or its affiliates. All Rights Reserved.
  3. Copyright (c) 2008, 2009 Google Inc.
  4. Copyright (c) 2009, Percona Inc.
  5. Portions of this file contain modifications contributed and copyrighted by
  6. Google, Inc. Those modifications are gratefully acknowledged and are described
  7. briefly in the InnoDB documentation. The contributions by Google are
  8. incorporated with their permission, and subject to the conditions contained in
  9. the file COPYING.Google.
  10. Portions of this file contain modifications contributed and copyrighted
  11. by Percona Inc.. Those modifications are
  12. gratefully acknowledged and are described briefly in the InnoDB
  13. documentation. The contributions by Percona Inc. are incorporated with
  14. their permission, and subject to the conditions contained in the file
  15. COPYING.Percona.
  16. This program is free software; you can redistribute it and/or modify it under
  17. the terms of the GNU General Public License as published by the Free Software
  18. Foundation; version 2 of the License.
  19. This program is distributed in the hope that it will be useful, but WITHOUT
  20. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  21. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22. You should have received a copy of the GNU General Public License along with
  23. this program; if not, write to the Free Software Foundation, Inc.,
  24. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  25. *****************************************************************************/
  26. /* TODO list for the InnoDB handler in 5.0:
  27. - fix savepoint functions to use savepoint storage area
  28. - Find out what kind of problems the OS X case-insensitivity causes to
  29. table and database names; should we 'normalize' the names like we do
  30. in Windows?
  31. */
  32. #ifdef USE_PRAGMA_IMPLEMENTATION
  33. #pragma implementation // gcc: Class implementation
  34. #endif
  35. #define MYSQL_SERVER 1
  36. #include <sql_table.h> // explain_filename, nz2, EXPLAIN_PARTITIONS_AS_COMMENT,
  37. // EXPLAIN_FILENAME_MAX_EXTRA_LENGTH
  38. #include <sql_acl.h> // PROCESS_ACL
  39. #include <m_ctype.h>
  40. #include <debug_sync.h> // DEBUG_SYNC
  41. #include <mysys_err.h>
  42. #include <mysql/plugin.h>
  43. #include <innodb_priv.h>
  44. #include <mysql/psi/psi.h>
  45. #include <my_sys.h>
  46. #ifdef MYSQL_SERVER
  47. #include <rpl_mi.h>
  48. #include <slave.h>
  49. #include <log_event.h> // rpl_get_position_info
  50. #endif /* MYSQL_SERVER */
  51. #ifdef _WIN32
  52. #include <io.h>
  53. #endif
  54. /** @file ha_innodb.cc */
  55. /* Include necessary InnoDB headers */
  56. extern "C" {
  57. #include "univ.i"
  58. #include "buf0lru.h"
  59. #include "btr0sea.h"
  60. #include "os0file.h"
  61. #include "os0thread.h"
  62. #include "srv0start.h"
  63. #include "srv0srv.h"
  64. #include "trx0roll.h"
  65. #include "trx0trx.h"
  66. #include "trx0sys.h"
  67. #include "mtr0mtr.h"
  68. #include "row0ins.h"
  69. #include "row0mysql.h"
  70. #include "row0sel.h"
  71. #include "row0upd.h"
  72. #include "log0log.h"
  73. #include "lock0lock.h"
  74. #include "dict0crea.h"
  75. #include "btr0cur.h"
  76. #include "btr0btr.h"
  77. #include "fsp0fsp.h"
  78. #include "sync0sync.h"
  79. #include "fil0fil.h"
  80. #include "trx0xa.h"
  81. #include "row0merge.h"
  82. #include "dict0boot.h"
  83. #include "ha_prototypes.h"
  84. #include "ut0mem.h"
  85. #include "ibuf0ibuf.h"
  86. }
  87. #include "ha_innodb.h"
  88. #include "i_s.h"
  89. #ifdef MYSQL_SERVER
  90. // Defined in trx0sys.c
  91. extern char trx_sys_mysql_master_log_name[];
  92. extern ib_int64_t trx_sys_mysql_master_log_pos;
  93. extern char trx_sys_mysql_relay_log_name[];
  94. extern ib_int64_t trx_sys_mysql_relay_log_pos;
  95. #endif /* MYSQL_SERVER */
  96. # ifndef MYSQL_PLUGIN_IMPORT
  97. # define MYSQL_PLUGIN_IMPORT /* nothing */
  98. # endif /* MYSQL_PLUGIN_IMPORT */
  99. /** to protect innobase_open_files */
  100. static mysql_mutex_t innobase_share_mutex;
  101. static ulong commit_threads = 0;
  102. static mysql_mutex_t commit_threads_m;
  103. static mysql_cond_t commit_cond;
  104. static mysql_mutex_t commit_cond_m;
  105. static mysql_mutex_t pending_checkpoint_mutex;
  106. static bool innodb_inited = 0;
  107. #define INSIDE_HA_INNOBASE_CC
  108. /* In the Windows plugin, the return value of current_thd is
  109. undefined. Map it to NULL. */
  110. #define EQ_CURRENT_THD(thd) ((thd) == current_thd)
  111. static struct handlerton* innodb_hton_ptr;
  112. static const long AUTOINC_OLD_STYLE_LOCKING = 0;
  113. static const long AUTOINC_NEW_STYLE_LOCKING = 1;
  114. static const long AUTOINC_NO_LOCKING = 2;
  115. static long innobase_mirrored_log_groups, innobase_log_files_in_group,
  116. innobase_log_buffer_size,
  117. innobase_additional_mem_pool_size, innobase_file_io_threads,
  118. innobase_force_recovery, innobase_open_files,
  119. innobase_autoinc_lock_mode;
  120. static ulong innobase_commit_concurrency = 0;
  121. static ulong innobase_read_io_threads;
  122. static ulong innobase_write_io_threads;
  123. static long innobase_buffer_pool_instances = 1;
  124. static ulong innobase_page_size;
  125. static ulong innobase_log_block_size;
  126. static my_bool innobase_thread_concurrency_timer_based;
  127. static long long innobase_buffer_pool_size, innobase_log_file_size;
  128. /** Percentage of the buffer pool to reserve for 'old' blocks.
  129. Connected to buf_LRU_old_ratio. */
  130. static uint innobase_old_blocks_pct;
  131. /* The default values for the following char* start-up parameters
  132. are determined in innobase_init below: */
  133. static char* innobase_data_home_dir = NULL;
  134. static char* innobase_data_file_path = NULL;
  135. static char* innobase_log_group_home_dir = NULL;
  136. static char* innobase_file_format_name = NULL;
  137. static char* innobase_change_buffering = NULL;
  138. static char* innobase_doublewrite_file = NULL;
  139. /* The highest file format being used in the database. The value can be
  140. set by user, however, it will be adjusted to the newer file format if
  141. a table of such format is created/opened. */
  142. static char* innobase_file_format_max = NULL;
  143. static char* innobase_file_flush_method = NULL;
  144. /* Below we have boolean-valued start-up parameters, and their default
  145. values */
  146. static ulong innobase_fast_shutdown = 1;
  147. static my_bool innobase_file_format_check = TRUE;
  148. #ifdef UNIV_LOG_ARCHIVE
  149. static my_bool innobase_log_archive = FALSE;
  150. static char* innobase_log_arch_dir = NULL;
  151. #endif /* UNIV_LOG_ARCHIVE */
  152. static my_bool innobase_use_doublewrite = TRUE;
  153. static my_bool innobase_use_checksums = TRUE;
  154. static my_bool innobase_fast_checksum = FALSE;
  155. static my_bool innobase_recovery_stats = TRUE;
  156. static my_bool innobase_locks_unsafe_for_binlog = FALSE;
  157. static my_bool innobase_overwrite_relay_log_info = FALSE;
  158. static my_bool innobase_rollback_on_timeout = FALSE;
  159. static my_bool innobase_create_status_file = FALSE;
  160. static my_bool innobase_stats_on_metadata = TRUE;
  161. static my_bool innobase_large_prefix = FALSE;
  162. static my_bool innobase_use_sys_stats_table = FALSE;
  163. #ifdef UNIV_DEBUG
  164. static ulong innobase_sys_stats_root_page = 0;
  165. #endif
  166. static my_bool innobase_buffer_pool_shm_checksum = TRUE;
  167. static uint innobase_buffer_pool_shm_key = 0;
  168. static char* internal_innobase_data_file_path = NULL;
  169. static char* innodb_version_str = (char*) INNODB_VERSION_STR;
  170. static my_bool innobase_blocking_lru_restore = FALSE;
  171. /** Possible values for system variable "innodb_stats_method". The values
  172. are defined the same as its corresponding MyISAM system variable
  173. "myisam_stats_method"(see "myisam_stats_method_names"), for better usability */
  174. static const char* innodb_stats_method_names[] = {
  175. "nulls_equal",
  176. "nulls_unequal",
  177. "nulls_ignored",
  178. NullS
  179. };
  180. /** Used to define an enumerate type of the system variable innodb_stats_method.
  181. This is the same as "myisam_stats_method_typelib" */
  182. static TYPELIB innodb_stats_method_typelib = {
  183. array_elements(innodb_stats_method_names) - 1,
  184. "innodb_stats_method_typelib",
  185. innodb_stats_method_names,
  186. NULL
  187. };
  188. /* The following counter is used to convey information to InnoDB
  189. about server activity: in selects it is not sensible to call
  190. srv_active_wake_master_thread after each fetch or search, we only do
  191. it every INNOBASE_WAKE_INTERVAL'th step. */
  192. #define INNOBASE_WAKE_INTERVAL 32
  193. static ulong innobase_active_counter = 0;
  194. static hash_table_t* innobase_open_tables;
  195. /** Allowed values of innodb_change_buffering */
  196. static const char* innobase_change_buffering_values[IBUF_USE_COUNT] = {
  197. "none", /* IBUF_USE_NONE */
  198. "inserts", /* IBUF_USE_INSERT */
  199. "deletes", /* IBUF_USE_DELETE_MARK */
  200. "changes", /* IBUF_USE_INSERT_DELETE_MARK */
  201. "purges", /* IBUF_USE_DELETE */
  202. "all" /* IBUF_USE_ALL */
  203. };
  204. #ifdef HAVE_PSI_INTERFACE
  205. /* Keys to register pthread mutexes/cond in the current file with
  206. performance schema */
  207. static mysql_pfs_key_t innobase_share_mutex_key;
  208. static mysql_pfs_key_t commit_threads_m_key;
  209. static mysql_pfs_key_t commit_cond_mutex_key;
  210. static mysql_pfs_key_t commit_cond_key;
  211. static mysql_pfs_key_t pending_checkpoint_mutex_key;
  212. static PSI_mutex_info all_pthread_mutexes[] = {
  213. {&commit_threads_m_key, "commit_threads_m", 0},
  214. {&commit_cond_mutex_key, "commit_cond_mutex", 0},
  215. {&innobase_share_mutex_key, "innobase_share_mutex", 0},
  216. {&pending_checkpoint_mutex_key, "pending_checkpoint_mutex", 0}
  217. };
  218. static PSI_cond_info all_innodb_conds[] = {
  219. {&commit_cond_key, "commit_cond", 0}
  220. };
  221. # ifdef UNIV_PFS_MUTEX
  222. /* all_innodb_mutexes array contains mutexes that are
  223. performance schema instrumented if "UNIV_PFS_MUTEX"
  224. is defined */
  225. static PSI_mutex_info all_innodb_mutexes[] = {
  226. {&autoinc_mutex_key, "autoinc_mutex", 0},
  227. {&btr_search_enabled_mutex_key, "btr_search_enabled_mutex", 0},
  228. # ifndef PFS_SKIP_BUFFER_MUTEX_RWLOCK
  229. {&buffer_block_mutex_key, "buffer_block_mutex", 0},
  230. # endif /* !PFS_SKIP_BUFFER_MUTEX_RWLOCK */
  231. {&buf_pool_mutex_key, "buf_pool_mutex", 0},
  232. {&buf_pool_zip_mutex_key, "buf_pool_zip_mutex", 0},
  233. {&buf_pool_LRU_list_mutex_key, "buf_pool_LRU_list_mutex", 0},
  234. {&buf_pool_free_list_mutex_key, "buf_pool_free_list_mutex", 0},
  235. {&buf_pool_zip_free_mutex_key, "buf_pool_zip_free_mutex", 0},
  236. {&buf_pool_zip_hash_mutex_key, "buf_pool_zip_hash_mutex", 0},
  237. {&cache_last_read_mutex_key, "cache_last_read_mutex", 0},
  238. {&dict_foreign_err_mutex_key, "dict_foreign_err_mutex", 0},
  239. {&dict_sys_mutex_key, "dict_sys_mutex", 0},
  240. {&file_format_max_mutex_key, "file_format_max_mutex", 0},
  241. {&fil_system_mutex_key, "fil_system_mutex", 0},
  242. {&flush_list_mutex_key, "flush_list_mutex", 0},
  243. {&log_flush_order_mutex_key, "log_flush_order_mutex", 0},
  244. {&hash_table_mutex_key, "hash_table_mutex", 0},
  245. {&ibuf_bitmap_mutex_key, "ibuf_bitmap_mutex", 0},
  246. {&ibuf_mutex_key, "ibuf_mutex", 0},
  247. {&ibuf_pessimistic_insert_mutex_key,
  248. "ibuf_pessimistic_insert_mutex", 0},
  249. {&kernel_mutex_key, "kernel_mutex", 0},
  250. {&log_sys_mutex_key, "log_sys_mutex", 0},
  251. # ifdef UNIV_MEM_DEBUG
  252. {&mem_hash_mutex_key, "mem_hash_mutex", 0},
  253. # endif /* UNIV_MEM_DEBUG */
  254. {&mem_pool_mutex_key, "mem_pool_mutex", 0},
  255. {&mutex_list_mutex_key, "mutex_list_mutex", 0},
  256. {&purge_sys_bh_mutex_key, "purge_sys_bh_mutex", 0},
  257. {&recv_sys_mutex_key, "recv_sys_mutex", 0},
  258. {&rseg_mutex_key, "rseg_mutex", 0},
  259. # ifdef UNIV_SYNC_DEBUG
  260. {&rw_lock_debug_mutex_key, "rw_lock_debug_mutex", 0},
  261. # endif /* UNIV_SYNC_DEBUG */
  262. {&rw_lock_list_mutex_key, "rw_lock_list_mutex", 0},
  263. {&rw_lock_mutex_key, "rw_lock_mutex", 0},
  264. {&srv_dict_tmpfile_mutex_key, "srv_dict_tmpfile_mutex", 0},
  265. {&srv_innodb_monitor_mutex_key, "srv_innodb_monitor_mutex", 0},
  266. {&srv_misc_tmpfile_mutex_key, "srv_misc_tmpfile_mutex", 0},
  267. {&srv_monitor_file_mutex_key, "srv_monitor_file_mutex", 0},
  268. {&syn_arr_mutex_key, "syn_arr_mutex", 0},
  269. # ifdef UNIV_SYNC_DEBUG
  270. {&sync_thread_mutex_key, "sync_thread_mutex", 0},
  271. # endif /* UNIV_SYNC_DEBUG */
  272. {&trx_doublewrite_mutex_key, "trx_doublewrite_mutex", 0},
  273. {&trx_undo_mutex_key, "trx_undo_mutex", 0}
  274. };
  275. # endif /* UNIV_PFS_MUTEX */
  276. # ifdef UNIV_PFS_RWLOCK
  277. /* all_innodb_rwlocks array contains rwlocks that are
  278. performance schema instrumented if "UNIV_PFS_RWLOCK"
  279. is defined */
  280. static PSI_rwlock_info all_innodb_rwlocks[] = {
  281. # ifdef UNIV_LOG_ARCHIVE
  282. {&archive_lock_key, "archive_lock", 0},
  283. # endif /* UNIV_LOG_ARCHIVE */
  284. {&btr_search_latch_key, "btr_search_latch", 0},
  285. {&buf_pool_page_hash_key, "buf_pool_page_hash_latch", 0},
  286. # ifndef PFS_SKIP_BUFFER_MUTEX_RWLOCK
  287. {&buf_block_lock_key, "buf_block_lock", 0},
  288. # endif /* !PFS_SKIP_BUFFER_MUTEX_RWLOCK */
  289. # ifdef UNIV_SYNC_DEBUG
  290. {&buf_block_debug_latch_key, "buf_block_debug_latch", 0},
  291. # endif /* UNIV_SYNC_DEBUG */
  292. {&dict_operation_lock_key, "dict_operation_lock", 0},
  293. {&fil_space_latch_key, "fil_space_latch", 0},
  294. {&checkpoint_lock_key, "checkpoint_lock", 0},
  295. {&trx_i_s_cache_lock_key, "trx_i_s_cache_lock", 0},
  296. {&trx_purge_latch_key, "trx_purge_latch", 0},
  297. {&index_tree_rw_lock_key, "index_tree_rw_lock", 0},
  298. {&dict_table_stats_latch_key, "dict_table_stats", 0}
  299. };
  300. # endif /* UNIV_PFS_RWLOCK */
  301. # ifdef UNIV_PFS_THREAD
  302. /* all_innodb_threads array contains threads that are
  303. performance schema instrumented if "UNIV_PFS_THREAD"
  304. is defined */
  305. static PSI_thread_info all_innodb_threads[] = {
  306. {&trx_rollback_clean_thread_key, "trx_rollback_clean_thread", 0},
  307. {&io_handler_thread_key, "io_handler_thread", 0},
  308. {&srv_lock_timeout_thread_key, "srv_lock_timeout_thread", 0},
  309. {&srv_error_monitor_thread_key, "srv_error_monitor_thread", 0},
  310. {&srv_monitor_thread_key, "srv_monitor_thread", 0},
  311. {&srv_master_thread_key, "srv_master_thread", 0},
  312. {&srv_purge_thread_key, "srv_purge_thread", 0}
  313. };
  314. # endif /* UNIV_PFS_THREAD */
  315. # ifdef UNIV_PFS_IO
  316. /* all_innodb_files array contains the type of files that are
  317. performance schema instrumented if "UNIV_PFS_IO" is defined */
  318. static PSI_file_info all_innodb_files[] = {
  319. {&innodb_file_data_key, "innodb_data_file", 0},
  320. {&innodb_file_log_key, "innodb_log_file", 0},
  321. {&innodb_file_temp_key, "innodb_temp_file", 0}
  322. };
  323. # endif /* UNIV_PFS_IO */
  324. #endif /* HAVE_PSI_INTERFACE */
  325. static INNOBASE_SHARE *get_share(const char *table_name);
  326. static void free_share(INNOBASE_SHARE *share);
  327. static int innobase_close_connection(handlerton *hton, THD* thd);
  328. static void innobase_commit_ordered(handlerton *hton, THD* thd, bool all);
  329. static int innobase_commit(handlerton *hton, THD* thd, bool all);
  330. static int innobase_rollback(handlerton *hton, THD* thd, bool all);
  331. static int innobase_rollback_to_savepoint(handlerton *hton, THD* thd,
  332. void *savepoint);
  333. static int innobase_savepoint(handlerton *hton, THD* thd, void *savepoint);
  334. static int innobase_release_savepoint(handlerton *hton, THD* thd,
  335. void *savepoint);
  336. static void innobase_checkpoint_request(handlerton *hton, void *cookie);
  337. static handler *innobase_create_handler(handlerton *hton,
  338. TABLE_SHARE *table,
  339. MEM_ROOT *mem_root);
  340. /* "GEN_CLUST_INDEX" is the name reserved for Innodb default
  341. system primary index. */
  342. static const char innobase_index_reserve_name[]= "GEN_CLUST_INDEX";
  343. /** @brief Initialize the default value of innodb_commit_concurrency.
  344. Once InnoDB is running, the innodb_commit_concurrency must not change
  345. from zero to nonzero. (Bug #42101)
  346. The initial default value is 0, and without this extra initialization,
  347. SET GLOBAL innodb_commit_concurrency=DEFAULT would set the parameter
  348. to 0, even if it was initially set to nonzero at the command line
  349. or configuration file. */
  350. static
  351. void
  352. innobase_commit_concurrency_init_default(void);
  353. /*==========================================*/
  354. /************************************************************//**
  355. Validate the file format name and return its corresponding id.
  356. @return valid file format id */
  357. static
  358. uint
  359. innobase_file_format_name_lookup(
  360. /*=============================*/
  361. const char* format_name); /*!< in: pointer to file format
  362. name */
  363. /************************************************************//**
  364. Validate the file format check config parameters, as a side effect it
  365. sets the srv_max_file_format_at_startup variable.
  366. @return the format_id if valid config value, otherwise, return -1 */
  367. static
  368. int
  369. innobase_file_format_validate_and_set(
  370. /*==================================*/
  371. const char* format_max); /*!< in: parameter value */
  372. /****************************************************************//**
  373. Return alter table flags supported in an InnoDB database. */
  374. static
  375. uint
  376. innobase_alter_table_flags(
  377. /*=======================*/
  378. uint flags);
  379. static const char innobase_hton_name[]= "InnoDB";
  380. /*************************************************************//**
  381. Check for a valid value of innobase_commit_concurrency.
  382. @return 0 for valid innodb_commit_concurrency */
  383. static
  384. int
  385. innobase_commit_concurrency_validate(
  386. /*=================================*/
  387. THD* thd, /*!< in: thread handle */
  388. struct st_mysql_sys_var* var, /*!< in: pointer to system
  389. variable */
  390. void* save, /*!< out: immediate result
  391. for update function */
  392. struct st_mysql_value* value) /*!< in: incoming string */
  393. {
  394. long long intbuf;
  395. ulong commit_concurrency;
  396. DBUG_ENTER("innobase_commit_concurrency_validate");
  397. if (value->val_int(value, &intbuf)) {
  398. /* The value is NULL. That is invalid. */
  399. DBUG_RETURN(1);
  400. }
  401. *reinterpret_cast<ulong*>(save) = commit_concurrency
  402. = static_cast<ulong>(intbuf);
  403. /* Allow the value to be updated, as long as it remains zero
  404. or nonzero. */
  405. DBUG_RETURN(!(!commit_concurrency == !innobase_commit_concurrency));
  406. }
  407. static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
  408. "Enable InnoDB support for the XA two-phase commit",
  409. /* check_func */ NULL, /* update_func */ NULL,
  410. /* default */ TRUE);
  411. static MYSQL_THDVAR_BOOL(table_locks, PLUGIN_VAR_OPCMDARG,
  412. "Enable InnoDB locking in LOCK TABLES",
  413. /* check_func */ NULL, /* update_func */ NULL,
  414. /* default */ TRUE);
  415. static MYSQL_THDVAR_BOOL(strict_mode, PLUGIN_VAR_OPCMDARG,
  416. "Use strict mode when evaluating create options.",
  417. NULL, NULL, FALSE);
  418. static MYSQL_THDVAR_ULONG(lock_wait_timeout, PLUGIN_VAR_RQCMDARG,
  419. "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
  420. NULL, NULL, 50, 1, 1024 * 1024 * 1024, 0);
  421. static MYSQL_THDVAR_ULONG(flush_log_at_trx_commit, PLUGIN_VAR_OPCMDARG,
  422. "Controls the durability/speed trade-off for commits."
  423. " Set to 0 (write and flush redo log to disk only once per second),"
  424. " 1 (flush to disk at each commit),"
  425. " 2 (write to log at commit but flush to disk only once per second)"
  426. " or 3 (flush to disk at prepare and at commit, slower and usually redundant)."
  427. " 1 and 3 guarantees that after a crash, committed transactions will"
  428. " not be lost and will be consistent with the binlog and other transactional"
  429. " engines. 2 can get inconsistent and lose transactions if there is a"
  430. " power failure or kernel crash but not if mysqld crashes. 0 has no"
  431. " guarantees in case of crash. 0 and 2 can be faster than 1 or 3.",
  432. NULL, NULL, 1, 0, 3, 0);
  433. static MYSQL_THDVAR_BOOL(fake_changes, PLUGIN_VAR_OPCMDARG,
  434. "In the transaction after enabled, UPDATE, INSERT and DELETE only move the cursor to the records "
  435. "and do nothing other operations (no changes, no ibuf, no undo, no transaction log) in the transaction. "
  436. "This is to cause replication prefetch IO. ATTENTION: the transaction started after enabled is affected.",
  437. NULL, NULL, FALSE);
  438. static MYSQL_THDVAR_ULONG(merge_sort_block_size, PLUGIN_VAR_RQCMDARG,
  439. "The block size used doing external merge-sort for secondary index creation.",
  440. NULL, NULL, 1UL << 20, 1UL << 20, 1UL << 30, 0);
  441. static handler *innobase_create_handler(handlerton *hton,
  442. TABLE_SHARE *table,
  443. MEM_ROOT *mem_root)
  444. {
  445. return new (mem_root) ha_innobase(hton, table);
  446. }
  447. /*******************************************************************//**
  448. This function is used to prepare an X/Open XA distributed transaction.
  449. @return 0 or error number */
  450. static
  451. int
  452. innobase_xa_prepare(
  453. /*================*/
  454. handlerton* hton, /*!< in: InnoDB handlerton */
  455. THD* thd, /*!< in: handle to the MySQL thread of
  456. the user whose XA transaction should
  457. be prepared */
  458. bool all); /*!< in: TRUE - commit transaction
  459. FALSE - the current SQL statement
  460. ended */
  461. /*******************************************************************//**
  462. This function is used to recover X/Open XA distributed transactions.
  463. @return number of prepared transactions stored in xid_list */
  464. static
  465. int
  466. innobase_xa_recover(
  467. /*================*/
  468. handlerton* hton, /*!< in: InnoDB handlerton */
  469. XID* xid_list,/*!< in/out: prepared transactions */
  470. uint len); /*!< in: number of slots in xid_list */
  471. /*******************************************************************//**
  472. This function is used to commit one X/Open XA distributed transaction
  473. which is in the prepared state
  474. @return 0 or error number */
  475. static
  476. int
  477. innobase_commit_by_xid(
  478. /*===================*/
  479. handlerton* hton,
  480. XID* xid); /*!< in: X/Open XA transaction identification */
  481. /*******************************************************************//**
  482. This function is used to rollback one X/Open XA distributed transaction
  483. which is in the prepared state
  484. @return 0 or error number */
  485. static
  486. int
  487. innobase_rollback_by_xid(
  488. /*=====================*/
  489. handlerton* hton, /*!< in: InnoDB handlerton */
  490. XID* xid); /*!< in: X/Open XA transaction
  491. identification */
  492. /*******************************************************************//**
  493. Create a consistent view for a cursor based on current transaction
  494. which is created if the corresponding MySQL thread still lacks one.
  495. This consistent view is then used inside of MySQL when accessing records
  496. using a cursor.
  497. @return pointer to cursor view or NULL */
  498. static
  499. void*
  500. innobase_create_cursor_view(
  501. /*========================*/
  502. handlerton* hton, /*!< in: innobase hton */
  503. THD* thd); /*!< in: user thread handle */
  504. /*******************************************************************//**
  505. Set the given consistent cursor view to a transaction which is created
  506. if the corresponding MySQL thread still lacks one. If the given
  507. consistent cursor view is NULL global read view of a transaction is
  508. restored to a transaction read view. */
  509. static
  510. void
  511. innobase_set_cursor_view(
  512. /*=====================*/
  513. handlerton* hton,
  514. THD* thd, /*!< in: user thread handle */
  515. void* curview);/*!< in: Consistent cursor view to be set */
  516. /*******************************************************************//**
  517. Close the given consistent cursor view of a transaction and restore
  518. global read view to a transaction read view. Transaction is created if the
  519. corresponding MySQL thread still lacks one. */
  520. static
  521. void
  522. innobase_close_cursor_view(
  523. /*=======================*/
  524. handlerton* hton,
  525. THD* thd, /*!< in: user thread handle */
  526. void* curview);/*!< in: Consistent read view to be closed */
  527. /*****************************************************************//**
  528. Removes all tables in the named database inside InnoDB. */
  529. static
  530. void
  531. innobase_drop_database(
  532. /*===================*/
  533. handlerton* hton, /*!< in: handlerton of Innodb */
  534. char* path); /*!< in: database path; inside InnoDB the name
  535. of the last directory in the path is used as
  536. the database name: for example, in 'mysql/data/test'
  537. the database name is 'test' */
  538. /*******************************************************************//**
  539. Closes an InnoDB database. */
  540. static
  541. int
  542. innobase_end(handlerton *hton, ha_panic_function type);
  543. /*****************************************************************//**
  544. Creates an InnoDB transaction struct for the thd if it does not yet have one.
  545. Starts a new InnoDB transaction if a transaction is not yet started. And
  546. assigns a new snapshot for a consistent read if the transaction does not yet
  547. have one.
  548. @return 0 */
  549. static
  550. int
  551. innobase_start_trx_and_assign_read_view(
  552. /*====================================*/
  553. /* out: 0 */
  554. handlerton* hton, /* in: Innodb handlerton */
  555. THD* thd); /* in: MySQL thread handle of the user for whom
  556. the transaction should be committed */
  557. /****************************************************************//**
  558. Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
  559. the logs, and the name of this function should be innobase_checkpoint.
  560. @return TRUE if error */
  561. static
  562. bool
  563. innobase_flush_logs(
  564. /*================*/
  565. handlerton* hton); /*!< in: InnoDB handlerton */
  566. /************************************************************************//**
  567. Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
  568. Monitor to the client. */
  569. static
  570. bool
  571. innodb_show_status(
  572. /*===============*/
  573. handlerton* hton, /*!< in: the innodb handlerton */
  574. THD* thd, /*!< in: the MySQL query thread of the caller */
  575. stat_print_fn *stat_print);
  576. static
  577. bool innobase_show_status(handlerton *hton, THD* thd,
  578. stat_print_fn* stat_print,
  579. enum ha_stat_type stat_type);
  580. /* Enable / disable checkpoints */
  581. static int innobase_checkpoint_state(handlerton *hton, bool disable)
  582. {
  583. if (disable)
  584. (void) log_disable_checkpoint();
  585. else
  586. log_enable_checkpoint();
  587. return 0;
  588. }
  589. /*****************************************************************//**
  590. Commits a transaction in an InnoDB database. */
  591. static
  592. void
  593. innobase_commit_low(
  594. /*================*/
  595. trx_t* trx); /*!< in: transaction handle */
  596. static SHOW_VAR innodb_status_variables[]= {
  597. {"adaptive_hash_cells",
  598. (char*) &export_vars.innodb_adaptive_hash_cells, SHOW_LONG},
  599. {"adaptive_hash_heap_buffers",
  600. (char*) &export_vars.innodb_adaptive_hash_heap_buffers, SHOW_LONG},
  601. {"adaptive_hash_hash_searches",
  602. (char*) &export_vars.innodb_adaptive_hash_hash_searches, SHOW_LONG},
  603. {"adaptive_hash_non_hash_searches",
  604. (char*) &export_vars.innodb_adaptive_hash_non_hash_searches, SHOW_LONG},
  605. {"background_log_sync",
  606. (char*) &export_vars.innodb_background_log_sync, SHOW_LONG},
  607. {"buffer_pool_pages_data",
  608. (char*) &export_vars.innodb_buffer_pool_pages_data, SHOW_LONG},
  609. {"buffer_pool_pages_dirty",
  610. (char*) &export_vars.innodb_buffer_pool_pages_dirty, SHOW_LONG},
  611. {"buffer_pool_pages_flushed",
  612. (char*) &export_vars.innodb_buffer_pool_pages_flushed, SHOW_LONG},
  613. {"buffer_pool_pages_LRU_flushed",
  614. (char*) &export_vars.innodb_buffer_pool_pages_LRU_flushed, SHOW_LONG},
  615. {"buffer_pool_pages_free",
  616. (char*) &export_vars.innodb_buffer_pool_pages_free, SHOW_LONG},
  617. #ifdef UNIV_DEBUG
  618. {"buffer_pool_pages_latched",
  619. (char*) &export_vars.innodb_buffer_pool_pages_latched, SHOW_LONG},
  620. #endif /* UNIV_DEBUG */
  621. {"buffer_pool_pages_made_not_young",
  622. (char*) &export_vars.innodb_buffer_pool_pages_made_not_young, SHOW_LONG},
  623. {"buffer_pool_pages_made_young",
  624. (char*) &export_vars.innodb_buffer_pool_pages_made_young, SHOW_LONG},
  625. {"buffer_pool_pages_misc",
  626. (char*) &export_vars.innodb_buffer_pool_pages_misc, SHOW_LONG},
  627. {"buffer_pool_pages_old",
  628. (char*) &export_vars.innodb_buffer_pool_pages_old, SHOW_LONG},
  629. {"buffer_pool_pages_total",
  630. (char*) &export_vars.innodb_buffer_pool_pages_total, SHOW_LONG},
  631. {"buffer_pool_read_ahead_rnd",
  632. (char*) &export_vars.innodb_buffer_pool_read_ahead_rnd, SHOW_LONG},
  633. {"buffer_pool_read_ahead",
  634. (char*) &export_vars.innodb_buffer_pool_read_ahead, SHOW_LONG},
  635. {"buffer_pool_read_ahead_evicted",
  636. (char*) &export_vars.innodb_buffer_pool_read_ahead_evicted, SHOW_LONG},
  637. {"buffer_pool_read_requests",
  638. (char*) &export_vars.innodb_buffer_pool_read_requests, SHOW_LONG},
  639. {"buffer_pool_reads",
  640. (char*) &export_vars.innodb_buffer_pool_reads, SHOW_LONG},
  641. {"buffer_pool_wait_free",
  642. (char*) &export_vars.innodb_buffer_pool_wait_free, SHOW_LONG},
  643. {"buffer_pool_write_requests",
  644. (char*) &export_vars.innodb_buffer_pool_write_requests, SHOW_LONG},
  645. {"checkpoint_age",
  646. (char*) &export_vars.innodb_checkpoint_age, SHOW_LONG},
  647. {"checkpoint_max_age",
  648. (char*) &export_vars.innodb_checkpoint_max_age, SHOW_LONG},
  649. {"checkpoint_target_age",
  650. (char*) &export_vars.innodb_checkpoint_target_age, SHOW_LONG},
  651. {"data_fsyncs",
  652. (char*) &export_vars.innodb_data_fsyncs, SHOW_LONG},
  653. {"data_pending_fsyncs",
  654. (char*) &export_vars.innodb_data_pending_fsyncs, SHOW_LONG},
  655. {"data_pending_reads",
  656. (char*) &export_vars.innodb_data_pending_reads, SHOW_LONG},
  657. {"data_pending_writes",
  658. (char*) &export_vars.innodb_data_pending_writes, SHOW_LONG},
  659. {"data_read",
  660. (char*) &export_vars.innodb_data_read, SHOW_LONG},
  661. {"data_reads",
  662. (char*) &export_vars.innodb_data_reads, SHOW_LONG},
  663. {"data_writes",
  664. (char*) &export_vars.innodb_data_writes, SHOW_LONG},
  665. {"data_written",
  666. (char*) &export_vars.innodb_data_written, SHOW_LONG},
  667. {"dblwr_pages_written",
  668. (char*) &export_vars.innodb_dblwr_pages_written, SHOW_LONG},
  669. {"dblwr_writes",
  670. (char*) &export_vars.innodb_dblwr_writes, SHOW_LONG},
  671. {"deadlocks",
  672. (char*) &export_vars.innodb_deadlocks, SHOW_LONG},
  673. {"dict_tables",
  674. (char*) &export_vars.innodb_dict_tables, SHOW_LONG},
  675. {"have_atomic_builtins",
  676. (char*) &export_vars.innodb_have_atomic_builtins, SHOW_BOOL},
  677. {"history_list_length",
  678. (char*) &export_vars.innodb_history_list_length, SHOW_LONG},
  679. {"ibuf_discarded_delete_marks",
  680. (char*) &export_vars.innodb_ibuf_discarded_delete_marks, SHOW_LONG},
  681. {"ibuf_discarded_deletes",
  682. (char*) &export_vars.innodb_ibuf_discarded_deletes, SHOW_LONG},
  683. {"ibuf_discarded_inserts",
  684. (char*) &export_vars.innodb_ibuf_discarded_inserts, SHOW_LONG},
  685. {"ibuf_free_list",
  686. (char*) &export_vars.innodb_ibuf_free_list, SHOW_LONG},
  687. {"ibuf_merged_delete_marks",
  688. (char*) &export_vars.innodb_ibuf_merged_delete_marks, SHOW_LONG},
  689. {"ibuf_merged_deletes",
  690. (char*) &export_vars.innodb_ibuf_merged_deletes, SHOW_LONG},
  691. {"ibuf_merged_inserts",
  692. (char*) &export_vars.innodb_ibuf_merged_inserts, SHOW_LONG},
  693. {"ibuf_merges",
  694. (char*) &export_vars.innodb_ibuf_merges, SHOW_LONG},
  695. {"ibuf_segment_size",
  696. (char*) &export_vars.innodb_ibuf_segment_size, SHOW_LONG},
  697. {"ibuf_size",
  698. (char*) &export_vars.innodb_ibuf_size, SHOW_LONG},
  699. {"log_waits",
  700. (char*) &export_vars.innodb_log_waits, SHOW_LONG},
  701. {"log_write_requests",
  702. (char*) &export_vars.innodb_log_write_requests, SHOW_LONG},
  703. {"log_writes",
  704. (char*) &export_vars.innodb_log_writes, SHOW_LONG},
  705. {"lsn_current",
  706. (char*) &export_vars.innodb_lsn_current, SHOW_LONGLONG},
  707. {"lsn_flushed",
  708. (char*) &export_vars.innodb_lsn_flushed, SHOW_LONGLONG},
  709. {"lsn_last_checkpoint",
  710. (char*) &export_vars.innodb_lsn_last_checkpoint, SHOW_LONGLONG},
  711. {"master_thread_1_second_loops",
  712. (char*) &export_vars.innodb_master_thread_1_second_loops, SHOW_LONG},
  713. {"master_thread_10_second_loops",
  714. (char*) &export_vars.innodb_master_thread_10_second_loops, SHOW_LONG},
  715. {"master_thread_background_loops",
  716. (char*) &export_vars.innodb_master_thread_background_loops, SHOW_LONG},
  717. {"master_thread_main_flush_loops",
  718. (char*) &export_vars.innodb_master_thread_main_flush_loops, SHOW_LONG},
  719. {"master_thread_sleeps",
  720. (char*) &export_vars.innodb_master_thread_sleeps, SHOW_LONG},
  721. {"max_trx_id",
  722. (char*) &export_vars.innodb_max_trx_id, SHOW_LONGLONG},
  723. {"mem_adaptive_hash",
  724. (char*) &export_vars.innodb_mem_adaptive_hash, SHOW_LONG},
  725. {"mem_dictionary",
  726. (char*) &export_vars.innodb_mem_dictionary, SHOW_LONG},
  727. {"mem_total",
  728. (char*) &export_vars.innodb_mem_total, SHOW_LONG},
  729. {"mutex_os_waits",
  730. (char*) &export_vars.innodb_mutex_os_waits, SHOW_LONGLONG},
  731. {"mutex_spin_rounds",
  732. (char*) &export_vars.innodb_mutex_spin_rounds, SHOW_LONGLONG},
  733. {"mutex_spin_waits",
  734. (char*) &export_vars.innodb_mutex_spin_waits, SHOW_LONGLONG},
  735. {"oldest_view_low_limit_trx_id",
  736. (char*) &export_vars.innodb_oldest_view_low_limit_trx_id, SHOW_LONGLONG},
  737. {"os_log_fsyncs",
  738. (char*) &export_vars.innodb_os_log_fsyncs, SHOW_LONG},
  739. {"os_log_pending_fsyncs",
  740. (char*) &export_vars.innodb_os_log_pending_fsyncs, SHOW_LONG},
  741. {"os_log_pending_writes",
  742. (char*) &export_vars.innodb_os_log_pending_writes, SHOW_LONG},
  743. {"os_log_written",
  744. (char*) &export_vars.innodb_os_log_written, SHOW_LONG},
  745. {"page_size",
  746. (char*) &export_vars.innodb_page_size, SHOW_LONG},
  747. {"pages_created",
  748. (char*) &export_vars.innodb_pages_created, SHOW_LONG},
  749. {"pages_read",
  750. (char*) &export_vars.innodb_pages_read, SHOW_LONG},
  751. {"pages_written",
  752. (char*) &export_vars.innodb_pages_written, SHOW_LONG},
  753. {"purge_trx_id",
  754. (char*) &export_vars.innodb_purge_trx_id, SHOW_LONGLONG},
  755. {"purge_undo_no",
  756. (char*) &export_vars.innodb_purge_undo_no, SHOW_LONGLONG},
  757. {"row_lock_current_waits",
  758. (char*) &export_vars.innodb_row_lock_current_waits, SHOW_LONG},
  759. {"current_row_locks",
  760. (char*) &export_vars.innodb_current_row_locks, SHOW_LONG},
  761. {"row_lock_time",
  762. (char*) &export_vars.innodb_row_lock_time, SHOW_LONGLONG},
  763. {"row_lock_time_avg",
  764. (char*) &export_vars.innodb_row_lock_time_avg, SHOW_LONG},
  765. {"row_lock_time_max",
  766. (char*) &export_vars.innodb_row_lock_time_max, SHOW_LONG},
  767. {"row_lock_waits",
  768. (char*) &export_vars.innodb_row_lock_waits, SHOW_LONG},
  769. {"rows_deleted",
  770. (char*) &export_vars.innodb_rows_deleted, SHOW_LONG},
  771. {"rows_inserted",
  772. (char*) &export_vars.innodb_rows_inserted, SHOW_LONG},
  773. {"rows_read",
  774. (char*) &export_vars.innodb_rows_read, SHOW_LONG},
  775. {"rows_updated",
  776. (char*) &export_vars.innodb_rows_updated, SHOW_LONG},
  777. {"s_lock_os_waits",
  778. (char*) &export_vars.innodb_s_lock_os_waits, SHOW_LONGLONG},
  779. {"s_lock_spin_rounds",
  780. (char*) &export_vars.innodb_s_lock_spin_rounds, SHOW_LONGLONG},
  781. {"s_lock_spin_waits",
  782. (char*) &export_vars.innodb_s_lock_spin_waits, SHOW_LONGLONG},
  783. {"truncated_status_writes",
  784. (char*) &export_vars.innodb_truncated_status_writes, SHOW_LONG},
  785. {"x_lock_os_waits",
  786. (char*) &export_vars.innodb_x_lock_os_waits, SHOW_LONGLONG},
  787. {"x_lock_spin_rounds",
  788. (char*) &export_vars.innodb_x_lock_spin_rounds, SHOW_LONGLONG},
  789. {"x_lock_spin_waits",
  790. (char*) &export_vars.innodb_x_lock_spin_waits, SHOW_LONGLONG},
  791. {NullS, NullS, SHOW_LONG}
  792. };
  793. /* General functions */
  794. /******************************************************************//**
  795. Returns true if the thread is the replication thread on the slave
  796. server. Used in srv_conc_enter_innodb() to determine if the thread
  797. should be allowed to enter InnoDB - the replication thread is treated
  798. differently than other threads. Also used in
  799. srv_conc_force_exit_innodb().
  800. @return true if thd is the replication thread */
  801. extern "C" UNIV_INTERN
  802. ibool
  803. thd_is_replication_slave_thread(
  804. /*============================*/
  805. void* thd) /*!< in: thread handle (THD*) */
  806. {
  807. return((ibool) thd_slave_thread((THD*) thd));
  808. }
  809. /******************************************************************//**
  810. Save some CPU by testing the value of srv_thread_concurrency in inline
  811. functions. */
  812. static inline
  813. void
  814. innodb_srv_conc_enter_innodb(
  815. /*=========================*/
  816. trx_t* trx) /*!< in: transaction handle */
  817. {
  818. if (UNIV_LIKELY(!srv_thread_concurrency)) {
  819. return;
  820. }
  821. srv_conc_enter_innodb(trx);
  822. }
  823. /******************************************************************//**
  824. Save some CPU by testing the value of srv_thread_concurrency in inline
  825. functions. */
  826. static inline
  827. void
  828. innodb_srv_conc_exit_innodb(
  829. /*========================*/
  830. trx_t* trx) /*!< in: transaction handle */
  831. {
  832. if (UNIV_LIKELY(!trx->declared_to_be_inside_innodb)) {
  833. return;
  834. }
  835. srv_conc_exit_innodb(trx);
  836. }
  837. /******************************************************************//**
  838. Releases possible search latch and InnoDB thread FIFO ticket. These should
  839. be released at each SQL statement end, and also when mysqld passes the
  840. control to the client. It does no harm to release these also in the middle
  841. of an SQL statement. */
  842. static inline
  843. void
  844. innobase_release_stat_resources(
  845. /*============================*/
  846. trx_t* trx) /*!< in: transaction object */
  847. {
  848. if (trx->has_search_latch) {
  849. trx_search_latch_release_if_reserved(trx);
  850. }
  851. if (trx->declared_to_be_inside_innodb) {
  852. /* Release our possible ticket in the FIFO */
  853. srv_conc_force_exit_innodb(trx);
  854. }
  855. }
  856. /******************************************************************//**
  857. Returns true if the transaction this thread is processing has edited
  858. non-transactional tables. Used by the deadlock detector when deciding
  859. which transaction to rollback in case of a deadlock - we try to avoid
  860. rolling back transactions that have edited non-transactional tables.
  861. @return true if non-transactional tables have been edited */
  862. extern "C" UNIV_INTERN
  863. ibool
  864. thd_has_edited_nontrans_tables(
  865. /*===========================*/
  866. void* thd) /*!< in: thread handle (THD*) */
  867. {
  868. return((ibool) thd_non_transactional_update((THD*) thd));
  869. }
  870. /******************************************************************//**
  871. Returns true if the thread is executing a SELECT statement.
  872. @return true if thd is executing SELECT */
  873. extern "C" UNIV_INTERN
  874. ibool
  875. thd_is_select(
  876. /*==========*/
  877. const void* thd) /*!< in: thread handle (THD*) */
  878. {
  879. return(thd_sql_command((const THD*) thd) == SQLCOM_SELECT);
  880. }
  881. /******************************************************************//**
  882. Returns true if the thread supports XA,
  883. global value of innodb_supports_xa if thd is NULL.
  884. @return true if thd has XA support */
  885. extern "C" UNIV_INTERN
  886. ibool
  887. thd_supports_xa(
  888. /*============*/
  889. void* thd) /*!< in: thread handle (THD*), or NULL to query
  890. the global innodb_supports_xa */
  891. {
  892. return(THDVAR((THD*) thd, support_xa));
  893. }
  894. /******************************************************************//**
  895. Returns the lock wait timeout for the current connection.
  896. @return the lock wait timeout, in seconds */
  897. extern "C" UNIV_INTERN
  898. ulong
  899. thd_lock_wait_timeout(
  900. /*==================*/
  901. void* thd) /*!< in: thread handle (THD*), or NULL to query
  902. the global innodb_lock_wait_timeout */
  903. {
  904. /* According to <mysql/plugin.h>, passing thd == NULL
  905. returns the global value of the session variable. */
  906. return(THDVAR((THD*) thd, lock_wait_timeout));
  907. }
  908. /******************************************************************//**
  909. Set the time waited for the lock for the current query. */
  910. extern "C" UNIV_INTERN
  911. void
  912. thd_set_lock_wait_time(
  913. /*===================*/
  914. void* thd, /*!< in: thread handle (THD*) */
  915. ulint value) /*!< in: time waited for the lock */
  916. {
  917. if (thd) {
  918. thd_storage_lock_wait((THD*)thd, value);
  919. }
  920. }
  921. /******************************************************************//**
  922. */
  923. extern "C" UNIV_INTERN
  924. ulong
  925. thd_flush_log_at_trx_commit(
  926. /*================================*/
  927. void* thd)
  928. {
  929. return(THDVAR((THD*) thd, flush_log_at_trx_commit));
  930. }
  931. /******************************************************************//**
  932. Returns the merge-sort block size used for the secondary index creation
  933. for the current connection.
  934. @return the merge-sort block size, in bytes */
  935. extern "C" UNIV_INTERN
  936. ulong
  937. thd_merge_sort_block_size(
  938. /*================================*/
  939. void* thd) /*!< in: thread handle (THD*), or NULL to query
  940. + the global merge_sort_block_size */
  941. {
  942. return(THDVAR((THD*) thd, merge_sort_block_size));
  943. }
  944. /********************************************************************//**
  945. Obtain the InnoDB transaction of a MySQL thread.
  946. @return reference to transaction pointer */
  947. static inline
  948. trx_t*&
  949. thd_to_trx(
  950. /*=======*/
  951. THD* thd) /*!< in: MySQL thread */
  952. {
  953. return(*(trx_t**) thd_ha_data(thd, innodb_hton_ptr));
  954. }
  955. /********************************************************************//**
  956. Call this function when mysqld passes control to the client. That is to
  957. avoid deadlocks on the adaptive hash S-latch possibly held by thd. For more
  958. documentation, see handler.cc.
  959. @return 0 */
  960. static
  961. int
  962. innobase_release_temporary_latches(
  963. /*===============================*/
  964. handlerton* hton, /*!< in: handlerton */
  965. THD* thd) /*!< in: MySQL thread */
  966. {
  967. trx_t* trx;
  968. DBUG_ASSERT(hton == innodb_hton_ptr);
  969. if (!innodb_inited) {
  970. return(0);
  971. }
  972. trx = thd_to_trx(thd);
  973. if (trx) {
  974. innobase_release_stat_resources(trx);
  975. }
  976. return(0);
  977. }
  978. /********************************************************************//**
  979. Increments innobase_active_counter and every INNOBASE_WAKE_INTERVALth
  980. time calls srv_active_wake_master_thread. This function should be used
  981. when a single database operation may introduce a small need for
  982. server utility activity, like checkpointing. */
  983. static inline
  984. void
  985. innobase_active_small(void)
  986. /*=======================*/
  987. {
  988. innobase_active_counter++;
  989. if ((innobase_active_counter % INNOBASE_WAKE_INTERVAL) == 0) {
  990. srv_active_wake_master_thread();
  991. }
  992. }
  993. /********************************************************************//**
  994. Converts an InnoDB error code to a MySQL error code and also tells to MySQL
  995. about a possible transaction rollback inside InnoDB caused by a lock wait
  996. timeout or a deadlock.
  997. @return MySQL error code */
  998. extern "C" UNIV_INTERN
  999. int
  1000. convert_error_code_to_mysql(
  1001. /*========================*/
  1002. int error, /*!< in: InnoDB error code */
  1003. ulint flags, /*!< in: InnoDB table flags, or 0 */
  1004. THD* thd) /*!< in: user thread handle or NULL */
  1005. {
  1006. switch (error) {
  1007. case DB_SUCCESS:
  1008. return(0);
  1009. case DB_INTERRUPTED:
  1010. my_error(ER_QUERY_INTERRUPTED, MYF(0));
  1011. /* fall through */
  1012. case DB_FOREIGN_EXCEED_MAX_CASCADE:
  1013. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  1014. HA_ERR_ROW_IS_REFERENCED,
  1015. "InnoDB: Cannot delete/update "
  1016. "rows with cascading foreign key "
  1017. "constraints that exceed max "
  1018. "depth of %d. Please "
  1019. "drop extra constraints and try "
  1020. "again", DICT_FK_MAX_RECURSIVE_LOAD);
  1021. /* fall through */
  1022. case DB_ERROR:
  1023. default:
  1024. return(-1); /* unspecified error */
  1025. case DB_DUPLICATE_KEY:
  1026. /* Be cautious with returning this error, since
  1027. mysql could re-enter the storage layer to get
  1028. duplicated key info, the operation requires a
  1029. valid table handle and/or transaction information,
  1030. which might not always be available in the error
  1031. handling stage. */
  1032. return(HA_ERR_FOUND_DUPP_KEY);
  1033. case DB_FOREIGN_DUPLICATE_KEY:
  1034. return(HA_ERR_FOREIGN_DUPLICATE_KEY);
  1035. case DB_MISSING_HISTORY:
  1036. return(HA_ERR_TABLE_DEF_CHANGED);
  1037. case DB_RECORD_NOT_FOUND:
  1038. return(HA_ERR_NO_ACTIVE_RECORD);
  1039. case DB_SEARCH_ABORTED_BY_USER:
  1040. return(HA_ERR_ABORTED_BY_USER);
  1041. case DB_DEADLOCK:
  1042. /* Since we rolled back the whole transaction, we must
  1043. tell it also to MySQL so that MySQL knows to empty the
  1044. cached binlog for this transaction */
  1045. if (thd) {
  1046. thd_mark_transaction_to_rollback(thd, TRUE);
  1047. }
  1048. return(HA_ERR_LOCK_DEADLOCK);
  1049. case DB_LOCK_WAIT_TIMEOUT:
  1050. /* Starting from 5.0.13, we let MySQL just roll back the
  1051. latest SQL statement in a lock wait timeout. Previously, we
  1052. rolled back the whole transaction. */
  1053. if (thd) {
  1054. thd_mark_transaction_to_rollback(
  1055. thd, (bool)row_rollback_on_timeout);
  1056. }
  1057. return(HA_ERR_LOCK_WAIT_TIMEOUT);
  1058. case DB_NO_REFERENCED_ROW:
  1059. return(HA_ERR_NO_REFERENCED_ROW);
  1060. case DB_ROW_IS_REFERENCED:
  1061. return(HA_ERR_ROW_IS_REFERENCED);
  1062. case DB_CANNOT_ADD_CONSTRAINT:
  1063. case DB_CHILD_NO_INDEX:
  1064. case DB_PARENT_NO_INDEX:
  1065. return(HA_ERR_CANNOT_ADD_FOREIGN);
  1066. case DB_CANNOT_DROP_CONSTRAINT:
  1067. return(HA_ERR_ROW_IS_REFERENCED); /* TODO: This is a bit
  1068. misleading, a new MySQL error
  1069. code should be introduced */
  1070. case DB_CORRUPTION:
  1071. return(HA_ERR_CRASHED);
  1072. case DB_OUT_OF_FILE_SPACE:
  1073. return(HA_ERR_RECORD_FILE_FULL);
  1074. case DB_TABLE_IN_FK_CHECK:
  1075. return(HA_ERR_TABLE_IN_FK_CHECK);
  1076. case DB_TABLE_IS_BEING_USED:
  1077. return(HA_ERR_WRONG_COMMAND);
  1078. case DB_TABLE_NOT_FOUND:
  1079. return(HA_ERR_NO_SUCH_TABLE);
  1080. case DB_TOO_BIG_RECORD:
  1081. my_error(ER_TOO_BIG_ROWSIZE, MYF(0),
  1082. page_get_free_space_of_empty(flags
  1083. & DICT_TF_COMPACT) / 2);
  1084. return(HA_ERR_TO_BIG_ROW);
  1085. case DB_TOO_BIG_INDEX_COL:
  1086. my_error(ER_INDEX_COLUMN_TOO_LONG, MYF(0),
  1087. DICT_MAX_FIELD_LEN_BY_FORMAT_FLAG(flags));
  1088. return(HA_ERR_INDEX_COL_TOO_LONG);
  1089. case DB_NO_SAVEPOINT:
  1090. return(HA_ERR_NO_SAVEPOINT);
  1091. case DB_LOCK_TABLE_FULL:
  1092. /* Since we rolled back the whole transaction, we must
  1093. tell it also to MySQL so that MySQL knows to empty the
  1094. cached binlog for this transaction */
  1095. if (thd) {
  1096. thd_mark_transaction_to_rollback(thd, TRUE);
  1097. }
  1098. return(HA_ERR_LOCK_TABLE_FULL);
  1099. case DB_PRIMARY_KEY_IS_NULL:
  1100. return(ER_PRIMARY_CANT_HAVE_NULL);
  1101. case DB_TOO_MANY_CONCURRENT_TRXS:
  1102. /* New error code HA_ERR_TOO_MANY_CONCURRENT_TRXS is only
  1103. available in 5.1.38 and later, but the plugin should still
  1104. work with previous versions of MySQL. */
  1105. #ifdef HA_ERR_TOO_MANY_CONCURRENT_TRXS
  1106. return(HA_ERR_TOO_MANY_CONCURRENT_TRXS);
  1107. #else /* HA_ERR_TOO_MANY_CONCURRENT_TRXS */
  1108. return(HA_ERR_RECORD_FILE_FULL);
  1109. #endif /* HA_ERR_TOO_MANY_CONCURRENT_TRXS */
  1110. case DB_UNSUPPORTED:
  1111. return(HA_ERR_UNSUPPORTED);
  1112. case DB_INDEX_CORRUPT:
  1113. return(HA_ERR_INDEX_CORRUPT);
  1114. case DB_UNDO_RECORD_TOO_BIG:
  1115. return(HA_ERR_UNDO_REC_TOO_BIG);
  1116. }
  1117. }
  1118. /*************************************************************//**
  1119. Prints info of a THD object (== user session thread) to the given file. */
  1120. extern "C" UNIV_INTERN
  1121. void
  1122. innobase_mysql_print_thd(
  1123. /*=====================*/
  1124. FILE* f, /*!< in: output stream */
  1125. void* thd, /*!< in: pointer to a MySQL THD object */
  1126. uint max_query_len) /*!< in: max query length to print, or 0 to
  1127. use the default max length */
  1128. {
  1129. char buffer[1024];
  1130. fputs(thd_security_context((THD*) thd, buffer, sizeof buffer,
  1131. max_query_len), f);
  1132. putc('\n', f);
  1133. }
  1134. /******************************************************************//**
  1135. Get the variable length bounds of the given character set. */
  1136. extern "C" UNIV_INTERN
  1137. void
  1138. innobase_get_cset_width(
  1139. /*====================*/
  1140. ulint cset, /*!< in: MySQL charset-collation code */
  1141. ulint* mbminlen, /*!< out: minimum length of a char (in bytes) */
  1142. ulint* mbmaxlen) /*!< out: maximum length of a char (in bytes) */
  1143. {
  1144. CHARSET_INFO* cs;
  1145. ut_ad(cset < 256);
  1146. ut_ad(mbminlen);
  1147. ut_ad(mbmaxlen);
  1148. cs = all_charsets[cset];
  1149. if (cs) {
  1150. *mbminlen = cs->mbminlen;
  1151. *mbmaxlen = cs->mbmaxlen;
  1152. ut_ad(*mbminlen < DATA_MBMAX);
  1153. ut_ad(*mbmaxlen < DATA_MBMAX);
  1154. } else {
  1155. THD* thd = current_thd;
  1156. if (thd && thd_sql_command(thd) == SQLCOM_DROP_TABLE) {
  1157. /* Fix bug#46256: allow tables to be dropped if the
  1158. collation is not found, but issue a warning. */
  1159. if ((global_system_variables.log_warnings)
  1160. && (cset != 0)){
  1161. sql_print_warning(
  1162. "Unknown collation #%lu.", cset);
  1163. }
  1164. } else {
  1165. ut_a(cset == 0);
  1166. }
  1167. *mbminlen = *mbmaxlen = 0;
  1168. }
  1169. }
  1170. /******************************************************************//**
  1171. Converts an identifier to a table name. */
  1172. extern "C" UNIV_INTERN
  1173. void
  1174. innobase_convert_from_table_id(
  1175. /*===========================*/
  1176. struct charset_info_st* cs, /*!< in: the 'from' character set */
  1177. char* to, /*!< out: converted identifier */
  1178. const char* from, /*!< in: identifier to convert */
  1179. ulint len) /*!< in: length of 'to', in bytes */
  1180. {
  1181. uint errors;
  1182. strconvert(cs, from, &my_charset_filename, to, (uint) len, &errors);
  1183. }
  1184. /******************************************************************//**
  1185. Converts an identifier to UTF-8. */
  1186. extern "C" UNIV_INTERN
  1187. void
  1188. innobase_convert_from_id(
  1189. /*=====================*/
  1190. struct charset_info_st* cs, /*!< in: the 'from' character set */
  1191. char* to, /*!< out: converted identifier */
  1192. const char* from, /*!< in: identifier to convert */
  1193. ulint len) /*!< in: length of 'to', in bytes */
  1194. {
  1195. uint errors;
  1196. strconvert(cs, from, system_charset_info, to, (uint) len, &errors);
  1197. }
  1198. /******************************************************************//**
  1199. Compares NUL-terminated UTF-8 strings case insensitively.
  1200. @return 0 if a=b, <0 if a<b, >1 if a>b */
  1201. extern "C" UNIV_INTERN
  1202. int
  1203. innobase_strcasecmp(
  1204. /*================*/
  1205. const char* a, /*!< in: first string to compare */
  1206. const char* b) /*!< in: second string to compare */
  1207. {
  1208. return(my_strcasecmp(system_charset_info, a, b));
  1209. }
  1210. /******************************************************************//**
  1211. Strip dir name from a full path name and return only the file name
  1212. @return file name or "null" if no file name */
  1213. extern "C" UNIV_INTERN
  1214. const char*
  1215. innobase_basename(
  1216. /*==============*/
  1217. const char* path_name) /*!< in: full path name */
  1218. {
  1219. const char* name = base_name(path_name);
  1220. return((name) ? name : "null");
  1221. }
  1222. /******************************************************************//**
  1223. Makes all characters in a NUL-terminated UTF-8 string lower case. */
  1224. extern "C" UNIV_INTERN
  1225. void
  1226. innobase_casedn_str(
  1227. /*================*/
  1228. char* a) /*!< in/out: string to put in lower case */
  1229. {
  1230. my_casedn_str(system_charset_info, a);
  1231. }
  1232. /**********************************************************************//**
  1233. Determines the connection character set.
  1234. @return connection character set */
  1235. extern "C" UNIV_INTERN
  1236. struct charset_info_st*
  1237. innobase_get_charset(
  1238. /*=================*/
  1239. void* mysql_thd) /*!< in: MySQL thread handle */
  1240. {
  1241. return(thd_charset((THD*) mysql_thd));
  1242. }
  1243. /**********************************************************************//**
  1244. Determines the current SQL statement.
  1245. @return SQL statement string */
  1246. extern "C" UNIV_INTERN
  1247. const char*
  1248. innobase_get_stmt(
  1249. /*==============*/
  1250. void* mysql_thd, /*!< in: MySQL thread handle */
  1251. size_t* length) /*!< out: length of the SQL statement */
  1252. {
  1253. LEX_STRING* stmt;
  1254. stmt = thd_query_string((THD*) mysql_thd);
  1255. *length = stmt->length;
  1256. return(stmt->str);
  1257. }
  1258. /**********************************************************************//**
  1259. Get the current setting of the lower_case_table_names global parameter from
  1260. mysqld.cc. We do a dirty read because for one there is no synchronization
  1261. object and secondly there is little harm in doing so even if we get a torn
  1262. read.
  1263. @return value of lower_case_table_names */
  1264. extern "C" UNIV_INTERN
  1265. ulint
  1266. innobase_get_lower_case_table_names(void)
  1267. /*=====================================*/
  1268. {
  1269. return(lower_case_table_names);
  1270. }
  1271. #if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
  1272. extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list;
  1273. /*******************************************************************//**
  1274. Map an OS error to an errno value. The OS error number is stored in
  1275. _doserrno and the mapped value is stored in errno) */
  1276. extern "C"
  1277. void __cdecl
  1278. _dosmaperr(
  1279. unsigned long); /*!< in: OS error value */
  1280. /*********************************************************************//**
  1281. Creates a temporary file.
  1282. @return temporary file descriptor, or < 0 on error */
  1283. extern "C" UNIV_INTERN
  1284. int
  1285. innobase_mysql_tmpfile(void)
  1286. /*========================*/
  1287. {
  1288. int fd; /* handle of opened file */
  1289. HANDLE osfh; /* OS handle of opened file */
  1290. char* tmpdir; /* point to the directory
  1291. where to create file */
  1292. TCHAR path_buf[MAX_PATH - 14]; /* buffer for tmp file path.
  1293. The length cannot be longer
  1294. than MAX_PATH - 14, or
  1295. GetTempFileName will fail. */
  1296. char filename[MAX_PATH]; /* name of the tmpfile */
  1297. DWORD fileaccess = GENERIC_READ /* OS file access */
  1298. | GENERIC_WRITE
  1299. | DELETE;
  1300. DWORD fileshare = FILE_SHARE_READ /* OS file sharing mode */
  1301. | FILE_SHARE_WRITE
  1302. | FILE_SHARE_DELETE;
  1303. DWORD filecreate = CREATE_ALWAYS; /* OS method of open/create */
  1304. DWORD fileattrib = /* OS file attribute flags */
  1305. FILE_ATTRIBUTE_NORMAL
  1306. | FILE_FLAG_DELETE_ON_CLOSE
  1307. | FILE_ATTRIBUTE_TEMPORARY
  1308. | FILE_FLAG_SEQUENTIAL_SCAN;
  1309. DBUG_ENTER("innobase_mysql_tmpfile");
  1310. tmpdir = my_tmpdir(&mysql_tmpdir_list);
  1311. /* The tmpdir parameter can not be NULL for GetTempFileName. */
  1312. if (!tmpdir) {
  1313. uint ret;
  1314. /* Use GetTempPath to determine path for temporary files. */
  1315. ret = GetTempPath(sizeof(path_buf), path_buf);
  1316. if (ret > sizeof(path_buf) || (ret == 0)) {
  1317. _dosmaperr(GetLastError()); /* map error */
  1318. DBUG_RETURN(-1);
  1319. }
  1320. tmpdir = path_buf;
  1321. }
  1322. /* Use GetTempFileName to generate a unique filename. */
  1323. if (!GetTempFileName(tmpdir, "ib", 0, filename)) {
  1324. _dosmaperr(GetLastError()); /* map error */
  1325. DBUG_RETURN(-1);
  1326. }
  1327. DBUG_PRINT("info", ("filename: %s", filename));
  1328. /* Open/Create the file. */
  1329. osfh = CreateFile(filename, fileaccess, fileshare, NULL,
  1330. filecreate, fileattrib, NULL);
  1331. if (osfh == INVALID_HANDLE_VALUE) {
  1332. /* open/create file failed! */
  1333. _dosmaperr(GetLastError()); /* map error */
  1334. DBUG_RETURN(-1);
  1335. }
  1336. do {
  1337. /* Associates a CRT file descriptor with the OS file handle. */
  1338. fd = _open_osfhandle((intptr_t) osfh, 0);
  1339. } while (fd == -1 && errno == EINTR);
  1340. if (fd == -1) {
  1341. /* Open failed, close the file handle. */
  1342. _dosmaperr(GetLastError()); /* map error */
  1343. CloseHandle(osfh); /* no need to check if
  1344. CloseHandle fails */
  1345. }
  1346. DBUG_RETURN(fd);
  1347. }
  1348. #else
  1349. /*********************************************************************//**
  1350. Creates a temporary file.
  1351. @return temporary file descriptor, or < 0 on error */
  1352. extern "C" UNIV_INTERN
  1353. int
  1354. innobase_mysql_tmpfile(void)
  1355. /*========================*/
  1356. {
  1357. int fd2 = -1;
  1358. File fd = mysql_tmpfile("ib");
  1359. if (fd >= 0) {
  1360. /* Copy the file descriptor, so that the additional resources
  1361. allocated by create_temp_file() can be freed by invoking
  1362. my_close().
  1363. Because the file descriptor returned by this function
  1364. will be passed to fdopen(), it will be closed by invoking
  1365. fclose(), which in turn will invoke close() instead of
  1366. my_close(). */
  1367. #ifdef _WIN32
  1368. /* Note that on Windows, the integer returned by mysql_tmpfile
  1369. has no relation to C runtime file descriptor. Here, we need
  1370. to call my_get_osfhandle to get the HANDLE and then convert it
  1371. to C runtime filedescriptor. */
  1372. {
  1373. HANDLE hFile = my_get_osfhandle(fd);
  1374. HANDLE hDup;
  1375. BOOL bOK =
  1376. DuplicateHandle(GetCurrentProcess(), hFile, GetCurrentProcess(),
  1377. &hDup, 0, FALSE, DUPLICATE_SAME_ACCESS);
  1378. if(bOK) {
  1379. fd2 = _open_osfhandle((intptr_t)hDup,0);
  1380. }
  1381. else {
  1382. my_osmaperr(GetLastError());
  1383. fd2 = -1;
  1384. }
  1385. }
  1386. #else
  1387. fd2 = dup(fd);
  1388. #endif
  1389. if (fd2 < 0) {
  1390. DBUG_PRINT("error",("Got error %d on dup",fd2));
  1391. my_errno=errno;
  1392. my_error(EE_OUT_OF_FILERESOURCES,
  1393. MYF(ME_BELL+ME_WAITTANG),
  1394. "ib*", my_errno);
  1395. }
  1396. my_close(fd, MYF(MY_WME));
  1397. }
  1398. return(fd2);
  1399. }
  1400. #endif /* defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN) */
  1401. /*********************************************************************//**
  1402. Wrapper around MySQL's copy_and_convert function.
  1403. @return number of bytes copied to 'to' */
  1404. extern "C" UNIV_INTERN
  1405. ulint
  1406. innobase_convert_string(
  1407. /*====================*/
  1408. void* to, /*!< out: converted string */
  1409. ulint to_length, /*!< in: number of bytes reserved
  1410. for the converted string */
  1411. CHARSET_INFO* to_cs, /*!< in: character set to convert to */
  1412. const void* from, /*!< in: string to convert */
  1413. ulint from_length, /*!< in: number of bytes to convert */
  1414. CHARSET_INFO* from_cs, /*!< in: character set to convert from */
  1415. uint* errors) /*!< out: number of errors encountered
  1416. during the conversion */
  1417. {
  1418. return(copy_and_convert((char*)to, (uint32) to_length, to_cs,
  1419. (const char*)from, (uint32) from_length, from_cs,
  1420. errors));
  1421. }
  1422. /*******************************************************************//**
  1423. Formats the raw data in "data" (in InnoDB on-disk format) that is of
  1424. type DATA_(CHAR|VARCHAR|MYSQL|VARMYSQL) using "charset_coll" and writes
  1425. the result to "buf". The result is converted to "system_charset_info".
  1426. Not more than "buf_size" bytes are written to "buf".
  1427. The result is always NUL-terminated (provided buf_size > 0) and the
  1428. number of bytes that were written to "buf" is returned (including the
  1429. terminating NUL).
  1430. @return number of bytes that were written */
  1431. extern "C" UNIV_INTERN
  1432. ulint
  1433. innobase_raw_format(
  1434. /*================*/
  1435. const char* data, /*!< in: raw data */
  1436. ulint data_len, /*!< in: raw data length
  1437. in bytes */
  1438. ulint charset_coll, /*!< in: charset collation */
  1439. char* buf, /*!< out: output buffer */
  1440. ulint buf_size) /*!< in: output buffer size
  1441. in bytes */
  1442. {
  1443. /* XXX we use a hard limit instead of allocating
  1444. but_size bytes from the heap */
  1445. CHARSET_INFO* data_cs;
  1446. char buf_tmp[8192];
  1447. ulint buf_tmp_used;
  1448. uint num_errors;
  1449. data_cs = all_charsets[charset_coll];
  1450. buf_tmp_used = innobase_convert_string(buf_tmp, sizeof(buf_tmp),
  1451. system_charset_info,
  1452. data, data_len, data_cs,
  1453. &num_errors);
  1454. return(ut_str_sql_format(buf_tmp, buf_tmp_used, buf, buf_size));
  1455. }
  1456. /*********************************************************************//**
  1457. Compute the next autoinc value.
  1458. For MySQL replication the autoincrement values can be partitioned among
  1459. the nodes. The offset is the start or origin of the autoincrement value
  1460. for a particular node. For n nodes the increment will be n and the offset
  1461. will be in the interval [1, n]. The formula tries to allocate the next
  1462. value for a particular node.
  1463. Note: This function is also called with increment set to the number of
  1464. values we want to reserve for multi-value inserts e.g.,
  1465. INSERT INTO T VALUES(), (), ();
  1466. innobase_next_autoinc() will be called with increment set to 3 where
  1467. autoinc_lock_mode != TRADITIONAL because we want to reserve 3 values for
  1468. the multi-value INSERT above.
  1469. @return the next value */
  1470. static
  1471. ulonglong
  1472. innobase_next_autoinc(
  1473. /*==================*/
  1474. ulonglong current, /*!< in: Current value */
  1475. ulonglong need, /*!< in: count of values needed */
  1476. ulonglong step, /*!< in: AUTOINC increment step */
  1477. ulonglong offset, /*!< in: AUTOINC offset */
  1478. ulonglong max_value) /*!< in: max value for type */
  1479. {
  1480. ulonglong next_value;
  1481. ulonglong block = need * step;
  1482. /* Should never be 0. */
  1483. ut_a(need > 0);
  1484. ut_a(block > 0);
  1485. ut_a(max_value > 0);
  1486. /*
  1487. Allow auto_increment to go over max_value up to max ulonglong.
  1488. This allows us to detect that all values are exhausted.
  1489. If we don't do this, we will return max_value several times
  1490. and get duplicate key errors instead of auto increment value
  1491. out of range.
  1492. */
  1493. max_value= (~(ulonglong) 0);
  1494. /* Current value should never be greater than the maximum. */
  1495. ut_a(current <= max_value);
  1496. /* According to MySQL documentation, if the offset is greater than
  1497. the step then the offset is ignored. */
  1498. if (offset > block) {
  1499. offset = 0;
  1500. }
  1501. /* Check for overflow. */
  1502. if (block >= max_value
  1503. || offset > max_value
  1504. || current == max_value
  1505. || max_value - offset <= offset) {
  1506. next_value = max_value;
  1507. } else {
  1508. ut_a(max_value > current);
  1509. ulonglong free = max_value - current;
  1510. if (free < offset || free - offset <= block) {
  1511. next_value = max_value;
  1512. } else {
  1513. next_value = 0;
  1514. }
  1515. }
  1516. if (next_value == 0) {
  1517. ulonglong next;
  1518. if (current > offset) {
  1519. next = (current - offset) / step;
  1520. } else {
  1521. next = (offset - current) / step;
  1522. }
  1523. ut_a(max_value > next);
  1524. next_value = next * step;
  1525. /* Check for multiplication overflow. */
  1526. ut_a(next_value >= next);
  1527. ut_a(max_value > next_value);
  1528. /* Check for overflow */
  1529. if (max_value - next_value >= block) {
  1530. next_value += block;
  1531. if (max_value - next_value >= offset) {
  1532. next_value += offset;
  1533. } else {
  1534. next_value = max_value;
  1535. }
  1536. } else {
  1537. next_value = max_value;
  1538. }
  1539. }
  1540. ut_a(next_value != 0);
  1541. ut_a(next_value <= max_value);
  1542. return(next_value);
  1543. }
  1544. /*********************************************************************//**
  1545. Initializes some fields in an InnoDB transaction object. */
  1546. static
  1547. void
  1548. innobase_trx_init(
  1549. /*==============*/
  1550. THD* thd, /*!< in: user thread handle */
  1551. trx_t* trx) /*!< in/out: InnoDB transaction handle */
  1552. {
  1553. DBUG_ENTER("innobase_trx_init");
  1554. DBUG_ASSERT(thd == trx->mysql_thd);
  1555. trx->check_foreigns = !thd_test_options(
  1556. thd, OPTION_NO_FOREIGN_KEY_CHECKS);
  1557. trx->check_unique_secondary = !thd_test_options(
  1558. thd, OPTION_RELAXED_UNIQUE_CHECKS);
  1559. trx->fake_changes = THDVAR(thd, fake_changes);
  1560. #ifdef EXTENDED_SLOWLOG
  1561. if (thd_log_slow_verbosity(thd) & SLOG_V_INNODB) {
  1562. trx->take_stats = TRUE;
  1563. } else {
  1564. trx->take_stats = FALSE;
  1565. }
  1566. #else
  1567. trx->take_stats = FALSE;
  1568. #endif
  1569. DBUG_VOID_RETURN;
  1570. }
  1571. /*********************************************************************//**
  1572. Allocates an InnoDB transaction for a MySQL handler object.
  1573. @return InnoDB transaction handle */
  1574. extern "C" UNIV_INTERN
  1575. trx_t*
  1576. innobase_trx_allocate(
  1577. /*==================*/
  1578. THD* thd) /*!< in: user thread handle */
  1579. {
  1580. trx_t* trx;
  1581. DBUG_ENTER("innobase_trx_allocate");
  1582. DBUG_ASSERT(thd != NULL);
  1583. DBUG_ASSERT(EQ_CURRENT_THD(thd));
  1584. trx = trx_allocate_for_mysql();
  1585. trx->mysql_thd = thd;
  1586. innobase_trx_init(thd, trx);
  1587. DBUG_RETURN(trx);
  1588. }
  1589. /*********************************************************************//**
  1590. Gets the InnoDB transaction handle for a MySQL handler object, creates
  1591. an InnoDB transaction struct if the corresponding MySQL thread struct still
  1592. lacks one.
  1593. @return InnoDB transaction handle */
  1594. static inline
  1595. trx_t*
  1596. check_trx_exists(
  1597. /*=============*/
  1598. THD* thd) /*!< in: user thread handle */
  1599. {
  1600. trx_t*& trx = thd_to_trx(thd);
  1601. if (trx == NULL) {
  1602. trx = innobase_trx_allocate(thd);
  1603. } else if (UNIV_UNLIKELY(trx->magic_n != TRX_MAGIC_N)) {
  1604. mem_analyze_corruption(trx);
  1605. ut_error;
  1606. }
  1607. innobase_trx_init(thd, trx);
  1608. return(trx);
  1609. }
  1610. /*************************************************************************
  1611. Gets current trx. */
  1612. extern "C"
  1613. trx_t*
  1614. innobase_get_trx()
  1615. {
  1616. THD *thd=current_thd;
  1617. if (likely(thd != 0)) {
  1618. trx_t*& trx = thd_to_trx(thd);
  1619. return(trx);
  1620. } else {
  1621. return(NULL);
  1622. }
  1623. }
  1624. extern "C"
  1625. ibool
  1626. innobase_get_slow_log()
  1627. {
  1628. #ifdef EXTENDED_SLOWLOG
  1629. return((ibool) thd_opt_slow_log());
  1630. #else
  1631. return(FALSE);
  1632. #endif
  1633. }
  1634. /*********************************************************************//**
  1635. Note that a transaction has been registered with MySQL.
  1636. @return true if transaction is registered with MySQL 2PC coordinator */
  1637. static inline
  1638. bool
  1639. trx_is_registered_for_2pc(
  1640. /*=========================*/
  1641. const trx_t* trx) /* in: transaction */
  1642. {
  1643. return(trx->is_registered == 1);
  1644. }
  1645. /*********************************************************************//**
  1646. Note that innobase_commit_ordered() was run. */
  1647. static inline
  1648. void
  1649. trx_set_active_commit_ordered(
  1650. /*==============================*/
  1651. trx_t* trx) /* in: transaction */
  1652. {
  1653. ut_a(trx_is_registered_for_2pc(trx));
  1654. trx->active_commit_ordered = 1;
  1655. }
  1656. /*********************************************************************//**
  1657. Note that a transaction has been registered with MySQL 2PC coordinator. */
  1658. static inline
  1659. void
  1660. trx_register_for_2pc(
  1661. /*==================*/
  1662. trx_t* trx) /* in: transaction */
  1663. {
  1664. trx->is_registered = 1;
  1665. ut_ad(trx->active_commit_ordered == 0);
  1666. }
  1667. /*********************************************************************//**
  1668. Note that a transaction has been deregistered. */
  1669. static inline
  1670. void
  1671. trx_deregister_from_2pc(
  1672. /*====================*/
  1673. trx_t* trx) /* in: transaction */
  1674. {
  1675. trx->is_registered = 0;
  1676. trx->active_commit_ordered = 0;
  1677. }
  1678. /*********************************************************************//**
  1679. Check whether a transaction has active_commit_ordered set */
  1680. static inline
  1681. bool
  1682. trx_is_active_commit_ordered(
  1683. /*=========================*/
  1684. const trx_t* trx) /* in: transaction */
  1685. {
  1686. return(trx->active_commit_ordered == 1);
  1687. }
  1688. /*********************************************************************//**
  1689. Check if transaction is started.
  1690. @reutrn true if transaction is in state started */
  1691. static
  1692. bool
  1693. trx_is_started(
  1694. /*===========*/
  1695. trx_t* trx) /* in: transaction */
  1696. {
  1697. return(trx->conc_state != TRX_NOT_STARTED);
  1698. }
  1699. /*********************************************************************//**
  1700. Construct ha_innobase handler. */
  1701. UNIV_INTERN
  1702. ha_innobase::ha_innobase(handlerton *hton, TABLE_SHARE *table_arg)
  1703. :handler(hton, table_arg),
  1704. int_table_flags(HA_REC_NOT_IN_SEQ |
  1705. HA_NULL_IN_KEY | HA_CAN_VIRTUAL_COLUMNS |
  1706. HA_CAN_INDEX_BLOBS |
  1707. HA_CAN_SQL_HANDLER |
  1708. HA_PRIMARY_KEY_REQUIRED_FOR_POSITION |
  1709. HA_PRIMARY_KEY_IN_READ_INDEX |
  1710. HA_BINLOG_ROW_CAPABLE |
  1711. HA_CAN_GEOMETRY | HA_PARTIAL_COLUMN_READ |
  1712. HA_TABLE_SCAN_ON_INDEX),
  1713. start_of_scan(0),
  1714. num_write_row(0)
  1715. {}
  1716. /*********************************************************************//**
  1717. Destruct ha_innobase handler. */
  1718. UNIV_INTERN
  1719. ha_innobase::~ha_innobase()
  1720. {
  1721. }
  1722. /*********************************************************************//**
  1723. Updates the user_thd field in a handle and also allocates a new InnoDB
  1724. transaction handle if needed, and updates the transaction fields in the
  1725. prebuilt struct. */
  1726. UNIV_INTERN inline
  1727. void
  1728. ha_innobase::update_thd(
  1729. /*====================*/
  1730. THD* thd) /*!< in: thd to use the handle */
  1731. {
  1732. trx_t* trx;
  1733. trx = check_trx_exists(thd);
  1734. if (prebuilt->trx != trx) {
  1735. row_update_prebuilt_trx(prebuilt, trx);
  1736. }
  1737. user_thd = thd;
  1738. }
  1739. /*********************************************************************//**
  1740. Updates the user_thd field in a handle and also allocates a new InnoDB
  1741. transaction handle if needed, and updates the transaction fields in the
  1742. prebuilt struct. */
  1743. UNIV_INTERN
  1744. void
  1745. ha_innobase::update_thd()
  1746. /*=====================*/
  1747. {
  1748. THD* thd = ha_thd();
  1749. ut_ad(EQ_CURRENT_THD(thd));
  1750. update_thd(thd);
  1751. }
  1752. /*********************************************************************//**
  1753. Registers an InnoDB transaction with the MySQL 2PC coordinator, so that
  1754. the MySQL XA code knows to call the InnoDB prepare and commit, or rollback
  1755. for the transaction. This MUST be called for every transaction for which
  1756. the user may call commit or rollback. Calling this several times to register
  1757. the same transaction is allowed, too. This function also registers the
  1758. current SQL statement. */
  1759. static inline
  1760. void
  1761. innobase_register_trx(
  1762. /*==================*/
  1763. handlerton* hton, /* in: Innobase handlerton */
  1764. THD* thd, /* in: MySQL thd (connection) object */
  1765. trx_t* trx) /* in: transaction to register */
  1766. {
  1767. trans_register_ha(thd, FALSE, hton);
  1768. if (!trx_is_registered_for_2pc(trx)
  1769. && thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  1770. trans_register_ha(thd, TRUE, hton);
  1771. }
  1772. trx_register_for_2pc(trx);
  1773. }
  1774. /* BACKGROUND INFO: HOW THE MYSQL QUERY CACHE WORKS WITH INNODB
  1775. ------------------------------------------------------------
  1776. 1) The use of the query cache for TBL is disabled when there is an
  1777. uncommitted change to TBL.
  1778. 2) When a change to TBL commits, InnoDB stores the current value of
  1779. its global trx id counter, let us denote it by INV_TRX_ID, to the table object
  1780. in the InnoDB data dictionary, and does only allow such transactions whose
  1781. id <= INV_TRX_ID to use the query cache.
  1782. 3) When InnoDB does an INSERT/DELETE/UPDATE to a table TBL, or an implicit
  1783. modification because an ON DELETE CASCADE, we invalidate the MySQL query cache
  1784. of TBL immediately.
  1785. How this is implemented inside InnoDB:
  1786. 1) Since every modification always sets an IX type table lock on the InnoDB
  1787. table, it is easy to check if there can be uncommitted modifications for a
  1788. table: just check if there are locks in the lock list of the table.
  1789. 2) When a transaction inside InnoDB commits, it reads the global trx id
  1790. counter and stores the value INV_TRX_ID to the tables on which it had a lock.
  1791. 3) If there is an implicit table change from ON DELETE CASCADE or SET NULL,
  1792. InnoDB calls an invalidate method for the MySQL query cache for that table.
  1793. How this is implemented inside sql_cache.cc:
  1794. 1) The query cache for an InnoDB table TBL is invalidated immediately at an
  1795. INSERT/UPDATE/DELETE, just like in the case of MyISAM. No need to delay
  1796. invalidation to the transaction commit.
  1797. 2) To store or retrieve a value from the query cache of an InnoDB table TBL,
  1798. any query must first ask InnoDB's permission. We must pass the thd as a
  1799. parameter because InnoDB will look at the trx id, if any, associated with
  1800. that thd.
  1801. 3) Use of the query cache for InnoDB tables is now allowed also when
  1802. AUTOCOMMIT==0 or we are inside BEGIN ... COMMIT. Thus transactions no longer
  1803. put restrictions on the use of the query cache.
  1804. */
  1805. /******************************************************************//**
  1806. The MySQL query cache uses this to check from InnoDB if the query cache at
  1807. the moment is allowed to operate on an InnoDB table. The SQL query must
  1808. be a non-locking SELECT.
  1809. The query cache is allowed to operate on certain query only if this function
  1810. returns TRUE for all tables in the query.
  1811. If thd is not in the autocommit state, this function also starts a new
  1812. transaction for thd if there is no active trx yet, and assigns a consistent
  1813. read view to it if there is no read view yet.
  1814. Why a deadlock of threads is not possible: the query cache calls this function
  1815. at the start of a SELECT processing. Then the calling thread cannot be
  1816. holding any InnoDB semaphores. The calling thread is holding the
  1817. query cache mutex, and this function will reserver the InnoDB kernel mutex.
  1818. Thus, the 'rank' in sync0sync.h of the MySQL query cache mutex is above
  1819. the InnoDB kernel mutex.
  1820. @return TRUE if permitted, FALSE if not; note that the value FALSE
  1821. does not mean we should invalidate the query cache: invalidation is
  1822. called explicitly */
  1823. static
  1824. my_bool
  1825. innobase_query_caching_of_table_permitted(
  1826. /*======================================*/
  1827. THD* thd, /*!< in: thd of the user who is trying to
  1828. store a result to the query cache or
  1829. retrieve it */
  1830. char* full_name, /*!< in: concatenation of database name,
  1831. the null character NUL, and the table
  1832. name */
  1833. uint full_name_len, /*!< in: length of the full name, i.e.
  1834. len(dbname) + len(tablename) + 1 */
  1835. ulonglong *unused) /*!< unused for this engine */
  1836. {
  1837. ibool is_autocommit;
  1838. trx_t* trx;
  1839. char norm_name[1000];
  1840. ut_a(full_name_len < 999);
  1841. trx = check_trx_exists(thd);
  1842. if (trx->isolation_level == TRX_ISO_SERIALIZABLE) {
  1843. /* In the SERIALIZABLE mode we add LOCK IN SHARE MODE to every
  1844. plain SELECT if AUTOCOMMIT is not on. */
  1845. return((my_bool)FALSE);
  1846. }
  1847. if (trx->has_search_latch) {
  1848. sql_print_error("The calling thread is holding the adaptive "
  1849. "search, latch though calling "
  1850. "innobase_query_caching_of_table_permitted.");
  1851. mutex_enter(&kernel_mutex);
  1852. trx_print(stderr, trx, 1024);
  1853. mutex_exit(&kernel_mutex);
  1854. }
  1855. innobase_release_stat_resources(trx);
  1856. if (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  1857. is_autocommit = TRUE;
  1858. } else {
  1859. is_autocommit = FALSE;
  1860. }
  1861. if (is_autocommit && trx->n_mysql_tables_in_use == 0) {
  1862. /* We are going to retrieve the query result from the query
  1863. cache. This cannot be a store operation to the query cache
  1864. because then MySQL would have locks on tables already.
  1865. TODO: if the user has used LOCK TABLES to lock the table,
  1866. then we open a transaction in the call of row_.. below.
  1867. That trx can stay open until UNLOCK TABLES. The same problem
  1868. exists even if we do not use the query cache. MySQL should be
  1869. modified so that it ALWAYS calls some cleanup function when
  1870. the processing of a query ends!
  1871. We can imagine we instantaneously serialize this consistent
  1872. read trx to the current trx id counter. If trx2 would have
  1873. changed the tables of a query result stored in the cache, and
  1874. trx2 would have already committed, making the result obsolete,
  1875. then trx2 would have already invalidated the cache. Thus we
  1876. can trust the result in the cache is ok for this query. */
  1877. return((my_bool)TRUE);
  1878. }
  1879. /* Normalize the table name to InnoDB format */
  1880. memcpy(norm_name, full_name, full_name_len);
  1881. norm_name[strlen(norm_name)] = '/'; /* InnoDB uses '/' as the
  1882. separator between db and table */
  1883. norm_name[full_name_len] = '\0';
  1884. #ifdef __WIN__
  1885. innobase_casedn_str(norm_name);
  1886. #endif
  1887. innobase_register_trx(innodb_hton_ptr, thd, trx);
  1888. if (row_search_check_if_query_cache_permitted(trx, norm_name)) {
  1889. /* printf("Query cache for %s permitted\n", norm_name); */
  1890. return((my_bool)TRUE);
  1891. }
  1892. /* printf("Query cache for %s NOT permitted\n", norm_name); */
  1893. return((my_bool)FALSE);
  1894. }
  1895. /*****************************************************************//**
  1896. Invalidates the MySQL query cache for the table. */
  1897. extern "C" UNIV_INTERN
  1898. void
  1899. innobase_invalidate_query_cache(
  1900. /*============================*/
  1901. trx_t* trx, /*!< in: transaction which
  1902. modifies the table */
  1903. const char* full_name, /*!< in: concatenation of
  1904. database name, null char NUL,
  1905. table name, null char NUL;
  1906. NOTE that in Windows this is
  1907. always in LOWER CASE! */
  1908. ulint full_name_len) /*!< in: full name length where
  1909. also the null chars count */
  1910. {
  1911. /* Note that the sync0sync.h rank of the query cache mutex is just
  1912. above the InnoDB kernel mutex. The caller of this function must not
  1913. have latches of a lower rank. */
  1914. /* Argument TRUE below means we are using transactions */
  1915. #ifdef HAVE_QUERY_CACHE
  1916. mysql_query_cache_invalidate4((THD*) trx->mysql_thd,
  1917. full_name,
  1918. (uint32) full_name_len,
  1919. TRUE);
  1920. #endif
  1921. }
  1922. /*****************************************************************//**
  1923. Convert an SQL identifier to the MySQL system_charset_info (UTF-8)
  1924. and quote it if needed.
  1925. @return pointer to the end of buf */
  1926. static
  1927. char*
  1928. innobase_convert_identifier(
  1929. /*========================*/
  1930. char* buf, /*!< out: buffer for converted identifier */
  1931. ulint buflen, /*!< in: length of buf, in bytes */
  1932. const char* id, /*!< in: identifier to convert */
  1933. ulint idlen, /*!< in: length of id, in bytes */
  1934. void* thd, /*!< in: MySQL connection thread, or NULL */
  1935. ibool file_id)/*!< in: TRUE=id is a table or database name;
  1936. FALSE=id is an UTF-8 string */
  1937. {
  1938. char nz[NAME_LEN + 1];
  1939. char nz2[NAME_LEN + 1 + EXPLAIN_FILENAME_MAX_EXTRA_LENGTH];
  1940. const char* s = id;
  1941. int q;
  1942. if (file_id) {
  1943. /* Decode the table name. The MySQL function expects
  1944. a NUL-terminated string. The input and output strings
  1945. buffers must not be shared. */
  1946. if (UNIV_UNLIKELY(idlen > (sizeof nz) - 1)) {
  1947. idlen = (sizeof nz) - 1;
  1948. }
  1949. memcpy(nz, id, idlen);
  1950. nz[idlen] = 0;
  1951. s = nz2;
  1952. idlen = explain_filename((THD*) thd, nz, nz2, sizeof nz2,
  1953. EXPLAIN_PARTITIONS_AS_COMMENT);
  1954. goto no_quote;
  1955. }
  1956. /* See if the identifier needs to be quoted. */
  1957. if (UNIV_UNLIKELY(!thd)) {
  1958. q = '"';
  1959. } else {
  1960. q = get_quote_char_for_identifier((THD*) thd, s, (int) idlen);
  1961. }
  1962. if (q == EOF) {
  1963. no_quote:
  1964. if (UNIV_UNLIKELY(idlen > buflen)) {
  1965. idlen = buflen;
  1966. }
  1967. memcpy(buf, s, idlen);
  1968. return(buf + idlen);
  1969. }
  1970. /* Quote the identifier. */
  1971. if (buflen < 2) {
  1972. return(buf);
  1973. }
  1974. *buf++ = q;
  1975. buflen--;
  1976. for (; idlen; idlen--) {
  1977. int c = *s++;
  1978. if (UNIV_UNLIKELY(c == q)) {
  1979. if (UNIV_UNLIKELY(buflen < 3)) {
  1980. break;
  1981. }
  1982. *buf++ = c;
  1983. *buf++ = c;
  1984. buflen -= 2;
  1985. } else {
  1986. if (UNIV_UNLIKELY(buflen < 2)) {
  1987. break;
  1988. }
  1989. *buf++ = c;
  1990. buflen--;
  1991. }
  1992. }
  1993. *buf++ = q;
  1994. return(buf);
  1995. }
  1996. /*****************************************************************//**
  1997. Convert a table or index name to the MySQL system_charset_info (UTF-8)
  1998. and quote it if needed.
  1999. @return pointer to the end of buf */
  2000. extern "C" UNIV_INTERN
  2001. char*
  2002. innobase_convert_name(
  2003. /*==================*/
  2004. char* buf, /*!< out: buffer for converted identifier */
  2005. ulint buflen, /*!< in: length of buf, in bytes */
  2006. const char* id, /*!< in: identifier to convert */
  2007. ulint idlen, /*!< in: length of id, in bytes */
  2008. void* thd, /*!< in: MySQL connection thread, or NULL */
  2009. ibool table_id)/*!< in: TRUE=id is a table or database name;
  2010. FALSE=id is an index name */
  2011. {
  2012. char* s = buf;
  2013. const char* bufend = buf + buflen;
  2014. if (table_id) {
  2015. const char* slash = (const char*) memchr(id, '/', idlen);
  2016. if (!slash) {
  2017. goto no_db_name;
  2018. }
  2019. /* Print the database name and table name separately. */
  2020. s = innobase_convert_identifier(s, bufend - s, id, slash - id,
  2021. thd, TRUE);
  2022. if (UNIV_LIKELY(s < bufend)) {
  2023. *s++ = '.';
  2024. s = innobase_convert_identifier(s, bufend - s,
  2025. slash + 1, idlen
  2026. - (slash - id) - 1,
  2027. thd, TRUE);
  2028. }
  2029. } else if (UNIV_UNLIKELY(*id == TEMP_INDEX_PREFIX)) {
  2030. /* Temporary index name (smart ALTER TABLE) */
  2031. const char temp_index_suffix[]= "--temporary--";
  2032. s = innobase_convert_identifier(buf, buflen, id + 1, idlen - 1,
  2033. thd, FALSE);
  2034. if (s - buf + (sizeof temp_index_suffix - 1) < buflen) {
  2035. memcpy(s, temp_index_suffix,
  2036. sizeof temp_index_suffix - 1);
  2037. s += sizeof temp_index_suffix - 1;
  2038. }
  2039. } else {
  2040. no_db_name:
  2041. s = innobase_convert_identifier(buf, buflen, id, idlen,
  2042. thd, table_id);
  2043. }
  2044. return(s);
  2045. }
  2046. /*****************************************************************//**
  2047. A wrapper function of innobase_convert_name(), convert a table or
  2048. index name to the MySQL system_charset_info (UTF-8) and quote it if needed.
  2049. @return pointer to the end of buf */
  2050. static inline
  2051. void
  2052. innobase_format_name(
  2053. /*==================*/
  2054. char* buf, /*!< out: buffer for converted identifier */
  2055. ulint buflen, /*!< in: length of buf, in bytes */
  2056. const char* name, /*!< in: index or table name to format */
  2057. ibool is_index_name) /*!< in: index name */
  2058. {
  2059. const char* bufend;
  2060. bufend = innobase_convert_name(buf, buflen, name, strlen(name),
  2061. NULL, !is_index_name);
  2062. ut_ad((ulint) (bufend - buf) < buflen);
  2063. buf[bufend - buf] = '\0';
  2064. }
  2065. /**********************************************************************//**
  2066. Determines if the currently running transaction has been interrupted.
  2067. @return TRUE if interrupted */
  2068. extern "C" UNIV_INTERN
  2069. ibool
  2070. trx_is_interrupted(
  2071. /*===============*/
  2072. trx_t* trx) /*!< in: transaction */
  2073. {
  2074. return(trx && trx->mysql_thd && thd_killed((THD*) trx->mysql_thd));
  2075. }
  2076. /**********************************************************************//**
  2077. Determines if the currently running transaction is in strict mode.
  2078. @return TRUE if strict */
  2079. extern "C" UNIV_INTERN
  2080. ibool
  2081. trx_is_strict(
  2082. /*==========*/
  2083. trx_t* trx) /*!< in: transaction */
  2084. {
  2085. return(trx && trx->mysql_thd
  2086. && THDVAR((THD*) trx->mysql_thd, strict_mode));
  2087. }
  2088. /**************************************************************//**
  2089. Resets some fields of a prebuilt struct. The template is used in fast
  2090. retrieval of just those column values MySQL needs in its processing. */
  2091. void
  2092. inline
  2093. ha_innobase::reset_template(void)
  2094. /*=============================*/
  2095. {
  2096. ut_ad(prebuilt->magic_n == ROW_PREBUILT_ALLOCATED);
  2097. ut_ad(prebuilt->magic_n2 == prebuilt->magic_n);
  2098. prebuilt->keep_other_fields_on_keyread = 0;
  2099. prebuilt->read_just_key = 0;
  2100. /* Reset index condition pushdown state. */
  2101. if (prebuilt->idx_cond) {
  2102. prebuilt->idx_cond = NULL;
  2103. prebuilt->idx_cond_n_cols = 0;
  2104. /* Invalidate prebuilt->mysql_template
  2105. in ha_innobase::write_row(). */
  2106. prebuilt->template_type = ROW_MYSQL_NO_TEMPLATE;
  2107. }
  2108. }
  2109. /*****************************************************************//**
  2110. Call this when you have opened a new table handle in HANDLER, before you
  2111. call index_read_idx() etc. Actually, we can let the cursor stay open even
  2112. over a transaction commit! Then you should call this before every operation,
  2113. fetch next etc. This function inits the necessary things even after a
  2114. transaction commit. */
  2115. UNIV_INTERN
  2116. void
  2117. ha_innobase::init_table_handle_for_HANDLER(void)
  2118. /*============================================*/
  2119. {
  2120. /* If current thd does not yet have a trx struct, create one.
  2121. If the current handle does not yet have a prebuilt struct, create
  2122. one. Update the trx pointers in the prebuilt struct. Normally
  2123. this operation is done in external_lock. */
  2124. update_thd(ha_thd());
  2125. /* Initialize the prebuilt struct much like it would be inited in
  2126. external_lock */
  2127. innobase_release_stat_resources(prebuilt->trx);
  2128. /* If the transaction is not started yet, start it */
  2129. trx_start_if_not_started(prebuilt->trx);
  2130. /* Assign a read view if the transaction does not have it yet */
  2131. trx_assign_read_view(prebuilt->trx);
  2132. innobase_register_trx(ht, user_thd, prebuilt->trx);
  2133. /* We did the necessary inits in this function, no need to repeat them
  2134. in row_search_for_mysql */
  2135. prebuilt->sql_stat_start = FALSE;
  2136. /* We let HANDLER always to do the reads as consistent reads, even
  2137. if the trx isolation level would have been specified as SERIALIZABLE */
  2138. prebuilt->select_lock_type = LOCK_NONE;
  2139. prebuilt->stored_select_lock_type = LOCK_NONE;
  2140. /* Always fetch all columns in the index record */
  2141. prebuilt->hint_need_to_fetch_extra_cols = ROW_RETRIEVE_ALL_COLS;
  2142. /* We want always to fetch all columns in the whole row? Or do
  2143. we???? */
  2144. prebuilt->used_in_HANDLER = TRUE;
  2145. reset_template();
  2146. }
  2147. /*********************************************************************//**
  2148. Opens an InnoDB database.
  2149. @return 0 on success, error code on failure */
  2150. static
  2151. int
  2152. innobase_init(
  2153. /*==========*/
  2154. void *p) /*!< in: InnoDB handlerton */
  2155. {
  2156. static char current_dir[3]; /*!< Set if using current lib */
  2157. int err;
  2158. bool ret;
  2159. char *default_path;
  2160. uint format_id;
  2161. DBUG_ENTER("innobase_init");
  2162. handlerton *innobase_hton= (handlerton *)p;
  2163. innodb_hton_ptr = innobase_hton;
  2164. innobase_hton->state = SHOW_OPTION_YES;
  2165. innobase_hton->db_type= DB_TYPE_INNODB;
  2166. innobase_hton->savepoint_offset=sizeof(trx_named_savept_t);
  2167. innobase_hton->close_connection=innobase_close_connection;
  2168. innobase_hton->savepoint_set=innobase_savepoint;
  2169. innobase_hton->savepoint_rollback=innobase_rollback_to_savepoint;
  2170. innobase_hton->savepoint_release=innobase_release_savepoint;
  2171. innobase_hton->commit_ordered=innobase_commit_ordered;
  2172. innobase_hton->commit=innobase_commit;
  2173. innobase_hton->rollback=innobase_rollback;
  2174. innobase_hton->prepare=innobase_xa_prepare;
  2175. innobase_hton->recover=innobase_xa_recover;
  2176. innobase_hton->commit_by_xid=innobase_commit_by_xid;
  2177. innobase_hton->rollback_by_xid=innobase_rollback_by_xid;
  2178. innobase_hton->commit_checkpoint_request=innobase_checkpoint_request;
  2179. innobase_hton->checkpoint_state= innobase_checkpoint_state;
  2180. innobase_hton->create_cursor_read_view=innobase_create_cursor_view;
  2181. innobase_hton->set_cursor_read_view=innobase_set_cursor_view;
  2182. innobase_hton->close_cursor_read_view=innobase_close_cursor_view;
  2183. innobase_hton->create=innobase_create_handler;
  2184. innobase_hton->drop_database=innobase_drop_database;
  2185. innobase_hton->panic=innobase_end;
  2186. innobase_hton->start_consistent_snapshot=innobase_start_trx_and_assign_read_view;
  2187. innobase_hton->flush_logs=innobase_flush_logs;
  2188. innobase_hton->show_status=innobase_show_status;
  2189. innobase_hton->flags=HTON_NO_FLAGS;
  2190. innobase_hton->release_temporary_latches=innobase_release_temporary_latches;
  2191. innobase_hton->alter_table_flags = innobase_alter_table_flags;
  2192. ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
  2193. #ifndef DBUG_OFF
  2194. static const char test_filename[] = "-@";
  2195. char test_tablename[sizeof test_filename
  2196. + sizeof srv_mysql50_table_name_prefix];
  2197. if ((sizeof test_tablename) - 1
  2198. != filename_to_tablename(test_filename, test_tablename,
  2199. sizeof test_tablename, true)
  2200. || strncmp(test_tablename,
  2201. srv_mysql50_table_name_prefix,
  2202. sizeof srv_mysql50_table_name_prefix)
  2203. || strcmp(test_tablename
  2204. + sizeof srv_mysql50_table_name_prefix,
  2205. test_filename)) {
  2206. sql_print_error("tablename encoding has been changed");
  2207. goto error;
  2208. }
  2209. #endif /* DBUG_OFF */
  2210. srv_page_size = 0;
  2211. srv_page_size_shift = 0;
  2212. if (innobase_page_size != (1 << 14)) {
  2213. uint n_shift;
  2214. fprintf(stderr,
  2215. "InnoDB: Warning: innodb_page_size has been changed from default value 16384. (###EXPERIMENTAL### operation)\n");
  2216. for (n_shift = 12; n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX; n_shift++) {
  2217. if (innobase_page_size == ((ulong)1 << n_shift)) {
  2218. srv_page_size_shift = n_shift;
  2219. srv_page_size = (1 << srv_page_size_shift);
  2220. fprintf(stderr,
  2221. "InnoDB: The universal page size of the database is set to %lu.\n",
  2222. srv_page_size);
  2223. break;
  2224. }
  2225. }
  2226. } else {
  2227. srv_page_size_shift = 14;
  2228. srv_page_size = (1 << srv_page_size_shift);
  2229. }
  2230. if (!srv_page_size_shift) {
  2231. fprintf(stderr,
  2232. "InnoDB: Error: %lu is not a valid value for innodb_page_size.\n"
  2233. "InnoDB: Error: Valid values are 4096, 8192, and 16384 (default=16384).\n",
  2234. innobase_page_size);
  2235. goto error;
  2236. }
  2237. srv_log_block_size = 0;
  2238. if (innobase_log_block_size != (1 << 9)) { /*!=512*/
  2239. uint n_shift;
  2240. fprintf(stderr,
  2241. "InnoDB: Warning: innodb_log_block_size has been changed from default value 512. (###EXPERIMENTAL### operation)\n");
  2242. for (n_shift = 9; n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX; n_shift++) {
  2243. if (innobase_log_block_size == ((ulong)1 << n_shift)) {
  2244. srv_log_block_size = (1 << n_shift);
  2245. fprintf(stderr,
  2246. "InnoDB: The log block size is set to %lu.\n",
  2247. srv_log_block_size);
  2248. break;
  2249. }
  2250. }
  2251. } else {
  2252. srv_log_block_size = 512;
  2253. }
  2254. if (!srv_log_block_size) {
  2255. fprintf(stderr,
  2256. "InnoDB: Error: %lu is not a valid value for innodb_log_block_size.\n"
  2257. "InnoDB: Error: A valid value for innodb_log_block_size is\n"
  2258. "InnoDB: Error: a power of 2 from 512 to 16384.\n",
  2259. innobase_log_block_size);
  2260. goto error;
  2261. }
  2262. #ifndef MYSQL_SERVER
  2263. innodb_overwrite_relay_log_info = FALSE;
  2264. #endif
  2265. #ifdef HAVE_REPLICATION
  2266. #ifdef MYSQL_SERVER
  2267. /* read master log position from relay-log.info if exists */
  2268. char fname[FN_REFLEN+128];
  2269. int pos;
  2270. int info_fd;
  2271. IO_CACHE info_file;
  2272. fname[0] = '\0';
  2273. if(innobase_overwrite_relay_log_info) {
  2274. fprintf(stderr,
  2275. "InnoDB: Warning: innodb_overwrite_relay_log_info is enabled."
  2276. " Updates by other storage engines may not be synchronized.\n");
  2277. bzero((char*) &info_file, sizeof(info_file));
  2278. fn_format(fname, relay_log_info_file, mysql_data_home, "", 4+32);
  2279. int error=0;
  2280. if (!access(fname,F_OK)) {
  2281. /* exist */
  2282. if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0) {
  2283. error=1;
  2284. } else if (init_io_cache(&info_file, info_fd, IO_SIZE*2,
  2285. READ_CACHE, 0L, 0, MYF(MY_WME))) {
  2286. error=1;
  2287. }
  2288. if (error) {
  2289. relay_info_error:
  2290. if (info_fd >= 0)
  2291. my_close(info_fd, MYF(0));
  2292. fname[0] = '\0';
  2293. goto skip_relay;
  2294. }
  2295. } else {
  2296. fname[0] = '\0';
  2297. goto skip_relay;
  2298. }
  2299. if (init_strvar_from_file(fname, sizeof(fname), &info_file, "") || /* dummy (it is relay-log) */
  2300. init_intvar_from_file(&pos, &info_file, BIN_LOG_HEADER_SIZE)) {
  2301. end_io_cache(&info_file);
  2302. error=1;
  2303. goto relay_info_error;
  2304. }
  2305. fprintf(stderr,
  2306. "InnoDB: relay-log.info is detected.\n"
  2307. "InnoDB: relay log: position %u, file name %s\n",
  2308. pos, fname);
  2309. strncpy(trx_sys_mysql_relay_log_name, fname, TRX_SYS_MYSQL_MASTER_LOG_NAME_LEN);
  2310. trx_sys_mysql_relay_log_pos = (ib_int64_t) pos;
  2311. if (init_strvar_from_file(fname, sizeof(fname), &info_file, "") ||
  2312. init_intvar_from_file(&pos, &info_file, 0)) {
  2313. end_io_cache(&info_file);
  2314. error=1;
  2315. goto relay_info_error;
  2316. }
  2317. fprintf(stderr,
  2318. "InnoDB: master log: position %u, file name %s\n",
  2319. pos, fname);
  2320. strncpy(trx_sys_mysql_master_log_name, fname, TRX_SYS_MYSQL_MASTER_LOG_NAME_LEN);
  2321. trx_sys_mysql_master_log_pos = (ib_int64_t) pos;
  2322. end_io_cache(&info_file);
  2323. if (info_fd >= 0)
  2324. my_close(info_fd, MYF(0));
  2325. }
  2326. skip_relay:
  2327. #endif /* MYSQL_SERVER */
  2328. #endif /* HAVE_REPLICATION */
  2329. /* Check that values don't overflow on 32-bit systems. */
  2330. if (sizeof(ulint) == 4) {
  2331. if (innobase_buffer_pool_size > UINT_MAX32) {
  2332. sql_print_error(
  2333. "innobase_buffer_pool_size can't be over 4GB"
  2334. " on 32-bit systems");
  2335. goto error;
  2336. }
  2337. if (innobase_log_file_size > UINT_MAX32) {
  2338. sql_print_error(
  2339. "innobase_log_file_size can't be over 4GB"
  2340. " on 32-bit systems");
  2341. goto error;
  2342. }
  2343. }
  2344. os_innodb_umask = (ulint)my_umask;
  2345. /* First calculate the default path for innodb_data_home_dir etc.,
  2346. in case the user has not given any value.
  2347. Note that when using the embedded server, the datadirectory is not
  2348. necessarily the current directory of this program. */
  2349. if (mysqld_embedded) {
  2350. default_path = mysql_real_data_home;
  2351. fil_path_to_mysql_datadir = mysql_real_data_home;
  2352. } else {
  2353. /* It's better to use current lib, to keep paths short */
  2354. current_dir[0] = FN_CURLIB;
  2355. current_dir[1] = FN_LIBCHAR;
  2356. current_dir[2] = 0;
  2357. default_path = current_dir;
  2358. }
  2359. ut_a(default_path);
  2360. /* Set InnoDB initialization parameters according to the values
  2361. read from MySQL .cnf file */
  2362. /*--------------- Data files -------------------------*/
  2363. /* The default dir for data files is the datadir of MySQL */
  2364. srv_data_home = (innobase_data_home_dir ? innobase_data_home_dir :
  2365. default_path);
  2366. /* Set default InnoDB data file size to 10 MB and let it be
  2367. auto-extending. Thus users can use InnoDB in >= 4.0 without having
  2368. to specify any startup options. */
  2369. if (!innobase_data_file_path) {
  2370. innobase_data_file_path = (char*) "ibdata1:10M:autoextend";
  2371. }
  2372. /* Since InnoDB edits the argument in the next call, we make another
  2373. copy of it: */
  2374. internal_innobase_data_file_path = my_strdup(innobase_data_file_path,
  2375. MYF(MY_FAE));
  2376. ret = (bool) srv_parse_data_file_paths_and_sizes(
  2377. internal_innobase_data_file_path);
  2378. if (ret == FALSE) {
  2379. sql_print_error(
  2380. "InnoDB: syntax error in innodb_data_file_path");
  2381. mem_free_and_error:
  2382. srv_free_paths_and_sizes();
  2383. my_free(internal_innobase_data_file_path);
  2384. goto error;
  2385. }
  2386. srv_doublewrite_file = innobase_doublewrite_file;
  2387. srv_use_sys_stats_table = (ibool) innobase_use_sys_stats_table;
  2388. #ifdef UNIV_DEBUG
  2389. srv_sys_stats_root_page = innobase_sys_stats_root_page;
  2390. #endif
  2391. /* -------------- Log files ---------------------------*/
  2392. /* The default dir for log files is the datadir of MySQL */
  2393. if (!innobase_log_group_home_dir) {
  2394. innobase_log_group_home_dir = default_path;
  2395. }
  2396. #ifdef UNIV_LOG_ARCHIVE
  2397. /* Since innodb_log_arch_dir has no relevance under MySQL,
  2398. starting from 4.0.6 we always set it the same as
  2399. innodb_log_group_home_dir: */
  2400. innobase_log_arch_dir = innobase_log_group_home_dir;
  2401. srv_arch_dir = innobase_log_arch_dir;
  2402. #endif /* UNIG_LOG_ARCHIVE */
  2403. ret = (bool)
  2404. srv_parse_log_group_home_dirs(innobase_log_group_home_dir);
  2405. if (ret == FALSE || innobase_mirrored_log_groups != 1) {
  2406. sql_print_error("syntax error in innodb_log_group_home_dir, or a "
  2407. "wrong number of mirrored log groups");
  2408. goto mem_free_and_error;
  2409. }
  2410. /* Validate the file format by animal name */
  2411. if (innobase_file_format_name != NULL) {
  2412. format_id = innobase_file_format_name_lookup(
  2413. innobase_file_format_name);
  2414. if (format_id > DICT_TF_FORMAT_MAX) {
  2415. sql_print_error("InnoDB: wrong innodb_file_format.");
  2416. goto mem_free_and_error;
  2417. }
  2418. } else {
  2419. /* Set it to the default file format id. Though this
  2420. should never happen. */
  2421. format_id = 0;
  2422. }
  2423. srv_file_format = format_id;
  2424. /* Given the type of innobase_file_format_name we have little
  2425. choice but to cast away the constness from the returned name.
  2426. innobase_file_format_name is used in the MySQL set variable
  2427. interface and so can't be const. */
  2428. innobase_file_format_name =
  2429. (char*) trx_sys_file_format_id_to_name(format_id);
  2430. /* Check innobase_file_format_check variable */
  2431. if (!innobase_file_format_check) {
  2432. /* Set the value to disable checking. */
  2433. srv_max_file_format_at_startup = DICT_TF_FORMAT_MAX + 1;
  2434. } else {
  2435. /* Set the value to the lowest supported format. */
  2436. srv_max_file_format_at_startup = DICT_TF_FORMAT_MIN;
  2437. }
  2438. /* Did the user specify a format name that we support?
  2439. As a side effect it will update the variable
  2440. srv_max_file_format_at_startup */
  2441. if (innobase_file_format_validate_and_set(
  2442. innobase_file_format_max) < 0) {
  2443. sql_print_error("InnoDB: invalid "
  2444. "innodb_file_format_max value: "
  2445. "should be any value up to %s or its "
  2446. "equivalent numeric id",
  2447. trx_sys_file_format_id_to_name(
  2448. DICT_TF_FORMAT_MAX));
  2449. goto mem_free_and_error;
  2450. }
  2451. if (innobase_change_buffering) {
  2452. ulint use;
  2453. for (use = 0;
  2454. use < UT_ARR_SIZE(innobase_change_buffering_values);
  2455. use++) {
  2456. if (!innobase_strcasecmp(
  2457. innobase_change_buffering,
  2458. innobase_change_buffering_values[use])) {
  2459. ibuf_use = (ibuf_use_t) use;
  2460. goto innobase_change_buffering_inited_ok;
  2461. }
  2462. }
  2463. sql_print_error("InnoDB: invalid value "
  2464. "innodb_change_buffering=%s",
  2465. innobase_change_buffering);
  2466. goto mem_free_and_error;
  2467. }
  2468. innobase_change_buffering_inited_ok:
  2469. ut_a((ulint) ibuf_use < UT_ARR_SIZE(innobase_change_buffering_values));
  2470. innobase_change_buffering = (char*)
  2471. innobase_change_buffering_values[ibuf_use];
  2472. /* --------------------------------------------------*/
  2473. srv_file_flush_method_str = innobase_file_flush_method;
  2474. srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
  2475. srv_n_log_files = (ulint) innobase_log_files_in_group;
  2476. srv_log_file_size = (ulint) innobase_log_file_size;
  2477. srv_thread_concurrency_timer_based =
  2478. (ibool) innobase_thread_concurrency_timer_based;
  2479. #ifdef UNIV_LOG_ARCHIVE
  2480. srv_log_archive_on = (ulint) innobase_log_archive;
  2481. #endif /* UNIV_LOG_ARCHIVE */
  2482. srv_log_buffer_size = (ulint) innobase_log_buffer_size;
  2483. srv_buf_pool_size = (ulint) innobase_buffer_pool_size;
  2484. srv_buf_pool_instances = (ulint) innobase_buffer_pool_instances;
  2485. if (innobase_buffer_pool_shm_key) {
  2486. fprintf(stderr,
  2487. "InnoDB: Warning: innodb_buffer_pool_shm_key is deprecated function.\n"
  2488. "InnoDB: innodb_buffer_pool_shm_key was ignored.\n");
  2489. }
  2490. srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
  2491. srv_n_file_io_threads = (ulint) innobase_file_io_threads;
  2492. srv_n_read_io_threads = (ulint) innobase_read_io_threads;
  2493. srv_n_write_io_threads = (ulint) innobase_write_io_threads;
  2494. srv_read_ahead &= 3;
  2495. srv_adaptive_flushing_method %= 3;
  2496. srv_flush_neighbor_pages %= 3;
  2497. srv_force_recovery = (ulint) innobase_force_recovery;
  2498. srv_recovery_stats = (ibool) innobase_recovery_stats;
  2499. srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
  2500. srv_use_checksums = (ibool) innobase_use_checksums;
  2501. srv_fast_checksum = (ibool) innobase_fast_checksum;
  2502. srv_blocking_lru_restore = (ibool) innobase_blocking_lru_restore;
  2503. #ifdef HAVE_LARGE_PAGES
  2504. if ((os_use_large_pages = (ibool) my_use_large_pages))
  2505. os_large_page_size = (ulint) opt_large_page_size;
  2506. #endif
  2507. row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
  2508. srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog;
  2509. srv_max_n_open_files = (ulint) innobase_open_files;
  2510. srv_innodb_status = (ibool) innobase_create_status_file;
  2511. srv_print_verbose_log = mysqld_embedded ? 0 : 1;
  2512. /* Store the default charset-collation number of this MySQL
  2513. installation */
  2514. data_mysql_default_charset_coll = (ulint)default_charset_info->number;
  2515. ut_a(DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL ==
  2516. my_charset_latin1.number);
  2517. ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
  2518. /* Store the latin1_swedish_ci character ordering table to InnoDB. For
  2519. non-latin1_swedish_ci charsets we use the MySQL comparison functions,
  2520. and consequently we do not need to know the ordering internally in
  2521. InnoDB. */
  2522. ut_a(0 == strcmp(my_charset_latin1.name, "latin1_swedish_ci"));
  2523. srv_latin1_ordering = my_charset_latin1.sort_order;
  2524. innobase_commit_concurrency_init_default();
  2525. #ifndef EXTENDED_FOR_KILLIDLE
  2526. srv_kill_idle_transaction = 0;
  2527. #endif
  2528. #ifdef HAVE_PSI_INTERFACE
  2529. /* Register keys with MySQL performance schema */
  2530. if (PSI_server) {
  2531. int count;
  2532. count = array_elements(all_pthread_mutexes);
  2533. PSI_server->register_mutex("innodb",
  2534. all_pthread_mutexes, count);
  2535. # ifdef UNIV_PFS_MUTEX
  2536. count = array_elements(all_innodb_mutexes);
  2537. PSI_server->register_mutex("innodb",
  2538. all_innodb_mutexes, count);
  2539. # endif /* UNIV_PFS_MUTEX */
  2540. # ifdef UNIV_PFS_RWLOCK
  2541. count = array_elements(all_innodb_rwlocks);
  2542. PSI_server->register_rwlock("innodb",
  2543. all_innodb_rwlocks, count);
  2544. # endif /* UNIV_PFS_MUTEX */
  2545. # ifdef UNIV_PFS_THREAD
  2546. count = array_elements(all_innodb_threads);
  2547. PSI_server->register_thread("innodb",
  2548. all_innodb_threads, count);
  2549. # endif /* UNIV_PFS_THREAD */
  2550. # ifdef UNIV_PFS_IO
  2551. count = array_elements(all_innodb_files);
  2552. PSI_server->register_file("innodb",
  2553. all_innodb_files, count);
  2554. # endif /* UNIV_PFS_IO */
  2555. count = array_elements(all_innodb_conds);
  2556. PSI_server->register_cond("innodb",
  2557. all_innodb_conds, count);
  2558. }
  2559. #endif /* HAVE_PSI_INTERFACE */
  2560. /* Since we in this module access directly the fields of a trx
  2561. struct, and due to different headers and flags it might happen that
  2562. mutex_t has a different size in this module and in InnoDB
  2563. modules, we check at run time that the size is the same in
  2564. these compilation modules. */
  2565. err = innobase_start_or_create_for_mysql();
  2566. if (err != DB_SUCCESS) {
  2567. goto mem_free_and_error;
  2568. }
  2569. #ifdef HAVE_REPLICATION
  2570. #ifdef MYSQL_SERVER
  2571. if(innobase_overwrite_relay_log_info) {
  2572. /* If InnoDB progressed from relay-log.info, overwrite it */
  2573. if (fname[0] == '\0') {
  2574. fprintf(stderr,
  2575. "InnoDB: Something is wrong with the file relay-info.log. InnoDB will not overwrite it.\n");
  2576. } else if (0 != strcmp(fname, trx_sys_mysql_master_log_name)
  2577. || pos != trx_sys_mysql_master_log_pos) {
  2578. /* Overwrite relay-log.info */
  2579. bzero((char*) &info_file, sizeof(info_file));
  2580. fn_format(fname, relay_log_info_file, mysql_data_home, "", 4+32);
  2581. int error = 0;
  2582. if (!access(fname,F_OK)) {
  2583. /* exist */
  2584. if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0) {
  2585. error = 1;
  2586. } else if (init_io_cache(&info_file, info_fd, IO_SIZE*2,
  2587. WRITE_CACHE, 0L, 0, MYF(MY_WME))) {
  2588. error = 1;
  2589. }
  2590. if (error) {
  2591. if (info_fd >= 0)
  2592. my_close(info_fd, MYF(0));
  2593. goto skip_overwrite;
  2594. }
  2595. } else {
  2596. error = 1;
  2597. goto skip_overwrite;
  2598. }
  2599. char buff[FN_REFLEN*2+22*2+4], *pos;
  2600. my_b_seek(&info_file, 0L);
  2601. pos=strmov(buff, trx_sys_mysql_relay_log_name);
  2602. *pos++='\n';
  2603. pos=longlong10_to_str(trx_sys_mysql_relay_log_pos, pos, 10);
  2604. *pos++='\n';
  2605. pos=strmov(pos, trx_sys_mysql_master_log_name);
  2606. *pos++='\n';
  2607. pos=longlong10_to_str(trx_sys_mysql_master_log_pos, pos, 10);
  2608. *pos='\n';
  2609. if (my_b_write(&info_file, (uchar*) buff, (size_t) (pos-buff)+1))
  2610. error = 1;
  2611. if (flush_io_cache(&info_file))
  2612. error = 1;
  2613. end_io_cache(&info_file);
  2614. if (info_fd >= 0)
  2615. my_close(info_fd, MYF(0));
  2616. skip_overwrite:
  2617. if (error) {
  2618. fprintf(stderr,
  2619. "InnoDB: ERROR: An error occurred while overwriting relay-log.info.\n");
  2620. } else {
  2621. fprintf(stderr,
  2622. "InnoDB: The file relay-log.info was successfully overwritten.\n");
  2623. }
  2624. } else {
  2625. fprintf(stderr,
  2626. "InnoDB: InnoDB and relay-log.info are synchronized. InnoDB will not overwrite it.\n");
  2627. }
  2628. }
  2629. #endif /* MYSQL_SERVER */
  2630. #endif /* HAVE_REPLICATION */
  2631. innobase_old_blocks_pct = buf_LRU_old_ratio_update(
  2632. innobase_old_blocks_pct, TRUE);
  2633. innobase_open_tables = hash_create(200);
  2634. mysql_mutex_init(innobase_share_mutex_key,
  2635. &innobase_share_mutex,
  2636. MY_MUTEX_INIT_FAST);
  2637. mysql_mutex_init(commit_threads_m_key,
  2638. &commit_threads_m, MY_MUTEX_INIT_FAST);
  2639. mysql_mutex_init(commit_cond_mutex_key,
  2640. &commit_cond_m, MY_MUTEX_INIT_FAST);
  2641. mysql_cond_init(commit_cond_key, &commit_cond, NULL);
  2642. mysql_mutex_init(pending_checkpoint_mutex_key,
  2643. &pending_checkpoint_mutex,
  2644. MY_MUTEX_INIT_FAST);
  2645. innodb_inited= 1;
  2646. #ifdef MYSQL_DYNAMIC_PLUGIN
  2647. if (innobase_hton != p) {
  2648. innobase_hton = reinterpret_cast<handlerton*>(p);
  2649. *innobase_hton = *innodb_hton_ptr;
  2650. }
  2651. #endif /* MYSQL_DYNAMIC_PLUGIN */
  2652. /* Get the current high water mark format. */
  2653. innobase_file_format_max = (char*) trx_sys_file_format_max_get();
  2654. DBUG_RETURN(FALSE);
  2655. error:
  2656. DBUG_RETURN(TRUE);
  2657. }
  2658. /*******************************************************************//**
  2659. Closes an InnoDB database.
  2660. @return TRUE if error */
  2661. static
  2662. int
  2663. innobase_end(
  2664. /*=========*/
  2665. handlerton* hton, /*!< in/out: InnoDB handlerton */
  2666. ha_panic_function type __attribute__((unused)))
  2667. /*!< in: ha_panic() parameter */
  2668. {
  2669. int err= 0;
  2670. DBUG_ENTER("innobase_end");
  2671. DBUG_ASSERT(hton == innodb_hton_ptr);
  2672. if (innodb_inited) {
  2673. srv_fast_shutdown = (ulint) innobase_fast_shutdown;
  2674. innodb_inited = 0;
  2675. hash_table_free(innobase_open_tables);
  2676. innobase_open_tables = NULL;
  2677. if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
  2678. err = 1;
  2679. }
  2680. srv_free_paths_and_sizes();
  2681. my_free(internal_innobase_data_file_path);
  2682. mysql_mutex_destroy(&innobase_share_mutex);
  2683. mysql_mutex_destroy(&commit_threads_m);
  2684. mysql_mutex_destroy(&commit_cond_m);
  2685. mysql_cond_destroy(&commit_cond);
  2686. mysql_mutex_destroy(&pending_checkpoint_mutex);
  2687. }
  2688. DBUG_RETURN(err);
  2689. }
  2690. /****************************************************************//**
  2691. Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
  2692. the logs, and the name of this function should be innobase_checkpoint.
  2693. @return TRUE if error */
  2694. static
  2695. bool
  2696. innobase_flush_logs(
  2697. /*================*/
  2698. handlerton* hton) /*!< in/out: InnoDB handlerton */
  2699. {
  2700. bool result = 0;
  2701. DBUG_ENTER("innobase_flush_logs");
  2702. DBUG_ASSERT(hton == innodb_hton_ptr);
  2703. log_buffer_flush_to_disk();
  2704. DBUG_RETURN(result);
  2705. }
  2706. /****************************************************************//**
  2707. Return alter table flags supported in an InnoDB database. */
  2708. static
  2709. uint
  2710. innobase_alter_table_flags(
  2711. /*=======================*/
  2712. uint flags)
  2713. {
  2714. return(HA_INPLACE_ADD_INDEX_NO_READ_WRITE
  2715. | HA_INPLACE_ADD_INDEX_NO_WRITE
  2716. | HA_INPLACE_DROP_INDEX_NO_READ_WRITE
  2717. | HA_INPLACE_ADD_UNIQUE_INDEX_NO_READ_WRITE
  2718. | HA_INPLACE_ADD_UNIQUE_INDEX_NO_WRITE
  2719. | HA_INPLACE_DROP_UNIQUE_INDEX_NO_READ_WRITE
  2720. | HA_INPLACE_ADD_PK_INDEX_NO_READ_WRITE);
  2721. }
  2722. /*****************************************************************//**
  2723. Commits a transaction in an InnoDB database. */
  2724. static
  2725. void
  2726. innobase_commit_low(
  2727. /*================*/
  2728. trx_t* trx) /*!< in: transaction handle */
  2729. {
  2730. if (trx_is_started(trx)) {
  2731. #ifdef HAVE_REPLICATION
  2732. #ifdef MYSQL_SERVER
  2733. THD *thd=current_thd;
  2734. if (innobase_overwrite_relay_log_info &&
  2735. thd && thd_is_replication_slave_thread(thd) &&
  2736. thd->connection_name.length) {
  2737. /* Update the replication position info inside InnoDB.
  2738. In embedded server, does nothing. */
  2739. const char *log_file_name, *group_relay_log_name;
  2740. ulonglong log_pos, relay_log_pos;
  2741. bool res = rpl_get_position_info(&log_file_name, &log_pos,
  2742. &group_relay_log_name,
  2743. &relay_log_pos);
  2744. if (res) {
  2745. trx->mysql_master_log_file_name = log_file_name;
  2746. trx->mysql_master_log_pos = (ib_int64_t)log_pos;
  2747. trx->mysql_relay_log_file_name = group_relay_log_name;
  2748. trx->mysql_relay_log_pos = (ib_int64_t)relay_log_pos;
  2749. }
  2750. }
  2751. #endif /* MYSQL_SERVER */
  2752. #endif /* HAVE_REPLICATION */
  2753. trx_commit_for_mysql(trx);
  2754. }
  2755. }
  2756. /*****************************************************************//**
  2757. Creates an InnoDB transaction struct for the thd if it does not yet have one.
  2758. Starts a new InnoDB transaction if a transaction is not yet started. And
  2759. assigns a new snapshot for a consistent read if the transaction does not yet
  2760. have one.
  2761. @return 0 */
  2762. static
  2763. int
  2764. innobase_start_trx_and_assign_read_view(
  2765. /*====================================*/
  2766. handlerton *hton, /*!< in: Innodb handlerton */
  2767. THD* thd) /*!< in: MySQL thread handle of the user for whom
  2768. the transaction should be committed */
  2769. {
  2770. trx_t* trx;
  2771. DBUG_ENTER("innobase_start_trx_and_assign_read_view");
  2772. DBUG_ASSERT(hton == innodb_hton_ptr);
  2773. /* Create a new trx struct for thd, if it does not yet have one */
  2774. trx = check_trx_exists(thd);
  2775. /* This is just to play safe: release a possible FIFO ticket and
  2776. search latch. Since we will reserve the kernel mutex, we have to
  2777. release the search system latch first to obey the latching order. */
  2778. innobase_release_stat_resources(trx);
  2779. /* If the transaction is not started yet, start it */
  2780. trx_start_if_not_started(trx);
  2781. /* Assign a read view if the transaction does not have it yet */
  2782. trx_assign_read_view(trx);
  2783. /* Set the MySQL flag to mark that there is an active transaction */
  2784. innobase_register_trx(hton, current_thd, trx);
  2785. DBUG_RETURN(0);
  2786. }
  2787. static
  2788. void
  2789. innobase_commit_ordered_2(
  2790. /*============*/
  2791. trx_t* trx, /*!< in: Innodb transaction */
  2792. THD* thd) /*!< in: MySQL thread handle */
  2793. {
  2794. ulonglong tmp_pos;
  2795. DBUG_ENTER("innobase_commit_ordered");
  2796. /* We need current binlog position for ibbackup to work.
  2797. Note, the position is current because commit_ordered is guaranteed
  2798. to be called in same sequenece as writing to binlog. */
  2799. retry:
  2800. if (innobase_commit_concurrency > 0) {
  2801. mysql_mutex_lock(&commit_cond_m);
  2802. commit_threads++;
  2803. if (commit_threads > innobase_commit_concurrency) {
  2804. commit_threads--;
  2805. mysql_cond_wait(&commit_cond,
  2806. &commit_cond_m);
  2807. mysql_mutex_unlock(&commit_cond_m);
  2808. goto retry;
  2809. }
  2810. else {
  2811. mysql_mutex_unlock(&commit_cond_m);
  2812. }
  2813. }
  2814. mysql_bin_log_commit_pos(thd, &tmp_pos, &(trx->mysql_log_file_name));
  2815. trx->mysql_log_offset = (ib_int64_t) tmp_pos;
  2816. /* Don't do write + flush right now. For group commit
  2817. to work we want to do the flush in the innobase_commit()
  2818. method, which runs without holding any locks. */
  2819. trx->flush_log_later = TRUE;
  2820. innobase_commit_low(trx);
  2821. trx->flush_log_later = FALSE;
  2822. if (innobase_commit_concurrency > 0) {
  2823. mysql_mutex_lock(&commit_cond_m);
  2824. commit_threads--;
  2825. mysql_cond_signal(&commit_cond);
  2826. mysql_mutex_unlock(&commit_cond_m);
  2827. }
  2828. DBUG_VOID_RETURN;
  2829. }
  2830. /*****************************************************************//**
  2831. Perform the first, fast part of InnoDB commit.
  2832. Doing it in this call ensures that we get the same commit order here
  2833. as in binlog and any other participating transactional storage engines.
  2834. Note that we want to do as little as really needed here, as we run
  2835. under a global mutex. The expensive fsync() is done later, in
  2836. innobase_commit(), without a lock so group commit can take place.
  2837. Note also that this method can be called from a different thread than
  2838. the one handling the rest of the transaction. */
  2839. static
  2840. void
  2841. innobase_commit_ordered(
  2842. /*============*/
  2843. handlerton *hton, /*!< in: Innodb handlerton */
  2844. THD* thd, /*!< in: MySQL thread handle of the user for whom
  2845. the transaction should be committed */
  2846. bool all) /*!< in: TRUE - commit transaction
  2847. FALSE - the current SQL statement ended */
  2848. {
  2849. trx_t* trx;
  2850. DBUG_ENTER("innobase_commit_ordered");
  2851. DBUG_ASSERT(hton == innodb_hton_ptr);
  2852. trx = check_trx_exists(thd);
  2853. /* Since we will reserve the kernel mutex, we must not be holding the
  2854. search system latch, or we will disobey the latching order. But we
  2855. already released it in innobase_xa_prepare() (if not before), so just
  2856. have an assert here.*/
  2857. ut_ad(!trx->has_search_latch);
  2858. if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) {
  2859. /* We cannot throw error here; instead we will catch this error
  2860. again in innobase_commit() and report it from there. */
  2861. DBUG_VOID_RETURN;
  2862. }
  2863. /* commit_ordered is only called when committing the whole transaction
  2864. (or an SQL statement when autocommit is on). */
  2865. DBUG_ASSERT(all ||
  2866. (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)));
  2867. innobase_commit_ordered_2(trx, thd);
  2868. trx_set_active_commit_ordered(trx);
  2869. DBUG_VOID_RETURN;
  2870. }
  2871. /*****************************************************************//**
  2872. Commits a transaction in an InnoDB database or marks an SQL statement
  2873. ended.
  2874. @return 0 */
  2875. static
  2876. int
  2877. innobase_commit(
  2878. /*============*/
  2879. handlerton *hton, /*!< in: Innodb handlerton */
  2880. THD* thd, /*!< in: MySQL thread handle of the user for whom
  2881. the transaction should be committed */
  2882. bool all) /*!< in: TRUE - commit transaction
  2883. FALSE - the current SQL statement ended */
  2884. {
  2885. trx_t* trx;
  2886. DBUG_ENTER("innobase_commit");
  2887. DBUG_ASSERT(hton == innodb_hton_ptr);
  2888. DBUG_PRINT("trans", ("ending transaction"));
  2889. trx = check_trx_exists(thd);
  2890. /* Since we will reserve the kernel mutex, we have to release
  2891. the search system latch first to obey the latching order. */
  2892. if (trx->has_search_latch && !trx_is_active_commit_ordered(trx)) {
  2893. trx_search_latch_release_if_reserved(trx);
  2894. }
  2895. if (trx->fake_changes && (all || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))) {
  2896. innobase_rollback(hton, thd, all); /* rollback implicitly */
  2897. thd->stmt_da->reset_diagnostics_area(); /* because debug assertion code complains, if something left */
  2898. DBUG_RETURN(HA_ERR_WRONG_COMMAND);
  2899. }
  2900. /* Transaction is deregistered only in a commit or a rollback. If
  2901. it is deregistered we know there cannot be resources to be freed
  2902. and we could return immediately. For the time being, we play safe
  2903. and do the cleanup though there should be nothing to clean up. */
  2904. if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) {
  2905. sql_print_error("Transaction not registered for MySQL 2PC, "
  2906. "but transaction is active");
  2907. }
  2908. if (all
  2909. || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
  2910. /* Run the fast part of commit if we did not already. */
  2911. if (!trx_is_active_commit_ordered(trx)) {
  2912. innobase_commit_ordered_2(trx, thd);
  2913. }
  2914. /* We were instructed to commit the whole transaction, or
  2915. this is an SQL statement end and autocommit is on */
  2916. /* We did the first part already in innobase_commit_ordered(),
  2917. Now finish by doing a write + flush of logs. */
  2918. trx_commit_complete_for_mysql(trx);
  2919. trx_deregister_from_2pc(trx);
  2920. } else {
  2921. /* We just mark the SQL statement ended and do not do a
  2922. transaction commit */
  2923. /* If we had reserved the auto-inc lock for some
  2924. table in this SQL statement we release it now */
  2925. row_unlock_table_autoinc_for_mysql(trx);
  2926. /* Store the current undo_no of the transaction so that we
  2927. know where to roll back if we have to roll back the next
  2928. SQL statement */
  2929. trx_mark_sql_stat_end(trx);
  2930. }
  2931. trx->n_autoinc_rows = 0; /* Reset the number AUTO-INC rows required */
  2932. if (trx->declared_to_be_inside_innodb) {
  2933. /* Release our possible ticket in the FIFO */
  2934. srv_conc_force_exit_innodb(trx);
  2935. }
  2936. /* Tell the InnoDB server that there might be work for utility
  2937. threads: */
  2938. srv_active_wake_master_thread();
  2939. DBUG_RETURN(0);
  2940. }
  2941. /*****************************************************************//**
  2942. Rolls back a transaction or the latest SQL statement.
  2943. @return 0 or error number */
  2944. static
  2945. int
  2946. innobase_rollback(
  2947. /*==============*/
  2948. handlerton *hton, /*!< in: Innodb handlerton */
  2949. THD* thd, /*!< in: handle to the MySQL thread of the user
  2950. whose transaction should be rolled back */
  2951. bool all) /*!< in: TRUE - commit transaction
  2952. FALSE - the current SQL statement ended */
  2953. {
  2954. int error = 0;
  2955. trx_t* trx;
  2956. DBUG_ENTER("innobase_rollback");
  2957. DBUG_ASSERT(hton == innodb_hton_ptr);
  2958. DBUG_PRINT("trans", ("aborting transaction"));
  2959. trx = check_trx_exists(thd);
  2960. /* Release a possible FIFO ticket and search latch. Since we will
  2961. reserve the kernel mutex, we have to release the search system latch
  2962. first to obey the latching order. */
  2963. innobase_release_stat_resources(trx);
  2964. trx->n_autoinc_rows = 0; /* Reset the number AUTO-INC rows required */
  2965. /* If we had reserved the auto-inc lock for some table (if
  2966. we come here to roll back the latest SQL statement) we
  2967. release it now before a possibly lengthy rollback */
  2968. row_unlock_table_autoinc_for_mysql(trx);
  2969. if (all
  2970. || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  2971. error = trx_rollback_for_mysql(trx);
  2972. trx_deregister_from_2pc(trx);
  2973. } else {
  2974. error = trx_rollback_last_sql_stat_for_mysql(trx);
  2975. }
  2976. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  2977. }
  2978. /*****************************************************************//**
  2979. Rolls back a transaction
  2980. @return 0 or error number */
  2981. static
  2982. int
  2983. innobase_rollback_trx(
  2984. /*==================*/
  2985. trx_t* trx) /*!< in: transaction */
  2986. {
  2987. int error = 0;
  2988. DBUG_ENTER("innobase_rollback_trx");
  2989. DBUG_PRINT("trans", ("aborting transaction"));
  2990. /* Release a possible FIFO ticket and search latch. Since we will
  2991. reserve the kernel mutex, we have to release the search system latch
  2992. first to obey the latching order. */
  2993. innobase_release_stat_resources(trx);
  2994. /* If we had reserved the auto-inc lock for some table (if
  2995. we come here to roll back the latest SQL statement) we
  2996. release it now before a possibly lengthy rollback */
  2997. row_unlock_table_autoinc_for_mysql(trx);
  2998. error = trx_rollback_for_mysql(trx);
  2999. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  3000. }
  3001. struct pending_checkpoint {
  3002. struct pending_checkpoint *next;
  3003. handlerton *hton;
  3004. void *cookie;
  3005. ib_uint64_t lsn;
  3006. };
  3007. static struct pending_checkpoint *pending_checkpoint_list;
  3008. static struct pending_checkpoint *pending_checkpoint_list_end;
  3009. /*****************************************************************//**
  3010. Handle a commit checkpoint request from server layer.
  3011. We put the request in a queue, so that we can notify upper layer about
  3012. checkpoint complete when we have flushed the redo log.
  3013. If we have already flushed all relevant redo log, we notify immediately.*/
  3014. static
  3015. void
  3016. innobase_checkpoint_request(
  3017. handlerton *hton,
  3018. void *cookie)
  3019. {
  3020. ib_uint64_t lsn;
  3021. ib_uint64_t flush_lsn;
  3022. struct pending_checkpoint * entry;
  3023. /* Do the allocation outside of lock to reduce contention. The normal
  3024. case is that not everything is flushed, so we will need to enqueue. */
  3025. entry = static_cast<struct pending_checkpoint *>
  3026. (my_malloc(sizeof(*entry), MYF(MY_WME)));
  3027. if (!entry) {
  3028. sql_print_error("Failed to allocate %u bytes."
  3029. " Commit checkpoint will be skipped.",
  3030. static_cast<unsigned>(sizeof(*entry)));
  3031. return;
  3032. }
  3033. entry->next = NULL;
  3034. entry->hton = hton;
  3035. entry->cookie = cookie;
  3036. mysql_mutex_lock(&pending_checkpoint_mutex);
  3037. lsn = log_get_lsn();
  3038. flush_lsn = log_get_flush_lsn();
  3039. if (lsn > flush_lsn) {
  3040. /* Put the request in queue.
  3041. When the log gets flushed past the lsn, we will remove the
  3042. entry from the queue and notify the upper layer. */
  3043. entry->lsn = lsn;
  3044. if (pending_checkpoint_list_end) {
  3045. pending_checkpoint_list_end->next = entry;
  3046. /* There is no need to order the entries in the list
  3047. by lsn. The upper layer can accept notifications in
  3048. any order, and short delays in notifications do not
  3049. significantly impact performance. */
  3050. } else {
  3051. pending_checkpoint_list = entry;
  3052. }
  3053. pending_checkpoint_list_end = entry;
  3054. entry = NULL;
  3055. }
  3056. mysql_mutex_unlock(&pending_checkpoint_mutex);
  3057. if (entry) {
  3058. /* We are already flushed. Notify the checkpoint immediately. */
  3059. commit_checkpoint_notify_ha(entry->hton, entry->cookie);
  3060. my_free(entry);
  3061. }
  3062. }
  3063. /*****************************************************************//**
  3064. Log code calls this whenever log has been written and/or flushed up
  3065. to a new position. We use this to notify upper layer of a new commit
  3066. checkpoint when necessary.*/
  3067. extern "C" UNIV_INTERN
  3068. void
  3069. innobase_mysql_log_notify(
  3070. /*===============*/
  3071. ib_uint64_t write_lsn, /*!< in: LSN written to log file */
  3072. ib_uint64_t flush_lsn) /*!< in: LSN flushed to disk */
  3073. {
  3074. struct pending_checkpoint * pending;
  3075. struct pending_checkpoint * entry;
  3076. struct pending_checkpoint * last_ready;
  3077. /* It is safe to do a quick check for NULL first without lock.
  3078. Even if we should race, we will at most skip one checkpoint and
  3079. take the next one, which is harmless. */
  3080. if (!pending_checkpoint_list)
  3081. return;
  3082. mysql_mutex_lock(&pending_checkpoint_mutex);
  3083. pending = pending_checkpoint_list;
  3084. if (!pending)
  3085. {
  3086. mysql_mutex_unlock(&pending_checkpoint_mutex);
  3087. return;
  3088. }
  3089. last_ready = NULL;
  3090. for (entry = pending; entry != NULL; entry = entry -> next)
  3091. {
  3092. /* Notify checkpoints up until the first entry that has not
  3093. been fully flushed to the redo log. Since we do not maintain
  3094. the list ordered, in principle there could be more entries
  3095. later than were also flushed. But there is no harm in
  3096. delaying notifications for those a bit. And in practise, the
  3097. list is unlikely to have more than one element anyway, as we
  3098. flush the redo log at least once every second. */
  3099. if (entry->lsn > flush_lsn)
  3100. break;
  3101. last_ready = entry;
  3102. }
  3103. if (last_ready)
  3104. {
  3105. /* We found some pending checkpoints that are now flushed to
  3106. disk. So remove them from the list. */
  3107. pending_checkpoint_list = entry;
  3108. if (!entry)
  3109. pending_checkpoint_list_end = NULL;
  3110. }
  3111. mysql_mutex_unlock(&pending_checkpoint_mutex);
  3112. if (!last_ready)
  3113. return;
  3114. /* Now that we have released the lock, notify upper layer about all
  3115. commit checkpoints that have now completed. */
  3116. for (;;) {
  3117. entry = pending;
  3118. pending = pending->next;
  3119. commit_checkpoint_notify_ha(entry->hton, entry->cookie);
  3120. my_free(entry);
  3121. if (entry == last_ready)
  3122. break;
  3123. }
  3124. }
  3125. /*****************************************************************//**
  3126. Rolls back a transaction to a savepoint.
  3127. @return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the
  3128. given name */
  3129. static
  3130. int
  3131. innobase_rollback_to_savepoint(
  3132. /*===========================*/
  3133. handlerton *hton, /*!< in: Innodb handlerton */
  3134. THD* thd, /*!< in: handle to the MySQL thread of the user
  3135. whose transaction should be rolled back */
  3136. void* savepoint) /*!< in: savepoint data */
  3137. {
  3138. ib_int64_t mysql_binlog_cache_pos;
  3139. int error = 0;
  3140. trx_t* trx;
  3141. char name[64];
  3142. DBUG_ENTER("innobase_rollback_to_savepoint");
  3143. DBUG_ASSERT(hton == innodb_hton_ptr);
  3144. trx = check_trx_exists(thd);
  3145. /* Release a possible FIFO ticket and search latch. Since we will
  3146. reserve the kernel mutex, we have to release the search system latch
  3147. first to obey the latching order. */
  3148. innobase_release_stat_resources(trx);
  3149. /* TODO: use provided savepoint data area to store savepoint data */
  3150. longlong2str((ulint)savepoint, name, 36);
  3151. error = (int) trx_rollback_to_savepoint_for_mysql(trx, name,
  3152. &mysql_binlog_cache_pos);
  3153. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  3154. }
  3155. /*****************************************************************//**
  3156. Release transaction savepoint name.
  3157. @return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the
  3158. given name */
  3159. static
  3160. int
  3161. innobase_release_savepoint(
  3162. /*=======================*/
  3163. handlerton* hton, /*!< in: handlerton for Innodb */
  3164. THD* thd, /*!< in: handle to the MySQL thread of the user
  3165. whose transaction should be rolled back */
  3166. void* savepoint) /*!< in: savepoint data */
  3167. {
  3168. int error = 0;
  3169. trx_t* trx;
  3170. char name[64];
  3171. DBUG_ENTER("innobase_release_savepoint");
  3172. DBUG_ASSERT(hton == innodb_hton_ptr);
  3173. trx = check_trx_exists(thd);
  3174. /* TODO: use provided savepoint data area to store savepoint data */
  3175. longlong2str((ulint)savepoint, name, 36);
  3176. error = (int) trx_release_savepoint_for_mysql(trx, name);
  3177. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  3178. }
  3179. /*****************************************************************//**
  3180. Sets a transaction savepoint.
  3181. @return always 0, that is, always succeeds */
  3182. static
  3183. int
  3184. innobase_savepoint(
  3185. /*===============*/
  3186. handlerton* hton, /*!< in: handle to the Innodb handlerton */
  3187. THD* thd, /*!< in: handle to the MySQL thread */
  3188. void* savepoint) /*!< in: savepoint data */
  3189. {
  3190. int error = 0;
  3191. trx_t* trx;
  3192. DBUG_ENTER("innobase_savepoint");
  3193. DBUG_ASSERT(hton == innodb_hton_ptr);
  3194. /*
  3195. In the autocommit mode there is no sense to set a savepoint
  3196. (unless we are in sub-statement), so SQL layer ensures that
  3197. this method is never called in such situation.
  3198. */
  3199. #ifdef MYSQL_SERVER /* plugins cannot access thd->in_sub_stmt */
  3200. DBUG_ASSERT(thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
  3201. thd->in_sub_stmt);
  3202. #endif /* MYSQL_SERVER */
  3203. trx = check_trx_exists(thd);
  3204. /* Release a possible FIFO ticket and search latch. Since we will
  3205. reserve the kernel mutex, we have to release the search system latch
  3206. first to obey the latching order. */
  3207. innobase_release_stat_resources(trx);
  3208. /* Cannot happen outside of transaction */
  3209. DBUG_ASSERT(trx_is_registered_for_2pc(trx));
  3210. /* TODO: use provided savepoint data area to store savepoint data */
  3211. char name[64];
  3212. longlong2str((ulint)savepoint,name,36);
  3213. error = (int) trx_savepoint_for_mysql(trx, name, (ib_int64_t)0);
  3214. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  3215. }
  3216. /*****************************************************************//**
  3217. Frees a possible InnoDB trx object associated with the current THD.
  3218. @return 0 or error number */
  3219. static
  3220. int
  3221. innobase_close_connection(
  3222. /*======================*/
  3223. handlerton* hton, /*!< in: innobase handlerton */
  3224. THD* thd) /*!< in: handle to the MySQL thread of the user
  3225. whose resources should be free'd */
  3226. {
  3227. trx_t* trx;
  3228. DBUG_ENTER("innobase_close_connection");
  3229. DBUG_ASSERT(hton == innodb_hton_ptr);
  3230. trx = thd_to_trx(thd);
  3231. ut_a(trx);
  3232. if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) {
  3233. sql_print_error("Transaction not registered for MySQL 2PC, "
  3234. "but transaction is active");
  3235. }
  3236. if (trx_is_started(trx) && global_system_variables.log_warnings) {
  3237. sql_print_warning(
  3238. "MySQL is closing a connection that has an active "
  3239. "InnoDB transaction. %llu row modifications will "
  3240. "roll back.",
  3241. (ullint) trx->undo_no);
  3242. }
  3243. innobase_rollback_trx(trx);
  3244. trx_free_for_mysql(trx);
  3245. DBUG_RETURN(0);
  3246. }
  3247. /*************************************************************************//**
  3248. ** InnoDB database tables
  3249. *****************************************************************************/
  3250. /****************************************************************//**
  3251. Get the record format from the data dictionary.
  3252. @return one of ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT,
  3253. ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC */
  3254. UNIV_INTERN
  3255. enum row_type
  3256. ha_innobase::get_row_type() const
  3257. /*=============================*/
  3258. {
  3259. if (prebuilt && prebuilt->table) {
  3260. const ulint flags = prebuilt->table->flags;
  3261. if (UNIV_UNLIKELY(!flags)) {
  3262. return(ROW_TYPE_REDUNDANT);
  3263. }
  3264. ut_ad(flags & DICT_TF_COMPACT);
  3265. switch (flags & DICT_TF_FORMAT_MASK) {
  3266. case DICT_TF_FORMAT_51 << DICT_TF_FORMAT_SHIFT:
  3267. return(ROW_TYPE_COMPACT);
  3268. case DICT_TF_FORMAT_ZIP << DICT_TF_FORMAT_SHIFT:
  3269. if (flags & DICT_TF_ZSSIZE_MASK) {
  3270. return(ROW_TYPE_COMPRESSED);
  3271. } else {
  3272. return(ROW_TYPE_DYNAMIC);
  3273. }
  3274. #if DICT_TF_FORMAT_ZIP != DICT_TF_FORMAT_MAX
  3275. # error "DICT_TF_FORMAT_ZIP != DICT_TF_FORMAT_MAX"
  3276. #endif
  3277. }
  3278. }
  3279. ut_ad(0);
  3280. return(ROW_TYPE_NOT_USED);
  3281. }
  3282. /****************************************************************//**
  3283. Get the table flags to use for the statement.
  3284. @return table flags */
  3285. UNIV_INTERN
  3286. handler::Table_flags
  3287. ha_innobase::table_flags() const
  3288. /*============================*/
  3289. {
  3290. /* Need to use tx_isolation here since table flags is (also)
  3291. called before prebuilt is inited. */
  3292. ulong const tx_isolation = thd_tx_isolation(ha_thd());
  3293. if (tx_isolation <= ISO_READ_COMMITTED)
  3294. return int_table_flags;
  3295. return int_table_flags | HA_BINLOG_STMT_CAPABLE;
  3296. }
  3297. /****************************************************************//**
  3298. Gives the file extension of an InnoDB single-table tablespace. */
  3299. static const char* ha_innobase_exts[] = {
  3300. ".ibd",
  3301. NullS
  3302. };
  3303. /****************************************************************//**
  3304. Returns the table type (storage engine name).
  3305. @return table type */
  3306. UNIV_INTERN
  3307. const char*
  3308. ha_innobase::table_type() const
  3309. /*===========================*/
  3310. {
  3311. return(innobase_hton_name);
  3312. }
  3313. /****************************************************************//**
  3314. Returns the index type. */
  3315. UNIV_INTERN
  3316. const char*
  3317. ha_innobase::index_type(
  3318. /*====================*/
  3319. uint)
  3320. /*!< out: index type */
  3321. {
  3322. return("BTREE");
  3323. }
  3324. /****************************************************************//**
  3325. Returns the table file name extension.
  3326. @return file extension string */
  3327. UNIV_INTERN
  3328. const char**
  3329. ha_innobase::bas_ext() const
  3330. /*========================*/
  3331. {
  3332. return(ha_innobase_exts);
  3333. }
  3334. /****************************************************************//**
  3335. Returns the operations supported for indexes.
  3336. @return flags of supported operations */
  3337. UNIV_INTERN
  3338. ulong
  3339. ha_innobase::index_flags(
  3340. /*=====================*/
  3341. uint index,
  3342. uint part,
  3343. bool all_parts)
  3344. const
  3345. {
  3346. ulong extra_flag= 0;
  3347. if (table && index == table->s->primary_key)
  3348. extra_flag= HA_CLUSTERED_INDEX;
  3349. return(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | extra_flag
  3350. | HA_READ_RANGE | HA_KEYREAD_ONLY | HA_DO_INDEX_COND_PUSHDOWN);
  3351. }
  3352. /****************************************************************//**
  3353. Returns the maximum number of keys.
  3354. @return MAX_KEY */
  3355. UNIV_INTERN
  3356. uint
  3357. ha_innobase::max_supported_keys() const
  3358. /*===================================*/
  3359. {
  3360. return(MAX_KEY);
  3361. }
  3362. /****************************************************************//**
  3363. Returns the maximum key length.
  3364. @return maximum supported key length, in bytes */
  3365. UNIV_INTERN
  3366. uint
  3367. ha_innobase::max_supported_key_length() const
  3368. /*=========================================*/
  3369. {
  3370. /* An InnoDB page must store >= 2 keys; a secondary key record
  3371. must also contain the primary key value: max key length is
  3372. therefore set to slightly less than 1 / 4 of page size which
  3373. is 16 kB; but currently MySQL does not work with keys whose
  3374. size is > MAX_KEY_LENGTH */
  3375. return(3500);
  3376. }
  3377. /****************************************************************//**
  3378. Returns the key map of keys that are usable for scanning.
  3379. @return key_map_full */
  3380. UNIV_INTERN
  3381. const key_map*
  3382. ha_innobase::keys_to_use_for_scanning()
  3383. {
  3384. return(&key_map_full);
  3385. }
  3386. /****************************************************************//**
  3387. Determines if table caching is supported.
  3388. @return HA_CACHE_TBL_ASKTRANSACT */
  3389. UNIV_INTERN
  3390. uint8
  3391. ha_innobase::table_cache_type()
  3392. {
  3393. return(HA_CACHE_TBL_ASKTRANSACT);
  3394. }
  3395. /****************************************************************//**
  3396. Determines if the primary key is clustered index.
  3397. @return true */
  3398. UNIV_INTERN
  3399. bool
  3400. ha_innobase::primary_key_is_clustered()
  3401. {
  3402. return(true);
  3403. }
  3404. /** Always normalize table name to lower case on Windows */
  3405. #ifdef __WIN__
  3406. #define normalize_table_name(norm_name, name) \
  3407. normalize_table_name_low(norm_name, name, TRUE)
  3408. #else
  3409. #define normalize_table_name(norm_name, name) \
  3410. normalize_table_name_low(norm_name, name, FALSE)
  3411. #endif /* __WIN__ */
  3412. /*****************************************************************//**
  3413. Normalizes a table name string. A normalized name consists of the
  3414. database name catenated to '/' and table name. An example:
  3415. test/mytable. On Windows normalization puts both the database name and the
  3416. table name always to lower case if "set_lower_case" is set to TRUE. */
  3417. static
  3418. void
  3419. normalize_table_name_low(
  3420. /*=====================*/
  3421. char* norm_name, /*!< out: normalized name as a
  3422. null-terminated string */
  3423. const char* name, /*!< in: table name string */
  3424. ibool set_lower_case) /*!< in: TRUE if we want to set
  3425. name to lower case */
  3426. {
  3427. char* name_ptr;
  3428. char* db_ptr;
  3429. ulint db_len;
  3430. char* ptr;
  3431. /* Scan name from the end */
  3432. ptr = strend(name) - 1;
  3433. /* seek to the last path separator */
  3434. while (ptr >= name && *ptr != '\\' && *ptr != '/') {
  3435. ptr--;
  3436. }
  3437. name_ptr = ptr + 1;
  3438. /* skip any number of path separators */
  3439. while (ptr >= name && (*ptr == '\\' || *ptr == '/')) {
  3440. ptr--;
  3441. }
  3442. DBUG_ASSERT(ptr >= name);
  3443. /* seek to the last but one path separator or one char before
  3444. the beginning of name */
  3445. db_len = 0;
  3446. while (ptr >= name && *ptr != '\\' && *ptr != '/') {
  3447. ptr--;
  3448. db_len++;
  3449. }
  3450. db_ptr = ptr + 1;
  3451. memcpy(norm_name, db_ptr, db_len);
  3452. norm_name[db_len] = '/';
  3453. memcpy(norm_name + db_len + 1, name_ptr, strlen(name_ptr) + 1);
  3454. if (set_lower_case) {
  3455. innobase_casedn_str(norm_name);
  3456. }
  3457. }
  3458. #if !defined(DBUG_OFF)
  3459. /*********************************************************************
  3460. Test normalize_table_name_low(). */
  3461. static
  3462. void
  3463. test_normalize_table_name_low()
  3464. /*===========================*/
  3465. {
  3466. char norm_name[128];
  3467. const char* test_data[][2] = {
  3468. /* input, expected result */
  3469. {"./mysqltest/t1", "mysqltest/t1"},
  3470. {"./test/#sql-842b_2", "test/#sql-842b_2"},
  3471. {"./test/#sql-85a3_10", "test/#sql-85a3_10"},
  3472. {"./test/#sql2-842b-2", "test/#sql2-842b-2"},
  3473. {"./test/bug29807", "test/bug29807"},
  3474. {"./test/foo", "test/foo"},
  3475. {"./test/innodb_bug52663", "test/innodb_bug52663"},
  3476. {"./test/t", "test/t"},
  3477. {"./test/t1", "test/t1"},
  3478. {"./test/t10", "test/t10"},
  3479. {"/a/b/db/table", "db/table"},
  3480. {"/a/b/db///////table", "db/table"},
  3481. {"/a/b////db///////table", "db/table"},
  3482. {"/var/tmp/mysqld.1/#sql842b_2_10", "mysqld.1/#sql842b_2_10"},
  3483. {"db/table", "db/table"},
  3484. {"ddd/t", "ddd/t"},
  3485. {"d/ttt", "d/ttt"},
  3486. {"d/t", "d/t"},
  3487. {".\\mysqltest\\t1", "mysqltest/t1"},
  3488. {".\\test\\#sql-842b_2", "test/#sql-842b_2"},
  3489. {".\\test\\#sql-85a3_10", "test/#sql-85a3_10"},
  3490. {".\\test\\#sql2-842b-2", "test/#sql2-842b-2"},
  3491. {".\\test\\bug29807", "test/bug29807"},
  3492. {".\\test\\foo", "test/foo"},
  3493. {".\\test\\innodb_bug52663", "test/innodb_bug52663"},
  3494. {".\\test\\t", "test/t"},
  3495. {".\\test\\t1", "test/t1"},
  3496. {".\\test\\t10", "test/t10"},
  3497. {"C:\\a\\b\\db\\table", "db/table"},
  3498. {"C:\\a\\b\\db\\\\\\\\\\\\\\table", "db/table"},
  3499. {"C:\\a\\b\\\\\\\\db\\\\\\\\\\\\\\table", "db/table"},
  3500. {"C:\\var\\tmp\\mysqld.1\\#sql842b_2_10", "mysqld.1/#sql842b_2_10"},
  3501. {"db\\table", "db/table"},
  3502. {"ddd\\t", "ddd/t"},
  3503. {"d\\ttt", "d/ttt"},
  3504. {"d\\t", "d/t"},
  3505. };
  3506. for (size_t i = 0; i < UT_ARR_SIZE(test_data); i++) {
  3507. printf("test_normalize_table_name_low(): "
  3508. "testing \"%s\", expected \"%s\"... ",
  3509. test_data[i][0], test_data[i][1]);
  3510. normalize_table_name_low(norm_name, test_data[i][0], FALSE);
  3511. if (strcmp(norm_name, test_data[i][1]) == 0) {
  3512. printf("ok\n");
  3513. } else {
  3514. printf("got \"%s\"\n", norm_name);
  3515. ut_error;
  3516. }
  3517. }
  3518. }
  3519. #endif /* !DBUG_OFF */
  3520. /********************************************************************//**
  3521. Get the upper limit of the MySQL integral and floating-point type.
  3522. @return maximum allowed value for the field */
  3523. static
  3524. ulonglong
  3525. innobase_get_int_col_max_value(
  3526. /*===========================*/
  3527. const Field* field) /*!< in: MySQL field */
  3528. {
  3529. ulonglong max_value = 0;
  3530. switch(field->key_type()) {
  3531. /* TINY */
  3532. case HA_KEYTYPE_BINARY:
  3533. max_value = 0xFFULL;
  3534. break;
  3535. case HA_KEYTYPE_INT8:
  3536. max_value = 0x7FULL;
  3537. break;
  3538. /* SHORT */
  3539. case HA_KEYTYPE_USHORT_INT:
  3540. max_value = 0xFFFFULL;
  3541. break;
  3542. case HA_KEYTYPE_SHORT_INT:
  3543. max_value = 0x7FFFULL;
  3544. break;
  3545. /* MEDIUM */
  3546. case HA_KEYTYPE_UINT24:
  3547. max_value = 0xFFFFFFULL;
  3548. break;
  3549. case HA_KEYTYPE_INT24:
  3550. max_value = 0x7FFFFFULL;
  3551. break;
  3552. /* LONG */
  3553. case HA_KEYTYPE_ULONG_INT:
  3554. max_value = 0xFFFFFFFFULL;
  3555. break;
  3556. case HA_KEYTYPE_LONG_INT:
  3557. max_value = 0x7FFFFFFFULL;
  3558. break;
  3559. /* BIG */
  3560. case HA_KEYTYPE_ULONGLONG:
  3561. max_value = 0xFFFFFFFFFFFFFFFFULL;
  3562. break;
  3563. case HA_KEYTYPE_LONGLONG:
  3564. max_value = 0x7FFFFFFFFFFFFFFFULL;
  3565. break;
  3566. case HA_KEYTYPE_FLOAT:
  3567. /* We use the maximum as per IEEE754-2008 standard, 2^24 */
  3568. max_value = 0x1000000ULL;
  3569. break;
  3570. case HA_KEYTYPE_DOUBLE:
  3571. /* We use the maximum as per IEEE754-2008 standard, 2^53 */
  3572. max_value = 0x20000000000000ULL;
  3573. break;
  3574. default:
  3575. ut_error;
  3576. }
  3577. return(max_value);
  3578. }
  3579. /*******************************************************************//**
  3580. This function checks whether the index column information
  3581. is consistent between KEY info from mysql and that from innodb index.
  3582. @return TRUE if all column types match. */
  3583. static
  3584. ibool
  3585. innobase_match_index_columns(
  3586. /*=========================*/
  3587. const KEY* key_info, /*!< in: Index info
  3588. from mysql */
  3589. const dict_index_t* index_info) /*!< in: Index info
  3590. from Innodb */
  3591. {
  3592. const KEY_PART_INFO* key_part;
  3593. const KEY_PART_INFO* key_end;
  3594. const dict_field_t* innodb_idx_fld;
  3595. const dict_field_t* innodb_idx_fld_end;
  3596. DBUG_ENTER("innobase_match_index_columns");
  3597. /* Check whether user defined index column count matches */
  3598. if (key_info->key_parts != index_info->n_user_defined_cols) {
  3599. DBUG_RETURN(FALSE);
  3600. }
  3601. key_part = key_info->key_part;
  3602. key_end = key_part + key_info->key_parts;
  3603. innodb_idx_fld = index_info->fields;
  3604. innodb_idx_fld_end = index_info->fields + index_info->n_fields;
  3605. /* Check each index column's datatype. We do not check
  3606. column name because there exists case that index
  3607. column name got modified in mysql but such change does not
  3608. propagate to InnoDB.
  3609. One hidden assumption here is that the index column sequences
  3610. are matched up between those in mysql and Innodb. */
  3611. for (; key_part != key_end; ++key_part) {
  3612. ulint col_type;
  3613. ibool is_unsigned;
  3614. ulint mtype = innodb_idx_fld->col->mtype;
  3615. /* Need to translate to InnoDB column type before
  3616. comparison. */
  3617. col_type = get_innobase_type_from_mysql_type(&is_unsigned,
  3618. key_part->field);
  3619. /* Ignore Innodb specific system columns. */
  3620. while (mtype == DATA_SYS) {
  3621. innodb_idx_fld++;
  3622. if (innodb_idx_fld >= innodb_idx_fld_end) {
  3623. DBUG_RETURN(FALSE);
  3624. }
  3625. }
  3626. if (col_type != mtype) {
  3627. /* Column Type mismatches */
  3628. DBUG_RETURN(FALSE);
  3629. }
  3630. innodb_idx_fld++;
  3631. }
  3632. DBUG_RETURN(TRUE);
  3633. }
  3634. /*******************************************************************//**
  3635. This function builds a translation table in INNOBASE_SHARE
  3636. structure for fast index location with mysql array number from its
  3637. table->key_info structure. This also provides the necessary translation
  3638. between the key order in mysql key_info and Innodb ib_table->indexes if
  3639. they are not fully matched with each other.
  3640. Note we do not have any mutex protecting the translation table
  3641. building based on the assumption that there is no concurrent
  3642. index creation/drop and DMLs that requires index lookup. All table
  3643. handle will be closed before the index creation/drop.
  3644. @return TRUE if index translation table built successfully */
  3645. static
  3646. ibool
  3647. innobase_build_index_translation(
  3648. /*=============================*/
  3649. const TABLE* table, /*!< in: table in MySQL data
  3650. dictionary */
  3651. dict_table_t* ib_table, /*!< in: table in Innodb data
  3652. dictionary */
  3653. INNOBASE_SHARE* share) /*!< in/out: share structure
  3654. where index translation table
  3655. will be constructed in. */
  3656. {
  3657. ulint mysql_num_index;
  3658. ulint ib_num_index;
  3659. dict_index_t** index_mapping;
  3660. ibool ret = TRUE;
  3661. DBUG_ENTER("innobase_build_index_translation");
  3662. mutex_enter(&dict_sys->mutex);
  3663. mysql_num_index = table->s->keys;
  3664. ib_num_index = UT_LIST_GET_LEN(ib_table->indexes);
  3665. index_mapping = share->idx_trans_tbl.index_mapping;
  3666. /* If there exists inconsistency between MySQL and InnoDB dictionary
  3667. (metadata) information, the number of index defined in MySQL
  3668. could exceed that in InnoDB, do not build index translation
  3669. table in such case */
  3670. if (UNIV_UNLIKELY(ib_num_index < mysql_num_index)) {
  3671. ret = FALSE;
  3672. goto func_exit;
  3673. }
  3674. /* If index entry count is non-zero, nothing has
  3675. changed since last update, directly return TRUE */
  3676. if (share->idx_trans_tbl.index_count) {
  3677. /* Index entry count should still match mysql_num_index */
  3678. ut_a(share->idx_trans_tbl.index_count == mysql_num_index);
  3679. goto func_exit;
  3680. }
  3681. /* The number of index increased, rebuild the mapping table */
  3682. if (mysql_num_index > share->idx_trans_tbl.array_size) {
  3683. index_mapping = (dict_index_t**) my_realloc(index_mapping,
  3684. mysql_num_index *
  3685. sizeof(*index_mapping),
  3686. MYF(MY_ALLOW_ZERO_PTR));
  3687. if (!index_mapping) {
  3688. /* Report an error if index_mapping continues to be
  3689. NULL and mysql_num_index is a non-zero value */
  3690. sql_print_error("InnoDB: fail to allocate memory for "
  3691. "index translation table. Number of "
  3692. "Index:%lu, array size:%lu",
  3693. mysql_num_index,
  3694. share->idx_trans_tbl.array_size);
  3695. ret = FALSE;
  3696. goto func_exit;
  3697. }
  3698. share->idx_trans_tbl.array_size = mysql_num_index;
  3699. }
  3700. /* For each index in the mysql key_info array, fetch its
  3701. corresponding InnoDB index pointer into index_mapping
  3702. array. */
  3703. for (ulint count = 0; count < mysql_num_index; count++) {
  3704. /* Fetch index pointers into index_mapping according to mysql
  3705. index sequence */
  3706. index_mapping[count] = dict_table_get_index_on_name(
  3707. ib_table, table->key_info[count].name);
  3708. if (!index_mapping[count]) {
  3709. sql_print_error("Cannot find index %s in InnoDB "
  3710. "index dictionary.",
  3711. table->key_info[count].name);
  3712. ret = FALSE;
  3713. goto func_exit;
  3714. }
  3715. /* Double check fetched index has the same
  3716. column info as those in mysql key_info. */
  3717. if (!innobase_match_index_columns(&table->key_info[count],
  3718. index_mapping[count])) {
  3719. sql_print_error("Found index %s whose column info "
  3720. "does not match that of MySQL.",
  3721. table->key_info[count].name);
  3722. ret = FALSE;
  3723. goto func_exit;
  3724. }
  3725. }
  3726. /* Successfully built the translation table */
  3727. share->idx_trans_tbl.index_count = mysql_num_index;
  3728. func_exit:
  3729. if (!ret) {
  3730. /* Build translation table failed. */
  3731. my_free(index_mapping);
  3732. share->idx_trans_tbl.array_size = 0;
  3733. share->idx_trans_tbl.index_count = 0;
  3734. index_mapping = NULL;
  3735. }
  3736. share->idx_trans_tbl.index_mapping = index_mapping;
  3737. mutex_exit(&dict_sys->mutex);
  3738. DBUG_RETURN(ret);
  3739. }
  3740. /*******************************************************************//**
  3741. This function uses index translation table to quickly locate the
  3742. requested index structure.
  3743. Note we do not have mutex protection for the index translatoin table
  3744. access, it is based on the assumption that there is no concurrent
  3745. translation table rebuild (fter create/drop index) and DMLs that
  3746. require index lookup.
  3747. @return dict_index_t structure for requested index. NULL if
  3748. fail to locate the index structure. */
  3749. static
  3750. dict_index_t*
  3751. innobase_index_lookup(
  3752. /*==================*/
  3753. INNOBASE_SHARE* share, /*!< in: share structure for index
  3754. translation table. */
  3755. uint keynr) /*!< in: index number for the requested
  3756. index */
  3757. {
  3758. if (!share->idx_trans_tbl.index_mapping
  3759. || keynr >= share->idx_trans_tbl.index_count) {
  3760. return(NULL);
  3761. }
  3762. return(share->idx_trans_tbl.index_mapping[keynr]);
  3763. }
  3764. /************************************************************************
  3765. Set the autoinc column max value. This should only be called once from
  3766. ha_innobase::open(). Therefore there's no need for a covering lock. */
  3767. UNIV_INTERN
  3768. void
  3769. ha_innobase::innobase_initialize_autoinc()
  3770. /*======================================*/
  3771. {
  3772. ulonglong auto_inc;
  3773. const Field* field = table->found_next_number_field;
  3774. if (field != NULL) {
  3775. auto_inc = innobase_get_int_col_max_value(field);
  3776. } else {
  3777. /* We have no idea what's been passed in to us as the
  3778. autoinc column. We set it to the 0, effectively disabling
  3779. updates to the table. */
  3780. auto_inc = 0;
  3781. ut_print_timestamp(stderr);
  3782. fprintf(stderr, " InnoDB: Unable to determine the AUTOINC "
  3783. "column name\n");
  3784. }
  3785. if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
  3786. /* If the recovery level is set so high that writes
  3787. are disabled we force the AUTOINC counter to 0
  3788. value effectively disabling writes to the table.
  3789. Secondly, we avoid reading the table in case the read
  3790. results in failure due to a corrupted table/index.
  3791. We will not return an error to the client, so that the
  3792. tables can be dumped with minimal hassle. If an error
  3793. were returned in this case, the first attempt to read
  3794. the table would fail and subsequent SELECTs would succeed. */
  3795. auto_inc = 0;
  3796. } else if (field == NULL) {
  3797. /* This is a far more serious error, best to avoid
  3798. opening the table and return failure. */
  3799. my_error(ER_AUTOINC_READ_FAILED, MYF(0));
  3800. } else {
  3801. dict_index_t* index;
  3802. const char* col_name;
  3803. ulonglong read_auto_inc;
  3804. ulint err;
  3805. update_thd(ha_thd());
  3806. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  3807. col_name = field->field_name;
  3808. index = innobase_get_index(table->s->next_number_index);
  3809. /* Execute SELECT MAX(col_name) FROM TABLE; */
  3810. err = row_search_max_autoinc(index, col_name, &read_auto_inc);
  3811. switch (err) {
  3812. case DB_SUCCESS: {
  3813. ulonglong col_max_value;
  3814. col_max_value = innobase_get_int_col_max_value(field);
  3815. /* At the this stage we do not know the increment
  3816. nor the offset, so use a default increment of 1. */
  3817. auto_inc = innobase_next_autoinc(
  3818. read_auto_inc, 1, 1, 0, col_max_value);
  3819. break;
  3820. }
  3821. case DB_RECORD_NOT_FOUND:
  3822. ut_print_timestamp(stderr);
  3823. fprintf(stderr, " InnoDB: MySQL and InnoDB data "
  3824. "dictionaries are out of sync.\n"
  3825. "InnoDB: Unable to find the AUTOINC column "
  3826. "%s in the InnoDB table %s.\n"
  3827. "InnoDB: We set the next AUTOINC column "
  3828. "value to 0,\n"
  3829. "InnoDB: in effect disabling the AUTOINC "
  3830. "next value generation.\n"
  3831. "InnoDB: You can either set the next "
  3832. "AUTOINC value explicitly using ALTER TABLE\n"
  3833. "InnoDB: or fix the data dictionary by "
  3834. "recreating the table.\n",
  3835. col_name, index->table->name);
  3836. /* This will disable the AUTOINC generation. */
  3837. auto_inc = 0;
  3838. /* We want the open to succeed, so that the user can
  3839. take corrective action. ie. reads should succeed but
  3840. updates should fail. */
  3841. err = DB_SUCCESS;
  3842. break;
  3843. default:
  3844. /* row_search_max_autoinc() should only return
  3845. one of DB_SUCCESS or DB_RECORD_NOT_FOUND. */
  3846. ut_error;
  3847. }
  3848. }
  3849. dict_table_autoinc_initialize(prebuilt->table, auto_inc);
  3850. }
  3851. /*****************************************************************//**
  3852. Creates and opens a handle to a table which already exists in an InnoDB
  3853. database.
  3854. @return 1 if error, 0 if success */
  3855. UNIV_INTERN
  3856. int
  3857. ha_innobase::open(
  3858. /*==============*/
  3859. const char* name, /*!< in: table name */
  3860. int mode, /*!< in: not used */
  3861. uint test_if_locked) /*!< in: not used */
  3862. {
  3863. dict_table_t* ib_table;
  3864. char norm_name[1000];
  3865. THD* thd;
  3866. ulint retries = 0;
  3867. char* is_part = NULL;
  3868. ibool par_case_name_set = FALSE;
  3869. char par_case_name[MAX_FULL_NAME_LEN + 1];
  3870. DBUG_ENTER("ha_innobase::open");
  3871. UT_NOT_USED(mode);
  3872. UT_NOT_USED(test_if_locked);
  3873. thd = ha_thd();
  3874. /* Under some cases MySQL seems to call this function while
  3875. holding btr_search_latch. This breaks the latching order as
  3876. we acquire dict_sys->mutex below and leads to a deadlock. */
  3877. if (thd != NULL) {
  3878. innobase_release_temporary_latches(ht, thd);
  3879. }
  3880. normalize_table_name(norm_name, name);
  3881. user_thd = NULL;
  3882. if (!(share=get_share(name))) {
  3883. DBUG_RETURN(1);
  3884. }
  3885. if (srv_pass_corrupt_table <= 1 && share->ib_table && share->ib_table->is_corrupt) {
  3886. free_share(share);
  3887. DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
  3888. }
  3889. /* Will be allocated if it is needed in ::update_row() */
  3890. upd_buf = NULL;
  3891. upd_buf_size = 0;
  3892. /* We look for pattern #P# to see if the table is partitioned
  3893. MySQL table. The retry logic for partitioned tables is a
  3894. workaround for http://bugs.mysql.com/bug.php?id=33349. Look
  3895. at support issue https://support.mysql.com/view.php?id=21080
  3896. for more details. */
  3897. #ifdef __WIN__
  3898. is_part = strstr(norm_name, "#p#");
  3899. #else
  3900. is_part = strstr(norm_name, "#P#");
  3901. #endif /* __WIN__ */
  3902. retry:
  3903. /* Get pointer to a table object in InnoDB dictionary cache */
  3904. ib_table = dict_table_get(norm_name, TRUE);
  3905. if (srv_pass_corrupt_table <= 1 && ib_table && ib_table->is_corrupt) {
  3906. free_share(share);
  3907. my_free(upd_buf);
  3908. upd_buf = NULL;
  3909. upd_buf_size = 0;
  3910. DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
  3911. }
  3912. share->ib_table = ib_table;
  3913. if (NULL == ib_table) {
  3914. if (is_part && retries < 10) {
  3915. /* MySQL partition engine hard codes the file name
  3916. separator as "#P#". The text case is fixed even if
  3917. lower_case_table_names is set to 1 or 2. This is true
  3918. for sub-partition names as well. InnoDB always
  3919. normalises file names to lower case on Windows, this
  3920. can potentially cause problems when copying/moving
  3921. tables between platforms.
  3922. 1) If boot against an installation from Windows
  3923. platform, then its partition table name could
  3924. be all be in lower case in system tables. So we
  3925. will need to check lower case name when load table.
  3926. 2) If we boot an installation from other case
  3927. sensitive platform in Windows, we might need to
  3928. check the existence of table name without lowering
  3929. case them in the system table. */
  3930. if (innobase_get_lower_case_table_names() == 1) {
  3931. if (!par_case_name_set) {
  3932. #ifndef __WIN__
  3933. /* Check for the table using lower
  3934. case name, including the partition
  3935. separator "P" */
  3936. memcpy(par_case_name, norm_name,
  3937. strlen(norm_name));
  3938. par_case_name[strlen(norm_name)] = 0;
  3939. innobase_casedn_str(par_case_name);
  3940. #else
  3941. /* On Windows platfrom, check
  3942. whether there exists table name in
  3943. system table whose name is
  3944. not being normalized to lower case */
  3945. normalize_table_name_low(
  3946. par_case_name, name, FALSE);
  3947. #endif
  3948. par_case_name_set = TRUE;
  3949. }
  3950. ib_table = dict_table_get(
  3951. par_case_name, FALSE);
  3952. }
  3953. if (!ib_table) {
  3954. ++retries;
  3955. os_thread_sleep(100000);
  3956. goto retry;
  3957. } else {
  3958. #ifndef __WIN__
  3959. sql_print_warning("Partition table %s opened "
  3960. "after converting to lower "
  3961. "case. The table may have "
  3962. "been moved from a case "
  3963. "in-sensitive file system. "
  3964. "Please recreate table in "
  3965. "the current file system\n",
  3966. norm_name);
  3967. #else
  3968. sql_print_warning("Partition table %s opened "
  3969. "after skipping the step to "
  3970. "lower case the table name. "
  3971. "The table may have been "
  3972. "moved from a case sensitive "
  3973. "file system. Please "
  3974. "recreate table in the "
  3975. "current file system\n",
  3976. norm_name);
  3977. #endif
  3978. goto table_opened;
  3979. }
  3980. }
  3981. if (is_part) {
  3982. sql_print_error("Failed to open table %s after "
  3983. "%lu attempts.\n", norm_name,
  3984. retries);
  3985. }
  3986. sql_print_error("Cannot find or open table %s from\n"
  3987. "the internal data dictionary of InnoDB "
  3988. "though the .frm file for the\n"
  3989. "table exists. Maybe you have deleted and "
  3990. "recreated InnoDB data\n"
  3991. "files but have forgotten to delete the "
  3992. "corresponding .frm files\n"
  3993. "of InnoDB tables, or you have moved .frm "
  3994. "files to another database?\n"
  3995. "or, the table contains indexes that this "
  3996. "version of the engine\n"
  3997. "doesn't support.\n"
  3998. "See " REFMAN "innodb-troubleshooting.html\n"
  3999. "how you can resolve the problem.\n",
  4000. norm_name);
  4001. free_share(share);
  4002. my_errno = ENOENT;
  4003. DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
  4004. }
  4005. table_opened:
  4006. if (ib_table->ibd_file_missing && !thd_tablespace_op(thd)) {
  4007. sql_print_error("MySQL is trying to open a table handle but "
  4008. "the .ibd file for\ntable %s does not exist.\n"
  4009. "Have you deleted the .ibd file from the "
  4010. "database directory under\nthe MySQL datadir, "
  4011. "or have you used DISCARD TABLESPACE?\n"
  4012. "See " REFMAN "innodb-troubleshooting.html\n"
  4013. "how you can resolve the problem.\n",
  4014. norm_name);
  4015. free_share(share);
  4016. my_errno = ENOENT;
  4017. dict_table_decrement_handle_count(ib_table, FALSE);
  4018. DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
  4019. }
  4020. prebuilt = row_create_prebuilt(ib_table, table->s->stored_rec_length);
  4021. prebuilt->default_rec = table->s->default_values;
  4022. ut_ad(prebuilt->default_rec);
  4023. /* Looks like MySQL-3.23 sometimes has primary key number != 0 */
  4024. primary_key = table->s->primary_key;
  4025. key_used_on_scan = primary_key;
  4026. if (!innobase_build_index_translation(table, ib_table, share)) {
  4027. sql_print_error("Build InnoDB index translation table for"
  4028. " Table %s failed", name);
  4029. }
  4030. /* Allocate a buffer for a 'row reference'. A row reference is
  4031. a string of bytes of length ref_length which uniquely specifies
  4032. a row in our table. Note that MySQL may also compare two row
  4033. references for equality by doing a simple memcmp on the strings
  4034. of length ref_length! */
  4035. if (!row_table_got_default_clust_index(ib_table)) {
  4036. prebuilt->clust_index_was_generated = FALSE;
  4037. if (UNIV_UNLIKELY(primary_key >= MAX_KEY)) {
  4038. sql_print_error("Table %s has a primary key in "
  4039. "InnoDB data dictionary, but not "
  4040. "in MySQL!", name);
  4041. /* This mismatch could cause further problems
  4042. if not attended, bring this to the user's attention
  4043. by printing a warning in addition to log a message
  4044. in the errorlog */
  4045. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  4046. ER_NO_SUCH_INDEX,
  4047. "InnoDB: Table %s has a "
  4048. "primary key in InnoDB data "
  4049. "dictionary, but not in "
  4050. "MySQL!", name);
  4051. /* If primary_key >= MAX_KEY, its (primary_key)
  4052. value could be out of bound if continue to index
  4053. into key_info[] array. Find InnoDB primary index,
  4054. and assign its key_length to ref_length.
  4055. In addition, since MySQL indexes are sorted starting
  4056. with primary index, unique index etc., initialize
  4057. ref_length to the first index key length in
  4058. case we fail to find InnoDB cluster index.
  4059. Please note, this will not resolve the primary
  4060. index mismatch problem, other side effects are
  4061. possible if users continue to use the table.
  4062. However, we allow this table to be opened so
  4063. that user can adopt necessary measures for the
  4064. mismatch while still being accessible to the table
  4065. date. */
  4066. ref_length = table->key_info[0].key_length;
  4067. /* Find correspoinding cluster index
  4068. key length in MySQL's key_info[] array */
  4069. for (ulint i = 0; i < table->s->keys; i++) {
  4070. dict_index_t* index;
  4071. index = innobase_get_index(i);
  4072. if (dict_index_is_clust(index)) {
  4073. ref_length =
  4074. table->key_info[i].key_length;
  4075. }
  4076. }
  4077. } else {
  4078. /* MySQL allocates the buffer for ref.
  4079. key_info->key_length includes space for all key
  4080. columns + one byte for each column that may be
  4081. NULL. ref_length must be as exact as possible to
  4082. save space, because all row reference buffers are
  4083. allocated based on ref_length. */
  4084. ref_length = table->key_info[primary_key].key_length;
  4085. }
  4086. } else {
  4087. if (primary_key != MAX_KEY) {
  4088. sql_print_error(
  4089. "Table %s has no primary key in InnoDB data "
  4090. "dictionary, but has one in MySQL! If you "
  4091. "created the table with a MySQL version < "
  4092. "3.23.54 and did not define a primary key, "
  4093. "but defined a unique key with all non-NULL "
  4094. "columns, then MySQL internally treats that "
  4095. "key as the primary key. You can fix this "
  4096. "error by dump + DROP + CREATE + reimport "
  4097. "of the table.", name);
  4098. /* This mismatch could cause further problems
  4099. if not attended, bring this to the user attention
  4100. by printing a warning in addition to log a message
  4101. in the errorlog */
  4102. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  4103. ER_NO_SUCH_INDEX,
  4104. "InnoDB: Table %s has no "
  4105. "primary key in InnoDB data "
  4106. "dictionary, but has one in "
  4107. "MySQL!", name);
  4108. }
  4109. prebuilt->clust_index_was_generated = TRUE;
  4110. ref_length = DATA_ROW_ID_LEN;
  4111. /* If we automatically created the clustered index, then
  4112. MySQL does not know about it, and MySQL must NOT be aware
  4113. of the index used on scan, to make it avoid checking if we
  4114. update the column of the index. That is why we assert below
  4115. that key_used_on_scan is the undefined value MAX_KEY.
  4116. The column is the row id in the automatical generation case,
  4117. and it will never be updated anyway. */
  4118. if (key_used_on_scan != MAX_KEY) {
  4119. sql_print_warning(
  4120. "Table %s key_used_on_scan is %lu even "
  4121. "though there is no primary key inside "
  4122. "InnoDB.", name, (ulong) key_used_on_scan);
  4123. }
  4124. }
  4125. /* Index block size in InnoDB: used by MySQL in query optimization */
  4126. stats.block_size = 16 * 1024;
  4127. /* Init table lock structure */
  4128. thr_lock_data_init(&share->lock,&lock,(void*) 0);
  4129. if (prebuilt->table) {
  4130. /* We update the highest file format in the system table
  4131. space, if this table has higher file format setting. */
  4132. trx_sys_file_format_max_upgrade(
  4133. (const char**) &innobase_file_format_max,
  4134. dict_table_get_format(prebuilt->table));
  4135. }
  4136. /* Only if the table has an AUTOINC column. */
  4137. if (prebuilt->table != NULL && table->found_next_number_field != NULL) {
  4138. dict_table_autoinc_lock(prebuilt->table);
  4139. /* Since a table can already be "open" in InnoDB's internal
  4140. data dictionary, we only init the autoinc counter once, the
  4141. first time the table is loaded. We can safely reuse the
  4142. autoinc value from a previous MySQL open. */
  4143. if (dict_table_autoinc_read(prebuilt->table) == 0) {
  4144. innobase_initialize_autoinc();
  4145. }
  4146. dict_table_autoinc_unlock(prebuilt->table);
  4147. }
  4148. info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
  4149. DBUG_RETURN(0);
  4150. }
  4151. UNIV_INTERN
  4152. handler*
  4153. ha_innobase::clone(
  4154. /*===============*/
  4155. const char* name, /*!< in: table name */
  4156. MEM_ROOT* mem_root) /*!< in: memory context */
  4157. {
  4158. ha_innobase* new_handler;
  4159. DBUG_ENTER("ha_innobase::clone");
  4160. new_handler = static_cast<ha_innobase*>(handler::clone(name,
  4161. mem_root));
  4162. if (new_handler) {
  4163. new_handler->prebuilt->select_lock_type
  4164. = prebuilt->select_lock_type;
  4165. }
  4166. DBUG_RETURN(new_handler);
  4167. }
  4168. UNIV_INTERN
  4169. uint
  4170. ha_innobase::max_supported_key_part_length() const
  4171. {
  4172. /* A table format specific index column length check will be performed
  4173. at ha_innobase::add_index() and row_create_index_for_mysql() */
  4174. return(innobase_large_prefix
  4175. ? REC_VERSION_56_MAX_INDEX_COL_LEN
  4176. : REC_ANTELOPE_MAX_INDEX_COL_LEN - 1);
  4177. }
  4178. /******************************************************************//**
  4179. Closes a handle to an InnoDB table.
  4180. @return 0 */
  4181. UNIV_INTERN
  4182. int
  4183. ha_innobase::close(void)
  4184. /*====================*/
  4185. {
  4186. THD* thd;
  4187. DBUG_ENTER("ha_innobase::close");
  4188. thd = ha_thd();
  4189. if (thd != NULL) {
  4190. innobase_release_temporary_latches(ht, thd);
  4191. }
  4192. row_prebuilt_free(prebuilt, FALSE);
  4193. if (upd_buf != NULL) {
  4194. ut_ad(upd_buf_size != 0);
  4195. my_free(upd_buf);
  4196. upd_buf = NULL;
  4197. upd_buf_size = 0;
  4198. }
  4199. free_share(share);
  4200. /* Tell InnoDB server that there might be work for
  4201. utility threads: */
  4202. srv_active_wake_master_thread();
  4203. DBUG_RETURN(0);
  4204. }
  4205. /* The following accessor functions should really be inside MySQL code! */
  4206. /**************************************************************//**
  4207. Gets field offset for a field in a table.
  4208. @return offset */
  4209. static inline
  4210. uint
  4211. get_field_offset(
  4212. /*=============*/
  4213. const TABLE* table, /*!< in: MySQL table object */
  4214. const Field* field) /*!< in: MySQL field object */
  4215. {
  4216. return((uint) (field->ptr - table->record[0]));
  4217. }
  4218. /**************************************************************//**
  4219. Checks if a field in a record is SQL NULL. Uses the record format
  4220. information in table to track the null bit in record.
  4221. @return 1 if NULL, 0 otherwise */
  4222. static inline
  4223. uint
  4224. field_in_record_is_null(
  4225. /*====================*/
  4226. TABLE* table, /*!< in: MySQL table object */
  4227. Field* field, /*!< in: MySQL field object */
  4228. char* record) /*!< in: a row in MySQL format */
  4229. {
  4230. int null_offset;
  4231. if (!field->null_ptr) {
  4232. return(0);
  4233. }
  4234. null_offset = (uint) ((char*) field->null_ptr
  4235. - (char*) table->record[0]);
  4236. if (record[null_offset] & field->null_bit) {
  4237. return(1);
  4238. }
  4239. return(0);
  4240. }
  4241. /*************************************************************//**
  4242. InnoDB uses this function to compare two data fields for which the data type
  4243. is such that we must use MySQL code to compare them. NOTE that the prototype
  4244. of this function is in rem0cmp.c in InnoDB source code! If you change this
  4245. function, remember to update the prototype there!
  4246. @return 1, 0, -1, if a is greater, equal, less than b, respectively */
  4247. extern "C" UNIV_INTERN
  4248. int
  4249. innobase_mysql_cmp(
  4250. /*===============*/
  4251. int mysql_type, /*!< in: MySQL type */
  4252. uint charset_number, /*!< in: number of the charset */
  4253. const unsigned char* a, /*!< in: data field */
  4254. unsigned int a_length, /*!< in: data field length,
  4255. not UNIV_SQL_NULL */
  4256. const unsigned char* b, /*!< in: data field */
  4257. unsigned int b_length) /*!< in: data field length,
  4258. not UNIV_SQL_NULL */
  4259. {
  4260. CHARSET_INFO* charset;
  4261. enum_field_types mysql_tp;
  4262. int ret;
  4263. DBUG_ASSERT(a_length != UNIV_SQL_NULL);
  4264. DBUG_ASSERT(b_length != UNIV_SQL_NULL);
  4265. mysql_tp = (enum_field_types) mysql_type;
  4266. switch (mysql_tp) {
  4267. case MYSQL_TYPE_BIT:
  4268. case MYSQL_TYPE_STRING:
  4269. case MYSQL_TYPE_VAR_STRING:
  4270. case MYSQL_TYPE_TINY_BLOB:
  4271. case MYSQL_TYPE_MEDIUM_BLOB:
  4272. case MYSQL_TYPE_BLOB:
  4273. case MYSQL_TYPE_LONG_BLOB:
  4274. case MYSQL_TYPE_VARCHAR:
  4275. /* Use the charset number to pick the right charset struct for
  4276. the comparison. Since the MySQL function get_charset may be
  4277. slow before Bar removes the mutex operation there, we first
  4278. look at 2 common charsets directly. */
  4279. if (charset_number == default_charset_info->number) {
  4280. charset = default_charset_info;
  4281. } else if (charset_number == my_charset_latin1.number) {
  4282. charset = &my_charset_latin1;
  4283. } else {
  4284. charset = get_charset(charset_number, MYF(MY_WME));
  4285. if (charset == NULL) {
  4286. sql_print_error("InnoDB needs charset %lu for doing "
  4287. "a comparison, but MySQL cannot "
  4288. "find that charset.",
  4289. (ulong) charset_number);
  4290. ut_a(0);
  4291. }
  4292. }
  4293. /* Starting from 4.1.3, we use strnncollsp() in comparisons of
  4294. non-latin1_swedish_ci strings. NOTE that the collation order
  4295. changes then: 'b\0\0...' is ordered BEFORE 'b ...'. Users
  4296. having indexes on such data need to rebuild their tables! */
  4297. ret = charset->coll->strnncollsp(charset,
  4298. a, a_length,
  4299. b, b_length, 0);
  4300. if (ret < 0) {
  4301. return(-1);
  4302. } else if (ret > 0) {
  4303. return(1);
  4304. } else {
  4305. return(0);
  4306. }
  4307. default:
  4308. ut_error;
  4309. }
  4310. return(0);
  4311. }
  4312. /**************************************************************//**
  4313. Converts a MySQL type to an InnoDB type. Note that this function returns
  4314. the 'mtype' of InnoDB. InnoDB differentiates between MySQL's old <= 4.1
  4315. VARCHAR and the new true VARCHAR in >= 5.0.3 by the 'prtype'.
  4316. @return DATA_BINARY, DATA_VARCHAR, ... */
  4317. extern "C" UNIV_INTERN
  4318. ulint
  4319. get_innobase_type_from_mysql_type(
  4320. /*==============================*/
  4321. ulint* unsigned_flag, /*!< out: DATA_UNSIGNED if an
  4322. 'unsigned type';
  4323. at least ENUM and SET,
  4324. and unsigned integer
  4325. types are 'unsigned types' */
  4326. const void* f) /*!< in: MySQL Field */
  4327. {
  4328. const class Field* field = reinterpret_cast<const class Field*>(f);
  4329. /* The following asserts try to check that the MySQL type code fits in
  4330. 8 bits: this is used in ibuf and also when DATA_NOT_NULL is ORed to
  4331. the type */
  4332. DBUG_ASSERT((ulint)MYSQL_TYPE_STRING < 256);
  4333. DBUG_ASSERT((ulint)MYSQL_TYPE_VAR_STRING < 256);
  4334. DBUG_ASSERT((ulint)MYSQL_TYPE_DOUBLE < 256);
  4335. DBUG_ASSERT((ulint)MYSQL_TYPE_FLOAT < 256);
  4336. DBUG_ASSERT((ulint)MYSQL_TYPE_DECIMAL < 256);
  4337. if (field->flags & UNSIGNED_FLAG) {
  4338. *unsigned_flag = DATA_UNSIGNED;
  4339. } else {
  4340. *unsigned_flag = 0;
  4341. }
  4342. if (field->real_type() == MYSQL_TYPE_ENUM
  4343. || field->real_type() == MYSQL_TYPE_SET) {
  4344. /* MySQL has field->type() a string type for these, but the
  4345. data is actually internally stored as an unsigned integer
  4346. code! */
  4347. *unsigned_flag = DATA_UNSIGNED; /* MySQL has its own unsigned
  4348. flag set to zero, even though
  4349. internally this is an unsigned
  4350. integer type */
  4351. return(DATA_INT);
  4352. }
  4353. switch (field->type()) {
  4354. /* NOTE that we only allow string types in DATA_MYSQL and
  4355. DATA_VARMYSQL */
  4356. case MYSQL_TYPE_VAR_STRING: /* old <= 4.1 VARCHAR */
  4357. case MYSQL_TYPE_VARCHAR: /* new >= 5.0.3 true VARCHAR */
  4358. if (field->binary()) {
  4359. return(DATA_BINARY);
  4360. } else if (strcmp(
  4361. field->charset()->name,
  4362. "latin1_swedish_ci") == 0) {
  4363. return(DATA_VARCHAR);
  4364. } else {
  4365. return(DATA_VARMYSQL);
  4366. }
  4367. case MYSQL_TYPE_BIT:
  4368. case MYSQL_TYPE_STRING: if (field->binary()) {
  4369. return(DATA_FIXBINARY);
  4370. } else if (strcmp(
  4371. field->charset()->name,
  4372. "latin1_swedish_ci") == 0) {
  4373. return(DATA_CHAR);
  4374. } else {
  4375. return(DATA_MYSQL);
  4376. }
  4377. case MYSQL_TYPE_NEWDECIMAL:
  4378. return(DATA_FIXBINARY);
  4379. case MYSQL_TYPE_LONG:
  4380. case MYSQL_TYPE_LONGLONG:
  4381. case MYSQL_TYPE_TINY:
  4382. case MYSQL_TYPE_SHORT:
  4383. case MYSQL_TYPE_INT24:
  4384. case MYSQL_TYPE_DATE:
  4385. case MYSQL_TYPE_YEAR:
  4386. case MYSQL_TYPE_NEWDATE:
  4387. return(DATA_INT);
  4388. case MYSQL_TYPE_TIME:
  4389. case MYSQL_TYPE_DATETIME:
  4390. case MYSQL_TYPE_TIMESTAMP:
  4391. /*
  4392. XtraDB should ideally just check field->keytype() and never
  4393. field->type(). The following check is here to only
  4394. change the new hires datetime/timestamp/time fields to
  4395. use DATA_FIXBINARY. We can't convert this function to
  4396. just test for field->keytype() as then the check if a
  4397. table is compatible will fail for old tables.
  4398. */
  4399. if (field->key_type() == HA_KEYTYPE_BINARY)
  4400. return(DATA_FIXBINARY);
  4401. return(DATA_INT);
  4402. case MYSQL_TYPE_FLOAT:
  4403. return(DATA_FLOAT);
  4404. case MYSQL_TYPE_DOUBLE:
  4405. return(DATA_DOUBLE);
  4406. case MYSQL_TYPE_DECIMAL:
  4407. return(DATA_DECIMAL);
  4408. case MYSQL_TYPE_GEOMETRY:
  4409. case MYSQL_TYPE_TINY_BLOB:
  4410. case MYSQL_TYPE_MEDIUM_BLOB:
  4411. case MYSQL_TYPE_BLOB:
  4412. case MYSQL_TYPE_LONG_BLOB:
  4413. return(DATA_BLOB);
  4414. case MYSQL_TYPE_NULL:
  4415. return(DATA_FIXBINARY);
  4416. default:
  4417. ut_error;
  4418. }
  4419. return(0);
  4420. }
  4421. /*******************************************************************//**
  4422. Writes an unsigned integer value < 64k to 2 bytes, in the little-endian
  4423. storage format. */
  4424. static inline
  4425. void
  4426. innobase_write_to_2_little_endian(
  4427. /*==============================*/
  4428. byte* buf, /*!< in: where to store */
  4429. ulint val) /*!< in: value to write, must be < 64k */
  4430. {
  4431. ut_a(val < 256 * 256);
  4432. buf[0] = (byte)(val & 0xFF);
  4433. buf[1] = (byte)(val / 256);
  4434. }
  4435. /*******************************************************************//**
  4436. Reads an unsigned integer value < 64k from 2 bytes, in the little-endian
  4437. storage format.
  4438. @return value */
  4439. static inline
  4440. uint
  4441. innobase_read_from_2_little_endian(
  4442. /*===============================*/
  4443. const uchar* buf) /*!< in: from where to read */
  4444. {
  4445. return (uint) ((ulint)(buf[0]) + 256 * ((ulint)(buf[1])));
  4446. }
  4447. /*******************************************************************//**
  4448. Stores a key value for a row to a buffer.
  4449. @return key value length as stored in buff */
  4450. UNIV_INTERN
  4451. uint
  4452. ha_innobase::store_key_val_for_row(
  4453. /*===============================*/
  4454. uint keynr, /*!< in: key number */
  4455. char* buff, /*!< in/out: buffer for the key value (in MySQL
  4456. format) */
  4457. uint buff_len,/*!< in: buffer length */
  4458. const uchar* record)/*!< in: row in MySQL format */
  4459. {
  4460. KEY* key_info = table->key_info + keynr;
  4461. KEY_PART_INFO* key_part = key_info->key_part;
  4462. KEY_PART_INFO* end = key_part + key_info->key_parts;
  4463. char* buff_start = buff;
  4464. enum_field_types mysql_type;
  4465. Field* field;
  4466. ibool is_null;
  4467. DBUG_ENTER("store_key_val_for_row");
  4468. /* The format for storing a key field in MySQL is the following:
  4469. 1. If the column can be NULL, then in the first byte we put 1 if the
  4470. field value is NULL, 0 otherwise.
  4471. 2. If the column is of a BLOB type (it must be a column prefix field
  4472. in this case), then we put the length of the data in the field to the
  4473. next 2 bytes, in the little-endian format. If the field is SQL NULL,
  4474. then these 2 bytes are set to 0. Note that the length of data in the
  4475. field is <= column prefix length.
  4476. 3. In a column prefix field, prefix_len next bytes are reserved for
  4477. data. In a normal field the max field length next bytes are reserved
  4478. for data. For a VARCHAR(n) the max field length is n. If the stored
  4479. value is the SQL NULL then these data bytes are set to 0.
  4480. 4. We always use a 2 byte length for a true >= 5.0.3 VARCHAR. Note that
  4481. in the MySQL row format, the length is stored in 1 or 2 bytes,
  4482. depending on the maximum allowed length. But in the MySQL key value
  4483. format, the length always takes 2 bytes.
  4484. We have to zero-fill the buffer so that MySQL is able to use a
  4485. simple memcmp to compare two key values to determine if they are
  4486. equal. MySQL does this to compare contents of two 'ref' values. */
  4487. bzero(buff, buff_len);
  4488. for (; key_part != end; key_part++) {
  4489. is_null = FALSE;
  4490. if (key_part->null_bit) {
  4491. if (record[key_part->null_offset]
  4492. & key_part->null_bit) {
  4493. *buff = 1;
  4494. is_null = TRUE;
  4495. } else {
  4496. *buff = 0;
  4497. }
  4498. buff++;
  4499. }
  4500. field = key_part->field;
  4501. mysql_type = field->type();
  4502. if (mysql_type == MYSQL_TYPE_VARCHAR) {
  4503. /* >= 5.0.3 true VARCHAR */
  4504. ulint lenlen;
  4505. ulint len;
  4506. const byte* data;
  4507. ulint key_len;
  4508. ulint true_len;
  4509. CHARSET_INFO* cs;
  4510. int error=0;
  4511. key_len = key_part->length;
  4512. if (is_null) {
  4513. buff += key_len + 2;
  4514. continue;
  4515. }
  4516. cs = field->charset();
  4517. lenlen = (ulint)
  4518. (((Field_varstring*)field)->length_bytes);
  4519. data = row_mysql_read_true_varchar(&len,
  4520. (byte*) (record
  4521. + (ulint)get_field_offset(table, field)),
  4522. lenlen);
  4523. true_len = len;
  4524. /* For multi byte character sets we need to calculate
  4525. the true length of the key */
  4526. if (len > 0 && cs->mbmaxlen > 1) {
  4527. true_len = (ulint) cs->cset->well_formed_len(cs,
  4528. (const char *) data,
  4529. (const char *) data + len,
  4530. (uint) (key_len /
  4531. cs->mbmaxlen),
  4532. &error);
  4533. }
  4534. /* In a column prefix index, we may need to truncate
  4535. the stored value: */
  4536. if (true_len > key_len) {
  4537. true_len = key_len;
  4538. }
  4539. /* The length in a key value is always stored in 2
  4540. bytes */
  4541. row_mysql_store_true_var_len((byte*)buff, true_len, 2);
  4542. buff += 2;
  4543. memcpy(buff, data, true_len);
  4544. /* Note that we always reserve the maximum possible
  4545. length of the true VARCHAR in the key value, though
  4546. only len first bytes after the 2 length bytes contain
  4547. actual data. The rest of the space was reset to zero
  4548. in the bzero() call above. */
  4549. buff += key_len;
  4550. } else if (mysql_type == MYSQL_TYPE_TINY_BLOB
  4551. || mysql_type == MYSQL_TYPE_MEDIUM_BLOB
  4552. || mysql_type == MYSQL_TYPE_BLOB
  4553. || mysql_type == MYSQL_TYPE_LONG_BLOB
  4554. /* MYSQL_TYPE_GEOMETRY data is treated
  4555. as BLOB data in innodb. */
  4556. || mysql_type == MYSQL_TYPE_GEOMETRY) {
  4557. CHARSET_INFO* cs;
  4558. ulint key_len;
  4559. ulint true_len;
  4560. int error=0;
  4561. ulint blob_len;
  4562. const byte* blob_data;
  4563. ut_a(key_part->key_part_flag & HA_PART_KEY_SEG);
  4564. key_len = key_part->length;
  4565. if (is_null) {
  4566. buff += key_len + 2;
  4567. continue;
  4568. }
  4569. cs = field->charset();
  4570. blob_data = row_mysql_read_blob_ref(&blob_len,
  4571. (byte*) (record
  4572. + (ulint)get_field_offset(table, field)),
  4573. (ulint) field->pack_length());
  4574. true_len = blob_len;
  4575. ut_a(get_field_offset(table, field)
  4576. == key_part->offset);
  4577. /* For multi byte character sets we need to calculate
  4578. the true length of the key */
  4579. if (blob_len > 0 && cs->mbmaxlen > 1) {
  4580. true_len = (ulint) cs->cset->well_formed_len(cs,
  4581. (const char *) blob_data,
  4582. (const char *) blob_data
  4583. + blob_len,
  4584. (uint) (key_len /
  4585. cs->mbmaxlen),
  4586. &error);
  4587. }
  4588. /* All indexes on BLOB and TEXT are column prefix
  4589. indexes, and we may need to truncate the data to be
  4590. stored in the key value: */
  4591. if (true_len > key_len) {
  4592. true_len = key_len;
  4593. }
  4594. /* MySQL reserves 2 bytes for the length and the
  4595. storage of the number is little-endian */
  4596. innobase_write_to_2_little_endian(
  4597. (byte*)buff, true_len);
  4598. buff += 2;
  4599. memcpy(buff, blob_data, true_len);
  4600. /* Note that we always reserve the maximum possible
  4601. length of the BLOB prefix in the key value. */
  4602. buff += key_len;
  4603. } else {
  4604. /* Here we handle all other data types except the
  4605. true VARCHAR, BLOB and TEXT. Note that the column
  4606. value we store may be also in a column prefix
  4607. index. */
  4608. CHARSET_INFO* cs;
  4609. ulint true_len;
  4610. ulint key_len;
  4611. const uchar* src_start;
  4612. int error=0;
  4613. enum_field_types real_type;
  4614. key_len = key_part->length;
  4615. if (is_null) {
  4616. buff += key_len;
  4617. continue;
  4618. }
  4619. src_start = record + key_part->offset;
  4620. real_type = field->real_type();
  4621. true_len = key_len;
  4622. /* Character set for the field is defined only
  4623. to fields whose type is string and real field
  4624. type is not enum or set. For these fields check
  4625. if character set is multi byte. */
  4626. if (real_type != MYSQL_TYPE_ENUM
  4627. && real_type != MYSQL_TYPE_SET
  4628. && ( mysql_type == MYSQL_TYPE_VAR_STRING
  4629. || mysql_type == MYSQL_TYPE_STRING)) {
  4630. cs = field->charset();
  4631. /* For multi byte character sets we need to
  4632. calculate the true length of the key */
  4633. if (key_len > 0 && cs->mbmaxlen > 1) {
  4634. true_len = (ulint)
  4635. cs->cset->well_formed_len(cs,
  4636. (const char *)src_start,
  4637. (const char *)src_start
  4638. + key_len,
  4639. (uint) (key_len /
  4640. cs->mbmaxlen),
  4641. &error);
  4642. }
  4643. }
  4644. memcpy(buff, src_start, true_len);
  4645. buff += true_len;
  4646. /* Pad the unused space with spaces. */
  4647. if (true_len < key_len) {
  4648. ulint pad_len = key_len - true_len;
  4649. ut_a(!(pad_len % cs->mbminlen));
  4650. cs->cset->fill(cs, buff, pad_len,
  4651. 0x20 /* space */);
  4652. buff += pad_len;
  4653. }
  4654. }
  4655. }
  4656. ut_a(buff <= buff_start + buff_len);
  4657. DBUG_RETURN((uint)(buff - buff_start));
  4658. }
  4659. /**************************************************************//**
  4660. Determines if a field is needed in a prebuilt struct 'template'.
  4661. @return field to use, or NULL if the field is not needed */
  4662. static
  4663. const Field*
  4664. build_template_needs_field(
  4665. /*=======================*/
  4666. ibool index_contains, /*!< in:
  4667. dict_index_contains_col_or_prefix(
  4668. index, i) */
  4669. ibool read_just_key, /*!< in: TRUE when MySQL calls
  4670. ha_innobase::extra with the
  4671. argument HA_EXTRA_KEYREAD; it is enough
  4672. to read just columns defined in
  4673. the index (i.e., no read of the
  4674. clustered index record necessary) */
  4675. ibool fetch_all_in_key,
  4676. /*!< in: true=fetch all fields in
  4677. the index */
  4678. ibool fetch_primary_key_cols,
  4679. /*!< in: true=fetch the
  4680. primary key columns */
  4681. dict_index_t* index, /*!< in: InnoDB index to use */
  4682. const TABLE* table, /*!< in: MySQL table object */
  4683. ulint i, /*!< in: field index in InnoDB table */
  4684. ulint sql_idx) /*!< in: field index in SQL table */
  4685. {
  4686. const Field* field = table->field[sql_idx];
  4687. ut_ad(index_contains == dict_index_contains_col_or_prefix(index, i));
  4688. if (!index_contains) {
  4689. if (read_just_key) {
  4690. /* If this is a 'key read', we do not need
  4691. columns that are not in the key */
  4692. return(NULL);
  4693. }
  4694. } else if (fetch_all_in_key) {
  4695. /* This field is needed in the query */
  4696. return(field);
  4697. }
  4698. if (bitmap_is_set(table->read_set, sql_idx)
  4699. || bitmap_is_set(table->write_set, sql_idx)) {
  4700. /* This field is needed in the query */
  4701. return(field);
  4702. }
  4703. if (fetch_primary_key_cols
  4704. && dict_table_col_in_clustered_key(index->table, i)) {
  4705. /* This field is needed in the query */
  4706. return(field);
  4707. }
  4708. /* This field is not needed in the query, skip it */
  4709. return(NULL);
  4710. }
  4711. /**************************************************************//**
  4712. Adds a field is to a prebuilt struct 'template'.
  4713. @return the field template */
  4714. static
  4715. mysql_row_templ_t*
  4716. build_template_field(
  4717. /*=================*/
  4718. row_prebuilt_t* prebuilt, /*!< in/out: template */
  4719. dict_index_t* clust_index, /*!< in: InnoDB clustered index */
  4720. dict_index_t* index, /*!< in: InnoDB index to use */
  4721. TABLE* table, /*!< in: MySQL table object */
  4722. const Field* field, /*!< in: field in MySQL table */
  4723. ulint i) /*!< in: field index in InnoDB table */
  4724. {
  4725. mysql_row_templ_t* templ;
  4726. const dict_col_t* col;
  4727. //ut_ad(field == table->field[i]);
  4728. ut_ad(clust_index->table == index->table);
  4729. col = dict_table_get_nth_col(index->table, i);
  4730. templ = prebuilt->mysql_template + prebuilt->n_template++;
  4731. UNIV_MEM_INVALID(templ, sizeof *templ);
  4732. templ->col_no = i;
  4733. templ->clust_rec_field_no = dict_col_get_clust_pos(col, clust_index);
  4734. ut_a(templ->clust_rec_field_no != ULINT_UNDEFINED);
  4735. if (dict_index_is_clust(index)) {
  4736. templ->rec_field_no = templ->clust_rec_field_no;
  4737. } else {
  4738. templ->rec_field_no = dict_index_get_nth_col_pos(index, i);
  4739. }
  4740. if (field->null_ptr) {
  4741. templ->mysql_null_byte_offset =
  4742. (ulint) ((char*) field->null_ptr
  4743. - (char*) table->record[0]);
  4744. templ->mysql_null_bit_mask = (ulint) field->null_bit;
  4745. } else {
  4746. templ->mysql_null_bit_mask = 0;
  4747. }
  4748. templ->mysql_col_offset = (ulint) get_field_offset(table, field);
  4749. templ->mysql_col_len = (ulint) field->pack_length();
  4750. templ->type = col->mtype;
  4751. templ->mysql_type = (ulint)field->type();
  4752. if (templ->mysql_type == DATA_MYSQL_TRUE_VARCHAR) {
  4753. templ->mysql_length_bytes = (ulint)
  4754. (((Field_varstring*)field)->length_bytes);
  4755. }
  4756. templ->charset = dtype_get_charset_coll(col->prtype);
  4757. templ->mbminlen = DATA_MBMINLEN(col->mbminmaxlen);
  4758. templ->mbmaxlen = DATA_MBMAXLEN(col->mbminmaxlen);
  4759. templ->is_unsigned = col->prtype & DATA_UNSIGNED;
  4760. if (!dict_index_is_clust(index)
  4761. && templ->rec_field_no == ULINT_UNDEFINED) {
  4762. prebuilt->need_to_access_clustered = TRUE;
  4763. }
  4764. if (prebuilt->mysql_prefix_len < templ->mysql_col_offset
  4765. + templ->mysql_col_len) {
  4766. prebuilt->mysql_prefix_len = templ->mysql_col_offset
  4767. + templ->mysql_col_len;
  4768. }
  4769. if (templ->type == DATA_BLOB) {
  4770. prebuilt->templ_contains_blob = TRUE;
  4771. }
  4772. return(templ);
  4773. }
  4774. /**************************************************************//**
  4775. Builds a 'template' to the prebuilt struct. The template is used in fast
  4776. retrieval of just those column values MySQL needs in its processing. */
  4777. UNIV_INTERN
  4778. void
  4779. ha_innobase::build_template(
  4780. /*========================*/
  4781. bool whole_row) /*!< in: true=ROW_MYSQL_WHOLE_ROW,
  4782. false=ROW_MYSQL_REC_FIELDS */
  4783. {
  4784. dict_index_t* index;
  4785. dict_index_t* clust_index;
  4786. ulint n_stored_fields;
  4787. ibool fetch_all_in_key = FALSE;
  4788. ibool fetch_primary_key_cols = FALSE;
  4789. ulint i, sql_idx;
  4790. if (prebuilt->select_lock_type == LOCK_X) {
  4791. /* We always retrieve the whole clustered index record if we
  4792. use exclusive row level locks, for example, if the read is
  4793. done in an UPDATE statement. */
  4794. whole_row = true;
  4795. } else if (!whole_row) {
  4796. if (prebuilt->hint_need_to_fetch_extra_cols
  4797. == ROW_RETRIEVE_ALL_COLS) {
  4798. /* We know we must at least fetch all columns in the
  4799. key, or all columns in the table */
  4800. if (prebuilt->read_just_key) {
  4801. /* MySQL has instructed us that it is enough
  4802. to fetch the columns in the key; looks like
  4803. MySQL can set this flag also when there is
  4804. only a prefix of the column in the key: in
  4805. that case we retrieve the whole column from
  4806. the clustered index */
  4807. fetch_all_in_key = TRUE;
  4808. } else {
  4809. whole_row = true;
  4810. }
  4811. } else if (prebuilt->hint_need_to_fetch_extra_cols
  4812. == ROW_RETRIEVE_PRIMARY_KEY) {
  4813. /* We must at least fetch all primary key cols. Note
  4814. that if the clustered index was internally generated
  4815. by InnoDB on the row id (no primary key was
  4816. defined), then row_search_for_mysql() will always
  4817. retrieve the row id to a special buffer in the
  4818. prebuilt struct. */
  4819. fetch_primary_key_cols = TRUE;
  4820. }
  4821. }
  4822. clust_index = dict_table_get_first_index(prebuilt->table);
  4823. index = whole_row ? clust_index : prebuilt->index;
  4824. prebuilt->need_to_access_clustered = (index == clust_index);
  4825. /* Below we check column by column if we need to access
  4826. the clustered index. */
  4827. n_stored_fields= (ulint)table->s->stored_fields; /* number of stored columns */
  4828. if (!prebuilt->mysql_template) {
  4829. prebuilt->mysql_template = (mysql_row_templ_t*)
  4830. mem_alloc(n_stored_fields * sizeof(mysql_row_templ_t));
  4831. }
  4832. prebuilt->template_type = whole_row
  4833. ? ROW_MYSQL_WHOLE_ROW : ROW_MYSQL_REC_FIELDS;
  4834. prebuilt->null_bitmap_len = table->s->null_bytes;
  4835. /* Prepare to build prebuilt->mysql_template[]. */
  4836. prebuilt->templ_contains_blob = FALSE;
  4837. prebuilt->mysql_prefix_len = 0;
  4838. prebuilt->n_template = 0;
  4839. prebuilt->idx_cond_n_cols = 0;
  4840. /* Note that in InnoDB, i is the column number in the table.
  4841. MySQL calls columns 'fields'. */
  4842. if (active_index != MAX_KEY && active_index == pushed_idx_cond_keyno) {
  4843. /* Push down an index condition or an end_range check. */
  4844. for (i = 0, sql_idx = 0; i < n_stored_fields; i++, sql_idx++) {
  4845. while (!table->field[sql_idx]->stored_in_db) {
  4846. sql_idx++;
  4847. }
  4848. const ibool index_contains
  4849. = dict_index_contains_col_or_prefix(index, i);
  4850. /* Test if an end_range or an index condition
  4851. refers to the field. Note that "index" and
  4852. "index_contains" may refer to the clustered index.
  4853. Index condition pushdown is relative to prebuilt->index
  4854. (the index that is being looked up first). */
  4855. /* When join_read_always_key() invokes this
  4856. code via handler::ha_index_init() and
  4857. ha_innobase::index_init(), end_range is not
  4858. yet initialized. Because of that, we must
  4859. always check for index_contains, instead of
  4860. the subset
  4861. field->part_of_key.is_set(active_index)
  4862. which would be acceptable if end_range==NULL. */
  4863. if (index == prebuilt->index
  4864. ? index_contains
  4865. : dict_index_contains_col_or_prefix(
  4866. prebuilt->index, i)) {
  4867. /* Needed in ICP */
  4868. const Field* field;
  4869. mysql_row_templ_t* templ;
  4870. if (whole_row) {
  4871. field = table->field[sql_idx];
  4872. } else {
  4873. field = build_template_needs_field(
  4874. index_contains,
  4875. prebuilt->read_just_key,
  4876. fetch_all_in_key,
  4877. fetch_primary_key_cols,
  4878. index, table, i, sql_idx);
  4879. if (!field) {
  4880. continue;
  4881. }
  4882. }
  4883. templ = build_template_field(
  4884. prebuilt, clust_index, index,
  4885. table, field, i);
  4886. prebuilt->idx_cond_n_cols++;
  4887. ut_ad(prebuilt->idx_cond_n_cols
  4888. == prebuilt->n_template);
  4889. if (index == prebuilt->index) {
  4890. templ->icp_rec_field_no
  4891. = templ->rec_field_no;
  4892. } else {
  4893. templ->icp_rec_field_no
  4894. = dict_index_get_nth_col_pos(
  4895. prebuilt->index, i);
  4896. }
  4897. if (dict_index_is_clust(prebuilt->index)) {
  4898. ut_ad(templ->icp_rec_field_no
  4899. != ULINT_UNDEFINED);
  4900. /* If the primary key includes
  4901. a column prefix, use it in
  4902. index condition pushdown,
  4903. because the condition is
  4904. evaluated before fetching any
  4905. off-page (externally stored)
  4906. columns. */
  4907. if (templ->icp_rec_field_no
  4908. < prebuilt->index->n_uniq) {
  4909. /* This is a key column;
  4910. all set. */
  4911. continue;
  4912. }
  4913. } else if (templ->icp_rec_field_no
  4914. != ULINT_UNDEFINED) {
  4915. continue;
  4916. }
  4917. /* This is a column prefix index.
  4918. The column prefix can be used in
  4919. an end_range comparison. */
  4920. templ->icp_rec_field_no
  4921. = dict_index_get_nth_col_or_prefix_pos(
  4922. prebuilt->index, i, TRUE);
  4923. ut_ad(templ->icp_rec_field_no
  4924. != ULINT_UNDEFINED);
  4925. /* Index condition pushdown can be used on
  4926. all columns of a secondary index, and on
  4927. the PRIMARY KEY columns. */
  4928. /* TODO: enable this assertion
  4929. (but first ensure that end_range is
  4930. valid here and use an accurate condition
  4931. for end_range)
  4932. ut_ad(!dict_index_is_clust(prebuilt->index)
  4933. || templ->rec_field_no
  4934. < prebuilt->index->n_uniq);
  4935. */
  4936. }
  4937. }
  4938. ut_ad(prebuilt->idx_cond_n_cols > 0);
  4939. ut_ad(prebuilt->idx_cond_n_cols == prebuilt->n_template);
  4940. /* Include the fields that are not needed in index condition
  4941. pushdown. */
  4942. for (i = 0, sql_idx = 0; i < n_stored_fields; i++, sql_idx++) {
  4943. while (!table->field[sql_idx]->stored_in_db) {
  4944. sql_idx++;
  4945. }
  4946. const ibool index_contains
  4947. = dict_index_contains_col_or_prefix(index, i);
  4948. if (index == prebuilt->index
  4949. ? !index_contains
  4950. : !dict_index_contains_col_or_prefix(
  4951. prebuilt->index, i)) {
  4952. /* Not needed in ICP */
  4953. const Field* field;
  4954. if (whole_row) {
  4955. field = table->field[sql_idx];
  4956. } else {
  4957. field = build_template_needs_field(
  4958. index_contains,
  4959. prebuilt->read_just_key,
  4960. fetch_all_in_key,
  4961. fetch_primary_key_cols,
  4962. index, table, i, sql_idx);
  4963. if (!field) {
  4964. continue;
  4965. }
  4966. }
  4967. build_template_field(prebuilt,
  4968. clust_index, index,
  4969. table, field, i);
  4970. }
  4971. }
  4972. prebuilt->idx_cond = this;
  4973. } else {
  4974. /* No index condition pushdown */
  4975. prebuilt->idx_cond = NULL;
  4976. for (i = 0, sql_idx = 0; i < n_stored_fields; i++, sql_idx++) {
  4977. const Field* field;
  4978. while (!table->field[sql_idx]->stored_in_db) {
  4979. sql_idx++;
  4980. }
  4981. if (whole_row) {
  4982. field = table->field[sql_idx];
  4983. } else {
  4984. field = build_template_needs_field(
  4985. dict_index_contains_col_or_prefix(
  4986. index, i),
  4987. prebuilt->read_just_key,
  4988. fetch_all_in_key,
  4989. fetch_primary_key_cols,
  4990. index, table, i, sql_idx);
  4991. if (!field) {
  4992. continue;
  4993. }
  4994. }
  4995. build_template_field(prebuilt, clust_index, index,
  4996. table, field, i);
  4997. }
  4998. }
  4999. if (index != clust_index && prebuilt->need_to_access_clustered) {
  5000. /* Change rec_field_no's to correspond to the clustered index
  5001. record */
  5002. for (i = 0; i < prebuilt->n_template; i++) {
  5003. mysql_row_templ_t* templ
  5004. = &prebuilt->mysql_template[i];
  5005. templ->rec_field_no = templ->clust_rec_field_no;
  5006. }
  5007. }
  5008. }
  5009. /********************************************************************//**
  5010. This special handling is really to overcome the limitations of MySQL's
  5011. binlogging. We need to eliminate the non-determinism that will arise in
  5012. INSERT ... SELECT type of statements, since MySQL binlog only stores the
  5013. min value of the autoinc interval. Once that is fixed we can get rid of
  5014. the special lock handling.
  5015. @return DB_SUCCESS if all OK else error code */
  5016. UNIV_INTERN
  5017. ulint
  5018. ha_innobase::innobase_lock_autoinc(void)
  5019. /*====================================*/
  5020. {
  5021. ulint error = DB_SUCCESS;
  5022. switch (innobase_autoinc_lock_mode) {
  5023. case AUTOINC_NO_LOCKING:
  5024. /* Acquire only the AUTOINC mutex. */
  5025. dict_table_autoinc_lock(prebuilt->table);
  5026. break;
  5027. case AUTOINC_NEW_STYLE_LOCKING:
  5028. /* For simple (single/multi) row INSERTs, we fallback to the
  5029. old style only if another transaction has already acquired
  5030. the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT
  5031. etc. type of statement. */
  5032. if (thd_sql_command(user_thd) == SQLCOM_INSERT
  5033. || thd_sql_command(user_thd) == SQLCOM_REPLACE) {
  5034. dict_table_t* table = prebuilt->table;
  5035. /* Acquire the AUTOINC mutex. */
  5036. dict_table_autoinc_lock(table);
  5037. /* We need to check that another transaction isn't
  5038. already holding the AUTOINC lock on the table. */
  5039. if (table->n_waiting_or_granted_auto_inc_locks) {
  5040. /* Release the mutex to avoid deadlocks. */
  5041. dict_table_autoinc_unlock(table);
  5042. } else {
  5043. break;
  5044. }
  5045. }
  5046. /* Fall through to old style locking. */
  5047. case AUTOINC_OLD_STYLE_LOCKING:
  5048. error = row_lock_table_autoinc_for_mysql(prebuilt);
  5049. if (error == DB_SUCCESS) {
  5050. /* Acquire the AUTOINC mutex. */
  5051. dict_table_autoinc_lock(prebuilt->table);
  5052. }
  5053. break;
  5054. default:
  5055. ut_error;
  5056. }
  5057. return(ulong(error));
  5058. }
  5059. /********************************************************************//**
  5060. Reset the autoinc value in the table.
  5061. @return DB_SUCCESS if all went well else error code */
  5062. UNIV_INTERN
  5063. ulint
  5064. ha_innobase::innobase_reset_autoinc(
  5065. /*================================*/
  5066. ulonglong autoinc) /*!< in: value to store */
  5067. {
  5068. ulint error;
  5069. error = innobase_lock_autoinc();
  5070. if (error == DB_SUCCESS) {
  5071. dict_table_autoinc_initialize(prebuilt->table, autoinc);
  5072. dict_table_autoinc_unlock(prebuilt->table);
  5073. }
  5074. return(ulong(error));
  5075. }
  5076. /********************************************************************//**
  5077. Store the autoinc value in the table. The autoinc value is only set if
  5078. it's greater than the existing autoinc value in the table.
  5079. @return DB_SUCCESS if all went well else error code */
  5080. UNIV_INTERN
  5081. ulint
  5082. ha_innobase::innobase_set_max_autoinc(
  5083. /*==================================*/
  5084. ulonglong auto_inc) /*!< in: value to store */
  5085. {
  5086. ulint error;
  5087. error = innobase_lock_autoinc();
  5088. if (error == DB_SUCCESS) {
  5089. dict_table_autoinc_update_if_greater(prebuilt->table, auto_inc);
  5090. dict_table_autoinc_unlock(prebuilt->table);
  5091. }
  5092. return(ulong(error));
  5093. }
  5094. /********************************************************************//**
  5095. Stores a row in an InnoDB database, to the table specified in this
  5096. handle.
  5097. @return error code */
  5098. UNIV_INTERN
  5099. int
  5100. ha_innobase::write_row(
  5101. /*===================*/
  5102. uchar* record) /*!< in: a row in MySQL format */
  5103. {
  5104. ulint error = 0;
  5105. int error_result= 0;
  5106. ibool auto_inc_used= FALSE;
  5107. ulint sql_command;
  5108. trx_t* trx = thd_to_trx(user_thd);
  5109. DBUG_ENTER("ha_innobase::write_row");
  5110. if (prebuilt->trx != trx) {
  5111. sql_print_error("The transaction object for the table handle is at "
  5112. "%p, but for the current thread it is at %p",
  5113. (const void*) prebuilt->trx, (const void*) trx);
  5114. fputs("InnoDB: Dump of 200 bytes around prebuilt: ", stderr);
  5115. ut_print_buf(stderr, ((const byte*)prebuilt) - 100, 200);
  5116. fputs("\n"
  5117. "InnoDB: Dump of 200 bytes around ha_data: ",
  5118. stderr);
  5119. ut_print_buf(stderr, ((const byte*) trx) - 100, 200);
  5120. putc('\n', stderr);
  5121. ut_error;
  5122. }
  5123. ha_statistic_increment(&SSV::ha_write_count);
  5124. if (share->ib_table->is_corrupt) {
  5125. DBUG_RETURN(HA_ERR_CRASHED);
  5126. }
  5127. sql_command = thd_sql_command(user_thd);
  5128. if ((sql_command == SQLCOM_ALTER_TABLE
  5129. || sql_command == SQLCOM_OPTIMIZE
  5130. || sql_command == SQLCOM_CREATE_INDEX
  5131. || sql_command == SQLCOM_DROP_INDEX)
  5132. && num_write_row >= 10000) {
  5133. /* ALTER TABLE is COMMITted at every 10000 copied rows.
  5134. The IX table lock for the original table has to be re-issued.
  5135. As this method will be called on a temporary table where the
  5136. contents of the original table is being copied to, it is
  5137. a bit tricky to determine the source table. The cursor
  5138. position in the source table need not be adjusted after the
  5139. intermediate COMMIT, since writes by other transactions are
  5140. being blocked by a MySQL table lock TL_WRITE_ALLOW_READ. */
  5141. dict_table_t* src_table;
  5142. enum lock_mode mode;
  5143. num_write_row = 0;
  5144. /* Commit the transaction. This will release the table
  5145. locks, so they have to be acquired again. */
  5146. /* Altering an InnoDB table */
  5147. /* Get the source table. */
  5148. src_table = lock_get_src_table(
  5149. prebuilt->trx, prebuilt->table, &mode);
  5150. if (!src_table) {
  5151. no_commit:
  5152. /* Unknown situation: do not commit */
  5153. /*
  5154. ut_print_timestamp(stderr);
  5155. fprintf(stderr,
  5156. " InnoDB: ALTER TABLE is holding lock"
  5157. " on %lu tables!\n",
  5158. prebuilt->trx->mysql_n_tables_locked);
  5159. */
  5160. ;
  5161. } else if (src_table == prebuilt->table) {
  5162. /* Source table is not in InnoDB format:
  5163. no need to re-acquire locks on it. */
  5164. /* Altering to InnoDB format */
  5165. innobase_commit(ht, user_thd, 1);
  5166. /* Note that this transaction is still active. */
  5167. trx_register_for_2pc(prebuilt->trx);
  5168. /* We will need an IX lock on the destination table. */
  5169. prebuilt->sql_stat_start = TRUE;
  5170. } else {
  5171. /* Ensure that there are no other table locks than
  5172. LOCK_IX and LOCK_AUTO_INC on the destination table. */
  5173. if (!lock_is_table_exclusive(prebuilt->table,
  5174. prebuilt->trx)) {
  5175. goto no_commit;
  5176. }
  5177. /* Commit the transaction. This will release the table
  5178. locks, so they have to be acquired again. */
  5179. innobase_commit(ht, user_thd, 1);
  5180. /* Note that this transaction is still active. */
  5181. trx_register_for_2pc(prebuilt->trx);
  5182. /* Re-acquire the table lock on the source table. */
  5183. row_lock_table_for_mysql(prebuilt, src_table, mode);
  5184. /* We will need an IX lock on the destination table. */
  5185. prebuilt->sql_stat_start = TRUE;
  5186. }
  5187. }
  5188. num_write_row++;
  5189. /* This is the case where the table has an auto-increment column */
  5190. if (table->next_number_field && record == table->record[0]) {
  5191. /* Reset the error code before calling
  5192. innobase_get_auto_increment(). */
  5193. prebuilt->autoinc_error = DB_SUCCESS;
  5194. if ((error = update_auto_increment())) {
  5195. /* We don't want to mask autoinc overflow errors. */
  5196. /* Handle the case where the AUTOINC sub-system
  5197. failed during initialization. */
  5198. if (prebuilt->autoinc_error == DB_UNSUPPORTED) {
  5199. error_result = ER_AUTOINC_READ_FAILED;
  5200. /* Set the error message to report too. */
  5201. my_error(ER_AUTOINC_READ_FAILED, MYF(0));
  5202. goto func_exit;
  5203. } else if (prebuilt->autoinc_error != DB_SUCCESS) {
  5204. error = (int) prebuilt->autoinc_error;
  5205. goto report_error;
  5206. }
  5207. /* MySQL errors are passed straight back. except for
  5208. HA_ERR_AUTO_INC_READ_FAILED. This can only happen
  5209. for values out of range.
  5210. */
  5211. error_result = (int) error;
  5212. goto func_exit;
  5213. }
  5214. auto_inc_used = TRUE;
  5215. }
  5216. if (prebuilt->mysql_template == NULL
  5217. || prebuilt->template_type != ROW_MYSQL_WHOLE_ROW) {
  5218. /* Build the template used in converting quickly between
  5219. the two database formats */
  5220. build_template(true);
  5221. }
  5222. innodb_srv_conc_enter_innodb(prebuilt->trx);
  5223. error = row_insert_for_mysql((byte*) record, prebuilt);
  5224. #ifdef EXTENDED_FOR_USERSTAT
  5225. if (error == DB_SUCCESS) rows_changed++;
  5226. #endif
  5227. /* Handle duplicate key errors */
  5228. if (auto_inc_used) {
  5229. ulint err;
  5230. ulonglong auto_inc;
  5231. ulonglong col_max_value;
  5232. /* Note the number of rows processed for this statement, used
  5233. by get_auto_increment() to determine the number of AUTO-INC
  5234. values to reserve. This is only useful for a mult-value INSERT
  5235. and is a statement level counter.*/
  5236. if (trx->n_autoinc_rows > 0) {
  5237. --trx->n_autoinc_rows;
  5238. }
  5239. /* We need the upper limit of the col type to check for
  5240. whether we update the table autoinc counter or not. */
  5241. col_max_value = innobase_get_int_col_max_value(
  5242. table->next_number_field);
  5243. /* Get the value that MySQL attempted to store in the table.*/
  5244. auto_inc = table->next_number_field->val_int();
  5245. switch (error) {
  5246. case DB_DUPLICATE_KEY:
  5247. /* A REPLACE command and LOAD DATA INFILE REPLACE
  5248. handle a duplicate key error themselves, but we
  5249. must update the autoinc counter if we are performing
  5250. those statements. */
  5251. switch (sql_command) {
  5252. case SQLCOM_LOAD:
  5253. if (trx->duplicates) {
  5254. goto set_max_autoinc;
  5255. }
  5256. break;
  5257. case SQLCOM_REPLACE:
  5258. case SQLCOM_INSERT_SELECT:
  5259. case SQLCOM_REPLACE_SELECT:
  5260. goto set_max_autoinc;
  5261. default:
  5262. break;
  5263. }
  5264. break;
  5265. case DB_SUCCESS:
  5266. /* If the actual value inserted is greater than
  5267. the upper limit of the interval, then we try and
  5268. update the table upper limit. Note: last_value
  5269. will be 0 if get_auto_increment() was not called.*/
  5270. if (auto_inc >= prebuilt->autoinc_last_value) {
  5271. set_max_autoinc:
  5272. /* This should filter out the negative
  5273. values set explicitly by the user. */
  5274. if (auto_inc <= col_max_value) {
  5275. ut_a(prebuilt->autoinc_increment > 0);
  5276. ulonglong offset;
  5277. ulonglong increment;
  5278. offset = prebuilt->autoinc_offset;
  5279. increment = prebuilt->autoinc_increment;
  5280. auto_inc = innobase_next_autoinc(
  5281. auto_inc,
  5282. 1, increment, offset,
  5283. col_max_value);
  5284. err = innobase_set_max_autoinc(
  5285. auto_inc);
  5286. if (err != DB_SUCCESS) {
  5287. error = err;
  5288. }
  5289. }
  5290. }
  5291. break;
  5292. }
  5293. }
  5294. innodb_srv_conc_exit_innodb(prebuilt->trx);
  5295. report_error:
  5296. error_result = convert_error_code_to_mysql((int) error,
  5297. prebuilt->table->flags,
  5298. user_thd);
  5299. func_exit:
  5300. innobase_active_small();
  5301. if (share->ib_table->is_corrupt) {
  5302. DBUG_RETURN(HA_ERR_CRASHED);
  5303. }
  5304. DBUG_RETURN(error_result);
  5305. }
  5306. /**********************************************************************//**
  5307. Checks which fields have changed in a row and stores information
  5308. of them to an update vector.
  5309. @return error number or 0 */
  5310. static
  5311. int
  5312. calc_row_difference(
  5313. /*================*/
  5314. upd_t* uvect, /*!< in/out: update vector */
  5315. uchar* old_row, /*!< in: old row in MySQL format */
  5316. uchar* new_row, /*!< in: new row in MySQL format */
  5317. TABLE* table, /*!< in: table in MySQL data
  5318. dictionary */
  5319. uchar* upd_buff, /*!< in: buffer to use */
  5320. ulint buff_len, /*!< in: buffer length */
  5321. row_prebuilt_t* prebuilt, /*!< in: InnoDB prebuilt struct */
  5322. THD* thd) /*!< in: user thread */
  5323. {
  5324. uchar* original_upd_buff = upd_buff;
  5325. Field* field;
  5326. enum_field_types field_mysql_type;
  5327. uint n_fields;
  5328. ulint o_len;
  5329. ulint n_len;
  5330. ulint col_pack_len;
  5331. const byte* new_mysql_row_col;
  5332. const byte* o_ptr;
  5333. const byte* n_ptr;
  5334. byte* buf;
  5335. upd_field_t* ufield;
  5336. ulint col_type;
  5337. ulint n_changed = 0;
  5338. dfield_t dfield;
  5339. dict_index_t* clust_index;
  5340. uint sql_idx, innodb_idx= 0;
  5341. n_fields = table->s->fields;
  5342. clust_index = dict_table_get_first_index(prebuilt->table);
  5343. /* We use upd_buff to convert changed fields */
  5344. buf = (byte*) upd_buff;
  5345. for (sql_idx = 0; sql_idx < n_fields; sql_idx++) {
  5346. field = table->field[sql_idx];
  5347. if (!field->stored_in_db)
  5348. continue;
  5349. o_ptr = (const byte*) old_row + get_field_offset(table, field);
  5350. n_ptr = (const byte*) new_row + get_field_offset(table, field);
  5351. /* Use new_mysql_row_col and col_pack_len save the values */
  5352. new_mysql_row_col = n_ptr;
  5353. col_pack_len = field->pack_length();
  5354. o_len = col_pack_len;
  5355. n_len = col_pack_len;
  5356. /* We use o_ptr and n_ptr to dig up the actual data for
  5357. comparison. */
  5358. field_mysql_type = field->type();
  5359. col_type = prebuilt->table->cols[innodb_idx].mtype;
  5360. switch (col_type) {
  5361. case DATA_BLOB:
  5362. o_ptr = row_mysql_read_blob_ref(&o_len, o_ptr, o_len);
  5363. n_ptr = row_mysql_read_blob_ref(&n_len, n_ptr, n_len);
  5364. break;
  5365. case DATA_VARCHAR:
  5366. case DATA_BINARY:
  5367. case DATA_VARMYSQL:
  5368. if (field_mysql_type == MYSQL_TYPE_VARCHAR) {
  5369. /* This is a >= 5.0.3 type true VARCHAR where
  5370. the real payload data length is stored in
  5371. 1 or 2 bytes */
  5372. o_ptr = row_mysql_read_true_varchar(
  5373. &o_len, o_ptr,
  5374. (ulint)
  5375. (((Field_varstring*)field)->length_bytes));
  5376. n_ptr = row_mysql_read_true_varchar(
  5377. &n_len, n_ptr,
  5378. (ulint)
  5379. (((Field_varstring*)field)->length_bytes));
  5380. }
  5381. break;
  5382. default:
  5383. ;
  5384. }
  5385. if (field->null_ptr) {
  5386. if (field_in_record_is_null(table, field,
  5387. (char*) old_row)) {
  5388. o_len = UNIV_SQL_NULL;
  5389. }
  5390. if (field_in_record_is_null(table, field,
  5391. (char*) new_row)) {
  5392. n_len = UNIV_SQL_NULL;
  5393. }
  5394. }
  5395. if (o_len != n_len || (o_len != UNIV_SQL_NULL &&
  5396. 0 != memcmp(o_ptr, n_ptr, o_len))) {
  5397. /* The field has changed */
  5398. ufield = uvect->fields + n_changed;
  5399. UNIV_MEM_INVALID(ufield, sizeof *ufield);
  5400. /* Let us use a dummy dfield to make the conversion
  5401. from the MySQL column format to the InnoDB format */
  5402. if (n_len != UNIV_SQL_NULL) {
  5403. dict_col_copy_type(prebuilt->table->cols + innodb_idx,
  5404. dfield_get_type(&dfield));
  5405. buf = row_mysql_store_col_in_innobase_format(
  5406. &dfield,
  5407. (byte*)buf,
  5408. TRUE,
  5409. new_mysql_row_col,
  5410. col_pack_len,
  5411. dict_table_is_comp(prebuilt->table));
  5412. dfield_copy(&ufield->new_val, &dfield);
  5413. } else {
  5414. dfield_set_null(&ufield->new_val);
  5415. }
  5416. ufield->exp = NULL;
  5417. ufield->orig_len = 0;
  5418. ufield->field_no = dict_col_get_clust_pos(
  5419. &prebuilt->table->cols[innodb_idx], clust_index);
  5420. n_changed++;
  5421. }
  5422. if (field->stored_in_db)
  5423. innodb_idx++;
  5424. }
  5425. uvect->n_fields = n_changed;
  5426. uvect->info_bits = 0;
  5427. ut_a(buf <= (byte*)original_upd_buff + buff_len);
  5428. return(0);
  5429. }
  5430. /**********************************************************************//**
  5431. Updates a row given as a parameter to a new value. Note that we are given
  5432. whole rows, not just the fields which are updated: this incurs some
  5433. overhead for CPU when we check which fields are actually updated.
  5434. TODO: currently InnoDB does not prevent the 'Halloween problem':
  5435. in a searched update a single row can get updated several times
  5436. if its index columns are updated!
  5437. @return error number or 0 */
  5438. UNIV_INTERN
  5439. int
  5440. ha_innobase::update_row(
  5441. /*====================*/
  5442. const uchar* old_row, /*!< in: old row in MySQL format */
  5443. uchar* new_row) /*!< in: new row in MySQL format */
  5444. {
  5445. upd_t* uvect;
  5446. int error = 0;
  5447. trx_t* trx = thd_to_trx(user_thd);
  5448. DBUG_ENTER("ha_innobase::update_row");
  5449. ut_a(prebuilt->trx == trx);
  5450. if (upd_buf == NULL) {
  5451. ut_ad(upd_buf_size == 0);
  5452. /* Create a buffer for packing the fields of a record. Why
  5453. table->stored_rec_length did not work here? Obviously, because char
  5454. fields when packed actually became 1 byte longer, when we also
  5455. stored the string length as the first byte. */
  5456. upd_buf_size = table->s->stored_rec_length + table->s->max_key_length
  5457. + MAX_REF_PARTS * 3;
  5458. upd_buf = (uchar*) my_malloc(upd_buf_size, MYF(MY_WME));
  5459. if (upd_buf == NULL) {
  5460. upd_buf_size = 0;
  5461. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  5462. }
  5463. }
  5464. ha_statistic_increment(&SSV::ha_update_count);
  5465. if (share->ib_table->is_corrupt) {
  5466. DBUG_RETURN(HA_ERR_CRASHED);
  5467. }
  5468. if (prebuilt->upd_node) {
  5469. uvect = prebuilt->upd_node->update;
  5470. } else {
  5471. uvect = row_get_prebuilt_update_vector(prebuilt);
  5472. }
  5473. /* Build an update vector from the modified fields in the rows
  5474. (uses upd_buf of the handle) */
  5475. calc_row_difference(uvect, (uchar*) old_row, new_row, table,
  5476. upd_buf, upd_buf_size, prebuilt, user_thd);
  5477. /* This is not a delete */
  5478. prebuilt->upd_node->is_delete = FALSE;
  5479. ut_a(prebuilt->template_type == ROW_MYSQL_WHOLE_ROW);
  5480. innodb_srv_conc_enter_innodb(trx);
  5481. error = row_update_for_mysql((byte*) old_row, prebuilt);
  5482. /* We need to do some special AUTOINC handling for the following case:
  5483. INSERT INTO t (c1,c2) VALUES(x,y) ON DUPLICATE KEY UPDATE ...
  5484. We need to use the AUTOINC counter that was actually used by
  5485. MySQL in the UPDATE statement, which can be different from the
  5486. value used in the INSERT statement.*/
  5487. if (error == DB_SUCCESS
  5488. && table->next_number_field
  5489. && new_row == table->record[0]
  5490. && thd_sql_command(user_thd) == SQLCOM_INSERT
  5491. && trx->duplicates) {
  5492. ulonglong auto_inc;
  5493. ulonglong col_max_value;
  5494. auto_inc = table->next_number_field->val_int();
  5495. /* We need the upper limit of the col type to check for
  5496. whether we update the table autoinc counter or not. */
  5497. col_max_value = innobase_get_int_col_max_value(
  5498. table->next_number_field);
  5499. if (auto_inc <= col_max_value && auto_inc != 0) {
  5500. ulonglong offset;
  5501. ulonglong increment;
  5502. offset = prebuilt->autoinc_offset;
  5503. increment = prebuilt->autoinc_increment;
  5504. auto_inc = innobase_next_autoinc(
  5505. auto_inc, 1, increment, offset, col_max_value);
  5506. error = innobase_set_max_autoinc(auto_inc);
  5507. }
  5508. }
  5509. #ifdef EXTENDED_FOR_USERSTAT
  5510. if (error == DB_SUCCESS) rows_changed++;
  5511. #endif
  5512. innodb_srv_conc_exit_innodb(trx);
  5513. error = convert_error_code_to_mysql(error,
  5514. prebuilt->table->flags, user_thd);
  5515. if (error == 0 /* success */
  5516. && uvect->n_fields == 0 /* no columns were updated */) {
  5517. /* This is the same as success, but instructs
  5518. MySQL that the row is not really updated and it
  5519. should not increase the count of updated rows.
  5520. This is fix for http://bugs.mysql.com/29157 */
  5521. error = HA_ERR_RECORD_IS_THE_SAME;
  5522. }
  5523. /* Tell InnoDB server that there might be work for
  5524. utility threads: */
  5525. innobase_active_small();
  5526. if (share->ib_table->is_corrupt) {
  5527. DBUG_RETURN(HA_ERR_CRASHED);
  5528. }
  5529. DBUG_RETURN(error);
  5530. }
  5531. /**********************************************************************//**
  5532. Deletes a row given as the parameter.
  5533. @return error number or 0 */
  5534. UNIV_INTERN
  5535. int
  5536. ha_innobase::delete_row(
  5537. /*====================*/
  5538. const uchar* record) /*!< in: a row in MySQL format */
  5539. {
  5540. int error = 0;
  5541. trx_t* trx = thd_to_trx(user_thd);
  5542. DBUG_ENTER("ha_innobase::delete_row");
  5543. ut_a(prebuilt->trx == trx);
  5544. ha_statistic_increment(&SSV::ha_delete_count);
  5545. if (share->ib_table->is_corrupt) {
  5546. DBUG_RETURN(HA_ERR_CRASHED);
  5547. }
  5548. if (!prebuilt->upd_node) {
  5549. row_get_prebuilt_update_vector(prebuilt);
  5550. }
  5551. /* This is a delete */
  5552. prebuilt->upd_node->is_delete = TRUE;
  5553. innodb_srv_conc_enter_innodb(trx);
  5554. error = row_update_for_mysql((byte*) record, prebuilt);
  5555. #ifdef EXTENDED_FOR_USERSTAT
  5556. if (error == DB_SUCCESS) rows_changed++;
  5557. #endif
  5558. innodb_srv_conc_exit_innodb(trx);
  5559. error = convert_error_code_to_mysql(
  5560. error, prebuilt->table->flags, user_thd);
  5561. /* Tell the InnoDB server that there might be work for
  5562. utility threads: */
  5563. innobase_active_small();
  5564. if (share->ib_table->is_corrupt) {
  5565. DBUG_RETURN(HA_ERR_CRASHED);
  5566. }
  5567. DBUG_RETURN(error);
  5568. }
  5569. /**********************************************************************//**
  5570. Removes a new lock set on a row, if it was not read optimistically. This can
  5571. be called after a row has been read in the processing of an UPDATE or a DELETE
  5572. query, if the option innodb_locks_unsafe_for_binlog is set. */
  5573. UNIV_INTERN
  5574. void
  5575. ha_innobase::unlock_row(void)
  5576. /*=========================*/
  5577. {
  5578. DBUG_ENTER("ha_innobase::unlock_row");
  5579. /* Consistent read does not take any locks, thus there is
  5580. nothing to unlock. */
  5581. if (prebuilt->select_lock_type == LOCK_NONE) {
  5582. DBUG_VOID_RETURN;
  5583. }
  5584. switch (prebuilt->row_read_type) {
  5585. case ROW_READ_WITH_LOCKS:
  5586. if (!srv_locks_unsafe_for_binlog
  5587. && prebuilt->trx->isolation_level
  5588. > TRX_ISO_READ_COMMITTED) {
  5589. break;
  5590. }
  5591. /* fall through */
  5592. case ROW_READ_TRY_SEMI_CONSISTENT:
  5593. row_unlock_for_mysql(prebuilt, FALSE);
  5594. break;
  5595. case ROW_READ_DID_SEMI_CONSISTENT:
  5596. prebuilt->row_read_type = ROW_READ_TRY_SEMI_CONSISTENT;
  5597. break;
  5598. }
  5599. DBUG_VOID_RETURN;
  5600. }
  5601. /* See handler.h and row0mysql.h for docs on this function. */
  5602. UNIV_INTERN
  5603. bool
  5604. ha_innobase::was_semi_consistent_read(void)
  5605. /*=======================================*/
  5606. {
  5607. return(prebuilt->row_read_type == ROW_READ_DID_SEMI_CONSISTENT);
  5608. }
  5609. /* See handler.h and row0mysql.h for docs on this function. */
  5610. UNIV_INTERN
  5611. void
  5612. ha_innobase::try_semi_consistent_read(bool yes)
  5613. /*===========================================*/
  5614. {
  5615. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  5616. /* Row read type is set to semi consistent read if this was
  5617. requested by the MySQL and either innodb_locks_unsafe_for_binlog
  5618. option is used or this session is using READ COMMITTED isolation
  5619. level. */
  5620. if (yes
  5621. && (srv_locks_unsafe_for_binlog
  5622. || prebuilt->trx->isolation_level <= TRX_ISO_READ_COMMITTED)) {
  5623. prebuilt->row_read_type = ROW_READ_TRY_SEMI_CONSISTENT;
  5624. } else {
  5625. prebuilt->row_read_type = ROW_READ_WITH_LOCKS;
  5626. }
  5627. }
  5628. /******************************************************************//**
  5629. Initializes a handle to use an index.
  5630. @return 0 or error number */
  5631. UNIV_INTERN
  5632. int
  5633. ha_innobase::index_init(
  5634. /*====================*/
  5635. uint keynr, /*!< in: key (index) number */
  5636. bool sorted) /*!< in: 1 if result MUST be sorted according to index */
  5637. {
  5638. DBUG_ENTER("index_init");
  5639. DBUG_RETURN(change_active_index(keynr));
  5640. }
  5641. /******************************************************************//**
  5642. Currently does nothing.
  5643. @return 0 */
  5644. UNIV_INTERN
  5645. int
  5646. ha_innobase::index_end(void)
  5647. /*========================*/
  5648. {
  5649. int error = 0;
  5650. DBUG_ENTER("index_end");
  5651. active_index=MAX_KEY;
  5652. in_range_check_pushed_down= FALSE;
  5653. ds_mrr.dsmrr_close();
  5654. DBUG_RETURN(error);
  5655. }
  5656. /*********************************************************************//**
  5657. Converts a search mode flag understood by MySQL to a flag understood
  5658. by InnoDB. */
  5659. static inline
  5660. ulint
  5661. convert_search_mode_to_innobase(
  5662. /*============================*/
  5663. enum ha_rkey_function find_flag)
  5664. {
  5665. switch (find_flag) {
  5666. case HA_READ_KEY_EXACT:
  5667. /* this does not require the index to be UNIQUE */
  5668. return(PAGE_CUR_GE);
  5669. case HA_READ_KEY_OR_NEXT:
  5670. return(PAGE_CUR_GE);
  5671. case HA_READ_KEY_OR_PREV:
  5672. return(PAGE_CUR_LE);
  5673. case HA_READ_AFTER_KEY:
  5674. return(PAGE_CUR_G);
  5675. case HA_READ_BEFORE_KEY:
  5676. return(PAGE_CUR_L);
  5677. case HA_READ_PREFIX:
  5678. return(PAGE_CUR_GE);
  5679. case HA_READ_PREFIX_LAST:
  5680. return(PAGE_CUR_LE);
  5681. case HA_READ_PREFIX_LAST_OR_PREV:
  5682. return(PAGE_CUR_LE);
  5683. /* In MySQL-4.0 HA_READ_PREFIX and HA_READ_PREFIX_LAST always
  5684. pass a complete-field prefix of a key value as the search
  5685. tuple. I.e., it is not allowed that the last field would
  5686. just contain n first bytes of the full field value.
  5687. MySQL uses a 'padding' trick to convert LIKE 'abc%'
  5688. type queries so that it can use as a search tuple
  5689. a complete-field-prefix of a key value. Thus, the InnoDB
  5690. search mode PAGE_CUR_LE_OR_EXTENDS is never used.
  5691. TODO: when/if MySQL starts to use also partial-field
  5692. prefixes, we have to deal with stripping of spaces
  5693. and comparison of non-latin1 char type fields in
  5694. innobase_mysql_cmp() to get PAGE_CUR_LE_OR_EXTENDS to
  5695. work correctly. */
  5696. case HA_READ_MBR_CONTAIN:
  5697. case HA_READ_MBR_INTERSECT:
  5698. case HA_READ_MBR_WITHIN:
  5699. case HA_READ_MBR_DISJOINT:
  5700. case HA_READ_MBR_EQUAL:
  5701. return(PAGE_CUR_UNSUPP);
  5702. /* do not use "default:" in order to produce a gcc warning:
  5703. enumeration value '...' not handled in switch
  5704. (if -Wswitch or -Wall is used) */
  5705. }
  5706. my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "this functionality");
  5707. return(PAGE_CUR_UNSUPP);
  5708. }
  5709. /*
  5710. BACKGROUND INFO: HOW A SELECT SQL QUERY IS EXECUTED
  5711. ---------------------------------------------------
  5712. The following does not cover all the details, but explains how we determine
  5713. the start of a new SQL statement, and what is associated with it.
  5714. For each table in the database the MySQL interpreter may have several
  5715. table handle instances in use, also in a single SQL query. For each table
  5716. handle instance there is an InnoDB 'prebuilt' struct which contains most
  5717. of the InnoDB data associated with this table handle instance.
  5718. A) if the user has not explicitly set any MySQL table level locks:
  5719. 1) MySQL calls ::external_lock to set an 'intention' table level lock on
  5720. the table of the handle instance. There we set
  5721. prebuilt->sql_stat_start = TRUE. The flag sql_stat_start should be set
  5722. true if we are taking this table handle instance to use in a new SQL
  5723. statement issued by the user. We also increment trx->n_mysql_tables_in_use.
  5724. 2) If prebuilt->sql_stat_start == TRUE we 'pre-compile' the MySQL search
  5725. instructions to prebuilt->template of the table handle instance in
  5726. ::index_read. The template is used to save CPU time in large joins.
  5727. 3) In row_search_for_mysql, if prebuilt->sql_stat_start is true, we
  5728. allocate a new consistent read view for the trx if it does not yet have one,
  5729. or in the case of a locking read, set an InnoDB 'intention' table level
  5730. lock on the table.
  5731. 4) We do the SELECT. MySQL may repeatedly call ::index_read for the
  5732. same table handle instance, if it is a join.
  5733. 5) When the SELECT ends, MySQL removes its intention table level locks
  5734. in ::external_lock. When trx->n_mysql_tables_in_use drops to zero,
  5735. (a) we execute a COMMIT there if the autocommit is on,
  5736. (b) we also release possible 'SQL statement level resources' InnoDB may
  5737. have for this SQL statement. The MySQL interpreter does NOT execute
  5738. autocommit for pure read transactions, though it should. That is why the
  5739. table handler in that case has to execute the COMMIT in ::external_lock.
  5740. B) If the user has explicitly set MySQL table level locks, then MySQL
  5741. does NOT call ::external_lock at the start of the statement. To determine
  5742. when we are at the start of a new SQL statement we at the start of
  5743. ::index_read also compare the query id to the latest query id where the
  5744. table handle instance was used. If it has changed, we know we are at the
  5745. start of a new SQL statement. Since the query id can theoretically
  5746. overwrap, we use this test only as a secondary way of determining the
  5747. start of a new SQL statement. */
  5748. /**********************************************************************//**
  5749. Positions an index cursor to the index specified in the handle. Fetches the
  5750. row if any.
  5751. @return 0, HA_ERR_KEY_NOT_FOUND, or error number */
  5752. UNIV_INTERN
  5753. int
  5754. ha_innobase::index_read(
  5755. /*====================*/
  5756. uchar* buf, /*!< in/out: buffer for the returned
  5757. row */
  5758. const uchar* key_ptr, /*!< in: key value; if this is NULL
  5759. we position the cursor at the
  5760. start or end of index; this can
  5761. also contain an InnoDB row id, in
  5762. which case key_len is the InnoDB
  5763. row id length; the key value can
  5764. also be a prefix of a full key value,
  5765. and the last column can be a prefix
  5766. of a full column */
  5767. uint key_len,/*!< in: key value length */
  5768. enum ha_rkey_function find_flag)/*!< in: search flags from my_base.h */
  5769. {
  5770. ulint mode;
  5771. dict_index_t* index;
  5772. ulint match_mode = 0;
  5773. int error;
  5774. ulint ret;
  5775. DBUG_ENTER("index_read");
  5776. DEBUG_SYNC_C("ha_innobase_index_read_begin");
  5777. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  5778. ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT);
  5779. ha_statistic_increment(&SSV::ha_read_key_count);
  5780. if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) {
  5781. DBUG_RETURN(HA_ERR_CRASHED);
  5782. }
  5783. index = prebuilt->index;
  5784. if (UNIV_UNLIKELY(index == NULL) || dict_index_is_corrupted(index)) {
  5785. prebuilt->index_usable = FALSE;
  5786. DBUG_RETURN(HA_ERR_CRASHED);
  5787. }
  5788. if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
  5789. DBUG_RETURN(dict_index_is_corrupted(index)
  5790. ? HA_ERR_INDEX_CORRUPT
  5791. : HA_ERR_TABLE_DEF_CHANGED);
  5792. }
  5793. /* Note that if the index for which the search template is built is not
  5794. necessarily prebuilt->index, but can also be the clustered index */
  5795. if (prebuilt->sql_stat_start) {
  5796. build_template(false);
  5797. }
  5798. if (key_ptr) {
  5799. /* Convert the search key value to InnoDB format into
  5800. prebuilt->search_tuple */
  5801. row_sel_convert_mysql_key_to_innobase(
  5802. prebuilt->search_tuple,
  5803. srch_key_val1, sizeof(srch_key_val1),
  5804. index,
  5805. (byte*) key_ptr,
  5806. (ulint) key_len,
  5807. prebuilt->trx);
  5808. DBUG_ASSERT(prebuilt->search_tuple->n_fields > 0);
  5809. } else {
  5810. /* We position the cursor to the last or the first entry
  5811. in the index */
  5812. dtuple_set_n_fields(prebuilt->search_tuple, 0);
  5813. }
  5814. mode = convert_search_mode_to_innobase(find_flag);
  5815. match_mode = 0;
  5816. if (find_flag == HA_READ_KEY_EXACT) {
  5817. match_mode = ROW_SEL_EXACT;
  5818. } else if (find_flag == HA_READ_PREFIX
  5819. || find_flag == HA_READ_PREFIX_LAST) {
  5820. match_mode = ROW_SEL_EXACT_PREFIX;
  5821. }
  5822. last_match_mode = (uint) match_mode;
  5823. if (mode != PAGE_CUR_UNSUPP) {
  5824. innodb_srv_conc_enter_innodb(prebuilt->trx);
  5825. ret = row_search_for_mysql((byte*) buf, mode, prebuilt,
  5826. match_mode, 0);
  5827. innodb_srv_conc_exit_innodb(prebuilt->trx);
  5828. } else {
  5829. ret = DB_UNSUPPORTED;
  5830. }
  5831. if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) {
  5832. DBUG_RETURN(HA_ERR_CRASHED);
  5833. }
  5834. switch (ret) {
  5835. case DB_SUCCESS:
  5836. error = 0;
  5837. table->status = 0;
  5838. #ifdef EXTENDED_FOR_USERSTAT
  5839. rows_read++;
  5840. if (active_index < MAX_KEY)
  5841. index_rows_read[active_index]++;
  5842. #endif
  5843. break;
  5844. case DB_RECORD_NOT_FOUND:
  5845. error = HA_ERR_KEY_NOT_FOUND;
  5846. table->status = STATUS_NOT_FOUND;
  5847. break;
  5848. case DB_END_OF_INDEX:
  5849. error = HA_ERR_KEY_NOT_FOUND;
  5850. table->status = STATUS_NOT_FOUND;
  5851. break;
  5852. default:
  5853. error = convert_error_code_to_mysql((int) ret,
  5854. prebuilt->table->flags,
  5855. user_thd);
  5856. table->status = STATUS_NOT_FOUND;
  5857. break;
  5858. }
  5859. DBUG_RETURN(error);
  5860. }
  5861. /*******************************************************************//**
  5862. The following functions works like index_read, but it find the last
  5863. row with the current key value or prefix.
  5864. @return 0, HA_ERR_KEY_NOT_FOUND, or an error code */
  5865. UNIV_INTERN
  5866. int
  5867. ha_innobase::index_read_last(
  5868. /*=========================*/
  5869. uchar* buf, /*!< out: fetched row */
  5870. const uchar* key_ptr,/*!< in: key value, or a prefix of a full
  5871. key value */
  5872. uint key_len)/*!< in: length of the key val or prefix
  5873. in bytes */
  5874. {
  5875. return(index_read(buf, key_ptr, key_len, HA_READ_PREFIX_LAST));
  5876. }
  5877. /********************************************************************//**
  5878. Get the index for a handle. Does not change active index.
  5879. @return NULL or index instance. */
  5880. UNIV_INTERN
  5881. dict_index_t*
  5882. ha_innobase::innobase_get_index(
  5883. /*============================*/
  5884. uint keynr) /*!< in: use this index; MAX_KEY means always
  5885. clustered index, even if it was internally
  5886. generated by InnoDB */
  5887. {
  5888. KEY* key = 0;
  5889. dict_index_t* index = 0;
  5890. DBUG_ENTER("innobase_get_index");
  5891. if (keynr != MAX_KEY && table->s->keys > 0) {
  5892. key = table->key_info + keynr;
  5893. index = innobase_index_lookup(share, keynr);
  5894. if (index) {
  5895. ut_a(ut_strcmp(index->name, key->name) == 0);
  5896. } else {
  5897. /* Can't find index with keynr in the translation
  5898. table. Only print message if the index translation
  5899. table exists */
  5900. if (share->idx_trans_tbl.index_mapping) {
  5901. sql_print_warning("InnoDB could not find "
  5902. "index %s key no %u for "
  5903. "table %s through its "
  5904. "index translation table",
  5905. key ? key->name : "NULL",
  5906. keynr,
  5907. prebuilt->table->name);
  5908. }
  5909. index = dict_table_get_index_on_name(prebuilt->table,
  5910. key->name);
  5911. }
  5912. } else {
  5913. index = dict_table_get_first_index(prebuilt->table);
  5914. }
  5915. if (!index) {
  5916. sql_print_error(
  5917. "Innodb could not find key n:o %u with name %s "
  5918. "from dict cache for table %s",
  5919. keynr, key ? key->name : "NULL",
  5920. prebuilt->table->name);
  5921. }
  5922. DBUG_RETURN(index);
  5923. }
  5924. /********************************************************************//**
  5925. Changes the active index of a handle.
  5926. @return 0 or error code */
  5927. UNIV_INTERN
  5928. int
  5929. ha_innobase::change_active_index(
  5930. /*=============================*/
  5931. uint keynr) /*!< in: use this index; MAX_KEY means always clustered
  5932. index, even if it was internally generated by
  5933. InnoDB */
  5934. {
  5935. DBUG_ENTER("change_active_index");
  5936. if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) {
  5937. DBUG_RETURN(HA_ERR_CRASHED);
  5938. }
  5939. ut_ad(user_thd == ha_thd());
  5940. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  5941. active_index = keynr;
  5942. prebuilt->index = innobase_get_index(keynr);
  5943. if (UNIV_UNLIKELY(!prebuilt->index)) {
  5944. sql_print_warning("InnoDB: change_active_index(%u) failed",
  5945. keynr);
  5946. prebuilt->index_usable = FALSE;
  5947. DBUG_RETURN(1);
  5948. }
  5949. prebuilt->index_usable = row_merge_is_index_usable(prebuilt->trx,
  5950. prebuilt->index);
  5951. if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
  5952. if (dict_index_is_corrupted(prebuilt->index)) {
  5953. char index_name[MAX_FULL_NAME_LEN + 1];
  5954. char table_name[MAX_FULL_NAME_LEN + 1];
  5955. innobase_format_name(
  5956. index_name, sizeof index_name,
  5957. prebuilt->index->name, TRUE);
  5958. innobase_format_name(
  5959. table_name, sizeof table_name,
  5960. prebuilt->index->table->name, FALSE);
  5961. push_warning_printf(
  5962. user_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  5963. HA_ERR_INDEX_CORRUPT,
  5964. "InnoDB: Index %s for table %s is"
  5965. " marked as corrupted",
  5966. index_name, table_name);
  5967. DBUG_RETURN(HA_ERR_INDEX_CORRUPT);
  5968. } else {
  5969. push_warning_printf(
  5970. user_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  5971. HA_ERR_TABLE_DEF_CHANGED,
  5972. "InnoDB: insufficient history for index %u",
  5973. keynr);
  5974. }
  5975. /* The caller seems to ignore this. Thus, we must check
  5976. this again in row_search_for_mysql(). */
  5977. DBUG_RETURN(convert_error_code_to_mysql(DB_MISSING_HISTORY,
  5978. 0, NULL));
  5979. }
  5980. ut_a(prebuilt->search_tuple != 0);
  5981. dtuple_set_n_fields(prebuilt->search_tuple, prebuilt->index->n_fields);
  5982. dict_index_copy_types(prebuilt->search_tuple, prebuilt->index,
  5983. prebuilt->index->n_fields);
  5984. /* MySQL changes the active index for a handle also during some
  5985. queries, for example SELECT MAX(a), SUM(a) first retrieves the MAX()
  5986. and then calculates the sum. Previously we played safe and used
  5987. the flag ROW_MYSQL_WHOLE_ROW below, but that caused unnecessary
  5988. copying. Starting from MySQL-4.1 we use a more efficient flag here. */
  5989. build_template(false);
  5990. DBUG_RETURN(0);
  5991. }
  5992. /**********************************************************************//**
  5993. Positions an index cursor to the index specified in keynr. Fetches the
  5994. row if any.
  5995. ??? This is only used to read whole keys ???
  5996. @return error number or 0 */
  5997. UNIV_INTERN
  5998. int
  5999. ha_innobase::index_read_idx(
  6000. /*========================*/
  6001. uchar* buf, /*!< in/out: buffer for the returned
  6002. row */
  6003. uint keynr, /*!< in: use this index */
  6004. const uchar* key, /*!< in: key value; if this is NULL
  6005. we position the cursor at the
  6006. start or end of index */
  6007. uint key_len, /*!< in: key value length */
  6008. enum ha_rkey_function find_flag)/*!< in: search flags from my_base.h */
  6009. {
  6010. if (change_active_index(keynr)) {
  6011. return(1);
  6012. }
  6013. return(index_read(buf, key, key_len, find_flag));
  6014. }
  6015. /***********************************************************************//**
  6016. Reads the next or previous row from a cursor, which must have previously been
  6017. positioned using index_read.
  6018. @return 0, HA_ERR_END_OF_FILE, or error number */
  6019. UNIV_INTERN
  6020. int
  6021. ha_innobase::general_fetch(
  6022. /*=======================*/
  6023. uchar* buf, /*!< in/out: buffer for next row in MySQL
  6024. format */
  6025. uint direction, /*!< in: ROW_SEL_NEXT or ROW_SEL_PREV */
  6026. uint match_mode) /*!< in: 0, ROW_SEL_EXACT, or
  6027. ROW_SEL_EXACT_PREFIX */
  6028. {
  6029. ulint ret;
  6030. int error = 0;
  6031. DBUG_ENTER("general_fetch");
  6032. if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) {
  6033. DBUG_RETURN(HA_ERR_CRASHED);
  6034. }
  6035. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  6036. innodb_srv_conc_enter_innodb(prebuilt->trx);
  6037. ret = row_search_for_mysql(
  6038. (byte*)buf, 0, prebuilt, match_mode, direction);
  6039. innodb_srv_conc_exit_innodb(prebuilt->trx);
  6040. if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) {
  6041. DBUG_RETURN(HA_ERR_CRASHED);
  6042. }
  6043. switch (ret) {
  6044. case DB_SUCCESS:
  6045. error = 0;
  6046. table->status = 0;
  6047. #ifdef EXTENDED_FOR_USERSTAT
  6048. rows_read++;
  6049. if (active_index < MAX_KEY)
  6050. index_rows_read[active_index]++;
  6051. #endif
  6052. break;
  6053. case DB_RECORD_NOT_FOUND:
  6054. error = HA_ERR_END_OF_FILE;
  6055. table->status = STATUS_NOT_FOUND;
  6056. break;
  6057. case DB_END_OF_INDEX:
  6058. error = HA_ERR_END_OF_FILE;
  6059. table->status = STATUS_NOT_FOUND;
  6060. break;
  6061. default:
  6062. error = convert_error_code_to_mysql(
  6063. (int) ret, prebuilt->table->flags, user_thd);
  6064. table->status = STATUS_NOT_FOUND;
  6065. break;
  6066. }
  6067. DBUG_RETURN(error);
  6068. }
  6069. /***********************************************************************//**
  6070. Reads the next row from a cursor, which must have previously been
  6071. positioned using index_read.
  6072. @return 0, HA_ERR_END_OF_FILE, or error number */
  6073. UNIV_INTERN
  6074. int
  6075. ha_innobase::index_next(
  6076. /*====================*/
  6077. uchar* buf) /*!< in/out: buffer for next row in MySQL
  6078. format */
  6079. {
  6080. ha_statistic_increment(&SSV::ha_read_next_count);
  6081. return(general_fetch(buf, ROW_SEL_NEXT, 0));
  6082. }
  6083. /*******************************************************************//**
  6084. Reads the next row matching to the key value given as the parameter.
  6085. @return 0, HA_ERR_END_OF_FILE, or error number */
  6086. UNIV_INTERN
  6087. int
  6088. ha_innobase::index_next_same(
  6089. /*=========================*/
  6090. uchar* buf, /*!< in/out: buffer for the row */
  6091. const uchar* key, /*!< in: key value */
  6092. uint keylen) /*!< in: key value length */
  6093. {
  6094. ha_statistic_increment(&SSV::ha_read_next_count);
  6095. return(general_fetch(buf, ROW_SEL_NEXT, last_match_mode));
  6096. }
  6097. /***********************************************************************//**
  6098. Reads the previous row from a cursor, which must have previously been
  6099. positioned using index_read.
  6100. @return 0, HA_ERR_END_OF_FILE, or error number */
  6101. UNIV_INTERN
  6102. int
  6103. ha_innobase::index_prev(
  6104. /*====================*/
  6105. uchar* buf) /*!< in/out: buffer for previous row in MySQL format */
  6106. {
  6107. ha_statistic_increment(&SSV::ha_read_prev_count);
  6108. return(general_fetch(buf, ROW_SEL_PREV, 0));
  6109. }
  6110. /********************************************************************//**
  6111. Positions a cursor on the first record in an index and reads the
  6112. corresponding row to buf.
  6113. @return 0, HA_ERR_END_OF_FILE, or error code */
  6114. UNIV_INTERN
  6115. int
  6116. ha_innobase::index_first(
  6117. /*=====================*/
  6118. uchar* buf) /*!< in/out: buffer for the row */
  6119. {
  6120. int error;
  6121. DBUG_ENTER("index_first");
  6122. ha_statistic_increment(&SSV::ha_read_first_count);
  6123. error = index_read(buf, NULL, 0, HA_READ_AFTER_KEY);
  6124. /* MySQL does not seem to allow this to return HA_ERR_KEY_NOT_FOUND */
  6125. if (error == HA_ERR_KEY_NOT_FOUND) {
  6126. error = HA_ERR_END_OF_FILE;
  6127. }
  6128. DBUG_RETURN(error);
  6129. }
  6130. /********************************************************************//**
  6131. Positions a cursor on the last record in an index and reads the
  6132. corresponding row to buf.
  6133. @return 0, HA_ERR_END_OF_FILE, or error code */
  6134. UNIV_INTERN
  6135. int
  6136. ha_innobase::index_last(
  6137. /*====================*/
  6138. uchar* buf) /*!< in/out: buffer for the row */
  6139. {
  6140. int error;
  6141. DBUG_ENTER("index_last");
  6142. ha_statistic_increment(&SSV::ha_read_last_count);
  6143. error = index_read(buf, NULL, 0, HA_READ_BEFORE_KEY);
  6144. /* MySQL does not seem to allow this to return HA_ERR_KEY_NOT_FOUND */
  6145. if (error == HA_ERR_KEY_NOT_FOUND) {
  6146. error = HA_ERR_END_OF_FILE;
  6147. }
  6148. DBUG_RETURN(error);
  6149. }
  6150. /****************************************************************//**
  6151. Initialize a table scan.
  6152. @return 0 or error number */
  6153. UNIV_INTERN
  6154. int
  6155. ha_innobase::rnd_init(
  6156. /*==================*/
  6157. bool scan) /*!< in: TRUE if table/index scan FALSE otherwise */
  6158. {
  6159. int err;
  6160. /* Store the active index value so that we can restore the original
  6161. value after a scan */
  6162. if (prebuilt->clust_index_was_generated) {
  6163. err = change_active_index(MAX_KEY);
  6164. } else {
  6165. err = change_active_index(primary_key);
  6166. }
  6167. /* Don't use semi-consistent read in random row reads (by position).
  6168. This means we must disable semi_consistent_read if scan is false */
  6169. if (!scan) {
  6170. try_semi_consistent_read(0);
  6171. }
  6172. start_of_scan = 1;
  6173. return(err);
  6174. }
  6175. /*****************************************************************//**
  6176. Ends a table scan.
  6177. @return 0 or error number */
  6178. UNIV_INTERN
  6179. int
  6180. ha_innobase::rnd_end(void)
  6181. /*======================*/
  6182. {
  6183. return(index_end());
  6184. }
  6185. /*****************************************************************//**
  6186. Reads the next row in a table scan (also used to read the FIRST row
  6187. in a table scan).
  6188. @return 0, HA_ERR_END_OF_FILE, or error number */
  6189. UNIV_INTERN
  6190. int
  6191. ha_innobase::rnd_next(
  6192. /*==================*/
  6193. uchar* buf) /*!< in/out: returns the row in this buffer,
  6194. in MySQL format */
  6195. {
  6196. int error;
  6197. DBUG_ENTER("rnd_next");
  6198. ha_statistic_increment(&SSV::ha_read_rnd_next_count);
  6199. if (start_of_scan) {
  6200. error = index_first(buf);
  6201. if (error == HA_ERR_KEY_NOT_FOUND) {
  6202. error = HA_ERR_END_OF_FILE;
  6203. }
  6204. start_of_scan = 0;
  6205. } else {
  6206. error = general_fetch(buf, ROW_SEL_NEXT, 0);
  6207. }
  6208. DBUG_RETURN(error);
  6209. }
  6210. /**********************************************************************//**
  6211. Fetches a row from the table based on a row reference.
  6212. @return 0, HA_ERR_KEY_NOT_FOUND, or error code */
  6213. UNIV_INTERN
  6214. int
  6215. ha_innobase::rnd_pos(
  6216. /*=================*/
  6217. uchar* buf, /*!< in/out: buffer for the row */
  6218. uchar* pos) /*!< in: primary key value of the row in the
  6219. MySQL format, or the row id if the clustered
  6220. index was internally generated by InnoDB; the
  6221. length of data in pos has to be ref_length */
  6222. {
  6223. int error;
  6224. uint keynr = active_index;
  6225. DBUG_ENTER("rnd_pos");
  6226. DBUG_DUMP("key", pos, ref_length);
  6227. ha_statistic_increment(&SSV::ha_read_rnd_count);
  6228. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  6229. if (prebuilt->clust_index_was_generated) {
  6230. /* No primary key was defined for the table and we
  6231. generated the clustered index from the row id: the
  6232. row reference is the row id, not any key value
  6233. that MySQL knows of */
  6234. error = change_active_index(MAX_KEY);
  6235. } else {
  6236. error = change_active_index(primary_key);
  6237. }
  6238. if (error) {
  6239. DBUG_PRINT("error", ("Got error: %d", error));
  6240. DBUG_RETURN(error);
  6241. }
  6242. /* Note that we assume the length of the row reference is fixed
  6243. for the table, and it is == ref_length */
  6244. error = index_read(buf, pos, ref_length, HA_READ_KEY_EXACT);
  6245. if (error) {
  6246. DBUG_PRINT("error", ("Got error: %d", error));
  6247. }
  6248. change_active_index(keynr);
  6249. DBUG_RETURN(error);
  6250. }
  6251. /*********************************************************************//**
  6252. Stores a reference to the current row to 'ref' field of the handle. Note
  6253. that in the case where we have generated the clustered index for the
  6254. table, the function parameter is illogical: we MUST ASSUME that 'record'
  6255. is the current 'position' of the handle, because if row ref is actually
  6256. the row id internally generated in InnoDB, then 'record' does not contain
  6257. it. We just guess that the row id must be for the record where the handle
  6258. was positioned the last time. */
  6259. UNIV_INTERN
  6260. void
  6261. ha_innobase::position(
  6262. /*==================*/
  6263. const uchar* record) /*!< in: row in MySQL format */
  6264. {
  6265. uint len;
  6266. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  6267. if (prebuilt->clust_index_was_generated) {
  6268. /* No primary key was defined for the table and we
  6269. generated the clustered index from row id: the
  6270. row reference will be the row id, not any key value
  6271. that MySQL knows of */
  6272. len = DATA_ROW_ID_LEN;
  6273. memcpy(ref, prebuilt->row_id, len);
  6274. } else {
  6275. len = store_key_val_for_row(primary_key, (char*)ref,
  6276. ref_length, record);
  6277. }
  6278. /* We assume that the 'ref' value len is always fixed for the same
  6279. table. */
  6280. if (len != ref_length) {
  6281. sql_print_error("Stored ref len is %lu, but table ref len is %lu",
  6282. (ulong) len, (ulong) ref_length);
  6283. }
  6284. }
  6285. /* limit innodb monitor access to users with PROCESS privilege.
  6286. See http://bugs.mysql.com/32710 for expl. why we choose PROCESS. */
  6287. #define IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(table_name, thd) \
  6288. (row_is_magic_monitor_table(table_name) \
  6289. && check_global_access(thd, PROCESS_ACL))
  6290. /*****************************************************************//**
  6291. Creates a table definition to an InnoDB database. */
  6292. static
  6293. int
  6294. create_table_def(
  6295. /*=============*/
  6296. trx_t* trx, /*!< in: InnoDB transaction handle */
  6297. TABLE* form, /*!< in: information on table
  6298. columns and indexes */
  6299. const char* table_name, /*!< in: table name */
  6300. const char* path_of_temp_table,/*!< in: if this is a table explicitly
  6301. created by the user with the
  6302. TEMPORARY keyword, then this
  6303. parameter is the dir path where the
  6304. table should be placed if we create
  6305. an .ibd file for it (no .ibd extension
  6306. in the path, though); otherwise this
  6307. is NULL */
  6308. ulint flags) /*!< in: table flags */
  6309. {
  6310. Field* field;
  6311. dict_table_t* table;
  6312. ulint n_cols;
  6313. int error;
  6314. ulint col_type;
  6315. ulint col_len;
  6316. ulint nulls_allowed;
  6317. ulint unsigned_type;
  6318. ulint binary_type;
  6319. ulint long_true_varchar;
  6320. ulint charset_no;
  6321. ulint i;
  6322. DBUG_ENTER("create_table_def");
  6323. DBUG_PRINT("enter", ("table_name: %s", table_name));
  6324. ut_a(trx->mysql_thd != NULL);
  6325. /* MySQL does the name length check. But we do additional check
  6326. on the name length here */
  6327. if (strlen(table_name) > MAX_FULL_NAME_LEN) {
  6328. push_warning_printf(
  6329. (THD*) trx->mysql_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6330. ER_TABLE_NAME,
  6331. "InnoDB: Table Name or Database Name is too long");
  6332. DBUG_RETURN(ER_TABLE_NAME);
  6333. }
  6334. n_cols = form->s->fields;
  6335. /* We pass 0 as the space id, and determine at a lower level the space
  6336. id where to store the table */
  6337. table = dict_mem_table_create(table_name, 0, form->s->stored_fields, flags);
  6338. if (path_of_temp_table) {
  6339. table->dir_path_of_temp_table =
  6340. mem_heap_strdup(table->heap, path_of_temp_table);
  6341. }
  6342. for (i = 0; i < n_cols; i++) {
  6343. field = form->field[i];
  6344. if (!field->stored_in_db)
  6345. continue;
  6346. col_type = get_innobase_type_from_mysql_type(&unsigned_type,
  6347. field);
  6348. if (!col_type) {
  6349. push_warning_printf(
  6350. (THD*) trx->mysql_thd,
  6351. MYSQL_ERROR::WARN_LEVEL_WARN,
  6352. ER_CANT_CREATE_TABLE,
  6353. "Error creating table '%s' with "
  6354. "column '%s'. Please check its "
  6355. "column type and try to re-create "
  6356. "the table with an appropriate "
  6357. "column type.",
  6358. table->name, (char*) field->field_name);
  6359. goto err_col;
  6360. }
  6361. if (field->null_ptr) {
  6362. nulls_allowed = 0;
  6363. } else {
  6364. nulls_allowed = DATA_NOT_NULL;
  6365. }
  6366. if (field->binary()) {
  6367. binary_type = DATA_BINARY_TYPE;
  6368. } else {
  6369. binary_type = 0;
  6370. }
  6371. charset_no = 0;
  6372. if (dtype_is_string_type(col_type)) {
  6373. charset_no = (ulint)field->charset()->number;
  6374. if (UNIV_UNLIKELY(charset_no >= 256)) {
  6375. /* in data0type.h we assume that the
  6376. number fits in one byte in prtype */
  6377. push_warning_printf(
  6378. (THD*) trx->mysql_thd,
  6379. MYSQL_ERROR::WARN_LEVEL_WARN,
  6380. ER_CANT_CREATE_TABLE,
  6381. "In InnoDB, charset-collation codes"
  6382. " must be below 256."
  6383. " Unsupported code %lu.",
  6384. (ulong) charset_no);
  6385. DBUG_RETURN(ER_CANT_CREATE_TABLE);
  6386. }
  6387. }
  6388. ut_a(field->type() < 256); /* we assume in dtype_form_prtype()
  6389. that this fits in one byte */
  6390. col_len = field->pack_length();
  6391. /* The MySQL pack length contains 1 or 2 bytes length field
  6392. for a true VARCHAR. Let us subtract that, so that the InnoDB
  6393. column length in the InnoDB data dictionary is the real
  6394. maximum byte length of the actual data. */
  6395. long_true_varchar = 0;
  6396. if (field->type() == MYSQL_TYPE_VARCHAR) {
  6397. col_len -= ((Field_varstring*)field)->length_bytes;
  6398. if (((Field_varstring*)field)->length_bytes == 2) {
  6399. long_true_varchar = DATA_LONG_TRUE_VARCHAR;
  6400. }
  6401. }
  6402. /* First check whether the column to be added has a
  6403. system reserved name. */
  6404. if (dict_col_name_is_reserved(field->field_name)){
  6405. my_error(ER_WRONG_COLUMN_NAME, MYF(0),
  6406. field->field_name);
  6407. err_col:
  6408. dict_mem_table_free(table);
  6409. trx_commit_for_mysql(trx);
  6410. error = DB_ERROR;
  6411. goto error_ret;
  6412. }
  6413. dict_mem_table_add_col(table, table->heap,
  6414. (char*) field->field_name,
  6415. col_type,
  6416. dtype_form_prtype(
  6417. (ulint)field->type()
  6418. | nulls_allowed | unsigned_type
  6419. | binary_type | long_true_varchar,
  6420. charset_no),
  6421. col_len);
  6422. }
  6423. error = row_create_table_for_mysql(table, trx);
  6424. if (error == DB_DUPLICATE_KEY) {
  6425. char buf[100];
  6426. char* buf_end = innobase_convert_identifier(
  6427. buf, sizeof buf - 1, table_name, strlen(table_name),
  6428. trx->mysql_thd, TRUE);
  6429. *buf_end = '\0';
  6430. my_error(ER_TABLE_EXISTS_ERROR, MYF(0), buf);
  6431. }
  6432. error_ret:
  6433. error = convert_error_code_to_mysql(error, flags, NULL);
  6434. DBUG_RETURN(error);
  6435. }
  6436. /*****************************************************************//**
  6437. Creates an index in an InnoDB database. */
  6438. static
  6439. int
  6440. create_index(
  6441. /*=========*/
  6442. trx_t* trx, /*!< in: InnoDB transaction handle */
  6443. TABLE* form, /*!< in: information on table
  6444. columns and indexes */
  6445. ulint flags, /*!< in: InnoDB table flags */
  6446. const char* table_name, /*!< in: table name */
  6447. uint key_num) /*!< in: index number */
  6448. {
  6449. Field* field;
  6450. dict_index_t* index;
  6451. int error;
  6452. ulint n_fields;
  6453. KEY* key;
  6454. KEY_PART_INFO* key_part;
  6455. ulint ind_type;
  6456. ulint col_type;
  6457. ulint prefix_len;
  6458. ulint is_unsigned;
  6459. ulint i;
  6460. ulint j;
  6461. ulint* field_lengths;
  6462. DBUG_ENTER("create_index");
  6463. key = form->key_info + key_num;
  6464. n_fields = key->key_parts;
  6465. /* Assert that "GEN_CLUST_INDEX" cannot be used as non-primary index */
  6466. ut_a(innobase_strcasecmp(key->name, innobase_index_reserve_name) != 0);
  6467. ind_type = 0;
  6468. if (key_num == form->s->primary_key) {
  6469. ind_type = ind_type | DICT_CLUSTERED;
  6470. }
  6471. if (key->flags & HA_NOSAME ) {
  6472. ind_type = ind_type | DICT_UNIQUE;
  6473. }
  6474. /* We pass 0 as the space id, and determine at a lower level the space
  6475. id where to store the table */
  6476. index = dict_mem_index_create(table_name, key->name, 0,
  6477. ind_type, n_fields);
  6478. field_lengths = (ulint*) my_malloc(sizeof(ulint) * n_fields,
  6479. MYF(MY_FAE));
  6480. for (i = 0; i < n_fields; i++) {
  6481. key_part = key->key_part + i;
  6482. /* (The flag HA_PART_KEY_SEG denotes in MySQL a column prefix
  6483. field in an index: we only store a specified number of first
  6484. bytes of the column to the index field.) The flag does not
  6485. seem to be properly set by MySQL. Let us fall back on testing
  6486. the length of the key part versus the column. */
  6487. field = NULL;
  6488. for (j = 0; j < form->s->fields; j++) {
  6489. field = form->field[j];
  6490. if (0 == innobase_strcasecmp(
  6491. field->field_name,
  6492. key_part->field->field_name)) {
  6493. /* Found the corresponding column */
  6494. break;
  6495. }
  6496. }
  6497. ut_a(j < form->s->fields);
  6498. col_type = get_innobase_type_from_mysql_type(
  6499. &is_unsigned, key_part->field);
  6500. if (DATA_BLOB == col_type
  6501. || (key_part->length < field->pack_length()
  6502. && field->type() != MYSQL_TYPE_VARCHAR)
  6503. || (field->type() == MYSQL_TYPE_VARCHAR
  6504. && key_part->length < field->pack_length()
  6505. - ((Field_varstring*)field)->length_bytes)) {
  6506. prefix_len = key_part->length;
  6507. if (col_type == DATA_INT
  6508. || col_type == DATA_FLOAT
  6509. || col_type == DATA_DOUBLE
  6510. || col_type == DATA_DECIMAL) {
  6511. sql_print_error(
  6512. "MySQL is trying to create a column "
  6513. "prefix index field, on an "
  6514. "inappropriate data type. Table "
  6515. "name %s, column name %s.",
  6516. table_name,
  6517. key_part->field->field_name);
  6518. prefix_len = 0;
  6519. }
  6520. } else {
  6521. prefix_len = 0;
  6522. }
  6523. field_lengths[i] = key_part->length;
  6524. dict_mem_index_add_field(index,
  6525. (char*) key_part->field->field_name, prefix_len);
  6526. }
  6527. /* Even though we've defined max_supported_key_part_length, we
  6528. still do our own checking using field_lengths to be absolutely
  6529. sure we don't create too long indexes. */
  6530. error = row_create_index_for_mysql(index, trx, field_lengths);
  6531. error = convert_error_code_to_mysql(error, flags, NULL);
  6532. my_free(field_lengths);
  6533. DBUG_RETURN(error);
  6534. }
  6535. /*****************************************************************//**
  6536. Creates an index to an InnoDB table when the user has defined no
  6537. primary index. */
  6538. static
  6539. int
  6540. create_clustered_index_when_no_primary(
  6541. /*===================================*/
  6542. trx_t* trx, /*!< in: InnoDB transaction handle */
  6543. ulint flags, /*!< in: InnoDB table flags */
  6544. const char* table_name) /*!< in: table name */
  6545. {
  6546. dict_index_t* index;
  6547. int error;
  6548. /* We pass 0 as the space id, and determine at a lower level the space
  6549. id where to store the table */
  6550. index = dict_mem_index_create(table_name,
  6551. innobase_index_reserve_name,
  6552. 0, DICT_CLUSTERED, 0);
  6553. error = row_create_index_for_mysql(index, trx, NULL);
  6554. error = convert_error_code_to_mysql(error, flags, NULL);
  6555. return(error);
  6556. }
  6557. /*****************************************************************//**
  6558. Return a display name for the row format
  6559. @return row format name */
  6560. UNIV_INTERN
  6561. const char*
  6562. get_row_format_name(
  6563. /*================*/
  6564. enum row_type row_format) /*!< in: Row Format */
  6565. {
  6566. switch (row_format) {
  6567. case ROW_TYPE_COMPACT:
  6568. return("COMPACT");
  6569. case ROW_TYPE_COMPRESSED:
  6570. return("COMPRESSED");
  6571. case ROW_TYPE_DYNAMIC:
  6572. return("DYNAMIC");
  6573. case ROW_TYPE_REDUNDANT:
  6574. return("REDUNDANT");
  6575. case ROW_TYPE_DEFAULT:
  6576. return("DEFAULT");
  6577. case ROW_TYPE_FIXED:
  6578. return("FIXED");
  6579. case ROW_TYPE_PAGE:
  6580. case ROW_TYPE_NOT_USED:
  6581. break;
  6582. }
  6583. return("NOT USED");
  6584. }
  6585. /** If file-per-table is missing, issue warning and set ret false */
  6586. #define CHECK_ERROR_ROW_TYPE_NEEDS_FILE_PER_TABLE \
  6587. if (!srv_file_per_table) { \
  6588. push_warning_printf( \
  6589. thd, MYSQL_ERROR::WARN_LEVEL_WARN, \
  6590. HA_WRONG_CREATE_OPTION, \
  6591. "InnoDB: ROW_FORMAT=%s requires" \
  6592. " innodb_file_per_table.", \
  6593. get_row_format_name(row_format)); \
  6594. ret = FALSE; \
  6595. }
  6596. /** If file-format is Antelope, issue warning and set ret false */
  6597. #define CHECK_ERROR_ROW_TYPE_NEEDS_GT_ANTELOPE \
  6598. if (srv_file_format < DICT_TF_FORMAT_ZIP) { \
  6599. push_warning_printf( \
  6600. thd, MYSQL_ERROR::WARN_LEVEL_WARN, \
  6601. HA_WRONG_CREATE_OPTION, \
  6602. "InnoDB: ROW_FORMAT=%s requires" \
  6603. " innodb_file_format > Antelope.", \
  6604. get_row_format_name(row_format)); \
  6605. ret = FALSE; \
  6606. }
  6607. /*****************************************************************//**
  6608. Validates the create options. We may build on this function
  6609. in future. For now, it checks two specifiers:
  6610. KEY_BLOCK_SIZE and ROW_FORMAT
  6611. If innodb_strict_mode is not set then this function is a no-op
  6612. @return TRUE if valid. */
  6613. static
  6614. ibool
  6615. create_options_are_valid(
  6616. /*=====================*/
  6617. THD* thd, /*!< in: connection thread. */
  6618. TABLE* form, /*!< in: information on table
  6619. columns and indexes */
  6620. HA_CREATE_INFO* create_info) /*!< in: create info. */
  6621. {
  6622. ibool kbs_specified = FALSE;
  6623. ibool ret = TRUE;
  6624. enum row_type row_format = form->s->row_type;
  6625. ut_ad(thd != NULL);
  6626. /* If innodb_strict_mode is not set don't do any validation. */
  6627. if (!(THDVAR(thd, strict_mode))) {
  6628. return(TRUE);
  6629. }
  6630. ut_ad(form != NULL);
  6631. ut_ad(create_info != NULL);
  6632. /* First check if a non-zero KEY_BLOCK_SIZE was specified. */
  6633. if (create_info->key_block_size) {
  6634. kbs_specified = TRUE;
  6635. switch (create_info->key_block_size) {
  6636. case 1:
  6637. case 2:
  6638. case 4:
  6639. case 8:
  6640. case 16:
  6641. /* Valid KEY_BLOCK_SIZE, check its dependencies. */
  6642. if (!srv_file_per_table) {
  6643. push_warning(
  6644. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6645. HA_WRONG_CREATE_OPTION,
  6646. "InnoDB: KEY_BLOCK_SIZE requires"
  6647. " innodb_file_per_table.");
  6648. ret = FALSE;
  6649. }
  6650. if (srv_file_format < DICT_TF_FORMAT_ZIP) {
  6651. push_warning(
  6652. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6653. HA_WRONG_CREATE_OPTION,
  6654. "InnoDB: KEY_BLOCK_SIZE requires"
  6655. " innodb_file_format > Antelope.");
  6656. ret = FALSE;
  6657. }
  6658. break;
  6659. default:
  6660. push_warning_printf(
  6661. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6662. HA_WRONG_CREATE_OPTION,
  6663. "InnoDB: invalid KEY_BLOCK_SIZE = %lu."
  6664. " Valid values are [1, 2, 4, 8, 16]",
  6665. create_info->key_block_size);
  6666. ret = FALSE;
  6667. break;
  6668. }
  6669. }
  6670. /* Check for a valid Innodb ROW_FORMAT specifier and
  6671. other incompatibilities. */
  6672. switch (row_format) {
  6673. case ROW_TYPE_COMPRESSED:
  6674. CHECK_ERROR_ROW_TYPE_NEEDS_FILE_PER_TABLE;
  6675. CHECK_ERROR_ROW_TYPE_NEEDS_GT_ANTELOPE;
  6676. break;
  6677. case ROW_TYPE_DYNAMIC:
  6678. CHECK_ERROR_ROW_TYPE_NEEDS_FILE_PER_TABLE;
  6679. CHECK_ERROR_ROW_TYPE_NEEDS_GT_ANTELOPE;
  6680. /* fall through since dynamic also shuns KBS */
  6681. case ROW_TYPE_COMPACT:
  6682. case ROW_TYPE_REDUNDANT:
  6683. if (kbs_specified) {
  6684. push_warning_printf(
  6685. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6686. HA_WRONG_CREATE_OPTION,
  6687. "InnoDB: cannot specify ROW_FORMAT = %s"
  6688. " with KEY_BLOCK_SIZE.",
  6689. get_row_format_name(row_format));
  6690. ret = FALSE;
  6691. }
  6692. break;
  6693. case ROW_TYPE_DEFAULT:
  6694. break;
  6695. case ROW_TYPE_FIXED:
  6696. case ROW_TYPE_PAGE:
  6697. case ROW_TYPE_NOT_USED:
  6698. push_warning(
  6699. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6700. HA_WRONG_CREATE_OPTION, \
  6701. "InnoDB: invalid ROW_FORMAT specifier.");
  6702. ret = FALSE;
  6703. break;
  6704. }
  6705. return(ret);
  6706. }
  6707. /*****************************************************************//**
  6708. Update create_info. Used in SHOW CREATE TABLE et al. */
  6709. UNIV_INTERN
  6710. void
  6711. ha_innobase::update_create_info(
  6712. /*============================*/
  6713. HA_CREATE_INFO* create_info) /*!< in/out: create info */
  6714. {
  6715. if (!(create_info->used_fields & HA_CREATE_USED_AUTO)) {
  6716. ha_innobase::info(HA_STATUS_AUTO);
  6717. create_info->auto_increment_value = stats.auto_increment_value;
  6718. }
  6719. }
  6720. /*****************************************************************//**
  6721. Creates a new table to an InnoDB database.
  6722. @return error number */
  6723. UNIV_INTERN
  6724. int
  6725. ha_innobase::create(
  6726. /*================*/
  6727. const char* name, /*!< in: table name */
  6728. TABLE* form, /*!< in: information on table
  6729. columns and indexes */
  6730. HA_CREATE_INFO* create_info) /*!< in: more information of the
  6731. created table, contains also the
  6732. create statement string */
  6733. {
  6734. int error;
  6735. dict_table_t* innobase_table;
  6736. trx_t* parent_trx;
  6737. trx_t* trx;
  6738. int primary_key_no;
  6739. uint i;
  6740. char name2[FN_REFLEN];
  6741. char norm_name[FN_REFLEN];
  6742. THD* thd = ha_thd();
  6743. ib_int64_t auto_inc_value;
  6744. ulint flags;
  6745. /* Cache the value of innodb_file_format, in case it is
  6746. modified by another thread while the table is being created. */
  6747. const ulint file_format = srv_file_format;
  6748. const char* stmt;
  6749. size_t stmt_len;
  6750. enum row_type row_format;
  6751. DBUG_ENTER("ha_innobase::create");
  6752. DBUG_ASSERT(thd != NULL);
  6753. DBUG_ASSERT(create_info != NULL);
  6754. #ifdef __WIN__
  6755. /* Names passed in from server are in two formats:
  6756. 1. <database_name>/<table_name>: for normal table creation
  6757. 2. full path: for temp table creation, or sym link
  6758. When srv_file_per_table is on and mysqld_embedded is off,
  6759. check for full path pattern, i.e.
  6760. X:\dir\..., X is a driver letter, or
  6761. \\dir1\dir2\..., UNC path
  6762. returns error if it is in full path format, but not creating a temp.
  6763. table. Currently InnoDB does not support symbolic link on Windows. */
  6764. if (srv_file_per_table
  6765. && !mysqld_embedded
  6766. && !(create_info->options & HA_LEX_CREATE_TMP_TABLE)) {
  6767. if ((name[1] == ':')
  6768. || (name[0] == '\\' && name[1] == '\\')) {
  6769. sql_print_error("Cannot create table %s\n", name);
  6770. DBUG_RETURN(HA_ERR_GENERIC);
  6771. }
  6772. }
  6773. #endif
  6774. if (form->s->stored_fields > 1000) {
  6775. /* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
  6776. but we play safe here */
  6777. DBUG_RETURN(HA_ERR_TO_BIG_ROW);
  6778. }
  6779. ut_a(strlen(name) < sizeof(name2));
  6780. strcpy(name2, name);
  6781. normalize_table_name(norm_name, name2);
  6782. /* Create the table definition in InnoDB */
  6783. flags = 0;
  6784. /* Validate create options if innodb_strict_mode is set. */
  6785. if (!create_options_are_valid(thd, form, create_info)) {
  6786. DBUG_RETURN(HA_WRONG_CREATE_OPTION);
  6787. }
  6788. if (create_info->key_block_size) {
  6789. /* Determine the page_zip.ssize corresponding to the
  6790. requested page size (key_block_size) in kilobytes. */
  6791. ulint ssize, ksize;
  6792. ulint key_block_size = create_info->key_block_size;
  6793. /* Set 'flags' to the correct key_block_size.
  6794. It will be zero if key_block_size is an invalid number.*/
  6795. for (ssize = ksize = 1; ssize <= DICT_TF_ZSSIZE_MAX;
  6796. ssize++, ksize <<= 1) {
  6797. if (key_block_size == ksize) {
  6798. flags = ssize << DICT_TF_ZSSIZE_SHIFT
  6799. | DICT_TF_COMPACT
  6800. | DICT_TF_FORMAT_ZIP
  6801. << DICT_TF_FORMAT_SHIFT;
  6802. break;
  6803. }
  6804. }
  6805. if (!srv_file_per_table) {
  6806. push_warning(
  6807. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6808. HA_WRONG_CREATE_OPTION,
  6809. "InnoDB: KEY_BLOCK_SIZE requires"
  6810. " innodb_file_per_table.");
  6811. flags = 0;
  6812. }
  6813. if (file_format < DICT_TF_FORMAT_ZIP) {
  6814. push_warning(
  6815. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6816. HA_WRONG_CREATE_OPTION,
  6817. "InnoDB: KEY_BLOCK_SIZE requires"
  6818. " innodb_file_format > Antelope.");
  6819. flags = 0;
  6820. }
  6821. if (!flags) {
  6822. push_warning_printf(
  6823. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6824. HA_WRONG_CREATE_OPTION,
  6825. "InnoDB: ignoring KEY_BLOCK_SIZE=%lu.",
  6826. create_info->key_block_size);
  6827. }
  6828. }
  6829. row_format = form->s->row_type;
  6830. if (flags) {
  6831. /* if ROW_FORMAT is set to default,
  6832. automatically change it to COMPRESSED.*/
  6833. if (row_format == ROW_TYPE_DEFAULT) {
  6834. row_format = ROW_TYPE_COMPRESSED;
  6835. } else if (row_format != ROW_TYPE_COMPRESSED) {
  6836. /* ROW_FORMAT other than COMPRESSED
  6837. ignores KEY_BLOCK_SIZE. It does not
  6838. make sense to reject conflicting
  6839. KEY_BLOCK_SIZE and ROW_FORMAT, because
  6840. such combinations can be obtained
  6841. with ALTER TABLE anyway. */
  6842. push_warning_printf(
  6843. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6844. HA_WRONG_CREATE_OPTION,
  6845. "InnoDB: ignoring KEY_BLOCK_SIZE=%lu"
  6846. " unless ROW_FORMAT=COMPRESSED.",
  6847. create_info->key_block_size);
  6848. flags = 0;
  6849. }
  6850. } else {
  6851. /* flags == 0 means no KEY_BLOCK_SIZE.*/
  6852. if (row_format == ROW_TYPE_COMPRESSED) {
  6853. /* ROW_FORMAT=COMPRESSED without
  6854. KEY_BLOCK_SIZE implies half the
  6855. maximum KEY_BLOCK_SIZE. */
  6856. flags = (DICT_TF_ZSSIZE_MAX - 1)
  6857. << DICT_TF_ZSSIZE_SHIFT
  6858. | DICT_TF_COMPACT
  6859. | DICT_TF_FORMAT_ZIP
  6860. << DICT_TF_FORMAT_SHIFT;
  6861. //#if DICT_TF_ZSSIZE_MAX < 1
  6862. //# error "DICT_TF_ZSSIZE_MAX < 1"
  6863. //#endif
  6864. }
  6865. }
  6866. switch (row_format) {
  6867. case ROW_TYPE_REDUNDANT:
  6868. break;
  6869. case ROW_TYPE_COMPRESSED:
  6870. case ROW_TYPE_DYNAMIC:
  6871. if (!srv_file_per_table) {
  6872. push_warning_printf(
  6873. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6874. HA_WRONG_CREATE_OPTION,
  6875. "InnoDB: ROW_FORMAT=%s requires"
  6876. " innodb_file_per_table.",
  6877. get_row_format_name(row_format));
  6878. } else if (file_format < DICT_TF_FORMAT_ZIP) {
  6879. push_warning_printf(
  6880. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6881. HA_WRONG_CREATE_OPTION,
  6882. "InnoDB: ROW_FORMAT=%s requires"
  6883. " innodb_file_format > Antelope.",
  6884. get_row_format_name(row_format));
  6885. } else {
  6886. flags |= DICT_TF_COMPACT
  6887. | (DICT_TF_FORMAT_ZIP
  6888. << DICT_TF_FORMAT_SHIFT);
  6889. break;
  6890. }
  6891. /* fall through */
  6892. case ROW_TYPE_NOT_USED:
  6893. case ROW_TYPE_FIXED:
  6894. case ROW_TYPE_PAGE:
  6895. push_warning(
  6896. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6897. HA_WRONG_CREATE_OPTION,
  6898. "InnoDB: assuming ROW_FORMAT=COMPACT.");
  6899. case ROW_TYPE_DEFAULT:
  6900. case ROW_TYPE_COMPACT:
  6901. flags = DICT_TF_COMPACT;
  6902. break;
  6903. }
  6904. /* Look for a primary key */
  6905. primary_key_no= (form->s->primary_key != MAX_KEY ?
  6906. (int) form->s->primary_key :
  6907. -1);
  6908. /* Our function innobase_get_mysql_key_number_for_index assumes
  6909. the primary key is always number 0, if it exists */
  6910. ut_a(primary_key_no == -1 || primary_key_no == 0);
  6911. /* Check for name conflicts (with reserved name) for
  6912. any user indices to be created. */
  6913. if (innobase_index_name_is_reserved(thd, form->key_info,
  6914. form->s->keys)) {
  6915. DBUG_RETURN(-1);
  6916. }
  6917. if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(norm_name, thd)) {
  6918. DBUG_RETURN(HA_ERR_GENERIC);
  6919. }
  6920. if (create_info->options & HA_LEX_CREATE_TMP_TABLE) {
  6921. flags |= DICT_TF2_TEMPORARY << DICT_TF2_SHIFT;
  6922. }
  6923. /* Get the transaction associated with the current thd, or create one
  6924. if not yet created */
  6925. parent_trx = check_trx_exists(thd);
  6926. /* In case MySQL calls this in the middle of a SELECT query, release
  6927. possible adaptive hash latch to avoid deadlocks of threads */
  6928. trx_search_latch_release_if_reserved(parent_trx);
  6929. trx = innobase_trx_allocate(thd);
  6930. if (trx->fake_changes) {
  6931. innobase_commit_low(trx);
  6932. trx_free_for_mysql(trx);
  6933. DBUG_RETURN(HA_ERR_WRONG_COMMAND);
  6934. }
  6935. /* Latch the InnoDB data dictionary exclusively so that no deadlocks
  6936. or lock waits can happen in it during a table create operation.
  6937. Drop table etc. do this latching in row0mysql.c. */
  6938. row_mysql_lock_data_dictionary(trx);
  6939. error = create_table_def(trx, form, norm_name,
  6940. create_info->options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL,
  6941. flags);
  6942. if (error) {
  6943. goto cleanup;
  6944. }
  6945. /* Create the keys */
  6946. if (form->s->keys == 0 || primary_key_no == -1) {
  6947. /* Create an index which is used as the clustered index;
  6948. order the rows by their row id which is internally generated
  6949. by InnoDB */
  6950. error = create_clustered_index_when_no_primary(
  6951. trx, flags, norm_name);
  6952. if (error) {
  6953. goto cleanup;
  6954. }
  6955. }
  6956. if (primary_key_no != -1) {
  6957. /* In InnoDB the clustered index must always be created
  6958. first */
  6959. if ((error = create_index(trx, form, flags, norm_name,
  6960. (uint) primary_key_no))) {
  6961. goto cleanup;
  6962. }
  6963. }
  6964. for (i = 0; i < form->s->keys; i++) {
  6965. if (i != (uint) primary_key_no) {
  6966. if ((error = create_index(trx, form, flags,
  6967. norm_name, i))) {
  6968. goto cleanup;
  6969. }
  6970. }
  6971. }
  6972. stmt = innobase_get_stmt(thd, &stmt_len);
  6973. if (stmt) {
  6974. error = row_table_add_foreign_constraints(
  6975. trx, stmt, stmt_len, norm_name,
  6976. create_info->options & HA_LEX_CREATE_TMP_TABLE);
  6977. switch (error) {
  6978. case DB_PARENT_NO_INDEX:
  6979. push_warning_printf(
  6980. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6981. HA_ERR_CANNOT_ADD_FOREIGN,
  6982. "Create table '%s' with foreign key constraint"
  6983. " failed. There is no index in the referenced"
  6984. " table where the referenced columns appear"
  6985. " as the first columns.\n", norm_name);
  6986. break;
  6987. case DB_CHILD_NO_INDEX:
  6988. push_warning_printf(
  6989. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  6990. HA_ERR_CANNOT_ADD_FOREIGN,
  6991. "Create table '%s' with foreign key constraint"
  6992. " failed. There is no index in the referencing"
  6993. " table where referencing columns appear"
  6994. " as the first columns.\n", norm_name);
  6995. break;
  6996. }
  6997. error = convert_error_code_to_mysql(error, flags, NULL);
  6998. if (error) {
  6999. goto cleanup;
  7000. }
  7001. }
  7002. innobase_commit_low(trx);
  7003. row_mysql_unlock_data_dictionary(trx);
  7004. /* Flush the log to reduce probability that the .frm files and
  7005. the InnoDB data dictionary get out-of-sync if the user runs
  7006. with innodb_flush_log_at_trx_commit = 0 */
  7007. log_buffer_flush_to_disk();
  7008. innobase_table = dict_table_get(norm_name, FALSE);
  7009. DBUG_ASSERT(innobase_table != 0);
  7010. if (innobase_table) {
  7011. /* We update the highest file format in the system table
  7012. space, if this table has higher file format setting. */
  7013. trx_sys_file_format_max_upgrade(
  7014. (const char**) &innobase_file_format_max,
  7015. dict_table_get_format(innobase_table));
  7016. }
  7017. /* Note: We can't call update_thd() as prebuilt will not be
  7018. setup at this stage and so we use thd. */
  7019. /* We need to copy the AUTOINC value from the old table if
  7020. this is an ALTER|OPTIMIZE TABLE or CREATE INDEX because CREATE INDEX
  7021. does a table copy too. If query was one of :
  7022. CREATE TABLE ...AUTO_INCREMENT = x; or
  7023. ALTER TABLE...AUTO_INCREMENT = x; or
  7024. OPTIMIZE TABLE t; or
  7025. CREATE INDEX x on t(...);
  7026. Find out a table definition from the dictionary and get
  7027. the current value of the auto increment field. Set a new
  7028. value to the auto increment field if the value is greater
  7029. than the maximum value in the column. */
  7030. if (((create_info->used_fields & HA_CREATE_USED_AUTO)
  7031. || thd_sql_command(thd) == SQLCOM_ALTER_TABLE
  7032. || thd_sql_command(thd) == SQLCOM_OPTIMIZE
  7033. || thd_sql_command(thd) == SQLCOM_CREATE_INDEX)
  7034. && create_info->auto_increment_value > 0) {
  7035. auto_inc_value = create_info->auto_increment_value;
  7036. dict_table_autoinc_lock(innobase_table);
  7037. dict_table_autoinc_initialize(innobase_table, auto_inc_value);
  7038. dict_table_autoinc_unlock(innobase_table);
  7039. }
  7040. /* Tell the InnoDB server that there might be work for
  7041. utility threads: */
  7042. srv_active_wake_master_thread();
  7043. trx_free_for_mysql(trx);
  7044. DBUG_RETURN(0);
  7045. cleanup:
  7046. innobase_commit_low(trx);
  7047. row_mysql_unlock_data_dictionary(trx);
  7048. trx_free_for_mysql(trx);
  7049. DBUG_RETURN(error);
  7050. }
  7051. /*****************************************************************//**
  7052. Discards or imports an InnoDB tablespace.
  7053. @return 0 == success, -1 == error */
  7054. UNIV_INTERN
  7055. int
  7056. ha_innobase::discard_or_import_tablespace(
  7057. /*======================================*/
  7058. my_bool discard) /*!< in: TRUE if discard, else import */
  7059. {
  7060. dict_table_t* dict_table;
  7061. trx_t* trx;
  7062. int err;
  7063. DBUG_ENTER("ha_innobase::discard_or_import_tablespace");
  7064. ut_a(prebuilt->trx);
  7065. ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
  7066. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  7067. dict_table = prebuilt->table;
  7068. trx = prebuilt->trx;
  7069. if (discard) {
  7070. err = row_discard_tablespace_for_mysql(dict_table->name, trx);
  7071. } else {
  7072. err = row_import_tablespace_for_mysql(dict_table->name, trx);
  7073. /* in expanded import mode re-initialize auto_increment again */
  7074. if ((err == DB_SUCCESS) && srv_expand_import &&
  7075. (table->found_next_number_field != NULL)) {
  7076. dict_table_autoinc_lock(dict_table);
  7077. innobase_initialize_autoinc();
  7078. dict_table_autoinc_unlock(dict_table);
  7079. }
  7080. }
  7081. err = convert_error_code_to_mysql(err, dict_table->flags, NULL);
  7082. DBUG_RETURN(err);
  7083. }
  7084. /*****************************************************************//**
  7085. Deletes all rows of an InnoDB table.
  7086. @return error number */
  7087. UNIV_INTERN
  7088. int
  7089. ha_innobase::truncate(void)
  7090. /*==============================*/
  7091. {
  7092. int error;
  7093. DBUG_ENTER("ha_innobase::truncate");
  7094. /* Get the transaction associated with the current thd, or create one
  7095. if not yet created, and update prebuilt->trx */
  7096. update_thd(ha_thd());
  7097. if (share->ib_table->is_corrupt) {
  7098. DBUG_RETURN(HA_ERR_CRASHED);
  7099. }
  7100. if (prebuilt->trx->fake_changes) {
  7101. DBUG_RETURN(HA_ERR_WRONG_COMMAND);
  7102. }
  7103. /* Truncate the table in InnoDB */
  7104. error = row_truncate_table_for_mysql(prebuilt->table, prebuilt->trx);
  7105. if (share->ib_table->is_corrupt) {
  7106. DBUG_RETURN(HA_ERR_CRASHED);
  7107. }
  7108. error = convert_error_code_to_mysql(error, prebuilt->table->flags,
  7109. NULL);
  7110. DBUG_RETURN(error);
  7111. }
  7112. /*****************************************************************//**
  7113. Drops a table from an InnoDB database. Before calling this function,
  7114. MySQL calls innobase_commit to commit the transaction of the current user.
  7115. Then the current user cannot have locks set on the table. Drop table
  7116. operation inside InnoDB will remove all locks any user has on the table
  7117. inside InnoDB.
  7118. @return error number */
  7119. UNIV_INTERN
  7120. int
  7121. ha_innobase::delete_table(
  7122. /*======================*/
  7123. const char* name) /*!< in: table name */
  7124. {
  7125. ulint name_len;
  7126. int error;
  7127. trx_t* parent_trx;
  7128. trx_t* trx;
  7129. THD *thd = ha_thd();
  7130. char norm_name[1000];
  7131. DBUG_ENTER("ha_innobase::delete_table");
  7132. DBUG_EXECUTE_IF(
  7133. "test_normalize_table_name_low",
  7134. test_normalize_table_name_low();
  7135. );
  7136. /* Strangely, MySQL passes the table name without the '.frm'
  7137. extension, in contrast to ::create */
  7138. normalize_table_name(norm_name, name);
  7139. if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(norm_name, thd)) {
  7140. DBUG_RETURN(HA_ERR_GENERIC);
  7141. }
  7142. /* Get the transaction associated with the current thd, or create one
  7143. if not yet created */
  7144. parent_trx = check_trx_exists(thd);
  7145. /* In case MySQL calls this in the middle of a SELECT query, release
  7146. possible adaptive hash latch to avoid deadlocks of threads */
  7147. trx_search_latch_release_if_reserved(parent_trx);
  7148. trx = innobase_trx_allocate(thd);
  7149. if (trx->fake_changes) {
  7150. innobase_commit_low(trx);
  7151. trx_free_for_mysql(trx);
  7152. DBUG_RETURN(HA_ERR_WRONG_COMMAND);
  7153. }
  7154. name_len = strlen(name);
  7155. ut_a(name_len < 1000);
  7156. /* Drop the table in InnoDB */
  7157. error = row_drop_table_for_mysql(norm_name, trx,
  7158. thd_sql_command(thd)
  7159. == SQLCOM_DROP_DB);
  7160. /* Flush the log to reduce probability that the .frm files and
  7161. the InnoDB data dictionary get out-of-sync if the user runs
  7162. with innodb_flush_log_at_trx_commit = 0 */
  7163. log_buffer_flush_to_disk();
  7164. /* Tell the InnoDB server that there might be work for
  7165. utility threads: */
  7166. srv_active_wake_master_thread();
  7167. innobase_commit_low(trx);
  7168. trx_free_for_mysql(trx);
  7169. error = convert_error_code_to_mysql(error, 0, NULL);
  7170. DBUG_RETURN(error);
  7171. }
  7172. /*****************************************************************//**
  7173. Removes all tables in the named database inside InnoDB. */
  7174. static
  7175. void
  7176. innobase_drop_database(
  7177. /*===================*/
  7178. handlerton *hton, /*!< in: handlerton of Innodb */
  7179. char* path) /*!< in: database path; inside InnoDB the name
  7180. of the last directory in the path is used as
  7181. the database name: for example, in 'mysql/data/test'
  7182. the database name is 'test' */
  7183. {
  7184. ulint len = 0;
  7185. trx_t* trx;
  7186. char* ptr;
  7187. char* namebuf;
  7188. THD* thd = current_thd;
  7189. /* Get the transaction associated with the current thd, or create one
  7190. if not yet created */
  7191. DBUG_ASSERT(hton == innodb_hton_ptr);
  7192. /* In the Windows plugin, thd = current_thd is always NULL */
  7193. if (thd) {
  7194. trx_t* parent_trx = check_trx_exists(thd);
  7195. /* In case MySQL calls this in the middle of a SELECT
  7196. query, release possible adaptive hash latch to avoid
  7197. deadlocks of threads */
  7198. trx_search_latch_release_if_reserved(parent_trx);
  7199. }
  7200. ptr = strend(path) - 2;
  7201. while (ptr >= path && *ptr != '\\' && *ptr != '/') {
  7202. ptr--;
  7203. len++;
  7204. }
  7205. ptr++;
  7206. namebuf = (char*) my_malloc((uint) len + 2, MYF(0));
  7207. memcpy(namebuf, ptr, len);
  7208. namebuf[len] = '/';
  7209. namebuf[len + 1] = '\0';
  7210. #ifdef __WIN__
  7211. innobase_casedn_str(namebuf);
  7212. #endif
  7213. #if defined __WIN__ && !defined MYSQL_SERVER
  7214. /* In the Windows plugin, thd = current_thd is always NULL */
  7215. trx = trx_allocate_for_mysql();
  7216. trx->mysql_thd = NULL;
  7217. #else
  7218. trx = innobase_trx_allocate(thd);
  7219. if (trx->fake_changes) {
  7220. my_free(namebuf);
  7221. innobase_commit_low(trx);
  7222. trx_free_for_mysql(trx);
  7223. return; /* ignore */
  7224. }
  7225. #endif
  7226. row_drop_database_for_mysql(namebuf, trx);
  7227. my_free(namebuf);
  7228. /* Flush the log to reduce probability that the .frm files and
  7229. the InnoDB data dictionary get out-of-sync if the user runs
  7230. with innodb_flush_log_at_trx_commit = 0 */
  7231. log_buffer_flush_to_disk();
  7232. /* Tell the InnoDB server that there might be work for
  7233. utility threads: */
  7234. srv_active_wake_master_thread();
  7235. innobase_commit_low(trx);
  7236. trx_free_for_mysql(trx);
  7237. }
  7238. /*********************************************************************//**
  7239. Renames an InnoDB table.
  7240. @return 0 or error code */
  7241. static
  7242. int
  7243. innobase_rename_table(
  7244. /*==================*/
  7245. trx_t* trx, /*!< in: transaction */
  7246. const char* from, /*!< in: old name of the table */
  7247. const char* to, /*!< in: new name of the table */
  7248. ibool lock_and_commit)
  7249. /*!< in: TRUE=lock data dictionary and commit */
  7250. {
  7251. int error;
  7252. char* norm_to;
  7253. char* norm_from;
  7254. DBUG_ENTER("innobase_rename_table");
  7255. // Magic number 64 arbitrary
  7256. norm_to = (char*) my_malloc(strlen(to) + 64, MYF(0));
  7257. norm_from = (char*) my_malloc(strlen(from) + 64, MYF(0));
  7258. normalize_table_name(norm_to, to);
  7259. normalize_table_name(norm_from, from);
  7260. DEBUG_SYNC_C("innodb_rename_table_ready");
  7261. /* Serialize data dictionary operations with dictionary mutex:
  7262. no deadlocks can occur then in these operations */
  7263. if (lock_and_commit) {
  7264. row_mysql_lock_data_dictionary(trx);
  7265. }
  7266. error = row_rename_table_for_mysql(
  7267. norm_from, norm_to, trx, lock_and_commit);
  7268. if (error != DB_SUCCESS) {
  7269. FILE* ef = dict_foreign_err_file;
  7270. DBUG_PRINT("info", ("rename failed: %d", error));
  7271. fputs("InnoDB: Renaming table ", ef);
  7272. ut_print_name(ef, trx, TRUE, norm_from);
  7273. fputs(" to ", ef);
  7274. ut_print_name(ef, trx, TRUE, norm_to);
  7275. fputs(" failed!\n", ef);
  7276. }
  7277. if (lock_and_commit) {
  7278. row_mysql_unlock_data_dictionary(trx);
  7279. /* Flush the log to reduce probability that the .frm
  7280. files and the InnoDB data dictionary get out-of-sync
  7281. if the user runs with innodb_flush_log_at_trx_commit = 0 */
  7282. log_buffer_flush_to_disk();
  7283. }
  7284. my_free(norm_to);
  7285. my_free(norm_from);
  7286. DBUG_RETURN(error);
  7287. }
  7288. /*********************************************************************//**
  7289. Renames an InnoDB table.
  7290. @return 0 or error code */
  7291. UNIV_INTERN
  7292. int
  7293. ha_innobase::rename_table(
  7294. /*======================*/
  7295. const char* from, /*!< in: old name of the table */
  7296. const char* to) /*!< in: new name of the table */
  7297. {
  7298. trx_t* trx;
  7299. int error;
  7300. trx_t* parent_trx;
  7301. THD* thd = ha_thd();
  7302. DBUG_ENTER("ha_innobase::rename_table");
  7303. /* Get the transaction associated with the current thd, or create one
  7304. if not yet created */
  7305. parent_trx = check_trx_exists(thd);
  7306. /* In case MySQL calls this in the middle of a SELECT query, release
  7307. possible adaptive hash latch to avoid deadlocks of threads */
  7308. trx_search_latch_release_if_reserved(parent_trx);
  7309. trx = innobase_trx_allocate(thd);
  7310. if (trx->fake_changes) {
  7311. innobase_commit_low(trx);
  7312. trx_free_for_mysql(trx);
  7313. DBUG_RETURN(HA_ERR_WRONG_COMMAND);
  7314. }
  7315. error = innobase_rename_table(trx, from, to, TRUE);
  7316. DEBUG_SYNC(thd, "after_innobase_rename_table");
  7317. /* Tell the InnoDB server that there might be work for
  7318. utility threads: */
  7319. srv_active_wake_master_thread();
  7320. innobase_commit_low(trx);
  7321. trx_free_for_mysql(trx);
  7322. /* Add a special case to handle the Duplicated Key error
  7323. and return DB_ERROR instead.
  7324. This is to avoid a possible SIGSEGV error from mysql error
  7325. handling code. Currently, mysql handles the Duplicated Key
  7326. error by re-entering the storage layer and getting dup key
  7327. info by calling get_dup_key(). This operation requires a valid
  7328. table handle ('row_prebuilt_t' structure) which could no
  7329. longer be available in the error handling stage. The suggested
  7330. solution is to report a 'table exists' error message (since
  7331. the dup key error here is due to an existing table whose name
  7332. is the one we are trying to rename to) and return the generic
  7333. error code. */
  7334. if (error == (int) DB_DUPLICATE_KEY) {
  7335. my_error(ER_TABLE_EXISTS_ERROR, MYF(0), to);
  7336. error = DB_ERROR;
  7337. }
  7338. error = convert_error_code_to_mysql(error, 0, NULL);
  7339. DBUG_RETURN(error);
  7340. }
  7341. /*********************************************************************//**
  7342. Estimates the number of index records in a range.
  7343. @return estimated number of rows */
  7344. UNIV_INTERN
  7345. ha_rows
  7346. ha_innobase::records_in_range(
  7347. /*==========================*/
  7348. uint keynr, /*!< in: index number */
  7349. key_range *min_key, /*!< in: start key value of the
  7350. range, may also be 0 */
  7351. key_range *max_key) /*!< in: range end key val, may
  7352. also be 0 */
  7353. {
  7354. KEY* key;
  7355. dict_index_t* index;
  7356. dtuple_t* range_start;
  7357. dtuple_t* range_end;
  7358. ib_int64_t n_rows;
  7359. ulint mode1;
  7360. ulint mode2;
  7361. uint key_parts;
  7362. mem_heap_t* heap;
  7363. DBUG_ENTER("records_in_range");
  7364. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  7365. prebuilt->trx->op_info = (char*)"estimating records in index range";
  7366. /* In case MySQL calls this in the middle of a SELECT query, release
  7367. possible adaptive hash latch to avoid deadlocks of threads */
  7368. trx_search_latch_release_if_reserved(prebuilt->trx);
  7369. active_index = keynr;
  7370. key = table->key_info + active_index;
  7371. index = innobase_get_index(keynr);
  7372. /* There exists possibility of not being able to find requested
  7373. index due to inconsistency between MySQL and InoDB dictionary info.
  7374. Necessary message should have been printed in innobase_get_index() */
  7375. if (UNIV_UNLIKELY(!index)) {
  7376. n_rows = HA_POS_ERROR;
  7377. goto func_exit;
  7378. }
  7379. if (dict_index_is_corrupted(index)) {
  7380. n_rows = HA_ERR_INDEX_CORRUPT;
  7381. goto func_exit;
  7382. }
  7383. if (UNIV_UNLIKELY(!row_merge_is_index_usable(prebuilt->trx, index))) {
  7384. n_rows = HA_ERR_TABLE_DEF_CHANGED;
  7385. goto func_exit;
  7386. }
  7387. key_parts= key->key_parts;
  7388. if ((min_key && min_key->keypart_map>=(key_part_map) (1<<key_parts)) ||
  7389. (max_key && max_key->keypart_map>=(key_part_map) (1<<key_parts)))
  7390. key_parts= key->ext_key_parts;
  7391. heap = mem_heap_create(2 * (key_parts * sizeof(dfield_t)
  7392. + sizeof(dtuple_t)));
  7393. range_start= dtuple_create(heap, key_parts);
  7394. dict_index_copy_types(range_start, index, key_parts);
  7395. range_end= dtuple_create(heap, key_parts);
  7396. dict_index_copy_types(range_end, index, key_parts);
  7397. row_sel_convert_mysql_key_to_innobase(
  7398. range_start,
  7399. srch_key_val1, sizeof(srch_key_val1),
  7400. index,
  7401. (byte*) (min_key ? min_key->key :
  7402. (const uchar*) 0),
  7403. (ulint) (min_key ? min_key->length : 0),
  7404. prebuilt->trx);
  7405. DBUG_ASSERT(min_key
  7406. ? range_start->n_fields > 0
  7407. : range_start->n_fields == 0);
  7408. row_sel_convert_mysql_key_to_innobase(
  7409. range_end,
  7410. srch_key_val2, sizeof(srch_key_val2),
  7411. index,
  7412. (byte*) (max_key ? max_key->key :
  7413. (const uchar*) 0),
  7414. (ulint) (max_key ? max_key->length : 0),
  7415. prebuilt->trx);
  7416. DBUG_ASSERT(max_key
  7417. ? range_end->n_fields > 0
  7418. : range_end->n_fields == 0);
  7419. mode1 = convert_search_mode_to_innobase(min_key ? min_key->flag :
  7420. HA_READ_KEY_EXACT);
  7421. mode2 = convert_search_mode_to_innobase(max_key ? max_key->flag :
  7422. HA_READ_KEY_EXACT);
  7423. if (mode1 != PAGE_CUR_UNSUPP && mode2 != PAGE_CUR_UNSUPP) {
  7424. n_rows = btr_estimate_n_rows_in_range(index, range_start,
  7425. mode1, range_end,
  7426. mode2);
  7427. } else {
  7428. n_rows = HA_POS_ERROR;
  7429. }
  7430. mem_heap_free(heap);
  7431. func_exit:
  7432. prebuilt->trx->op_info = (char*)"";
  7433. /* The MySQL optimizer seems to believe an estimate of 0 rows is
  7434. always accurate and may return the result 'Empty set' based on that.
  7435. The accuracy is not guaranteed, and even if it were, for a locking
  7436. read we should anyway perform the search to set the next-key lock.
  7437. Add 1 to the value to make sure MySQL does not make the assumption! */
  7438. if (n_rows == 0) {
  7439. n_rows = 1;
  7440. }
  7441. DBUG_RETURN((ha_rows) n_rows);
  7442. }
  7443. /*********************************************************************//**
  7444. Gives an UPPER BOUND to the number of rows in a table. This is used in
  7445. filesort.cc.
  7446. @return upper bound of rows */
  7447. UNIV_INTERN
  7448. ha_rows
  7449. ha_innobase::estimate_rows_upper_bound(void)
  7450. /*======================================*/
  7451. {
  7452. dict_index_t* index;
  7453. ulonglong estimate;
  7454. ulonglong local_data_file_length;
  7455. ulint stat_n_leaf_pages;
  7456. DBUG_ENTER("estimate_rows_upper_bound");
  7457. /* We do not know if MySQL can call this function before calling
  7458. external_lock(). To be safe, update the thd of the current table
  7459. handle. */
  7460. update_thd(ha_thd());
  7461. prebuilt->trx->op_info = (char*)
  7462. "calculating upper bound for table rows";
  7463. /* In case MySQL calls this in the middle of a SELECT query, release
  7464. possible adaptive hash latch to avoid deadlocks of threads */
  7465. trx_search_latch_release_if_reserved(prebuilt->trx);
  7466. index = dict_table_get_first_index(prebuilt->table);
  7467. stat_n_leaf_pages = index->stat_n_leaf_pages;
  7468. ut_a(stat_n_leaf_pages > 0);
  7469. local_data_file_length =
  7470. ((ulonglong) stat_n_leaf_pages) * UNIV_PAGE_SIZE;
  7471. /* Calculate a minimum length for a clustered index record and from
  7472. that an upper bound for the number of rows. Since we only calculate
  7473. new statistics in row0mysql.c when a table has grown by a threshold
  7474. factor, we must add a safety factor 2 in front of the formula below. */
  7475. estimate = 2 * local_data_file_length /
  7476. dict_index_calc_min_rec_len(index);
  7477. prebuilt->trx->op_info = (char*)"";
  7478. DBUG_RETURN((ha_rows) estimate);
  7479. }
  7480. /*********************************************************************//**
  7481. How many seeks it will take to read through the table. This is to be
  7482. comparable to the number returned by records_in_range so that we can
  7483. decide if we should scan the table or use keys.
  7484. @return estimated time measured in disk seeks */
  7485. UNIV_INTERN
  7486. double
  7487. ha_innobase::scan_time()
  7488. /*====================*/
  7489. {
  7490. /* Since MySQL seems to favor table scans too much over index
  7491. searches, we pretend that a sequential read takes the same time
  7492. as a random disk read, that is, we do not divide the following
  7493. by 10, which would be physically realistic. */
  7494. return((double) (prebuilt->table->stat_clustered_index_size));
  7495. }
  7496. /******************************************************************//**
  7497. Calculate the time it takes to read a set of ranges through an index
  7498. This enables us to optimise reads for clustered indexes.
  7499. @return estimated time measured in disk seeks */
  7500. UNIV_INTERN
  7501. double
  7502. ha_innobase::read_time(
  7503. /*===================*/
  7504. uint index, /*!< in: key number */
  7505. uint ranges, /*!< in: how many ranges */
  7506. ha_rows rows) /*!< in: estimated number of rows in the ranges */
  7507. {
  7508. ha_rows total_rows;
  7509. double time_for_scan;
  7510. if (index != table->s->primary_key) {
  7511. /* Not clustered */
  7512. return(handler::read_time(index, ranges, rows));
  7513. }
  7514. /* Assume that the read time is proportional to the scan time for all
  7515. rows + at most one seek per range. */
  7516. time_for_scan = scan_time();
  7517. if ((total_rows = estimate_rows_upper_bound()) < rows) {
  7518. return(time_for_scan);
  7519. }
  7520. return(ranges + (double) rows / (double) total_rows * time_for_scan);
  7521. }
  7522. UNIV_INTERN
  7523. bool
  7524. ha_innobase::is_corrupt() const
  7525. {
  7526. if (share->ib_table)
  7527. return ((bool)share->ib_table->is_corrupt);
  7528. else
  7529. return (FALSE);
  7530. }
  7531. /*********************************************************************//**
  7532. Calculates the key number used inside MySQL for an Innobase index. We will
  7533. first check the "index translation table" for a match of the index to get
  7534. the index number. If there does not exist an "index translation table",
  7535. or not able to find the index in the translation table, then we will fall back
  7536. to the traditional way of looping through dict_index_t list to find a
  7537. match. In this case, we have to take into account if we generated a
  7538. default clustered index for the table
  7539. @return the key number used inside MySQL */
  7540. static
  7541. unsigned int
  7542. innobase_get_mysql_key_number_for_index(
  7543. /*====================================*/
  7544. INNOBASE_SHARE* share, /*!< in: share structure for index
  7545. translation table. */
  7546. const TABLE* table, /*!< in: table in MySQL data
  7547. dictionary */
  7548. dict_table_t* ib_table,/*!< in: table in Innodb data
  7549. dictionary */
  7550. const dict_index_t* index) /*!< in: index */
  7551. {
  7552. const dict_index_t* ind;
  7553. unsigned int i;
  7554. ut_a(index);
  7555. /* If index does not belong to the table of share structure. Search
  7556. index->table instead */
  7557. if (index->table != ib_table) {
  7558. i = 0;
  7559. ind = dict_table_get_first_index(index->table);
  7560. while (index != ind) {
  7561. ind = dict_table_get_next_index(ind);
  7562. i++;
  7563. }
  7564. if (row_table_got_default_clust_index(index->table)) {
  7565. ut_a(i > 0);
  7566. i--;
  7567. }
  7568. return(i);
  7569. }
  7570. /* If index translation table exists, we will first check
  7571. the index through index translation table for a match. */
  7572. if (share->idx_trans_tbl.index_mapping) {
  7573. for (i = 0; i < share->idx_trans_tbl.index_count; i++) {
  7574. if (share->idx_trans_tbl.index_mapping[i] == index) {
  7575. return(i);
  7576. }
  7577. }
  7578. /* If index_count in translation table is set to 0, it
  7579. is possible we are in the process of rebuilding table,
  7580. do not spit error in this case */
  7581. if (share->idx_trans_tbl.index_count) {
  7582. /* Print an error message if we cannot find the index
  7583. ** in the "index translation table". */
  7584. sql_print_error("Cannot find index %s in InnoDB index "
  7585. "translation table.", index->name);
  7586. }
  7587. }
  7588. /* If we do not have an "index translation table", or not able
  7589. to find the index in the translation table, we'll directly find
  7590. matching index with information from mysql TABLE structure and
  7591. InnoDB dict_index_t list */
  7592. for (i = 0; i < table->s->keys; i++) {
  7593. ind = dict_table_get_index_on_name(
  7594. ib_table, table->key_info[i].name);
  7595. if (index == ind) {
  7596. return(i);
  7597. }
  7598. }
  7599. ut_error;
  7600. return(0);
  7601. }
  7602. /*********************************************************************//**
  7603. Calculate Record Per Key value. Need to exclude the NULL value if
  7604. innodb_stats_method is set to "nulls_ignored"
  7605. @return estimated record per key value */
  7606. static
  7607. ha_rows
  7608. innodb_rec_per_key(
  7609. /*===============*/
  7610. dict_index_t* index, /*!< in: dict_index_t structure */
  7611. ulint i, /*!< in: the column we are
  7612. calculating rec per key */
  7613. ha_rows records) /*!< in: estimated total records */
  7614. {
  7615. ha_rows rec_per_key;
  7616. ut_ad(i < dict_index_get_n_unique(index));
  7617. /* Note the stat_n_diff_key_vals[] stores the diff value with
  7618. n-prefix indexing, so it is always stat_n_diff_key_vals[i + 1] */
  7619. if (index->stat_n_diff_key_vals[i + 1] == 0) {
  7620. rec_per_key = records;
  7621. } else if (srv_innodb_stats_method == SRV_STATS_NULLS_IGNORED) {
  7622. ib_int64_t num_null;
  7623. /* Number of rows with NULL value in this
  7624. field */
  7625. num_null = records - index->stat_n_non_null_key_vals[i];
  7626. /* In theory, index->stat_n_non_null_key_vals[i]
  7627. should always be less than the number of records.
  7628. Since this is statistics value, the value could
  7629. have slight discrepancy. But we will make sure
  7630. the number of null values is not a negative number. */
  7631. num_null = (num_null < 0) ? 0 : num_null;
  7632. /* If the number of NULL values is the same as or
  7633. large than that of the distinct values, we could
  7634. consider that the table consists mostly of NULL value.
  7635. Set rec_per_key to 1. */
  7636. if (index->stat_n_diff_key_vals[i + 1] <= num_null) {
  7637. rec_per_key = 1;
  7638. } else {
  7639. /* Need to exclude rows with NULL values from
  7640. rec_per_key calculation */
  7641. rec_per_key = (ha_rows)(
  7642. (records - num_null)
  7643. / (index->stat_n_diff_key_vals[i + 1]
  7644. - num_null));
  7645. }
  7646. } else {
  7647. rec_per_key = (ha_rows)
  7648. (records / index->stat_n_diff_key_vals[i + 1]);
  7649. }
  7650. return(rec_per_key);
  7651. }
  7652. /*********************************************************************//**
  7653. Returns statistics information of the table to the MySQL interpreter,
  7654. in various fields of the handle object. */
  7655. UNIV_INTERN
  7656. int
  7657. ha_innobase::info_low(
  7658. /*==================*/
  7659. uint flag, /*!< in: what information MySQL
  7660. requests */
  7661. bool called_from_analyze) /* in: TRUE if called from
  7662. ::analyze() */
  7663. {
  7664. dict_table_t* ib_table;
  7665. dict_index_t* index;
  7666. ha_rows rec_per_key;
  7667. ib_int64_t n_rows;
  7668. char path[FN_REFLEN];
  7669. os_file_stat_t stat_info;
  7670. DBUG_ENTER("info");
  7671. /* If we are forcing recovery at a high level, we will suppress
  7672. statistics calculation on tables, because that may crash the
  7673. server if an index is badly corrupted. */
  7674. /* We do not know if MySQL can call this function before calling
  7675. external_lock(). To be safe, update the thd of the current table
  7676. handle. */
  7677. update_thd(ha_thd());
  7678. /* In case MySQL calls this in the middle of a SELECT query, release
  7679. possible adaptive hash latch to avoid deadlocks of threads */
  7680. prebuilt->trx->op_info = (char*)"returning various info to MySQL";
  7681. trx_search_latch_release_if_reserved(prebuilt->trx);
  7682. ib_table = prebuilt->table;
  7683. if (flag & HA_STATUS_TIME) {
  7684. if ((called_from_analyze || innobase_stats_on_metadata) && !share->ib_table->is_corrupt) {
  7685. /* In sql_show we call with this flag: update
  7686. then statistics so that they are up-to-date */
  7687. if (srv_use_sys_stats_table && !((ib_table->flags >> DICT_TF2_SHIFT) & DICT_TF2_TEMPORARY)
  7688. && called_from_analyze) {
  7689. /* If the indexes on the table don't have enough rows in SYS_STATS system table, */
  7690. /* they need to be created. */
  7691. dict_index_t* index;
  7692. prebuilt->trx->op_info = "confirming rows of SYS_STATS to store statistics";
  7693. ut_a(prebuilt->trx->conc_state == TRX_NOT_STARTED);
  7694. for (index = dict_table_get_first_index(ib_table);
  7695. index != NULL;
  7696. index = dict_table_get_next_index(index)) {
  7697. if (dict_is_older_statistics(index)) {
  7698. row_delete_stats_for_mysql(index, prebuilt->trx);
  7699. innobase_commit_low(prebuilt->trx);
  7700. }
  7701. row_insert_stats_for_mysql(index, prebuilt->trx);
  7702. innobase_commit_low(prebuilt->trx);
  7703. }
  7704. ut_a(prebuilt->trx->conc_state == TRX_NOT_STARTED);
  7705. }
  7706. prebuilt->trx->op_info = "updating table statistics";
  7707. dict_update_statistics(ib_table,
  7708. FALSE /* update even if stats
  7709. are initialized */, called_from_analyze);
  7710. prebuilt->trx->op_info = "returning various info to MySQL";
  7711. }
  7712. my_snprintf(path, sizeof(path), "%s/%s%s",
  7713. mysql_data_home, ib_table->name, reg_ext);
  7714. unpack_filename(path,path);
  7715. /* Note that we do not know the access time of the table,
  7716. nor the CHECK TABLE time, nor the UPDATE or INSERT time. */
  7717. if (os_file_get_status(path,&stat_info)) {
  7718. stats.create_time = (ulong) stat_info.ctime;
  7719. }
  7720. }
  7721. if (flag & HA_STATUS_VARIABLE) {
  7722. ulint page_size;
  7723. dict_table_stats_lock(ib_table, RW_S_LATCH);
  7724. n_rows = ib_table->stat_n_rows;
  7725. /* Because we do not protect stat_n_rows by any mutex in a
  7726. delete, it is theoretically possible that the value can be
  7727. smaller than zero! TODO: fix this race.
  7728. The MySQL optimizer seems to assume in a left join that n_rows
  7729. is an accurate estimate if it is zero. Of course, it is not,
  7730. since we do not have any locks on the rows yet at this phase.
  7731. Since SHOW TABLE STATUS seems to call this function with the
  7732. HA_STATUS_TIME flag set, while the left join optimizer does not
  7733. set that flag, we add one to a zero value if the flag is not
  7734. set. That way SHOW TABLE STATUS will show the best estimate,
  7735. while the optimizer never sees the table empty. */
  7736. if (n_rows < 0) {
  7737. n_rows = 0;
  7738. }
  7739. if (n_rows == 0 && !(flag & HA_STATUS_TIME)) {
  7740. n_rows++;
  7741. }
  7742. /* Fix bug#40386: Not flushing query cache after truncate.
  7743. n_rows can not be 0 unless the table is empty, set to 1
  7744. instead. The original problem of bug#29507 is actually
  7745. fixed in the server code. */
  7746. if (thd_sql_command(user_thd) == SQLCOM_TRUNCATE) {
  7747. n_rows = 1;
  7748. /* We need to reset the prebuilt value too, otherwise
  7749. checks for values greater than the last value written
  7750. to the table will fail and the autoinc counter will
  7751. not be updated. This will force write_row() into
  7752. attempting an update of the table's AUTOINC counter. */
  7753. prebuilt->autoinc_last_value = 0;
  7754. }
  7755. page_size = dict_table_zip_size(ib_table);
  7756. if (page_size == 0) {
  7757. page_size = UNIV_PAGE_SIZE;
  7758. }
  7759. stats.records = (ha_rows)n_rows;
  7760. stats.deleted = 0;
  7761. stats.data_file_length
  7762. = ((ulonglong) ib_table->stat_clustered_index_size)
  7763. * page_size;
  7764. stats.index_file_length =
  7765. ((ulonglong) ib_table->stat_sum_of_other_index_sizes)
  7766. * page_size;
  7767. dict_table_stats_unlock(ib_table, RW_S_LATCH);
  7768. /* Since fsp_get_available_space_in_free_extents() is
  7769. acquiring latches inside InnoDB, we do not call it if we
  7770. are asked by MySQL to avoid locking. Another reason to
  7771. avoid the call is that it uses quite a lot of CPU.
  7772. See Bug#38185. */
  7773. if (flag & HA_STATUS_NO_LOCK || !srv_stats_update_need_lock
  7774. || !(flag & HA_STATUS_VARIABLE_EXTRA)) {
  7775. /* We do not update delete_length if no
  7776. locking is requested so the "old" value can
  7777. remain. delete_length is initialized to 0 in
  7778. the ha_statistics' constructor. Also we only
  7779. need delete_length to be set when
  7780. HA_STATUS_VARIABLE_EXTRA is set */
  7781. } else if (UNIV_UNLIKELY
  7782. (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE)) {
  7783. /* Avoid accessing the tablespace if
  7784. innodb_crash_recovery is set to a high value. */
  7785. stats.delete_length = 0;
  7786. } else {
  7787. ullint avail_space;
  7788. avail_space = fsp_get_available_space_in_free_extents(
  7789. ib_table->space);
  7790. if (avail_space == ULLINT_UNDEFINED) {
  7791. THD* thd;
  7792. thd = ha_thd();
  7793. push_warning_printf(
  7794. thd,
  7795. MYSQL_ERROR::WARN_LEVEL_WARN,
  7796. ER_CANT_GET_STAT,
  7797. "InnoDB: Trying to get the free "
  7798. "space for table %s but its "
  7799. "tablespace has been discarded or "
  7800. "the .ibd file is missing. Setting "
  7801. "the free space to zero.",
  7802. ib_table->name);
  7803. stats.delete_length = 0;
  7804. } else {
  7805. stats.delete_length = avail_space * 1024;
  7806. }
  7807. }
  7808. stats.check_time = 0;
  7809. stats.mrr_length_per_rec= ref_length + portable_sizeof_char_ptr;
  7810. if (stats.records == 0) {
  7811. stats.mean_rec_length = 0;
  7812. } else {
  7813. stats.mean_rec_length = (ulong) (stats.data_file_length / stats.records);
  7814. }
  7815. }
  7816. if (flag & HA_STATUS_CONST) {
  7817. ulong i;
  7818. /* Verify the number of index in InnoDB and MySQL
  7819. matches up. If prebuilt->clust_index_was_generated
  7820. holds, InnoDB defines GEN_CLUST_INDEX internally */
  7821. ulint num_innodb_index = UT_LIST_GET_LEN(ib_table->indexes)
  7822. - prebuilt->clust_index_was_generated;
  7823. if (table->s->keys != num_innodb_index) {
  7824. sql_print_error("Table %s contains %lu "
  7825. "indexes inside InnoDB, which "
  7826. "is different from the number of "
  7827. "indexes %u defined in the MySQL ",
  7828. ib_table->name, num_innodb_index,
  7829. table->s->keys);
  7830. }
  7831. dict_table_stats_lock(ib_table, RW_S_LATCH);
  7832. for (i = 0; i < table->s->keys; i++) {
  7833. ulong j;
  7834. rec_per_key = 1;
  7835. /* We could get index quickly through internal
  7836. index mapping with the index translation table.
  7837. The identity of index (match up index name with
  7838. that of table->key_info[i]) is already verified in
  7839. innobase_get_index(). */
  7840. index = innobase_get_index(i);
  7841. if (index == NULL) {
  7842. sql_print_error("Table %s contains fewer "
  7843. "indexes inside InnoDB than "
  7844. "are defined in the MySQL "
  7845. ".frm file. Have you mixed up "
  7846. ".frm files from different "
  7847. "installations? See "
  7848. REFMAN
  7849. "innodb-troubleshooting.html\n",
  7850. ib_table->name);
  7851. break;
  7852. }
  7853. for (j = 0; j < table->key_info[i].key_parts; j++) {
  7854. if (j + 1 > index->n_uniq) {
  7855. sql_print_error(
  7856. "Index %s of %s has %lu columns unique inside InnoDB, but MySQL is asking "
  7857. "statistics for %lu columns. Have you mixed up .frm files from different "
  7858. "installations? "
  7859. "See " REFMAN "innodb-troubleshooting.html\n",
  7860. index->name,
  7861. ib_table->name,
  7862. (unsigned long)
  7863. index->n_uniq, j + 1);
  7864. break;
  7865. }
  7866. rec_per_key = innodb_rec_per_key(
  7867. index, j, stats.records);
  7868. /* Since MySQL seems to favor table scans
  7869. too much over index searches, we pretend
  7870. index selectivity is 2 times better than
  7871. our estimate: */
  7872. rec_per_key = rec_per_key / 2;
  7873. if (rec_per_key == 0) {
  7874. rec_per_key = 1;
  7875. }
  7876. table->key_info[i].rec_per_key[j]=
  7877. rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
  7878. (ulong) rec_per_key;
  7879. }
  7880. KEY *key_info= table->key_info+i;
  7881. key_part_map ext_key_part_map=
  7882. key_info->ext_key_part_map;
  7883. if (key_info->key_parts != key_info->ext_key_parts) {
  7884. KEY *pk_key_info= key_info+
  7885. table->s->primary_key;
  7886. uint k = key_info->key_parts;
  7887. ha_rows k_rec_per_key = rec_per_key;
  7888. uint pk_parts = pk_key_info->key_parts;
  7889. index= innobase_get_index(
  7890. table->s->primary_key);
  7891. n_rows= ib_table->stat_n_rows;
  7892. for (j = 0; j < pk_parts; j++) {
  7893. if (ext_key_part_map & 1<<j) {
  7894. rec_per_key =
  7895. innodb_rec_per_key(index,
  7896. j, stats.records);
  7897. if (rec_per_key == 0) {
  7898. rec_per_key = 1;
  7899. }
  7900. else if (rec_per_key > 1) {
  7901. rec_per_key =
  7902. (ha_rows)
  7903. (k_rec_per_key *
  7904. (double)rec_per_key /
  7905. n_rows);
  7906. }
  7907. key_info->rec_per_key[k++]=
  7908. rec_per_key >= ~(ulong) 0 ?
  7909. ~(ulong) 0 :
  7910. (ulong) rec_per_key;
  7911. }
  7912. }
  7913. }
  7914. }
  7915. dict_table_stats_unlock(ib_table, RW_S_LATCH);
  7916. }
  7917. if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
  7918. goto func_exit;
  7919. }
  7920. if (flag & HA_STATUS_ERRKEY) {
  7921. const dict_index_t* err_index;
  7922. ut_a(prebuilt->trx);
  7923. ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
  7924. err_index = trx_get_error_info(prebuilt->trx);
  7925. if (err_index) {
  7926. errkey = innobase_get_mysql_key_number_for_index(
  7927. share, table, ib_table, err_index);
  7928. } else {
  7929. errkey = (unsigned int) prebuilt->trx->error_key_num;
  7930. }
  7931. }
  7932. if ((flag & HA_STATUS_AUTO) && table->found_next_number_field) {
  7933. stats.auto_increment_value = innobase_peek_autoinc();
  7934. }
  7935. func_exit:
  7936. prebuilt->trx->op_info = (char*)"";
  7937. DBUG_RETURN(0);
  7938. }
  7939. /*********************************************************************//**
  7940. Returns statistics information of the table to the MySQL interpreter,
  7941. in various fields of the handle object. */
  7942. UNIV_INTERN
  7943. int
  7944. ha_innobase::info(
  7945. /*==============*/
  7946. uint flag) /*!< in: what information MySQL requests */
  7947. {
  7948. return(info_low(flag, false /* not called from analyze */));
  7949. }
  7950. /**********************************************************************//**
  7951. Updates index cardinalities of the table, based on 8 random dives into
  7952. each index tree. This does NOT calculate exact statistics on the table.
  7953. @return returns always 0 (success) */
  7954. UNIV_INTERN
  7955. int
  7956. ha_innobase::analyze(
  7957. /*=================*/
  7958. THD* thd, /*!< in: connection thread handle */
  7959. HA_CHECK_OPT* check_opt) /*!< in: currently ignored */
  7960. {
  7961. if (share->ib_table->is_corrupt) {
  7962. return(HA_ADMIN_CORRUPT);
  7963. }
  7964. /* Simply call ::info() with all the flags */
  7965. info_low(HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE,
  7966. true /* called from analyze */);
  7967. if (share->ib_table->is_corrupt) {
  7968. return(HA_ADMIN_CORRUPT);
  7969. }
  7970. return(0);
  7971. }
  7972. /**********************************************************************//**
  7973. This is mapped to "ALTER TABLE tablename ENGINE=InnoDB", which rebuilds
  7974. the table in MySQL. */
  7975. UNIV_INTERN
  7976. int
  7977. ha_innobase::optimize(
  7978. /*==================*/
  7979. THD* thd, /*!< in: connection thread handle */
  7980. HA_CHECK_OPT* check_opt) /*!< in: currently ignored */
  7981. {
  7982. return(HA_ADMIN_TRY_ALTER);
  7983. }
  7984. /*******************************************************************//**
  7985. Tries to check that an InnoDB table is not corrupted. If corruption is
  7986. noticed, prints to stderr information about it. In case of corruption
  7987. may also assert a failure and crash the server.
  7988. @return HA_ADMIN_CORRUPT or HA_ADMIN_OK */
  7989. UNIV_INTERN
  7990. int
  7991. ha_innobase::check(
  7992. /*===============*/
  7993. THD* thd, /*!< in: user thread handle */
  7994. HA_CHECK_OPT* check_opt) /*!< in: check options, currently
  7995. ignored */
  7996. {
  7997. dict_index_t* index;
  7998. ulint n_rows;
  7999. ulint n_rows_in_table = ULINT_UNDEFINED;
  8000. ibool is_ok = TRUE;
  8001. ulint old_isolation_level;
  8002. ibool table_corrupted;
  8003. DBUG_ENTER("ha_innobase::check");
  8004. DBUG_ASSERT(thd == ha_thd());
  8005. ut_a(prebuilt->trx);
  8006. ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
  8007. ut_a(prebuilt->trx == thd_to_trx(thd));
  8008. if (prebuilt->mysql_template == NULL) {
  8009. /* Build the template; we will use a dummy template
  8010. in index scans done in checking */
  8011. build_template(true);
  8012. }
  8013. if (prebuilt->table->ibd_file_missing) {
  8014. sql_print_error("InnoDB: Error:\n"
  8015. "InnoDB: MySQL is trying to use a table handle"
  8016. " but the .ibd file for\n"
  8017. "InnoDB: table %s does not exist.\n"
  8018. "InnoDB: Have you deleted the .ibd file"
  8019. " from the database directory under\n"
  8020. "InnoDB: the MySQL datadir, or have you"
  8021. " used DISCARD TABLESPACE?\n"
  8022. "InnoDB: Please refer to\n"
  8023. "InnoDB: " REFMAN "innodb-troubleshooting.html\n"
  8024. "InnoDB: how you can resolve the problem.\n",
  8025. prebuilt->table->name);
  8026. DBUG_RETURN(HA_ADMIN_CORRUPT);
  8027. }
  8028. prebuilt->trx->op_info = "checking table";
  8029. old_isolation_level = prebuilt->trx->isolation_level;
  8030. /* We must run the index record counts at an isolation level
  8031. >= READ COMMITTED, because a dirty read can see a wrong number
  8032. of records in some index; to play safe, we use always
  8033. REPEATABLE READ here */
  8034. prebuilt->trx->isolation_level = TRX_ISO_REPEATABLE_READ;
  8035. /* Check whether the table is already marked as corrupted
  8036. before running the check table */
  8037. table_corrupted = prebuilt->table->corrupted;
  8038. /* Reset table->corrupted bit so that check table can proceed to
  8039. do additional check */
  8040. prebuilt->table->corrupted = FALSE;
  8041. /* Enlarge the fatal lock wait timeout during CHECK TABLE. */
  8042. mutex_enter(&kernel_mutex);
  8043. srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION;
  8044. mutex_exit(&kernel_mutex);
  8045. for (index = dict_table_get_first_index(prebuilt->table);
  8046. index != NULL;
  8047. index = dict_table_get_next_index(index)) {
  8048. char index_name[MAX_FULL_NAME_LEN + 1];
  8049. #if 0
  8050. fputs("Validating index ", stderr);
  8051. ut_print_name(stderr, trx, FALSE, index->name);
  8052. putc('\n', stderr);
  8053. #endif
  8054. /* If this is an index being created, break */
  8055. if (*index->name == TEMP_INDEX_PREFIX) {
  8056. break;
  8057. } else if (!btr_validate_index(index, prebuilt->trx)) {
  8058. is_ok = FALSE;
  8059. innobase_format_name(
  8060. index_name, sizeof index_name,
  8061. prebuilt->index->name, TRUE);
  8062. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  8063. ER_NOT_KEYFILE,
  8064. "InnoDB: The B-tree of"
  8065. " index %s is corrupted.",
  8066. index_name);
  8067. continue;
  8068. }
  8069. /* Instead of invoking change_active_index(), set up
  8070. a dummy template for non-locking reads, disabling
  8071. access to the clustered index. */
  8072. prebuilt->index = index;
  8073. prebuilt->index_usable = row_merge_is_index_usable(
  8074. prebuilt->trx, prebuilt->index);
  8075. if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
  8076. innobase_format_name(
  8077. index_name, sizeof index_name,
  8078. prebuilt->index->name, TRUE);
  8079. if (dict_index_is_corrupted(prebuilt->index)) {
  8080. push_warning_printf(
  8081. user_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  8082. HA_ERR_INDEX_CORRUPT,
  8083. "InnoDB: Index %s is marked as"
  8084. " corrupted",
  8085. index_name);
  8086. is_ok = FALSE;
  8087. } else {
  8088. push_warning_printf(
  8089. thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  8090. HA_ERR_TABLE_DEF_CHANGED,
  8091. "InnoDB: Insufficient history for"
  8092. " index %s",
  8093. index_name);
  8094. }
  8095. continue;
  8096. }
  8097. prebuilt->sql_stat_start = TRUE;
  8098. prebuilt->template_type = ROW_MYSQL_DUMMY_TEMPLATE;
  8099. prebuilt->n_template = 0;
  8100. prebuilt->need_to_access_clustered = FALSE;
  8101. dtuple_set_n_fields(prebuilt->search_tuple, 0);
  8102. prebuilt->select_lock_type = LOCK_NONE;
  8103. if (!row_check_index_for_mysql(prebuilt, index, &n_rows)) {
  8104. innobase_format_name(
  8105. index_name, sizeof index_name,
  8106. index->name, TRUE);
  8107. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  8108. ER_NOT_KEYFILE,
  8109. "InnoDB: The B-tree of"
  8110. " index %s is corrupted.",
  8111. index_name);
  8112. is_ok = FALSE;
  8113. row_mysql_lock_data_dictionary(prebuilt->trx);
  8114. dict_set_corrupted(index);
  8115. row_mysql_unlock_data_dictionary(prebuilt->trx);
  8116. }
  8117. if (thd_killed(user_thd)) {
  8118. break;
  8119. }
  8120. #if 0
  8121. fprintf(stderr, "%lu entries in index %s\n", n_rows,
  8122. index->name);
  8123. #endif
  8124. if (index == dict_table_get_first_index(prebuilt->table)) {
  8125. n_rows_in_table = n_rows;
  8126. } else if (n_rows != n_rows_in_table) {
  8127. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  8128. ER_NOT_KEYFILE,
  8129. "InnoDB: Index '%-.200s'"
  8130. " contains %lu entries,"
  8131. " should be %lu.",
  8132. index->name,
  8133. (ulong) n_rows,
  8134. (ulong) n_rows_in_table);
  8135. is_ok = FALSE;
  8136. }
  8137. }
  8138. if (table_corrupted) {
  8139. /* If some previous operation has marked the table as
  8140. corrupted in memory, and has not propagated such to
  8141. clustered index, we will do so here */
  8142. index = dict_table_get_first_index(prebuilt->table);
  8143. if (!dict_index_is_corrupted(index)) {
  8144. mutex_enter(&dict_sys->mutex);
  8145. dict_set_corrupted(index);
  8146. mutex_exit(&dict_sys->mutex);
  8147. }
  8148. prebuilt->table->corrupted = TRUE;
  8149. }
  8150. /* Restore the original isolation level */
  8151. prebuilt->trx->isolation_level = old_isolation_level;
  8152. /* We validate also the whole adaptive hash index for all tables
  8153. at every CHECK TABLE */
  8154. if (!btr_search_validate()) {
  8155. push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  8156. ER_NOT_KEYFILE,
  8157. "InnoDB: The adaptive hash index is corrupted.");
  8158. is_ok = FALSE;
  8159. }
  8160. /* Restore the fatal lock wait timeout after CHECK TABLE. */
  8161. mutex_enter(&kernel_mutex);
  8162. srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION;
  8163. mutex_exit(&kernel_mutex);
  8164. prebuilt->trx->op_info = "";
  8165. if (thd_killed(user_thd)) {
  8166. my_error(ER_QUERY_INTERRUPTED, MYF(0));
  8167. }
  8168. if (share->ib_table->is_corrupt) {
  8169. return(HA_ADMIN_CORRUPT);
  8170. }
  8171. DBUG_RETURN(is_ok ? HA_ADMIN_OK : HA_ADMIN_CORRUPT);
  8172. }
  8173. /*************************************************************//**
  8174. Adds information about free space in the InnoDB tablespace to a table comment
  8175. which is printed out when a user calls SHOW TABLE STATUS. Adds also info on
  8176. foreign keys.
  8177. @return table comment + InnoDB free space + info on foreign keys */
  8178. UNIV_INTERN
  8179. char*
  8180. ha_innobase::update_table_comment(
  8181. /*==============================*/
  8182. const char* comment)/*!< in: table comment defined by user */
  8183. {
  8184. uint length = (uint) strlen(comment);
  8185. char* str;
  8186. long flen;
  8187. /* We do not know if MySQL can call this function before calling
  8188. external_lock(). To be safe, update the thd of the current table
  8189. handle. */
  8190. if (length > 64000 - 3) {
  8191. return((char*)comment); /* string too long */
  8192. }
  8193. update_thd(ha_thd());
  8194. prebuilt->trx->op_info = (char*)"returning table comment";
  8195. /* In case MySQL calls this in the middle of a SELECT query, release
  8196. possible adaptive hash latch to avoid deadlocks of threads */
  8197. trx_search_latch_release_if_reserved(prebuilt->trx);
  8198. str = NULL;
  8199. /* output the data to a temporary file */
  8200. mutex_enter(&srv_dict_tmpfile_mutex);
  8201. rewind(srv_dict_tmpfile);
  8202. fprintf(srv_dict_tmpfile, "InnoDB free: %llu kB",
  8203. fsp_get_available_space_in_free_extents(
  8204. prebuilt->table->space));
  8205. dict_print_info_on_foreign_keys(FALSE, srv_dict_tmpfile,
  8206. prebuilt->trx, prebuilt->table);
  8207. flen = ftell(srv_dict_tmpfile);
  8208. if (flen < 0) {
  8209. flen = 0;
  8210. } else if (length + flen + 3 > 64000) {
  8211. flen = 64000 - 3 - length;
  8212. }
  8213. /* allocate buffer for the full string, and
  8214. read the contents of the temporary file */
  8215. str = (char*) my_malloc(length + flen + 3, MYF(0));
  8216. if (str) {
  8217. char* pos = str + length;
  8218. if (length) {
  8219. memcpy(str, comment, length);
  8220. *pos++ = ';';
  8221. *pos++ = ' ';
  8222. }
  8223. rewind(srv_dict_tmpfile);
  8224. flen = (uint) fread(pos, 1, flen, srv_dict_tmpfile);
  8225. pos[flen] = 0;
  8226. }
  8227. mutex_exit(&srv_dict_tmpfile_mutex);
  8228. prebuilt->trx->op_info = (char*)"";
  8229. return(str ? str : (char*) comment);
  8230. }
  8231. /*******************************************************************//**
  8232. Gets the foreign key create info for a table stored in InnoDB.
  8233. @return own: character string in the form which can be inserted to the
  8234. CREATE TABLE statement, MUST be freed with
  8235. ha_innobase::free_foreign_key_create_info */
  8236. UNIV_INTERN
  8237. char*
  8238. ha_innobase::get_foreign_key_create_info(void)
  8239. /*==========================================*/
  8240. {
  8241. char* str = 0;
  8242. long flen;
  8243. ut_a(prebuilt != NULL);
  8244. /* We do not know if MySQL can call this function before calling
  8245. external_lock(). To be safe, update the thd of the current table
  8246. handle. */
  8247. update_thd(ha_thd());
  8248. prebuilt->trx->op_info = (char*)"getting info on foreign keys";
  8249. /* In case MySQL calls this in the middle of a SELECT query,
  8250. release possible adaptive hash latch to avoid
  8251. deadlocks of threads */
  8252. trx_search_latch_release_if_reserved(prebuilt->trx);
  8253. mutex_enter(&srv_dict_tmpfile_mutex);
  8254. rewind(srv_dict_tmpfile);
  8255. /* output the data to a temporary file */
  8256. dict_print_info_on_foreign_keys(TRUE, srv_dict_tmpfile,
  8257. prebuilt->trx, prebuilt->table);
  8258. prebuilt->trx->op_info = (char*)"";
  8259. flen = ftell(srv_dict_tmpfile);
  8260. if (flen < 0) {
  8261. flen = 0;
  8262. }
  8263. /* allocate buffer for the string, and
  8264. read the contents of the temporary file */
  8265. str = (char*) my_malloc(flen + 1, MYF(0));
  8266. if (str) {
  8267. rewind(srv_dict_tmpfile);
  8268. flen = (uint) fread(str, 1, flen, srv_dict_tmpfile);
  8269. str[flen] = 0;
  8270. }
  8271. mutex_exit(&srv_dict_tmpfile_mutex);
  8272. return(str);
  8273. }
  8274. /***********************************************************************//**
  8275. Maps a InnoDB foreign key constraint to a equivalent MySQL foreign key info.
  8276. @return pointer to foreign key info */
  8277. static
  8278. FOREIGN_KEY_INFO*
  8279. get_foreign_key_info(
  8280. /*=================*/
  8281. THD* thd, /*!< in: user thread handle */
  8282. dict_foreign_t* foreign) /*!< in: foreign key constraint */
  8283. {
  8284. FOREIGN_KEY_INFO f_key_info;
  8285. FOREIGN_KEY_INFO* pf_key_info;
  8286. uint i = 0;
  8287. ulint len;
  8288. char tmp_buff[NAME_LEN+1];
  8289. char name_buff[NAME_LEN+1];
  8290. const char* ptr;
  8291. LEX_STRING* referenced_key_name;
  8292. LEX_STRING* name = NULL;
  8293. ptr = dict_remove_db_name(foreign->id);
  8294. f_key_info.foreign_id = thd_make_lex_string(thd, 0, ptr,
  8295. (uint) strlen(ptr), 1);
  8296. /* Name format: database name, '/', table name, '\0' */
  8297. /* Referenced (parent) database name */
  8298. len = dict_get_db_name_len(foreign->referenced_table_name);
  8299. ut_a(len < sizeof(tmp_buff));
  8300. ut_memcpy(tmp_buff, foreign->referenced_table_name, len);
  8301. tmp_buff[len] = 0;
  8302. len = filename_to_tablename(tmp_buff, name_buff, sizeof(name_buff));
  8303. f_key_info.referenced_db = thd_make_lex_string(thd, 0, name_buff, len, 1);
  8304. /* Referenced (parent) table name */
  8305. ptr = dict_remove_db_name(foreign->referenced_table_name);
  8306. len = filename_to_tablename(ptr, name_buff, sizeof(name_buff));
  8307. f_key_info.referenced_table = thd_make_lex_string(thd, 0, name_buff, len, 1);
  8308. /* Dependent (child) database name */
  8309. len = dict_get_db_name_len(foreign->foreign_table_name);
  8310. ut_a(len < sizeof(tmp_buff));
  8311. ut_memcpy(tmp_buff, foreign->foreign_table_name, len);
  8312. tmp_buff[len] = 0;
  8313. len = filename_to_tablename(tmp_buff, name_buff, sizeof(name_buff));
  8314. f_key_info.foreign_db = thd_make_lex_string(thd, 0, name_buff, len, 1);
  8315. /* Dependent (child) table name */
  8316. ptr = dict_remove_db_name(foreign->foreign_table_name);
  8317. len = filename_to_tablename(ptr, name_buff, sizeof(name_buff));
  8318. f_key_info.foreign_table = thd_make_lex_string(thd, 0, name_buff, len, 1);
  8319. do {
  8320. ptr = foreign->foreign_col_names[i];
  8321. name = thd_make_lex_string(thd, name, ptr,
  8322. (uint) strlen(ptr), 1);
  8323. f_key_info.foreign_fields.push_back(name);
  8324. ptr = foreign->referenced_col_names[i];
  8325. name = thd_make_lex_string(thd, name, ptr,
  8326. (uint) strlen(ptr), 1);
  8327. f_key_info.referenced_fields.push_back(name);
  8328. } while (++i < foreign->n_fields);
  8329. if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) {
  8330. len = 7;
  8331. ptr = "CASCADE";
  8332. } else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) {
  8333. len = 8;
  8334. ptr = "SET NULL";
  8335. } else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
  8336. len = 9;
  8337. ptr = "NO ACTION";
  8338. } else {
  8339. len = 8;
  8340. ptr = "RESTRICT";
  8341. }
  8342. f_key_info.delete_method = thd_make_lex_string(thd,
  8343. f_key_info.delete_method,
  8344. ptr, len, 1);
  8345. if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) {
  8346. len = 7;
  8347. ptr = "CASCADE";
  8348. } else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) {
  8349. len = 8;
  8350. ptr = "SET NULL";
  8351. } else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
  8352. len = 9;
  8353. ptr = "NO ACTION";
  8354. } else {
  8355. len = 8;
  8356. ptr = "RESTRICT";
  8357. }
  8358. f_key_info.update_method = thd_make_lex_string(thd,
  8359. f_key_info.update_method,
  8360. ptr, len, 1);
  8361. if (foreign->referenced_index && foreign->referenced_index->name) {
  8362. referenced_key_name = thd_make_lex_string(thd,
  8363. f_key_info.referenced_key_name,
  8364. foreign->referenced_index->name,
  8365. (uint) strlen(foreign->referenced_index->name),
  8366. 1);
  8367. } else {
  8368. referenced_key_name = NULL;
  8369. }
  8370. f_key_info.referenced_key_name = referenced_key_name;
  8371. pf_key_info = (FOREIGN_KEY_INFO *) thd_memdup(thd, &f_key_info,
  8372. sizeof(FOREIGN_KEY_INFO));
  8373. return(pf_key_info);
  8374. }
  8375. /*******************************************************************//**
  8376. Gets the list of foreign keys in this table.
  8377. @return always 0, that is, always succeeds */
  8378. UNIV_INTERN
  8379. int
  8380. ha_innobase::get_foreign_key_list(
  8381. /*==============================*/
  8382. THD* thd, /*!< in: user thread handle */
  8383. List<FOREIGN_KEY_INFO>* f_key_list) /*!< out: foreign key list */
  8384. {
  8385. FOREIGN_KEY_INFO* pf_key_info;
  8386. dict_foreign_t* foreign;
  8387. ut_a(prebuilt != NULL);
  8388. update_thd(ha_thd());
  8389. prebuilt->trx->op_info = "getting list of foreign keys";
  8390. trx_search_latch_release_if_reserved(prebuilt->trx);
  8391. mutex_enter(&(dict_sys->mutex));
  8392. for (foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
  8393. foreign != NULL;
  8394. foreign = UT_LIST_GET_NEXT(foreign_list, foreign)) {
  8395. pf_key_info = get_foreign_key_info(thd, foreign);
  8396. if (pf_key_info) {
  8397. f_key_list->push_back(pf_key_info);
  8398. }
  8399. }
  8400. mutex_exit(&(dict_sys->mutex));
  8401. prebuilt->trx->op_info = "";
  8402. return(0);
  8403. }
  8404. /*******************************************************************//**
  8405. Gets the set of foreign keys where this table is the referenced table.
  8406. @return always 0, that is, always succeeds */
  8407. UNIV_INTERN
  8408. int
  8409. ha_innobase::get_parent_foreign_key_list(
  8410. /*=====================================*/
  8411. THD* thd, /*!< in: user thread handle */
  8412. List<FOREIGN_KEY_INFO>* f_key_list) /*!< out: foreign key list */
  8413. {
  8414. FOREIGN_KEY_INFO* pf_key_info;
  8415. dict_foreign_t* foreign;
  8416. ut_a(prebuilt != NULL);
  8417. update_thd(ha_thd());
  8418. prebuilt->trx->op_info = "getting list of referencing foreign keys";
  8419. trx_search_latch_release_if_reserved(prebuilt->trx);
  8420. mutex_enter(&(dict_sys->mutex));
  8421. for (foreign = UT_LIST_GET_FIRST(prebuilt->table->referenced_list);
  8422. foreign != NULL;
  8423. foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) {
  8424. pf_key_info = get_foreign_key_info(thd, foreign);
  8425. if (pf_key_info) {
  8426. f_key_list->push_back(pf_key_info);
  8427. }
  8428. }
  8429. mutex_exit(&(dict_sys->mutex));
  8430. prebuilt->trx->op_info = "";
  8431. return(0);
  8432. }
  8433. /*****************************************************************//**
  8434. Checks if ALTER TABLE may change the storage engine of the table.
  8435. Changing storage engines is not allowed for tables for which there
  8436. are foreign key constraints (parent or child tables).
  8437. @return TRUE if can switch engines */
  8438. UNIV_INTERN
  8439. bool
  8440. ha_innobase::can_switch_engines(void)
  8441. /*=================================*/
  8442. {
  8443. bool can_switch;
  8444. DBUG_ENTER("ha_innobase::can_switch_engines");
  8445. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  8446. prebuilt->trx->op_info =
  8447. "determining if there are foreign key constraints";
  8448. row_mysql_lock_data_dictionary(prebuilt->trx);
  8449. can_switch = !UT_LIST_GET_FIRST(prebuilt->table->referenced_list)
  8450. && !UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
  8451. row_mysql_unlock_data_dictionary(prebuilt->trx);
  8452. prebuilt->trx->op_info = "";
  8453. DBUG_RETURN(can_switch);
  8454. }
  8455. /*******************************************************************//**
  8456. Checks if a table is referenced by a foreign key. The MySQL manual states that
  8457. a REPLACE is either equivalent to an INSERT, or DELETE(s) + INSERT. Only a
  8458. delete is then allowed internally to resolve a duplicate key conflict in
  8459. REPLACE, not an update.
  8460. @return > 0 if referenced by a FOREIGN KEY */
  8461. UNIV_INTERN
  8462. uint
  8463. ha_innobase::referenced_by_foreign_key(void)
  8464. /*========================================*/
  8465. {
  8466. if (dict_table_is_referenced_by_foreign_key(prebuilt->table)) {
  8467. return(1);
  8468. }
  8469. return(0);
  8470. }
  8471. /*******************************************************************//**
  8472. Frees the foreign key create info for a table stored in InnoDB, if it is
  8473. non-NULL. */
  8474. UNIV_INTERN
  8475. void
  8476. ha_innobase::free_foreign_key_create_info(
  8477. /*======================================*/
  8478. char* str) /*!< in, own: create info string to free */
  8479. {
  8480. if (str) {
  8481. my_free(str);
  8482. }
  8483. }
  8484. /*******************************************************************//**
  8485. Tells something additional to the handler about how to do things.
  8486. @return 0 or error number */
  8487. UNIV_INTERN
  8488. int
  8489. ha_innobase::extra(
  8490. /*===============*/
  8491. enum ha_extra_function operation)
  8492. /*!< in: HA_EXTRA_FLUSH or some other flag */
  8493. {
  8494. /* Warning: since it is not sure that MySQL calls external_lock
  8495. before calling this function, the trx field in prebuilt can be
  8496. obsolete! */
  8497. switch (operation) {
  8498. case HA_EXTRA_FLUSH:
  8499. if (prebuilt->blob_heap) {
  8500. row_mysql_prebuilt_free_blob_heap(prebuilt);
  8501. }
  8502. break;
  8503. case HA_EXTRA_RESET_STATE:
  8504. reset_template();
  8505. thd_to_trx(ha_thd())->duplicates = 0;
  8506. break;
  8507. case HA_EXTRA_NO_KEYREAD:
  8508. prebuilt->read_just_key = 0;
  8509. break;
  8510. case HA_EXTRA_KEYREAD:
  8511. prebuilt->read_just_key = 1;
  8512. break;
  8513. case HA_EXTRA_KEYREAD_PRESERVE_FIELDS:
  8514. prebuilt->keep_other_fields_on_keyread = 1;
  8515. break;
  8516. /* IMPORTANT: prebuilt->trx can be obsolete in
  8517. this method, because it is not sure that MySQL
  8518. calls external_lock before this method with the
  8519. parameters below. We must not invoke update_thd()
  8520. either, because the calling threads may change.
  8521. CAREFUL HERE, OR MEMORY CORRUPTION MAY OCCUR! */
  8522. case HA_EXTRA_INSERT_WITH_UPDATE:
  8523. thd_to_trx(ha_thd())->duplicates |= TRX_DUP_IGNORE;
  8524. break;
  8525. case HA_EXTRA_NO_IGNORE_DUP_KEY:
  8526. thd_to_trx(ha_thd())->duplicates &= ~TRX_DUP_IGNORE;
  8527. break;
  8528. case HA_EXTRA_WRITE_CAN_REPLACE:
  8529. thd_to_trx(ha_thd())->duplicates |= TRX_DUP_REPLACE;
  8530. break;
  8531. case HA_EXTRA_WRITE_CANNOT_REPLACE:
  8532. thd_to_trx(ha_thd())->duplicates &= ~TRX_DUP_REPLACE;
  8533. break;
  8534. default:/* Do nothing */
  8535. ;
  8536. }
  8537. return(0);
  8538. }
  8539. UNIV_INTERN
  8540. int
  8541. ha_innobase::reset()
  8542. {
  8543. if (prebuilt->blob_heap) {
  8544. row_mysql_prebuilt_free_blob_heap(prebuilt);
  8545. }
  8546. reset_template();
  8547. ds_mrr.dsmrr_close();
  8548. /* TODO: This should really be reset in reset_template() but for now
  8549. it's safer to do it explicitly here. */
  8550. /* This is a statement level counter. */
  8551. prebuilt->autoinc_last_value = 0;
  8552. return(0);
  8553. }
  8554. /******************************************************************//**
  8555. MySQL calls this function at the start of each SQL statement inside LOCK
  8556. TABLES. Inside LOCK TABLES the ::external_lock method does not work to
  8557. mark SQL statement borders. Note also a special case: if a temporary table
  8558. is created inside LOCK TABLES, MySQL has not called external_lock() at all
  8559. on that table.
  8560. MySQL-5.0 also calls this before each statement in an execution of a stored
  8561. procedure. To make the execution more deterministic for binlogging, MySQL-5.0
  8562. locks all tables involved in a stored procedure with full explicit table
  8563. locks (thd_in_lock_tables(thd) holds in store_lock()) before executing the
  8564. procedure.
  8565. @return 0 or error code */
  8566. UNIV_INTERN
  8567. int
  8568. ha_innobase::start_stmt(
  8569. /*====================*/
  8570. THD* thd, /*!< in: handle to the user thread */
  8571. thr_lock_type lock_type)
  8572. {
  8573. trx_t* trx;
  8574. update_thd(thd);
  8575. trx = prebuilt->trx;
  8576. /* Here we release the search latch and the InnoDB thread FIFO ticket
  8577. if they were reserved. They should have been released already at the
  8578. end of the previous statement, but because inside LOCK TABLES the
  8579. lock count method does not work to mark the end of a SELECT statement,
  8580. that may not be the case. We MUST release the search latch before an
  8581. INSERT, for example. */
  8582. innobase_release_stat_resources(trx);
  8583. /* Reset the AUTOINC statement level counter for multi-row INSERTs. */
  8584. trx->n_autoinc_rows = 0;
  8585. prebuilt->sql_stat_start = TRUE;
  8586. prebuilt->hint_need_to_fetch_extra_cols = 0;
  8587. reset_template();
  8588. if (!prebuilt->mysql_has_locked) {
  8589. /* This handle is for a temporary table created inside
  8590. this same LOCK TABLES; since MySQL does NOT call external_lock
  8591. in this case, we must use x-row locks inside InnoDB to be
  8592. prepared for an update of a row */
  8593. prebuilt->select_lock_type = LOCK_X;
  8594. } else if (trx->isolation_level != TRX_ISO_SERIALIZABLE
  8595. && thd_sql_command(thd) == SQLCOM_SELECT
  8596. && lock_type == TL_READ) {
  8597. /* For other than temporary tables, we obtain
  8598. no lock for consistent read (plain SELECT). */
  8599. prebuilt->select_lock_type = LOCK_NONE;
  8600. } else {
  8601. /* Not a consistent read: restore the
  8602. select_lock_type value. The value of
  8603. stored_select_lock_type was decided in:
  8604. 1) ::store_lock(),
  8605. 2) ::external_lock(),
  8606. 3) ::init_table_handle_for_HANDLER(), and
  8607. 4) ::transactional_table_lock(). */
  8608. prebuilt->select_lock_type = prebuilt->stored_select_lock_type;
  8609. }
  8610. *trx->detailed_error = 0;
  8611. innobase_register_trx(ht, thd, trx);
  8612. return(0);
  8613. }
  8614. /******************************************************************//**
  8615. Maps a MySQL trx isolation level code to the InnoDB isolation level code
  8616. @return InnoDB isolation level */
  8617. static inline
  8618. ulint
  8619. innobase_map_isolation_level(
  8620. /*=========================*/
  8621. enum_tx_isolation iso) /*!< in: MySQL isolation level code */
  8622. {
  8623. switch(iso) {
  8624. case ISO_REPEATABLE_READ: return(TRX_ISO_REPEATABLE_READ);
  8625. case ISO_READ_COMMITTED: return(TRX_ISO_READ_COMMITTED);
  8626. case ISO_SERIALIZABLE: return(TRX_ISO_SERIALIZABLE);
  8627. case ISO_READ_UNCOMMITTED: return(TRX_ISO_READ_UNCOMMITTED);
  8628. default: ut_a(0); return(0);
  8629. }
  8630. }
  8631. /******************************************************************//**
  8632. As MySQL will execute an external lock for every new table it uses when it
  8633. starts to process an SQL statement (an exception is when MySQL calls
  8634. start_stmt for the handle) we can use this function to store the pointer to
  8635. the THD in the handle. We will also use this function to communicate
  8636. to InnoDB that a new SQL statement has started and that we must store a
  8637. savepoint to our transaction handle, so that we are able to roll back
  8638. the SQL statement in case of an error.
  8639. @return 0 */
  8640. UNIV_INTERN
  8641. int
  8642. ha_innobase::external_lock(
  8643. /*=======================*/
  8644. THD* thd, /*!< in: handle to the user thread */
  8645. int lock_type) /*!< in: lock type */
  8646. {
  8647. trx_t* trx;
  8648. DBUG_ENTER("ha_innobase::external_lock");
  8649. DBUG_PRINT("enter",("lock_type: %d", lock_type));
  8650. update_thd(thd);
  8651. /* Statement based binlogging does not work in isolation level
  8652. READ UNCOMMITTED and READ COMMITTED since the necessary
  8653. locks cannot be taken. In this case, we print an
  8654. informative error message and return with an error.
  8655. Note: decide_logging_format would give the same error message,
  8656. except it cannot give the extra details. */
  8657. if (lock_type == F_WRLCK
  8658. && !(table_flags() & HA_BINLOG_STMT_CAPABLE)
  8659. && thd_binlog_format(thd) == BINLOG_FORMAT_STMT
  8660. && thd_binlog_filter_ok(thd)
  8661. && thd_sqlcom_can_generate_row_events(thd))
  8662. {
  8663. int skip = 0;
  8664. /* used by test case */
  8665. DBUG_EXECUTE_IF("no_innodb_binlog_errors", skip = 1;);
  8666. if (!skip) {
  8667. my_error(ER_BINLOG_STMT_MODE_AND_ROW_ENGINE, MYF(0),
  8668. " InnoDB is limited to row-logging when "
  8669. "transaction isolation level is "
  8670. "READ COMMITTED or READ UNCOMMITTED.");
  8671. DBUG_RETURN(HA_ERR_LOGGING_IMPOSSIBLE);
  8672. }
  8673. }
  8674. trx = prebuilt->trx;
  8675. prebuilt->sql_stat_start = TRUE;
  8676. prebuilt->hint_need_to_fetch_extra_cols = 0;
  8677. reset_template();
  8678. if (lock_type == F_WRLCK) {
  8679. /* If this is a SELECT, then it is in UPDATE TABLE ...
  8680. or SELECT ... FOR UPDATE */
  8681. prebuilt->select_lock_type = LOCK_X;
  8682. prebuilt->stored_select_lock_type = LOCK_X;
  8683. }
  8684. if (lock_type != F_UNLCK) {
  8685. /* MySQL is setting a new table lock */
  8686. *trx->detailed_error = 0;
  8687. innobase_register_trx(ht, thd, trx);
  8688. if (trx->isolation_level == TRX_ISO_SERIALIZABLE
  8689. && prebuilt->select_lock_type == LOCK_NONE
  8690. && thd_test_options(
  8691. thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  8692. /* To get serializable execution, we let InnoDB
  8693. conceptually add 'LOCK IN SHARE MODE' to all SELECTs
  8694. which otherwise would have been consistent reads. An
  8695. exception is consistent reads in the AUTOCOMMIT=1 mode:
  8696. we know that they are read-only transactions, and they
  8697. can be serialized also if performed as consistent
  8698. reads. */
  8699. prebuilt->select_lock_type = LOCK_S;
  8700. prebuilt->stored_select_lock_type = LOCK_S;
  8701. }
  8702. /* Starting from 4.1.9, no InnoDB table lock is taken in LOCK
  8703. TABLES if AUTOCOMMIT=1. It does not make much sense to acquire
  8704. an InnoDB table lock if it is released immediately at the end
  8705. of LOCK TABLES, and InnoDB's table locks in that case cause
  8706. VERY easily deadlocks.
  8707. We do not set InnoDB table locks if user has not explicitly
  8708. requested a table lock. Note that thd_in_lock_tables(thd)
  8709. can hold in some cases, e.g., at the start of a stored
  8710. procedure call (SQLCOM_CALL). */
  8711. if (prebuilt->select_lock_type != LOCK_NONE) {
  8712. if (thd_sql_command(thd) == SQLCOM_LOCK_TABLES
  8713. && THDVAR(thd, table_locks)
  8714. && thd_test_options(thd, OPTION_NOT_AUTOCOMMIT)
  8715. && thd_in_lock_tables(thd)) {
  8716. ulint error = row_lock_table_for_mysql(
  8717. prebuilt, NULL, 0);
  8718. if (error != DB_SUCCESS) {
  8719. error = convert_error_code_to_mysql(
  8720. (int) error, 0, thd);
  8721. DBUG_RETURN((int) error);
  8722. }
  8723. }
  8724. trx->mysql_n_tables_locked++;
  8725. }
  8726. trx->n_mysql_tables_in_use++;
  8727. prebuilt->mysql_has_locked = TRUE;
  8728. DBUG_RETURN(0);
  8729. }
  8730. /* MySQL is releasing a table lock */
  8731. trx->n_mysql_tables_in_use--;
  8732. prebuilt->mysql_has_locked = FALSE;
  8733. /* Release a possible FIFO ticket and search latch. Since we
  8734. may reserve the kernel mutex, we have to release the search
  8735. system latch first to obey the latching order. */
  8736. innobase_release_stat_resources(trx);
  8737. /* If the MySQL lock count drops to zero we know that the current SQL
  8738. statement has ended */
  8739. if (trx->n_mysql_tables_in_use == 0) {
  8740. #ifdef EXTENDED_SLOWLOG
  8741. increment_thd_innodb_stats(thd,
  8742. (unsigned long long) trx->id,
  8743. trx->io_reads,
  8744. trx->io_read,
  8745. trx->io_reads_wait_timer,
  8746. trx->lock_que_wait_timer,
  8747. trx->innodb_que_wait_timer,
  8748. trx->distinct_page_access);
  8749. trx->io_reads = 0;
  8750. trx->io_read = 0;
  8751. trx->io_reads_wait_timer = 0;
  8752. trx->lock_que_wait_timer = 0;
  8753. trx->innodb_que_wait_timer = 0;
  8754. trx->distinct_page_access = 0;
  8755. if (trx->distinct_page_access_hash)
  8756. memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
  8757. #endif
  8758. trx->mysql_n_tables_locked = 0;
  8759. prebuilt->used_in_HANDLER = FALSE;
  8760. if (!thd_test_options(
  8761. thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  8762. if (trx_is_started(trx)) {
  8763. innobase_commit(ht, thd, TRUE);
  8764. }
  8765. } else if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
  8766. && trx->global_read_view) {
  8767. /* At low transaction isolation levels we let
  8768. each consistent read set its own snapshot */
  8769. read_view_close_for_mysql(trx);
  8770. }
  8771. }
  8772. DBUG_RETURN(0);
  8773. }
  8774. /******************************************************************//**
  8775. With this function MySQL request a transactional lock to a table when
  8776. user issued query LOCK TABLES..WHERE ENGINE = InnoDB.
  8777. @return error code */
  8778. UNIV_INTERN
  8779. int
  8780. ha_innobase::transactional_table_lock(
  8781. /*==================================*/
  8782. THD* thd, /*!< in: handle to the user thread */
  8783. int lock_type) /*!< in: lock type */
  8784. {
  8785. trx_t* trx;
  8786. DBUG_ENTER("ha_innobase::transactional_table_lock");
  8787. DBUG_PRINT("enter",("lock_type: %d", lock_type));
  8788. /* We do not know if MySQL can call this function before calling
  8789. external_lock(). To be safe, update the thd of the current table
  8790. handle. */
  8791. update_thd(thd);
  8792. if (share->ib_table->is_corrupt) {
  8793. DBUG_RETURN(HA_ERR_CRASHED);
  8794. }
  8795. if (prebuilt->table->ibd_file_missing && !thd_tablespace_op(thd)) {
  8796. ut_print_timestamp(stderr);
  8797. fprintf(stderr,
  8798. " InnoDB: MySQL is trying to use a table handle"
  8799. " but the .ibd file for\n"
  8800. "InnoDB: table %s does not exist.\n"
  8801. "InnoDB: Have you deleted the .ibd file"
  8802. " from the database directory under\n"
  8803. "InnoDB: the MySQL datadir?"
  8804. "InnoDB: See " REFMAN
  8805. "innodb-troubleshooting.html\n"
  8806. "InnoDB: how you can resolve the problem.\n",
  8807. prebuilt->table->name);
  8808. DBUG_RETURN(HA_ERR_CRASHED);
  8809. }
  8810. trx = prebuilt->trx;
  8811. prebuilt->sql_stat_start = TRUE;
  8812. prebuilt->hint_need_to_fetch_extra_cols = 0;
  8813. reset_template();
  8814. if (lock_type == F_WRLCK) {
  8815. prebuilt->select_lock_type = LOCK_X;
  8816. prebuilt->stored_select_lock_type = LOCK_X;
  8817. } else if (lock_type == F_RDLCK) {
  8818. prebuilt->select_lock_type = LOCK_S;
  8819. prebuilt->stored_select_lock_type = LOCK_S;
  8820. } else {
  8821. ut_print_timestamp(stderr);
  8822. fprintf(stderr, " InnoDB error:\n"
  8823. "MySQL is trying to set transactional table lock with corrupted lock type\n"
  8824. "to table %s, lock type %d does not exist.\n",
  8825. prebuilt->table->name, lock_type);
  8826. DBUG_RETURN(HA_ERR_CRASHED);
  8827. }
  8828. /* MySQL is setting a new transactional table lock */
  8829. innobase_register_trx(ht, thd, trx);
  8830. if (THDVAR(thd, table_locks) && thd_in_lock_tables(thd)) {
  8831. ulint error = DB_SUCCESS;
  8832. error = row_lock_table_for_mysql(prebuilt, NULL, 0);
  8833. if (error != DB_SUCCESS) {
  8834. error = convert_error_code_to_mysql(
  8835. (int) error, prebuilt->table->flags, thd);
  8836. DBUG_RETURN((int) error);
  8837. }
  8838. if (thd_test_options(
  8839. thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  8840. /* Store the current undo_no of the transaction
  8841. so that we know where to roll back if we have
  8842. to roll back the next SQL statement */
  8843. trx_mark_sql_stat_end(trx);
  8844. }
  8845. }
  8846. DBUG_RETURN(0);
  8847. }
  8848. /************************************************************************//**
  8849. Here we export InnoDB status variables to MySQL. */
  8850. static
  8851. void
  8852. innodb_export_status(void)
  8853. /*======================*/
  8854. {
  8855. if (innodb_inited) {
  8856. srv_export_innodb_status();
  8857. }
  8858. }
  8859. /************************************************************************//**
  8860. Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
  8861. Monitor to the client. */
  8862. static
  8863. bool
  8864. innodb_show_status(
  8865. /*===============*/
  8866. handlerton* hton, /*!< in: the innodb handlerton */
  8867. THD* thd, /*!< in: the MySQL query thread of the caller */
  8868. stat_print_fn *stat_print)
  8869. {
  8870. trx_t* trx;
  8871. static const char truncated_msg[] = "... truncated...\n";
  8872. const long MAX_STATUS_SIZE = 1048576;
  8873. ulint trx_list_start = ULINT_UNDEFINED;
  8874. ulint trx_list_end = ULINT_UNDEFINED;
  8875. bool res;
  8876. DBUG_ENTER("innodb_show_status");
  8877. DBUG_ASSERT(hton == innodb_hton_ptr);
  8878. trx = check_trx_exists(thd);
  8879. innobase_release_stat_resources(trx);
  8880. /* We let the InnoDB Monitor to output at most MAX_STATUS_SIZE
  8881. bytes of text. */
  8882. long flen, usable_len;
  8883. char* str;
  8884. mutex_enter(&srv_monitor_file_mutex);
  8885. rewind(srv_monitor_file);
  8886. srv_printf_innodb_monitor(srv_monitor_file, FALSE,
  8887. &trx_list_start, &trx_list_end);
  8888. flen = ftell(srv_monitor_file);
  8889. os_file_set_eof(srv_monitor_file);
  8890. if (flen < 0) {
  8891. flen = 0;
  8892. }
  8893. if (flen > MAX_STATUS_SIZE) {
  8894. usable_len = MAX_STATUS_SIZE;
  8895. srv_truncated_status_writes++;
  8896. } else {
  8897. usable_len = flen;
  8898. }
  8899. /* allocate buffer for the string, and
  8900. read the contents of the temporary file */
  8901. if (!(str = (char*) my_malloc(usable_len + 1, MYF(0)))) {
  8902. mutex_exit(&srv_monitor_file_mutex);
  8903. DBUG_RETURN(TRUE);
  8904. }
  8905. rewind(srv_monitor_file);
  8906. if (flen < MAX_STATUS_SIZE) {
  8907. /* Display the entire output. */
  8908. flen = (long) fread(str, 1, flen, srv_monitor_file);
  8909. } else if (trx_list_end < (ulint) flen
  8910. && trx_list_start < trx_list_end
  8911. && trx_list_start + (flen - trx_list_end)
  8912. < MAX_STATUS_SIZE - sizeof truncated_msg - 1) {
  8913. /* Omit the beginning of the list of active transactions. */
  8914. long len = (long) fread(str, 1, trx_list_start, srv_monitor_file);
  8915. memcpy(str + len, truncated_msg, sizeof truncated_msg - 1);
  8916. len += sizeof truncated_msg - 1;
  8917. usable_len = (MAX_STATUS_SIZE - 1) - len;
  8918. fseek(srv_monitor_file, flen - usable_len, SEEK_SET);
  8919. len += (long) fread(str + len, 1, usable_len, srv_monitor_file);
  8920. flen = len;
  8921. } else {
  8922. /* Omit the end of the output. */
  8923. flen = (long) fread(str, 1, MAX_STATUS_SIZE - 1, srv_monitor_file);
  8924. }
  8925. mutex_exit(&srv_monitor_file_mutex);
  8926. res= stat_print(thd, innobase_hton_name,
  8927. (uint) strlen(innobase_hton_name),
  8928. STRING_WITH_LEN(""), str, flen);
  8929. my_free(str);
  8930. DBUG_RETURN(res);
  8931. }
  8932. /************************************************************************//**
  8933. Implements the SHOW MUTEX STATUS command.
  8934. @return TRUE on failure, FALSE on success. */
  8935. static
  8936. bool
  8937. innodb_mutex_show_status(
  8938. /*=====================*/
  8939. handlerton* hton, /*!< in: the innodb handlerton */
  8940. THD* thd, /*!< in: the MySQL query thread of the
  8941. caller */
  8942. stat_print_fn* stat_print) /*!< in: function for printing
  8943. statistics */
  8944. {
  8945. char buf1[IO_SIZE], buf2[IO_SIZE];
  8946. mutex_t* mutex;
  8947. rw_lock_t* lock;
  8948. ulint block_mutex_oswait_count = 0;
  8949. ulint block_lock_oswait_count = 0;
  8950. mutex_t* block_mutex = NULL;
  8951. rw_lock_t* block_lock = NULL;
  8952. #ifdef UNIV_DEBUG
  8953. ulint rw_lock_count= 0;
  8954. ulint rw_lock_count_spin_loop= 0;
  8955. ulint rw_lock_count_spin_rounds= 0;
  8956. ulint rw_lock_count_os_wait= 0;
  8957. ulint rw_lock_count_os_yield= 0;
  8958. ulonglong rw_lock_wait_time= 0;
  8959. #endif /* UNIV_DEBUG */
  8960. uint hton_name_len= (uint) strlen(innobase_hton_name), buf1len, buf2len;
  8961. DBUG_ENTER("innodb_mutex_show_status");
  8962. DBUG_ASSERT(hton == innodb_hton_ptr);
  8963. mutex_enter(&mutex_list_mutex);
  8964. for (mutex = UT_LIST_GET_FIRST(mutex_list); mutex != NULL;
  8965. mutex = UT_LIST_GET_NEXT(list, mutex)) {
  8966. if (mutex->count_os_wait == 0) {
  8967. continue;
  8968. }
  8969. if (buf_pool_is_block_mutex(mutex)) {
  8970. block_mutex = mutex;
  8971. block_mutex_oswait_count += mutex->count_os_wait;
  8972. continue;
  8973. }
  8974. #ifdef UNIV_DEBUG
  8975. if (mutex->mutex_type != 1) {
  8976. if (mutex->count_using > 0) {
  8977. buf1len= my_snprintf(buf1, sizeof(buf1),
  8978. "%s:%s",
  8979. mutex->cmutex_name,
  8980. innobase_basename(mutex->cfile_name));
  8981. buf2len= my_snprintf(buf2, sizeof(buf2),
  8982. "count=%lu, spin_waits=%lu,"
  8983. " spin_rounds=%lu, "
  8984. "os_waits=%lu, os_yields=%lu,"
  8985. " os_wait_times=%lu",
  8986. mutex->count_using,
  8987. mutex->count_spin_loop,
  8988. mutex->count_spin_rounds,
  8989. mutex->count_os_wait,
  8990. mutex->count_os_yield,
  8991. (ulong) (mutex->lspent_time/1000));
  8992. if (stat_print(thd, innobase_hton_name,
  8993. hton_name_len, buf1, buf1len,
  8994. buf2, buf2len)) {
  8995. mutex_exit(&mutex_list_mutex);
  8996. DBUG_RETURN(1);
  8997. }
  8998. }
  8999. } else {
  9000. rw_lock_count += mutex->count_using;
  9001. rw_lock_count_spin_loop += mutex->count_spin_loop;
  9002. rw_lock_count_spin_rounds += mutex->count_spin_rounds;
  9003. rw_lock_count_os_wait += mutex->count_os_wait;
  9004. rw_lock_count_os_yield += mutex->count_os_yield;
  9005. rw_lock_wait_time += mutex->lspent_time;
  9006. }
  9007. #else /* UNIV_DEBUG */
  9008. buf1len= (uint) my_snprintf(buf1, sizeof(buf1), "%s",
  9009. mutex->cmutex_name);
  9010. buf2len= (uint) my_snprintf(buf2, sizeof(buf2), "os_waits=%lu",
  9011. (ulong) mutex->count_os_wait);
  9012. if (stat_print(thd, innobase_hton_name,
  9013. hton_name_len, buf1, buf1len,
  9014. buf2, buf2len)) {
  9015. mutex_exit(&mutex_list_mutex);
  9016. DBUG_RETURN(1);
  9017. }
  9018. #endif /* UNIV_DEBUG */
  9019. }
  9020. if (block_mutex) {
  9021. buf1len = (uint) my_snprintf(buf1, sizeof buf1,
  9022. "combined %s",
  9023. block_mutex->cmutex_name);
  9024. buf2len = (uint) my_snprintf(buf2, sizeof buf2,
  9025. "os_waits=%lu",
  9026. (ulong) block_mutex_oswait_count);
  9027. if (stat_print(thd, innobase_hton_name,
  9028. hton_name_len, buf1, buf1len,
  9029. buf2, buf2len)) {
  9030. mutex_exit(&mutex_list_mutex);
  9031. DBUG_RETURN(1);
  9032. }
  9033. }
  9034. mutex_exit(&mutex_list_mutex);
  9035. mutex_enter(&rw_lock_list_mutex);
  9036. for (lock = UT_LIST_GET_FIRST(rw_lock_list); lock != NULL;
  9037. lock = UT_LIST_GET_NEXT(list, lock)) {
  9038. if (lock->count_os_wait == 0) {
  9039. continue;
  9040. }
  9041. if (buf_pool_is_block_lock(lock)) {
  9042. block_lock = lock;
  9043. block_lock_oswait_count += lock->count_os_wait;
  9044. continue;
  9045. }
  9046. buf1len = my_snprintf(buf1, sizeof buf1, "%s",
  9047. lock->lock_name);
  9048. buf2len = my_snprintf(buf2, sizeof buf2, "os_waits=%lu",
  9049. (ulong) lock->count_os_wait);
  9050. if (stat_print(thd, innobase_hton_name,
  9051. hton_name_len, buf1, buf1len,
  9052. buf2, buf2len)) {
  9053. mutex_exit(&rw_lock_list_mutex);
  9054. DBUG_RETURN(1);
  9055. }
  9056. }
  9057. if (block_lock) {
  9058. buf1len = (uint) my_snprintf(buf1, sizeof buf1,
  9059. "combined %s",
  9060. block_lock->lock_name);
  9061. buf2len = (uint) my_snprintf(buf2, sizeof buf2,
  9062. "os_waits=%lu",
  9063. (ulong) block_lock_oswait_count);
  9064. if (stat_print(thd, innobase_hton_name,
  9065. hton_name_len, buf1, buf1len,
  9066. buf2, buf2len)) {
  9067. mutex_exit(&rw_lock_list_mutex);
  9068. DBUG_RETURN(1);
  9069. }
  9070. }
  9071. mutex_exit(&rw_lock_list_mutex);
  9072. #ifdef UNIV_DEBUG
  9073. buf2len = my_snprintf(buf2, sizeof buf2,
  9074. "count=%lu, spin_waits=%lu, spin_rounds=%lu, "
  9075. "os_waits=%lu, os_yields=%lu, os_wait_times=%lu",
  9076. (ulong) rw_lock_count,
  9077. (ulong) rw_lock_count_spin_loop,
  9078. (ulong) rw_lock_count_spin_rounds,
  9079. (ulong) rw_lock_count_os_wait,
  9080. (ulong) rw_lock_count_os_yield,
  9081. (ulong) (rw_lock_wait_time / 1000));
  9082. if (stat_print(thd, innobase_hton_name, hton_name_len,
  9083. STRING_WITH_LEN("rw_lock_mutexes"), buf2, buf2len)) {
  9084. DBUG_RETURN(1);
  9085. }
  9086. #endif /* UNIV_DEBUG */
  9087. DBUG_RETURN(FALSE);
  9088. }
  9089. static
  9090. bool innobase_show_status(handlerton *hton, THD* thd,
  9091. stat_print_fn* stat_print,
  9092. enum ha_stat_type stat_type)
  9093. {
  9094. DBUG_ASSERT(hton == innodb_hton_ptr);
  9095. switch (stat_type) {
  9096. case HA_ENGINE_STATUS:
  9097. return innodb_show_status(hton, thd, stat_print);
  9098. case HA_ENGINE_MUTEX:
  9099. return innodb_mutex_show_status(hton, thd, stat_print);
  9100. default:
  9101. return(FALSE);
  9102. }
  9103. }
  9104. /************************************************************************//**
  9105. Handling the shared INNOBASE_SHARE structure that is needed to provide table
  9106. locking.
  9107. ****************************************************************************/
  9108. static INNOBASE_SHARE* get_share(const char* table_name)
  9109. {
  9110. INNOBASE_SHARE *share;
  9111. mysql_mutex_lock(&innobase_share_mutex);
  9112. ulint fold = ut_fold_string(table_name);
  9113. HASH_SEARCH(table_name_hash, innobase_open_tables, fold,
  9114. INNOBASE_SHARE*, share,
  9115. ut_ad(share->use_count > 0),
  9116. !strcmp(share->table_name, table_name));
  9117. if (!share) {
  9118. uint length = (uint) strlen(table_name);
  9119. /* TODO: invoke HASH_MIGRATE if innobase_open_tables
  9120. grows too big */
  9121. share = (INNOBASE_SHARE *) my_malloc(sizeof(*share)+length+1,
  9122. MYF(MY_FAE | MY_ZEROFILL));
  9123. share->table_name = (char*) memcpy(share + 1,
  9124. table_name, length + 1);
  9125. HASH_INSERT(INNOBASE_SHARE, table_name_hash,
  9126. innobase_open_tables, fold, share);
  9127. thr_lock_init(&share->lock);
  9128. /* Index translation table initialization */
  9129. share->idx_trans_tbl.index_mapping = NULL;
  9130. share->idx_trans_tbl.index_count = 0;
  9131. share->idx_trans_tbl.array_size = 0;
  9132. }
  9133. share->use_count++;
  9134. mysql_mutex_unlock(&innobase_share_mutex);
  9135. return(share);
  9136. }
  9137. static void free_share(INNOBASE_SHARE* share)
  9138. {
  9139. mysql_mutex_lock(&innobase_share_mutex);
  9140. #ifdef UNIV_DEBUG
  9141. INNOBASE_SHARE* share2;
  9142. ulint fold = ut_fold_string(share->table_name);
  9143. HASH_SEARCH(table_name_hash, innobase_open_tables, fold,
  9144. INNOBASE_SHARE*, share2,
  9145. ut_ad(share->use_count > 0),
  9146. !strcmp(share->table_name, share2->table_name));
  9147. ut_a(share2 == share);
  9148. #endif /* UNIV_DEBUG */
  9149. if (!--share->use_count) {
  9150. ulint fold = ut_fold_string(share->table_name);
  9151. HASH_DELETE(INNOBASE_SHARE, table_name_hash,
  9152. innobase_open_tables, fold, share);
  9153. thr_lock_delete(&share->lock);
  9154. /* Free any memory from index translation table */
  9155. my_free(share->idx_trans_tbl.index_mapping);
  9156. my_free(share);
  9157. /* TODO: invoke HASH_MIGRATE if innobase_open_tables
  9158. shrinks too much */
  9159. }
  9160. mysql_mutex_unlock(&innobase_share_mutex);
  9161. }
  9162. /*****************************************************************//**
  9163. Converts a MySQL table lock stored in the 'lock' field of the handle to
  9164. a proper type before storing pointer to the lock into an array of pointers.
  9165. MySQL also calls this if it wants to reset some table locks to a not-locked
  9166. state during the processing of an SQL query. An example is that during a
  9167. SELECT the read lock is released early on the 'const' tables where we only
  9168. fetch one row. MySQL does not call this when it releases all locks at the
  9169. end of an SQL statement.
  9170. @return pointer to the next element in the 'to' array */
  9171. UNIV_INTERN
  9172. THR_LOCK_DATA**
  9173. ha_innobase::store_lock(
  9174. /*====================*/
  9175. THD* thd, /*!< in: user thread handle */
  9176. THR_LOCK_DATA** to, /*!< in: pointer to an array
  9177. of pointers to lock structs;
  9178. pointer to the 'lock' field
  9179. of current handle is stored
  9180. next to this array */
  9181. enum thr_lock_type lock_type) /*!< in: lock type to store in
  9182. 'lock'; this may also be
  9183. TL_IGNORE */
  9184. {
  9185. trx_t* trx;
  9186. /* Note that trx in this function is NOT necessarily prebuilt->trx
  9187. because we call update_thd() later, in ::external_lock()! Failure to
  9188. understand this caused a serious memory corruption bug in 5.1.11. */
  9189. trx = check_trx_exists(thd);
  9190. /* NOTE: MySQL can call this function with lock 'type' TL_IGNORE!
  9191. Be careful to ignore TL_IGNORE if we are going to do something with
  9192. only 'real' locks! */
  9193. /* If no MySQL table is in use, we need to set the isolation level
  9194. of the transaction. */
  9195. if (lock_type != TL_IGNORE
  9196. && trx->n_mysql_tables_in_use == 0) {
  9197. trx->isolation_level = innobase_map_isolation_level(
  9198. (enum_tx_isolation) thd_tx_isolation(thd));
  9199. if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
  9200. && trx->global_read_view) {
  9201. /* At low transaction isolation levels we let
  9202. each consistent read set its own snapshot */
  9203. read_view_close_for_mysql(trx);
  9204. }
  9205. }
  9206. DBUG_ASSERT(EQ_CURRENT_THD(thd));
  9207. const bool in_lock_tables = thd_in_lock_tables(thd);
  9208. const uint sql_command = thd_sql_command(thd);
  9209. if (sql_command == SQLCOM_DROP_TABLE) {
  9210. /* MySQL calls this function in DROP TABLE though this table
  9211. handle may belong to another thd that is running a query. Let
  9212. us in that case skip any changes to the prebuilt struct. */
  9213. } else if ((lock_type == TL_READ && in_lock_tables)
  9214. || (lock_type == TL_READ_HIGH_PRIORITY && in_lock_tables)
  9215. || lock_type == TL_READ_WITH_SHARED_LOCKS
  9216. || lock_type == TL_READ_NO_INSERT
  9217. || (lock_type != TL_IGNORE
  9218. && sql_command != SQLCOM_SELECT)) {
  9219. /* The OR cases above are in this order:
  9220. 1) MySQL is doing LOCK TABLES ... READ LOCAL, or we
  9221. are processing a stored procedure or function, or
  9222. 2) (we do not know when TL_READ_HIGH_PRIORITY is used), or
  9223. 3) this is a SELECT ... IN SHARE MODE, or
  9224. 4) we are doing a complex SQL statement like
  9225. INSERT INTO ... SELECT ... and the logical logging (MySQL
  9226. binlog) requires the use of a locking read, or
  9227. MySQL is doing LOCK TABLES ... READ.
  9228. 5) we let InnoDB do locking reads for all SQL statements that
  9229. are not simple SELECTs; note that select_lock_type in this
  9230. case may get strengthened in ::external_lock() to LOCK_X.
  9231. Note that we MUST use a locking read in all data modifying
  9232. SQL statements, because otherwise the execution would not be
  9233. serializable, and also the results from the update could be
  9234. unexpected if an obsolete consistent read view would be
  9235. used. */
  9236. ulint isolation_level;
  9237. isolation_level = trx->isolation_level;
  9238. if ((srv_locks_unsafe_for_binlog
  9239. || isolation_level <= TRX_ISO_READ_COMMITTED)
  9240. && isolation_level != TRX_ISO_SERIALIZABLE
  9241. && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
  9242. && (sql_command == SQLCOM_INSERT_SELECT
  9243. || sql_command == SQLCOM_REPLACE_SELECT
  9244. || sql_command == SQLCOM_UPDATE
  9245. || sql_command == SQLCOM_CREATE_TABLE)) {
  9246. /* If we either have innobase_locks_unsafe_for_binlog
  9247. option set or this session is using READ COMMITTED
  9248. isolation level and isolation level of the transaction
  9249. is not set to serializable and MySQL is doing
  9250. INSERT INTO...SELECT or REPLACE INTO...SELECT
  9251. or UPDATE ... = (SELECT ...) or CREATE ...
  9252. SELECT... without FOR UPDATE or IN SHARE
  9253. MODE in select, then we use consistent read
  9254. for select. */
  9255. prebuilt->select_lock_type = LOCK_NONE;
  9256. prebuilt->stored_select_lock_type = LOCK_NONE;
  9257. } else if (sql_command == SQLCOM_CHECKSUM) {
  9258. /* Use consistent read for checksum table */
  9259. prebuilt->select_lock_type = LOCK_NONE;
  9260. prebuilt->stored_select_lock_type = LOCK_NONE;
  9261. } else {
  9262. prebuilt->select_lock_type = LOCK_S;
  9263. prebuilt->stored_select_lock_type = LOCK_S;
  9264. }
  9265. } else if (lock_type != TL_IGNORE) {
  9266. /* We set possible LOCK_X value in external_lock, not yet
  9267. here even if this would be SELECT ... FOR UPDATE */
  9268. prebuilt->select_lock_type = LOCK_NONE;
  9269. prebuilt->stored_select_lock_type = LOCK_NONE;
  9270. }
  9271. if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) {
  9272. /* Starting from 5.0.7, we weaken also the table locks
  9273. set at the start of a MySQL stored procedure call, just like
  9274. we weaken the locks set at the start of an SQL statement.
  9275. MySQL does set in_lock_tables TRUE there, but in reality
  9276. we do not need table locks to make the execution of a
  9277. single transaction stored procedure call deterministic
  9278. (if it does not use a consistent read). */
  9279. if (lock_type == TL_READ
  9280. && sql_command == SQLCOM_LOCK_TABLES) {
  9281. /* We come here if MySQL is processing LOCK TABLES
  9282. ... READ LOCAL. MyISAM under that table lock type
  9283. reads the table as it was at the time the lock was
  9284. granted (new inserts are allowed, but not seen by the
  9285. reader). To get a similar effect on an InnoDB table,
  9286. we must use LOCK TABLES ... READ. We convert the lock
  9287. type here, so that for InnoDB, READ LOCAL is
  9288. equivalent to READ. This will change the InnoDB
  9289. behavior in mysqldump, so that dumps of InnoDB tables
  9290. are consistent with dumps of MyISAM tables. */
  9291. lock_type = TL_READ_NO_INSERT;
  9292. }
  9293. /* If we are not doing a LOCK TABLE, DISCARD/IMPORT
  9294. TABLESPACE or TRUNCATE TABLE then allow multiple
  9295. writers. Note that ALTER TABLE uses a TL_WRITE_ALLOW_READ
  9296. < TL_WRITE_CONCURRENT_INSERT.
  9297. We especially allow multiple writers if MySQL is at the
  9298. start of a stored procedure call (SQLCOM_CALL) or a
  9299. stored function call (MySQL does have in_lock_tables
  9300. TRUE there). */
  9301. if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
  9302. && lock_type <= TL_WRITE)
  9303. && !(in_lock_tables
  9304. && sql_command == SQLCOM_LOCK_TABLES)
  9305. && !thd_tablespace_op(thd)
  9306. && sql_command != SQLCOM_TRUNCATE
  9307. && sql_command != SQLCOM_OPTIMIZE
  9308. && sql_command != SQLCOM_CREATE_TABLE) {
  9309. lock_type = TL_WRITE_ALLOW_WRITE;
  9310. }
  9311. /* In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
  9312. MySQL would use the lock TL_READ_NO_INSERT on t2, and that
  9313. would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
  9314. to t2. Convert the lock to a normal read lock to allow
  9315. concurrent inserts to t2.
  9316. We especially allow concurrent inserts if MySQL is at the
  9317. start of a stored procedure call (SQLCOM_CALL)
  9318. (MySQL does have thd_in_lock_tables() TRUE there). */
  9319. if (lock_type == TL_READ_NO_INSERT
  9320. && sql_command != SQLCOM_LOCK_TABLES) {
  9321. lock_type = TL_READ;
  9322. }
  9323. lock.type = lock_type;
  9324. }
  9325. *to++= &lock;
  9326. return(to);
  9327. }
  9328. /*********************************************************************//**
  9329. Read the next autoinc value. Acquire the relevant locks before reading
  9330. the AUTOINC value. If SUCCESS then the table AUTOINC mutex will be locked
  9331. on return and all relevant locks acquired.
  9332. @return DB_SUCCESS or error code */
  9333. UNIV_INTERN
  9334. ulint
  9335. ha_innobase::innobase_get_autoinc(
  9336. /*==============================*/
  9337. ulonglong* value) /*!< out: autoinc value */
  9338. {
  9339. *value = 0;
  9340. prebuilt->autoinc_error = innobase_lock_autoinc();
  9341. if (prebuilt->autoinc_error == DB_SUCCESS) {
  9342. /* Determine the first value of the interval */
  9343. *value = dict_table_autoinc_read(prebuilt->table);
  9344. /* It should have been initialized during open. */
  9345. if (*value == 0) {
  9346. prebuilt->autoinc_error = DB_UNSUPPORTED;
  9347. dict_table_autoinc_unlock(prebuilt->table);
  9348. }
  9349. }
  9350. return(prebuilt->autoinc_error);
  9351. }
  9352. /*******************************************************************//**
  9353. This function reads the global auto-inc counter. It doesn't use the
  9354. AUTOINC lock even if the lock mode is set to TRADITIONAL.
  9355. @return the autoinc value */
  9356. UNIV_INTERN
  9357. ulonglong
  9358. ha_innobase::innobase_peek_autoinc(void)
  9359. /*====================================*/
  9360. {
  9361. ulonglong auto_inc;
  9362. dict_table_t* innodb_table;
  9363. ut_a(prebuilt != NULL);
  9364. ut_a(prebuilt->table != NULL);
  9365. innodb_table = prebuilt->table;
  9366. dict_table_autoinc_lock(innodb_table);
  9367. auto_inc = dict_table_autoinc_read(innodb_table);
  9368. if (auto_inc == 0) {
  9369. ut_print_timestamp(stderr);
  9370. fprintf(stderr, " InnoDB: AUTOINC next value generation "
  9371. "is disabled for '%s'\n", innodb_table->name);
  9372. }
  9373. dict_table_autoinc_unlock(innodb_table);
  9374. return(auto_inc);
  9375. }
  9376. /*********************************************************************//**
  9377. This function initializes the auto-inc counter if it has not been
  9378. initialized yet. This function does not change the value of the auto-inc
  9379. counter if it already has been initialized. Returns the value of the
  9380. auto-inc counter in *first_value, and ULONGLONG_MAX in *nb_reserved_values (as
  9381. we have a table-level lock). offset, increment, nb_desired_values are ignored.
  9382. *first_value is set to -1 if error (deadlock or lock wait timeout) */
  9383. UNIV_INTERN
  9384. void
  9385. ha_innobase::get_auto_increment(
  9386. /*============================*/
  9387. ulonglong offset, /*!< in: table autoinc offset */
  9388. ulonglong increment, /*!< in: table autoinc increment */
  9389. ulonglong nb_desired_values, /*!< in: number of values reqd */
  9390. ulonglong *first_value, /*!< out: the autoinc value */
  9391. ulonglong *nb_reserved_values) /*!< out: count of reserved values */
  9392. {
  9393. trx_t* trx;
  9394. ulint error;
  9395. ulonglong autoinc = 0;
  9396. /* Prepare prebuilt->trx in the table handle */
  9397. update_thd(ha_thd());
  9398. error = innobase_get_autoinc(&autoinc);
  9399. if (error != DB_SUCCESS) {
  9400. *first_value = (~(ulonglong) 0);
  9401. return;
  9402. }
  9403. /* This is a hack, since nb_desired_values seems to be accurate only
  9404. for the first call to get_auto_increment() for multi-row INSERT and
  9405. meaningless for other statements e.g, LOAD etc. Subsequent calls to
  9406. this method for the same statement results in different values which
  9407. don't make sense. Therefore we store the value the first time we are
  9408. called and count down from that as rows are written (see write_row()).
  9409. */
  9410. trx = prebuilt->trx;
  9411. /* Note: We can't rely on *first_value since some MySQL engines,
  9412. in particular the partition engine, don't initialize it to 0 when
  9413. invoking this method. So we are not sure if it's guaranteed to
  9414. be 0 or not. */
  9415. /* We need the upper limit of the col type to check for
  9416. whether we update the table autoinc counter or not. */
  9417. ulonglong col_max_value = innobase_get_int_col_max_value(
  9418. table->next_number_field);
  9419. /* Called for the first time ? */
  9420. if (trx->n_autoinc_rows == 0) {
  9421. trx->n_autoinc_rows = (ulint) nb_desired_values;
  9422. /* It's possible for nb_desired_values to be 0:
  9423. e.g., INSERT INTO T1(C) SELECT C FROM T2; */
  9424. if (nb_desired_values == 0) {
  9425. trx->n_autoinc_rows = 1;
  9426. }
  9427. set_if_bigger(*first_value, autoinc);
  9428. /* Not in the middle of a mult-row INSERT. */
  9429. } else if (prebuilt->autoinc_last_value == 0) {
  9430. set_if_bigger(*first_value, autoinc);
  9431. }
  9432. if (*first_value > col_max_value)
  9433. {
  9434. /* Out of range number. Let handler::update_auto_increment()
  9435. take care of this */
  9436. prebuilt->autoinc_last_value = 0;
  9437. dict_table_autoinc_unlock(prebuilt->table);
  9438. *nb_reserved_values = 0;
  9439. return;
  9440. }
  9441. *nb_reserved_values = trx->n_autoinc_rows;
  9442. /* With old style AUTOINC locking we only update the table's
  9443. AUTOINC counter after attempting to insert the row. */
  9444. if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) {
  9445. ulonglong current;
  9446. ulonglong next_value;
  9447. current = *first_value;
  9448. /* Compute the last value in the interval */
  9449. next_value = innobase_next_autoinc(
  9450. current, *nb_reserved_values, increment, offset,
  9451. col_max_value);
  9452. prebuilt->autoinc_last_value = next_value;
  9453. if (prebuilt->autoinc_last_value < *first_value) {
  9454. *first_value = (~(ulonglong) 0);
  9455. } else {
  9456. /* Update the table autoinc variable */
  9457. dict_table_autoinc_update_if_greater(
  9458. prebuilt->table, prebuilt->autoinc_last_value);
  9459. }
  9460. } else {
  9461. /* This will force write_row() into attempting an update
  9462. of the table's AUTOINC counter. */
  9463. prebuilt->autoinc_last_value = 0;
  9464. }
  9465. /* The increment to be used to increase the AUTOINC value, we use
  9466. this in write_row() and update_row() to increase the autoinc counter
  9467. for columns that are filled by the user. We need the offset and
  9468. the increment. */
  9469. prebuilt->autoinc_offset = offset;
  9470. prebuilt->autoinc_increment = increment;
  9471. dict_table_autoinc_unlock(prebuilt->table);
  9472. }
  9473. /*******************************************************************//**
  9474. Reset the auto-increment counter to the given value, i.e. the next row
  9475. inserted will get the given value. This is called e.g. after TRUNCATE
  9476. is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
  9477. returned by storage engines that don't support this operation.
  9478. @return 0 or error code */
  9479. UNIV_INTERN
  9480. int
  9481. ha_innobase::reset_auto_increment(
  9482. /*==============================*/
  9483. ulonglong value) /*!< in: new value for table autoinc */
  9484. {
  9485. DBUG_ENTER("ha_innobase::reset_auto_increment");
  9486. int error;
  9487. update_thd(ha_thd());
  9488. error = row_lock_table_autoinc_for_mysql(prebuilt);
  9489. if (error != DB_SUCCESS) {
  9490. error = convert_error_code_to_mysql(error,
  9491. prebuilt->table->flags,
  9492. user_thd);
  9493. DBUG_RETURN(error);
  9494. }
  9495. /* The next value can never be 0. */
  9496. if (value == 0) {
  9497. value = 1;
  9498. }
  9499. innobase_reset_autoinc(value);
  9500. DBUG_RETURN(0);
  9501. }
  9502. /* See comment in handler.cc */
  9503. UNIV_INTERN
  9504. bool
  9505. ha_innobase::get_error_message(int error, String *buf)
  9506. {
  9507. trx_t* trx = check_trx_exists(ha_thd());
  9508. buf->copy(trx->detailed_error, (uint) strlen(trx->detailed_error),
  9509. system_charset_info);
  9510. return(FALSE);
  9511. }
  9512. /*******************************************************************//**
  9513. Compares two 'refs'. A 'ref' is the (internal) primary key value of the row.
  9514. If there is no explicitly declared non-null unique key or a primary key, then
  9515. InnoDB internally uses the row id as the primary key.
  9516. @return < 0 if ref1 < ref2, 0 if equal, else > 0 */
  9517. UNIV_INTERN
  9518. int
  9519. ha_innobase::cmp_ref(
  9520. /*=================*/
  9521. const uchar* ref1, /*!< in: an (internal) primary key value in the
  9522. MySQL key value format */
  9523. const uchar* ref2) /*!< in: an (internal) primary key value in the
  9524. MySQL key value format */
  9525. {
  9526. enum_field_types mysql_type;
  9527. Field* field;
  9528. KEY_PART_INFO* key_part;
  9529. KEY_PART_INFO* key_part_end;
  9530. uint len1;
  9531. uint len2;
  9532. int result;
  9533. if (prebuilt->clust_index_was_generated) {
  9534. /* The 'ref' is an InnoDB row id */
  9535. return(memcmp(ref1, ref2, DATA_ROW_ID_LEN));
  9536. }
  9537. /* Do a type-aware comparison of primary key fields. PK fields
  9538. are always NOT NULL, so no checks for NULL are performed. */
  9539. key_part = table->key_info[table->s->primary_key].key_part;
  9540. key_part_end = key_part
  9541. + table->key_info[table->s->primary_key].key_parts;
  9542. for (; key_part != key_part_end; ++key_part) {
  9543. field = key_part->field;
  9544. mysql_type = field->type();
  9545. if (mysql_type == MYSQL_TYPE_TINY_BLOB
  9546. || mysql_type == MYSQL_TYPE_MEDIUM_BLOB
  9547. || mysql_type == MYSQL_TYPE_BLOB
  9548. || mysql_type == MYSQL_TYPE_LONG_BLOB) {
  9549. /* In the MySQL key value format, a column prefix of
  9550. a BLOB is preceded by a 2-byte length field */
  9551. len1 = innobase_read_from_2_little_endian(ref1);
  9552. len2 = innobase_read_from_2_little_endian(ref2);
  9553. ref1 += 2;
  9554. ref2 += 2;
  9555. result = ((Field_blob*)field)->cmp( ref1, len1,
  9556. ref2, len2);
  9557. } else {
  9558. result = field->key_cmp(ref1, ref2);
  9559. }
  9560. if (result) {
  9561. return(result);
  9562. }
  9563. ref1 += key_part->store_length;
  9564. ref2 += key_part->store_length;
  9565. }
  9566. return(0);
  9567. }
  9568. /*******************************************************************//**
  9569. Ask InnoDB if a query to a table can be cached.
  9570. @return TRUE if query caching of the table is permitted */
  9571. UNIV_INTERN
  9572. my_bool
  9573. ha_innobase::register_query_cache_table(
  9574. /*====================================*/
  9575. THD* thd, /*!< in: user thread handle */
  9576. char* table_key, /*!< in: concatenation of database name,
  9577. the null character NUL,
  9578. and the table name */
  9579. uint key_length, /*!< in: length of the full name, i.e.
  9580. len(dbname) + len(tablename) + 1 */
  9581. qc_engine_callback*
  9582. call_back, /*!< out: pointer to function for
  9583. checking if query caching
  9584. is permitted */
  9585. ulonglong *engine_data) /*!< in/out: data to call_back */
  9586. {
  9587. *call_back = innobase_query_caching_of_table_permitted;
  9588. *engine_data = 0;
  9589. return(innobase_query_caching_of_table_permitted(thd, table_key,
  9590. key_length,
  9591. engine_data));
  9592. }
  9593. UNIV_INTERN
  9594. char*
  9595. ha_innobase::get_mysql_bin_log_name()
  9596. {
  9597. return(trx_sys_mysql_bin_log_name);
  9598. }
  9599. UNIV_INTERN
  9600. ulonglong
  9601. ha_innobase::get_mysql_bin_log_pos()
  9602. {
  9603. /* trx... is ib_int64_t, which is a typedef for a 64-bit integer
  9604. (__int64 or longlong) so it's ok to cast it to ulonglong. */
  9605. return(trx_sys_mysql_bin_log_pos);
  9606. }
  9607. /******************************************************************//**
  9608. This function is used to find the storage length in bytes of the first n
  9609. characters for prefix indexes using a multibyte character set. The function
  9610. finds charset information and returns length of prefix_len characters in the
  9611. index field in bytes.
  9612. @return number of bytes occupied by the first n characters */
  9613. extern "C" UNIV_INTERN
  9614. ulint
  9615. innobase_get_at_most_n_mbchars(
  9616. /*===========================*/
  9617. ulint charset_id, /*!< in: character set id */
  9618. ulint prefix_len, /*!< in: prefix length in bytes of the index
  9619. (this has to be divided by mbmaxlen to get the
  9620. number of CHARACTERS n in the prefix) */
  9621. ulint data_len, /*!< in: length of the string in bytes */
  9622. const char* str) /*!< in: character string */
  9623. {
  9624. ulint char_length; /*!< character length in bytes */
  9625. ulint n_chars; /*!< number of characters in prefix */
  9626. CHARSET_INFO* charset; /*!< charset used in the field */
  9627. charset = get_charset((uint) charset_id, MYF(MY_WME));
  9628. ut_ad(charset);
  9629. ut_ad(charset->mbmaxlen);
  9630. /* Calculate how many characters at most the prefix index contains */
  9631. n_chars = prefix_len / charset->mbmaxlen;
  9632. /* If the charset is multi-byte, then we must find the length of the
  9633. first at most n chars in the string. If the string contains less
  9634. characters than n, then we return the length to the end of the last
  9635. character. */
  9636. if (charset->mbmaxlen > 1) {
  9637. /* my_charpos() returns the byte length of the first n_chars
  9638. characters, or a value bigger than the length of str, if
  9639. there were not enough full characters in str.
  9640. Why does the code below work:
  9641. Suppose that we are looking for n UTF-8 characters.
  9642. 1) If the string is long enough, then the prefix contains at
  9643. least n complete UTF-8 characters + maybe some extra
  9644. characters + an incomplete UTF-8 character. No problem in
  9645. this case. The function returns the pointer to the
  9646. end of the nth character.
  9647. 2) If the string is not long enough, then the string contains
  9648. the complete value of a column, that is, only complete UTF-8
  9649. characters, and we can store in the column prefix index the
  9650. whole string. */
  9651. char_length = my_charpos(charset, str,
  9652. str + data_len, (int) n_chars);
  9653. if (char_length > data_len) {
  9654. char_length = data_len;
  9655. }
  9656. } else {
  9657. if (data_len < prefix_len) {
  9658. char_length = data_len;
  9659. } else {
  9660. char_length = prefix_len;
  9661. }
  9662. }
  9663. return(char_length);
  9664. }
  9665. /*******************************************************************//**
  9666. This function is used to prepare an X/Open XA distributed transaction.
  9667. @return 0 or error number */
  9668. static
  9669. int
  9670. innobase_xa_prepare(
  9671. /*================*/
  9672. handlerton* hton, /*!< in: InnoDB handlerton */
  9673. THD* thd, /*!< in: handle to the MySQL thread of
  9674. the user whose XA transaction should
  9675. be prepared */
  9676. bool all) /*!< in: TRUE - commit transaction
  9677. FALSE - the current SQL statement
  9678. ended */
  9679. {
  9680. int error = 0;
  9681. trx_t* trx = check_trx_exists(thd);
  9682. DBUG_ASSERT(hton == innodb_hton_ptr);
  9683. /* we use support_xa value as it was seen at transaction start
  9684. time, not the current session variable value. Any possible changes
  9685. to the session variable take effect only in the next transaction */
  9686. if (!trx->support_xa) {
  9687. return(0);
  9688. }
  9689. if (trx->fake_changes) {
  9690. return(0);
  9691. }
  9692. thd_get_xid(thd, (MYSQL_XID*) &trx->xid);
  9693. /* Release a possible FIFO ticket and search latch. Since we will
  9694. reserve the kernel mutex, we have to release the search system latch
  9695. first to obey the latching order. */
  9696. innobase_release_stat_resources(trx);
  9697. if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) {
  9698. sql_print_error("Transaction not registered for MySQL 2PC, "
  9699. "but transaction is active");
  9700. }
  9701. if (all
  9702. || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
  9703. /* We were instructed to prepare the whole transaction, or
  9704. this is an SQL statement end and autocommit is on */
  9705. ut_ad(trx_is_registered_for_2pc(trx));
  9706. error = (int) trx_prepare_for_mysql(trx);
  9707. } else {
  9708. /* We just mark the SQL statement ended and do not do a
  9709. transaction prepare */
  9710. /* If we had reserved the auto-inc lock for some
  9711. table in this SQL statement we release it now */
  9712. row_unlock_table_autoinc_for_mysql(trx);
  9713. /* Store the current undo_no of the transaction so that we
  9714. know where to roll back if we have to roll back the next
  9715. SQL statement */
  9716. trx_mark_sql_stat_end(trx);
  9717. }
  9718. /* Tell the InnoDB server that there might be work for utility
  9719. threads: */
  9720. srv_active_wake_master_thread();
  9721. return(error);
  9722. }
  9723. /*******************************************************************//**
  9724. This function is used to recover X/Open XA distributed transactions.
  9725. @return number of prepared transactions stored in xid_list */
  9726. static
  9727. int
  9728. innobase_xa_recover(
  9729. /*================*/
  9730. handlerton* hton, /*!< in: InnoDB handlerton */
  9731. XID* xid_list,/*!< in/out: prepared transactions */
  9732. uint len) /*!< in: number of slots in xid_list */
  9733. {
  9734. DBUG_ASSERT(hton == innodb_hton_ptr);
  9735. if (len == 0 || xid_list == NULL) {
  9736. return(0);
  9737. }
  9738. return(trx_recover_for_mysql(xid_list, len));
  9739. }
  9740. /*******************************************************************//**
  9741. This function is used to commit one X/Open XA distributed transaction
  9742. which is in the prepared state
  9743. @return 0 or error number */
  9744. static
  9745. int
  9746. innobase_commit_by_xid(
  9747. /*===================*/
  9748. handlerton* hton,
  9749. XID* xid) /*!< in: X/Open XA transaction identification */
  9750. {
  9751. trx_t* trx;
  9752. DBUG_ASSERT(hton == innodb_hton_ptr);
  9753. trx = trx_get_trx_by_xid(xid);
  9754. if (trx) {
  9755. innobase_commit_low(trx);
  9756. trx_free_for_background(trx);
  9757. return(XA_OK);
  9758. } else {
  9759. return(XAER_NOTA);
  9760. }
  9761. }
  9762. /*******************************************************************//**
  9763. This function is used to rollback one X/Open XA distributed transaction
  9764. which is in the prepared state
  9765. @return 0 or error number */
  9766. static
  9767. int
  9768. innobase_rollback_by_xid(
  9769. /*=====================*/
  9770. handlerton* hton, /*!< in: InnoDB handlerton */
  9771. XID* xid) /*!< in: X/Open XA transaction
  9772. identification */
  9773. {
  9774. trx_t* trx;
  9775. DBUG_ASSERT(hton == innodb_hton_ptr);
  9776. trx = trx_get_trx_by_xid(xid);
  9777. if (trx) {
  9778. int ret = innobase_rollback_trx(trx);
  9779. trx_free_for_background(trx);
  9780. return(ret);
  9781. } else {
  9782. return(XAER_NOTA);
  9783. }
  9784. }
  9785. /*******************************************************************//**
  9786. Create a consistent view for a cursor based on current transaction
  9787. which is created if the corresponding MySQL thread still lacks one.
  9788. This consistent view is then used inside of MySQL when accessing records
  9789. using a cursor.
  9790. @return pointer to cursor view or NULL */
  9791. static
  9792. void*
  9793. innobase_create_cursor_view(
  9794. /*========================*/
  9795. handlerton *hton, /*!< in: innobase hton */
  9796. THD* thd) /*!< in: user thread handle */
  9797. {
  9798. DBUG_ASSERT(hton == innodb_hton_ptr);
  9799. return(read_cursor_view_create_for_mysql(check_trx_exists(thd)));
  9800. }
  9801. /*******************************************************************//**
  9802. Close the given consistent cursor view of a transaction and restore
  9803. global read view to a transaction read view. Transaction is created if the
  9804. corresponding MySQL thread still lacks one. */
  9805. static
  9806. void
  9807. innobase_close_cursor_view(
  9808. /*=======================*/
  9809. handlerton *hton,
  9810. THD* thd, /*!< in: user thread handle */
  9811. void* curview)/*!< in: Consistent read view to be closed */
  9812. {
  9813. DBUG_ASSERT(hton == innodb_hton_ptr);
  9814. read_cursor_view_close_for_mysql(check_trx_exists(thd),
  9815. (cursor_view_t*) curview);
  9816. }
  9817. /*******************************************************************//**
  9818. Set the given consistent cursor view to a transaction which is created
  9819. if the corresponding MySQL thread still lacks one. If the given
  9820. consistent cursor view is NULL global read view of a transaction is
  9821. restored to a transaction read view. */
  9822. static
  9823. void
  9824. innobase_set_cursor_view(
  9825. /*=====================*/
  9826. handlerton *hton,
  9827. THD* thd, /*!< in: user thread handle */
  9828. void* curview)/*!< in: Consistent cursor view to be set */
  9829. {
  9830. DBUG_ASSERT(hton == innodb_hton_ptr);
  9831. read_cursor_set_for_mysql(check_trx_exists(thd),
  9832. (cursor_view_t*) curview);
  9833. }
  9834. /*******************************************************************//**
  9835. If col_name is not NULL, check whether the named column is being
  9836. renamed in the table. If col_name is not provided, check
  9837. whether any one of columns in the table is being renamed.
  9838. @return true if the column is being renamed */
  9839. static
  9840. bool
  9841. check_column_being_renamed(
  9842. /*=======================*/
  9843. const TABLE* table, /*!< in: MySQL table */
  9844. const char* col_name) /*!< in: name of the column */
  9845. {
  9846. uint k;
  9847. Field* field;
  9848. for (k = 0; k < table->s->fields; k++) {
  9849. field = table->field[k];
  9850. if (field->flags & FIELD_IS_RENAMED) {
  9851. /* If col_name is not provided, return
  9852. if the field is marked as being renamed. */
  9853. if (!col_name) {
  9854. return(true);
  9855. }
  9856. /* If col_name is provided, return only
  9857. if names match */
  9858. if (innobase_strcasecmp(field->field_name,
  9859. col_name) == 0) {
  9860. return(true);
  9861. }
  9862. }
  9863. }
  9864. return(false);
  9865. }
  9866. /*******************************************************************//**
  9867. Check whether any of the given columns is being renamed in the table.
  9868. @return true if any of col_names is being renamed in table */
  9869. static
  9870. bool
  9871. column_is_being_renamed(
  9872. /*====================*/
  9873. TABLE* table, /*!< in: MySQL table */
  9874. uint n_cols, /*!< in: number of columns */
  9875. const char** col_names) /*!< in: names of the columns */
  9876. {
  9877. uint j;
  9878. for (j = 0; j < n_cols; j++) {
  9879. if (check_column_being_renamed(table, col_names[j])) {
  9880. return(true);
  9881. }
  9882. }
  9883. return(false);
  9884. }
  9885. /***********************************************************************
  9886. Check whether a column in table "table" is being renamed and if this column
  9887. is part of a foreign key, either part of another table, referencing this
  9888. table or part of this table, referencing another table. */
  9889. static
  9890. bool
  9891. foreign_key_column_is_being_renamed(
  9892. /*================================*/
  9893. /* out: true if a column that
  9894. participates in a foreign key definition
  9895. is being renamed */
  9896. row_prebuilt_t* prebuilt, /* in: InnoDB prebuilt struct */
  9897. TABLE* table) /* in: MySQL table */
  9898. {
  9899. dict_foreign_t* foreign;
  9900. /* check whether there are foreign keys at all */
  9901. if (UT_LIST_GET_LEN(prebuilt->table->foreign_list) == 0
  9902. && UT_LIST_GET_LEN(prebuilt->table->referenced_list) == 0) {
  9903. /* no foreign keys involved with prebuilt->table */
  9904. return(false);
  9905. }
  9906. row_mysql_lock_data_dictionary(prebuilt->trx);
  9907. /* Check whether any column in the foreign key constraints which refer
  9908. to this table is being renamed. */
  9909. for (foreign = UT_LIST_GET_FIRST(prebuilt->table->referenced_list);
  9910. foreign != NULL;
  9911. foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) {
  9912. if (column_is_being_renamed(table, foreign->n_fields,
  9913. foreign->referenced_col_names)) {
  9914. row_mysql_unlock_data_dictionary(prebuilt->trx);
  9915. return(true);
  9916. }
  9917. }
  9918. /* Check whether any column in the foreign key constraints in the
  9919. table is being renamed. */
  9920. for (foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
  9921. foreign != NULL;
  9922. foreign = UT_LIST_GET_NEXT(foreign_list, foreign)) {
  9923. if (column_is_being_renamed(table, foreign->n_fields,
  9924. foreign->foreign_col_names)) {
  9925. row_mysql_unlock_data_dictionary(prebuilt->trx);
  9926. return(true);
  9927. }
  9928. }
  9929. row_mysql_unlock_data_dictionary(prebuilt->trx);
  9930. return(false);
  9931. }
  9932. UNIV_INTERN
  9933. bool
  9934. ha_innobase::check_if_incompatible_data(
  9935. HA_CREATE_INFO* info,
  9936. uint table_changes)
  9937. {
  9938. enum row_type row_type, info_row_type;
  9939. DBUG_ENTER("ha_innobase::check_if_incompatible_data");
  9940. if (table_changes != IS_EQUAL_YES) {
  9941. DBUG_PRINT("info", ("table_changes != IS_EQUAL_YES "
  9942. "-> COMPATIBLE_DATA_NO"));
  9943. DBUG_RETURN(COMPATIBLE_DATA_NO);
  9944. }
  9945. /* Check that auto_increment value was not changed */
  9946. if ((info->used_fields & HA_CREATE_USED_AUTO) &&
  9947. info->auto_increment_value != 0) {
  9948. DBUG_PRINT("info", ("auto_increment_value changed -> "
  9949. "COMPATIBLE_DATA_NO"));
  9950. DBUG_RETURN(COMPATIBLE_DATA_NO);
  9951. }
  9952. /* For column rename operation, MySQL does not supply enough
  9953. information (new column name etc.) for InnoDB to make appropriate
  9954. system metadata change. To avoid system metadata inconsistency,
  9955. currently we can just request a table rebuild/copy by returning
  9956. COMPATIBLE_DATA_NO */
  9957. if (check_column_being_renamed(table, NULL)) {
  9958. DBUG_RETURN(COMPATIBLE_DATA_NO);
  9959. }
  9960. /* Check if a column participating in a foreign key is being renamed.
  9961. There is no mechanism for updating InnoDB foreign key definitions. */
  9962. if (foreign_key_column_is_being_renamed(prebuilt, table)) {
  9963. DBUG_RETURN(COMPATIBLE_DATA_NO);
  9964. }
  9965. /* Check that row format didn't change */
  9966. row_type = get_row_type();
  9967. info_row_type = info->row_type;
  9968. /* Default is compact. */
  9969. if (info_row_type == ROW_TYPE_DEFAULT)
  9970. info_row_type = ROW_TYPE_COMPACT;
  9971. if ((info->used_fields & HA_CREATE_USED_ROW_FORMAT) &&
  9972. row_type != ((info->row_type == ROW_TYPE_DEFAULT)
  9973. ? ROW_TYPE_COMPACT : info->row_type)) {
  9974. DBUG_PRINT("info", ("get_row_type()=%d != info->row_type=%d -> "
  9975. "COMPATIBLE_DATA_NO",
  9976. row_type, info->row_type));
  9977. DBUG_RETURN(COMPATIBLE_DATA_NO);
  9978. }
  9979. /* Specifying KEY_BLOCK_SIZE requests a rebuild of the table. */
  9980. if (info->used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE) {
  9981. DBUG_PRINT("info", ("HA_CREATE_USED_KEY_BLOCK_SIZE -> "
  9982. "COMPATIBLE_DATA_NO"));
  9983. DBUG_RETURN(COMPATIBLE_DATA_NO);
  9984. }
  9985. DBUG_PRINT("info", (" -> COMPATIBLE_DATA_YES"));
  9986. DBUG_RETURN(COMPATIBLE_DATA_YES);
  9987. }
  9988. /************************************************************//**
  9989. Validate the file format name and return its corresponding id.
  9990. @return valid file format id */
  9991. static
  9992. uint
  9993. innobase_file_format_name_lookup(
  9994. /*=============================*/
  9995. const char* format_name) /*!< in: pointer to file format name */
  9996. {
  9997. char* endp;
  9998. uint format_id;
  9999. ut_a(format_name != NULL);
  10000. /* The format name can contain the format id itself instead of
  10001. the name and we check for that. */
  10002. format_id = (uint) strtoul(format_name, &endp, 10);
  10003. /* Check for valid parse. */
  10004. if (*endp == '\0' && *format_name != '\0') {
  10005. if (format_id <= DICT_TF_FORMAT_MAX) {
  10006. return(format_id);
  10007. }
  10008. } else {
  10009. for (format_id = 0; format_id <= DICT_TF_FORMAT_MAX;
  10010. format_id++) {
  10011. const char* name;
  10012. name = trx_sys_file_format_id_to_name(format_id);
  10013. if (!innobase_strcasecmp(format_name, name)) {
  10014. return(format_id);
  10015. }
  10016. }
  10017. }
  10018. return(DICT_TF_FORMAT_MAX + 1);
  10019. }
  10020. /************************************************************//**
  10021. Validate the file format check config parameters, as a side effect it
  10022. sets the srv_max_file_format_at_startup variable.
  10023. @return the format_id if valid config value, otherwise, return -1 */
  10024. static
  10025. int
  10026. innobase_file_format_validate_and_set(
  10027. /*==================================*/
  10028. const char* format_max) /*!< in: parameter value */
  10029. {
  10030. uint format_id;
  10031. format_id = innobase_file_format_name_lookup(format_max);
  10032. if (format_id < DICT_TF_FORMAT_MAX + 1) {
  10033. srv_max_file_format_at_startup = format_id;
  10034. return((int) format_id);
  10035. } else {
  10036. return(-1);
  10037. }
  10038. }
  10039. /*************************************************************//**
  10040. Check if it is a valid file format. This function is registered as
  10041. a callback with MySQL.
  10042. @return 0 for valid file format */
  10043. static
  10044. int
  10045. innodb_file_format_name_validate(
  10046. /*=============================*/
  10047. THD* thd, /*!< in: thread handle */
  10048. struct st_mysql_sys_var* var, /*!< in: pointer to system
  10049. variable */
  10050. void* save, /*!< out: immediate result
  10051. for update function */
  10052. struct st_mysql_value* value) /*!< in: incoming string */
  10053. {
  10054. const char* file_format_input;
  10055. char buff[STRING_BUFFER_USUAL_SIZE];
  10056. int len = sizeof(buff);
  10057. ut_a(save != NULL);
  10058. ut_a(value != NULL);
  10059. file_format_input = value->val_str(value, buff, &len);
  10060. if (file_format_input != NULL) {
  10061. uint format_id;
  10062. format_id = innobase_file_format_name_lookup(
  10063. file_format_input);
  10064. if (format_id <= DICT_TF_FORMAT_MAX) {
  10065. /* Save a pointer to the name in the
  10066. 'file_format_name_map' constant array. */
  10067. *static_cast<const char**>(save) =
  10068. trx_sys_file_format_id_to_name(format_id);
  10069. return(0);
  10070. }
  10071. }
  10072. *static_cast<const char**>(save) = NULL;
  10073. return(1);
  10074. }
  10075. /****************************************************************//**
  10076. Update the system variable innodb_file_format using the "saved"
  10077. value. This function is registered as a callback with MySQL. */
  10078. static
  10079. void
  10080. innodb_file_format_name_update(
  10081. /*===========================*/
  10082. THD* thd, /*!< in: thread handle */
  10083. struct st_mysql_sys_var* var, /*!< in: pointer to
  10084. system variable */
  10085. void* var_ptr, /*!< out: where the
  10086. formal string goes */
  10087. const void* save) /*!< in: immediate result
  10088. from check function */
  10089. {
  10090. const char* format_name;
  10091. ut_a(var_ptr != NULL);
  10092. ut_a(save != NULL);
  10093. format_name = *static_cast<const char*const*>(save);
  10094. if (format_name) {
  10095. uint format_id;
  10096. format_id = innobase_file_format_name_lookup(format_name);
  10097. if (format_id <= DICT_TF_FORMAT_MAX) {
  10098. srv_file_format = format_id;
  10099. }
  10100. }
  10101. *static_cast<const char**>(var_ptr)
  10102. = trx_sys_file_format_id_to_name(srv_file_format);
  10103. }
  10104. /*************************************************************//**
  10105. Check if valid argument to innodb_file_format_max. This function
  10106. is registered as a callback with MySQL.
  10107. @return 0 for valid file format */
  10108. static
  10109. int
  10110. innodb_file_format_max_validate(
  10111. /*============================*/
  10112. THD* thd, /*!< in: thread handle */
  10113. struct st_mysql_sys_var* var, /*!< in: pointer to system
  10114. variable */
  10115. void* save, /*!< out: immediate result
  10116. for update function */
  10117. struct st_mysql_value* value) /*!< in: incoming string */
  10118. {
  10119. const char* file_format_input;
  10120. char buff[STRING_BUFFER_USUAL_SIZE];
  10121. int len = sizeof(buff);
  10122. int format_id;
  10123. ut_a(save != NULL);
  10124. ut_a(value != NULL);
  10125. file_format_input = value->val_str(value, buff, &len);
  10126. if (file_format_input != NULL) {
  10127. format_id = innobase_file_format_validate_and_set(
  10128. file_format_input);
  10129. if (format_id >= 0) {
  10130. /* Save a pointer to the name in the
  10131. 'file_format_name_map' constant array. */
  10132. *static_cast<const char**>(save) =
  10133. trx_sys_file_format_id_to_name(
  10134. (uint)format_id);
  10135. return(0);
  10136. } else {
  10137. push_warning_printf(thd,
  10138. MYSQL_ERROR::WARN_LEVEL_WARN,
  10139. ER_WRONG_ARGUMENTS,
  10140. "InnoDB: invalid innodb_file_format_max "
  10141. "value; can be any format up to %s "
  10142. "or equivalent id of %d",
  10143. trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX),
  10144. DICT_TF_FORMAT_MAX);
  10145. }
  10146. }
  10147. *static_cast<const char**>(save) = NULL;
  10148. return(1);
  10149. }
  10150. /****************************************************************//**
  10151. Update the system variable innodb_file_format_max using the "saved"
  10152. value. This function is registered as a callback with MySQL. */
  10153. static
  10154. void
  10155. innodb_file_format_max_update(
  10156. /*==========================*/
  10157. THD* thd, /*!< in: thread handle */
  10158. struct st_mysql_sys_var* var, /*!< in: pointer to
  10159. system variable */
  10160. void* var_ptr, /*!< out: where the
  10161. formal string goes */
  10162. const void* save) /*!< in: immediate result
  10163. from check function */
  10164. {
  10165. const char* format_name_in;
  10166. const char** format_name_out;
  10167. uint format_id;
  10168. ut_a(save != NULL);
  10169. ut_a(var_ptr != NULL);
  10170. format_name_in = *static_cast<const char*const*>(save);
  10171. if (!format_name_in) {
  10172. return;
  10173. }
  10174. format_id = innobase_file_format_name_lookup(format_name_in);
  10175. if (format_id > DICT_TF_FORMAT_MAX) {
  10176. /* DEFAULT is "on", which is invalid at runtime. */
  10177. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  10178. ER_WRONG_ARGUMENTS,
  10179. "Ignoring SET innodb_file_format=%s",
  10180. format_name_in);
  10181. return;
  10182. }
  10183. format_name_out = static_cast<const char**>(var_ptr);
  10184. /* Update the max format id in the system tablespace. */
  10185. if (trx_sys_file_format_max_set(format_id, format_name_out)) {
  10186. ut_print_timestamp(stderr);
  10187. fprintf(stderr,
  10188. " [Info] InnoDB: the file format in the system "
  10189. "tablespace is now set to %s.\n", *format_name_out);
  10190. }
  10191. }
  10192. /****************************************************************//**
  10193. Update the system variable innodb_adaptive_hash_index using the "saved"
  10194. value. This function is registered as a callback with MySQL. */
  10195. static
  10196. void
  10197. innodb_adaptive_hash_index_update(
  10198. /*==============================*/
  10199. THD* thd, /*!< in: thread handle */
  10200. struct st_mysql_sys_var* var, /*!< in: pointer to
  10201. system variable */
  10202. void* var_ptr, /*!< out: where the
  10203. formal string goes */
  10204. const void* save) /*!< in: immediate result
  10205. from check function */
  10206. {
  10207. if (*(my_bool*) save) {
  10208. btr_search_enable();
  10209. } else {
  10210. btr_search_disable();
  10211. }
  10212. }
  10213. /****************************************************************//**
  10214. Update the system variable innodb_old_blocks_pct using the "saved"
  10215. value. This function is registered as a callback with MySQL. */
  10216. static
  10217. void
  10218. innodb_old_blocks_pct_update(
  10219. /*=========================*/
  10220. THD* thd, /*!< in: thread handle */
  10221. struct st_mysql_sys_var* var, /*!< in: pointer to
  10222. system variable */
  10223. void* var_ptr,/*!< out: where the
  10224. formal string goes */
  10225. const void* save) /*!< in: immediate result
  10226. from check function */
  10227. {
  10228. innobase_old_blocks_pct = buf_LRU_old_ratio_update(
  10229. *static_cast<const uint*>(save), TRUE);
  10230. }
  10231. /*************************************************************//**
  10232. Find the corresponding ibuf_use_t value that indexes into
  10233. innobase_change_buffering_values[] array for the input
  10234. change buffering option name.
  10235. @return corresponding IBUF_USE_* value for the input variable
  10236. name, or IBUF_USE_COUNT if not able to find a match */
  10237. static
  10238. ibuf_use_t
  10239. innodb_find_change_buffering_value(
  10240. /*===============================*/
  10241. const char* input_name) /*!< in: input change buffering
  10242. option name */
  10243. {
  10244. ulint use;
  10245. for (use = 0; use < UT_ARR_SIZE(innobase_change_buffering_values);
  10246. use++) {
  10247. /* found a match */
  10248. if (!innobase_strcasecmp(
  10249. input_name, innobase_change_buffering_values[use])) {
  10250. return((ibuf_use_t)use);
  10251. }
  10252. }
  10253. /* Did not find any match */
  10254. return(IBUF_USE_COUNT);
  10255. }
  10256. /*************************************************************//**
  10257. Check if it is a valid value of innodb_change_buffering. This function is
  10258. registered as a callback with MySQL.
  10259. @return 0 for valid innodb_change_buffering */
  10260. static
  10261. int
  10262. innodb_change_buffering_validate(
  10263. /*=============================*/
  10264. THD* thd, /*!< in: thread handle */
  10265. struct st_mysql_sys_var* var, /*!< in: pointer to system
  10266. variable */
  10267. void* save, /*!< out: immediate result
  10268. for update function */
  10269. struct st_mysql_value* value) /*!< in: incoming string */
  10270. {
  10271. const char* change_buffering_input;
  10272. char buff[STRING_BUFFER_USUAL_SIZE];
  10273. int len = sizeof(buff);
  10274. ut_a(save != NULL);
  10275. ut_a(value != NULL);
  10276. change_buffering_input = value->val_str(value, buff, &len);
  10277. if (change_buffering_input != NULL) {
  10278. ibuf_use_t use;
  10279. use = innodb_find_change_buffering_value(
  10280. change_buffering_input);
  10281. if (use != IBUF_USE_COUNT) {
  10282. /* Find a matching change_buffering option value. */
  10283. *static_cast<const char**>(save) =
  10284. innobase_change_buffering_values[use];
  10285. return(0);
  10286. }
  10287. }
  10288. /* No corresponding change buffering option for user supplied
  10289. "change_buffering_input" */
  10290. return(1);
  10291. }
  10292. /****************************************************************//**
  10293. Update the system variable innodb_change_buffering using the "saved"
  10294. value. This function is registered as a callback with MySQL. */
  10295. static
  10296. void
  10297. innodb_change_buffering_update(
  10298. /*===========================*/
  10299. THD* thd, /*!< in: thread handle */
  10300. struct st_mysql_sys_var* var, /*!< in: pointer to
  10301. system variable */
  10302. void* var_ptr,/*!< out: where the
  10303. formal string goes */
  10304. const void* save) /*!< in: immediate result
  10305. from check function */
  10306. {
  10307. ibuf_use_t use;
  10308. ut_a(var_ptr != NULL);
  10309. ut_a(save != NULL);
  10310. use = innodb_find_change_buffering_value(
  10311. *static_cast<const char*const*>(save));
  10312. ut_a(use < IBUF_USE_COUNT);
  10313. ibuf_use = use;
  10314. *static_cast<const char**>(var_ptr) =
  10315. *static_cast<const char*const*>(save);
  10316. }
  10317. static int show_innodb_vars(THD *thd, SHOW_VAR *var, char *buff)
  10318. {
  10319. innodb_export_status();
  10320. var->type= SHOW_ARRAY;
  10321. var->value= (char *) &innodb_status_variables;
  10322. return 0;
  10323. }
  10324. /*********************************************************************//**
  10325. This function checks each index name for a table against reserved
  10326. system default primary index name 'GEN_CLUST_INDEX'. If a name
  10327. matches, this function pushes an warning message to the client,
  10328. and returns true.
  10329. @return true if the index name matches the reserved name */
  10330. extern "C" UNIV_INTERN
  10331. bool
  10332. innobase_index_name_is_reserved(
  10333. /*============================*/
  10334. THD* thd, /*!< in/out: MySQL connection */
  10335. const KEY* key_info, /*!< in: Indexes to be created */
  10336. ulint num_of_keys) /*!< in: Number of indexes to
  10337. be created. */
  10338. {
  10339. const KEY* key;
  10340. uint key_num; /* index number */
  10341. for (key_num = 0; key_num < num_of_keys; key_num++) {
  10342. key = &key_info[key_num];
  10343. if (innobase_strcasecmp(key->name,
  10344. innobase_index_reserve_name) == 0) {
  10345. /* Push warning to mysql */
  10346. push_warning_printf(thd,
  10347. MYSQL_ERROR::WARN_LEVEL_WARN,
  10348. ER_WRONG_NAME_FOR_INDEX,
  10349. "Cannot Create Index with name "
  10350. "'%s'. The name is reserved "
  10351. "for the system default primary "
  10352. "index.",
  10353. innobase_index_reserve_name);
  10354. my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0),
  10355. innobase_index_reserve_name);
  10356. return(true);
  10357. }
  10358. }
  10359. return(false);
  10360. }
  10361. /***********************************************************************
  10362. functions for kill session of idle transaction */
  10363. extern "C"
  10364. ibool
  10365. innobase_thd_is_idle(
  10366. /*=================*/
  10367. const void* thd) /*!< in: thread handle (THD*) */
  10368. {
  10369. #ifdef EXTENDED_FOR_KILLIDLE
  10370. return(thd_command((const THD*) thd) == COM_SLEEP);
  10371. #else
  10372. return(FALSE);
  10373. #endif
  10374. }
  10375. extern "C"
  10376. ib_int64_t
  10377. innobase_thd_get_start_time(
  10378. /*========================*/
  10379. const void* thd) /*!< in: thread handle (THD*) */
  10380. {
  10381. #ifdef EXTENDED_FOR_KILLIDLE
  10382. return((ib_int64_t)thd_start_time((const THD*) thd));
  10383. #else
  10384. return(0); /*dummy value*/
  10385. #endif
  10386. }
  10387. extern "C"
  10388. void
  10389. innobase_thd_kill(
  10390. /*==============*/
  10391. ulong thd_id)
  10392. {
  10393. #ifdef EXTENDED_FOR_KILLIDLE
  10394. thd_kill(thd_id);
  10395. #else
  10396. return;
  10397. #endif
  10398. }
  10399. extern "C"
  10400. ulong
  10401. innobase_thd_get_thread_id(
  10402. /*=======================*/
  10403. const void* thd)
  10404. {
  10405. return(thd_get_thread_id((const THD*) thd));
  10406. }
  10407. static SHOW_VAR innodb_status_variables_export[]= {
  10408. {"Innodb", (char*) &show_innodb_vars, SHOW_FUNC},
  10409. {NullS, NullS, SHOW_LONG}
  10410. };
  10411. static struct st_mysql_storage_engine innobase_storage_engine=
  10412. { MYSQL_HANDLERTON_INTERFACE_VERSION };
  10413. /* plugin options */
  10414. static MYSQL_SYSVAR_BOOL(checksums, innobase_use_checksums,
  10415. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10416. "Enable InnoDB checksums validation (enabled by default). "
  10417. "Disable with --skip-innodb-checksums.",
  10418. NULL, NULL, TRUE);
  10419. static MYSQL_SYSVAR_BOOL(fast_checksum, innobase_fast_checksum,
  10420. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10421. "Change the algorithm of checksum for the whole of datapage to 4-bytes word based. "
  10422. "The original checksum is checked after the new one. It may be slow for reading page"
  10423. " which has orginal checksum. Overwrite the page or recreate the InnoDB database, "
  10424. "if you want the entire benefit for performance at once. "
  10425. "#### Attention: The checksum is not compatible for normal or disabled version! ####",
  10426. NULL, NULL, FALSE);
  10427. static MYSQL_SYSVAR_ULONG(page_size, innobase_page_size,
  10428. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10429. "###EXPERIMENTAL###: The universal page size of the database. Changing for created database is not supported. Use on your own risk!",
  10430. NULL, NULL, (1 << 14), (1 << 12), (1 << UNIV_PAGE_SIZE_SHIFT_MAX), 0);
  10431. static MYSQL_SYSVAR_ULONG(log_block_size, innobase_log_block_size,
  10432. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10433. "###EXPERIMENTAL###: The log block size of the transaction log file. Changing for created log file is not supported. Use on your own risk!",
  10434. NULL, NULL, (1 << 9)/*512*/, (1 << 9)/*512*/, (1 << UNIV_PAGE_SIZE_SHIFT_MAX), 0);
  10435. static MYSQL_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
  10436. PLUGIN_VAR_READONLY,
  10437. "The common part for InnoDB table spaces.",
  10438. NULL, NULL, NULL);
  10439. static MYSQL_SYSVAR_BOOL(recovery_stats, innobase_recovery_stats,
  10440. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10441. "Output statistics of recovery process after it.",
  10442. NULL, NULL, FALSE);
  10443. static MYSQL_SYSVAR_BOOL(recovery_update_relay_log, innobase_overwrite_relay_log_info,
  10444. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10445. "During InnoDB crash recovery on slave overwrite relay-log.info "
  10446. "to align master log file position if information in InnoDB and relay-log.info is different.",
  10447. NULL, NULL, FALSE);
  10448. static MYSQL_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite,
  10449. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10450. "Enable InnoDB doublewrite buffer (enabled by default). "
  10451. "Disable with --skip-innodb-doublewrite.",
  10452. NULL, NULL, TRUE);
  10453. static MYSQL_SYSVAR_ULONG(io_capacity, srv_io_capacity,
  10454. PLUGIN_VAR_RQCMDARG,
  10455. "Number of IOPs the server can do. Tunes the background IO rate",
  10456. NULL, NULL, 200, 100, ~0UL, 0);
  10457. static MYSQL_SYSVAR_ULONG(purge_batch_size, srv_purge_batch_size,
  10458. PLUGIN_VAR_OPCMDARG,
  10459. "Number of UNDO log pages to purge in one batch from the history list.",
  10460. NULL, NULL,
  10461. 20, /* Default setting */
  10462. 1, /* Minimum value */
  10463. 5000, 0); /* Maximum value */
  10464. static MYSQL_SYSVAR_ULONG(rollback_segments, srv_rollback_segments,
  10465. PLUGIN_VAR_OPCMDARG,
  10466. "Number of UNDO logs to use.",
  10467. NULL, NULL,
  10468. 128, /* Default setting */
  10469. 1, /* Minimum value */
  10470. TRX_SYS_N_RSEGS, 0); /* Maximum value */
  10471. static MYSQL_SYSVAR_ULONG(purge_threads, srv_n_purge_threads,
  10472. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  10473. "Purge threads can be either 0 or 1.",
  10474. NULL, NULL,
  10475. 1, /* Default setting */
  10476. 0, /* Minimum value */
  10477. 1, 0); /* Maximum value */
  10478. static MYSQL_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
  10479. PLUGIN_VAR_OPCMDARG,
  10480. "Speeds up the shutdown process of the InnoDB storage engine. Possible "
  10481. "values are 0, 1 (faster) or 2 (fastest - crash-like).",
  10482. NULL, NULL, 1, 0, 2, 0);
  10483. static MYSQL_SYSVAR_BOOL(file_per_table, srv_file_per_table,
  10484. PLUGIN_VAR_NOCMDARG,
  10485. "Stores each InnoDB table to an .ibd file in the database dir.",
  10486. NULL, NULL, FALSE);
  10487. static MYSQL_SYSVAR_STR(file_format, innobase_file_format_name,
  10488. PLUGIN_VAR_RQCMDARG,
  10489. "File format to use for new tables in .ibd files.",
  10490. innodb_file_format_name_validate,
  10491. innodb_file_format_name_update, "Antelope");
  10492. /* "innobase_file_format_check" decides whether we would continue
  10493. booting the server if the file format stamped on the system
  10494. table space exceeds the maximum file format supported
  10495. by the server. Can be set during server startup at command
  10496. line or configure file, and a read only variable after
  10497. server startup */
  10498. static MYSQL_SYSVAR_BOOL(file_format_check, innobase_file_format_check,
  10499. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10500. "Whether to perform system file format check.",
  10501. NULL, NULL, TRUE);
  10502. /* If a new file format is introduced, the file format
  10503. name needs to be updated accordingly. Please refer to
  10504. file_format_name_map[] defined in trx0sys.c for the next
  10505. file format name. */
  10506. static MYSQL_SYSVAR_STR(file_format_max, innobase_file_format_max,
  10507. PLUGIN_VAR_OPCMDARG,
  10508. "The highest file format in the tablespace.",
  10509. innodb_file_format_max_validate,
  10510. innodb_file_format_max_update, "Antelope");
  10511. /* Changed to the THDVAR */
  10512. //static MYSQL_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
  10513. // PLUGIN_VAR_OPCMDARG,
  10514. // "Set to 0 (write and flush once per second),"
  10515. // " 1 (write and flush at each commit)"
  10516. // " or 2 (write at commit, flush once per second).",
  10517. // NULL, NULL, 1, 0, 2, 0);
  10518. static MYSQL_SYSVAR_BOOL(use_global_flush_log_at_trx_commit, srv_use_global_flush_log_at_trx_commit,
  10519. PLUGIN_VAR_NOCMDARG,
  10520. "Use global innodb_flush_log_at_trx_commit value. (default: ON).",
  10521. NULL, NULL, TRUE);
  10522. static MYSQL_SYSVAR_STR(flush_method, innobase_file_flush_method,
  10523. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10524. "With which method to flush data.", NULL, NULL, NULL);
  10525. static MYSQL_SYSVAR_BOOL(large_prefix, innobase_large_prefix,
  10526. PLUGIN_VAR_NOCMDARG,
  10527. "Support large index prefix length of REC_VERSION_56_MAX_INDEX_COL_LEN (3072) bytes.",
  10528. NULL, NULL, FALSE);
  10529. static MYSQL_SYSVAR_BOOL(force_load_corrupted, srv_load_corrupted,
  10530. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10531. "Force InnoDB to load metadata of corrupted table.",
  10532. NULL, NULL, FALSE);
  10533. static MYSQL_SYSVAR_BOOL(locks_unsafe_for_binlog, innobase_locks_unsafe_for_binlog,
  10534. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10535. "Force InnoDB to not use next-key locking, to use only row-level locking.",
  10536. NULL, NULL, FALSE);
  10537. static MYSQL_SYSVAR_ULONG(show_verbose_locks, srv_show_verbose_locks,
  10538. PLUGIN_VAR_OPCMDARG,
  10539. "Whether to show records locked in SHOW INNODB STATUS.",
  10540. NULL, NULL, 0, 0, 1, 0);
  10541. static MYSQL_SYSVAR_ULONG(show_locks_held, srv_show_locks_held,
  10542. PLUGIN_VAR_RQCMDARG,
  10543. "Number of locks held to print for each InnoDB transaction in SHOW INNODB STATUS.",
  10544. NULL, NULL, 10, 0, 1000, 0);
  10545. #ifdef UNIV_LOG_ARCHIVE
  10546. static MYSQL_SYSVAR_STR(log_arch_dir, innobase_log_arch_dir,
  10547. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10548. "Where full logs should be archived.", NULL, NULL, NULL);
  10549. static MYSQL_SYSVAR_BOOL(log_archive, innobase_log_archive,
  10550. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  10551. "Set to 1 if you want to have logs archived.", NULL, NULL, FALSE);
  10552. #endif /* UNIV_LOG_ARCHIVE */
  10553. static MYSQL_SYSVAR_STR(log_group_home_dir, innobase_log_group_home_dir,
  10554. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10555. "Path to InnoDB log files.", NULL, NULL, NULL);
  10556. static MYSQL_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
  10557. PLUGIN_VAR_RQCMDARG,
  10558. "Percentage of dirty pages allowed in bufferpool.",
  10559. NULL, NULL, 75, 0, 99, 0);
  10560. static MYSQL_SYSVAR_BOOL(adaptive_flushing, srv_adaptive_flushing,
  10561. PLUGIN_VAR_NOCMDARG,
  10562. "Attempt flushing dirty pages to avoid IO bursts at checkpoints.",
  10563. NULL, NULL, TRUE);
  10564. static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
  10565. PLUGIN_VAR_RQCMDARG,
  10566. "Desired maximum length of the purge queue (0 = no limit)",
  10567. NULL, NULL, 0, 0, ~0UL, 0);
  10568. static MYSQL_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
  10569. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  10570. "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
  10571. NULL, NULL, FALSE);
  10572. static MYSQL_SYSVAR_BOOL(status_file, innobase_create_status_file,
  10573. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_NOSYSVAR,
  10574. "Enable SHOW INNODB STATUS output in the innodb_status.<pid> file",
  10575. NULL, NULL, FALSE);
  10576. static MYSQL_SYSVAR_BOOL(stats_on_metadata, innobase_stats_on_metadata,
  10577. PLUGIN_VAR_OPCMDARG,
  10578. "Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)",
  10579. NULL, NULL, TRUE);
  10580. static MYSQL_SYSVAR_ULONGLONG(stats_sample_pages, srv_stats_sample_pages,
  10581. PLUGIN_VAR_RQCMDARG,
  10582. "The number of index pages to sample when calculating statistics (default 8)",
  10583. NULL, NULL, 8, 1, ~0ULL, 0);
  10584. static MYSQL_SYSVAR_ULINT(stats_auto_update, srv_stats_auto_update,
  10585. PLUGIN_VAR_RQCMDARG,
  10586. "Enable/Disable InnoDB's auto update statistics of indexes. "
  10587. "(except for ANALYZE TABLE command) 0:disable 1:enable",
  10588. NULL, NULL, 1, 0, 1, 0);
  10589. static MYSQL_SYSVAR_ULINT(stats_update_need_lock, srv_stats_update_need_lock,
  10590. PLUGIN_VAR_RQCMDARG,
  10591. "Enable/Disable InnoDB's update statistics which needs to lock dictionary. "
  10592. "e.g. Data_free.",
  10593. NULL, NULL, 1, 0, 1, 0);
  10594. static MYSQL_SYSVAR_BOOL(use_sys_stats_table, innobase_use_sys_stats_table,
  10595. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10596. "Enable to use SYS_STATS system table to store statistics statically, "
  10597. "And avoids to calculate statistics at every first open of the tables. "
  10598. "This option may make the opportunities of update statistics less. "
  10599. "So you should use ANALYZE TABLE command intentionally.",
  10600. NULL, NULL, FALSE);
  10601. #ifdef UNIV_DEBUG_never
  10602. static MYSQL_SYSVAR_ULONG(sys_stats_root_page, innobase_sys_stats_root_page,
  10603. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10604. "Override the SYS_STATS root page id, 0 = no override (for testing only)",
  10605. NULL, NULL, 0, 0, ULONG_MAX, 0);
  10606. #endif
  10607. static MYSQL_SYSVAR_BOOL(adaptive_hash_index, btr_search_enabled,
  10608. PLUGIN_VAR_OPCMDARG,
  10609. "Enable InnoDB adaptive hash index (enabled by default). "
  10610. "Disable with --skip-innodb-adaptive-hash-index.",
  10611. NULL, innodb_adaptive_hash_index_update, TRUE);
  10612. static MYSQL_SYSVAR_ULINT(adaptive_hash_index_partitions, btr_search_index_num,
  10613. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10614. "Number of InnoDB adaptive hash index partitions (default 1: disable partitioning)",
  10615. NULL, NULL, 1, 1, sizeof(ulint) * 8, 0);
  10616. static MYSQL_SYSVAR_ULONG(replication_delay, srv_replication_delay,
  10617. PLUGIN_VAR_RQCMDARG,
  10618. "Replication thread delay (ms) on the slave server if "
  10619. "innodb_thread_concurrency is reached (0 by default)",
  10620. NULL, NULL, 0, 0, ~0UL, 0);
  10621. static MYSQL_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
  10622. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10623. "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.",
  10624. NULL, NULL, 8*1024*1024L, 512*1024L, LONG_MAX, 1024);
  10625. static MYSQL_SYSVAR_ULONG(autoextend_increment, srv_auto_extend_increment,
  10626. PLUGIN_VAR_RQCMDARG,
  10627. "Data file autoextend increment in megabytes",
  10628. NULL, NULL, 8L, 1L, 1000L, 0);
  10629. static MYSQL_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
  10630. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10631. "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
  10632. NULL, NULL, 128*1024*1024L, 5*1024*1024L, LONGLONG_MAX, 1024*1024L);
  10633. static MYSQL_SYSVAR_LONG(buffer_pool_instances, innobase_buffer_pool_instances,
  10634. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10635. "Number of buffer pool instances, set to higher value on high-end machines to increase scalability",
  10636. NULL, NULL, 1L, 1L, MAX_BUFFER_POOLS, 1L);
  10637. static MYSQL_SYSVAR_UINT(buffer_pool_shm_key, innobase_buffer_pool_shm_key,
  10638. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10639. "[Deprecated option] no effect",
  10640. NULL, NULL, 0, 0, INT_MAX32, 0);
  10641. static MYSQL_SYSVAR_BOOL(buffer_pool_shm_checksum, innobase_buffer_pool_shm_checksum,
  10642. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10643. "[Deprecated option] no effect",
  10644. NULL, NULL, TRUE);
  10645. static MYSQL_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency,
  10646. PLUGIN_VAR_RQCMDARG,
  10647. "Helps in performance tuning in heavily concurrent environments.",
  10648. innobase_commit_concurrency_validate, NULL, 0, 0, 1000, 0);
  10649. static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter,
  10650. PLUGIN_VAR_RQCMDARG,
  10651. "Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket",
  10652. NULL, NULL, 500L, 1L, ~0UL, 0);
  10653. #ifdef EXTENDED_FOR_KILLIDLE
  10654. #define kill_idle_help_text "If non-zero value, the idle session with transaction which is idle over the value in seconds is killed by InnoDB."
  10655. #else
  10656. #define kill_idle_help_text "No effect for this build."
  10657. #endif
  10658. static MYSQL_SYSVAR_LONGLONG(kill_idle_transaction, srv_kill_idle_transaction,
  10659. PLUGIN_VAR_RQCMDARG, kill_idle_help_text, NULL, NULL, 0, 0, LONG_MAX, 0);
  10660. static MYSQL_SYSVAR_LONG(file_io_threads, innobase_file_io_threads,
  10661. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR,
  10662. "Number of file I/O threads in InnoDB.",
  10663. NULL, NULL, 4, 4, 64, 0);
  10664. static MYSQL_SYSVAR_ULONG(read_io_threads, innobase_read_io_threads,
  10665. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10666. "Number of background read I/O threads in InnoDB.",
  10667. NULL, NULL, 4, 1, 64, 0);
  10668. static MYSQL_SYSVAR_ULONG(write_io_threads, innobase_write_io_threads,
  10669. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10670. "Number of background write I/O threads in InnoDB.",
  10671. NULL, NULL, 4, 1, 64, 0);
  10672. static MYSQL_SYSVAR_LONG(force_recovery, innobase_force_recovery,
  10673. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10674. "Helps to save your data in case the disk image of the database becomes corrupt.",
  10675. NULL, NULL, 0, 0, 6, 0);
  10676. static MYSQL_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
  10677. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10678. "The size of the buffer which InnoDB uses to write log to the log files on disk.",
  10679. NULL, NULL, 8*1024*1024L, 256*1024L, LONG_MAX, 1024);
  10680. static MYSQL_SYSVAR_LONGLONG(log_file_size, innobase_log_file_size,
  10681. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10682. "Size of each log file in a log group.",
  10683. NULL, NULL, 5*1024*1024L, 1*1024*1024L, LONGLONG_MAX, 1024*1024L);
  10684. static MYSQL_SYSVAR_LONG(log_files_in_group, innobase_log_files_in_group,
  10685. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10686. "Number of log files in the log group. InnoDB writes to the files in a circular fashion. Value 3 is recommended here.",
  10687. NULL, NULL, 2, 2, 100, 0);
  10688. static MYSQL_SYSVAR_LONG(mirrored_log_groups, innobase_mirrored_log_groups,
  10689. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10690. "Number of identical copies of log groups we keep for the database. Currently this should be set to 1.",
  10691. NULL, NULL, 1, 1, 10, 0);
  10692. static MYSQL_SYSVAR_UINT(old_blocks_pct, innobase_old_blocks_pct,
  10693. PLUGIN_VAR_RQCMDARG,
  10694. "Percentage of the buffer pool to reserve for 'old' blocks.",
  10695. NULL, innodb_old_blocks_pct_update, 100 * 3 / 8, 5, 95, 0);
  10696. static MYSQL_SYSVAR_UINT(old_blocks_time, buf_LRU_old_threshold_ms,
  10697. PLUGIN_VAR_RQCMDARG,
  10698. "Move blocks to the 'new' end of the buffer pool if the first access"
  10699. " was at least this many milliseconds ago."
  10700. " The timeout is disabled if 0 (the default).",
  10701. NULL, NULL, 0, 0, UINT_MAX32, 0);
  10702. static MYSQL_SYSVAR_LONG(open_files, innobase_open_files,
  10703. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10704. "How many files at the maximum InnoDB keeps open at the same time.",
  10705. NULL, NULL, 300L, 10L, LONG_MAX, 0);
  10706. static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
  10707. PLUGIN_VAR_RQCMDARG,
  10708. "Count of spin-loop rounds in InnoDB mutexes (30 by default)",
  10709. NULL, NULL, 30L, 0L, ~0UL, 0);
  10710. static MYSQL_SYSVAR_ULONG(spin_wait_delay, srv_spin_wait_delay,
  10711. PLUGIN_VAR_OPCMDARG,
  10712. "Maximum delay between polling for a spin lock (6 by default)",
  10713. NULL, NULL, 6L, 0L, ~0UL, 0);
  10714. static MYSQL_SYSVAR_BOOL(thread_concurrency_timer_based,
  10715. innobase_thread_concurrency_timer_based,
  10716. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10717. "Use InnoDB timer based concurrency throttling. ",
  10718. NULL, NULL, FALSE);
  10719. static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
  10720. PLUGIN_VAR_RQCMDARG,
  10721. "Helps in performance tuning in heavily concurrent environments. Sets the maximum number of threads allowed inside InnoDB. Value 0 will disable the thread throttling.",
  10722. NULL, NULL, 0, 0, 1000, 0);
  10723. static MYSQL_SYSVAR_ULONG(thread_sleep_delay, srv_thread_sleep_delay,
  10724. PLUGIN_VAR_RQCMDARG,
  10725. "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0 disable a sleep",
  10726. NULL, NULL, 10000L, 0L, ~0UL, 0);
  10727. static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path,
  10728. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10729. "Path to individual files and their sizes.",
  10730. NULL, NULL, NULL);
  10731. static MYSQL_SYSVAR_STR(doublewrite_file, innobase_doublewrite_file,
  10732. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10733. "Path to special datafile for doublewrite buffer. (default is "": not used) ### ONLY FOR EXPERTS!!! ###",
  10734. NULL, NULL, NULL);
  10735. static MYSQL_SYSVAR_LONG(autoinc_lock_mode, innobase_autoinc_lock_mode,
  10736. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10737. "The AUTOINC lock modes supported by InnoDB: "
  10738. "0 => Old style AUTOINC locking (for backward"
  10739. " compatibility) "
  10740. "1 => New style AUTOINC locking "
  10741. "2 => No AUTOINC locking (unsafe for SBR)",
  10742. NULL, NULL,
  10743. AUTOINC_NEW_STYLE_LOCKING, /* Default setting */
  10744. AUTOINC_OLD_STYLE_LOCKING, /* Minimum value */
  10745. AUTOINC_NO_LOCKING, 0); /* Maximum value */
  10746. static MYSQL_SYSVAR_STR(version, innodb_version_str,
  10747. PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_READONLY,
  10748. "Percona-InnoDB-plugin version", NULL, NULL, INNODB_VERSION_STR);
  10749. static MYSQL_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc,
  10750. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10751. "Use OS memory allocator instead of InnoDB's internal memory allocator",
  10752. NULL, NULL, TRUE);
  10753. static MYSQL_SYSVAR_BOOL(use_native_aio, srv_use_native_aio,
  10754. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10755. "Use native AIO if supported on this platform.",
  10756. NULL, NULL, TRUE);
  10757. static MYSQL_SYSVAR_STR(change_buffering, innobase_change_buffering,
  10758. PLUGIN_VAR_RQCMDARG,
  10759. "Buffer changes to reduce random access: "
  10760. "OFF, ON, inserting, deleting, changing, or purging.",
  10761. innodb_change_buffering_validate,
  10762. innodb_change_buffering_update, "all");
  10763. static MYSQL_SYSVAR_ENUM(stats_method, srv_innodb_stats_method,
  10764. PLUGIN_VAR_RQCMDARG,
  10765. "Specifies how InnoDB index statistics collection code should "
  10766. "treat NULLs. Possible values are NULLS_EQUAL (default), "
  10767. "NULLS_UNEQUAL and NULLS_IGNORED",
  10768. NULL, NULL, SRV_STATS_NULLS_EQUAL, &innodb_stats_method_typelib);
  10769. #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
  10770. static MYSQL_SYSVAR_UINT(change_buffering_debug, ibuf_debug,
  10771. PLUGIN_VAR_RQCMDARG,
  10772. "Debug flags for InnoDB change buffering (0=none)",
  10773. NULL, NULL, 0, 0, 1, 0);
  10774. #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
  10775. static MYSQL_SYSVAR_BOOL(random_read_ahead, srv_random_read_ahead,
  10776. PLUGIN_VAR_NOCMDARG,
  10777. "Whether to use read ahead for random access within an extent.",
  10778. NULL, NULL, FALSE);
  10779. static MYSQL_SYSVAR_ULONG(read_ahead_threshold, srv_read_ahead_threshold,
  10780. PLUGIN_VAR_RQCMDARG,
  10781. "Number of pages that must be accessed sequentially for InnoDB to "
  10782. "trigger a readahead.",
  10783. NULL, NULL, 56, 0, 64, 0);
  10784. #ifdef UNIV_DEBUG_never
  10785. static MYSQL_SYSVAR_UINT(trx_rseg_n_slots_debug, trx_rseg_n_slots_debug,
  10786. PLUGIN_VAR_RQCMDARG,
  10787. "Debug flags for InnoDB to limit TRX_RSEG_N_SLOTS for trx_rsegf_undo_find_free()",
  10788. NULL, NULL, 0, 0, 1024, 0);
  10789. #endif /* UNIV_DEBUG */
  10790. static MYSQL_SYSVAR_LONGLONG(ibuf_max_size, srv_ibuf_max_size,
  10791. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  10792. "The maximum size of the insert buffer. (in bytes)",
  10793. NULL, NULL, LONGLONG_MAX, 0, LONGLONG_MAX, 0);
  10794. static MYSQL_SYSVAR_ULONG(ibuf_active_contract, srv_ibuf_active_contract,
  10795. PLUGIN_VAR_RQCMDARG,
  10796. "Enable/Disable active_contract of insert buffer. 0:disable 1:enable",
  10797. NULL, NULL, 1, 0, 1, 0);
  10798. static MYSQL_SYSVAR_ULONG(ibuf_accel_rate, srv_ibuf_accel_rate,
  10799. PLUGIN_VAR_RQCMDARG,
  10800. "Tunes amount of insert buffer processing of background, in addition to innodb_io_capacity. (in percentage)",
  10801. NULL, NULL, 100, 100, 999999999, 0);
  10802. static MYSQL_SYSVAR_ULINT(checkpoint_age_target, srv_checkpoint_age_target,
  10803. PLUGIN_VAR_RQCMDARG,
  10804. "Control soft limit of checkpoint age. (0 : not control)",
  10805. NULL, NULL, 0, 0, ~0UL, 0);
  10806. static
  10807. void
  10808. innodb_flush_neighbor_pages_update(
  10809. THD* thd,
  10810. struct st_mysql_sys_var* var,
  10811. void* var_ptr,
  10812. const void* save)
  10813. {
  10814. *(long *)var_ptr = (*(long *)save) % 3;
  10815. }
  10816. const char *flush_neighbor_pages_names[]=
  10817. {
  10818. "none", /* 0 */
  10819. "area",
  10820. "cont", /* 2 */
  10821. /* For compatibility with the older patch */
  10822. "0", /* "none" + 3 */
  10823. "1", /* "area" + 3 */
  10824. "2", /* "cont" + 3 */
  10825. NullS
  10826. };
  10827. TYPELIB flush_neighbor_pages_typelib=
  10828. {
  10829. array_elements(flush_neighbor_pages_names) - 1,
  10830. "flush_neighbor_pages_typelib",
  10831. flush_neighbor_pages_names,
  10832. NULL
  10833. };
  10834. static MYSQL_SYSVAR_ENUM(flush_neighbor_pages, srv_flush_neighbor_pages,
  10835. PLUGIN_VAR_RQCMDARG, "Neighbor page flushing behaviour: none: do not flush, "
  10836. "[area]: flush selected pages one-by-one, "
  10837. "cont: flush a contiguous block of pages", NULL,
  10838. innodb_flush_neighbor_pages_update, 1, &flush_neighbor_pages_typelib);
  10839. static
  10840. void
  10841. innodb_read_ahead_update(
  10842. THD* thd,
  10843. struct st_mysql_sys_var* var,
  10844. void* var_ptr,
  10845. const void* save)
  10846. {
  10847. *(long *)var_ptr= (*(long *)save) & 3;
  10848. }
  10849. const char *read_ahead_names[]=
  10850. {
  10851. "none", /* 0 */
  10852. "random",
  10853. "linear",
  10854. "both", /* 3 */
  10855. /* For compatibility of the older patch */
  10856. "0", /* 4 ("none" + 4) */
  10857. "1",
  10858. "2",
  10859. "3", /* 7 ("both" + 4) */
  10860. NullS
  10861. };
  10862. TYPELIB read_ahead_typelib=
  10863. {
  10864. array_elements(read_ahead_names) - 1, "read_ahead_typelib",
  10865. read_ahead_names, NULL
  10866. };
  10867. static MYSQL_SYSVAR_ENUM(read_ahead, srv_read_ahead,
  10868. PLUGIN_VAR_RQCMDARG,
  10869. "Control read ahead activity (none, random, [linear], both). [from 1.0.5: random read ahead is ignored]",
  10870. NULL, innodb_read_ahead_update, 2, &read_ahead_typelib);
  10871. static
  10872. void
  10873. innodb_adaptive_flushing_method_update(
  10874. THD* thd,
  10875. struct st_mysql_sys_var* var,
  10876. void* var_ptr,
  10877. const void* save)
  10878. {
  10879. *(long *)var_ptr= (*(long *)save) % 3;
  10880. }
  10881. const char *adaptive_flushing_method_names[]=
  10882. {
  10883. "native", /* 0 */
  10884. "estimate", /* 1 */
  10885. "keep_average", /* 2 */
  10886. /* For compatibility of the older patch */
  10887. "0", /* 3 ("none" + 3) */
  10888. "1", /* 4 ("estimate" + 3) */
  10889. "2", /* 5 ("keep_average" + 3) */
  10890. NullS
  10891. };
  10892. TYPELIB adaptive_flushing_method_typelib=
  10893. {
  10894. array_elements(adaptive_flushing_method_names) - 1, "adaptive_flushing_method_typelib",
  10895. adaptive_flushing_method_names, NULL
  10896. };
  10897. static MYSQL_SYSVAR_ENUM(adaptive_flushing_method, srv_adaptive_flushing_method,
  10898. PLUGIN_VAR_RQCMDARG,
  10899. "Choose method of innodb_adaptive_flushing. (native, [estimate], keep_average)",
  10900. NULL, innodb_adaptive_flushing_method_update, 1, &adaptive_flushing_method_typelib);
  10901. static MYSQL_SYSVAR_ULONG(import_table_from_xtrabackup, srv_expand_import,
  10902. PLUGIN_VAR_RQCMDARG,
  10903. "Enable/Disable converting automatically *.ibd files when import tablespace.",
  10904. NULL, NULL, 0, 0, 1, 0);
  10905. static MYSQL_SYSVAR_ULINT(dict_size_limit, srv_dict_size_limit,
  10906. PLUGIN_VAR_RQCMDARG,
  10907. "Limit the allocated memory for dictionary cache. (0: unlimited)",
  10908. NULL, NULL, 0, 0, LONG_MAX, 0);
  10909. static MYSQL_SYSVAR_UINT(buffer_pool_restore_at_startup, srv_auto_lru_dump,
  10910. PLUGIN_VAR_RQCMDARG,
  10911. "Time in seconds between automatic buffer pool dumps. "
  10912. "0 (the default) disables automatic dumps.",
  10913. NULL, NULL, 0, 0, UINT_MAX32, 0);
  10914. static MYSQL_SYSVAR_BOOL(blocking_buffer_pool_restore,
  10915. innobase_blocking_lru_restore,
  10916. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  10917. "Block XtraDB startup process until buffer pool is full restored from a "
  10918. "dump file (if present). Disabled by default.",
  10919. NULL, NULL, FALSE);
  10920. const char *corrupt_table_action_names[]=
  10921. {
  10922. "assert", /* 0 */
  10923. "warn", /* 1 */
  10924. "salvage", /* 2 */
  10925. NullS
  10926. };
  10927. TYPELIB corrupt_table_action_typelib=
  10928. {
  10929. array_elements(corrupt_table_action_names) - 1, "corrupt_table_action_typelib",
  10930. corrupt_table_action_names, NULL
  10931. };
  10932. static MYSQL_SYSVAR_ENUM(corrupt_table_action, srv_pass_corrupt_table,
  10933. PLUGIN_VAR_RQCMDARG,
  10934. "Warn corruptions of user tables as 'corrupt table' instead of not crashing itself, "
  10935. "when used with file_per_table. "
  10936. "All file io for the datafile after detected as corrupt are disabled, "
  10937. "except for the deletion. Possible options are 'assert', 'warn' & 'salvage'",
  10938. NULL, NULL, 0, &corrupt_table_action_typelib);
  10939. static MYSQL_SYSVAR_ULINT(lazy_drop_table, srv_lazy_drop_table,
  10940. PLUGIN_VAR_RQCMDARG,
  10941. "At deleting tablespace, only miminum needed processes at the time are done. "
  10942. "e.g. for http://bugs.mysql.com/51325",
  10943. NULL, NULL, 0, 0, 1, 0);
  10944. static struct st_mysql_sys_var* innobase_system_variables[]= {
  10945. MYSQL_SYSVAR(page_size),
  10946. MYSQL_SYSVAR(log_block_size),
  10947. MYSQL_SYSVAR(additional_mem_pool_size),
  10948. MYSQL_SYSVAR(autoextend_increment),
  10949. MYSQL_SYSVAR(buffer_pool_size),
  10950. MYSQL_SYSVAR(buffer_pool_instances),
  10951. MYSQL_SYSVAR(buffer_pool_shm_key),
  10952. MYSQL_SYSVAR(buffer_pool_shm_checksum),
  10953. MYSQL_SYSVAR(checksums),
  10954. MYSQL_SYSVAR(fast_checksum),
  10955. MYSQL_SYSVAR(commit_concurrency),
  10956. MYSQL_SYSVAR(concurrency_tickets),
  10957. MYSQL_SYSVAR(kill_idle_transaction),
  10958. MYSQL_SYSVAR(data_file_path),
  10959. MYSQL_SYSVAR(doublewrite_file),
  10960. MYSQL_SYSVAR(data_home_dir),
  10961. MYSQL_SYSVAR(doublewrite),
  10962. MYSQL_SYSVAR(recovery_stats),
  10963. MYSQL_SYSVAR(fast_shutdown),
  10964. MYSQL_SYSVAR(file_io_threads),
  10965. MYSQL_SYSVAR(read_io_threads),
  10966. MYSQL_SYSVAR(write_io_threads),
  10967. MYSQL_SYSVAR(file_per_table),
  10968. MYSQL_SYSVAR(file_format),
  10969. MYSQL_SYSVAR(file_format_check),
  10970. MYSQL_SYSVAR(file_format_max),
  10971. MYSQL_SYSVAR(flush_log_at_trx_commit),
  10972. MYSQL_SYSVAR(use_global_flush_log_at_trx_commit),
  10973. MYSQL_SYSVAR(flush_method),
  10974. MYSQL_SYSVAR(force_recovery),
  10975. MYSQL_SYSVAR(large_prefix),
  10976. MYSQL_SYSVAR(force_load_corrupted),
  10977. MYSQL_SYSVAR(locks_unsafe_for_binlog),
  10978. MYSQL_SYSVAR(lock_wait_timeout),
  10979. #ifdef UNIV_LOG_ARCHIVE
  10980. MYSQL_SYSVAR(log_arch_dir),
  10981. MYSQL_SYSVAR(log_archive),
  10982. #endif /* UNIV_LOG_ARCHIVE */
  10983. MYSQL_SYSVAR(log_buffer_size),
  10984. MYSQL_SYSVAR(log_file_size),
  10985. MYSQL_SYSVAR(log_files_in_group),
  10986. MYSQL_SYSVAR(log_group_home_dir),
  10987. MYSQL_SYSVAR(max_dirty_pages_pct),
  10988. MYSQL_SYSVAR(adaptive_flushing),
  10989. MYSQL_SYSVAR(max_purge_lag),
  10990. MYSQL_SYSVAR(mirrored_log_groups),
  10991. MYSQL_SYSVAR(old_blocks_pct),
  10992. MYSQL_SYSVAR(old_blocks_time),
  10993. MYSQL_SYSVAR(open_files),
  10994. MYSQL_SYSVAR(recovery_update_relay_log),
  10995. MYSQL_SYSVAR(rollback_on_timeout),
  10996. MYSQL_SYSVAR(stats_on_metadata),
  10997. MYSQL_SYSVAR(stats_auto_update),
  10998. MYSQL_SYSVAR(stats_update_need_lock),
  10999. MYSQL_SYSVAR(use_sys_stats_table),
  11000. #ifdef UNIV_DEBUG_never /* disable this flag. --innodb-sys-stats becomes ambiguous */
  11001. MYSQL_SYSVAR(sys_stats_root_page),
  11002. #endif
  11003. MYSQL_SYSVAR(stats_sample_pages),
  11004. MYSQL_SYSVAR(adaptive_hash_index),
  11005. MYSQL_SYSVAR(adaptive_hash_index_partitions),
  11006. MYSQL_SYSVAR(stats_method),
  11007. MYSQL_SYSVAR(replication_delay),
  11008. MYSQL_SYSVAR(status_file),
  11009. MYSQL_SYSVAR(strict_mode),
  11010. MYSQL_SYSVAR(support_xa),
  11011. MYSQL_SYSVAR(sync_spin_loops),
  11012. MYSQL_SYSVAR(spin_wait_delay),
  11013. MYSQL_SYSVAR(table_locks),
  11014. MYSQL_SYSVAR(thread_concurrency),
  11015. MYSQL_SYSVAR(thread_concurrency_timer_based),
  11016. MYSQL_SYSVAR(thread_sleep_delay),
  11017. MYSQL_SYSVAR(autoinc_lock_mode),
  11018. MYSQL_SYSVAR(show_verbose_locks),
  11019. MYSQL_SYSVAR(show_locks_held),
  11020. MYSQL_SYSVAR(version),
  11021. MYSQL_SYSVAR(ibuf_max_size),
  11022. MYSQL_SYSVAR(ibuf_active_contract),
  11023. MYSQL_SYSVAR(ibuf_accel_rate),
  11024. MYSQL_SYSVAR(checkpoint_age_target),
  11025. MYSQL_SYSVAR(flush_neighbor_pages),
  11026. MYSQL_SYSVAR(read_ahead),
  11027. MYSQL_SYSVAR(adaptive_flushing_method),
  11028. MYSQL_SYSVAR(import_table_from_xtrabackup),
  11029. MYSQL_SYSVAR(dict_size_limit),
  11030. MYSQL_SYSVAR(use_sys_malloc),
  11031. MYSQL_SYSVAR(use_native_aio),
  11032. MYSQL_SYSVAR(change_buffering),
  11033. #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
  11034. MYSQL_SYSVAR(change_buffering_debug),
  11035. #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
  11036. MYSQL_SYSVAR(random_read_ahead),
  11037. MYSQL_SYSVAR(read_ahead_threshold),
  11038. MYSQL_SYSVAR(io_capacity),
  11039. MYSQL_SYSVAR(buffer_pool_restore_at_startup),
  11040. MYSQL_SYSVAR(blocking_buffer_pool_restore),
  11041. MYSQL_SYSVAR(purge_threads),
  11042. MYSQL_SYSVAR(purge_batch_size),
  11043. MYSQL_SYSVAR(rollback_segments),
  11044. #ifdef UNIV_DEBUG_never /* disable this flag. --innodb-trx becomes ambiguous */
  11045. MYSQL_SYSVAR(trx_rseg_n_slots_debug),
  11046. #endif /* UNIV_DEBUG */
  11047. MYSQL_SYSVAR(corrupt_table_action),
  11048. MYSQL_SYSVAR(lazy_drop_table),
  11049. MYSQL_SYSVAR(fake_changes),
  11050. MYSQL_SYSVAR(merge_sort_block_size),
  11051. NULL
  11052. };
  11053. maria_declare_plugin(xtradb)
  11054. { /* InnoDB */
  11055. MYSQL_STORAGE_ENGINE_PLUGIN,
  11056. &innobase_storage_engine,
  11057. innobase_hton_name,
  11058. plugin_author,
  11059. "Percona-XtraDB, Supports transactions, row-level locking, and foreign keys",
  11060. PLUGIN_LICENSE_GPL,
  11061. innobase_init, /* Plugin Init */
  11062. NULL, /* Plugin Deinit */
  11063. INNODB_VERSION_SHORT,
  11064. innodb_status_variables_export,/* status variables */
  11065. innobase_system_variables, /* system variables */
  11066. INNODB_VERSION_STR, /* string version */
  11067. MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
  11068. },
  11069. i_s_innodb_rseg_maria,
  11070. i_s_innodb_undo_logs_maria,
  11071. i_s_innodb_trx_maria,
  11072. i_s_innodb_locks_maria,
  11073. i_s_innodb_lock_waits_maria,
  11074. i_s_innodb_cmp_maria,
  11075. i_s_innodb_cmp_reset_maria,
  11076. i_s_innodb_cmpmem_maria,
  11077. i_s_innodb_cmpmem_reset_maria,
  11078. i_s_innodb_sys_tables_maria,
  11079. i_s_innodb_sys_tablestats_maria,
  11080. i_s_innodb_sys_indexes_maria,
  11081. i_s_innodb_sys_columns_maria,
  11082. i_s_innodb_sys_fields_maria,
  11083. i_s_innodb_sys_foreign_maria,
  11084. i_s_innodb_sys_foreign_cols_maria,
  11085. i_s_innodb_sys_stats_maria,
  11086. i_s_innodb_table_stats_maria,
  11087. i_s_innodb_index_stats_maria,
  11088. i_s_innodb_buffer_pool_pages_maria,
  11089. i_s_innodb_buffer_pool_pages_index_maria,
  11090. i_s_innodb_buffer_pool_pages_blob_maria,
  11091. i_s_innodb_admin_command_maria
  11092. maria_declare_plugin_end;
  11093. /** @brief Initialize the default value of innodb_commit_concurrency.
  11094. Once InnoDB is running, the innodb_commit_concurrency must not change
  11095. from zero to nonzero. (Bug #42101)
  11096. The initial default value is 0, and without this extra initialization,
  11097. SET GLOBAL innodb_commit_concurrency=DEFAULT would set the parameter
  11098. to 0, even if it was initially set to nonzero at the command line
  11099. or configuration file. */
  11100. static
  11101. void
  11102. innobase_commit_concurrency_init_default(void)
  11103. /*==========================================*/
  11104. {
  11105. MYSQL_SYSVAR_NAME(commit_concurrency).def_val
  11106. = innobase_commit_concurrency;
  11107. }
  11108. #ifdef UNIV_COMPILE_TEST_FUNCS
  11109. typedef struct innobase_convert_name_test_struct {
  11110. char* buf;
  11111. ulint buflen;
  11112. const char* id;
  11113. ulint idlen;
  11114. void* thd;
  11115. ibool file_id;
  11116. const char* expected;
  11117. } innobase_convert_name_test_t;
  11118. void
  11119. test_innobase_convert_name()
  11120. {
  11121. char buf[1024];
  11122. ulint i;
  11123. innobase_convert_name_test_t test_input[] = {
  11124. {buf, sizeof(buf), "abcd", 4, NULL, TRUE, "\"abcd\""},
  11125. {buf, 7, "abcd", 4, NULL, TRUE, "\"abcd\""},
  11126. {buf, 6, "abcd", 4, NULL, TRUE, "\"abcd\""},
  11127. {buf, 5, "abcd", 4, NULL, TRUE, "\"abc\""},
  11128. {buf, 4, "abcd", 4, NULL, TRUE, "\"ab\""},
  11129. {buf, sizeof(buf), "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  11130. {buf, 9, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  11131. {buf, 8, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  11132. {buf, 7, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  11133. {buf, 6, "ab@0060cd", 9, NULL, TRUE, "\"ab`c\""},
  11134. {buf, 5, "ab@0060cd", 9, NULL, TRUE, "\"ab`\""},
  11135. {buf, 4, "ab@0060cd", 9, NULL, TRUE, "\"ab\""},
  11136. {buf, sizeof(buf), "ab\"cd", 5, NULL, TRUE,
  11137. "\"#mysql50#ab\"\"cd\""},
  11138. {buf, 17, "ab\"cd", 5, NULL, TRUE,
  11139. "\"#mysql50#ab\"\"cd\""},
  11140. {buf, 16, "ab\"cd", 5, NULL, TRUE,
  11141. "\"#mysql50#ab\"\"c\""},
  11142. {buf, 15, "ab\"cd", 5, NULL, TRUE,
  11143. "\"#mysql50#ab\"\"\""},
  11144. {buf, 14, "ab\"cd", 5, NULL, TRUE,
  11145. "\"#mysql50#ab\""},
  11146. {buf, 13, "ab\"cd", 5, NULL, TRUE,
  11147. "\"#mysql50#ab\""},
  11148. {buf, 12, "ab\"cd", 5, NULL, TRUE,
  11149. "\"#mysql50#a\""},
  11150. {buf, 11, "ab\"cd", 5, NULL, TRUE,
  11151. "\"#mysql50#\""},
  11152. {buf, 10, "ab\"cd", 5, NULL, TRUE,
  11153. "\"#mysql50\""},
  11154. {buf, sizeof(buf), "ab/cd", 5, NULL, TRUE, "\"ab\".\"cd\""},
  11155. {buf, 9, "ab/cd", 5, NULL, TRUE, "\"ab\".\"cd\""},
  11156. {buf, 8, "ab/cd", 5, NULL, TRUE, "\"ab\".\"c\""},
  11157. {buf, 7, "ab/cd", 5, NULL, TRUE, "\"ab\".\"\""},
  11158. {buf, 6, "ab/cd", 5, NULL, TRUE, "\"ab\"."},
  11159. {buf, 5, "ab/cd", 5, NULL, TRUE, "\"ab\"."},
  11160. {buf, 4, "ab/cd", 5, NULL, TRUE, "\"ab\""},
  11161. {buf, 3, "ab/cd", 5, NULL, TRUE, "\"a\""},
  11162. {buf, 2, "ab/cd", 5, NULL, TRUE, "\"\""},
  11163. /* XXX probably "" is a better result in this case
  11164. {buf, 1, "ab/cd", 5, NULL, TRUE, "."},
  11165. */
  11166. {buf, 0, "ab/cd", 5, NULL, TRUE, ""},
  11167. };
  11168. for (i = 0; i < sizeof(test_input) / sizeof(test_input[0]); i++) {
  11169. char* end;
  11170. ibool ok = TRUE;
  11171. size_t res_len;
  11172. fprintf(stderr, "TESTING %lu, %s, %lu, %s\n",
  11173. test_input[i].buflen,
  11174. test_input[i].id,
  11175. test_input[i].idlen,
  11176. test_input[i].expected);
  11177. end = innobase_convert_name(
  11178. test_input[i].buf,
  11179. test_input[i].buflen,
  11180. test_input[i].id,
  11181. test_input[i].idlen,
  11182. test_input[i].thd,
  11183. test_input[i].file_id);
  11184. res_len = (size_t) (end - test_input[i].buf);
  11185. if (res_len != strlen(test_input[i].expected)) {
  11186. fprintf(stderr, "unexpected len of the result: %u, "
  11187. "expected: %u\n", (unsigned) res_len,
  11188. (unsigned) strlen(test_input[i].expected));
  11189. ok = FALSE;
  11190. }
  11191. if (memcmp(test_input[i].buf,
  11192. test_input[i].expected,
  11193. strlen(test_input[i].expected)) != 0
  11194. || !ok) {
  11195. fprintf(stderr, "unexpected result: %.*s, "
  11196. "expected: %s\n", (int) res_len,
  11197. test_input[i].buf,
  11198. test_input[i].expected);
  11199. ok = FALSE;
  11200. }
  11201. if (ok) {
  11202. fprintf(stderr, "OK: res: %.*s\n\n", (int) res_len,
  11203. buf);
  11204. } else {
  11205. fprintf(stderr, "FAILED\n\n");
  11206. return;
  11207. }
  11208. }
  11209. }
  11210. #endif /* UNIV_COMPILE_TEST_FUNCS */
  11211. /****************************************************************************
  11212. * DS-MRR implementation
  11213. ***************************************************************************/
  11214. /**
  11215. * Multi Range Read interface, DS-MRR calls
  11216. */
  11217. int ha_innobase::multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
  11218. uint n_ranges, uint mode,
  11219. HANDLER_BUFFER *buf)
  11220. {
  11221. return ds_mrr.dsmrr_init(this, seq, seq_init_param, n_ranges, mode, buf);
  11222. }
  11223. int ha_innobase::multi_range_read_next(range_id_t *range_info)
  11224. {
  11225. return ds_mrr.dsmrr_next(range_info);
  11226. }
  11227. ha_rows ha_innobase::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
  11228. void *seq_init_param,
  11229. uint n_ranges, uint *bufsz,
  11230. uint *flags,
  11231. COST_VECT *cost)
  11232. {
  11233. /* See comments in ha_myisam::multi_range_read_info_const */
  11234. ds_mrr.init(this, table);
  11235. if (prebuilt->select_lock_type != LOCK_NONE)
  11236. *flags |= HA_MRR_USE_DEFAULT_IMPL;
  11237. ha_rows res= ds_mrr.dsmrr_info_const(keyno, seq, seq_init_param, n_ranges,
  11238. bufsz, flags, cost);
  11239. return res;
  11240. }
  11241. ha_rows ha_innobase::multi_range_read_info(uint keyno, uint n_ranges, uint keys,
  11242. uint key_parts, uint *bufsz,
  11243. uint *flags, COST_VECT *cost)
  11244. {
  11245. ds_mrr.init(this, table);
  11246. ha_rows res= ds_mrr.dsmrr_info(keyno, n_ranges, keys, key_parts, bufsz,
  11247. flags, cost);
  11248. return res;
  11249. }
  11250. int ha_innobase::multi_range_read_explain_info(uint mrr_mode, char *str, size_t size)
  11251. {
  11252. return ds_mrr.dsmrr_explain_info(mrr_mode, str, size);
  11253. }
  11254. /*
  11255. A helper function used only in index_cond_func_innodb
  11256. */
  11257. bool ha_innobase::is_thd_killed()
  11258. {
  11259. return thd_killed(user_thd);
  11260. }
  11261. /**
  11262. * Index Condition Pushdown interface implementation
  11263. */
  11264. /** Attempt to push down an index condition.
  11265. * @param[in] keyno MySQL key number
  11266. * @param[in] idx_cond Index condition to be checked
  11267. * @return idx_cond if pushed; NULL if not pushed
  11268. */
  11269. UNIV_INTERN
  11270. class Item*
  11271. ha_innobase::idx_cond_push(
  11272. uint keyno,
  11273. class Item* idx_cond)
  11274. {
  11275. DBUG_ENTER("ha_innobase::idx_cond_push");
  11276. DBUG_ASSERT(keyno != MAX_KEY);
  11277. DBUG_ASSERT(idx_cond != NULL);
  11278. pushed_idx_cond = idx_cond;
  11279. pushed_idx_cond_keyno = keyno;
  11280. in_range_check_pushed_down = TRUE;
  11281. /* Table handler will check the entire condition */
  11282. DBUG_RETURN(NULL);
  11283. }