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.

9804 lines
276 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2537:2605 from branches/5.1: ------------------------------------------------------------------------ r2545 | vasil | 2008-07-25 17:24:23 +0300 (Fri, 25 Jul 2008) | 37 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Fix Bug#38185 ha_innobase::info can hold locks even when called with HA_STATUS_NO_LOCK The fix is to call fsp_get_available_space_in_free_extents() from ha_innobase::info() only if HA_STATUS_NO_LOCK is not present in the flag *AND* change get_schema_tables_record() in MySQL's sql/sql_show.cc to call ::info() *without* HA_STATUS_NO_LOCK whenever a user issues SELECT FROM information_schema.tables; Without the change to sql/sql_show.cc this patch would lead to Bug#32440 resurfacing. I.e. delete_length would never be updated in ::info() and will remain 0 forever, resulting in the free space not being shown anywhere. This is the change to sql/sql_show.cc for reference, it needs to be committed to the MySQL repo before or at the same time with this change to ha_innodb.cc: --- patch begins here --- --- sql/sql_show.cc.orig 2008-07-23 09:32:14.000000000 +0300 +++ sql/sql_show.cc 2008-07-23 09:32:19.000000000 +0300 @@ -3549,8 +3549,7 @@ static int get_schema_tables_record(THD if(file) { - file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO | - HA_STATUS_NO_LOCK); + file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO); enum row_type row_type = file->get_row_type(); switch (row_type) { case ROW_TYPE_NOT_USED: --- patch ends here --- Approved by: Heikki ------------------------------------------------------------------------ r2603 | marko | 2008-08-21 16:25:05 +0300 (Thu, 21 Aug 2008) | 10 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/ha_prototypes.h M /branches/5.1/row/row0sel.c branches/5.1: Identify SELECT statements by thd_sql_command() == SQLCOM_SELECT instead of parsing the query string. This fixes MySQL Bug #37885 without us having to implement lexical analysis of SQL comments in yet another place. thd_is_select(): A new predicate. row_search_for_mysql(): Use thd_is_select(). Approved by Heikki. ------------------------------------------------------------------------
18 years ago
branches/zip: Merge 2537:2605 from branches/5.1: ------------------------------------------------------------------------ r2545 | vasil | 2008-07-25 17:24:23 +0300 (Fri, 25 Jul 2008) | 37 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Fix Bug#38185 ha_innobase::info can hold locks even when called with HA_STATUS_NO_LOCK The fix is to call fsp_get_available_space_in_free_extents() from ha_innobase::info() only if HA_STATUS_NO_LOCK is not present in the flag *AND* change get_schema_tables_record() in MySQL's sql/sql_show.cc to call ::info() *without* HA_STATUS_NO_LOCK whenever a user issues SELECT FROM information_schema.tables; Without the change to sql/sql_show.cc this patch would lead to Bug#32440 resurfacing. I.e. delete_length would never be updated in ::info() and will remain 0 forever, resulting in the free space not being shown anywhere. This is the change to sql/sql_show.cc for reference, it needs to be committed to the MySQL repo before or at the same time with this change to ha_innodb.cc: --- patch begins here --- --- sql/sql_show.cc.orig 2008-07-23 09:32:14.000000000 +0300 +++ sql/sql_show.cc 2008-07-23 09:32:19.000000000 +0300 @@ -3549,8 +3549,7 @@ static int get_schema_tables_record(THD if(file) { - file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO | - HA_STATUS_NO_LOCK); + file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO); enum row_type row_type = file->get_row_type(); switch (row_type) { case ROW_TYPE_NOT_USED: --- patch ends here --- Approved by: Heikki ------------------------------------------------------------------------ r2603 | marko | 2008-08-21 16:25:05 +0300 (Thu, 21 Aug 2008) | 10 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/ha_prototypes.h M /branches/5.1/row/row0sel.c branches/5.1: Identify SELECT statements by thd_sql_command() == SQLCOM_SELECT instead of parsing the query string. This fixes MySQL Bug #37885 without us having to implement lexical analysis of SQL comments in yet another place. thd_is_select(): A new predicate. row_search_for_mysql(): Use thd_is_select(). Approved by Heikki. ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
20 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
20 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2384:2423 from branches/5.1: ------------------------------------------------------------------------ r2386 | vasil | 2008-03-27 07:45:02 +0200 (Thu, 27 Mar 2008) | 22 lines branches/5.1: Merge change from MySQL (this fixes the failing innodb test): ChangeSet@1.1810.3601.4, 2008-02-07 02:33:21+04:00, gshchepa@host.loc +9 -0 Fixed bug#30059. Server handles truncation for assignment of too-long values into CHAR/VARCHAR/TEXT columns in a different ways when the truncated characters are spaces: 1. CHAR(N) columns silently ignore end-space truncation; 2. TEXT columns post a truncation warning/error in the non-strict/strict mode. 3. VARCHAR columns always post a truncation note in any mode. Space truncation processing has been synchronised over CHAR/VARCHAR/TEXT columns: current behavior of VARCHAR columns has been propagated as standard. Binary-encoded string/BLOB columns are not affected. ------------------------------------------------------------------------ r2387 | vasil | 2008-03-27 08:49:05 +0200 (Thu, 27 Mar 2008) | 8 lines branches/5.1: Check whether *trx->mysql_query_str is != NULL in addition to trx->mysql_query_str. This adds more safety. This may or may not fix Bug#35226 RBR event crashes slave. ------------------------------------------------------------------------ r2388 | vasil | 2008-03-27 14:02:34 +0200 (Thu, 27 Mar 2008) | 7 lines branches/5.1: Swap the order in which mysql_thd, mysql_query_str and *mysql_query_str are checked for non-NULL. Suggested by: Marko ------------------------------------------------------------------------ r2419 | vasil | 2008-04-23 19:08:06 +0300 (Wed, 23 Apr 2008) | 9 lines branches/5.1: Change the fix for Bug#32440 to show bytes instead of kilobytes in INFORMATION_SCHEMA.TABLES.DATA_FREE. Suggested by: Domas Mituzas <domas@mysql.com> Approved by: Heikki ------------------------------------------------------------------------ r2420 | calvin | 2008-04-24 15:25:30 +0300 (Thu, 24 Apr 2008) | 4 lines branches/5.1: Fix bug#29507 TRUNCATE shows to many rows effected In InnoDB, the row count is only a rough estimate used by SQL optimization. InnoDB is now return row count 0 for TRUNCATE operation. ------------------------------------------------------------------------ r2421 | calvin | 2008-04-24 15:32:30 +0300 (Thu, 24 Apr 2008) | 6 lines branches/5.1: Fix bug#35537 - Innodb doesn't increment handler_update and handler_delete Add the calls to ha_statistic_increment() in ha_innobase::delete_row() and ha_innobase::update_row(). ------------------------------------------------------------------------ r2422 | vasil | 2008-04-24 16:00:30 +0300 (Thu, 24 Apr 2008) | 11 lines branches/5.1: Fix Bug#36169 create innodb compressed table with too large row size crashed Sometimes it is possible that row_drop_table_for_mysql(index->table_name, trx, FALSE); is invoked in row_create_index_for_mysql() when the index object is freed so copy the table name to a safe place beforehand and use the copy. Approved by: Sunny ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2384:2423 from branches/5.1: ------------------------------------------------------------------------ r2386 | vasil | 2008-03-27 07:45:02 +0200 (Thu, 27 Mar 2008) | 22 lines branches/5.1: Merge change from MySQL (this fixes the failing innodb test): ChangeSet@1.1810.3601.4, 2008-02-07 02:33:21+04:00, gshchepa@host.loc +9 -0 Fixed bug#30059. Server handles truncation for assignment of too-long values into CHAR/VARCHAR/TEXT columns in a different ways when the truncated characters are spaces: 1. CHAR(N) columns silently ignore end-space truncation; 2. TEXT columns post a truncation warning/error in the non-strict/strict mode. 3. VARCHAR columns always post a truncation note in any mode. Space truncation processing has been synchronised over CHAR/VARCHAR/TEXT columns: current behavior of VARCHAR columns has been propagated as standard. Binary-encoded string/BLOB columns are not affected. ------------------------------------------------------------------------ r2387 | vasil | 2008-03-27 08:49:05 +0200 (Thu, 27 Mar 2008) | 8 lines branches/5.1: Check whether *trx->mysql_query_str is != NULL in addition to trx->mysql_query_str. This adds more safety. This may or may not fix Bug#35226 RBR event crashes slave. ------------------------------------------------------------------------ r2388 | vasil | 2008-03-27 14:02:34 +0200 (Thu, 27 Mar 2008) | 7 lines branches/5.1: Swap the order in which mysql_thd, mysql_query_str and *mysql_query_str are checked for non-NULL. Suggested by: Marko ------------------------------------------------------------------------ r2419 | vasil | 2008-04-23 19:08:06 +0300 (Wed, 23 Apr 2008) | 9 lines branches/5.1: Change the fix for Bug#32440 to show bytes instead of kilobytes in INFORMATION_SCHEMA.TABLES.DATA_FREE. Suggested by: Domas Mituzas <domas@mysql.com> Approved by: Heikki ------------------------------------------------------------------------ r2420 | calvin | 2008-04-24 15:25:30 +0300 (Thu, 24 Apr 2008) | 4 lines branches/5.1: Fix bug#29507 TRUNCATE shows to many rows effected In InnoDB, the row count is only a rough estimate used by SQL optimization. InnoDB is now return row count 0 for TRUNCATE operation. ------------------------------------------------------------------------ r2421 | calvin | 2008-04-24 15:32:30 +0300 (Thu, 24 Apr 2008) | 6 lines branches/5.1: Fix bug#35537 - Innodb doesn't increment handler_update and handler_delete Add the calls to ha_statistic_increment() in ha_innobase::delete_row() and ha_innobase::update_row(). ------------------------------------------------------------------------ r2422 | vasil | 2008-04-24 16:00:30 +0300 (Thu, 24 Apr 2008) | 11 lines branches/5.1: Fix Bug#36169 create innodb compressed table with too large row size crashed Sometimes it is possible that row_drop_table_for_mysql(index->table_name, trx, FALSE); is invoked in row_create_index_for_mysql() when the index object is freed so copy the table name to a safe place beforehand and use the copy. Approved by: Sunny ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
20 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2384:2423 from branches/5.1: ------------------------------------------------------------------------ r2386 | vasil | 2008-03-27 07:45:02 +0200 (Thu, 27 Mar 2008) | 22 lines branches/5.1: Merge change from MySQL (this fixes the failing innodb test): ChangeSet@1.1810.3601.4, 2008-02-07 02:33:21+04:00, gshchepa@host.loc +9 -0 Fixed bug#30059. Server handles truncation for assignment of too-long values into CHAR/VARCHAR/TEXT columns in a different ways when the truncated characters are spaces: 1. CHAR(N) columns silently ignore end-space truncation; 2. TEXT columns post a truncation warning/error in the non-strict/strict mode. 3. VARCHAR columns always post a truncation note in any mode. Space truncation processing has been synchronised over CHAR/VARCHAR/TEXT columns: current behavior of VARCHAR columns has been propagated as standard. Binary-encoded string/BLOB columns are not affected. ------------------------------------------------------------------------ r2387 | vasil | 2008-03-27 08:49:05 +0200 (Thu, 27 Mar 2008) | 8 lines branches/5.1: Check whether *trx->mysql_query_str is != NULL in addition to trx->mysql_query_str. This adds more safety. This may or may not fix Bug#35226 RBR event crashes slave. ------------------------------------------------------------------------ r2388 | vasil | 2008-03-27 14:02:34 +0200 (Thu, 27 Mar 2008) | 7 lines branches/5.1: Swap the order in which mysql_thd, mysql_query_str and *mysql_query_str are checked for non-NULL. Suggested by: Marko ------------------------------------------------------------------------ r2419 | vasil | 2008-04-23 19:08:06 +0300 (Wed, 23 Apr 2008) | 9 lines branches/5.1: Change the fix for Bug#32440 to show bytes instead of kilobytes in INFORMATION_SCHEMA.TABLES.DATA_FREE. Suggested by: Domas Mituzas <domas@mysql.com> Approved by: Heikki ------------------------------------------------------------------------ r2420 | calvin | 2008-04-24 15:25:30 +0300 (Thu, 24 Apr 2008) | 4 lines branches/5.1: Fix bug#29507 TRUNCATE shows to many rows effected In InnoDB, the row count is only a rough estimate used by SQL optimization. InnoDB is now return row count 0 for TRUNCATE operation. ------------------------------------------------------------------------ r2421 | calvin | 2008-04-24 15:32:30 +0300 (Thu, 24 Apr 2008) | 6 lines branches/5.1: Fix bug#35537 - Innodb doesn't increment handler_update and handler_delete Add the calls to ha_statistic_increment() in ha_innobase::delete_row() and ha_innobase::update_row(). ------------------------------------------------------------------------ r2422 | vasil | 2008-04-24 16:00:30 +0300 (Thu, 24 Apr 2008) | 11 lines branches/5.1: Fix Bug#36169 create innodb compressed table with too large row size crashed Sometimes it is possible that row_drop_table_for_mysql(index->table_name, trx, FALSE); is invoked in row_create_index_for_mysql() when the index object is freed so copy the table name to a safe place beforehand and use the copy. Approved by: Sunny ------------------------------------------------------------------------
18 years ago
branches/zip: Merge 2489:2524 from branches/5.1: ------------------------------------------------------------------------ r2519 | sunny | 2008-06-26 16:55:43 +0300 (Thu, 26 Jun 2008) | 5 lines branches/5.1: Add test cases and fix a bug where the last AUTOINC cached value was not reset to 0 when the table was truncated. Bug #37531 : After truncate, auto_increment behaves incorrectly for InnoDB ------------------------------------------------------------------------ r2520 | vasil | 2008-06-26 17:38:02 +0300 (Thu, 26 Jun 2008) | 7 lines branches/5.1: Fix Bug#36941 Performance problem in ha_print_info (SHOW INNODB STATUS) by disabling some of the code in ha_print_info() in production builds. Approved by: Heikki (via IM) ------------------------------------------------------------------------ r2521 | vasil | 2008-06-26 17:39:01 +0300 (Thu, 26 Jun 2008) | 8 lines branches/5.1: Fix Bug#36942 Performance problem in lock_get_n_rec_locks (SHOW INNODB STATUS) by not calling lock_get_n_rec_locks() from lock_print_info_summary() on production builds. Approved by: Heikki (via IM) ------------------------------------------------------------------------ r2524 | vasil | 2008-07-01 10:37:34 +0300 (Tue, 01 Jul 2008) | 29 lines branches/5.1: Merge a change from MySQL (this fixes the failing innodb-replace test): revno: 2659 committer: Mattias Jonsson <mattiasj@mysql.com> branch nick: b31210-51-bugteam timestamp: Tue 2008-06-03 13:25:41 +0200 message: Bug#31210: INSERT DELAYED crashes server when used on partitioned tables Problem was an unclear error message since it could suggest that MyISAM did not support INSERT DELAYED. Changed the error message to say that DELAYED is not supported by the table, instead of the table's storage engine. The confusion is that a partitioned table is in somewhat sense using the partitioning storage engine, which in turn uses the ordinary storage engine. By saying that the table does not support DELAYED we do not give any extra informantion about the storage engine or if it is partitioned. modified: mysql-test/r/innodb-replace.result mysql-test/t/innodb-replace.test mysql-test/t/merge.test mysql-test/t/partition_hash.test sql/share/errmsg.txt sql/sql_insert.cc ------------------------------------------------------------------------
18 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge 2384:2423 from branches/5.1: ------------------------------------------------------------------------ r2386 | vasil | 2008-03-27 07:45:02 +0200 (Thu, 27 Mar 2008) | 22 lines branches/5.1: Merge change from MySQL (this fixes the failing innodb test): ChangeSet@1.1810.3601.4, 2008-02-07 02:33:21+04:00, gshchepa@host.loc +9 -0 Fixed bug#30059. Server handles truncation for assignment of too-long values into CHAR/VARCHAR/TEXT columns in a different ways when the truncated characters are spaces: 1. CHAR(N) columns silently ignore end-space truncation; 2. TEXT columns post a truncation warning/error in the non-strict/strict mode. 3. VARCHAR columns always post a truncation note in any mode. Space truncation processing has been synchronised over CHAR/VARCHAR/TEXT columns: current behavior of VARCHAR columns has been propagated as standard. Binary-encoded string/BLOB columns are not affected. ------------------------------------------------------------------------ r2387 | vasil | 2008-03-27 08:49:05 +0200 (Thu, 27 Mar 2008) | 8 lines branches/5.1: Check whether *trx->mysql_query_str is != NULL in addition to trx->mysql_query_str. This adds more safety. This may or may not fix Bug#35226 RBR event crashes slave. ------------------------------------------------------------------------ r2388 | vasil | 2008-03-27 14:02:34 +0200 (Thu, 27 Mar 2008) | 7 lines branches/5.1: Swap the order in which mysql_thd, mysql_query_str and *mysql_query_str are checked for non-NULL. Suggested by: Marko ------------------------------------------------------------------------ r2419 | vasil | 2008-04-23 19:08:06 +0300 (Wed, 23 Apr 2008) | 9 lines branches/5.1: Change the fix for Bug#32440 to show bytes instead of kilobytes in INFORMATION_SCHEMA.TABLES.DATA_FREE. Suggested by: Domas Mituzas <domas@mysql.com> Approved by: Heikki ------------------------------------------------------------------------ r2420 | calvin | 2008-04-24 15:25:30 +0300 (Thu, 24 Apr 2008) | 4 lines branches/5.1: Fix bug#29507 TRUNCATE shows to many rows effected In InnoDB, the row count is only a rough estimate used by SQL optimization. InnoDB is now return row count 0 for TRUNCATE operation. ------------------------------------------------------------------------ r2421 | calvin | 2008-04-24 15:32:30 +0300 (Thu, 24 Apr 2008) | 6 lines branches/5.1: Fix bug#35537 - Innodb doesn't increment handler_update and handler_delete Add the calls to ha_statistic_increment() in ha_innobase::delete_row() and ha_innobase::update_row(). ------------------------------------------------------------------------ r2422 | vasil | 2008-04-24 16:00:30 +0300 (Thu, 24 Apr 2008) | 11 lines branches/5.1: Fix Bug#36169 create innodb compressed table with too large row size crashed Sometimes it is possible that row_drop_table_for_mysql(index->table_name, trx, FALSE); is invoked in row_create_index_for_mysql() when the index object is freed so copy the table name to a safe place beforehand and use the copy. Approved by: Sunny ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
branches/zip: Merge 2537:2605 from branches/5.1: ------------------------------------------------------------------------ r2545 | vasil | 2008-07-25 17:24:23 +0300 (Fri, 25 Jul 2008) | 37 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Fix Bug#38185 ha_innobase::info can hold locks even when called with HA_STATUS_NO_LOCK The fix is to call fsp_get_available_space_in_free_extents() from ha_innobase::info() only if HA_STATUS_NO_LOCK is not present in the flag *AND* change get_schema_tables_record() in MySQL's sql/sql_show.cc to call ::info() *without* HA_STATUS_NO_LOCK whenever a user issues SELECT FROM information_schema.tables; Without the change to sql/sql_show.cc this patch would lead to Bug#32440 resurfacing. I.e. delete_length would never be updated in ::info() and will remain 0 forever, resulting in the free space not being shown anywhere. This is the change to sql/sql_show.cc for reference, it needs to be committed to the MySQL repo before or at the same time with this change to ha_innodb.cc: --- patch begins here --- --- sql/sql_show.cc.orig 2008-07-23 09:32:14.000000000 +0300 +++ sql/sql_show.cc 2008-07-23 09:32:19.000000000 +0300 @@ -3549,8 +3549,7 @@ static int get_schema_tables_record(THD if(file) { - file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO | - HA_STATUS_NO_LOCK); + file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO); enum row_type row_type = file->get_row_type(); switch (row_type) { case ROW_TYPE_NOT_USED: --- patch ends here --- Approved by: Heikki ------------------------------------------------------------------------ r2603 | marko | 2008-08-21 16:25:05 +0300 (Thu, 21 Aug 2008) | 10 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/ha_prototypes.h M /branches/5.1/row/row0sel.c branches/5.1: Identify SELECT statements by thd_sql_command() == SQLCOM_SELECT instead of parsing the query string. This fixes MySQL Bug #37885 without us having to implement lexical analysis of SQL comments in yet another place. thd_is_select(): A new predicate. row_search_for_mysql(): Use thd_is_select(). Approved by Heikki. ------------------------------------------------------------------------
18 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge 2744:2837 from branches/5.1 (skipping r2782 and r2826): ------------------------------------------------------------------------ r2832 | vasil | 2008-10-21 10:08:30 +0300 (Tue, 21 Oct 2008) | 10 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: In ha_innobase::info(): Replace sql_print_warning() which prints to mysqld error log with push_warning_printf() which sends the error message to the client. Suggested by: Marko, Sunny, Michael Objected by: Inaam ------------------------------------------------------------------------ r2837 | vasil | 2008-10-21 12:07:44 +0300 (Tue, 21 Oct 2008) | 32 lines Changed paths: M /branches/5.1/mysql-test/innodb-semi-consistent.result M /branches/5.1/mysql-test/innodb-semi-consistent.test M /branches/5.1/mysql-test/innodb.result M /branches/5.1/mysql-test/innodb.test branches/5.1: Merge a change from MySQL (this fixes the failing innodb and innodb-semi-consistent tests): revno: 2757 committer: Georgi Kodinov <kgeorge@mysql.com> branch nick: B39812-5.1-5.1.29-rc timestamp: Fri 2008-10-03 15:24:19 +0300 message: Bug #39812: Make statement replication default for 5.1 (to match 5.0) Make STMT replication default for 5.1. Add a default of MIXED into the config files Fix the tests that needed MIXED replication mode. modified: mysql-test/include/mix1.inc mysql-test/r/innodb-semi-consistent.result mysql-test/r/innodb.result mysql-test/r/innodb_mysql.result mysql-test/r/tx_isolation_func.result mysql-test/t/innodb-semi-consistent.test mysql-test/t/innodb.test mysql-test/t/tx_isolation_func.test sql/mysqld.cc support-files/my-huge.cnf.sh support-files/my-innodb-heavy-4G.cnf.sh support-files/my-large.cnf.sh support-files/my-medium.cnf.sh support-files/my-small.cnf.sh ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge 2537:2605 from branches/5.1: ------------------------------------------------------------------------ r2545 | vasil | 2008-07-25 17:24:23 +0300 (Fri, 25 Jul 2008) | 37 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Fix Bug#38185 ha_innobase::info can hold locks even when called with HA_STATUS_NO_LOCK The fix is to call fsp_get_available_space_in_free_extents() from ha_innobase::info() only if HA_STATUS_NO_LOCK is not present in the flag *AND* change get_schema_tables_record() in MySQL's sql/sql_show.cc to call ::info() *without* HA_STATUS_NO_LOCK whenever a user issues SELECT FROM information_schema.tables; Without the change to sql/sql_show.cc this patch would lead to Bug#32440 resurfacing. I.e. delete_length would never be updated in ::info() and will remain 0 forever, resulting in the free space not being shown anywhere. This is the change to sql/sql_show.cc for reference, it needs to be committed to the MySQL repo before or at the same time with this change to ha_innodb.cc: --- patch begins here --- --- sql/sql_show.cc.orig 2008-07-23 09:32:14.000000000 +0300 +++ sql/sql_show.cc 2008-07-23 09:32:19.000000000 +0300 @@ -3549,8 +3549,7 @@ static int get_schema_tables_record(THD if(file) { - file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO | - HA_STATUS_NO_LOCK); + file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO); enum row_type row_type = file->get_row_type(); switch (row_type) { case ROW_TYPE_NOT_USED: --- patch ends here --- Approved by: Heikki ------------------------------------------------------------------------ r2603 | marko | 2008-08-21 16:25:05 +0300 (Thu, 21 Aug 2008) | 10 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/ha_prototypes.h M /branches/5.1/row/row0sel.c branches/5.1: Identify SELECT statements by thd_sql_command() == SQLCOM_SELECT instead of parsing the query string. This fixes MySQL Bug #37885 without us having to implement lexical analysis of SQL comments in yet another place. thd_is_select(): A new predicate. row_search_for_mysql(): Use thd_is_select(). Approved by Heikki. ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2423:2437 from branches/5.1: ------------------------------------------------------------------------ r2429 | vasil | 2008-04-30 11:19:06 +0300 (Wed, 30 Apr 2008) | 10 lines branches/5.1: * Use INNODB_CFLAGS insead of cluttering CFLAGS with InnoDB specific flags. CFLAGS are used to compile every file in the MySQL source tree. * Add INNODB_DYNAMIC_CFLAGS to the flags of the dynamic plugin and use -prefer-non-pic to make the dynamic plugin faster on i386. Approved by: Sunny ------------------------------------------------------------------------ r2430 | vasil | 2008-04-30 11:48:35 +0300 (Wed, 30 Apr 2008) | 8 lines branches/5.1: Use CFLAGS instead of INNODB_CFLAGS to avoid having incompatible flags inserted in CFLAGS and INNODB_CFLAGS and to avoid compiling mysql and innodb with different flags. Discussed with: Sunny ------------------------------------------------------------------------ r2431 | vasil | 2008-04-30 11:54:49 +0300 (Wed, 30 Apr 2008) | 4 lines branches/5.1: Fix r2430, it should be CFLAGS="$CFLAGS ..." not CFLAGS="..." ------------------------------------------------------------------------ r2432 | vasil | 2008-04-30 11:58:38 +0300 (Wed, 30 Apr 2008) | 4 lines branches/5.1: Non-functional change: use tabs for indentation in plug.in. ------------------------------------------------------------------------ r2433 | vasil | 2008-04-30 12:02:35 +0300 (Wed, 30 Apr 2008) | 5 lines branches/5.1: Add vim modeline to hint it that plug.in is a config file so it can be colorized. ------------------------------------------------------------------------ r2434 | vasil | 2008-04-30 18:45:44 +0300 (Wed, 30 Apr 2008) | 17 lines branches/5.1: Merge changes from MySQL: ChangeSet@1.2645, 2007-12-19 13:24:43+00:00, jperkin@chorlton.adsl.perkin.org.uk +14 -0 Add new pkgplugindir handling to seperate plugins from libraries, and allow override for binary distributions. Extend mysql_config to print compiled-in plugin location for third-party plugins to use. Resolves bug#31736. and ChangeSet@1.2646, 2008-01-02 13:00:46+00:00, jperkin@chorlton.adsl.perkin.org.uk +11 -0 Use pkglibdir to simplify pkgplugindir, and fix the path in a couple of Makefiles. Continuation of the fix for bug#31736. ------------------------------------------------------------------------ r2435 | vasil | 2008-04-30 19:04:36 +0300 (Wed, 30 Apr 2008) | 10 lines branches/5.1: Merge change from MySQL: ChangeSet@1.2563, 2008-03-18 19:42:04+04:00, gluh@mysql.com +1 -0 Bug#35406 5.1-opt crashes on select from I_S.REFERENTIAL_CONSTRAINTS added intialization of f_key_info.referenced_key_name for the case when referenced table is dropped ------------------------------------------------------------------------ r2436 | vasil | 2008-04-30 19:15:46 +0300 (Wed, 30 Apr 2008) | 7 lines branches/5.1: Non-functional white space change in Makefile.am: Use tabs for indentation and be consistent about spaces around the equal sign. ------------------------------------------------------------------------ r2437 | vasil | 2008-04-30 20:36:11 +0300 (Wed, 30 Apr 2008) | 8 lines branches/5.1: Fix Bug#36434 ha_innodb.so is installed in the wrong directory Change pkglib_LTLIBRARIES with pkgplugin_LTLIBRARIES which has been forgotten in this commit: http://lists.mysql.com/commits/40206 ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2605:2617 from branches/5.1: ------------------------------------------------------------------------ r2609 | sunny | 2008-08-24 01:19:05 +0300 (Sun, 24 Aug 2008) | 12 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Fix for MySQL Bug#38839. Reset the statement level last value field in prebuilt. This field tracks the last value in an autoincrement interval. We use this value to check whether we need to update a table's AUTOINC counter, if the value written to a table is less than this value then we avoid updating the table's AUTOINC value in order to reduce mutex contention. If it's not reset (e.g., after a DELETE statement) then there is the possibility of missing updates to the table's AUTOINC counter resulting in a subsequent duplicate row error message under certain conditions (see the test case for details). Bug #38839 - auto increment does not work properly with InnoDB after update ------------------------------------------------------------------------ r2617 | vasil | 2008-09-09 15:46:17 +0300 (Tue, 09 Sep 2008) | 47 lines Changed paths: M /branches/5.1/mysql-test/innodb.result branches/5.1: Merge a change from MySQL (fix the failing innodb test): ------------------------------------------------------------ revno: 2646.12.1 committer: Mattias Jonsson <mattiasj@mysql.com> branch nick: wl4176_2-51-bugteam timestamp: Mon 2008-08-11 20:02:03 +0200 message: Bug#20129: ALTER TABLE ... REPAIR PARTITION ... complains that partition is corrupt The main problem was that ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR PARTITION took another code path (over mysql_alter_table instead of mysql_admin_table) which differs in two ways: 1) alter table opens the tables in a different way than admin tables do resulting in returning with error before it tried the command 2) alter table does not start to send any diagnostic rows to the client which the lower admin functions continue to use -> resulting in assertion crash The fix: Remapped ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR PARTITION to use the same code path as ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE t. Adding check in mysql_admin_table to setup the partition list for which partitions that should be used. Partitioned tables will still not work with REPAIR TABLE/PARTITION USE_FRM, since that requires moving partitions to tables, REPAIR TABLE t USE_FRM, and check that the data still fulfills the partitioning function and then move the table back to being a partition. NOTE: I have removed the following functions from the handler interface: analyze_partitions, check_partitions, optimize_partitions, repair_partitions Since they are not longer needed. THIS ALTERS THE STORAGE ENGINE API I have verified that OPTIMIZE TABLE actually rebuilds the table and calls ANALYZE. Approved by: Heikki
18 years ago
branches/zip: Merge 2605:2617 from branches/5.1: ------------------------------------------------------------------------ r2609 | sunny | 2008-08-24 01:19:05 +0300 (Sun, 24 Aug 2008) | 12 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Fix for MySQL Bug#38839. Reset the statement level last value field in prebuilt. This field tracks the last value in an autoincrement interval. We use this value to check whether we need to update a table's AUTOINC counter, if the value written to a table is less than this value then we avoid updating the table's AUTOINC value in order to reduce mutex contention. If it's not reset (e.g., after a DELETE statement) then there is the possibility of missing updates to the table's AUTOINC counter resulting in a subsequent duplicate row error message under certain conditions (see the test case for details). Bug #38839 - auto increment does not work properly with InnoDB after update ------------------------------------------------------------------------ r2617 | vasil | 2008-09-09 15:46:17 +0300 (Tue, 09 Sep 2008) | 47 lines Changed paths: M /branches/5.1/mysql-test/innodb.result branches/5.1: Merge a change from MySQL (fix the failing innodb test): ------------------------------------------------------------ revno: 2646.12.1 committer: Mattias Jonsson <mattiasj@mysql.com> branch nick: wl4176_2-51-bugteam timestamp: Mon 2008-08-11 20:02:03 +0200 message: Bug#20129: ALTER TABLE ... REPAIR PARTITION ... complains that partition is corrupt The main problem was that ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR PARTITION took another code path (over mysql_alter_table instead of mysql_admin_table) which differs in two ways: 1) alter table opens the tables in a different way than admin tables do resulting in returning with error before it tried the command 2) alter table does not start to send any diagnostic rows to the client which the lower admin functions continue to use -> resulting in assertion crash The fix: Remapped ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR PARTITION to use the same code path as ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE t. Adding check in mysql_admin_table to setup the partition list for which partitions that should be used. Partitioned tables will still not work with REPAIR TABLE/PARTITION USE_FRM, since that requires moving partitions to tables, REPAIR TABLE t USE_FRM, and check that the data still fulfills the partitioning function and then move the table back to being a partition. NOTE: I have removed the following functions from the handler interface: analyze_partitions, check_partitions, optimize_partitions, repair_partitions Since they are not longer needed. THIS ALTERS THE STORAGE ENGINE API I have verified that OPTIMIZE TABLE actually rebuilds the table and calls ANALYZE. Approved by: Heikki
18 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge 2605:2617 from branches/5.1: ------------------------------------------------------------------------ r2609 | sunny | 2008-08-24 01:19:05 +0300 (Sun, 24 Aug 2008) | 12 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Fix for MySQL Bug#38839. Reset the statement level last value field in prebuilt. This field tracks the last value in an autoincrement interval. We use this value to check whether we need to update a table's AUTOINC counter, if the value written to a table is less than this value then we avoid updating the table's AUTOINC value in order to reduce mutex contention. If it's not reset (e.g., after a DELETE statement) then there is the possibility of missing updates to the table's AUTOINC counter resulting in a subsequent duplicate row error message under certain conditions (see the test case for details). Bug #38839 - auto increment does not work properly with InnoDB after update ------------------------------------------------------------------------ r2617 | vasil | 2008-09-09 15:46:17 +0300 (Tue, 09 Sep 2008) | 47 lines Changed paths: M /branches/5.1/mysql-test/innodb.result branches/5.1: Merge a change from MySQL (fix the failing innodb test): ------------------------------------------------------------ revno: 2646.12.1 committer: Mattias Jonsson <mattiasj@mysql.com> branch nick: wl4176_2-51-bugteam timestamp: Mon 2008-08-11 20:02:03 +0200 message: Bug#20129: ALTER TABLE ... REPAIR PARTITION ... complains that partition is corrupt The main problem was that ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR PARTITION took another code path (over mysql_alter_table instead of mysql_admin_table) which differs in two ways: 1) alter table opens the tables in a different way than admin tables do resulting in returning with error before it tried the command 2) alter table does not start to send any diagnostic rows to the client which the lower admin functions continue to use -> resulting in assertion crash The fix: Remapped ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR PARTITION to use the same code path as ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE t. Adding check in mysql_admin_table to setup the partition list for which partitions that should be used. Partitioned tables will still not work with REPAIR TABLE/PARTITION USE_FRM, since that requires moving partitions to tables, REPAIR TABLE t USE_FRM, and check that the data still fulfills the partitioning function and then move the table back to being a partition. NOTE: I have removed the following functions from the handler interface: analyze_partitions, check_partitions, optimize_partitions, repair_partitions Since they are not longer needed. THIS ALTERS THE STORAGE ENGINE API I have verified that OPTIMIZE TABLE actually rebuilds the table and calls ANALYZE. Approved by: Heikki
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Throw warnings, not errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, so that any table dump can be loaded. As of this change, InnoDB supports the following table formats: ROW_FORMAT=REDUNDANT the only format before MySQL/InnoDB 5.0.3 ROW_FORMAT=COMPACT the new default format of MySQL/InnoDB 5.0.3 ROW_FORMAT=DYNAMIC uncompressed, no prefix in the clustered index record for BLOBs ROW_FORMAT=COMPRESSED like ROW_FORMAT=DYNAMIC, but zlib compressed B-trees and BLOBs; the compressed page size is specified by KEY_BLOCK_SIZE in kilobytes (1, 2, 4, 8, or 16; default 8) KEY_BLOCK_SIZE=1, 2, 4, 8, or 16: implies ROW_FORMAT=COMPRESSED; ignored if ROW_FORMAT is not COMPRESSED KEY_BLOCK_SIZE=anything else: ignored The InnoDB row format is displayed in the 4th column (Row_format) of the output of SHOW TABLE STATUS. The Create_options column may show ROW_FORMAT= and KEY_BLOCK_SIZE=, but they do not necessarily have anything to do with InnoDB. The table format can also be queried like this: SELECT table_schema, table_name, row_format FROM information_schema.tables WHERE engine='innodb' and row_format in ('Compressed','Dynamic'); When Row_format='Compressed', KEY_BLOCK_SIZE should usually correspond to the compressed page size. But the .frm file could be manipulated to show any KEY_BLOCK_SIZE. For some reason, INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS does not include KEY_BLOCK_SIZE. It does include row_format (spelled in lowercase). This looks like a MySQL bug, because the table INFORMATION_SCHEMA.TABLES probably tries to replace SHOW TABLE STATUS. I reported this as Bug #35275 <http://bugs.mysql.com/35275>. ha_innobase::get_row_type(): Add ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC. ha_innobase::create(): Implement ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC. Do not throw errors for wrong ROW_FORMAT or KEY_BLOCK_SIZE, but issue warnings instead. ha_innobase::check_if_incompatible_data(): Return COMPATIBLE_DATA_NO if KEY_BLOCK_SIZE has been specified. innodb.result: Adjust the result for the warning issued for ROW_FORMAT=FIXED. innodb-zip.test: Add tests. Query INFORMATION_SCHEMA.TABLES for ROW_FORMAT.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
  1. /* Copyright (C) 2000-2005 MySQL AB & Innobase Oy
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /* TODO list for the InnoDB handler in 5.0:
  13. - Remove the flag trx->active_trans and look at trx->conc_state
  14. - fix savepoint functions to use savepoint storage area
  15. - Find out what kind of problems the OS X case-insensitivity causes to
  16. table and database names; should we 'normalize' the names like we do
  17. in Windows?
  18. */
  19. #ifdef USE_PRAGMA_IMPLEMENTATION
  20. #pragma implementation // gcc: Class implementation
  21. #endif
  22. #include <mysql_priv.h>
  23. #include <mysqld_error.h>
  24. #include <m_ctype.h>
  25. #include <hash.h>
  26. #include <myisampack.h>
  27. #include <mysys_err.h>
  28. #include <my_sys.h>
  29. #include <mysql/plugin.h>
  30. /* Include necessary InnoDB headers */
  31. extern "C" {
  32. #include "../storage/innobase/include/univ.i"
  33. #include "../storage/innobase/include/btr0sea.h"
  34. #include "../storage/innobase/include/os0file.h"
  35. #include "../storage/innobase/include/os0thread.h"
  36. #include "../storage/innobase/include/srv0start.h"
  37. #include "../storage/innobase/include/srv0srv.h"
  38. #include "../storage/innobase/include/trx0roll.h"
  39. #include "../storage/innobase/include/trx0trx.h"
  40. #include "../storage/innobase/include/trx0sys.h"
  41. #include "../storage/innobase/include/mtr0mtr.h"
  42. #include "../storage/innobase/include/row0ins.h"
  43. #include "../storage/innobase/include/row0mysql.h"
  44. #include "../storage/innobase/include/row0sel.h"
  45. #include "../storage/innobase/include/row0upd.h"
  46. #include "../storage/innobase/include/log0log.h"
  47. #include "../storage/innobase/include/lock0lock.h"
  48. #include "../storage/innobase/include/dict0crea.h"
  49. #include "../storage/innobase/include/btr0cur.h"
  50. #include "../storage/innobase/include/btr0btr.h"
  51. #include "../storage/innobase/include/fsp0fsp.h"
  52. #include "../storage/innobase/include/sync0sync.h"
  53. #include "../storage/innobase/include/fil0fil.h"
  54. #include "../storage/innobase/include/trx0xa.h"
  55. #include "../storage/innobase/include/row0merge.h"
  56. #include "../storage/innobase/include/thr0loc.h"
  57. #include "../storage/innobase/include/dict0boot.h"
  58. #include "../storage/innobase/include/ha_prototypes.h"
  59. #include "../storage/innobase/include/ut0mem.h"
  60. }
  61. #include "ha_innodb.h"
  62. #include "i_s.h"
  63. #ifndef MYSQL_SERVER
  64. /* This is needed because of Bug #3596. Let us hope that pthread_mutex_t
  65. is defined the same in both builds: the MySQL server and the InnoDB plugin. */
  66. extern pthread_mutex_t LOCK_thread_count;
  67. #if MYSQL_VERSION_ID < 50124
  68. /* this is defined in mysql_priv.h inside #ifdef MYSQL_SERVER
  69. but we need it here */
  70. bool check_global_access(THD *thd, ulong want_access);
  71. #endif /* MYSQL_VERSION_ID < 50124 */
  72. #endif /* MYSQL_SERVER */
  73. /** to protect innobase_open_files */
  74. static pthread_mutex_t innobase_share_mutex;
  75. /** to force correct commit order in binlog */
  76. static pthread_mutex_t prepare_commit_mutex;
  77. static ulong commit_threads = 0;
  78. static pthread_mutex_t commit_threads_m;
  79. static pthread_cond_t commit_cond;
  80. static pthread_mutex_t commit_cond_m;
  81. static bool innodb_inited = 0;
  82. #define INSIDE_HA_INNOBASE_CC
  83. /* In the Windows plugin, the return value of current_thd is
  84. undefined. Map it to NULL. */
  85. #if defined MYSQL_DYNAMIC_PLUGIN && defined __WIN__
  86. # undef current_thd
  87. # define current_thd NULL
  88. # define EQ_CURRENT_THD(thd) TRUE
  89. #else /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
  90. # define EQ_CURRENT_THD(thd) ((thd) == current_thd)
  91. #endif /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
  92. #ifdef MYSQL_DYNAMIC_PLUGIN
  93. /* These must be weak global variables in the dynamic plugin. */
  94. struct handlerton* innodb_hton_ptr;
  95. int builtin_innobase_plugin;
  96. /********************************************************************
  97. Copy InnoDB system variables from the static InnoDB to the dynamic
  98. plugin. */
  99. static
  100. bool
  101. innodb_plugin_init(void);
  102. /*====================*/
  103. /* out: TRUE if the dynamic InnoDB plugin should start */
  104. #else /* MYSQL_DYNAMIC_PLUGIN */
  105. /* This must be a global variable in the statically linked InnoDB. */
  106. struct handlerton* innodb_hton_ptr = NULL;
  107. #endif /* MYSQL_DYNAMIC_PLUGIN */
  108. static const long AUTOINC_OLD_STYLE_LOCKING = 0;
  109. static const long AUTOINC_NEW_STYLE_LOCKING = 1;
  110. static const long AUTOINC_NO_LOCKING = 2;
  111. static long innobase_mirrored_log_groups, innobase_log_files_in_group,
  112. innobase_log_buffer_size,
  113. innobase_additional_mem_pool_size, innobase_file_io_threads,
  114. innobase_force_recovery, innobase_open_files,
  115. innobase_autoinc_lock_mode;
  116. static long long innobase_buffer_pool_size, innobase_log_file_size;
  117. /* The default values for the following char* start-up parameters
  118. are determined in innobase_init below: */
  119. static char* innobase_data_home_dir = NULL;
  120. static char* innobase_data_file_path = NULL;
  121. static char* innobase_log_group_home_dir = NULL;
  122. static char* innobase_file_format_name = NULL;
  123. /* Note: This variable can be set to on/off and any of the supported
  124. file formats in the configuration file, but can only be set to any
  125. of the supported file formats during runtime. */
  126. static char* innobase_file_format_check = NULL;
  127. /* The following has a misleading name: starting from 4.0.5, this also
  128. affects Windows: */
  129. static char* innobase_unix_file_flush_method = NULL;
  130. /* Below we have boolean-valued start-up parameters, and their default
  131. values */
  132. static ulong innobase_fast_shutdown = 1;
  133. #ifdef UNIV_LOG_ARCHIVE
  134. static my_bool innobase_log_archive = FALSE;
  135. static char* innobase_log_arch_dir = NULL;
  136. #endif /* UNIV_LOG_ARCHIVE */
  137. static my_bool innobase_use_doublewrite = TRUE;
  138. static my_bool innobase_use_checksums = TRUE;
  139. static my_bool innobase_locks_unsafe_for_binlog = FALSE;
  140. static my_bool innobase_rollback_on_timeout = FALSE;
  141. static my_bool innobase_create_status_file = FALSE;
  142. static my_bool innobase_stats_on_metadata = TRUE;
  143. static my_bool innobase_adaptive_hash_index = TRUE;
  144. static char* internal_innobase_data_file_path = NULL;
  145. static char* innodb_version_str = (char*) INNODB_VERSION_STR;
  146. /* The following counter is used to convey information to InnoDB
  147. about server activity: in selects it is not sensible to call
  148. srv_active_wake_master_thread after each fetch or search, we only do
  149. it every INNOBASE_WAKE_INTERVAL'th step. */
  150. #define INNOBASE_WAKE_INTERVAL 32
  151. static ulong innobase_active_counter = 0;
  152. static HASH innobase_open_tables;
  153. #ifdef __NETWARE__ /* some special cleanup for NetWare */
  154. bool nw_panic = FALSE;
  155. #endif
  156. static uchar* innobase_get_key(INNOBASE_SHARE *share, size_t *length,
  157. my_bool not_used __attribute__((unused)));
  158. static INNOBASE_SHARE *get_share(const char *table_name);
  159. static void free_share(INNOBASE_SHARE *share);
  160. static int innobase_close_connection(handlerton *hton, THD* thd);
  161. static int innobase_commit(handlerton *hton, THD* thd, bool all);
  162. static int innobase_rollback(handlerton *hton, THD* thd, bool all);
  163. static int innobase_rollback_to_savepoint(handlerton *hton, THD* thd,
  164. void *savepoint);
  165. static int innobase_savepoint(handlerton *hton, THD* thd, void *savepoint);
  166. static int innobase_release_savepoint(handlerton *hton, THD* thd,
  167. void *savepoint);
  168. static handler *innobase_create_handler(handlerton *hton,
  169. TABLE_SHARE *table,
  170. MEM_ROOT *mem_root);
  171. /****************************************************************
  172. Validate the file format name and return its corresponding id. */
  173. static
  174. uint
  175. innobase_file_format_name_lookup(
  176. /*=============================*/
  177. /* out: valid file format id */
  178. const char* format_name); /* in: pointer to file format
  179. name */
  180. /****************************************************************
  181. Validate the file format check config parameters, as a side effect it
  182. sets the srv_check_file_format_at_startup variable. */
  183. static
  184. bool
  185. innobase_file_format_check_on_off(
  186. /*==============================*/
  187. /* out: true if one of
  188. "on" or "off" */
  189. const char* format_check); /* in: parameter value */
  190. /****************************************************************
  191. Validate the file format check config parameters, as a side effect it
  192. sets the srv_check_file_format_at_startup variable. */
  193. static
  194. bool
  195. innobase_file_format_check_validate(
  196. /*================================*/
  197. /* out: true if valid
  198. config value */
  199. const char* format_check); /* in: parameter value */
  200. /********************************************************************
  201. Return alter table flags supported in an InnoDB database. */
  202. static
  203. uint
  204. innobase_alter_table_flags(
  205. /*=======================*/
  206. uint flags);
  207. static const char innobase_hton_name[]= "InnoDB";
  208. static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
  209. "Enable InnoDB support for the XA two-phase commit",
  210. /* check_func */ NULL, /* update_func */ NULL,
  211. /* default */ TRUE);
  212. static MYSQL_THDVAR_BOOL(table_locks, PLUGIN_VAR_OPCMDARG,
  213. "Enable InnoDB locking in LOCK TABLES",
  214. /* check_func */ NULL, /* update_func */ NULL,
  215. /* default */ TRUE);
  216. static MYSQL_THDVAR_BOOL(strict_mode, PLUGIN_VAR_OPCMDARG,
  217. "Use strict mode when evaluating create options.",
  218. NULL, NULL, FALSE);
  219. static MYSQL_THDVAR_ULONG(lock_wait_timeout, PLUGIN_VAR_RQCMDARG,
  220. "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
  221. NULL, NULL, 50, 1, 1024 * 1024 * 1024, 0);
  222. static handler *innobase_create_handler(handlerton *hton,
  223. TABLE_SHARE *table,
  224. MEM_ROOT *mem_root)
  225. {
  226. return new (mem_root) ha_innobase(hton, table);
  227. }
  228. /***********************************************************************
  229. This function is used to prepare X/Open XA distributed transaction */
  230. static
  231. int
  232. innobase_xa_prepare(
  233. /*================*/
  234. /* out: 0 or error number */
  235. handlerton* hton,
  236. THD* thd, /* in: handle to the MySQL thread of the user
  237. whose XA transaction should be prepared */
  238. bool all); /* in: TRUE - commit transaction
  239. FALSE - the current SQL statement ended */
  240. /***********************************************************************
  241. This function is used to recover X/Open XA distributed transactions */
  242. static
  243. int
  244. innobase_xa_recover(
  245. /*================*/
  246. /* out: number of prepared transactions
  247. stored in xid_list */
  248. handlerton* hton,
  249. XID* xid_list, /* in/out: prepared transactions */
  250. uint len); /* in: number of slots in xid_list */
  251. /***********************************************************************
  252. This function is used to commit one X/Open XA distributed transaction
  253. which is in the prepared state */
  254. static
  255. int
  256. innobase_commit_by_xid(
  257. /*===================*/
  258. /* out: 0 or error number */
  259. handlerton* hton,
  260. XID* xid); /* in: X/Open XA transaction identification */
  261. /***********************************************************************
  262. This function is used to rollback one X/Open XA distributed transaction
  263. which is in the prepared state */
  264. static
  265. int
  266. innobase_rollback_by_xid(
  267. /*=====================*/
  268. /* out: 0 or error number */
  269. handlerton* hton,
  270. XID *xid); /* in: X/Open XA transaction identification */
  271. /***********************************************************************
  272. Create a consistent view for a cursor based on current transaction
  273. which is created if the corresponding MySQL thread still lacks one.
  274. This consistent view is then used inside of MySQL when accessing records
  275. using a cursor. */
  276. static
  277. void*
  278. innobase_create_cursor_view(
  279. /*========================*/
  280. /* out: pointer to cursor view or NULL */
  281. handlerton* hton, /* in: innobase hton */
  282. THD* thd); /* in: user thread handle */
  283. /***********************************************************************
  284. Set the given consistent cursor view to a transaction which is created
  285. if the corresponding MySQL thread still lacks one. If the given
  286. consistent cursor view is NULL global read view of a transaction is
  287. restored to a transaction read view. */
  288. static
  289. void
  290. innobase_set_cursor_view(
  291. /*=====================*/
  292. handlerton* hton,
  293. THD* thd, /* in: user thread handle */
  294. void* curview);/* in: Consistent cursor view to be set */
  295. /***********************************************************************
  296. Close the given consistent cursor view of a transaction and restore
  297. global read view to a transaction read view. Transaction is created if the
  298. corresponding MySQL thread still lacks one. */
  299. static
  300. void
  301. innobase_close_cursor_view(
  302. /*=======================*/
  303. handlerton* hton,
  304. THD* thd, /* in: user thread handle */
  305. void* curview);/* in: Consistent read view to be closed */
  306. /*********************************************************************
  307. Removes all tables in the named database inside InnoDB. */
  308. static
  309. void
  310. innobase_drop_database(
  311. /*===================*/
  312. /* out: error number */
  313. handlerton* hton, /* in: handlerton of Innodb */
  314. char* path); /* in: database path; inside InnoDB the name
  315. of the last directory in the path is used as
  316. the database name: for example, in 'mysql/data/test'
  317. the database name is 'test' */
  318. /***********************************************************************
  319. Closes an InnoDB database. */
  320. static
  321. int
  322. innobase_end(handlerton *hton, ha_panic_function type);
  323. /*********************************************************************
  324. Creates an InnoDB transaction struct for the thd if it does not yet have one.
  325. Starts a new InnoDB transaction if a transaction is not yet started. And
  326. assigns a new snapshot for a consistent read if the transaction does not yet
  327. have one. */
  328. static
  329. int
  330. innobase_start_trx_and_assign_read_view(
  331. /*====================================*/
  332. /* out: 0 */
  333. handlerton* hton, /* in: Innodb handlerton */
  334. THD* thd); /* in: MySQL thread handle of the user for whom
  335. the transaction should be committed */
  336. /********************************************************************
  337. Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
  338. the logs, and the name of this function should be innobase_checkpoint. */
  339. static
  340. bool
  341. innobase_flush_logs(
  342. /*================*/
  343. /* out: TRUE if error */
  344. handlerton* hton); /* in: InnoDB handlerton */
  345. /****************************************************************************
  346. Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
  347. Monitor to the client. */
  348. static
  349. bool
  350. innodb_show_status(
  351. /*===============*/
  352. handlerton* hton, /* in: the innodb handlerton */
  353. THD* thd, /* in: the MySQL query thread of the caller */
  354. stat_print_fn *stat_print);
  355. static
  356. bool innobase_show_status(handlerton *hton, THD* thd,
  357. stat_print_fn* stat_print,
  358. enum ha_stat_type stat_type);
  359. /*********************************************************************
  360. Commits a transaction in an InnoDB database. */
  361. static
  362. void
  363. innobase_commit_low(
  364. /*================*/
  365. trx_t* trx); /* in: transaction handle */
  366. static SHOW_VAR innodb_status_variables[]= {
  367. {"buffer_pool_pages_data",
  368. (char*) &export_vars.innodb_buffer_pool_pages_data, SHOW_LONG},
  369. {"buffer_pool_pages_dirty",
  370. (char*) &export_vars.innodb_buffer_pool_pages_dirty, SHOW_LONG},
  371. {"buffer_pool_pages_flushed",
  372. (char*) &export_vars.innodb_buffer_pool_pages_flushed, SHOW_LONG},
  373. {"buffer_pool_pages_free",
  374. (char*) &export_vars.innodb_buffer_pool_pages_free, SHOW_LONG},
  375. #ifdef UNIV_DEBUG
  376. {"buffer_pool_pages_latched",
  377. (char*) &export_vars.innodb_buffer_pool_pages_latched, SHOW_LONG},
  378. #endif /* UNIV_DEBUG */
  379. {"buffer_pool_pages_misc",
  380. (char*) &export_vars.innodb_buffer_pool_pages_misc, SHOW_LONG},
  381. {"buffer_pool_pages_total",
  382. (char*) &export_vars.innodb_buffer_pool_pages_total, SHOW_LONG},
  383. {"buffer_pool_read_ahead_rnd",
  384. (char*) &export_vars.innodb_buffer_pool_read_ahead_rnd, SHOW_LONG},
  385. {"buffer_pool_read_ahead_seq",
  386. (char*) &export_vars.innodb_buffer_pool_read_ahead_seq, SHOW_LONG},
  387. {"buffer_pool_read_requests",
  388. (char*) &export_vars.innodb_buffer_pool_read_requests, SHOW_LONG},
  389. {"buffer_pool_reads",
  390. (char*) &export_vars.innodb_buffer_pool_reads, SHOW_LONG},
  391. {"buffer_pool_wait_free",
  392. (char*) &export_vars.innodb_buffer_pool_wait_free, SHOW_LONG},
  393. {"buffer_pool_write_requests",
  394. (char*) &export_vars.innodb_buffer_pool_write_requests, SHOW_LONG},
  395. {"data_fsyncs",
  396. (char*) &export_vars.innodb_data_fsyncs, SHOW_LONG},
  397. {"data_pending_fsyncs",
  398. (char*) &export_vars.innodb_data_pending_fsyncs, SHOW_LONG},
  399. {"data_pending_reads",
  400. (char*) &export_vars.innodb_data_pending_reads, SHOW_LONG},
  401. {"data_pending_writes",
  402. (char*) &export_vars.innodb_data_pending_writes, SHOW_LONG},
  403. {"data_read",
  404. (char*) &export_vars.innodb_data_read, SHOW_LONG},
  405. {"data_reads",
  406. (char*) &export_vars.innodb_data_reads, SHOW_LONG},
  407. {"data_writes",
  408. (char*) &export_vars.innodb_data_writes, SHOW_LONG},
  409. {"data_written",
  410. (char*) &export_vars.innodb_data_written, SHOW_LONG},
  411. {"dblwr_pages_written",
  412. (char*) &export_vars.innodb_dblwr_pages_written, SHOW_LONG},
  413. {"dblwr_writes",
  414. (char*) &export_vars.innodb_dblwr_writes, SHOW_LONG},
  415. {"log_waits",
  416. (char*) &export_vars.innodb_log_waits, SHOW_LONG},
  417. {"log_write_requests",
  418. (char*) &export_vars.innodb_log_write_requests, SHOW_LONG},
  419. {"log_writes",
  420. (char*) &export_vars.innodb_log_writes, SHOW_LONG},
  421. {"os_log_fsyncs",
  422. (char*) &export_vars.innodb_os_log_fsyncs, SHOW_LONG},
  423. {"os_log_pending_fsyncs",
  424. (char*) &export_vars.innodb_os_log_pending_fsyncs, SHOW_LONG},
  425. {"os_log_pending_writes",
  426. (char*) &export_vars.innodb_os_log_pending_writes, SHOW_LONG},
  427. {"os_log_written",
  428. (char*) &export_vars.innodb_os_log_written, SHOW_LONG},
  429. {"page_size",
  430. (char*) &export_vars.innodb_page_size, SHOW_LONG},
  431. {"pages_created",
  432. (char*) &export_vars.innodb_pages_created, SHOW_LONG},
  433. {"pages_read",
  434. (char*) &export_vars.innodb_pages_read, SHOW_LONG},
  435. {"pages_written",
  436. (char*) &export_vars.innodb_pages_written, SHOW_LONG},
  437. {"row_lock_current_waits",
  438. (char*) &export_vars.innodb_row_lock_current_waits, SHOW_LONG},
  439. {"row_lock_time",
  440. (char*) &export_vars.innodb_row_lock_time, SHOW_LONGLONG},
  441. {"row_lock_time_avg",
  442. (char*) &export_vars.innodb_row_lock_time_avg, SHOW_LONG},
  443. {"row_lock_time_max",
  444. (char*) &export_vars.innodb_row_lock_time_max, SHOW_LONG},
  445. {"row_lock_waits",
  446. (char*) &export_vars.innodb_row_lock_waits, SHOW_LONG},
  447. {"rows_deleted",
  448. (char*) &export_vars.innodb_rows_deleted, SHOW_LONG},
  449. {"rows_inserted",
  450. (char*) &export_vars.innodb_rows_inserted, SHOW_LONG},
  451. {"rows_read",
  452. (char*) &export_vars.innodb_rows_read, SHOW_LONG},
  453. {"rows_updated",
  454. (char*) &export_vars.innodb_rows_updated, SHOW_LONG},
  455. {NullS, NullS, SHOW_LONG}
  456. };
  457. /* General functions */
  458. /**********************************************************************
  459. Returns true if the thread is the replication thread on the slave
  460. server. Used in srv_conc_enter_innodb() to determine if the thread
  461. should be allowed to enter InnoDB - the replication thread is treated
  462. differently than other threads. Also used in
  463. srv_conc_force_exit_innodb(). */
  464. extern "C" UNIV_INTERN
  465. ibool
  466. thd_is_replication_slave_thread(
  467. /*============================*/
  468. /* out: true if thd is the replication thread */
  469. void* thd) /* in: thread handle (THD*) */
  470. {
  471. return((ibool) thd_slave_thread((THD*) thd));
  472. }
  473. /**********************************************************************
  474. Save some CPU by testing the value of srv_thread_concurrency in inline
  475. functions. */
  476. inline
  477. void
  478. innodb_srv_conc_enter_innodb(
  479. /*=========================*/
  480. trx_t* trx) /* in: transaction handle */
  481. {
  482. if (UNIV_LIKELY(!srv_thread_concurrency)) {
  483. return;
  484. }
  485. srv_conc_enter_innodb(trx);
  486. }
  487. /**********************************************************************
  488. Save some CPU by testing the value of srv_thread_concurrency in inline
  489. functions. */
  490. inline
  491. void
  492. innodb_srv_conc_exit_innodb(
  493. /*========================*/
  494. trx_t* trx) /* in: transaction handle */
  495. {
  496. if (UNIV_LIKELY(!srv_thread_concurrency)) {
  497. return;
  498. }
  499. srv_conc_exit_innodb(trx);
  500. }
  501. /**********************************************************************
  502. Releases possible search latch and InnoDB thread FIFO ticket. These should
  503. be released at each SQL statement end, and also when mysqld passes the
  504. control to the client. It does no harm to release these also in the middle
  505. of an SQL statement. */
  506. inline
  507. void
  508. innobase_release_stat_resources(
  509. /*============================*/
  510. trx_t* trx) /* in: transaction object */
  511. {
  512. if (trx->has_search_latch) {
  513. trx_search_latch_release_if_reserved(trx);
  514. }
  515. if (trx->declared_to_be_inside_innodb) {
  516. /* Release our possible ticket in the FIFO */
  517. srv_conc_force_exit_innodb(trx);
  518. }
  519. }
  520. /**********************************************************************
  521. Returns true if the transaction this thread is processing has edited
  522. non-transactional tables. Used by the deadlock detector when deciding
  523. which transaction to rollback in case of a deadlock - we try to avoid
  524. rolling back transactions that have edited non-transactional tables. */
  525. extern "C" UNIV_INTERN
  526. ibool
  527. thd_has_edited_nontrans_tables(
  528. /*===========================*/
  529. /* out: true if non-transactional tables have
  530. been edited */
  531. void* thd) /* in: thread handle (THD*) */
  532. {
  533. return((ibool) thd_non_transactional_update((THD*) thd));
  534. }
  535. /**********************************************************************
  536. Returns true if the thread is executing a SELECT statement. */
  537. extern "C" UNIV_INTERN
  538. ibool
  539. thd_is_select(
  540. /*==========*/
  541. /* out: true if thd is executing SELECT */
  542. const void* thd) /* in: thread handle (THD*) */
  543. {
  544. return(thd_sql_command((const THD*) thd) == SQLCOM_SELECT);
  545. }
  546. /**********************************************************************
  547. Returns true if the thread is executing in innodb_strict_mode. */
  548. extern "C" UNIV_INTERN
  549. ibool
  550. thd_is_strict(
  551. /*==========*/
  552. /* out: true if thd is in strict mode */
  553. void* thd) /* in: thread handle (THD*) */
  554. {
  555. return(THDVAR((THD*) thd, strict_mode));
  556. }
  557. /**********************************************************************
  558. Returns the lock wait timeout for the current connection. */
  559. extern "C" UNIV_INTERN
  560. ulong
  561. thd_lock_wait_timeout(
  562. /*==================*/
  563. /* out: the lock wait timeout, in seconds */
  564. void* thd) /* in: thread handle (THD*), or NULL to query
  565. the global innodb_lock_wait_timeout */
  566. {
  567. /* According to <mysql/plugin.h>, passing thd == NULL
  568. returns the global value of the session variable. */
  569. return(THDVAR((THD*) thd, lock_wait_timeout));
  570. }
  571. /************************************************************************
  572. Obtain the InnoDB transaction of a MySQL thread. */
  573. inline
  574. trx_t*&
  575. thd_to_trx(
  576. /*=======*/
  577. /* out: reference to transaction pointer */
  578. THD* thd) /* in: MySQL thread */
  579. {
  580. return(*(trx_t**) thd_ha_data(thd, innodb_hton_ptr));
  581. }
  582. /************************************************************************
  583. Call this function when mysqld passes control to the client. That is to
  584. avoid deadlocks on the adaptive hash S-latch possibly held by thd. For more
  585. documentation, see handler.cc. */
  586. static
  587. int
  588. innobase_release_temporary_latches(
  589. /*===============================*/
  590. /* out: 0 */
  591. handlerton* hton, /* in: handlerton */
  592. THD* thd) /* in: MySQL thread */
  593. {
  594. trx_t* trx;
  595. DBUG_ASSERT(hton == innodb_hton_ptr);
  596. if (!innodb_inited) {
  597. return(0);
  598. }
  599. trx = thd_to_trx(thd);
  600. if (trx) {
  601. innobase_release_stat_resources(trx);
  602. }
  603. return(0);
  604. }
  605. /************************************************************************
  606. Increments innobase_active_counter and every INNOBASE_WAKE_INTERVALth
  607. time calls srv_active_wake_master_thread. This function should be used
  608. when a single database operation may introduce a small need for
  609. server utility activity, like checkpointing. */
  610. inline
  611. void
  612. innobase_active_small(void)
  613. /*=======================*/
  614. {
  615. innobase_active_counter++;
  616. if ((innobase_active_counter % INNOBASE_WAKE_INTERVAL) == 0) {
  617. srv_active_wake_master_thread();
  618. }
  619. }
  620. /************************************************************************
  621. Converts an InnoDB error code to a MySQL error code and also tells to MySQL
  622. about a possible transaction rollback inside InnoDB caused by a lock wait
  623. timeout or a deadlock. */
  624. extern "C" UNIV_INTERN
  625. int
  626. convert_error_code_to_mysql(
  627. /*========================*/
  628. /* out: MySQL error code */
  629. int error, /* in: InnoDB error code */
  630. ulint flags, /* in: InnoDB table flags, or 0 */
  631. THD* thd) /* in: user thread handle or NULL */
  632. {
  633. switch (error) {
  634. case DB_SUCCESS:
  635. return(0);
  636. case DB_ERROR:
  637. default:
  638. return(-1); /* unspecified error */
  639. case DB_DUPLICATE_KEY:
  640. return(HA_ERR_FOUND_DUPP_KEY);
  641. case DB_FOREIGN_DUPLICATE_KEY:
  642. return(HA_ERR_FOREIGN_DUPLICATE_KEY);
  643. case DB_RECORD_NOT_FOUND:
  644. return(HA_ERR_NO_ACTIVE_RECORD);
  645. case DB_DEADLOCK:
  646. /* Since we rolled back the whole transaction, we must
  647. tell it also to MySQL so that MySQL knows to empty the
  648. cached binlog for this transaction */
  649. if (thd) {
  650. thd_mark_transaction_to_rollback(thd, TRUE);
  651. }
  652. return(HA_ERR_LOCK_DEADLOCK);
  653. case DB_LOCK_WAIT_TIMEOUT:
  654. /* Starting from 5.0.13, we let MySQL just roll back the
  655. latest SQL statement in a lock wait timeout. Previously, we
  656. rolled back the whole transaction. */
  657. if (thd) {
  658. thd_mark_transaction_to_rollback(
  659. thd, (bool)row_rollback_on_timeout);
  660. }
  661. return(HA_ERR_LOCK_WAIT_TIMEOUT);
  662. case DB_NO_REFERENCED_ROW:
  663. return(HA_ERR_NO_REFERENCED_ROW);
  664. case DB_ROW_IS_REFERENCED:
  665. return(HA_ERR_ROW_IS_REFERENCED);
  666. case DB_CANNOT_ADD_CONSTRAINT:
  667. return(HA_ERR_CANNOT_ADD_FOREIGN);
  668. case DB_CANNOT_DROP_CONSTRAINT:
  669. return(HA_ERR_ROW_IS_REFERENCED); /* TODO: This is a bit
  670. misleading, a new MySQL error
  671. code should be introduced */
  672. case DB_COL_APPEARS_TWICE_IN_INDEX:
  673. case DB_CORRUPTION:
  674. return(HA_ERR_CRASHED);
  675. case DB_OUT_OF_FILE_SPACE:
  676. return(HA_ERR_RECORD_FILE_FULL);
  677. case DB_TABLE_IS_BEING_USED:
  678. return(HA_ERR_WRONG_COMMAND);
  679. case DB_TABLE_NOT_FOUND:
  680. return(HA_ERR_NO_SUCH_TABLE);
  681. case DB_TOO_BIG_RECORD:
  682. my_error(ER_TOO_BIG_ROWSIZE, MYF(0),
  683. page_get_free_space_of_empty(flags
  684. & DICT_TF_COMPACT) / 2);
  685. return(HA_ERR_TO_BIG_ROW);
  686. case DB_NO_SAVEPOINT:
  687. return(HA_ERR_NO_SAVEPOINT);
  688. case DB_LOCK_TABLE_FULL:
  689. /* Since we rolled back the whole transaction, we must
  690. tell it also to MySQL so that MySQL knows to empty the
  691. cached binlog for this transaction */
  692. if (thd) {
  693. thd_mark_transaction_to_rollback(thd, TRUE);
  694. }
  695. return(HA_ERR_LOCK_TABLE_FULL);
  696. case DB_PRIMARY_KEY_IS_NULL:
  697. return(ER_PRIMARY_CANT_HAVE_NULL);
  698. case DB_TOO_MANY_CONCURRENT_TRXS:
  699. /* Once MySQL add the appropriate code to errmsg.txt then
  700. we can get rid of this #ifdef. NOTE: The code checked by
  701. the #ifdef is the suggested name for the error condition
  702. and the actual error code name could very well be different.
  703. This will require some monitoring, ie. the status
  704. of this request on our part.*/
  705. #ifdef ER_TOO_MANY_CONCURRENT_TRXS
  706. return(ER_TOO_MANY_CONCURRENT_TRXS);
  707. #else
  708. return(HA_ERR_RECORD_FILE_FULL);
  709. #endif
  710. case DB_UNSUPPORTED:
  711. return(HA_ERR_UNSUPPORTED);
  712. }
  713. }
  714. /*****************************************************************
  715. If you want to print a thd that is not associated with the current thread,
  716. you must call this function before reserving the InnoDB kernel_mutex, to
  717. protect MySQL from setting thd->query NULL. If you print a thd of the current
  718. thread, we know that MySQL cannot modify thd->query, and it is not necessary
  719. to call this. Call innobase_mysql_end_print_arbitrary_thd() after you release
  720. the kernel_mutex. */
  721. extern "C" UNIV_INTERN
  722. void
  723. innobase_mysql_prepare_print_arbitrary_thd(void)
  724. /*============================================*/
  725. {
  726. ut_ad(!mutex_own(&kernel_mutex));
  727. VOID(pthread_mutex_lock(&LOCK_thread_count));
  728. }
  729. /*****************************************************************
  730. Releases the mutex reserved by innobase_mysql_prepare_print_arbitrary_thd().
  731. In the InnoDB latching order, the mutex sits right above the
  732. kernel_mutex. In debug builds, we assert that the kernel_mutex is
  733. released before this function is invoked. */
  734. extern "C" UNIV_INTERN
  735. void
  736. innobase_mysql_end_print_arbitrary_thd(void)
  737. /*========================================*/
  738. {
  739. ut_ad(!mutex_own(&kernel_mutex));
  740. VOID(pthread_mutex_unlock(&LOCK_thread_count));
  741. }
  742. /*****************************************************************
  743. Prints info of a THD object (== user session thread) to the given file. */
  744. extern "C" UNIV_INTERN
  745. void
  746. innobase_mysql_print_thd(
  747. /*=====================*/
  748. FILE* f, /* in: output stream */
  749. void* thd, /* in: pointer to a MySQL THD object */
  750. uint max_query_len) /* in: max query length to print, or 0 to
  751. use the default max length */
  752. {
  753. char buffer[1024];
  754. fputs(thd_security_context((THD*) thd, buffer, sizeof buffer,
  755. max_query_len), f);
  756. putc('\n', f);
  757. }
  758. /**********************************************************************
  759. Get the variable length bounds of the given character set. */
  760. extern "C" UNIV_INTERN
  761. void
  762. innobase_get_cset_width(
  763. /*====================*/
  764. ulint cset, /* in: MySQL charset-collation code */
  765. ulint* mbminlen, /* out: minimum length of a char (in bytes) */
  766. ulint* mbmaxlen) /* out: maximum length of a char (in bytes) */
  767. {
  768. CHARSET_INFO* cs;
  769. ut_ad(cset < 256);
  770. ut_ad(mbminlen);
  771. ut_ad(mbmaxlen);
  772. cs = all_charsets[cset];
  773. if (cs) {
  774. *mbminlen = cs->mbminlen;
  775. *mbmaxlen = cs->mbmaxlen;
  776. } else {
  777. ut_a(cset == 0);
  778. *mbminlen = *mbmaxlen = 0;
  779. }
  780. }
  781. /**********************************************************************
  782. Converts an identifier to a table name. */
  783. extern "C" UNIV_INTERN
  784. void
  785. innobase_convert_from_table_id(
  786. /*===========================*/
  787. struct charset_info_st* cs, /* in: the 'from' character set */
  788. char* to, /* out: converted identifier */
  789. const char* from, /* in: identifier to convert */
  790. ulint len) /* in: length of 'to', in bytes */
  791. {
  792. uint errors;
  793. strconvert(cs, from, &my_charset_filename, to, (uint) len, &errors);
  794. }
  795. /**********************************************************************
  796. Converts an identifier to UTF-8. */
  797. extern "C" UNIV_INTERN
  798. void
  799. innobase_convert_from_id(
  800. /*=====================*/
  801. struct charset_info_st* cs, /* in: the 'from' character set */
  802. char* to, /* out: converted identifier */
  803. const char* from, /* in: identifier to convert */
  804. ulint len) /* in: length of 'to', in bytes */
  805. {
  806. uint errors;
  807. strconvert(cs, from, system_charset_info, to, (uint) len, &errors);
  808. }
  809. /**********************************************************************
  810. Compares NUL-terminated UTF-8 strings case insensitively. */
  811. extern "C" UNIV_INTERN
  812. int
  813. innobase_strcasecmp(
  814. /*================*/
  815. /* out: 0 if a=b, <0 if a<b, >1 if a>b */
  816. const char* a, /* in: first string to compare */
  817. const char* b) /* in: second string to compare */
  818. {
  819. return(my_strcasecmp(system_charset_info, a, b));
  820. }
  821. /**********************************************************************
  822. Makes all characters in a NUL-terminated UTF-8 string lower case. */
  823. extern "C" UNIV_INTERN
  824. void
  825. innobase_casedn_str(
  826. /*================*/
  827. char* a) /* in/out: string to put in lower case */
  828. {
  829. my_casedn_str(system_charset_info, a);
  830. }
  831. /**************************************************************************
  832. Determines the connection character set. */
  833. extern "C" UNIV_INTERN
  834. struct charset_info_st*
  835. innobase_get_charset(
  836. /*=================*/
  837. /* out: connection character set */
  838. void* mysql_thd) /* in: MySQL thread handle */
  839. {
  840. return(thd_charset((THD*) mysql_thd));
  841. }
  842. /*************************************************************************
  843. Creates a temporary file. */
  844. extern "C" UNIV_INTERN
  845. int
  846. innobase_mysql_tmpfile(void)
  847. /*========================*/
  848. /* out: temporary file descriptor, or < 0 on error */
  849. {
  850. int fd2 = -1;
  851. File fd = mysql_tmpfile("ib");
  852. if (fd >= 0) {
  853. /* Copy the file descriptor, so that the additional resources
  854. allocated by create_temp_file() can be freed by invoking
  855. my_close().
  856. Because the file descriptor returned by this function
  857. will be passed to fdopen(), it will be closed by invoking
  858. fclose(), which in turn will invoke close() instead of
  859. my_close(). */
  860. fd2 = dup(fd);
  861. if (fd2 < 0) {
  862. DBUG_PRINT("error",("Got error %d on dup",fd2));
  863. my_errno=errno;
  864. my_error(EE_OUT_OF_FILERESOURCES,
  865. MYF(ME_BELL+ME_WAITTANG),
  866. "ib*", my_errno);
  867. }
  868. my_close(fd, MYF(MY_WME));
  869. }
  870. return(fd2);
  871. }
  872. /*************************************************************************
  873. Wrapper around MySQL's copy_and_convert function, see it for
  874. documentation. */
  875. extern "C" UNIV_INTERN
  876. ulint
  877. innobase_convert_string(
  878. /*====================*/
  879. void* to,
  880. ulint to_length,
  881. CHARSET_INFO* to_cs,
  882. const void* from,
  883. ulint from_length,
  884. CHARSET_INFO* from_cs,
  885. uint* errors)
  886. {
  887. return(copy_and_convert((char*)to, (uint32) to_length, to_cs,
  888. (const char*)from, (uint32) from_length, from_cs,
  889. errors));
  890. }
  891. /***********************************************************************
  892. Formats the raw data in "data" (in InnoDB on-disk format) that is of
  893. type DATA_(CHAR|VARCHAR|MYSQL|VARMYSQL) using "charset_coll" and writes
  894. the result to "buf". The result is converted to "system_charset_info".
  895. Not more than "buf_size" bytes are written to "buf".
  896. The result is always '\0'-terminated (provided buf_size > 0) and the
  897. number of bytes that were written to "buf" is returned (including the
  898. terminating '\0'). */
  899. extern "C" UNIV_INTERN
  900. ulint
  901. innobase_raw_format(
  902. /*================*/
  903. /* out: number of bytes
  904. that were written */
  905. const char* data, /* in: raw data */
  906. ulint data_len, /* in: raw data length
  907. in bytes */
  908. ulint charset_coll, /* in: charset collation */
  909. char* buf, /* out: output buffer */
  910. ulint buf_size) /* in: output buffer size
  911. in bytes */
  912. {
  913. /* XXX we use a hard limit instead of allocating
  914. but_size bytes from the heap */
  915. CHARSET_INFO* data_cs;
  916. char buf_tmp[8192];
  917. ulint buf_tmp_used;
  918. uint num_errors;
  919. data_cs = all_charsets[charset_coll];
  920. buf_tmp_used = innobase_convert_string(buf_tmp, sizeof(buf_tmp),
  921. system_charset_info,
  922. data, data_len, data_cs,
  923. &num_errors);
  924. return(ut_str_sql_format(buf_tmp, buf_tmp_used, buf, buf_size));
  925. }
  926. /*************************************************************************
  927. Compute the next autoinc value.
  928. For MySQL replication the autoincrement values can be partitioned among
  929. the nodes. The offset is the start or origin of the autoincrement value
  930. for a particular node. For n nodes the increment will be n and the offset
  931. will be in the interval [1, n]. The formula tries to allocate the next
  932. value for a particular node.
  933. Note: This function is also called with increment set to the number of
  934. values we want to reserve for multi-value inserts e.g.,
  935. INSERT INTO T VALUES(), (), ();
  936. innobase_next_autoinc() will be called with increment set to
  937. n * 3 where autoinc_lock_mode != TRADITIONAL because we want
  938. to reserve 3 values for the multi-value INSERT above. */
  939. static
  940. ulonglong
  941. innobase_next_autoinc(
  942. /*==================*/
  943. /* out: the next value */
  944. ulonglong current, /* in: Current value */
  945. ulonglong increment, /* in: increment current by */
  946. ulonglong offset, /* in: AUTOINC offset */
  947. ulonglong max_value) /* in: max value for type */
  948. {
  949. ulonglong next_value;
  950. /* Should never be 0. */
  951. ut_a(increment > 0);
  952. if (max_value <= current) {
  953. next_value = max_value;
  954. } else if (offset <= 1) {
  955. /* Offset 0 and 1 are the same, because there must be at
  956. least one node in the system. */
  957. if (max_value - current <= increment) {
  958. next_value = max_value;
  959. } else {
  960. next_value = current + increment;
  961. }
  962. } else if (max_value > current) {
  963. if (current > offset) {
  964. next_value = ((current - offset) / increment) + 1;
  965. } else {
  966. next_value = ((offset - current) / increment) + 1;
  967. }
  968. ut_a(increment > 0);
  969. ut_a(next_value > 0);
  970. /* Check for multiplication overflow. */
  971. if (increment > (max_value / next_value)) {
  972. next_value = max_value;
  973. } else {
  974. next_value *= increment;
  975. ut_a(max_value >= next_value);
  976. /* Check for overflow. */
  977. if (max_value - next_value <= offset) {
  978. next_value = max_value;
  979. } else {
  980. next_value += offset;
  981. }
  982. }
  983. } else {
  984. next_value = max_value;
  985. }
  986. ut_a(next_value <= max_value);
  987. return(next_value);
  988. }
  989. /*************************************************************************
  990. Gets the InnoDB transaction handle for a MySQL handler object, creates
  991. an InnoDB transaction struct if the corresponding MySQL thread struct still
  992. lacks one. */
  993. static
  994. trx_t*
  995. check_trx_exists(
  996. /*=============*/
  997. /* out: InnoDB transaction handle */
  998. THD* thd) /* in: user thread handle */
  999. {
  1000. trx_t*& trx = thd_to_trx(thd);
  1001. ut_ad(EQ_CURRENT_THD(thd));
  1002. if (trx == NULL) {
  1003. DBUG_ASSERT(thd != NULL);
  1004. trx = trx_allocate_for_mysql();
  1005. trx->mysql_thd = thd;
  1006. trx->mysql_query_str = thd_query(thd);
  1007. /* Update the info whether we should skip XA steps that eat
  1008. CPU time */
  1009. trx->support_xa = THDVAR(thd, support_xa);
  1010. } else {
  1011. if (trx->magic_n != TRX_MAGIC_N) {
  1012. mem_analyze_corruption(trx);
  1013. ut_error;
  1014. }
  1015. }
  1016. if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
  1017. trx->check_foreigns = FALSE;
  1018. } else {
  1019. trx->check_foreigns = TRUE;
  1020. }
  1021. if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
  1022. trx->check_unique_secondary = FALSE;
  1023. } else {
  1024. trx->check_unique_secondary = TRUE;
  1025. }
  1026. return(trx);
  1027. }
  1028. /*************************************************************************
  1029. Construct ha_innobase handler. */
  1030. UNIV_INTERN
  1031. ha_innobase::ha_innobase(handlerton *hton, TABLE_SHARE *table_arg)
  1032. :handler(hton, table_arg),
  1033. int_table_flags(HA_REC_NOT_IN_SEQ |
  1034. HA_NULL_IN_KEY |
  1035. HA_CAN_INDEX_BLOBS |
  1036. HA_CAN_SQL_HANDLER |
  1037. HA_PRIMARY_KEY_REQUIRED_FOR_POSITION |
  1038. HA_PRIMARY_KEY_IN_READ_INDEX |
  1039. HA_BINLOG_ROW_CAPABLE |
  1040. HA_CAN_GEOMETRY | HA_PARTIAL_COLUMN_READ |
  1041. HA_TABLE_SCAN_ON_INDEX),
  1042. start_of_scan(0),
  1043. num_write_row(0)
  1044. {}
  1045. /*************************************************************************
  1046. Destruct ha_innobase handler. */
  1047. UNIV_INTERN
  1048. ha_innobase::~ha_innobase()
  1049. {
  1050. }
  1051. /*************************************************************************
  1052. Updates the user_thd field in a handle and also allocates a new InnoDB
  1053. transaction handle if needed, and updates the transaction fields in the
  1054. prebuilt struct. */
  1055. inline
  1056. void
  1057. ha_innobase::update_thd(
  1058. /*====================*/
  1059. THD* thd) /* in: thd to use the handle */
  1060. {
  1061. trx_t* trx;
  1062. trx = check_trx_exists(thd);
  1063. if (prebuilt->trx != trx) {
  1064. row_update_prebuilt_trx(prebuilt, trx);
  1065. }
  1066. user_thd = thd;
  1067. }
  1068. /*************************************************************************
  1069. Updates the user_thd field in a handle and also allocates a new InnoDB
  1070. transaction handle if needed, and updates the transaction fields in the
  1071. prebuilt struct. */
  1072. UNIV_INTERN
  1073. void
  1074. ha_innobase::update_thd()
  1075. /*=====================*/
  1076. {
  1077. THD* thd = ha_thd();
  1078. ut_ad(EQ_CURRENT_THD(thd));
  1079. update_thd(thd);
  1080. }
  1081. /*************************************************************************
  1082. Registers that InnoDB takes part in an SQL statement, so that MySQL knows to
  1083. roll back the statement if the statement results in an error. This MUST be
  1084. called for every SQL statement that may be rolled back by MySQL. Calling this
  1085. several times to register the same statement is allowed, too. */
  1086. inline
  1087. void
  1088. innobase_register_stmt(
  1089. /*===================*/
  1090. handlerton* hton, /* in: Innobase hton */
  1091. THD* thd) /* in: MySQL thd (connection) object */
  1092. {
  1093. DBUG_ASSERT(hton == innodb_hton_ptr);
  1094. /* Register the statement */
  1095. trans_register_ha(thd, FALSE, hton);
  1096. }
  1097. /*************************************************************************
  1098. Registers an InnoDB transaction in MySQL, so that the MySQL XA code knows
  1099. to call the InnoDB prepare and commit, or rollback for the transaction. This
  1100. MUST be called for every transaction for which the user may call commit or
  1101. rollback. Calling this several times to register the same transaction is
  1102. allowed, too.
  1103. This function also registers the current SQL statement. */
  1104. inline
  1105. void
  1106. innobase_register_trx_and_stmt(
  1107. /*===========================*/
  1108. handlerton *hton, /* in: Innobase handlerton */
  1109. THD* thd) /* in: MySQL thd (connection) object */
  1110. {
  1111. /* NOTE that actually innobase_register_stmt() registers also
  1112. the transaction in the AUTOCOMMIT=1 mode. */
  1113. innobase_register_stmt(hton, thd);
  1114. if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  1115. /* No autocommit mode, register for a transaction */
  1116. trans_register_ha(thd, TRUE, hton);
  1117. }
  1118. }
  1119. /* BACKGROUND INFO: HOW THE MYSQL QUERY CACHE WORKS WITH INNODB
  1120. ------------------------------------------------------------
  1121. 1) The use of the query cache for TBL is disabled when there is an
  1122. uncommitted change to TBL.
  1123. 2) When a change to TBL commits, InnoDB stores the current value of
  1124. its global trx id counter, let us denote it by INV_TRX_ID, to the table object
  1125. in the InnoDB data dictionary, and does only allow such transactions whose
  1126. id <= INV_TRX_ID to use the query cache.
  1127. 3) When InnoDB does an INSERT/DELETE/UPDATE to a table TBL, or an implicit
  1128. modification because an ON DELETE CASCADE, we invalidate the MySQL query cache
  1129. of TBL immediately.
  1130. How this is implemented inside InnoDB:
  1131. 1) Since every modification always sets an IX type table lock on the InnoDB
  1132. table, it is easy to check if there can be uncommitted modifications for a
  1133. table: just check if there are locks in the lock list of the table.
  1134. 2) When a transaction inside InnoDB commits, it reads the global trx id
  1135. counter and stores the value INV_TRX_ID to the tables on which it had a lock.
  1136. 3) If there is an implicit table change from ON DELETE CASCADE or SET NULL,
  1137. InnoDB calls an invalidate method for the MySQL query cache for that table.
  1138. How this is implemented inside sql_cache.cc:
  1139. 1) The query cache for an InnoDB table TBL is invalidated immediately at an
  1140. INSERT/UPDATE/DELETE, just like in the case of MyISAM. No need to delay
  1141. invalidation to the transaction commit.
  1142. 2) To store or retrieve a value from the query cache of an InnoDB table TBL,
  1143. any query must first ask InnoDB's permission. We must pass the thd as a
  1144. parameter because InnoDB will look at the trx id, if any, associated with
  1145. that thd.
  1146. 3) Use of the query cache for InnoDB tables is now allowed also when
  1147. AUTOCOMMIT==0 or we are inside BEGIN ... COMMIT. Thus transactions no longer
  1148. put restrictions on the use of the query cache.
  1149. */
  1150. /**********************************************************************
  1151. The MySQL query cache uses this to check from InnoDB if the query cache at
  1152. the moment is allowed to operate on an InnoDB table. The SQL query must
  1153. be a non-locking SELECT.
  1154. The query cache is allowed to operate on certain query only if this function
  1155. returns TRUE for all tables in the query.
  1156. If thd is not in the autocommit state, this function also starts a new
  1157. transaction for thd if there is no active trx yet, and assigns a consistent
  1158. read view to it if there is no read view yet.
  1159. Why a deadlock of threads is not possible: the query cache calls this function
  1160. at the start of a SELECT processing. Then the calling thread cannot be
  1161. holding any InnoDB semaphores. The calling thread is holding the
  1162. query cache mutex, and this function will reserver the InnoDB kernel mutex.
  1163. Thus, the 'rank' in sync0sync.h of the MySQL query cache mutex is above
  1164. the InnoDB kernel mutex. */
  1165. static
  1166. my_bool
  1167. innobase_query_caching_of_table_permitted(
  1168. /*======================================*/
  1169. /* out: TRUE if permitted, FALSE if not;
  1170. note that the value FALSE does not mean
  1171. we should invalidate the query cache:
  1172. invalidation is called explicitly */
  1173. THD* thd, /* in: thd of the user who is trying to
  1174. store a result to the query cache or
  1175. retrieve it */
  1176. char* full_name, /* in: concatenation of database name,
  1177. the null character '\0', and the table
  1178. name */
  1179. uint full_name_len, /* in: length of the full name, i.e.
  1180. len(dbname) + len(tablename) + 1 */
  1181. ulonglong *unused) /* unused for this engine */
  1182. {
  1183. ibool is_autocommit;
  1184. trx_t* trx;
  1185. char norm_name[1000];
  1186. ut_a(full_name_len < 999);
  1187. trx = check_trx_exists(thd);
  1188. if (trx->isolation_level == TRX_ISO_SERIALIZABLE) {
  1189. /* In the SERIALIZABLE mode we add LOCK IN SHARE MODE to every
  1190. plain SELECT if AUTOCOMMIT is not on. */
  1191. return((my_bool)FALSE);
  1192. }
  1193. if (trx->has_search_latch) {
  1194. sql_print_error("The calling thread is holding the adaptive "
  1195. "search, latch though calling "
  1196. "innobase_query_caching_of_table_permitted.");
  1197. mutex_enter(&kernel_mutex);
  1198. trx_print(stderr, trx, 1024);
  1199. mutex_exit(&kernel_mutex);
  1200. }
  1201. innobase_release_stat_resources(trx);
  1202. if (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  1203. is_autocommit = TRUE;
  1204. } else {
  1205. is_autocommit = FALSE;
  1206. }
  1207. if (is_autocommit && trx->n_mysql_tables_in_use == 0) {
  1208. /* We are going to retrieve the query result from the query
  1209. cache. This cannot be a store operation to the query cache
  1210. because then MySQL would have locks on tables already.
  1211. TODO: if the user has used LOCK TABLES to lock the table,
  1212. then we open a transaction in the call of row_.. below.
  1213. That trx can stay open until UNLOCK TABLES. The same problem
  1214. exists even if we do not use the query cache. MySQL should be
  1215. modified so that it ALWAYS calls some cleanup function when
  1216. the processing of a query ends!
  1217. We can imagine we instantaneously serialize this consistent
  1218. read trx to the current trx id counter. If trx2 would have
  1219. changed the tables of a query result stored in the cache, and
  1220. trx2 would have already committed, making the result obsolete,
  1221. then trx2 would have already invalidated the cache. Thus we
  1222. can trust the result in the cache is ok for this query. */
  1223. return((my_bool)TRUE);
  1224. }
  1225. /* Normalize the table name to InnoDB format */
  1226. memcpy(norm_name, full_name, full_name_len);
  1227. norm_name[strlen(norm_name)] = '/'; /* InnoDB uses '/' as the
  1228. separator between db and table */
  1229. norm_name[full_name_len] = '\0';
  1230. #ifdef __WIN__
  1231. innobase_casedn_str(norm_name);
  1232. #endif
  1233. /* The call of row_search_.. will start a new transaction if it is
  1234. not yet started */
  1235. if (trx->active_trans == 0) {
  1236. innobase_register_trx_and_stmt(innodb_hton_ptr, thd);
  1237. trx->active_trans = 1;
  1238. }
  1239. if (row_search_check_if_query_cache_permitted(trx, norm_name)) {
  1240. /* printf("Query cache for %s permitted\n", norm_name); */
  1241. return((my_bool)TRUE);
  1242. }
  1243. /* printf("Query cache for %s NOT permitted\n", norm_name); */
  1244. return((my_bool)FALSE);
  1245. }
  1246. /*********************************************************************
  1247. Invalidates the MySQL query cache for the table.
  1248. NOTE that the exact prototype of this function has to be in
  1249. /innobase/row/row0ins.c! */
  1250. extern "C" UNIV_INTERN
  1251. void
  1252. innobase_invalidate_query_cache(
  1253. /*============================*/
  1254. trx_t* trx, /* in: transaction which modifies the table */
  1255. char* full_name, /* in: concatenation of database name, null
  1256. char '\0', table name, null char'\0';
  1257. NOTE that in Windows this is always
  1258. in LOWER CASE! */
  1259. ulint full_name_len) /* in: full name length where also the null
  1260. chars count */
  1261. {
  1262. /* Note that the sync0sync.h rank of the query cache mutex is just
  1263. above the InnoDB kernel mutex. The caller of this function must not
  1264. have latches of a lower rank. */
  1265. /* Argument TRUE below means we are using transactions */
  1266. #ifdef HAVE_QUERY_CACHE
  1267. mysql_query_cache_invalidate4((THD*) trx->mysql_thd,
  1268. (const char*) full_name,
  1269. (uint32) full_name_len,
  1270. TRUE);
  1271. #endif
  1272. }
  1273. /*********************************************************************
  1274. Convert an SQL identifier to the MySQL system_charset_info (UTF-8)
  1275. and quote it if needed. */
  1276. static
  1277. char*
  1278. innobase_convert_identifier(
  1279. /*========================*/
  1280. /* out: pointer to the end of buf */
  1281. char* buf, /* out: buffer for converted identifier */
  1282. ulint buflen, /* in: length of buf, in bytes */
  1283. const char* id, /* in: identifier to convert */
  1284. ulint idlen, /* in: length of id, in bytes */
  1285. void* thd, /* in: MySQL connection thread, or NULL */
  1286. ibool file_id)/* in: TRUE=id is a table or database name;
  1287. FALSE=id is an UTF-8 string */
  1288. {
  1289. char nz[NAME_LEN + 1];
  1290. char nz2[NAME_LEN + 1 + sizeof srv_mysql50_table_name_prefix];
  1291. const char* s = id;
  1292. int q;
  1293. if (file_id) {
  1294. /* Decode the table name. The filename_to_tablename()
  1295. function expects a NUL-terminated string. The input and
  1296. output strings buffers must not be shared. */
  1297. if (UNIV_UNLIKELY(idlen > (sizeof nz) - 1)) {
  1298. idlen = (sizeof nz) - 1;
  1299. }
  1300. memcpy(nz, id, idlen);
  1301. nz[idlen] = 0;
  1302. s = nz2;
  1303. idlen = filename_to_tablename(nz, nz2, sizeof nz2);
  1304. }
  1305. /* See if the identifier needs to be quoted. */
  1306. if (UNIV_UNLIKELY(!thd)) {
  1307. q = '"';
  1308. } else {
  1309. q = get_quote_char_for_identifier((THD*) thd, s, (int) idlen);
  1310. }
  1311. if (q == EOF) {
  1312. if (UNIV_UNLIKELY(idlen > buflen)) {
  1313. idlen = buflen;
  1314. }
  1315. memcpy(buf, s, idlen);
  1316. return(buf + idlen);
  1317. }
  1318. /* Quote the identifier. */
  1319. if (buflen < 2) {
  1320. return(buf);
  1321. }
  1322. *buf++ = q;
  1323. buflen--;
  1324. for (; idlen; idlen--) {
  1325. int c = *s++;
  1326. if (UNIV_UNLIKELY(c == q)) {
  1327. if (UNIV_UNLIKELY(buflen < 3)) {
  1328. break;
  1329. }
  1330. *buf++ = c;
  1331. *buf++ = c;
  1332. buflen -= 2;
  1333. } else {
  1334. if (UNIV_UNLIKELY(buflen < 2)) {
  1335. break;
  1336. }
  1337. *buf++ = c;
  1338. buflen--;
  1339. }
  1340. }
  1341. *buf++ = q;
  1342. return(buf);
  1343. }
  1344. /*********************************************************************
  1345. Convert a table or index name to the MySQL system_charset_info (UTF-8)
  1346. and quote it if needed. */
  1347. extern "C" UNIV_INTERN
  1348. char*
  1349. innobase_convert_name(
  1350. /*==================*/
  1351. /* out: pointer to the end of buf */
  1352. char* buf, /* out: buffer for converted identifier */
  1353. ulint buflen, /* in: length of buf, in bytes */
  1354. const char* id, /* in: identifier to convert */
  1355. ulint idlen, /* in: length of id, in bytes */
  1356. void* thd, /* in: MySQL connection thread, or NULL */
  1357. ibool table_id)/* in: TRUE=id is a table or database name;
  1358. FALSE=id is an index name */
  1359. {
  1360. char* s = buf;
  1361. const char* bufend = buf + buflen;
  1362. if (table_id) {
  1363. const char* slash = (const char*) memchr(id, '/', idlen);
  1364. if (!slash) {
  1365. goto no_db_name;
  1366. }
  1367. /* Print the database name and table name separately. */
  1368. s = innobase_convert_identifier(s, bufend - s, id, slash - id,
  1369. thd, TRUE);
  1370. if (UNIV_LIKELY(s < bufend)) {
  1371. *s++ = '.';
  1372. s = innobase_convert_identifier(s, bufend - s,
  1373. slash + 1, idlen
  1374. - (slash - id) - 1,
  1375. thd, TRUE);
  1376. }
  1377. } else if (UNIV_UNLIKELY(*id == TEMP_INDEX_PREFIX)) {
  1378. /* Temporary index name (smart ALTER TABLE) */
  1379. const char temp_index_suffix[]= "--temporary--";
  1380. s = innobase_convert_identifier(buf, buflen, id + 1, idlen - 1,
  1381. thd, FALSE);
  1382. if (s - buf + (sizeof temp_index_suffix - 1) < buflen) {
  1383. memcpy(s, temp_index_suffix,
  1384. sizeof temp_index_suffix - 1);
  1385. s += sizeof temp_index_suffix - 1;
  1386. }
  1387. } else {
  1388. no_db_name:
  1389. s = innobase_convert_identifier(buf, buflen, id, idlen,
  1390. thd, table_id);
  1391. }
  1392. return(s);
  1393. }
  1394. /**************************************************************************
  1395. Determines if the currently running transaction has been interrupted. */
  1396. extern "C" UNIV_INTERN
  1397. ibool
  1398. trx_is_interrupted(
  1399. /*===============*/
  1400. /* out: TRUE if interrupted */
  1401. trx_t* trx) /* in: transaction */
  1402. {
  1403. return(trx && trx->mysql_thd && thd_killed((THD*) trx->mysql_thd));
  1404. }
  1405. /******************************************************************
  1406. Resets some fields of a prebuilt struct. The template is used in fast
  1407. retrieval of just those column values MySQL needs in its processing. */
  1408. static
  1409. void
  1410. reset_template(
  1411. /*===========*/
  1412. row_prebuilt_t* prebuilt) /* in/out: prebuilt struct */
  1413. {
  1414. prebuilt->keep_other_fields_on_keyread = 0;
  1415. prebuilt->read_just_key = 0;
  1416. }
  1417. /*********************************************************************
  1418. Call this when you have opened a new table handle in HANDLER, before you
  1419. call index_read_idx() etc. Actually, we can let the cursor stay open even
  1420. over a transaction commit! Then you should call this before every operation,
  1421. fetch next etc. This function inits the necessary things even after a
  1422. transaction commit. */
  1423. UNIV_INTERN
  1424. void
  1425. ha_innobase::init_table_handle_for_HANDLER(void)
  1426. /*============================================*/
  1427. {
  1428. /* If current thd does not yet have a trx struct, create one.
  1429. If the current handle does not yet have a prebuilt struct, create
  1430. one. Update the trx pointers in the prebuilt struct. Normally
  1431. this operation is done in external_lock. */
  1432. update_thd(ha_thd());
  1433. /* Initialize the prebuilt struct much like it would be inited in
  1434. external_lock */
  1435. innobase_release_stat_resources(prebuilt->trx);
  1436. /* If the transaction is not started yet, start it */
  1437. trx_start_if_not_started(prebuilt->trx);
  1438. /* Assign a read view if the transaction does not have it yet */
  1439. trx_assign_read_view(prebuilt->trx);
  1440. /* Set the MySQL flag to mark that there is an active transaction */
  1441. if (prebuilt->trx->active_trans == 0) {
  1442. innobase_register_trx_and_stmt(ht, user_thd);
  1443. prebuilt->trx->active_trans = 1;
  1444. }
  1445. /* We did the necessary inits in this function, no need to repeat them
  1446. in row_search_for_mysql */
  1447. prebuilt->sql_stat_start = FALSE;
  1448. /* We let HANDLER always to do the reads as consistent reads, even
  1449. if the trx isolation level would have been specified as SERIALIZABLE */
  1450. prebuilt->select_lock_type = LOCK_NONE;
  1451. prebuilt->stored_select_lock_type = LOCK_NONE;
  1452. /* Always fetch all columns in the index record */
  1453. prebuilt->hint_need_to_fetch_extra_cols = ROW_RETRIEVE_ALL_COLS;
  1454. /* We want always to fetch all columns in the whole row? Or do
  1455. we???? */
  1456. prebuilt->used_in_HANDLER = TRUE;
  1457. reset_template(prebuilt);
  1458. }
  1459. /*************************************************************************
  1460. Opens an InnoDB database. */
  1461. static
  1462. int
  1463. innobase_init(
  1464. /*==========*/
  1465. /* out: 0 on success, error code on failure */
  1466. void *p) /* in: InnoDB handlerton */
  1467. {
  1468. static char current_dir[3]; /* Set if using current lib */
  1469. int err;
  1470. bool ret;
  1471. char *default_path;
  1472. uint format_id;
  1473. DBUG_ENTER("innobase_init");
  1474. handlerton *innobase_hton= (handlerton *)p;
  1475. #ifdef MYSQL_DYNAMIC_PLUGIN
  1476. if (!innodb_plugin_init()) {
  1477. sql_print_error("InnoDB plugin init failed.");
  1478. DBUG_RETURN(-1);
  1479. }
  1480. if (innodb_hton_ptr) {
  1481. /* Patch the statically linked handlerton and variables */
  1482. innobase_hton = innodb_hton_ptr;
  1483. }
  1484. #endif /* MYSQL_DYNAMIC_PLUGIN */
  1485. innodb_hton_ptr = innobase_hton;
  1486. innobase_hton->state = SHOW_OPTION_YES;
  1487. innobase_hton->db_type= DB_TYPE_INNODB;
  1488. innobase_hton->savepoint_offset=sizeof(trx_named_savept_t);
  1489. innobase_hton->close_connection=innobase_close_connection;
  1490. innobase_hton->savepoint_set=innobase_savepoint;
  1491. innobase_hton->savepoint_rollback=innobase_rollback_to_savepoint;
  1492. innobase_hton->savepoint_release=innobase_release_savepoint;
  1493. innobase_hton->commit=innobase_commit;
  1494. innobase_hton->rollback=innobase_rollback;
  1495. innobase_hton->prepare=innobase_xa_prepare;
  1496. innobase_hton->recover=innobase_xa_recover;
  1497. innobase_hton->commit_by_xid=innobase_commit_by_xid;
  1498. innobase_hton->rollback_by_xid=innobase_rollback_by_xid;
  1499. innobase_hton->create_cursor_read_view=innobase_create_cursor_view;
  1500. innobase_hton->set_cursor_read_view=innobase_set_cursor_view;
  1501. innobase_hton->close_cursor_read_view=innobase_close_cursor_view;
  1502. innobase_hton->create=innobase_create_handler;
  1503. innobase_hton->drop_database=innobase_drop_database;
  1504. innobase_hton->panic=innobase_end;
  1505. innobase_hton->start_consistent_snapshot=innobase_start_trx_and_assign_read_view;
  1506. innobase_hton->flush_logs=innobase_flush_logs;
  1507. innobase_hton->show_status=innobase_show_status;
  1508. innobase_hton->flags=HTON_NO_FLAGS;
  1509. innobase_hton->release_temporary_latches=innobase_release_temporary_latches;
  1510. innobase_hton->alter_table_flags = innobase_alter_table_flags;
  1511. ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
  1512. #ifdef UNIV_DEBUG
  1513. static const char test_filename[] = "-@";
  1514. char test_tablename[sizeof test_filename
  1515. + sizeof srv_mysql50_table_name_prefix];
  1516. if ((sizeof test_tablename) - 1
  1517. != filename_to_tablename(test_filename, test_tablename,
  1518. sizeof test_tablename)
  1519. || strncmp(test_tablename,
  1520. srv_mysql50_table_name_prefix,
  1521. sizeof srv_mysql50_table_name_prefix)
  1522. || strcmp(test_tablename
  1523. + sizeof srv_mysql50_table_name_prefix,
  1524. test_filename)) {
  1525. sql_print_error("tablename encoding has been changed");
  1526. goto error;
  1527. }
  1528. #endif /* UNIV_DEBUG */
  1529. /* Check that values don't overflow on 32-bit systems. */
  1530. if (sizeof(ulint) == 4) {
  1531. if (innobase_buffer_pool_size > UINT_MAX32) {
  1532. sql_print_error(
  1533. "innobase_buffer_pool_size can't be over 4GB"
  1534. " on 32-bit systems");
  1535. goto error;
  1536. }
  1537. if (innobase_log_file_size > UINT_MAX32) {
  1538. sql_print_error(
  1539. "innobase_log_file_size can't be over 4GB"
  1540. " on 32-bit systems");
  1541. goto error;
  1542. }
  1543. }
  1544. os_innodb_umask = (ulint)my_umask;
  1545. /* First calculate the default path for innodb_data_home_dir etc.,
  1546. in case the user has not given any value.
  1547. Note that when using the embedded server, the datadirectory is not
  1548. necessarily the current directory of this program. */
  1549. if (mysqld_embedded) {
  1550. default_path = mysql_real_data_home;
  1551. fil_path_to_mysql_datadir = mysql_real_data_home;
  1552. } else {
  1553. /* It's better to use current lib, to keep paths short */
  1554. current_dir[0] = FN_CURLIB;
  1555. current_dir[1] = FN_LIBCHAR;
  1556. current_dir[2] = 0;
  1557. default_path = current_dir;
  1558. }
  1559. ut_a(default_path);
  1560. if (specialflag & SPECIAL_NO_PRIOR) {
  1561. srv_set_thread_priorities = FALSE;
  1562. } else {
  1563. srv_set_thread_priorities = TRUE;
  1564. srv_query_thread_priority = QUERY_PRIOR;
  1565. }
  1566. /* Set InnoDB initialization parameters according to the values
  1567. read from MySQL .cnf file */
  1568. /*--------------- Data files -------------------------*/
  1569. /* The default dir for data files is the datadir of MySQL */
  1570. srv_data_home = (innobase_data_home_dir ? innobase_data_home_dir :
  1571. default_path);
  1572. /* Set default InnoDB data file size to 10 MB and let it be
  1573. auto-extending. Thus users can use InnoDB in >= 4.0 without having
  1574. to specify any startup options. */
  1575. if (!innobase_data_file_path) {
  1576. innobase_data_file_path = (char*) "ibdata1:10M:autoextend";
  1577. }
  1578. /* Since InnoDB edits the argument in the next call, we make another
  1579. copy of it: */
  1580. internal_innobase_data_file_path = my_strdup(innobase_data_file_path,
  1581. MYF(MY_FAE));
  1582. ret = (bool) srv_parse_data_file_paths_and_sizes(
  1583. internal_innobase_data_file_path,
  1584. &srv_data_file_names,
  1585. &srv_data_file_sizes,
  1586. &srv_data_file_is_raw_partition,
  1587. &srv_n_data_files,
  1588. &srv_auto_extend_last_data_file,
  1589. &srv_last_file_size_max);
  1590. if (ret == FALSE) {
  1591. sql_print_error(
  1592. "InnoDB: syntax error in innodb_data_file_path");
  1593. my_free(internal_innobase_data_file_path,
  1594. MYF(MY_ALLOW_ZERO_PTR));
  1595. goto error;
  1596. }
  1597. /* -------------- Log files ---------------------------*/
  1598. /* The default dir for log files is the datadir of MySQL */
  1599. if (!innobase_log_group_home_dir) {
  1600. innobase_log_group_home_dir = default_path;
  1601. }
  1602. #ifdef UNIV_LOG_ARCHIVE
  1603. /* Since innodb_log_arch_dir has no relevance under MySQL,
  1604. starting from 4.0.6 we always set it the same as
  1605. innodb_log_group_home_dir: */
  1606. innobase_log_arch_dir = innobase_log_group_home_dir;
  1607. srv_arch_dir = innobase_log_arch_dir;
  1608. #endif /* UNIG_LOG_ARCHIVE */
  1609. ret = (bool)
  1610. srv_parse_log_group_home_dirs(innobase_log_group_home_dir,
  1611. &srv_log_group_home_dirs);
  1612. if (ret == FALSE || innobase_mirrored_log_groups != 1) {
  1613. sql_print_error("syntax error in innodb_log_group_home_dir, or a "
  1614. "wrong number of mirrored log groups");
  1615. my_free(internal_innobase_data_file_path,
  1616. MYF(MY_ALLOW_ZERO_PTR));
  1617. goto error;
  1618. }
  1619. /* Validate the file format by animal name */
  1620. if (innobase_file_format_name != NULL) {
  1621. format_id = innobase_file_format_name_lookup(
  1622. innobase_file_format_name);
  1623. if (format_id > DICT_TF_FORMAT_MAX) {
  1624. sql_print_error("InnoDB: wrong innodb_file_format.");
  1625. my_free(internal_innobase_data_file_path,
  1626. MYF(MY_ALLOW_ZERO_PTR));
  1627. goto error;
  1628. }
  1629. } else {
  1630. /* Set it to the default file format id. Though this
  1631. should never happen. */
  1632. format_id = 0;
  1633. }
  1634. srv_file_format = format_id;
  1635. /* Given the type of innobase_file_format_name we have little
  1636. choice but to cast away the constness from the returned name.
  1637. innobase_file_format_name is used in the MySQL set variable
  1638. interface and so can't be const. */
  1639. innobase_file_format_name =
  1640. (char*) trx_sys_file_format_id_to_name(format_id);
  1641. /* Process innobase_file_format_check variable */
  1642. ut_a(innobase_file_format_check != NULL);
  1643. /* As a side effect it will set srv_check_file_format_at_startup
  1644. on valid input. First we check for "on"/"off". */
  1645. if (!innobase_file_format_check_on_off(innobase_file_format_check)) {
  1646. /* Did the user specify a format name that we support ?
  1647. As a side effect it will update the variable
  1648. srv_check_file_format_at_startup */
  1649. if (!innobase_file_format_check_validate(
  1650. innobase_file_format_check)) {
  1651. sql_print_error("InnoDB: invalid "
  1652. "innodb_file_format_check value: "
  1653. "should be either 'on' or 'off' or "
  1654. "any value up to %s or its "
  1655. "equivalent numeric id",
  1656. trx_sys_file_format_id_to_name(
  1657. DICT_TF_FORMAT_MAX));
  1658. my_free(internal_innobase_data_file_path,
  1659. MYF(MY_ALLOW_ZERO_PTR));
  1660. goto error;
  1661. }
  1662. }
  1663. /* --------------------------------------------------*/
  1664. srv_file_flush_method_str = innobase_unix_file_flush_method;
  1665. srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
  1666. srv_n_log_files = (ulint) innobase_log_files_in_group;
  1667. srv_log_file_size = (ulint) innobase_log_file_size;
  1668. #ifdef UNIV_LOG_ARCHIVE
  1669. srv_log_archive_on = (ulint) innobase_log_archive;
  1670. #endif /* UNIV_LOG_ARCHIVE */
  1671. srv_log_buffer_size = (ulint) innobase_log_buffer_size;
  1672. srv_buf_pool_size = (ulint) innobase_buffer_pool_size;
  1673. srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
  1674. srv_n_file_io_threads = (ulint) innobase_file_io_threads;
  1675. srv_force_recovery = (ulint) innobase_force_recovery;
  1676. srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
  1677. srv_use_checksums = (ibool) innobase_use_checksums;
  1678. #ifdef HAVE_LARGE_PAGES
  1679. if ((os_use_large_pages = (ibool) my_use_large_pages))
  1680. os_large_page_size = (ulint) opt_large_page_size;
  1681. #endif
  1682. row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
  1683. srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog;
  1684. srv_max_n_open_files = (ulint) innobase_open_files;
  1685. srv_innodb_status = (ibool) innobase_create_status_file;
  1686. srv_stats_on_metadata = (ibool) innobase_stats_on_metadata;
  1687. btr_search_disabled = (ibool) !innobase_adaptive_hash_index;
  1688. srv_print_verbose_log = mysqld_embedded ? 0 : 1;
  1689. /* Store the default charset-collation number of this MySQL
  1690. installation */
  1691. data_mysql_default_charset_coll = (ulint)default_charset_info->number;
  1692. ut_a(DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL ==
  1693. my_charset_latin1.number);
  1694. ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
  1695. /* Store the latin1_swedish_ci character ordering table to InnoDB. For
  1696. non-latin1_swedish_ci charsets we use the MySQL comparison functions,
  1697. and consequently we do not need to know the ordering internally in
  1698. InnoDB. */
  1699. ut_a(0 == strcmp(my_charset_latin1.name, "latin1_swedish_ci"));
  1700. srv_latin1_ordering = my_charset_latin1.sort_order;
  1701. /* Since we in this module access directly the fields of a trx
  1702. struct, and due to different headers and flags it might happen that
  1703. mutex_t has a different size in this module and in InnoDB
  1704. modules, we check at run time that the size is the same in
  1705. these compilation modules. */
  1706. err = innobase_start_or_create_for_mysql();
  1707. if (err != DB_SUCCESS) {
  1708. my_free(internal_innobase_data_file_path,
  1709. MYF(MY_ALLOW_ZERO_PTR));
  1710. goto error;
  1711. }
  1712. (void) hash_init(&innobase_open_tables,system_charset_info, 32, 0, 0,
  1713. (hash_get_key) innobase_get_key, 0, 0);
  1714. pthread_mutex_init(&innobase_share_mutex, MY_MUTEX_INIT_FAST);
  1715. pthread_mutex_init(&prepare_commit_mutex, MY_MUTEX_INIT_FAST);
  1716. pthread_mutex_init(&commit_threads_m, MY_MUTEX_INIT_FAST);
  1717. pthread_mutex_init(&commit_cond_m, MY_MUTEX_INIT_FAST);
  1718. pthread_cond_init(&commit_cond, NULL);
  1719. innodb_inited= 1;
  1720. #ifdef MYSQL_DYNAMIC_PLUGIN
  1721. if (innobase_hton != p) {
  1722. innobase_hton = reinterpret_cast<handlerton*>(p);
  1723. *innobase_hton = *innodb_hton_ptr;
  1724. }
  1725. #endif /* MYSQL_DYNAMIC_PLUGIN */
  1726. /* Get the current high water mark format. */
  1727. innobase_file_format_check = (char*) trx_sys_file_format_max_get();
  1728. DBUG_RETURN(FALSE);
  1729. error:
  1730. DBUG_RETURN(TRUE);
  1731. }
  1732. /***********************************************************************
  1733. Closes an InnoDB database. */
  1734. static
  1735. int
  1736. innobase_end(handlerton *hton, ha_panic_function type)
  1737. /*==============*/
  1738. /* out: TRUE if error */
  1739. {
  1740. int err= 0;
  1741. DBUG_ENTER("innobase_end");
  1742. DBUG_ASSERT(hton == innodb_hton_ptr);
  1743. #ifdef __NETWARE__ /* some special cleanup for NetWare */
  1744. if (nw_panic) {
  1745. set_panic_flag_for_netware();
  1746. }
  1747. #endif
  1748. if (innodb_inited) {
  1749. srv_fast_shutdown = (ulint) innobase_fast_shutdown;
  1750. innodb_inited = 0;
  1751. if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
  1752. err = 1;
  1753. }
  1754. hash_free(&innobase_open_tables);
  1755. my_free(internal_innobase_data_file_path,
  1756. MYF(MY_ALLOW_ZERO_PTR));
  1757. pthread_mutex_destroy(&innobase_share_mutex);
  1758. pthread_mutex_destroy(&prepare_commit_mutex);
  1759. pthread_mutex_destroy(&commit_threads_m);
  1760. pthread_mutex_destroy(&commit_cond_m);
  1761. pthread_cond_destroy(&commit_cond);
  1762. }
  1763. DBUG_RETURN(err);
  1764. }
  1765. /********************************************************************
  1766. Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
  1767. the logs, and the name of this function should be innobase_checkpoint. */
  1768. static
  1769. bool
  1770. innobase_flush_logs(handlerton *hton)
  1771. /*=====================*/
  1772. /* out: TRUE if error */
  1773. {
  1774. bool result = 0;
  1775. DBUG_ENTER("innobase_flush_logs");
  1776. DBUG_ASSERT(hton == innodb_hton_ptr);
  1777. log_buffer_flush_to_disk();
  1778. DBUG_RETURN(result);
  1779. }
  1780. /********************************************************************
  1781. Return alter table flags supported in an InnoDB database. */
  1782. static
  1783. uint
  1784. innobase_alter_table_flags(
  1785. /*=======================*/
  1786. uint flags)
  1787. {
  1788. return(HA_ONLINE_ADD_INDEX_NO_WRITES
  1789. | HA_ONLINE_DROP_INDEX_NO_WRITES
  1790. | HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES
  1791. | HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES
  1792. | HA_ONLINE_ADD_PK_INDEX_NO_WRITES);
  1793. }
  1794. /*********************************************************************
  1795. Commits a transaction in an InnoDB database. */
  1796. static
  1797. void
  1798. innobase_commit_low(
  1799. /*================*/
  1800. trx_t* trx) /* in: transaction handle */
  1801. {
  1802. if (trx->conc_state == TRX_NOT_STARTED) {
  1803. return;
  1804. }
  1805. trx_commit_for_mysql(trx);
  1806. }
  1807. /*********************************************************************
  1808. Creates an InnoDB transaction struct for the thd if it does not yet have one.
  1809. Starts a new InnoDB transaction if a transaction is not yet started. And
  1810. assigns a new snapshot for a consistent read if the transaction does not yet
  1811. have one. */
  1812. static
  1813. int
  1814. innobase_start_trx_and_assign_read_view(
  1815. /*====================================*/
  1816. /* out: 0 */
  1817. handlerton *hton, /* in: Innodb handlerton */
  1818. THD* thd) /* in: MySQL thread handle of the user for whom
  1819. the transaction should be committed */
  1820. {
  1821. trx_t* trx;
  1822. DBUG_ENTER("innobase_start_trx_and_assign_read_view");
  1823. DBUG_ASSERT(hton == innodb_hton_ptr);
  1824. /* Create a new trx struct for thd, if it does not yet have one */
  1825. trx = check_trx_exists(thd);
  1826. /* This is just to play safe: release a possible FIFO ticket and
  1827. search latch. Since we will reserve the kernel mutex, we have to
  1828. release the search system latch first to obey the latching order. */
  1829. innobase_release_stat_resources(trx);
  1830. /* If the transaction is not started yet, start it */
  1831. trx_start_if_not_started(trx);
  1832. /* Assign a read view if the transaction does not have it yet */
  1833. trx_assign_read_view(trx);
  1834. /* Set the MySQL flag to mark that there is an active transaction */
  1835. if (trx->active_trans == 0) {
  1836. innobase_register_trx_and_stmt(hton, thd);
  1837. trx->active_trans = 1;
  1838. }
  1839. DBUG_RETURN(0);
  1840. }
  1841. /*********************************************************************
  1842. Commits a transaction in an InnoDB database or marks an SQL statement
  1843. ended. */
  1844. static
  1845. int
  1846. innobase_commit(
  1847. /*============*/
  1848. /* out: 0 */
  1849. handlerton *hton, /* in: Innodb handlerton */
  1850. THD* thd, /* in: MySQL thread handle of the user for whom
  1851. the transaction should be committed */
  1852. bool all) /* in: TRUE - commit transaction
  1853. FALSE - the current SQL statement ended */
  1854. {
  1855. trx_t* trx;
  1856. DBUG_ENTER("innobase_commit");
  1857. DBUG_ASSERT(hton == innodb_hton_ptr);
  1858. DBUG_PRINT("trans", ("ending transaction"));
  1859. trx = check_trx_exists(thd);
  1860. /* Update the info whether we should skip XA steps that eat CPU time */
  1861. trx->support_xa = THDVAR(thd, support_xa);
  1862. /* Since we will reserve the kernel mutex, we have to release
  1863. the search system latch first to obey the latching order. */
  1864. if (trx->has_search_latch) {
  1865. trx_search_latch_release_if_reserved(trx);
  1866. }
  1867. /* The flag trx->active_trans is set to 1 in
  1868. 1. ::external_lock(),
  1869. 2. ::start_stmt(),
  1870. 3. innobase_query_caching_of_table_permitted(),
  1871. 4. innobase_savepoint(),
  1872. 5. ::init_table_handle_for_HANDLER(),
  1873. 6. innobase_start_trx_and_assign_read_view(),
  1874. 7. ::transactional_table_lock()
  1875. and it is only set to 0 in a commit or a rollback. If it is 0 we know
  1876. there cannot be resources to be freed and we could return immediately.
  1877. For the time being, we play safe and do the cleanup though there should
  1878. be nothing to clean up. */
  1879. if (trx->active_trans == 0
  1880. && trx->conc_state != TRX_NOT_STARTED) {
  1881. sql_print_error("trx->active_trans == 0, but"
  1882. " trx->conc_state != TRX_NOT_STARTED");
  1883. }
  1884. if (all
  1885. || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
  1886. /* We were instructed to commit the whole transaction, or
  1887. this is an SQL statement end and autocommit is on */
  1888. /* We need current binlog position for ibbackup to work.
  1889. Note, the position is current because of
  1890. prepare_commit_mutex */
  1891. retry:
  1892. if (srv_commit_concurrency > 0) {
  1893. pthread_mutex_lock(&commit_cond_m);
  1894. commit_threads++;
  1895. if (commit_threads > srv_commit_concurrency) {
  1896. commit_threads--;
  1897. pthread_cond_wait(&commit_cond,
  1898. &commit_cond_m);
  1899. pthread_mutex_unlock(&commit_cond_m);
  1900. goto retry;
  1901. }
  1902. else {
  1903. pthread_mutex_unlock(&commit_cond_m);
  1904. }
  1905. }
  1906. trx->mysql_log_file_name = mysql_bin_log_file_name();
  1907. trx->mysql_log_offset = (ib_int64_t) mysql_bin_log_file_pos();
  1908. innobase_commit_low(trx);
  1909. if (srv_commit_concurrency > 0) {
  1910. pthread_mutex_lock(&commit_cond_m);
  1911. commit_threads--;
  1912. pthread_cond_signal(&commit_cond);
  1913. pthread_mutex_unlock(&commit_cond_m);
  1914. }
  1915. if (trx->active_trans == 2) {
  1916. pthread_mutex_unlock(&prepare_commit_mutex);
  1917. }
  1918. trx->active_trans = 0;
  1919. } else {
  1920. /* We just mark the SQL statement ended and do not do a
  1921. transaction commit */
  1922. /* If we had reserved the auto-inc lock for some
  1923. table in this SQL statement we release it now */
  1924. row_unlock_table_autoinc_for_mysql(trx);
  1925. /* Store the current undo_no of the transaction so that we
  1926. know where to roll back if we have to roll back the next
  1927. SQL statement */
  1928. trx_mark_sql_stat_end(trx);
  1929. }
  1930. trx->n_autoinc_rows = 0; /* Reset the number AUTO-INC rows required */
  1931. if (trx->declared_to_be_inside_innodb) {
  1932. /* Release our possible ticket in the FIFO */
  1933. srv_conc_force_exit_innodb(trx);
  1934. }
  1935. /* Tell the InnoDB server that there might be work for utility
  1936. threads: */
  1937. srv_active_wake_master_thread();
  1938. DBUG_RETURN(0);
  1939. }
  1940. /*********************************************************************
  1941. Rolls back a transaction or the latest SQL statement. */
  1942. static
  1943. int
  1944. innobase_rollback(
  1945. /*==============*/
  1946. /* out: 0 or error number */
  1947. handlerton *hton, /* in: Innodb handlerton */
  1948. THD* thd, /* in: handle to the MySQL thread of the user
  1949. whose transaction should be rolled back */
  1950. bool all) /* in: TRUE - commit transaction
  1951. FALSE - the current SQL statement ended */
  1952. {
  1953. int error = 0;
  1954. trx_t* trx;
  1955. DBUG_ENTER("innobase_rollback");
  1956. DBUG_ASSERT(hton == innodb_hton_ptr);
  1957. DBUG_PRINT("trans", ("aborting transaction"));
  1958. trx = check_trx_exists(thd);
  1959. /* Update the info whether we should skip XA steps that eat CPU time */
  1960. trx->support_xa = THDVAR(thd, support_xa);
  1961. /* Release a possible FIFO ticket and search latch. Since we will
  1962. reserve the kernel mutex, we have to release the search system latch
  1963. first to obey the latching order. */
  1964. innobase_release_stat_resources(trx);
  1965. /* If we had reserved the auto-inc lock for some table (if
  1966. we come here to roll back the latest SQL statement) we
  1967. release it now before a possibly lengthy rollback */
  1968. row_unlock_table_autoinc_for_mysql(trx);
  1969. if (all
  1970. || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  1971. error = trx_rollback_for_mysql(trx);
  1972. trx->active_trans = 0;
  1973. } else {
  1974. error = trx_rollback_last_sql_stat_for_mysql(trx);
  1975. }
  1976. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  1977. }
  1978. /*********************************************************************
  1979. Rolls back a transaction */
  1980. static
  1981. int
  1982. innobase_rollback_trx(
  1983. /*==================*/
  1984. /* out: 0 or error number */
  1985. trx_t* trx) /* in: transaction */
  1986. {
  1987. int error = 0;
  1988. DBUG_ENTER("innobase_rollback_trx");
  1989. DBUG_PRINT("trans", ("aborting transaction"));
  1990. /* Release a possible FIFO ticket and search latch. Since we will
  1991. reserve the kernel mutex, we have to release the search system latch
  1992. first to obey the latching order. */
  1993. innobase_release_stat_resources(trx);
  1994. /* If we had reserved the auto-inc lock for some table (if
  1995. we come here to roll back the latest SQL statement) we
  1996. release it now before a possibly lengthy rollback */
  1997. row_unlock_table_autoinc_for_mysql(trx);
  1998. error = trx_rollback_for_mysql(trx);
  1999. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  2000. }
  2001. /*********************************************************************
  2002. Rolls back a transaction to a savepoint. */
  2003. static
  2004. int
  2005. innobase_rollback_to_savepoint(
  2006. /*===========================*/
  2007. /* out: 0 if success, HA_ERR_NO_SAVEPOINT if
  2008. no savepoint with the given name */
  2009. handlerton *hton, /* in: Innodb handlerton */
  2010. THD* thd, /* in: handle to the MySQL thread of the user
  2011. whose transaction should be rolled back */
  2012. void* savepoint) /* in: savepoint data */
  2013. {
  2014. ib_int64_t mysql_binlog_cache_pos;
  2015. int error = 0;
  2016. trx_t* trx;
  2017. char name[64];
  2018. DBUG_ENTER("innobase_rollback_to_savepoint");
  2019. DBUG_ASSERT(hton == innodb_hton_ptr);
  2020. trx = check_trx_exists(thd);
  2021. /* Release a possible FIFO ticket and search latch. Since we will
  2022. reserve the kernel mutex, we have to release the search system latch
  2023. first to obey the latching order. */
  2024. innobase_release_stat_resources(trx);
  2025. /* TODO: use provided savepoint data area to store savepoint data */
  2026. longlong2str((ulint)savepoint, name, 36);
  2027. error = (int) trx_rollback_to_savepoint_for_mysql(trx, name,
  2028. &mysql_binlog_cache_pos);
  2029. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  2030. }
  2031. /*********************************************************************
  2032. Release transaction savepoint name. */
  2033. static
  2034. int
  2035. innobase_release_savepoint(
  2036. /*=======================*/
  2037. /* out: 0 if success, HA_ERR_NO_SAVEPOINT if
  2038. no savepoint with the given name */
  2039. handlerton* hton, /* in: handlerton for Innodb */
  2040. THD* thd, /* in: handle to the MySQL thread of the user
  2041. whose transaction should be rolled back */
  2042. void* savepoint) /* in: savepoint data */
  2043. {
  2044. int error = 0;
  2045. trx_t* trx;
  2046. char name[64];
  2047. DBUG_ENTER("innobase_release_savepoint");
  2048. DBUG_ASSERT(hton == innodb_hton_ptr);
  2049. trx = check_trx_exists(thd);
  2050. /* TODO: use provided savepoint data area to store savepoint data */
  2051. longlong2str((ulint)savepoint, name, 36);
  2052. error = (int) trx_release_savepoint_for_mysql(trx, name);
  2053. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  2054. }
  2055. /*********************************************************************
  2056. Sets a transaction savepoint. */
  2057. static
  2058. int
  2059. innobase_savepoint(
  2060. /*===============*/
  2061. /* out: always 0, that is, always succeeds */
  2062. handlerton* hton, /* in: handle to the Innodb handlerton */
  2063. THD* thd, /* in: handle to the MySQL thread */
  2064. void* savepoint) /* in: savepoint data */
  2065. {
  2066. int error = 0;
  2067. trx_t* trx;
  2068. DBUG_ENTER("innobase_savepoint");
  2069. DBUG_ASSERT(hton == innodb_hton_ptr);
  2070. /*
  2071. In the autocommit mode there is no sense to set a savepoint
  2072. (unless we are in sub-statement), so SQL layer ensures that
  2073. this method is never called in such situation.
  2074. */
  2075. #ifdef MYSQL_SERVER /* plugins cannot access thd->in_sub_stmt */
  2076. DBUG_ASSERT(thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
  2077. thd->in_sub_stmt);
  2078. #endif /* MYSQL_SERVER */
  2079. trx = check_trx_exists(thd);
  2080. /* Release a possible FIFO ticket and search latch. Since we will
  2081. reserve the kernel mutex, we have to release the search system latch
  2082. first to obey the latching order. */
  2083. innobase_release_stat_resources(trx);
  2084. /* cannot happen outside of transaction */
  2085. DBUG_ASSERT(trx->active_trans);
  2086. /* TODO: use provided savepoint data area to store savepoint data */
  2087. char name[64];
  2088. longlong2str((ulint)savepoint,name,36);
  2089. error = (int) trx_savepoint_for_mysql(trx, name, (ib_int64_t)0);
  2090. DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
  2091. }
  2092. /*********************************************************************
  2093. Frees a possible InnoDB trx object associated with the current THD. */
  2094. static
  2095. int
  2096. innobase_close_connection(
  2097. /*======================*/
  2098. /* out: 0 or error number */
  2099. handlerton* hton, /* in: innobase handlerton */
  2100. THD* thd) /* in: handle to the MySQL thread of the user
  2101. whose resources should be free'd */
  2102. {
  2103. trx_t* trx;
  2104. DBUG_ENTER("innobase_close_connection");
  2105. DBUG_ASSERT(hton == innodb_hton_ptr);
  2106. trx = thd_to_trx(thd);
  2107. ut_a(trx);
  2108. if (trx->active_trans == 0
  2109. && trx->conc_state != TRX_NOT_STARTED) {
  2110. sql_print_error("trx->active_trans == 0, but"
  2111. " trx->conc_state != TRX_NOT_STARTED");
  2112. }
  2113. if (trx->conc_state != TRX_NOT_STARTED &&
  2114. global_system_variables.log_warnings) {
  2115. sql_print_warning(
  2116. "MySQL is closing a connection that has an active "
  2117. "InnoDB transaction. %lu row modifications will "
  2118. "roll back.",
  2119. (ulong) trx->undo_no.low);
  2120. }
  2121. innobase_rollback_trx(trx);
  2122. thr_local_free(trx->mysql_thread_id);
  2123. trx_free_for_mysql(trx);
  2124. DBUG_RETURN(0);
  2125. }
  2126. /*****************************************************************************
  2127. ** InnoDB database tables
  2128. *****************************************************************************/
  2129. /********************************************************************
  2130. Get the record format from the data dictionary. */
  2131. UNIV_INTERN
  2132. enum row_type
  2133. ha_innobase::get_row_type() const
  2134. /*=============================*/
  2135. /* out: one of
  2136. ROW_TYPE_REDUNDANT,
  2137. ROW_TYPE_COMPACT,
  2138. ROW_TYPE_COMPRESSED,
  2139. ROW_TYPE_DYNAMIC */
  2140. {
  2141. if (prebuilt && prebuilt->table) {
  2142. const ulint flags = prebuilt->table->flags;
  2143. if (UNIV_UNLIKELY(!flags)) {
  2144. return(ROW_TYPE_REDUNDANT);
  2145. }
  2146. ut_ad(flags & DICT_TF_COMPACT);
  2147. switch (flags & DICT_TF_FORMAT_MASK) {
  2148. case DICT_TF_FORMAT_51 << DICT_TF_FORMAT_SHIFT:
  2149. return(ROW_TYPE_COMPACT);
  2150. case DICT_TF_FORMAT_ZIP << DICT_TF_FORMAT_SHIFT:
  2151. if (flags & DICT_TF_ZSSIZE_MASK) {
  2152. return(ROW_TYPE_COMPRESSED);
  2153. } else {
  2154. return(ROW_TYPE_DYNAMIC);
  2155. }
  2156. #if DICT_TF_FORMAT_ZIP != DICT_TF_FORMAT_MAX
  2157. # error "DICT_TF_FORMAT_ZIP != DICT_TF_FORMAT_MAX"
  2158. #endif
  2159. }
  2160. }
  2161. ut_ad(0);
  2162. return(ROW_TYPE_NOT_USED);
  2163. }
  2164. /********************************************************************
  2165. Get the table flags to use for the statement. */
  2166. UNIV_INTERN
  2167. handler::Table_flags
  2168. ha_innobase::table_flags() const
  2169. {
  2170. /* Need to use tx_isolation here since table flags is (also)
  2171. called before prebuilt is inited. */
  2172. ulong const tx_isolation = thd_tx_isolation(ha_thd());
  2173. if (tx_isolation <= ISO_READ_COMMITTED)
  2174. return int_table_flags;
  2175. return int_table_flags | HA_BINLOG_STMT_CAPABLE;
  2176. }
  2177. /********************************************************************
  2178. Gives the file extension of an InnoDB single-table tablespace. */
  2179. static const char* ha_innobase_exts[] = {
  2180. ".ibd",
  2181. NullS
  2182. };
  2183. UNIV_INTERN
  2184. const char*
  2185. ha_innobase::table_type() const
  2186. /*===========================*/
  2187. /* out: table type */
  2188. {
  2189. return(innobase_hton_name);
  2190. }
  2191. UNIV_INTERN
  2192. const char*
  2193. ha_innobase::index_type(uint)
  2194. /*=========================*/
  2195. /* out: index type */
  2196. {
  2197. return("BTREE");
  2198. }
  2199. UNIV_INTERN
  2200. const char**
  2201. ha_innobase::bas_ext() const
  2202. /*========================*/
  2203. /* out: file extension string */
  2204. {
  2205. return(ha_innobase_exts);
  2206. }
  2207. UNIV_INTERN
  2208. ulong
  2209. ha_innobase::index_flags(uint, uint, bool) const
  2210. {
  2211. return(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER
  2212. | HA_READ_RANGE | HA_KEYREAD_ONLY);
  2213. }
  2214. UNIV_INTERN
  2215. uint
  2216. ha_innobase::max_supported_keys() const
  2217. {
  2218. return(MAX_KEY);
  2219. }
  2220. UNIV_INTERN
  2221. uint
  2222. ha_innobase::max_supported_key_length() const
  2223. {
  2224. /* An InnoDB page must store >= 2 keys; a secondary key record
  2225. must also contain the primary key value: max key length is
  2226. therefore set to slightly less than 1 / 4 of page size which
  2227. is 16 kB; but currently MySQL does not work with keys whose
  2228. size is > MAX_KEY_LENGTH */
  2229. return(3500);
  2230. }
  2231. UNIV_INTERN
  2232. const key_map*
  2233. ha_innobase::keys_to_use_for_scanning()
  2234. {
  2235. return(&key_map_full);
  2236. }
  2237. UNIV_INTERN
  2238. uint8
  2239. ha_innobase::table_cache_type()
  2240. {
  2241. return(HA_CACHE_TBL_ASKTRANSACT);
  2242. }
  2243. UNIV_INTERN
  2244. bool
  2245. ha_innobase::primary_key_is_clustered()
  2246. {
  2247. return(true);
  2248. }
  2249. /*********************************************************************
  2250. Normalizes a table name string. A normalized name consists of the
  2251. database name catenated to '/' and table name. An example:
  2252. test/mytable. On Windows normalization puts both the database name and the
  2253. table name always to lower case. */
  2254. static
  2255. void
  2256. normalize_table_name(
  2257. /*=================*/
  2258. char* norm_name, /* out: normalized name as a
  2259. null-terminated string */
  2260. const char* name) /* in: table name string */
  2261. {
  2262. char* name_ptr;
  2263. char* db_ptr;
  2264. char* ptr;
  2265. /* Scan name from the end */
  2266. ptr = strend(name)-1;
  2267. while (ptr >= name && *ptr != '\\' && *ptr != '/') {
  2268. ptr--;
  2269. }
  2270. name_ptr = ptr + 1;
  2271. DBUG_ASSERT(ptr > name);
  2272. ptr--;
  2273. while (ptr >= name && *ptr != '\\' && *ptr != '/') {
  2274. ptr--;
  2275. }
  2276. db_ptr = ptr + 1;
  2277. memcpy(norm_name, db_ptr, strlen(name) + 1 - (db_ptr - name));
  2278. norm_name[name_ptr - db_ptr - 1] = '/';
  2279. #ifdef __WIN__
  2280. innobase_casedn_str(norm_name);
  2281. #endif
  2282. }
  2283. /************************************************************************
  2284. Set the autoinc column max value. This should only be called once from
  2285. ha_innobase::open(). Therefore there's no need for a covering lock. */
  2286. UNIV_INTERN
  2287. ulint
  2288. ha_innobase::innobase_initialize_autoinc()
  2289. /*======================================*/
  2290. {
  2291. dict_index_t* index;
  2292. ulonglong auto_inc;
  2293. const char* col_name;
  2294. ulint error = DB_SUCCESS;
  2295. dict_table_t* innodb_table = prebuilt->table;
  2296. col_name = table->found_next_number_field->field_name;
  2297. index = innobase_get_index(table->s->next_number_index);
  2298. /* Execute SELECT MAX(col_name) FROM TABLE; */
  2299. error = row_search_max_autoinc(index, col_name, &auto_inc);
  2300. if (error == DB_SUCCESS) {
  2301. /* At the this stage we dont' know the increment
  2302. or the offset, so use default inrement of 1. */
  2303. ++auto_inc;
  2304. dict_table_autoinc_initialize(innodb_table, auto_inc);
  2305. } else {
  2306. ut_print_timestamp(stderr);
  2307. fprintf(stderr, " InnoDB: Error: (%lu) Couldn't read "
  2308. "the MAX(%s) autoinc value from the "
  2309. "index (%s).\n", error, col_name, index->name);
  2310. }
  2311. return(error);
  2312. }
  2313. /*********************************************************************
  2314. Creates and opens a handle to a table which already exists in an InnoDB
  2315. database. */
  2316. UNIV_INTERN
  2317. int
  2318. ha_innobase::open(
  2319. /*==============*/
  2320. /* out: 1 if error, 0 if success */
  2321. const char* name, /* in: table name */
  2322. int mode, /* in: not used */
  2323. uint test_if_locked) /* in: not used */
  2324. {
  2325. dict_table_t* ib_table;
  2326. char norm_name[1000];
  2327. THD* thd;
  2328. ulint retries = 0;
  2329. char* is_part = NULL;
  2330. DBUG_ENTER("ha_innobase::open");
  2331. UT_NOT_USED(mode);
  2332. UT_NOT_USED(test_if_locked);
  2333. thd = ha_thd();
  2334. /* Under some cases MySQL seems to call this function while
  2335. holding btr_search_latch. This breaks the latching order as
  2336. we acquire dict_sys->mutex below and leads to a deadlock. */
  2337. if (thd != NULL) {
  2338. innobase_release_temporary_latches(ht, thd);
  2339. }
  2340. normalize_table_name(norm_name, name);
  2341. user_thd = NULL;
  2342. if (!(share=get_share(name))) {
  2343. DBUG_RETURN(1);
  2344. }
  2345. /* Create buffers for packing the fields of a record. Why
  2346. table->reclength did not work here? Obviously, because char
  2347. fields when packed actually became 1 byte longer, when we also
  2348. stored the string length as the first byte. */
  2349. upd_and_key_val_buff_len =
  2350. table->s->reclength + table->s->max_key_length
  2351. + MAX_REF_PARTS * 3;
  2352. if (!(uchar*) my_multi_malloc(MYF(MY_WME),
  2353. &upd_buff, upd_and_key_val_buff_len,
  2354. &key_val_buff, upd_and_key_val_buff_len,
  2355. NullS)) {
  2356. free_share(share);
  2357. DBUG_RETURN(1);
  2358. }
  2359. /* We look for pattern #P# to see if the table is partitioned
  2360. MySQL table. The retry logic for partitioned tables is a
  2361. workaround for http://bugs.mysql.com/bug.php?id=33349. Look
  2362. at support issue https://support.mysql.com/view.php?id=21080
  2363. for more details. */
  2364. is_part = strstr(norm_name, "#P#");
  2365. retry:
  2366. /* Get pointer to a table object in InnoDB dictionary cache */
  2367. ib_table = dict_table_get(norm_name, TRUE);
  2368. if (NULL == ib_table) {
  2369. if (is_part && retries < 10) {
  2370. ++retries;
  2371. os_thread_sleep(100000);
  2372. goto retry;
  2373. }
  2374. if (is_part) {
  2375. sql_print_error("Failed to open table %s after "
  2376. "%lu attemtps.\n", norm_name,
  2377. retries);
  2378. }
  2379. sql_print_error("Cannot find or open table %s from\n"
  2380. "the internal data dictionary of InnoDB "
  2381. "though the .frm file for the\n"
  2382. "table exists. Maybe you have deleted and "
  2383. "recreated InnoDB data\n"
  2384. "files but have forgotten to delete the "
  2385. "corresponding .frm files\n"
  2386. "of InnoDB tables, or you have moved .frm "
  2387. "files to another database?\n"
  2388. "or, the table contains indexes that this "
  2389. "version of the engine\n"
  2390. "doesn't support.\n"
  2391. "See http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n"
  2392. "how you can resolve the problem.\n",
  2393. norm_name);
  2394. free_share(share);
  2395. my_free(upd_buff, MYF(0));
  2396. my_errno = ENOENT;
  2397. DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
  2398. }
  2399. if (ib_table->ibd_file_missing && !thd_tablespace_op(thd)) {
  2400. sql_print_error("MySQL is trying to open a table handle but "
  2401. "the .ibd file for\ntable %s does not exist.\n"
  2402. "Have you deleted the .ibd file from the "
  2403. "database directory under\nthe MySQL datadir, "
  2404. "or have you used DISCARD TABLESPACE?\n"
  2405. "See http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n"
  2406. "how you can resolve the problem.\n",
  2407. norm_name);
  2408. free_share(share);
  2409. my_free(upd_buff, MYF(0));
  2410. my_errno = ENOENT;
  2411. dict_table_decrement_handle_count(ib_table, FALSE);
  2412. DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
  2413. }
  2414. prebuilt = row_create_prebuilt(ib_table);
  2415. prebuilt->mysql_row_len = table->s->reclength;
  2416. /* Looks like MySQL-3.23 sometimes has primary key number != 0 */
  2417. primary_key = table->s->primary_key;
  2418. key_used_on_scan = primary_key;
  2419. /* Allocate a buffer for a 'row reference'. A row reference is
  2420. a string of bytes of length ref_length which uniquely specifies
  2421. a row in our table. Note that MySQL may also compare two row
  2422. references for equality by doing a simple memcmp on the strings
  2423. of length ref_length! */
  2424. if (!row_table_got_default_clust_index(ib_table)) {
  2425. if (primary_key >= MAX_KEY) {
  2426. sql_print_error("Table %s has a primary key in InnoDB data "
  2427. "dictionary, but not in MySQL!", name);
  2428. }
  2429. prebuilt->clust_index_was_generated = FALSE;
  2430. /* MySQL allocates the buffer for ref. key_info->key_length
  2431. includes space for all key columns + one byte for each column
  2432. that may be NULL. ref_length must be as exact as possible to
  2433. save space, because all row reference buffers are allocated
  2434. based on ref_length. */
  2435. ref_length = table->key_info[primary_key].key_length;
  2436. } else {
  2437. if (primary_key != MAX_KEY) {
  2438. sql_print_error("Table %s has no primary key in InnoDB data "
  2439. "dictionary, but has one in MySQL! If you "
  2440. "created the table with a MySQL version < "
  2441. "3.23.54 and did not define a primary key, "
  2442. "but defined a unique key with all non-NULL "
  2443. "columns, then MySQL internally treats that "
  2444. "key as the primary key. You can fix this "
  2445. "error by dump + DROP + CREATE + reimport "
  2446. "of the table.", name);
  2447. }
  2448. prebuilt->clust_index_was_generated = TRUE;
  2449. ref_length = DATA_ROW_ID_LEN;
  2450. /* If we automatically created the clustered index, then
  2451. MySQL does not know about it, and MySQL must NOT be aware
  2452. of the index used on scan, to make it avoid checking if we
  2453. update the column of the index. That is why we assert below
  2454. that key_used_on_scan is the undefined value MAX_KEY.
  2455. The column is the row id in the automatical generation case,
  2456. and it will never be updated anyway. */
  2457. if (key_used_on_scan != MAX_KEY) {
  2458. sql_print_warning(
  2459. "Table %s key_used_on_scan is %lu even "
  2460. "though there is no primary key inside "
  2461. "InnoDB.", name, (ulong) key_used_on_scan);
  2462. }
  2463. }
  2464. /* Index block size in InnoDB: used by MySQL in query optimization */
  2465. stats.block_size = 16 * 1024;
  2466. /* Init table lock structure */
  2467. thr_lock_data_init(&share->lock,&lock,(void*) 0);
  2468. if (prebuilt->table) {
  2469. /* We update the highest file format in the system table
  2470. space, if this table has higher file format setting. */
  2471. trx_sys_file_format_max_upgrade(
  2472. (const char**) &innobase_file_format_check,
  2473. dict_table_get_format(prebuilt->table));
  2474. }
  2475. info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
  2476. /* Only if the table has an AUTOINC column. */
  2477. if (prebuilt->table != NULL && table->found_next_number_field != NULL) {
  2478. ulint error;
  2479. dict_table_autoinc_lock(prebuilt->table);
  2480. /* Since a table can already be "open" in InnoDB's internal
  2481. data dictionary, we only init the autoinc counter once, the
  2482. first time the table is loaded. We can safely reuse the
  2483. autoinc value from a previous MySQL open. */
  2484. if (dict_table_autoinc_read(prebuilt->table) == 0) {
  2485. error = innobase_initialize_autoinc();
  2486. /* Should always succeed! */
  2487. ut_a(error == DB_SUCCESS);
  2488. }
  2489. dict_table_autoinc_unlock(prebuilt->table);
  2490. }
  2491. DBUG_RETURN(0);
  2492. }
  2493. UNIV_INTERN
  2494. uint
  2495. ha_innobase::max_supported_key_part_length() const
  2496. {
  2497. return(DICT_MAX_INDEX_COL_LEN - 1);
  2498. }
  2499. /**********************************************************************
  2500. Closes a handle to an InnoDB table. */
  2501. UNIV_INTERN
  2502. int
  2503. ha_innobase::close(void)
  2504. /*====================*/
  2505. /* out: 0 */
  2506. {
  2507. THD* thd;
  2508. DBUG_ENTER("ha_innobase::close");
  2509. thd = ha_thd();
  2510. if (thd != NULL) {
  2511. innobase_release_temporary_latches(ht, thd);
  2512. }
  2513. row_prebuilt_free(prebuilt, FALSE);
  2514. my_free(upd_buff, MYF(0));
  2515. free_share(share);
  2516. /* Tell InnoDB server that there might be work for
  2517. utility threads: */
  2518. srv_active_wake_master_thread();
  2519. DBUG_RETURN(0);
  2520. }
  2521. /* The following accessor functions should really be inside MySQL code! */
  2522. /******************************************************************
  2523. Gets field offset for a field in a table. */
  2524. inline
  2525. uint
  2526. get_field_offset(
  2527. /*=============*/
  2528. /* out: offset */
  2529. TABLE* table, /* in: MySQL table object */
  2530. Field* field) /* in: MySQL field object */
  2531. {
  2532. return((uint) (field->ptr - table->record[0]));
  2533. }
  2534. /******************************************************************
  2535. Checks if a field in a record is SQL NULL. Uses the record format
  2536. information in table to track the null bit in record. */
  2537. static inline
  2538. uint
  2539. field_in_record_is_null(
  2540. /*====================*/
  2541. /* out: 1 if NULL, 0 otherwise */
  2542. TABLE* table, /* in: MySQL table object */
  2543. Field* field, /* in: MySQL field object */
  2544. char* record) /* in: a row in MySQL format */
  2545. {
  2546. int null_offset;
  2547. if (!field->null_ptr) {
  2548. return(0);
  2549. }
  2550. null_offset = (uint) ((char*) field->null_ptr
  2551. - (char*) table->record[0]);
  2552. if (record[null_offset] & field->null_bit) {
  2553. return(1);
  2554. }
  2555. return(0);
  2556. }
  2557. /******************************************************************
  2558. Sets a field in a record to SQL NULL. Uses the record format
  2559. information in table to track the null bit in record. */
  2560. inline
  2561. void
  2562. set_field_in_record_to_null(
  2563. /*========================*/
  2564. TABLE* table, /* in: MySQL table object */
  2565. Field* field, /* in: MySQL field object */
  2566. char* record) /* in: a row in MySQL format */
  2567. {
  2568. int null_offset;
  2569. null_offset = (uint) ((char*) field->null_ptr
  2570. - (char*) table->record[0]);
  2571. record[null_offset] = record[null_offset] | field->null_bit;
  2572. }
  2573. /*****************************************************************
  2574. InnoDB uses this function to compare two data fields for which the data type
  2575. is such that we must use MySQL code to compare them. NOTE that the prototype
  2576. of this function is in rem0cmp.c in InnoDB source code! If you change this
  2577. function, remember to update the prototype there! */
  2578. extern "C" UNIV_INTERN
  2579. int
  2580. innobase_mysql_cmp(
  2581. /*===============*/
  2582. /* out: 1, 0, -1, if a is greater,
  2583. equal, less than b, respectively */
  2584. int mysql_type, /* in: MySQL type */
  2585. uint charset_number, /* in: number of the charset */
  2586. const unsigned char* a, /* in: data field */
  2587. unsigned int a_length, /* in: data field length,
  2588. not UNIV_SQL_NULL */
  2589. const unsigned char* b, /* in: data field */
  2590. unsigned int b_length) /* in: data field length,
  2591. not UNIV_SQL_NULL */
  2592. {
  2593. CHARSET_INFO* charset;
  2594. enum_field_types mysql_tp;
  2595. int ret;
  2596. DBUG_ASSERT(a_length != UNIV_SQL_NULL);
  2597. DBUG_ASSERT(b_length != UNIV_SQL_NULL);
  2598. mysql_tp = (enum_field_types) mysql_type;
  2599. switch (mysql_tp) {
  2600. case MYSQL_TYPE_BIT:
  2601. case MYSQL_TYPE_STRING:
  2602. case MYSQL_TYPE_VAR_STRING:
  2603. case MYSQL_TYPE_TINY_BLOB:
  2604. case MYSQL_TYPE_MEDIUM_BLOB:
  2605. case MYSQL_TYPE_BLOB:
  2606. case MYSQL_TYPE_LONG_BLOB:
  2607. case MYSQL_TYPE_VARCHAR:
  2608. /* Use the charset number to pick the right charset struct for
  2609. the comparison. Since the MySQL function get_charset may be
  2610. slow before Bar removes the mutex operation there, we first
  2611. look at 2 common charsets directly. */
  2612. if (charset_number == default_charset_info->number) {
  2613. charset = default_charset_info;
  2614. } else if (charset_number == my_charset_latin1.number) {
  2615. charset = &my_charset_latin1;
  2616. } else {
  2617. charset = get_charset(charset_number, MYF(MY_WME));
  2618. if (charset == NULL) {
  2619. sql_print_error("InnoDB needs charset %lu for doing "
  2620. "a comparison, but MySQL cannot "
  2621. "find that charset.",
  2622. (ulong) charset_number);
  2623. ut_a(0);
  2624. }
  2625. }
  2626. /* Starting from 4.1.3, we use strnncollsp() in comparisons of
  2627. non-latin1_swedish_ci strings. NOTE that the collation order
  2628. changes then: 'b\0\0...' is ordered BEFORE 'b ...'. Users
  2629. having indexes on such data need to rebuild their tables! */
  2630. ret = charset->coll->strnncollsp(charset,
  2631. a, a_length,
  2632. b, b_length, 0);
  2633. if (ret < 0) {
  2634. return(-1);
  2635. } else if (ret > 0) {
  2636. return(1);
  2637. } else {
  2638. return(0);
  2639. }
  2640. default:
  2641. ut_error;
  2642. }
  2643. return(0);
  2644. }
  2645. /******************************************************************
  2646. Converts a MySQL type to an InnoDB type. Note that this function returns
  2647. the 'mtype' of InnoDB. InnoDB differentiates between MySQL's old <= 4.1
  2648. VARCHAR and the new true VARCHAR in >= 5.0.3 by the 'prtype'. */
  2649. extern "C" UNIV_INTERN
  2650. ulint
  2651. get_innobase_type_from_mysql_type(
  2652. /*==============================*/
  2653. /* out: DATA_BINARY,
  2654. DATA_VARCHAR, ... */
  2655. ulint* unsigned_flag, /* out: DATA_UNSIGNED if an
  2656. 'unsigned type';
  2657. at least ENUM and SET,
  2658. and unsigned integer
  2659. types are 'unsigned types' */
  2660. const void* f) /* in: MySQL Field */
  2661. {
  2662. const class Field* field = reinterpret_cast<const class Field*>(f);
  2663. /* The following asserts try to check that the MySQL type code fits in
  2664. 8 bits: this is used in ibuf and also when DATA_NOT_NULL is ORed to
  2665. the type */
  2666. DBUG_ASSERT((ulint)MYSQL_TYPE_STRING < 256);
  2667. DBUG_ASSERT((ulint)MYSQL_TYPE_VAR_STRING < 256);
  2668. DBUG_ASSERT((ulint)MYSQL_TYPE_DOUBLE < 256);
  2669. DBUG_ASSERT((ulint)MYSQL_TYPE_FLOAT < 256);
  2670. DBUG_ASSERT((ulint)MYSQL_TYPE_DECIMAL < 256);
  2671. if (field->flags & UNSIGNED_FLAG) {
  2672. *unsigned_flag = DATA_UNSIGNED;
  2673. } else {
  2674. *unsigned_flag = 0;
  2675. }
  2676. if (field->real_type() == MYSQL_TYPE_ENUM
  2677. || field->real_type() == MYSQL_TYPE_SET) {
  2678. /* MySQL has field->type() a string type for these, but the
  2679. data is actually internally stored as an unsigned integer
  2680. code! */
  2681. *unsigned_flag = DATA_UNSIGNED; /* MySQL has its own unsigned
  2682. flag set to zero, even though
  2683. internally this is an unsigned
  2684. integer type */
  2685. return(DATA_INT);
  2686. }
  2687. switch (field->type()) {
  2688. /* NOTE that we only allow string types in DATA_MYSQL and
  2689. DATA_VARMYSQL */
  2690. case MYSQL_TYPE_VAR_STRING: /* old <= 4.1 VARCHAR */
  2691. case MYSQL_TYPE_VARCHAR: /* new >= 5.0.3 true VARCHAR */
  2692. if (field->binary()) {
  2693. return(DATA_BINARY);
  2694. } else if (strcmp(
  2695. field->charset()->name,
  2696. "latin1_swedish_ci") == 0) {
  2697. return(DATA_VARCHAR);
  2698. } else {
  2699. return(DATA_VARMYSQL);
  2700. }
  2701. case MYSQL_TYPE_BIT:
  2702. case MYSQL_TYPE_STRING: if (field->binary()) {
  2703. return(DATA_FIXBINARY);
  2704. } else if (strcmp(
  2705. field->charset()->name,
  2706. "latin1_swedish_ci") == 0) {
  2707. return(DATA_CHAR);
  2708. } else {
  2709. return(DATA_MYSQL);
  2710. }
  2711. case MYSQL_TYPE_NEWDECIMAL:
  2712. return(DATA_FIXBINARY);
  2713. case MYSQL_TYPE_LONG:
  2714. case MYSQL_TYPE_LONGLONG:
  2715. case MYSQL_TYPE_TINY:
  2716. case MYSQL_TYPE_SHORT:
  2717. case MYSQL_TYPE_INT24:
  2718. case MYSQL_TYPE_DATE:
  2719. case MYSQL_TYPE_DATETIME:
  2720. case MYSQL_TYPE_YEAR:
  2721. case MYSQL_TYPE_NEWDATE:
  2722. case MYSQL_TYPE_TIME:
  2723. case MYSQL_TYPE_TIMESTAMP:
  2724. return(DATA_INT);
  2725. case MYSQL_TYPE_FLOAT:
  2726. return(DATA_FLOAT);
  2727. case MYSQL_TYPE_DOUBLE:
  2728. return(DATA_DOUBLE);
  2729. case MYSQL_TYPE_DECIMAL:
  2730. return(DATA_DECIMAL);
  2731. case MYSQL_TYPE_GEOMETRY:
  2732. case MYSQL_TYPE_TINY_BLOB:
  2733. case MYSQL_TYPE_MEDIUM_BLOB:
  2734. case MYSQL_TYPE_BLOB:
  2735. case MYSQL_TYPE_LONG_BLOB:
  2736. return(DATA_BLOB);
  2737. default:
  2738. ut_error;
  2739. }
  2740. return(0);
  2741. }
  2742. /***********************************************************************
  2743. Writes an unsigned integer value < 64k to 2 bytes, in the little-endian
  2744. storage format. */
  2745. inline
  2746. void
  2747. innobase_write_to_2_little_endian(
  2748. /*==============================*/
  2749. byte* buf, /* in: where to store */
  2750. ulint val) /* in: value to write, must be < 64k */
  2751. {
  2752. ut_a(val < 256 * 256);
  2753. buf[0] = (byte)(val & 0xFF);
  2754. buf[1] = (byte)(val / 256);
  2755. }
  2756. /***********************************************************************
  2757. Reads an unsigned integer value < 64k from 2 bytes, in the little-endian
  2758. storage format. */
  2759. inline
  2760. uint
  2761. innobase_read_from_2_little_endian(
  2762. /*===============================*/
  2763. /* out: value */
  2764. const uchar* buf) /* in: from where to read */
  2765. {
  2766. return (uint) ((ulint)(buf[0]) + 256 * ((ulint)(buf[1])));
  2767. }
  2768. /***********************************************************************
  2769. Stores a key value for a row to a buffer. */
  2770. UNIV_INTERN
  2771. uint
  2772. ha_innobase::store_key_val_for_row(
  2773. /*===============================*/
  2774. /* out: key value length as stored in buff */
  2775. uint keynr, /* in: key number */
  2776. char* buff, /* in/out: buffer for the key value (in MySQL
  2777. format) */
  2778. uint buff_len,/* in: buffer length */
  2779. const uchar* record)/* in: row in MySQL format */
  2780. {
  2781. KEY* key_info = table->key_info + keynr;
  2782. KEY_PART_INFO* key_part = key_info->key_part;
  2783. KEY_PART_INFO* end = key_part + key_info->key_parts;
  2784. char* buff_start = buff;
  2785. enum_field_types mysql_type;
  2786. Field* field;
  2787. ibool is_null;
  2788. DBUG_ENTER("store_key_val_for_row");
  2789. /* The format for storing a key field in MySQL is the following:
  2790. 1. If the column can be NULL, then in the first byte we put 1 if the
  2791. field value is NULL, 0 otherwise.
  2792. 2. If the column is of a BLOB type (it must be a column prefix field
  2793. in this case), then we put the length of the data in the field to the
  2794. next 2 bytes, in the little-endian format. If the field is SQL NULL,
  2795. then these 2 bytes are set to 0. Note that the length of data in the
  2796. field is <= column prefix length.
  2797. 3. In a column prefix field, prefix_len next bytes are reserved for
  2798. data. In a normal field the max field length next bytes are reserved
  2799. for data. For a VARCHAR(n) the max field length is n. If the stored
  2800. value is the SQL NULL then these data bytes are set to 0.
  2801. 4. We always use a 2 byte length for a true >= 5.0.3 VARCHAR. Note that
  2802. in the MySQL row format, the length is stored in 1 or 2 bytes,
  2803. depending on the maximum allowed length. But in the MySQL key value
  2804. format, the length always takes 2 bytes.
  2805. We have to zero-fill the buffer so that MySQL is able to use a
  2806. simple memcmp to compare two key values to determine if they are
  2807. equal. MySQL does this to compare contents of two 'ref' values. */
  2808. bzero(buff, buff_len);
  2809. for (; key_part != end; key_part++) {
  2810. is_null = FALSE;
  2811. if (key_part->null_bit) {
  2812. if (record[key_part->null_offset]
  2813. & key_part->null_bit) {
  2814. *buff = 1;
  2815. is_null = TRUE;
  2816. } else {
  2817. *buff = 0;
  2818. }
  2819. buff++;
  2820. }
  2821. field = key_part->field;
  2822. mysql_type = field->type();
  2823. if (mysql_type == MYSQL_TYPE_VARCHAR) {
  2824. /* >= 5.0.3 true VARCHAR */
  2825. ulint lenlen;
  2826. ulint len;
  2827. const byte* data;
  2828. ulint key_len;
  2829. ulint true_len;
  2830. CHARSET_INFO* cs;
  2831. int error=0;
  2832. key_len = key_part->length;
  2833. if (is_null) {
  2834. buff += key_len + 2;
  2835. continue;
  2836. }
  2837. cs = field->charset();
  2838. lenlen = (ulint)
  2839. (((Field_varstring*)field)->length_bytes);
  2840. data = row_mysql_read_true_varchar(&len,
  2841. (byte*) (record
  2842. + (ulint)get_field_offset(table, field)),
  2843. lenlen);
  2844. true_len = len;
  2845. /* For multi byte character sets we need to calculate
  2846. the true length of the key */
  2847. if (len > 0 && cs->mbmaxlen > 1) {
  2848. true_len = (ulint) cs->cset->well_formed_len(cs,
  2849. (const char *) data,
  2850. (const char *) data + len,
  2851. (uint) (key_len /
  2852. cs->mbmaxlen),
  2853. &error);
  2854. }
  2855. /* In a column prefix index, we may need to truncate
  2856. the stored value: */
  2857. if (true_len > key_len) {
  2858. true_len = key_len;
  2859. }
  2860. /* The length in a key value is always stored in 2
  2861. bytes */
  2862. row_mysql_store_true_var_len((byte*)buff, true_len, 2);
  2863. buff += 2;
  2864. memcpy(buff, data, true_len);
  2865. /* Note that we always reserve the maximum possible
  2866. length of the true VARCHAR in the key value, though
  2867. only len first bytes after the 2 length bytes contain
  2868. actual data. The rest of the space was reset to zero
  2869. in the bzero() call above. */
  2870. buff += key_len;
  2871. } else if (mysql_type == MYSQL_TYPE_TINY_BLOB
  2872. || mysql_type == MYSQL_TYPE_MEDIUM_BLOB
  2873. || mysql_type == MYSQL_TYPE_BLOB
  2874. || mysql_type == MYSQL_TYPE_LONG_BLOB) {
  2875. CHARSET_INFO* cs;
  2876. ulint key_len;
  2877. ulint true_len;
  2878. int error=0;
  2879. ulint blob_len;
  2880. const byte* blob_data;
  2881. ut_a(key_part->key_part_flag & HA_PART_KEY_SEG);
  2882. key_len = key_part->length;
  2883. if (is_null) {
  2884. buff += key_len + 2;
  2885. continue;
  2886. }
  2887. cs = field->charset();
  2888. blob_data = row_mysql_read_blob_ref(&blob_len,
  2889. (byte*) (record
  2890. + (ulint)get_field_offset(table, field)),
  2891. (ulint) field->pack_length());
  2892. true_len = blob_len;
  2893. ut_a(get_field_offset(table, field)
  2894. == key_part->offset);
  2895. /* For multi byte character sets we need to calculate
  2896. the true length of the key */
  2897. if (blob_len > 0 && cs->mbmaxlen > 1) {
  2898. true_len = (ulint) cs->cset->well_formed_len(cs,
  2899. (const char *) blob_data,
  2900. (const char *) blob_data
  2901. + blob_len,
  2902. (uint) (key_len /
  2903. cs->mbmaxlen),
  2904. &error);
  2905. }
  2906. /* All indexes on BLOB and TEXT are column prefix
  2907. indexes, and we may need to truncate the data to be
  2908. stored in the key value: */
  2909. if (true_len > key_len) {
  2910. true_len = key_len;
  2911. }
  2912. /* MySQL reserves 2 bytes for the length and the
  2913. storage of the number is little-endian */
  2914. innobase_write_to_2_little_endian(
  2915. (byte*)buff, true_len);
  2916. buff += 2;
  2917. memcpy(buff, blob_data, true_len);
  2918. /* Note that we always reserve the maximum possible
  2919. length of the BLOB prefix in the key value. */
  2920. buff += key_len;
  2921. } else {
  2922. /* Here we handle all other data types except the
  2923. true VARCHAR, BLOB and TEXT. Note that the column
  2924. value we store may be also in a column prefix
  2925. index. */
  2926. CHARSET_INFO* cs;
  2927. ulint true_len;
  2928. ulint key_len;
  2929. const uchar* src_start;
  2930. int error=0;
  2931. enum_field_types real_type;
  2932. key_len = key_part->length;
  2933. if (is_null) {
  2934. buff += key_len;
  2935. continue;
  2936. }
  2937. src_start = record + key_part->offset;
  2938. real_type = field->real_type();
  2939. true_len = key_len;
  2940. /* Character set for the field is defined only
  2941. to fields whose type is string and real field
  2942. type is not enum or set. For these fields check
  2943. if character set is multi byte. */
  2944. if (real_type != MYSQL_TYPE_ENUM
  2945. && real_type != MYSQL_TYPE_SET
  2946. && ( mysql_type == MYSQL_TYPE_VAR_STRING
  2947. || mysql_type == MYSQL_TYPE_STRING)) {
  2948. cs = field->charset();
  2949. /* For multi byte character sets we need to
  2950. calculate the true length of the key */
  2951. if (key_len > 0 && cs->mbmaxlen > 1) {
  2952. true_len = (ulint)
  2953. cs->cset->well_formed_len(cs,
  2954. (const char *)src_start,
  2955. (const char *)src_start
  2956. + key_len,
  2957. (uint) (key_len /
  2958. cs->mbmaxlen),
  2959. &error);
  2960. }
  2961. }
  2962. memcpy(buff, src_start, true_len);
  2963. buff += true_len;
  2964. /* Pad the unused space with spaces. Note that no
  2965. padding is ever needed for UCS-2 because in MySQL,
  2966. all UCS2 characters are 2 bytes, as MySQL does not
  2967. support surrogate pairs, which are needed to represent
  2968. characters in the range U+10000 to U+10FFFF. */
  2969. if (true_len < key_len) {
  2970. ulint pad_len = key_len - true_len;
  2971. memset(buff, ' ', pad_len);
  2972. buff += pad_len;
  2973. }
  2974. }
  2975. }
  2976. ut_a(buff <= buff_start + buff_len);
  2977. DBUG_RETURN((uint)(buff - buff_start));
  2978. }
  2979. /******************************************************************
  2980. Builds a 'template' to the prebuilt struct. The template is used in fast
  2981. retrieval of just those column values MySQL needs in its processing. */
  2982. static
  2983. void
  2984. build_template(
  2985. /*===========*/
  2986. row_prebuilt_t* prebuilt, /* in/out: prebuilt struct */
  2987. THD* thd, /* in: current user thread, used
  2988. only if templ_type is
  2989. ROW_MYSQL_REC_FIELDS */
  2990. TABLE* table, /* in: MySQL table */
  2991. uint templ_type) /* in: ROW_MYSQL_WHOLE_ROW or
  2992. ROW_MYSQL_REC_FIELDS */
  2993. {
  2994. dict_index_t* index;
  2995. dict_index_t* clust_index;
  2996. mysql_row_templ_t* templ;
  2997. Field* field;
  2998. ulint n_fields;
  2999. ulint n_requested_fields = 0;
  3000. ibool fetch_all_in_key = FALSE;
  3001. ibool fetch_primary_key_cols = FALSE;
  3002. ulint i;
  3003. /* byte offset of the end of last requested column */
  3004. ulint mysql_prefix_len = 0;
  3005. if (prebuilt->select_lock_type == LOCK_X) {
  3006. /* We always retrieve the whole clustered index record if we
  3007. use exclusive row level locks, for example, if the read is
  3008. done in an UPDATE statement. */
  3009. templ_type = ROW_MYSQL_WHOLE_ROW;
  3010. }
  3011. if (templ_type == ROW_MYSQL_REC_FIELDS) {
  3012. if (prebuilt->hint_need_to_fetch_extra_cols
  3013. == ROW_RETRIEVE_ALL_COLS) {
  3014. /* We know we must at least fetch all columns in the
  3015. key, or all columns in the table */
  3016. if (prebuilt->read_just_key) {
  3017. /* MySQL has instructed us that it is enough
  3018. to fetch the columns in the key; looks like
  3019. MySQL can set this flag also when there is
  3020. only a prefix of the column in the key: in
  3021. that case we retrieve the whole column from
  3022. the clustered index */
  3023. fetch_all_in_key = TRUE;
  3024. } else {
  3025. templ_type = ROW_MYSQL_WHOLE_ROW;
  3026. }
  3027. } else if (prebuilt->hint_need_to_fetch_extra_cols
  3028. == ROW_RETRIEVE_PRIMARY_KEY) {
  3029. /* We must at least fetch all primary key cols. Note
  3030. that if the clustered index was internally generated
  3031. by InnoDB on the row id (no primary key was
  3032. defined), then row_search_for_mysql() will always
  3033. retrieve the row id to a special buffer in the
  3034. prebuilt struct. */
  3035. fetch_primary_key_cols = TRUE;
  3036. }
  3037. }
  3038. clust_index = dict_table_get_first_index(prebuilt->table);
  3039. if (templ_type == ROW_MYSQL_REC_FIELDS) {
  3040. index = prebuilt->index;
  3041. } else {
  3042. index = clust_index;
  3043. }
  3044. if (index == clust_index) {
  3045. prebuilt->need_to_access_clustered = TRUE;
  3046. } else {
  3047. prebuilt->need_to_access_clustered = FALSE;
  3048. /* Below we check column by column if we need to access
  3049. the clustered index */
  3050. }
  3051. n_fields = (ulint)table->s->fields; /* number of columns */
  3052. if (!prebuilt->mysql_template) {
  3053. prebuilt->mysql_template = (mysql_row_templ_t*)
  3054. mem_alloc(n_fields * sizeof(mysql_row_templ_t));
  3055. }
  3056. prebuilt->template_type = templ_type;
  3057. prebuilt->null_bitmap_len = table->s->null_bytes;
  3058. prebuilt->templ_contains_blob = FALSE;
  3059. /* Note that in InnoDB, i is the column number. MySQL calls columns
  3060. 'fields'. */
  3061. for (i = 0; i < n_fields; i++) {
  3062. templ = prebuilt->mysql_template + n_requested_fields;
  3063. field = table->field[i];
  3064. if (UNIV_LIKELY(templ_type == ROW_MYSQL_REC_FIELDS)) {
  3065. /* Decide which columns we should fetch
  3066. and which we can skip. */
  3067. register const ibool index_contains_field =
  3068. dict_index_contains_col_or_prefix(index, i);
  3069. if (!index_contains_field && prebuilt->read_just_key) {
  3070. /* If this is a 'key read', we do not need
  3071. columns that are not in the key */
  3072. goto skip_field;
  3073. }
  3074. if (index_contains_field && fetch_all_in_key) {
  3075. /* This field is needed in the query */
  3076. goto include_field;
  3077. }
  3078. if (bitmap_is_set(table->read_set, i) ||
  3079. bitmap_is_set(table->write_set, i)) {
  3080. /* This field is needed in the query */
  3081. goto include_field;
  3082. }
  3083. if (fetch_primary_key_cols
  3084. && dict_table_col_in_clustered_key(
  3085. index->table, i)) {
  3086. /* This field is needed in the query */
  3087. goto include_field;
  3088. }
  3089. /* This field is not needed in the query, skip it */
  3090. goto skip_field;
  3091. }
  3092. include_field:
  3093. n_requested_fields++;
  3094. templ->col_no = i;
  3095. if (index == clust_index) {
  3096. templ->rec_field_no = dict_col_get_clust_pos(
  3097. &index->table->cols[i], index);
  3098. } else {
  3099. templ->rec_field_no = dict_index_get_nth_col_pos(
  3100. index, i);
  3101. }
  3102. if (templ->rec_field_no == ULINT_UNDEFINED) {
  3103. prebuilt->need_to_access_clustered = TRUE;
  3104. }
  3105. if (field->null_ptr) {
  3106. templ->mysql_null_byte_offset =
  3107. (ulint) ((char*) field->null_ptr
  3108. - (char*) table->record[0]);
  3109. templ->mysql_null_bit_mask = (ulint) field->null_bit;
  3110. } else {
  3111. templ->mysql_null_bit_mask = 0;
  3112. }
  3113. templ->mysql_col_offset = (ulint)
  3114. get_field_offset(table, field);
  3115. templ->mysql_col_len = (ulint) field->pack_length();
  3116. if (mysql_prefix_len < templ->mysql_col_offset
  3117. + templ->mysql_col_len) {
  3118. mysql_prefix_len = templ->mysql_col_offset
  3119. + templ->mysql_col_len;
  3120. }
  3121. templ->type = index->table->cols[i].mtype;
  3122. templ->mysql_type = (ulint)field->type();
  3123. if (templ->mysql_type == DATA_MYSQL_TRUE_VARCHAR) {
  3124. templ->mysql_length_bytes = (ulint)
  3125. (((Field_varstring*)field)->length_bytes);
  3126. }
  3127. templ->charset = dtype_get_charset_coll(
  3128. index->table->cols[i].prtype);
  3129. templ->mbminlen = index->table->cols[i].mbminlen;
  3130. templ->mbmaxlen = index->table->cols[i].mbmaxlen;
  3131. templ->is_unsigned = index->table->cols[i].prtype
  3132. & DATA_UNSIGNED;
  3133. if (templ->type == DATA_BLOB) {
  3134. prebuilt->templ_contains_blob = TRUE;
  3135. }
  3136. skip_field:
  3137. ;
  3138. }
  3139. prebuilt->n_template = n_requested_fields;
  3140. prebuilt->mysql_prefix_len = mysql_prefix_len;
  3141. if (index != clust_index && prebuilt->need_to_access_clustered) {
  3142. /* Change rec_field_no's to correspond to the clustered index
  3143. record */
  3144. for (i = 0; i < n_requested_fields; i++) {
  3145. templ = prebuilt->mysql_template + i;
  3146. templ->rec_field_no = dict_col_get_clust_pos(
  3147. &index->table->cols[templ->col_no],
  3148. clust_index);
  3149. }
  3150. }
  3151. }
  3152. /************************************************************************
  3153. Get the upper limit of the MySQL integral type. */
  3154. UNIV_INTERN
  3155. ulonglong
  3156. ha_innobase::innobase_get_int_col_max_value(
  3157. /*========================================*/
  3158. const Field* field)
  3159. {
  3160. ulonglong max_value = 0;
  3161. switch(field->key_type()) {
  3162. /* TINY */
  3163. case HA_KEYTYPE_BINARY:
  3164. max_value = 0xFFULL;
  3165. break;
  3166. case HA_KEYTYPE_INT8:
  3167. max_value = 0x7FULL;
  3168. break;
  3169. /* SHORT */
  3170. case HA_KEYTYPE_USHORT_INT:
  3171. max_value = 0xFFFFULL;
  3172. break;
  3173. case HA_KEYTYPE_SHORT_INT:
  3174. max_value = 0x7FFFULL;
  3175. break;
  3176. /* MEDIUM */
  3177. case HA_KEYTYPE_UINT24:
  3178. max_value = 0xFFFFFFULL;
  3179. break;
  3180. case HA_KEYTYPE_INT24:
  3181. max_value = 0x7FFFFFULL;
  3182. break;
  3183. /* LONG */
  3184. case HA_KEYTYPE_ULONG_INT:
  3185. max_value = 0xFFFFFFFFULL;
  3186. break;
  3187. case HA_KEYTYPE_LONG_INT:
  3188. max_value = 0x7FFFFFFFULL;
  3189. break;
  3190. /* BIG */
  3191. case HA_KEYTYPE_ULONGLONG:
  3192. max_value = 0xFFFFFFFFFFFFFFFFULL;
  3193. break;
  3194. case HA_KEYTYPE_LONGLONG:
  3195. max_value = 0x7FFFFFFFFFFFFFFFULL;
  3196. break;
  3197. default:
  3198. ut_error;
  3199. }
  3200. return(max_value);
  3201. }
  3202. /************************************************************************
  3203. This special handling is really to overcome the limitations of MySQL's
  3204. binlogging. We need to eliminate the non-determinism that will arise in
  3205. INSERT ... SELECT type of statements, since MySQL binlog only stores the
  3206. min value of the autoinc interval. Once that is fixed we can get rid of
  3207. the special lock handling.*/
  3208. UNIV_INTERN
  3209. ulint
  3210. ha_innobase::innobase_lock_autoinc(void)
  3211. /*====================================*/
  3212. /* out: DB_SUCCESS if all OK else
  3213. error code */
  3214. {
  3215. ulint error = DB_SUCCESS;
  3216. switch (innobase_autoinc_lock_mode) {
  3217. case AUTOINC_NO_LOCKING:
  3218. /* Acquire only the AUTOINC mutex. */
  3219. dict_table_autoinc_lock(prebuilt->table);
  3220. break;
  3221. case AUTOINC_NEW_STYLE_LOCKING:
  3222. /* For simple (single/multi) row INSERTs, we fallback to the
  3223. old style only if another transaction has already acquired
  3224. the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT
  3225. etc. type of statement. */
  3226. if (thd_sql_command(user_thd) == SQLCOM_INSERT
  3227. || thd_sql_command(user_thd) == SQLCOM_REPLACE) {
  3228. dict_table_t* table = prebuilt->table;
  3229. /* Acquire the AUTOINC mutex. */
  3230. dict_table_autoinc_lock(table);
  3231. /* We need to check that another transaction isn't
  3232. already holding the AUTOINC lock on the table. */
  3233. if (table->n_waiting_or_granted_auto_inc_locks) {
  3234. /* Release the mutex to avoid deadlocks. */
  3235. dict_table_autoinc_unlock(table);
  3236. } else {
  3237. break;
  3238. }
  3239. }
  3240. /* Fall through to old style locking. */
  3241. case AUTOINC_OLD_STYLE_LOCKING:
  3242. error = row_lock_table_autoinc_for_mysql(prebuilt);
  3243. if (error == DB_SUCCESS) {
  3244. /* Acquire the AUTOINC mutex. */
  3245. dict_table_autoinc_lock(prebuilt->table);
  3246. }
  3247. break;
  3248. default:
  3249. ut_error;
  3250. }
  3251. return(ulong(error));
  3252. }
  3253. /************************************************************************
  3254. Reset the autoinc value in the table.*/
  3255. UNIV_INTERN
  3256. ulint
  3257. ha_innobase::innobase_reset_autoinc(
  3258. /*================================*/
  3259. /* out: DB_SUCCESS if all went well
  3260. else error code */
  3261. ulonglong autoinc) /* in: value to store */
  3262. {
  3263. ulint error;
  3264. error = innobase_lock_autoinc();
  3265. if (error == DB_SUCCESS) {
  3266. dict_table_autoinc_initialize(prebuilt->table, autoinc);
  3267. dict_table_autoinc_unlock(prebuilt->table);
  3268. }
  3269. return(ulong(error));
  3270. }
  3271. /************************************************************************
  3272. Store the autoinc value in the table. The autoinc value is only set if
  3273. it's greater than the existing autoinc value in the table.*/
  3274. UNIV_INTERN
  3275. ulint
  3276. ha_innobase::innobase_set_max_autoinc(
  3277. /*==================================*/
  3278. /* out: DB_SUCCES if all went well
  3279. else error code */
  3280. ulonglong auto_inc) /* in: value to store */
  3281. {
  3282. ulint error;
  3283. error = innobase_lock_autoinc();
  3284. if (error == DB_SUCCESS) {
  3285. dict_table_autoinc_update_if_greater(prebuilt->table, auto_inc);
  3286. dict_table_autoinc_unlock(prebuilt->table);
  3287. }
  3288. return(ulong(error));
  3289. }
  3290. /************************************************************************
  3291. Stores a row in an InnoDB database, to the table specified in this
  3292. handle. */
  3293. UNIV_INTERN
  3294. int
  3295. ha_innobase::write_row(
  3296. /*===================*/
  3297. /* out: error code */
  3298. uchar* record) /* in: a row in MySQL format */
  3299. {
  3300. int error = 0;
  3301. ibool auto_inc_used= FALSE;
  3302. ulint sql_command;
  3303. trx_t* trx = thd_to_trx(user_thd);
  3304. DBUG_ENTER("ha_innobase::write_row");
  3305. if (prebuilt->trx != trx) {
  3306. sql_print_error("The transaction object for the table handle is at "
  3307. "%p, but for the current thread it is at %p",
  3308. (const void*) prebuilt->trx, (const void*) trx);
  3309. fputs("InnoDB: Dump of 200 bytes around prebuilt: ", stderr);
  3310. ut_print_buf(stderr, ((const byte*)prebuilt) - 100, 200);
  3311. fputs("\n"
  3312. "InnoDB: Dump of 200 bytes around ha_data: ",
  3313. stderr);
  3314. ut_print_buf(stderr, ((const byte*) trx) - 100, 200);
  3315. putc('\n', stderr);
  3316. ut_error;
  3317. }
  3318. ha_statistic_increment(&SSV::ha_write_count);
  3319. if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
  3320. table->timestamp_field->set_time();
  3321. sql_command = thd_sql_command(user_thd);
  3322. if ((sql_command == SQLCOM_ALTER_TABLE
  3323. || sql_command == SQLCOM_OPTIMIZE
  3324. || sql_command == SQLCOM_CREATE_INDEX
  3325. || sql_command == SQLCOM_DROP_INDEX)
  3326. && num_write_row >= 10000) {
  3327. /* ALTER TABLE is COMMITted at every 10000 copied rows.
  3328. The IX table lock for the original table has to be re-issued.
  3329. As this method will be called on a temporary table where the
  3330. contents of the original table is being copied to, it is
  3331. a bit tricky to determine the source table. The cursor
  3332. position in the source table need not be adjusted after the
  3333. intermediate COMMIT, since writes by other transactions are
  3334. being blocked by a MySQL table lock TL_WRITE_ALLOW_READ. */
  3335. dict_table_t* src_table;
  3336. enum lock_mode mode;
  3337. num_write_row = 0;
  3338. /* Commit the transaction. This will release the table
  3339. locks, so they have to be acquired again. */
  3340. /* Altering an InnoDB table */
  3341. /* Get the source table. */
  3342. src_table = lock_get_src_table(
  3343. prebuilt->trx, prebuilt->table, &mode);
  3344. if (!src_table) {
  3345. no_commit:
  3346. /* Unknown situation: do not commit */
  3347. /*
  3348. ut_print_timestamp(stderr);
  3349. fprintf(stderr,
  3350. " InnoDB: ALTER TABLE is holding lock"
  3351. " on %lu tables!\n",
  3352. prebuilt->trx->mysql_n_tables_locked);
  3353. */
  3354. ;
  3355. } else if (src_table == prebuilt->table) {
  3356. /* Source table is not in InnoDB format:
  3357. no need to re-acquire locks on it. */
  3358. /* Altering to InnoDB format */
  3359. innobase_commit(ht, user_thd, 1);
  3360. /* Note that this transaction is still active. */
  3361. prebuilt->trx->active_trans = 1;
  3362. /* We will need an IX lock on the destination table. */
  3363. prebuilt->sql_stat_start = TRUE;
  3364. } else {
  3365. /* Ensure that there are no other table locks than
  3366. LOCK_IX and LOCK_AUTO_INC on the destination table. */
  3367. if (!lock_is_table_exclusive(prebuilt->table,
  3368. prebuilt->trx)) {
  3369. goto no_commit;
  3370. }
  3371. /* Commit the transaction. This will release the table
  3372. locks, so they have to be acquired again. */
  3373. innobase_commit(ht, user_thd, 1);
  3374. /* Note that this transaction is still active. */
  3375. prebuilt->trx->active_trans = 1;
  3376. /* Re-acquire the table lock on the source table. */
  3377. row_lock_table_for_mysql(prebuilt, src_table, mode);
  3378. /* We will need an IX lock on the destination table. */
  3379. prebuilt->sql_stat_start = TRUE;
  3380. }
  3381. }
  3382. num_write_row++;
  3383. /* This is the case where the table has an auto-increment column */
  3384. if (table->next_number_field && record == table->record[0]) {
  3385. /* Reset the error code before calling
  3386. innobase_get_auto_increment(). */
  3387. prebuilt->autoinc_error = DB_SUCCESS;
  3388. if ((error = update_auto_increment())) {
  3389. /* We don't want to mask autoinc overflow errors. */
  3390. if (prebuilt->autoinc_error != DB_SUCCESS) {
  3391. error = prebuilt->autoinc_error;
  3392. goto report_error;
  3393. }
  3394. /* MySQL errors are passed straight back. */
  3395. goto func_exit;
  3396. }
  3397. auto_inc_used = TRUE;
  3398. }
  3399. if (prebuilt->mysql_template == NULL
  3400. || prebuilt->template_type != ROW_MYSQL_WHOLE_ROW) {
  3401. /* Build the template used in converting quickly between
  3402. the two database formats */
  3403. build_template(prebuilt, NULL, table, ROW_MYSQL_WHOLE_ROW);
  3404. }
  3405. innodb_srv_conc_enter_innodb(prebuilt->trx);
  3406. error = row_insert_for_mysql((byte*) record, prebuilt);
  3407. /* Handle duplicate key errors */
  3408. if (auto_inc_used) {
  3409. ulint err;
  3410. ulonglong auto_inc;
  3411. ulonglong col_max_value;
  3412. /* Note the number of rows processed for this statement, used
  3413. by get_auto_increment() to determine the number of AUTO-INC
  3414. values to reserve. This is only useful for a mult-value INSERT
  3415. and is a statement level counter.*/
  3416. if (trx->n_autoinc_rows > 0) {
  3417. --trx->n_autoinc_rows;
  3418. }
  3419. /* We need the upper limit of the col type to check for
  3420. whether we update the table autoinc counter or not. */
  3421. col_max_value = innobase_get_int_col_max_value(
  3422. table->next_number_field);
  3423. /* Get the value that MySQL attempted to store in the table.*/
  3424. auto_inc = table->next_number_field->val_int();
  3425. switch (error) {
  3426. case DB_DUPLICATE_KEY:
  3427. /* A REPLACE command and LOAD DATA INFILE REPLACE
  3428. handle a duplicate key error themselves, but we
  3429. must update the autoinc counter if we are performing
  3430. those statements. */
  3431. switch (sql_command) {
  3432. case SQLCOM_LOAD:
  3433. if ((trx->duplicates
  3434. & (TRX_DUP_IGNORE | TRX_DUP_REPLACE))) {
  3435. goto set_max_autoinc;
  3436. }
  3437. break;
  3438. case SQLCOM_REPLACE:
  3439. case SQLCOM_INSERT_SELECT:
  3440. case SQLCOM_REPLACE_SELECT:
  3441. goto set_max_autoinc;
  3442. default:
  3443. break;
  3444. }
  3445. break;
  3446. case DB_SUCCESS:
  3447. /* If the actual value inserted is greater than
  3448. the upper limit of the interval, then we try and
  3449. update the table upper limit. Note: last_value
  3450. will be 0 if get_auto_increment() was not called.*/
  3451. if (auto_inc <= col_max_value
  3452. && auto_inc > prebuilt->autoinc_last_value) {
  3453. set_max_autoinc:
  3454. ut_a(prebuilt->autoinc_increment > 0);
  3455. ulonglong need;
  3456. ulonglong offset;
  3457. offset = prebuilt->autoinc_offset;
  3458. need = prebuilt->autoinc_increment;
  3459. auto_inc = innobase_next_autoinc(
  3460. auto_inc, need, offset, col_max_value);
  3461. err = innobase_set_max_autoinc(auto_inc);
  3462. if (err != DB_SUCCESS) {
  3463. error = (int) err;
  3464. }
  3465. }
  3466. break;
  3467. }
  3468. }
  3469. innodb_srv_conc_exit_innodb(prebuilt->trx);
  3470. report_error:
  3471. error = convert_error_code_to_mysql(error, prebuilt->table->flags,
  3472. user_thd);
  3473. func_exit:
  3474. innobase_active_small();
  3475. DBUG_RETURN(error);
  3476. }
  3477. /**************************************************************************
  3478. Checks which fields have changed in a row and stores information
  3479. of them to an update vector. */
  3480. static
  3481. int
  3482. calc_row_difference(
  3483. /*================*/
  3484. /* out: error number or 0 */
  3485. upd_t* uvect, /* in/out: update vector */
  3486. uchar* old_row, /* in: old row in MySQL format */
  3487. uchar* new_row, /* in: new row in MySQL format */
  3488. struct st_table* table, /* in: table in MySQL data
  3489. dictionary */
  3490. uchar* upd_buff, /* in: buffer to use */
  3491. ulint buff_len, /* in: buffer length */
  3492. row_prebuilt_t* prebuilt, /* in: InnoDB prebuilt struct */
  3493. THD* thd) /* in: user thread */
  3494. {
  3495. uchar* original_upd_buff = upd_buff;
  3496. Field* field;
  3497. enum_field_types field_mysql_type;
  3498. uint n_fields;
  3499. ulint o_len;
  3500. ulint n_len;
  3501. ulint col_pack_len;
  3502. const byte* new_mysql_row_col;
  3503. const byte* o_ptr;
  3504. const byte* n_ptr;
  3505. byte* buf;
  3506. upd_field_t* ufield;
  3507. ulint col_type;
  3508. ulint n_changed = 0;
  3509. dfield_t dfield;
  3510. dict_index_t* clust_index;
  3511. uint i;
  3512. n_fields = table->s->fields;
  3513. clust_index = dict_table_get_first_index(prebuilt->table);
  3514. /* We use upd_buff to convert changed fields */
  3515. buf = (byte*) upd_buff;
  3516. for (i = 0; i < n_fields; i++) {
  3517. field = table->field[i];
  3518. o_ptr = (const byte*) old_row + get_field_offset(table, field);
  3519. n_ptr = (const byte*) new_row + get_field_offset(table, field);
  3520. /* Use new_mysql_row_col and col_pack_len save the values */
  3521. new_mysql_row_col = n_ptr;
  3522. col_pack_len = field->pack_length();
  3523. o_len = col_pack_len;
  3524. n_len = col_pack_len;
  3525. /* We use o_ptr and n_ptr to dig up the actual data for
  3526. comparison. */
  3527. field_mysql_type = field->type();
  3528. col_type = prebuilt->table->cols[i].mtype;
  3529. switch (col_type) {
  3530. case DATA_BLOB:
  3531. o_ptr = row_mysql_read_blob_ref(&o_len, o_ptr, o_len);
  3532. n_ptr = row_mysql_read_blob_ref(&n_len, n_ptr, n_len);
  3533. break;
  3534. case DATA_VARCHAR:
  3535. case DATA_BINARY:
  3536. case DATA_VARMYSQL:
  3537. if (field_mysql_type == MYSQL_TYPE_VARCHAR) {
  3538. /* This is a >= 5.0.3 type true VARCHAR where
  3539. the real payload data length is stored in
  3540. 1 or 2 bytes */
  3541. o_ptr = row_mysql_read_true_varchar(
  3542. &o_len, o_ptr,
  3543. (ulint)
  3544. (((Field_varstring*)field)->length_bytes));
  3545. n_ptr = row_mysql_read_true_varchar(
  3546. &n_len, n_ptr,
  3547. (ulint)
  3548. (((Field_varstring*)field)->length_bytes));
  3549. }
  3550. break;
  3551. default:
  3552. ;
  3553. }
  3554. if (field->null_ptr) {
  3555. if (field_in_record_is_null(table, field,
  3556. (char*) old_row)) {
  3557. o_len = UNIV_SQL_NULL;
  3558. }
  3559. if (field_in_record_is_null(table, field,
  3560. (char*) new_row)) {
  3561. n_len = UNIV_SQL_NULL;
  3562. }
  3563. }
  3564. if (o_len != n_len || (o_len != UNIV_SQL_NULL &&
  3565. 0 != memcmp(o_ptr, n_ptr, o_len))) {
  3566. /* The field has changed */
  3567. ufield = uvect->fields + n_changed;
  3568. /* Let us use a dummy dfield to make the conversion
  3569. from the MySQL column format to the InnoDB format */
  3570. dict_col_copy_type(prebuilt->table->cols + i,
  3571. dfield_get_type(&dfield));
  3572. if (n_len != UNIV_SQL_NULL) {
  3573. buf = row_mysql_store_col_in_innobase_format(
  3574. &dfield,
  3575. (byte*)buf,
  3576. TRUE,
  3577. new_mysql_row_col,
  3578. col_pack_len,
  3579. dict_table_is_comp(prebuilt->table));
  3580. dfield_copy_data(&ufield->new_val, &dfield);
  3581. } else {
  3582. dfield_set_null(&ufield->new_val);
  3583. }
  3584. ufield->exp = NULL;
  3585. ufield->orig_len = 0;
  3586. ufield->field_no = dict_col_get_clust_pos(
  3587. &prebuilt->table->cols[i], clust_index);
  3588. n_changed++;
  3589. }
  3590. }
  3591. uvect->n_fields = n_changed;
  3592. uvect->info_bits = 0;
  3593. ut_a(buf <= (byte*)original_upd_buff + buff_len);
  3594. return(0);
  3595. }
  3596. /**************************************************************************
  3597. Updates a row given as a parameter to a new value. Note that we are given
  3598. whole rows, not just the fields which are updated: this incurs some
  3599. overhead for CPU when we check which fields are actually updated.
  3600. TODO: currently InnoDB does not prevent the 'Halloween problem':
  3601. in a searched update a single row can get updated several times
  3602. if its index columns are updated! */
  3603. UNIV_INTERN
  3604. int
  3605. ha_innobase::update_row(
  3606. /*====================*/
  3607. /* out: error number or 0 */
  3608. const uchar* old_row, /* in: old row in MySQL format */
  3609. uchar* new_row) /* in: new row in MySQL format */
  3610. {
  3611. upd_t* uvect;
  3612. int error = 0;
  3613. trx_t* trx = thd_to_trx(user_thd);
  3614. DBUG_ENTER("ha_innobase::update_row");
  3615. ut_a(prebuilt->trx == trx);
  3616. ha_statistic_increment(&SSV::ha_update_count);
  3617. if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
  3618. table->timestamp_field->set_time();
  3619. if (prebuilt->upd_node) {
  3620. uvect = prebuilt->upd_node->update;
  3621. } else {
  3622. uvect = row_get_prebuilt_update_vector(prebuilt);
  3623. }
  3624. /* Build an update vector from the modified fields in the rows
  3625. (uses upd_buff of the handle) */
  3626. calc_row_difference(uvect, (uchar*) old_row, new_row, table,
  3627. upd_buff, (ulint)upd_and_key_val_buff_len,
  3628. prebuilt, user_thd);
  3629. /* This is not a delete */
  3630. prebuilt->upd_node->is_delete = FALSE;
  3631. ut_a(prebuilt->template_type == ROW_MYSQL_WHOLE_ROW);
  3632. innodb_srv_conc_enter_innodb(trx);
  3633. error = row_update_for_mysql((byte*) old_row, prebuilt);
  3634. /* We need to do some special AUTOINC handling for the following case:
  3635. INSERT INTO t (c1,c2) VALUES(x,y) ON DUPLICATE KEY UPDATE ...
  3636. We need to use the AUTOINC counter that was actually used by
  3637. MySQL in the UPDATE statement, which can be different from the
  3638. value used in the INSERT statement.*/
  3639. if (error == DB_SUCCESS
  3640. && table->next_number_field
  3641. && new_row == table->record[0]
  3642. && thd_sql_command(user_thd) == SQLCOM_INSERT
  3643. && (trx->duplicates & (TRX_DUP_IGNORE | TRX_DUP_REPLACE))
  3644. == TRX_DUP_IGNORE) {
  3645. ulonglong auto_inc;
  3646. ulonglong col_max_value;
  3647. auto_inc = table->next_number_field->val_int();
  3648. /* We need the upper limit of the col type to check for
  3649. whether we update the table autoinc counter or not. */
  3650. col_max_value = innobase_get_int_col_max_value(
  3651. table->next_number_field);
  3652. if (auto_inc <= col_max_value && auto_inc != 0) {
  3653. ulonglong need;
  3654. ulonglong offset;
  3655. offset = prebuilt->autoinc_offset;
  3656. need = prebuilt->autoinc_increment;
  3657. auto_inc = innobase_next_autoinc(
  3658. auto_inc, need, offset, col_max_value);
  3659. error = innobase_set_max_autoinc(auto_inc);
  3660. }
  3661. }
  3662. innodb_srv_conc_exit_innodb(trx);
  3663. error = convert_error_code_to_mysql(error,
  3664. prebuilt->table->flags, user_thd);
  3665. if (error == 0 /* success */
  3666. && uvect->n_fields == 0 /* no columns were updated */) {
  3667. /* This is the same as success, but instructs
  3668. MySQL that the row is not really updated and it
  3669. should not increase the count of updated rows.
  3670. This is fix for http://bugs.mysql.com/29157 */
  3671. error = HA_ERR_RECORD_IS_THE_SAME;
  3672. }
  3673. /* Tell InnoDB server that there might be work for
  3674. utility threads: */
  3675. innobase_active_small();
  3676. DBUG_RETURN(error);
  3677. }
  3678. /**************************************************************************
  3679. Deletes a row given as the parameter. */
  3680. UNIV_INTERN
  3681. int
  3682. ha_innobase::delete_row(
  3683. /*====================*/
  3684. /* out: error number or 0 */
  3685. const uchar* record) /* in: a row in MySQL format */
  3686. {
  3687. int error = 0;
  3688. trx_t* trx = thd_to_trx(user_thd);
  3689. DBUG_ENTER("ha_innobase::delete_row");
  3690. ut_a(prebuilt->trx == trx);
  3691. ha_statistic_increment(&SSV::ha_delete_count);
  3692. if (!prebuilt->upd_node) {
  3693. row_get_prebuilt_update_vector(prebuilt);
  3694. }
  3695. /* This is a delete */
  3696. prebuilt->upd_node->is_delete = TRUE;
  3697. innodb_srv_conc_enter_innodb(trx);
  3698. error = row_update_for_mysql((byte*) record, prebuilt);
  3699. innodb_srv_conc_exit_innodb(trx);
  3700. error = convert_error_code_to_mysql(
  3701. error, prebuilt->table->flags, user_thd);
  3702. /* Tell the InnoDB server that there might be work for
  3703. utility threads: */
  3704. innobase_active_small();
  3705. DBUG_RETURN(error);
  3706. }
  3707. /**************************************************************************
  3708. Removes a new lock set on a row, if it was not read optimistically. This can
  3709. be called after a row has been read in the processing of an UPDATE or a DELETE
  3710. query, if the option innodb_locks_unsafe_for_binlog is set. */
  3711. UNIV_INTERN
  3712. void
  3713. ha_innobase::unlock_row(void)
  3714. /*=========================*/
  3715. {
  3716. DBUG_ENTER("ha_innobase::unlock_row");
  3717. /* Consistent read does not take any locks, thus there is
  3718. nothing to unlock. */
  3719. if (prebuilt->select_lock_type == LOCK_NONE) {
  3720. DBUG_VOID_RETURN;
  3721. }
  3722. switch (prebuilt->row_read_type) {
  3723. case ROW_READ_WITH_LOCKS:
  3724. if (!srv_locks_unsafe_for_binlog
  3725. || prebuilt->trx->isolation_level == TRX_ISO_READ_COMMITTED) {
  3726. break;
  3727. }
  3728. /* fall through */
  3729. case ROW_READ_TRY_SEMI_CONSISTENT:
  3730. row_unlock_for_mysql(prebuilt, FALSE);
  3731. break;
  3732. case ROW_READ_DID_SEMI_CONSISTENT:
  3733. prebuilt->row_read_type = ROW_READ_TRY_SEMI_CONSISTENT;
  3734. break;
  3735. }
  3736. DBUG_VOID_RETURN;
  3737. }
  3738. /* See handler.h and row0mysql.h for docs on this function. */
  3739. UNIV_INTERN
  3740. bool
  3741. ha_innobase::was_semi_consistent_read(void)
  3742. /*=======================================*/
  3743. {
  3744. return(prebuilt->row_read_type == ROW_READ_DID_SEMI_CONSISTENT);
  3745. }
  3746. /* See handler.h and row0mysql.h for docs on this function. */
  3747. UNIV_INTERN
  3748. void
  3749. ha_innobase::try_semi_consistent_read(bool yes)
  3750. /*===========================================*/
  3751. {
  3752. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  3753. /* Row read type is set to semi consistent read if this was
  3754. requested by the MySQL and either innodb_locks_unsafe_for_binlog
  3755. option is used or this session is using READ COMMITTED isolation
  3756. level. */
  3757. if (yes
  3758. && (srv_locks_unsafe_for_binlog
  3759. || prebuilt->trx->isolation_level == TRX_ISO_READ_COMMITTED)) {
  3760. prebuilt->row_read_type = ROW_READ_TRY_SEMI_CONSISTENT;
  3761. } else {
  3762. prebuilt->row_read_type = ROW_READ_WITH_LOCKS;
  3763. }
  3764. }
  3765. #ifdef ROW_MERGE_IS_INDEX_USABLE
  3766. /**********************************************************************
  3767. Check if an index can be used by the optimizer. */
  3768. UNIV_INTERN
  3769. bool
  3770. ha_innobase::is_index_available(
  3771. /*============================*/
  3772. /* out: true if available else false*/
  3773. uint keynr) /* in: index number to check */
  3774. {
  3775. DBUG_ENTER("ha_innobase::is_index_available");
  3776. if (table && keynr != MAX_KEY && table->s->keys > 0) {
  3777. const dict_index_t* index;
  3778. const KEY* key = table->key_info + keynr;
  3779. ut_ad(user_thd == ha_thd());
  3780. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  3781. index = dict_table_get_index_on_name(
  3782. prebuilt->table, key->name);
  3783. if (!row_merge_is_index_usable(prebuilt->trx, index)) {
  3784. DBUG_RETURN(false);
  3785. }
  3786. }
  3787. DBUG_RETURN(true);
  3788. }
  3789. #endif /* ROW_MERGE_IS_INDEX_USABLE */
  3790. /**********************************************************************
  3791. Initializes a handle to use an index. */
  3792. UNIV_INTERN
  3793. int
  3794. ha_innobase::index_init(
  3795. /*====================*/
  3796. /* out: 0 or error number */
  3797. uint keynr, /* in: key (index) number */
  3798. bool sorted) /* in: 1 if result MUST be sorted according to index */
  3799. {
  3800. DBUG_ENTER("index_init");
  3801. DBUG_RETURN(change_active_index(keynr));
  3802. }
  3803. /**********************************************************************
  3804. Currently does nothing. */
  3805. UNIV_INTERN
  3806. int
  3807. ha_innobase::index_end(void)
  3808. /*========================*/
  3809. {
  3810. int error = 0;
  3811. DBUG_ENTER("index_end");
  3812. active_index=MAX_KEY;
  3813. DBUG_RETURN(error);
  3814. }
  3815. /*************************************************************************
  3816. Converts a search mode flag understood by MySQL to a flag understood
  3817. by InnoDB. */
  3818. inline
  3819. ulint
  3820. convert_search_mode_to_innobase(
  3821. /*============================*/
  3822. enum ha_rkey_function find_flag)
  3823. {
  3824. switch (find_flag) {
  3825. case HA_READ_KEY_EXACT:
  3826. /* this does not require the index to be UNIQUE */
  3827. return(PAGE_CUR_GE);
  3828. case HA_READ_KEY_OR_NEXT:
  3829. return(PAGE_CUR_GE);
  3830. case HA_READ_KEY_OR_PREV:
  3831. return(PAGE_CUR_LE);
  3832. case HA_READ_AFTER_KEY:
  3833. return(PAGE_CUR_G);
  3834. case HA_READ_BEFORE_KEY:
  3835. return(PAGE_CUR_L);
  3836. case HA_READ_PREFIX:
  3837. return(PAGE_CUR_GE);
  3838. case HA_READ_PREFIX_LAST:
  3839. return(PAGE_CUR_LE);
  3840. case HA_READ_PREFIX_LAST_OR_PREV:
  3841. return(PAGE_CUR_LE);
  3842. /* In MySQL-4.0 HA_READ_PREFIX and HA_READ_PREFIX_LAST always
  3843. pass a complete-field prefix of a key value as the search
  3844. tuple. I.e., it is not allowed that the last field would
  3845. just contain n first bytes of the full field value.
  3846. MySQL uses a 'padding' trick to convert LIKE 'abc%'
  3847. type queries so that it can use as a search tuple
  3848. a complete-field-prefix of a key value. Thus, the InnoDB
  3849. search mode PAGE_CUR_LE_OR_EXTENDS is never used.
  3850. TODO: when/if MySQL starts to use also partial-field
  3851. prefixes, we have to deal with stripping of spaces
  3852. and comparison of non-latin1 char type fields in
  3853. innobase_mysql_cmp() to get PAGE_CUR_LE_OR_EXTENDS to
  3854. work correctly. */
  3855. case HA_READ_MBR_CONTAIN:
  3856. case HA_READ_MBR_INTERSECT:
  3857. case HA_READ_MBR_WITHIN:
  3858. case HA_READ_MBR_DISJOINT:
  3859. case HA_READ_MBR_EQUAL:
  3860. my_error(ER_TABLE_CANT_HANDLE_SPKEYS, MYF(0));
  3861. return(PAGE_CUR_UNSUPP);
  3862. /* do not use "default:" in order to produce a gcc warning:
  3863. enumeration value '...' not handled in switch
  3864. (if -Wswitch or -Wall is used) */
  3865. }
  3866. my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "this functionality");
  3867. return(PAGE_CUR_UNSUPP);
  3868. }
  3869. /*
  3870. BACKGROUND INFO: HOW A SELECT SQL QUERY IS EXECUTED
  3871. ---------------------------------------------------
  3872. The following does not cover all the details, but explains how we determine
  3873. the start of a new SQL statement, and what is associated with it.
  3874. For each table in the database the MySQL interpreter may have several
  3875. table handle instances in use, also in a single SQL query. For each table
  3876. handle instance there is an InnoDB 'prebuilt' struct which contains most
  3877. of the InnoDB data associated with this table handle instance.
  3878. A) if the user has not explicitly set any MySQL table level locks:
  3879. 1) MySQL calls ::external_lock to set an 'intention' table level lock on
  3880. the table of the handle instance. There we set
  3881. prebuilt->sql_stat_start = TRUE. The flag sql_stat_start should be set
  3882. true if we are taking this table handle instance to use in a new SQL
  3883. statement issued by the user. We also increment trx->n_mysql_tables_in_use.
  3884. 2) If prebuilt->sql_stat_start == TRUE we 'pre-compile' the MySQL search
  3885. instructions to prebuilt->template of the table handle instance in
  3886. ::index_read. The template is used to save CPU time in large joins.
  3887. 3) In row_search_for_mysql, if prebuilt->sql_stat_start is true, we
  3888. allocate a new consistent read view for the trx if it does not yet have one,
  3889. or in the case of a locking read, set an InnoDB 'intention' table level
  3890. lock on the table.
  3891. 4) We do the SELECT. MySQL may repeatedly call ::index_read for the
  3892. same table handle instance, if it is a join.
  3893. 5) When the SELECT ends, MySQL removes its intention table level locks
  3894. in ::external_lock. When trx->n_mysql_tables_in_use drops to zero,
  3895. (a) we execute a COMMIT there if the autocommit is on,
  3896. (b) we also release possible 'SQL statement level resources' InnoDB may
  3897. have for this SQL statement. The MySQL interpreter does NOT execute
  3898. autocommit for pure read transactions, though it should. That is why the
  3899. table handler in that case has to execute the COMMIT in ::external_lock.
  3900. B) If the user has explicitly set MySQL table level locks, then MySQL
  3901. does NOT call ::external_lock at the start of the statement. To determine
  3902. when we are at the start of a new SQL statement we at the start of
  3903. ::index_read also compare the query id to the latest query id where the
  3904. table handle instance was used. If it has changed, we know we are at the
  3905. start of a new SQL statement. Since the query id can theoretically
  3906. overwrap, we use this test only as a secondary way of determining the
  3907. start of a new SQL statement. */
  3908. /**************************************************************************
  3909. Positions an index cursor to the index specified in the handle. Fetches the
  3910. row if any. */
  3911. UNIV_INTERN
  3912. int
  3913. ha_innobase::index_read(
  3914. /*====================*/
  3915. /* out: 0, HA_ERR_KEY_NOT_FOUND,
  3916. or error number */
  3917. uchar* buf, /* in/out: buffer for the returned
  3918. row */
  3919. const uchar* key_ptr, /* in: key value; if this is NULL
  3920. we position the cursor at the
  3921. start or end of index; this can
  3922. also contain an InnoDB row id, in
  3923. which case key_len is the InnoDB
  3924. row id length; the key value can
  3925. also be a prefix of a full key value,
  3926. and the last column can be a prefix
  3927. of a full column */
  3928. uint key_len,/* in: key value length */
  3929. enum ha_rkey_function find_flag)/* in: search flags from my_base.h */
  3930. {
  3931. ulint mode;
  3932. dict_index_t* index;
  3933. ulint match_mode = 0;
  3934. int error;
  3935. ulint ret;
  3936. DBUG_ENTER("index_read");
  3937. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  3938. ha_statistic_increment(&SSV::ha_read_key_count);
  3939. index = prebuilt->index;
  3940. /* Note that if the index for which the search template is built is not
  3941. necessarily prebuilt->index, but can also be the clustered index */
  3942. if (prebuilt->sql_stat_start) {
  3943. build_template(prebuilt, user_thd, table, ROW_MYSQL_REC_FIELDS);
  3944. }
  3945. if (key_ptr) {
  3946. /* Convert the search key value to InnoDB format into
  3947. prebuilt->search_tuple */
  3948. row_sel_convert_mysql_key_to_innobase(
  3949. prebuilt->search_tuple,
  3950. (byte*) key_val_buff,
  3951. (ulint)upd_and_key_val_buff_len,
  3952. index,
  3953. (byte*) key_ptr,
  3954. (ulint) key_len,
  3955. prebuilt->trx);
  3956. } else {
  3957. /* We position the cursor to the last or the first entry
  3958. in the index */
  3959. dtuple_set_n_fields(prebuilt->search_tuple, 0);
  3960. }
  3961. mode = convert_search_mode_to_innobase(find_flag);
  3962. match_mode = 0;
  3963. if (find_flag == HA_READ_KEY_EXACT) {
  3964. match_mode = ROW_SEL_EXACT;
  3965. } else if (find_flag == HA_READ_PREFIX
  3966. || find_flag == HA_READ_PREFIX_LAST) {
  3967. match_mode = ROW_SEL_EXACT_PREFIX;
  3968. }
  3969. last_match_mode = (uint) match_mode;
  3970. if (mode != PAGE_CUR_UNSUPP) {
  3971. innodb_srv_conc_enter_innodb(prebuilt->trx);
  3972. ret = row_search_for_mysql((byte*) buf, mode, prebuilt,
  3973. match_mode, 0);
  3974. innodb_srv_conc_exit_innodb(prebuilt->trx);
  3975. } else {
  3976. ret = DB_UNSUPPORTED;
  3977. }
  3978. switch (ret) {
  3979. case DB_SUCCESS:
  3980. error = 0;
  3981. table->status = 0;
  3982. break;
  3983. case DB_RECORD_NOT_FOUND:
  3984. error = HA_ERR_KEY_NOT_FOUND;
  3985. table->status = STATUS_NOT_FOUND;
  3986. break;
  3987. case DB_END_OF_INDEX:
  3988. error = HA_ERR_KEY_NOT_FOUND;
  3989. table->status = STATUS_NOT_FOUND;
  3990. break;
  3991. default:
  3992. error = convert_error_code_to_mysql((int) ret,
  3993. prebuilt->table->flags,
  3994. user_thd);
  3995. table->status = STATUS_NOT_FOUND;
  3996. break;
  3997. }
  3998. DBUG_RETURN(error);
  3999. }
  4000. /***********************************************************************
  4001. The following functions works like index_read, but it find the last
  4002. row with the current key value or prefix. */
  4003. UNIV_INTERN
  4004. int
  4005. ha_innobase::index_read_last(
  4006. /*=========================*/
  4007. /* out: 0, HA_ERR_KEY_NOT_FOUND, or an
  4008. error code */
  4009. uchar* buf, /* out: fetched row */
  4010. const uchar* key_ptr,/* in: key value, or a prefix of a full
  4011. key value */
  4012. uint key_len)/* in: length of the key val or prefix
  4013. in bytes */
  4014. {
  4015. return(index_read(buf, key_ptr, key_len, HA_READ_PREFIX_LAST));
  4016. }
  4017. /************************************************************************
  4018. Get the index for a handle. Does not change active index.*/
  4019. UNIV_INTERN
  4020. dict_index_t*
  4021. ha_innobase::innobase_get_index(
  4022. /*============================*/
  4023. /* out: NULL or index instance. */
  4024. uint keynr) /* in: use this index; MAX_KEY means always
  4025. clustered index, even if it was internally
  4026. generated by InnoDB */
  4027. {
  4028. KEY* key = 0;
  4029. dict_index_t* index = 0;
  4030. DBUG_ENTER("innobase_get_index");
  4031. ha_statistic_increment(&SSV::ha_read_key_count);
  4032. ut_ad(user_thd == ha_thd());
  4033. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  4034. if (keynr != MAX_KEY && table->s->keys > 0) {
  4035. key = table->key_info + keynr;
  4036. index = dict_table_get_index_on_name(prebuilt->table,
  4037. key->name);
  4038. } else {
  4039. index = dict_table_get_first_index(prebuilt->table);
  4040. }
  4041. if (!index) {
  4042. sql_print_error(
  4043. "Innodb could not find key n:o %u with name %s "
  4044. "from dict cache for table %s",
  4045. keynr, key ? key->name : "NULL",
  4046. prebuilt->table->name);
  4047. }
  4048. DBUG_RETURN(index);
  4049. }
  4050. /************************************************************************
  4051. Changes the active index of a handle. */
  4052. UNIV_INTERN
  4053. int
  4054. ha_innobase::change_active_index(
  4055. /*=============================*/
  4056. /* out: 0 or error code */
  4057. uint keynr) /* in: use this index; MAX_KEY means always clustered
  4058. index, even if it was internally generated by
  4059. InnoDB */
  4060. {
  4061. DBUG_ENTER("change_active_index");
  4062. ut_ad(user_thd == ha_thd());
  4063. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  4064. active_index = keynr;
  4065. prebuilt->index = innobase_get_index(keynr);
  4066. if (UNIV_UNLIKELY(!prebuilt->index)) {
  4067. sql_print_warning("InnoDB: change_active_index(%u) failed",
  4068. keynr);
  4069. DBUG_RETURN(1);
  4070. }
  4071. ut_a(prebuilt->search_tuple != 0);
  4072. dtuple_set_n_fields(prebuilt->search_tuple, prebuilt->index->n_fields);
  4073. dict_index_copy_types(prebuilt->search_tuple, prebuilt->index,
  4074. prebuilt->index->n_fields);
  4075. /* MySQL changes the active index for a handle also during some
  4076. queries, for example SELECT MAX(a), SUM(a) first retrieves the MAX()
  4077. and then calculates the sum. Previously we played safe and used
  4078. the flag ROW_MYSQL_WHOLE_ROW below, but that caused unnecessary
  4079. copying. Starting from MySQL-4.1 we use a more efficient flag here. */
  4080. build_template(prebuilt, user_thd, table, ROW_MYSQL_REC_FIELDS);
  4081. DBUG_RETURN(0);
  4082. }
  4083. /**************************************************************************
  4084. Positions an index cursor to the index specified in keynr. Fetches the
  4085. row if any. */
  4086. /* ??? This is only used to read whole keys ??? */
  4087. UNIV_INTERN
  4088. int
  4089. ha_innobase::index_read_idx(
  4090. /*========================*/
  4091. /* out: error number or 0 */
  4092. uchar* buf, /* in/out: buffer for the returned
  4093. row */
  4094. uint keynr, /* in: use this index */
  4095. const uchar* key, /* in: key value; if this is NULL
  4096. we position the cursor at the
  4097. start or end of index */
  4098. uint key_len, /* in: key value length */
  4099. enum ha_rkey_function find_flag)/* in: search flags from my_base.h */
  4100. {
  4101. if (change_active_index(keynr)) {
  4102. return(1);
  4103. }
  4104. return(index_read(buf, key, key_len, find_flag));
  4105. }
  4106. /***************************************************************************
  4107. Reads the next or previous row from a cursor, which must have previously been
  4108. positioned using index_read. */
  4109. UNIV_INTERN
  4110. int
  4111. ha_innobase::general_fetch(
  4112. /*=======================*/
  4113. /* out: 0, HA_ERR_END_OF_FILE, or error
  4114. number */
  4115. uchar* buf, /* in/out: buffer for next row in MySQL
  4116. format */
  4117. uint direction, /* in: ROW_SEL_NEXT or ROW_SEL_PREV */
  4118. uint match_mode) /* in: 0, ROW_SEL_EXACT, or
  4119. ROW_SEL_EXACT_PREFIX */
  4120. {
  4121. ulint ret;
  4122. int error = 0;
  4123. DBUG_ENTER("general_fetch");
  4124. ut_a(prebuilt->trx == thd_to_trx(user_thd));
  4125. innodb_srv_conc_enter_innodb(prebuilt->trx);
  4126. ret = row_search_for_mysql(
  4127. (byte*)buf, 0, prebuilt, match_mode, direction);
  4128. innodb_srv_conc_exit_innodb(prebuilt->trx);
  4129. switch (ret) {
  4130. case DB_SUCCESS:
  4131. error = 0;
  4132. table->status = 0;
  4133. break;
  4134. case DB_RECORD_NOT_FOUND:
  4135. error = HA_ERR_END_OF_FILE;
  4136. table->status = STATUS_NOT_FOUND;
  4137. break;
  4138. case DB_END_OF_INDEX:
  4139. error = HA_ERR_END_OF_FILE;
  4140. table->status = STATUS_NOT_FOUND;
  4141. break;
  4142. default:
  4143. error = convert_error_code_to_mysql(
  4144. (int) ret, prebuilt->table->flags, user_thd);
  4145. table->status = STATUS_NOT_FOUND;
  4146. break;
  4147. }
  4148. DBUG_RETURN(error);
  4149. }
  4150. /***************************************************************************
  4151. Reads the next row from a cursor, which must have previously been
  4152. positioned using index_read. */
  4153. UNIV_INTERN
  4154. int
  4155. ha_innobase::index_next(
  4156. /*====================*/
  4157. /* out: 0, HA_ERR_END_OF_FILE, or error
  4158. number */
  4159. uchar* buf) /* in/out: buffer for next row in MySQL
  4160. format */
  4161. {
  4162. ha_statistic_increment(&SSV::ha_read_next_count);
  4163. return(general_fetch(buf, ROW_SEL_NEXT, 0));
  4164. }
  4165. /***********************************************************************
  4166. Reads the next row matching to the key value given as the parameter. */
  4167. UNIV_INTERN
  4168. int
  4169. ha_innobase::index_next_same(
  4170. /*=========================*/
  4171. /* out: 0, HA_ERR_END_OF_FILE, or error
  4172. number */
  4173. uchar* buf, /* in/out: buffer for the row */
  4174. const uchar* key, /* in: key value */
  4175. uint keylen) /* in: key value length */
  4176. {
  4177. ha_statistic_increment(&SSV::ha_read_next_count);
  4178. return(general_fetch(buf, ROW_SEL_NEXT, last_match_mode));
  4179. }
  4180. /***************************************************************************
  4181. Reads the previous row from a cursor, which must have previously been
  4182. positioned using index_read. */
  4183. UNIV_INTERN
  4184. int
  4185. ha_innobase::index_prev(
  4186. /*====================*/
  4187. /* out: 0, HA_ERR_END_OF_FILE, or error number */
  4188. uchar* buf) /* in/out: buffer for previous row in MySQL format */
  4189. {
  4190. ha_statistic_increment(&SSV::ha_read_prev_count);
  4191. return(general_fetch(buf, ROW_SEL_PREV, 0));
  4192. }
  4193. /************************************************************************
  4194. Positions a cursor on the first record in an index and reads the
  4195. corresponding row to buf. */
  4196. UNIV_INTERN
  4197. int
  4198. ha_innobase::index_first(
  4199. /*=====================*/
  4200. /* out: 0, HA_ERR_END_OF_FILE, or error code */
  4201. uchar* buf) /* in/out: buffer for the row */
  4202. {
  4203. int error;
  4204. DBUG_ENTER("index_first");
  4205. ha_statistic_increment(&SSV::ha_read_first_count);
  4206. error = index_read(buf, NULL, 0, HA_READ_AFTER_KEY);
  4207. /* MySQL does not seem to allow this to return HA_ERR_KEY_NOT_FOUND */
  4208. if (error == HA_ERR_KEY_NOT_FOUND) {
  4209. error = HA_ERR_END_OF_FILE;
  4210. }
  4211. DBUG_RETURN(error);
  4212. }
  4213. /************************************************************************
  4214. Positions a cursor on the last record in an index and reads the
  4215. corresponding row to buf. */
  4216. UNIV_INTERN
  4217. int
  4218. ha_innobase::index_last(
  4219. /*====================*/
  4220. /* out: 0, HA_ERR_END_OF_FILE, or error code */
  4221. uchar* buf) /* in/out: buffer for the row */
  4222. {
  4223. int error;
  4224. DBUG_ENTER("index_last");
  4225. ha_statistic_increment(&SSV::ha_read_last_count);
  4226. error = index_read(buf, NULL, 0, HA_READ_BEFORE_KEY);
  4227. /* MySQL does not seem to allow this to return HA_ERR_KEY_NOT_FOUND */
  4228. if (error == HA_ERR_KEY_NOT_FOUND) {
  4229. error = HA_ERR_END_OF_FILE;
  4230. }
  4231. DBUG_RETURN(error);
  4232. }
  4233. /********************************************************************
  4234. Initialize a table scan. */
  4235. UNIV_INTERN
  4236. int
  4237. ha_innobase::rnd_init(
  4238. /*==================*/
  4239. /* out: 0 or error number */
  4240. bool scan) /* in: TRUE if table/index scan FALSE otherwise */
  4241. {
  4242. int err;
  4243. /* Store the active index value so that we can restore the original
  4244. value after a scan */
  4245. if (prebuilt->clust_index_was_generated) {
  4246. err = change_active_index(MAX_KEY);
  4247. } else {
  4248. err = change_active_index(primary_key);
  4249. }
  4250. /* Don't use semi-consistent read in random row reads (by position).
  4251. This means we must disable semi_consistent_read if scan is false */
  4252. if (!scan) {
  4253. try_semi_consistent_read(0);
  4254. }
  4255. start_of_scan = 1;
  4256. return(err);
  4257. }
  4258. /*********************************************************************
  4259. Ends a table scan. */
  4260. UNIV_INTERN
  4261. int
  4262. ha_innobase::rnd_end(void)
  4263. /*======================*/
  4264. /* out: 0 or error number */
  4265. {
  4266. return(index_end());
  4267. }
  4268. /*********************************************************************
  4269. Reads the next row in a table scan (also used to read the FIRST row
  4270. in a table scan). */
  4271. UNIV_INTERN
  4272. int
  4273. ha_innobase::rnd_next(
  4274. /*==================*/
  4275. /* out: 0, HA_ERR_END_OF_FILE, or error number */
  4276. uchar* buf) /* in/out: returns the row in this buffer,
  4277. in MySQL format */
  4278. {
  4279. int error;
  4280. DBUG_ENTER("rnd_next");
  4281. ha_statistic_increment(&SSV::ha_read_rnd_next_count);
  4282. if (start_of_scan) {
  4283. error = index_first(buf);
  4284. if (error == HA_ERR_KEY_NOT_FOUND) {
  4285. error = HA_ERR_END_OF_FILE;
  4286. }
  4287. start_of_scan = 0;
  4288. } else {
  4289. error = general_fetch(buf, ROW_SEL_NEXT, 0);
  4290. }
  4291. DBUG_RETURN(error);
  4292. }
  4293. /**************************************************************************
  4294. Fetches a row from the table based on a row reference. */
  4295. UNIV_INTERN
  4296. int
  4297. ha_innobase::rnd_pos(
  4298. /*=================*/
  4299. /* out: 0, HA_ERR_KEY_NOT_FOUND, or error code */
  4300. uchar* buf, /* in/out: buffer for the row */
  4301. uchar* pos) /* in: primary key value of the row in the
  4302. MySQL format, or the row id if the clustered
  4303. index was internally generated by InnoDB; the
  4304. length of data in pos has to be ref_length */
  4305. {
  4306. int error;
  4307. uint keynr = active_index;
  4308. DBUG_ENTER("rnd_pos");
  4309. DBUG_DUMP("key", pos, ref_length);
  4310. ha_statistic_increment(&SSV::ha_read_rnd_count);
  4311. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  4312. if (prebuilt->clust_index_was_generated) {
  4313. /* No primary key was defined for the table and we
  4314. generated the clustered index from the row id: the
  4315. row reference is the row id, not any key value
  4316. that MySQL knows of */
  4317. error = change_active_index(MAX_KEY);
  4318. } else {
  4319. error = change_active_index(primary_key);
  4320. }
  4321. if (error) {
  4322. DBUG_PRINT("error", ("Got error: %d", error));
  4323. DBUG_RETURN(error);
  4324. }
  4325. /* Note that we assume the length of the row reference is fixed
  4326. for the table, and it is == ref_length */
  4327. error = index_read(buf, pos, ref_length, HA_READ_KEY_EXACT);
  4328. if (error) {
  4329. DBUG_PRINT("error", ("Got error: %d", error));
  4330. }
  4331. change_active_index(keynr);
  4332. DBUG_RETURN(error);
  4333. }
  4334. /*************************************************************************
  4335. Stores a reference to the current row to 'ref' field of the handle. Note
  4336. that in the case where we have generated the clustered index for the
  4337. table, the function parameter is illogical: we MUST ASSUME that 'record'
  4338. is the current 'position' of the handle, because if row ref is actually
  4339. the row id internally generated in InnoDB, then 'record' does not contain
  4340. it. We just guess that the row id must be for the record where the handle
  4341. was positioned the last time. */
  4342. UNIV_INTERN
  4343. void
  4344. ha_innobase::position(
  4345. /*==================*/
  4346. const uchar* record) /* in: row in MySQL format */
  4347. {
  4348. uint len;
  4349. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  4350. if (prebuilt->clust_index_was_generated) {
  4351. /* No primary key was defined for the table and we
  4352. generated the clustered index from row id: the
  4353. row reference will be the row id, not any key value
  4354. that MySQL knows of */
  4355. len = DATA_ROW_ID_LEN;
  4356. memcpy(ref, prebuilt->row_id, len);
  4357. } else {
  4358. len = store_key_val_for_row(primary_key, (char*)ref,
  4359. ref_length, record);
  4360. }
  4361. /* We assume that the 'ref' value len is always fixed for the same
  4362. table. */
  4363. if (len != ref_length) {
  4364. sql_print_error("Stored ref len is %lu, but table ref len is %lu",
  4365. (ulong) len, (ulong) ref_length);
  4366. }
  4367. }
  4368. /* limit innodb monitor access to users with PROCESS privilege.
  4369. See http://bugs.mysql.com/32710 for expl. why we choose PROCESS. */
  4370. #define IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(table_name, thd) \
  4371. (row_is_magic_monitor_table(table_name) \
  4372. && check_global_access(thd, PROCESS_ACL))
  4373. /*********************************************************************
  4374. Creates a table definition to an InnoDB database. */
  4375. static
  4376. int
  4377. create_table_def(
  4378. /*=============*/
  4379. trx_t* trx, /* in: InnoDB transaction handle */
  4380. TABLE* form, /* in: information on table
  4381. columns and indexes */
  4382. const char* table_name, /* in: table name */
  4383. const char* path_of_temp_table,/* in: if this is a table explicitly
  4384. created by the user with the
  4385. TEMPORARY keyword, then this
  4386. parameter is the dir path where the
  4387. table should be placed if we create
  4388. an .ibd file for it (no .ibd extension
  4389. in the path, though); otherwise this
  4390. is NULL */
  4391. ulint flags) /* in: table flags */
  4392. {
  4393. Field* field;
  4394. dict_table_t* table;
  4395. ulint n_cols;
  4396. int error;
  4397. ulint col_type;
  4398. ulint col_len;
  4399. ulint nulls_allowed;
  4400. ulint unsigned_type;
  4401. ulint binary_type;
  4402. ulint long_true_varchar;
  4403. ulint charset_no;
  4404. ulint i;
  4405. DBUG_ENTER("create_table_def");
  4406. DBUG_PRINT("enter", ("table_name: %s", table_name));
  4407. ut_a(trx->mysql_thd != NULL);
  4408. if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(table_name,
  4409. (THD*) trx->mysql_thd)) {
  4410. DBUG_RETURN(HA_ERR_GENERIC);
  4411. }
  4412. n_cols = form->s->fields;
  4413. /* We pass 0 as the space id, and determine at a lower level the space
  4414. id where to store the table */
  4415. table = dict_mem_table_create(table_name, 0, n_cols, flags);
  4416. if (path_of_temp_table) {
  4417. table->dir_path_of_temp_table =
  4418. mem_heap_strdup(table->heap, path_of_temp_table);
  4419. }
  4420. for (i = 0; i < n_cols; i++) {
  4421. field = form->field[i];
  4422. col_type = get_innobase_type_from_mysql_type(&unsigned_type,
  4423. field);
  4424. if (field->null_ptr) {
  4425. nulls_allowed = 0;
  4426. } else {
  4427. nulls_allowed = DATA_NOT_NULL;
  4428. }
  4429. if (field->binary()) {
  4430. binary_type = DATA_BINARY_TYPE;
  4431. } else {
  4432. binary_type = 0;
  4433. }
  4434. charset_no = 0;
  4435. if (dtype_is_string_type(col_type)) {
  4436. charset_no = (ulint)field->charset()->number;
  4437. ut_a(charset_no < 256); /* in data0type.h we assume
  4438. that the number fits in one
  4439. byte */
  4440. }
  4441. ut_a(field->type() < 256); /* we assume in dtype_form_prtype()
  4442. that this fits in one byte */
  4443. col_len = field->pack_length();
  4444. /* The MySQL pack length contains 1 or 2 bytes length field
  4445. for a true VARCHAR. Let us subtract that, so that the InnoDB
  4446. column length in the InnoDB data dictionary is the real
  4447. maximum byte length of the actual data. */
  4448. long_true_varchar = 0;
  4449. if (field->type() == MYSQL_TYPE_VARCHAR) {
  4450. col_len -= ((Field_varstring*)field)->length_bytes;
  4451. if (((Field_varstring*)field)->length_bytes == 2) {
  4452. long_true_varchar = DATA_LONG_TRUE_VARCHAR;
  4453. }
  4454. }
  4455. dict_mem_table_add_col(table, table->heap,
  4456. (char*) field->field_name,
  4457. col_type,
  4458. dtype_form_prtype(
  4459. (ulint)field->type()
  4460. | nulls_allowed | unsigned_type
  4461. | binary_type | long_true_varchar,
  4462. charset_no),
  4463. col_len);
  4464. }
  4465. error = row_create_table_for_mysql(table, trx);
  4466. error = convert_error_code_to_mysql(error, flags, NULL);
  4467. DBUG_RETURN(error);
  4468. }
  4469. /*********************************************************************
  4470. Creates an index in an InnoDB database. */
  4471. static
  4472. int
  4473. create_index(
  4474. /*=========*/
  4475. trx_t* trx, /* in: InnoDB transaction handle */
  4476. TABLE* form, /* in: information on table
  4477. columns and indexes */
  4478. ulint flags, /* in: InnoDB table flags */
  4479. const char* table_name, /* in: table name */
  4480. uint key_num) /* in: index number */
  4481. {
  4482. Field* field;
  4483. dict_index_t* index;
  4484. int error;
  4485. ulint n_fields;
  4486. KEY* key;
  4487. KEY_PART_INFO* key_part;
  4488. ulint ind_type;
  4489. ulint col_type;
  4490. ulint prefix_len;
  4491. ulint is_unsigned;
  4492. ulint i;
  4493. ulint j;
  4494. ulint* field_lengths;
  4495. DBUG_ENTER("create_index");
  4496. key = form->key_info + key_num;
  4497. n_fields = key->key_parts;
  4498. ind_type = 0;
  4499. if (key_num == form->s->primary_key) {
  4500. ind_type = ind_type | DICT_CLUSTERED;
  4501. }
  4502. if (key->flags & HA_NOSAME ) {
  4503. ind_type = ind_type | DICT_UNIQUE;
  4504. }
  4505. /* We pass 0 as the space id, and determine at a lower level the space
  4506. id where to store the table */
  4507. index = dict_mem_index_create(table_name, key->name, 0,
  4508. ind_type, n_fields);
  4509. field_lengths = (ulint*) my_malloc(sizeof(ulint) * n_fields,
  4510. MYF(MY_FAE));
  4511. for (i = 0; i < n_fields; i++) {
  4512. key_part = key->key_part + i;
  4513. /* (The flag HA_PART_KEY_SEG denotes in MySQL a column prefix
  4514. field in an index: we only store a specified number of first
  4515. bytes of the column to the index field.) The flag does not
  4516. seem to be properly set by MySQL. Let us fall back on testing
  4517. the length of the key part versus the column. */
  4518. field = NULL;
  4519. for (j = 0; j < form->s->fields; j++) {
  4520. field = form->field[j];
  4521. if (0 == innobase_strcasecmp(
  4522. field->field_name,
  4523. key_part->field->field_name)) {
  4524. /* Found the corresponding column */
  4525. break;
  4526. }
  4527. }
  4528. ut_a(j < form->s->fields);
  4529. col_type = get_innobase_type_from_mysql_type(
  4530. &is_unsigned, key_part->field);
  4531. if (DATA_BLOB == col_type
  4532. || (key_part->length < field->pack_length()
  4533. && field->type() != MYSQL_TYPE_VARCHAR)
  4534. || (field->type() == MYSQL_TYPE_VARCHAR
  4535. && key_part->length < field->pack_length()
  4536. - ((Field_varstring*)field)->length_bytes)) {
  4537. prefix_len = key_part->length;
  4538. if (col_type == DATA_INT
  4539. || col_type == DATA_FLOAT
  4540. || col_type == DATA_DOUBLE
  4541. || col_type == DATA_DECIMAL) {
  4542. sql_print_error(
  4543. "MySQL is trying to create a column "
  4544. "prefix index field, on an "
  4545. "inappropriate data type. Table "
  4546. "name %s, column name %s.",
  4547. table_name,
  4548. key_part->field->field_name);
  4549. prefix_len = 0;
  4550. }
  4551. } else {
  4552. prefix_len = 0;
  4553. }
  4554. field_lengths[i] = key_part->length;
  4555. dict_mem_index_add_field(index,
  4556. (char*) key_part->field->field_name, prefix_len);
  4557. }
  4558. /* Even though we've defined max_supported_key_part_length, we
  4559. still do our own checking using field_lengths to be absolutely
  4560. sure we don't create too long indexes. */
  4561. error = row_create_index_for_mysql(index, trx, field_lengths);
  4562. error = convert_error_code_to_mysql(error, flags, NULL);
  4563. my_free(field_lengths, MYF(0));
  4564. DBUG_RETURN(error);
  4565. }
  4566. /*********************************************************************
  4567. Creates an index to an InnoDB table when the user has defined no
  4568. primary index. */
  4569. static
  4570. int
  4571. create_clustered_index_when_no_primary(
  4572. /*===================================*/
  4573. trx_t* trx, /* in: InnoDB transaction handle */
  4574. ulint flags, /* in: InnoDB table flags */
  4575. const char* table_name) /* in: table name */
  4576. {
  4577. dict_index_t* index;
  4578. int error;
  4579. /* We pass 0 as the space id, and determine at a lower level the space
  4580. id where to store the table */
  4581. index = dict_mem_index_create(table_name, "GEN_CLUST_INDEX",
  4582. 0, DICT_CLUSTERED, 0);
  4583. error = row_create_index_for_mysql(index, trx, NULL);
  4584. error = convert_error_code_to_mysql(error, flags, NULL);
  4585. return(error);
  4586. }
  4587. /*********************************************************************
  4588. Validates the create options. We may build on this function
  4589. in future. For now, it checks two specifiers:
  4590. KEY_BLOCK_SIZE and ROW_FORMAT
  4591. If innodb_strict_mode is not set then this function is a no-op */
  4592. static
  4593. ibool
  4594. create_options_are_valid(
  4595. /*=====================*/
  4596. /* out: TRUE if valid. */
  4597. THD* thd, /* in: connection thread. */
  4598. TABLE* form, /* in: information on table
  4599. columns and indexes */
  4600. HA_CREATE_INFO* create_info) /* in: create info. */
  4601. {
  4602. ibool kbs_specified = FALSE;
  4603. ibool ret = TRUE;
  4604. ut_ad(thd != NULL);
  4605. /* If innodb_strict_mode is not set don't do any validation. */
  4606. if (!(THDVAR(thd, strict_mode))) {
  4607. return(TRUE);
  4608. }
  4609. ut_ad(form != NULL);
  4610. ut_ad(create_info != NULL);
  4611. /* First check if KEY_BLOCK_SIZE was specified. */
  4612. if (create_info->key_block_size
  4613. || (create_info->used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE)) {
  4614. kbs_specified = TRUE;
  4615. switch (create_info->key_block_size) {
  4616. case 1:
  4617. case 2:
  4618. case 4:
  4619. case 8:
  4620. case 16:
  4621. /* Valid value. */
  4622. break;
  4623. default:
  4624. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
  4625. ER_ILLEGAL_HA_CREATE_OPTION,
  4626. "InnoDB: invalid"
  4627. " KEY_BLOCK_SIZE = %lu."
  4628. " Valid values are"
  4629. " [1, 2, 4, 8, 16]",
  4630. create_info->key_block_size);
  4631. ret = FALSE;
  4632. }
  4633. }
  4634. /* If KEY_BLOCK_SIZE was specified, check for its
  4635. dependencies. */
  4636. if (kbs_specified && !srv_file_per_table) {
  4637. push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
  4638. ER_ILLEGAL_HA_CREATE_OPTION,
  4639. "InnoDB: KEY_BLOCK_SIZE"
  4640. " requires innodb_file_per_table.");
  4641. ret = FALSE;
  4642. }
  4643. if (kbs_specified && srv_file_format < DICT_TF_FORMAT_ZIP) {
  4644. push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
  4645. ER_ILLEGAL_HA_CREATE_OPTION,
  4646. "InnoDB: KEY_BLOCK_SIZE"
  4647. " requires innodb_file_format >"
  4648. " Antelope.");
  4649. ret = FALSE;
  4650. }
  4651. /* Now check for ROW_FORMAT specifier. */
  4652. if (create_info->used_fields & HA_CREATE_USED_ROW_FORMAT) {
  4653. switch (form->s->row_type) {
  4654. const char* row_format_name;
  4655. case ROW_TYPE_COMPRESSED:
  4656. case ROW_TYPE_DYNAMIC:
  4657. row_format_name
  4658. = form->s->row_type == ROW_TYPE_COMPRESSED
  4659. ? "COMPRESSED"
  4660. : "DYNAMIC";
  4661. /* These two ROW_FORMATs require
  4662. srv_file_per_table and srv_file_format */
  4663. if (!srv_file_per_table) {
  4664. push_warning_printf(
  4665. thd,
  4666. MYSQL_ERROR::WARN_LEVEL_ERROR,
  4667. ER_ILLEGAL_HA_CREATE_OPTION,
  4668. "InnoDB: ROW_FORMAT=%s"
  4669. " requires innodb_file_per_table.",
  4670. row_format_name);
  4671. ret = FALSE;
  4672. }
  4673. if (srv_file_format < DICT_TF_FORMAT_ZIP) {
  4674. push_warning_printf(
  4675. thd,
  4676. MYSQL_ERROR::WARN_LEVEL_ERROR,
  4677. ER_ILLEGAL_HA_CREATE_OPTION,
  4678. "InnoDB: ROW_FORMAT=%s"
  4679. " requires innodb_file_format >"
  4680. " Antelope.",
  4681. row_format_name);
  4682. ret = FALSE;
  4683. }
  4684. /* Cannot specify KEY_BLOCK_SIZE with
  4685. ROW_FORMAT = DYNAMIC.
  4686. However, we do allow COMPRESSED to be
  4687. specified with KEY_BLOCK_SIZE. */
  4688. if (kbs_specified
  4689. && form->s->row_type == ROW_TYPE_DYNAMIC) {
  4690. push_warning_printf(
  4691. thd,
  4692. MYSQL_ERROR::WARN_LEVEL_ERROR,
  4693. ER_ILLEGAL_HA_CREATE_OPTION,
  4694. "InnoDB: cannot specify"
  4695. " ROW_FORMAT = DYNAMIC with"
  4696. " KEY_BLOCK_SIZE.");
  4697. ret = FALSE;
  4698. }
  4699. break;
  4700. case ROW_TYPE_REDUNDANT:
  4701. case ROW_TYPE_COMPACT:
  4702. case ROW_TYPE_DEFAULT:
  4703. /* Default is COMPACT. */
  4704. row_format_name
  4705. = form->s->row_type == ROW_TYPE_REDUNDANT
  4706. ? "REDUNDANT"
  4707. : "COMPACT";
  4708. /* Cannot specify KEY_BLOCK_SIZE with these
  4709. format specifiers. */
  4710. if (kbs_specified) {
  4711. push_warning_printf(
  4712. thd,
  4713. MYSQL_ERROR::WARN_LEVEL_ERROR,
  4714. ER_ILLEGAL_HA_CREATE_OPTION,
  4715. "InnoDB: cannot specify"
  4716. " ROW_FORMAT = %s with"
  4717. " KEY_BLOCK_SIZE.",
  4718. row_format_name);
  4719. ret = FALSE;
  4720. }
  4721. break;
  4722. default:
  4723. push_warning(thd,
  4724. MYSQL_ERROR::WARN_LEVEL_ERROR,
  4725. ER_ILLEGAL_HA_CREATE_OPTION,
  4726. "InnoDB: invalid ROW_FORMAT specifier.");
  4727. ret = FALSE;
  4728. }
  4729. }
  4730. return(ret);
  4731. }
  4732. /*********************************************************************
  4733. Update create_info. Used in SHOW CREATE TABLE et al. */
  4734. UNIV_INTERN
  4735. void
  4736. ha_innobase::update_create_info(
  4737. /*============================*/
  4738. HA_CREATE_INFO* create_info) /* in/out: create info */
  4739. {
  4740. if (!(create_info->used_fields & HA_CREATE_USED_AUTO)) {
  4741. ha_innobase::info(HA_STATUS_AUTO);
  4742. create_info->auto_increment_value = stats.auto_increment_value;
  4743. }
  4744. }
  4745. /*********************************************************************
  4746. Creates a new table to an InnoDB database. */
  4747. UNIV_INTERN
  4748. int
  4749. ha_innobase::create(
  4750. /*================*/
  4751. /* out: error number */
  4752. const char* name, /* in: table name */
  4753. TABLE* form, /* in: information on table
  4754. columns and indexes */
  4755. HA_CREATE_INFO* create_info) /* in: more information of the
  4756. created table, contains also the
  4757. create statement string */
  4758. {
  4759. int error;
  4760. dict_table_t* innobase_table;
  4761. trx_t* parent_trx;
  4762. trx_t* trx;
  4763. int primary_key_no;
  4764. uint i;
  4765. char name2[FN_REFLEN];
  4766. char norm_name[FN_REFLEN];
  4767. THD* thd = ha_thd();
  4768. ib_int64_t auto_inc_value;
  4769. ulint flags;
  4770. /* Cache the value of innodb_file_format, in case it is
  4771. modified by another thread while the table is being created. */
  4772. const ulint file_format = srv_file_format;
  4773. DBUG_ENTER("ha_innobase::create");
  4774. DBUG_ASSERT(thd != NULL);
  4775. DBUG_ASSERT(create_info != NULL);
  4776. #ifdef __WIN__
  4777. /* Names passed in from server are in two formats:
  4778. 1. <database_name>/<table_name>: for normal table creation
  4779. 2. full path: for temp table creation, or sym link
  4780. When srv_file_per_table is on, check for full path pattern, i.e.
  4781. X:\dir\..., X is a driver letter, or
  4782. \\dir1\dir2\..., UNC path
  4783. returns error if it is in full path format, but not creating a temp.
  4784. table. Currently InnoDB does not support symbolic link on Windows. */
  4785. if (srv_file_per_table
  4786. && (!create_info->options & HA_LEX_CREATE_TMP_TABLE)) {
  4787. if ((name[1] == ':')
  4788. || (name[0] == '\\' && name[1] == '\\')) {
  4789. sql_print_error("Cannot create table %s\n", name);
  4790. DBUG_RETURN(HA_ERR_GENERIC);
  4791. }
  4792. }
  4793. #endif
  4794. if (form->s->fields > 1000) {
  4795. /* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
  4796. but we play safe here */
  4797. DBUG_RETURN(HA_ERR_TO_BIG_ROW);
  4798. }
  4799. /* Get the transaction associated with the current thd, or create one
  4800. if not yet created */
  4801. parent_trx = check_trx_exists(thd);
  4802. /* In case MySQL calls this in the middle of a SELECT query, release
  4803. possible adaptive hash latch to avoid deadlocks of threads */
  4804. trx_search_latch_release_if_reserved(parent_trx);
  4805. trx = trx_allocate_for_mysql();
  4806. trx->mysql_thd = thd;
  4807. trx->mysql_query_str = thd_query(thd);
  4808. if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
  4809. trx->check_foreigns = FALSE;
  4810. }
  4811. if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
  4812. trx->check_unique_secondary = FALSE;
  4813. }
  4814. if (lower_case_table_names) {
  4815. srv_lower_case_table_names = TRUE;
  4816. } else {
  4817. srv_lower_case_table_names = FALSE;
  4818. }
  4819. strcpy(name2, name);
  4820. normalize_table_name(norm_name, name2);
  4821. /* Latch the InnoDB data dictionary exclusively so that no deadlocks
  4822. or lock waits can happen in it during a table create operation.
  4823. Drop table etc. do this latching in row0mysql.c. */
  4824. row_mysql_lock_data_dictionary(trx);
  4825. /* Create the table definition in InnoDB */
  4826. flags = 0;
  4827. /* Validate create options if innodb_strict_mode is set. */
  4828. if (!create_options_are_valid(thd, form, create_info)) {
  4829. error = ER_ILLEGAL_HA_CREATE_OPTION;
  4830. goto cleanup;
  4831. }
  4832. if (create_info->key_block_size
  4833. || (create_info->used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE)) {
  4834. switch (create_info->key_block_size) {
  4835. case 1:
  4836. flags = 1 << DICT_TF_ZSSIZE_SHIFT
  4837. | DICT_TF_COMPACT
  4838. | DICT_TF_FORMAT_ZIP
  4839. << DICT_TF_FORMAT_SHIFT;
  4840. break;
  4841. case 2:
  4842. flags = 2 << DICT_TF_ZSSIZE_SHIFT
  4843. | DICT_TF_COMPACT
  4844. | DICT_TF_FORMAT_ZIP
  4845. << DICT_TF_FORMAT_SHIFT;
  4846. break;
  4847. case 4:
  4848. flags = 3 << DICT_TF_ZSSIZE_SHIFT
  4849. | DICT_TF_COMPACT
  4850. | DICT_TF_FORMAT_ZIP
  4851. << DICT_TF_FORMAT_SHIFT;
  4852. break;
  4853. case 8:
  4854. flags = 4 << DICT_TF_ZSSIZE_SHIFT
  4855. | DICT_TF_COMPACT
  4856. | DICT_TF_FORMAT_ZIP
  4857. << DICT_TF_FORMAT_SHIFT;
  4858. break;
  4859. case 16:
  4860. flags = 5 << DICT_TF_ZSSIZE_SHIFT
  4861. | DICT_TF_COMPACT
  4862. | DICT_TF_FORMAT_ZIP
  4863. << DICT_TF_FORMAT_SHIFT;
  4864. break;
  4865. #if DICT_TF_ZSSIZE_MAX != 5
  4866. # error "DICT_TF_ZSSIZE_MAX != 5"
  4867. #endif
  4868. }
  4869. if (!srv_file_per_table) {
  4870. push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  4871. ER_ILLEGAL_HA_CREATE_OPTION,
  4872. "InnoDB: KEY_BLOCK_SIZE"
  4873. " requires innodb_file_per_table.");
  4874. flags = 0;
  4875. }
  4876. if (file_format < DICT_TF_FORMAT_ZIP) {
  4877. push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  4878. ER_ILLEGAL_HA_CREATE_OPTION,
  4879. "InnoDB: KEY_BLOCK_SIZE"
  4880. " requires innodb_file_format >"
  4881. " Antelope.");
  4882. flags = 0;
  4883. }
  4884. if (!flags) {
  4885. push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
  4886. ER_ILLEGAL_HA_CREATE_OPTION,
  4887. "InnoDB: ignoring"
  4888. " KEY_BLOCK_SIZE=%lu.",
  4889. create_info->key_block_size);
  4890. }
  4891. }
  4892. if (create_info->used_fields & HA_CREATE_USED_ROW_FORMAT) {
  4893. if (flags) {
  4894. /* KEY_BLOCK_SIZE was specified. */
  4895. if (form->s->row_type != ROW_TYPE_COMPRESSED) {
  4896. /* ROW_FORMAT other than COMPRESSED
  4897. ignores KEY_BLOCK_SIZE. It does not
  4898. make sense to reject conflicting
  4899. KEY_BLOCK_SIZE and ROW_FORMAT, because
  4900. such combinations can be obtained
  4901. with ALTER TABLE anyway. */
  4902. push_warning_printf(
  4903. thd,
  4904. MYSQL_ERROR::WARN_LEVEL_WARN,
  4905. ER_ILLEGAL_HA_CREATE_OPTION,
  4906. "InnoDB: ignoring KEY_BLOCK_SIZE=%lu"
  4907. " unless ROW_FORMAT=COMPRESSED.",
  4908. create_info->key_block_size);
  4909. flags = 0;
  4910. }
  4911. } else {
  4912. /* No KEY_BLOCK_SIZE */
  4913. if (form->s->row_type == ROW_TYPE_COMPRESSED) {
  4914. /* ROW_FORMAT=COMPRESSED without
  4915. KEY_BLOCK_SIZE implies
  4916. KEY_BLOCK_SIZE=8. */
  4917. flags = 4 << DICT_TF_ZSSIZE_SHIFT
  4918. | DICT_TF_COMPACT
  4919. | DICT_TF_FORMAT_ZIP
  4920. << DICT_TF_FORMAT_SHIFT;
  4921. }
  4922. }
  4923. switch (form->s->row_type) {
  4924. const char* row_format_name;
  4925. case ROW_TYPE_REDUNDANT:
  4926. break;
  4927. case ROW_TYPE_COMPRESSED:
  4928. case ROW_TYPE_DYNAMIC:
  4929. row_format_name
  4930. = form->s->row_type == ROW_TYPE_COMPRESSED
  4931. ? "COMPRESSED"
  4932. : "DYNAMIC";
  4933. if (!srv_file_per_table) {
  4934. push_warning_printf(
  4935. thd,
  4936. MYSQL_ERROR::WARN_LEVEL_WARN,
  4937. ER_ILLEGAL_HA_CREATE_OPTION,
  4938. "InnoDB: ROW_FORMAT=%s"
  4939. " requires innodb_file_per_table.",
  4940. row_format_name);
  4941. } else if (file_format < DICT_TF_FORMAT_ZIP) {
  4942. push_warning_printf(
  4943. thd,
  4944. MYSQL_ERROR::WARN_LEVEL_WARN,
  4945. ER_ILLEGAL_HA_CREATE_OPTION,
  4946. "InnoDB: ROW_FORMAT=%s"
  4947. " requires innodb_file_format >"
  4948. " Antelope.",
  4949. row_format_name);
  4950. } else {
  4951. flags |= DICT_TF_COMPACT
  4952. | (DICT_TF_FORMAT_ZIP
  4953. << DICT_TF_FORMAT_SHIFT);
  4954. break;
  4955. }
  4956. /* fall through */
  4957. case ROW_TYPE_NOT_USED:
  4958. case ROW_TYPE_FIXED:
  4959. default:
  4960. push_warning(thd,
  4961. MYSQL_ERROR::WARN_LEVEL_WARN,
  4962. ER_ILLEGAL_HA_CREATE_OPTION,
  4963. "InnoDB: assuming ROW_FORMAT=COMPACT.");
  4964. case ROW_TYPE_DEFAULT:
  4965. case ROW_TYPE_COMPACT:
  4966. flags = DICT_TF_COMPACT;
  4967. break;
  4968. }
  4969. } else if (!flags) {
  4970. /* No KEY_BLOCK_SIZE or ROW_FORMAT specified:
  4971. use ROW_FORMAT=COMPACT by default. */
  4972. flags = DICT_TF_COMPACT;
  4973. }
  4974. error = create_table_def(trx, form, norm_name,
  4975. create_info->options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL,
  4976. flags);
  4977. if (error) {
  4978. goto cleanup;
  4979. }
  4980. /* Look for a primary key */
  4981. primary_key_no= (form->s->primary_key != MAX_KEY ?
  4982. (int) form->s->primary_key :
  4983. -1);
  4984. /* Our function row_get_mysql_key_number_for_index assumes
  4985. the primary key is always number 0, if it exists */
  4986. DBUG_ASSERT(primary_key_no == -1 || primary_key_no == 0);
  4987. /* Create the keys */
  4988. if (form->s->keys == 0 || primary_key_no == -1) {
  4989. /* Create an index which is used as the clustered index;
  4990. order the rows by their row id which is internally generated
  4991. by InnoDB */
  4992. error = create_clustered_index_when_no_primary(
  4993. trx, flags, norm_name);
  4994. if (error) {
  4995. goto cleanup;
  4996. }
  4997. }
  4998. if (primary_key_no != -1) {
  4999. /* In InnoDB the clustered index must always be created
  5000. first */
  5001. if ((error = create_index(trx, form, flags, norm_name,
  5002. (uint) primary_key_no))) {
  5003. goto cleanup;
  5004. }
  5005. }
  5006. for (i = 0; i < form->s->keys; i++) {
  5007. if (i != (uint) primary_key_no) {
  5008. if ((error = create_index(trx, form, flags, norm_name,
  5009. i))) {
  5010. goto cleanup;
  5011. }
  5012. }
  5013. }
  5014. if (*trx->mysql_query_str) {
  5015. error = row_table_add_foreign_constraints(trx,
  5016. *trx->mysql_query_str, norm_name,
  5017. create_info->options & HA_LEX_CREATE_TMP_TABLE);
  5018. error = convert_error_code_to_mysql(error, flags, NULL);
  5019. if (error) {
  5020. goto cleanup;
  5021. }
  5022. }
  5023. innobase_commit_low(trx);
  5024. row_mysql_unlock_data_dictionary(trx);
  5025. /* Flush the log to reduce probability that the .frm files and
  5026. the InnoDB data dictionary get out-of-sync if the user runs
  5027. with innodb_flush_log_at_trx_commit = 0 */
  5028. log_buffer_flush_to_disk();
  5029. innobase_table = dict_table_get(norm_name, FALSE);
  5030. DBUG_ASSERT(innobase_table != 0);
  5031. if (innobase_table) {
  5032. /* We update the highest file format in the system table
  5033. space, if this table has higher file format setting. */
  5034. trx_sys_file_format_max_upgrade(
  5035. (const char**) &innobase_file_format_check,
  5036. dict_table_get_format(innobase_table));
  5037. }
  5038. /* Note: We can't call update_thd() as prebuilt will not be
  5039. setup at this stage and so we use thd. */
  5040. /* We need to copy the AUTOINC value from the old table if
  5041. this is an ALTER TABLE. */
  5042. if (((create_info->used_fields & HA_CREATE_USED_AUTO)
  5043. || thd_sql_command(thd) == SQLCOM_ALTER_TABLE)
  5044. && create_info->auto_increment_value != 0) {
  5045. /* Query was ALTER TABLE...AUTO_INCREMENT = x; or
  5046. CREATE TABLE ...AUTO_INCREMENT = x; Find out a table
  5047. definition from the dictionary and get the current value
  5048. of the auto increment field. Set a new value to the
  5049. auto increment field if the value is greater than the
  5050. maximum value in the column. */
  5051. auto_inc_value = create_info->auto_increment_value;
  5052. dict_table_autoinc_lock(innobase_table);
  5053. dict_table_autoinc_initialize(innobase_table, auto_inc_value);
  5054. dict_table_autoinc_unlock(innobase_table);
  5055. }
  5056. /* Tell the InnoDB server that there might be work for
  5057. utility threads: */
  5058. srv_active_wake_master_thread();
  5059. trx_free_for_mysql(trx);
  5060. DBUG_RETURN(0);
  5061. cleanup:
  5062. innobase_commit_low(trx);
  5063. row_mysql_unlock_data_dictionary(trx);
  5064. trx_free_for_mysql(trx);
  5065. DBUG_RETURN(error);
  5066. }
  5067. /*********************************************************************
  5068. Discards or imports an InnoDB tablespace. */
  5069. UNIV_INTERN
  5070. int
  5071. ha_innobase::discard_or_import_tablespace(
  5072. /*======================================*/
  5073. /* out: 0 == success, -1 == error */
  5074. my_bool discard) /* in: TRUE if discard, else import */
  5075. {
  5076. dict_table_t* dict_table;
  5077. trx_t* trx;
  5078. int err;
  5079. DBUG_ENTER("ha_innobase::discard_or_import_tablespace");
  5080. ut_a(prebuilt->trx);
  5081. ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
  5082. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  5083. dict_table = prebuilt->table;
  5084. trx = prebuilt->trx;
  5085. if (discard) {
  5086. err = row_discard_tablespace_for_mysql(dict_table->name, trx);
  5087. } else {
  5088. err = row_import_tablespace_for_mysql(dict_table->name, trx);
  5089. }
  5090. err = convert_error_code_to_mysql(err, dict_table->flags, NULL);
  5091. DBUG_RETURN(err);
  5092. }
  5093. /*********************************************************************
  5094. Deletes all rows of an InnoDB table. */
  5095. UNIV_INTERN
  5096. int
  5097. ha_innobase::delete_all_rows(void)
  5098. /*==============================*/
  5099. /* out: error number */
  5100. {
  5101. int error;
  5102. DBUG_ENTER("ha_innobase::delete_all_rows");
  5103. /* Get the transaction associated with the current thd, or create one
  5104. if not yet created, and update prebuilt->trx */
  5105. update_thd(ha_thd());
  5106. if (thd_sql_command(user_thd) != SQLCOM_TRUNCATE) {
  5107. fallback:
  5108. /* We only handle TRUNCATE TABLE t as a special case.
  5109. DELETE FROM t will have to use ha_innobase::delete_row(),
  5110. because DELETE is transactional while TRUNCATE is not. */
  5111. DBUG_RETURN(my_errno=HA_ERR_WRONG_COMMAND);
  5112. }
  5113. /* Truncate the table in InnoDB */
  5114. error = row_truncate_table_for_mysql(prebuilt->table, prebuilt->trx);
  5115. if (error == DB_ERROR) {
  5116. /* Cannot truncate; resort to ha_innobase::delete_row() */
  5117. goto fallback;
  5118. }
  5119. error = convert_error_code_to_mysql(error, prebuilt->table->flags,
  5120. NULL);
  5121. DBUG_RETURN(error);
  5122. }
  5123. /*********************************************************************
  5124. Drops a table from an InnoDB database. Before calling this function,
  5125. MySQL calls innobase_commit to commit the transaction of the current user.
  5126. Then the current user cannot have locks set on the table. Drop table
  5127. operation inside InnoDB will remove all locks any user has on the table
  5128. inside InnoDB. */
  5129. UNIV_INTERN
  5130. int
  5131. ha_innobase::delete_table(
  5132. /*======================*/
  5133. /* out: error number */
  5134. const char* name) /* in: table name */
  5135. {
  5136. ulint name_len;
  5137. int error;
  5138. trx_t* parent_trx;
  5139. trx_t* trx;
  5140. THD *thd = ha_thd();
  5141. char norm_name[1000];
  5142. DBUG_ENTER("ha_innobase::delete_table");
  5143. /* Strangely, MySQL passes the table name without the '.frm'
  5144. extension, in contrast to ::create */
  5145. normalize_table_name(norm_name, name);
  5146. if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(norm_name, thd)) {
  5147. DBUG_RETURN(HA_ERR_GENERIC);
  5148. }
  5149. /* Get the transaction associated with the current thd, or create one
  5150. if not yet created */
  5151. parent_trx = check_trx_exists(thd);
  5152. /* In case MySQL calls this in the middle of a SELECT query, release
  5153. possible adaptive hash latch to avoid deadlocks of threads */
  5154. trx_search_latch_release_if_reserved(parent_trx);
  5155. if (lower_case_table_names) {
  5156. srv_lower_case_table_names = TRUE;
  5157. } else {
  5158. srv_lower_case_table_names = FALSE;
  5159. }
  5160. trx = trx_allocate_for_mysql();
  5161. trx->mysql_thd = thd;
  5162. trx->mysql_query_str = thd_query(thd);
  5163. if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
  5164. trx->check_foreigns = FALSE;
  5165. }
  5166. if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
  5167. trx->check_unique_secondary = FALSE;
  5168. }
  5169. name_len = strlen(name);
  5170. ut_a(name_len < 1000);
  5171. /* Drop the table in InnoDB */
  5172. error = row_drop_table_for_mysql(norm_name, trx,
  5173. thd_sql_command(thd)
  5174. == SQLCOM_DROP_DB);
  5175. /* Flush the log to reduce probability that the .frm files and
  5176. the InnoDB data dictionary get out-of-sync if the user runs
  5177. with innodb_flush_log_at_trx_commit = 0 */
  5178. log_buffer_flush_to_disk();
  5179. /* Tell the InnoDB server that there might be work for
  5180. utility threads: */
  5181. srv_active_wake_master_thread();
  5182. innobase_commit_low(trx);
  5183. trx_free_for_mysql(trx);
  5184. error = convert_error_code_to_mysql(error, 0, NULL);
  5185. DBUG_RETURN(error);
  5186. }
  5187. /*********************************************************************
  5188. Removes all tables in the named database inside InnoDB. */
  5189. static
  5190. void
  5191. innobase_drop_database(
  5192. /*===================*/
  5193. /* out: error number */
  5194. handlerton *hton, /* in: handlerton of Innodb */
  5195. char* path) /* in: database path; inside InnoDB the name
  5196. of the last directory in the path is used as
  5197. the database name: for example, in 'mysql/data/test'
  5198. the database name is 'test' */
  5199. {
  5200. ulint len = 0;
  5201. trx_t* trx;
  5202. char* ptr;
  5203. int error;
  5204. char* namebuf;
  5205. THD* thd = current_thd;
  5206. /* Get the transaction associated with the current thd, or create one
  5207. if not yet created */
  5208. DBUG_ASSERT(hton == innodb_hton_ptr);
  5209. /* In the Windows plugin, thd = current_thd is always NULL */
  5210. if (thd) {
  5211. trx_t* parent_trx = check_trx_exists(thd);
  5212. /* In case MySQL calls this in the middle of a SELECT
  5213. query, release possible adaptive hash latch to avoid
  5214. deadlocks of threads */
  5215. trx_search_latch_release_if_reserved(parent_trx);
  5216. }
  5217. ptr = strend(path) - 2;
  5218. while (ptr >= path && *ptr != '\\' && *ptr != '/') {
  5219. ptr--;
  5220. len++;
  5221. }
  5222. ptr++;
  5223. namebuf = (char*) my_malloc((uint) len + 2, MYF(0));
  5224. memcpy(namebuf, ptr, len);
  5225. namebuf[len] = '/';
  5226. namebuf[len + 1] = '\0';
  5227. #ifdef __WIN__
  5228. innobase_casedn_str(namebuf);
  5229. #endif
  5230. trx = trx_allocate_for_mysql();
  5231. trx->mysql_thd = thd;
  5232. if (thd) {
  5233. trx->mysql_query_str = thd_query(thd);
  5234. if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
  5235. trx->check_foreigns = FALSE;
  5236. }
  5237. } else {
  5238. /* In the Windows plugin, thd = current_thd is always NULL */
  5239. trx->mysql_query_str = NULL;
  5240. }
  5241. error = row_drop_database_for_mysql(namebuf, trx);
  5242. my_free(namebuf, MYF(0));
  5243. /* Flush the log to reduce probability that the .frm files and
  5244. the InnoDB data dictionary get out-of-sync if the user runs
  5245. with innodb_flush_log_at_trx_commit = 0 */
  5246. log_buffer_flush_to_disk();
  5247. /* Tell the InnoDB server that there might be work for
  5248. utility threads: */
  5249. srv_active_wake_master_thread();
  5250. innobase_commit_low(trx);
  5251. trx_free_for_mysql(trx);
  5252. }
  5253. /*************************************************************************
  5254. Renames an InnoDB table. */
  5255. static
  5256. int
  5257. innobase_rename_table(
  5258. /*==================*/
  5259. /* out: 0 or error code */
  5260. trx_t* trx, /* in: transaction */
  5261. const char* from, /* in: old name of the table */
  5262. const char* to, /* in: new name of the table */
  5263. ibool lock_and_commit)
  5264. /* in: TRUE=lock data dictionary and commit */
  5265. {
  5266. int error;
  5267. char* norm_to;
  5268. char* norm_from;
  5269. if (lower_case_table_names) {
  5270. srv_lower_case_table_names = TRUE;
  5271. } else {
  5272. srv_lower_case_table_names = FALSE;
  5273. }
  5274. // Magic number 64 arbitrary
  5275. norm_to = (char*) my_malloc(strlen(to) + 64, MYF(0));
  5276. norm_from = (char*) my_malloc(strlen(from) + 64, MYF(0));
  5277. normalize_table_name(norm_to, to);
  5278. normalize_table_name(norm_from, from);
  5279. /* Serialize data dictionary operations with dictionary mutex:
  5280. no deadlocks can occur then in these operations */
  5281. if (lock_and_commit) {
  5282. row_mysql_lock_data_dictionary(trx);
  5283. }
  5284. error = row_rename_table_for_mysql(
  5285. norm_from, norm_to, trx, lock_and_commit);
  5286. if (error != DB_SUCCESS) {
  5287. FILE* ef = dict_foreign_err_file;
  5288. fputs("InnoDB: Renaming table ", ef);
  5289. ut_print_name(ef, trx, TRUE, norm_from);
  5290. fputs(" to ", ef);
  5291. ut_print_name(ef, trx, TRUE, norm_to);
  5292. fputs(" failed!\n", ef);
  5293. }
  5294. if (lock_and_commit) {
  5295. row_mysql_unlock_data_dictionary(trx);
  5296. /* Flush the log to reduce probability that the .frm
  5297. files and the InnoDB data dictionary get out-of-sync
  5298. if the user runs with innodb_flush_log_at_trx_commit = 0 */
  5299. log_buffer_flush_to_disk();
  5300. }
  5301. my_free(norm_to, MYF(0));
  5302. my_free(norm_from, MYF(0));
  5303. return error;
  5304. }
  5305. /*************************************************************************
  5306. Renames an InnoDB table. */
  5307. UNIV_INTERN
  5308. int
  5309. ha_innobase::rename_table(
  5310. /*======================*/
  5311. /* out: 0 or error code */
  5312. const char* from, /* in: old name of the table */
  5313. const char* to) /* in: new name of the table */
  5314. {
  5315. trx_t* trx;
  5316. int error;
  5317. trx_t* parent_trx;
  5318. THD* thd = ha_thd();
  5319. DBUG_ENTER("ha_innobase::rename_table");
  5320. /* Get the transaction associated with the current thd, or create one
  5321. if not yet created */
  5322. parent_trx = check_trx_exists(thd);
  5323. /* In case MySQL calls this in the middle of a SELECT query, release
  5324. possible adaptive hash latch to avoid deadlocks of threads */
  5325. trx_search_latch_release_if_reserved(parent_trx);
  5326. trx = trx_allocate_for_mysql();
  5327. trx->mysql_thd = thd;
  5328. trx->mysql_query_str = thd_query(thd);
  5329. if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
  5330. trx->check_foreigns = FALSE;
  5331. }
  5332. error = innobase_rename_table(trx, from, to, TRUE);
  5333. /* Tell the InnoDB server that there might be work for
  5334. utility threads: */
  5335. srv_active_wake_master_thread();
  5336. innobase_commit_low(trx);
  5337. trx_free_for_mysql(trx);
  5338. error = convert_error_code_to_mysql(error, 0, NULL);
  5339. DBUG_RETURN(error);
  5340. }
  5341. /*************************************************************************
  5342. Estimates the number of index records in a range. */
  5343. UNIV_INTERN
  5344. ha_rows
  5345. ha_innobase::records_in_range(
  5346. /*==========================*/
  5347. /* out: estimated number of
  5348. rows */
  5349. uint keynr, /* in: index number */
  5350. key_range *min_key, /* in: start key value of the
  5351. range, may also be 0 */
  5352. key_range *max_key) /* in: range end key val, may
  5353. also be 0 */
  5354. {
  5355. KEY* key;
  5356. dict_index_t* index;
  5357. uchar* key_val_buff2 = (uchar*) my_malloc(
  5358. table->s->reclength
  5359. + table->s->max_key_length + 100,
  5360. MYF(MY_FAE));
  5361. ulint buff2_len = table->s->reclength
  5362. + table->s->max_key_length + 100;
  5363. dtuple_t* range_start;
  5364. dtuple_t* range_end;
  5365. ib_int64_t n_rows;
  5366. ulint mode1;
  5367. ulint mode2;
  5368. mem_heap_t* heap;
  5369. DBUG_ENTER("records_in_range");
  5370. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  5371. prebuilt->trx->op_info = (char*)"estimating records in index range";
  5372. /* In case MySQL calls this in the middle of a SELECT query, release
  5373. possible adaptive hash latch to avoid deadlocks of threads */
  5374. trx_search_latch_release_if_reserved(prebuilt->trx);
  5375. active_index = keynr;
  5376. key = table->key_info + active_index;
  5377. index = dict_table_get_index_on_name(prebuilt->table, key->name);
  5378. /* MySQL knows about this index and so we must be able to find it.*/
  5379. ut_a(index);
  5380. heap = mem_heap_create(2 * (key->key_parts * sizeof(dfield_t)
  5381. + sizeof(dtuple_t)));
  5382. range_start = dtuple_create(heap, key->key_parts);
  5383. dict_index_copy_types(range_start, index, key->key_parts);
  5384. range_end = dtuple_create(heap, key->key_parts);
  5385. dict_index_copy_types(range_end, index, key->key_parts);
  5386. row_sel_convert_mysql_key_to_innobase(
  5387. range_start, (byte*) key_val_buff,
  5388. (ulint)upd_and_key_val_buff_len,
  5389. index,
  5390. (byte*) (min_key ? min_key->key :
  5391. (const uchar*) 0),
  5392. (ulint) (min_key ? min_key->length : 0),
  5393. prebuilt->trx);
  5394. row_sel_convert_mysql_key_to_innobase(
  5395. range_end, (byte*) key_val_buff2,
  5396. buff2_len, index,
  5397. (byte*) (max_key ? max_key->key :
  5398. (const uchar*) 0),
  5399. (ulint) (max_key ? max_key->length : 0),
  5400. prebuilt->trx);
  5401. mode1 = convert_search_mode_to_innobase(min_key ? min_key->flag :
  5402. HA_READ_KEY_EXACT);
  5403. mode2 = convert_search_mode_to_innobase(max_key ? max_key->flag :
  5404. HA_READ_KEY_EXACT);
  5405. if (mode1 != PAGE_CUR_UNSUPP && mode2 != PAGE_CUR_UNSUPP) {
  5406. n_rows = btr_estimate_n_rows_in_range(index, range_start,
  5407. mode1, range_end,
  5408. mode2);
  5409. } else {
  5410. n_rows = 0;
  5411. }
  5412. mem_heap_free(heap);
  5413. my_free(key_val_buff2, MYF(0));
  5414. prebuilt->trx->op_info = (char*)"";
  5415. /* The MySQL optimizer seems to believe an estimate of 0 rows is
  5416. always accurate and may return the result 'Empty set' based on that.
  5417. The accuracy is not guaranteed, and even if it were, for a locking
  5418. read we should anyway perform the search to set the next-key lock.
  5419. Add 1 to the value to make sure MySQL does not make the assumption! */
  5420. if (n_rows == 0) {
  5421. n_rows = 1;
  5422. }
  5423. DBUG_RETURN((ha_rows) n_rows);
  5424. }
  5425. /*************************************************************************
  5426. Gives an UPPER BOUND to the number of rows in a table. This is used in
  5427. filesort.cc. */
  5428. UNIV_INTERN
  5429. ha_rows
  5430. ha_innobase::estimate_rows_upper_bound(void)
  5431. /*======================================*/
  5432. /* out: upper bound of rows */
  5433. {
  5434. dict_index_t* index;
  5435. ulonglong estimate;
  5436. ulonglong local_data_file_length;
  5437. DBUG_ENTER("estimate_rows_upper_bound");
  5438. /* We do not know if MySQL can call this function before calling
  5439. external_lock(). To be safe, update the thd of the current table
  5440. handle. */
  5441. update_thd(ha_thd());
  5442. prebuilt->trx->op_info = (char*)
  5443. "calculating upper bound for table rows";
  5444. /* In case MySQL calls this in the middle of a SELECT query, release
  5445. possible adaptive hash latch to avoid deadlocks of threads */
  5446. trx_search_latch_release_if_reserved(prebuilt->trx);
  5447. index = dict_table_get_first_index(prebuilt->table);
  5448. ut_a(index->stat_n_leaf_pages > 0);
  5449. local_data_file_length =
  5450. ((ulonglong) index->stat_n_leaf_pages) * UNIV_PAGE_SIZE;
  5451. /* Calculate a minimum length for a clustered index record and from
  5452. that an upper bound for the number of rows. Since we only calculate
  5453. new statistics in row0mysql.c when a table has grown by a threshold
  5454. factor, we must add a safety factor 2 in front of the formula below. */
  5455. estimate = 2 * local_data_file_length /
  5456. dict_index_calc_min_rec_len(index);
  5457. prebuilt->trx->op_info = (char*)"";
  5458. DBUG_RETURN((ha_rows) estimate);
  5459. }
  5460. /*************************************************************************
  5461. How many seeks it will take to read through the table. This is to be
  5462. comparable to the number returned by records_in_range so that we can
  5463. decide if we should scan the table or use keys. */
  5464. UNIV_INTERN
  5465. double
  5466. ha_innobase::scan_time()
  5467. /*====================*/
  5468. /* out: estimated time measured in disk seeks */
  5469. {
  5470. /* Since MySQL seems to favor table scans too much over index
  5471. searches, we pretend that a sequential read takes the same time
  5472. as a random disk read, that is, we do not divide the following
  5473. by 10, which would be physically realistic. */
  5474. return((double) (prebuilt->table->stat_clustered_index_size));
  5475. }
  5476. /**********************************************************************
  5477. Calculate the time it takes to read a set of ranges through an index
  5478. This enables us to optimise reads for clustered indexes. */
  5479. UNIV_INTERN
  5480. double
  5481. ha_innobase::read_time(
  5482. /*===================*/
  5483. /* out: estimated time measured in disk seeks */
  5484. uint index, /* in: key number */
  5485. uint ranges, /* in: how many ranges */
  5486. ha_rows rows) /* in: estimated number of rows in the ranges */
  5487. {
  5488. ha_rows total_rows;
  5489. double time_for_scan;
  5490. if (index != table->s->primary_key) {
  5491. /* Not clustered */
  5492. return(handler::read_time(index, ranges, rows));
  5493. }
  5494. if (rows <= 2) {
  5495. return((double) rows);
  5496. }
  5497. /* Assume that the read time is proportional to the scan time for all
  5498. rows + at most one seek per range. */
  5499. time_for_scan = scan_time();
  5500. if ((total_rows = estimate_rows_upper_bound()) < rows) {
  5501. return(time_for_scan);
  5502. }
  5503. return(ranges + (double) rows / (double) total_rows * time_for_scan);
  5504. }
  5505. /*************************************************************************
  5506. Returns statistics information of the table to the MySQL interpreter,
  5507. in various fields of the handle object. */
  5508. UNIV_INTERN
  5509. int
  5510. ha_innobase::info(
  5511. /*==============*/
  5512. uint flag) /* in: what information MySQL requests */
  5513. {
  5514. dict_table_t* ib_table;
  5515. dict_index_t* index;
  5516. ha_rows rec_per_key;
  5517. ib_int64_t n_rows;
  5518. ulong j;
  5519. ulong i;
  5520. char path[FN_REFLEN];
  5521. os_file_stat_t stat_info;
  5522. DBUG_ENTER("info");
  5523. /* If we are forcing recovery at a high level, we will suppress
  5524. statistics calculation on tables, because that may crash the
  5525. server if an index is badly corrupted. */
  5526. if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
  5527. /* We return success (0) instead of HA_ERR_CRASHED,
  5528. because we want MySQL to process this query and not
  5529. stop, like it would do if it received the error code
  5530. HA_ERR_CRASHED. */
  5531. DBUG_RETURN(0);
  5532. }
  5533. /* We do not know if MySQL can call this function before calling
  5534. external_lock(). To be safe, update the thd of the current table
  5535. handle. */
  5536. update_thd(ha_thd());
  5537. /* In case MySQL calls this in the middle of a SELECT query, release
  5538. possible adaptive hash latch to avoid deadlocks of threads */
  5539. prebuilt->trx->op_info = (char*)"returning various info to MySQL";
  5540. trx_search_latch_release_if_reserved(prebuilt->trx);
  5541. ib_table = prebuilt->table;
  5542. if (flag & HA_STATUS_TIME) {
  5543. if (srv_stats_on_metadata) {
  5544. /* In sql_show we call with this flag: update
  5545. then statistics so that they are up-to-date */
  5546. prebuilt->trx->op_info = "updating table statistics";
  5547. dict_update_statistics(ib_table);
  5548. prebuilt->trx->op_info = "returning various info to MySQL";
  5549. }
  5550. my_snprintf(path, sizeof(path), "%s/%s%s",
  5551. mysql_data_home, ib_table->name, reg_ext);
  5552. unpack_filename(path,path);
  5553. /* Note that we do not know the access time of the table,
  5554. nor the CHECK TABLE time, nor the UPDATE or INSERT time. */
  5555. if (os_file_get_status(path,&stat_info)) {
  5556. stats.create_time = stat_info.ctime;
  5557. }
  5558. }
  5559. if (flag & HA_STATUS_VARIABLE) {
  5560. n_rows = ib_table->stat_n_rows;
  5561. /* Because we do not protect stat_n_rows by any mutex in a
  5562. delete, it is theoretically possible that the value can be
  5563. smaller than zero! TODO: fix this race.
  5564. The MySQL optimizer seems to assume in a left join that n_rows
  5565. is an accurate estimate if it is zero. Of course, it is not,
  5566. since we do not have any locks on the rows yet at this phase.
  5567. Since SHOW TABLE STATUS seems to call this function with the
  5568. HA_STATUS_TIME flag set, while the left join optimizer does not
  5569. set that flag, we add one to a zero value if the flag is not
  5570. set. That way SHOW TABLE STATUS will show the best estimate,
  5571. while the optimizer never sees the table empty. */
  5572. if (n_rows < 0) {
  5573. n_rows = 0;
  5574. }
  5575. if (n_rows == 0 && !(flag & HA_STATUS_TIME)) {
  5576. n_rows++;
  5577. }
  5578. /* Fix bug#29507: TRUNCATE shows too many rows affected.
  5579. Do not show the estimates for TRUNCATE command. */
  5580. if (thd_sql_command(user_thd) == SQLCOM_TRUNCATE) {
  5581. n_rows = 0;
  5582. /* We need to reset the prebuilt value too, otherwise
  5583. checks for values greater than the last value written
  5584. to the table will fail and the autoinc counter will
  5585. not be updated. This will force write_row() into
  5586. attempting an update of the table's AUTOINC counter. */
  5587. prebuilt->autoinc_last_value = 0;
  5588. }
  5589. stats.records = (ha_rows)n_rows;
  5590. stats.deleted = 0;
  5591. stats.data_file_length = ((ulonglong)
  5592. ib_table->stat_clustered_index_size)
  5593. * UNIV_PAGE_SIZE;
  5594. stats.index_file_length = ((ulonglong)
  5595. ib_table->stat_sum_of_other_index_sizes)
  5596. * UNIV_PAGE_SIZE;
  5597. /* Since fsp_get_available_space_in_free_extents() is
  5598. acquiring latches inside InnoDB, we do not call it if we
  5599. are asked by MySQL to avoid locking. Another reason to
  5600. avoid the call is that it uses quite a lot of CPU.
  5601. See Bug#38185.
  5602. We do not update delete_length if no locking is requested
  5603. so the "old" value can remain. delete_length is initialized
  5604. to 0 in the ha_statistics' constructor. */
  5605. if (!(flag & HA_STATUS_NO_LOCK)) {
  5606. /* lock the data dictionary to avoid races with
  5607. ibd_file_missing and tablespace_discarded */
  5608. row_mysql_lock_data_dictionary(prebuilt->trx);
  5609. /* ib_table->space must be an existent tablespace */
  5610. if (!ib_table->ibd_file_missing
  5611. && !ib_table->tablespace_discarded) {
  5612. stats.delete_length =
  5613. fsp_get_available_space_in_free_extents(
  5614. ib_table->space) * 1024;
  5615. } else {
  5616. THD* thd;
  5617. thd = ha_thd();
  5618. push_warning_printf(
  5619. thd,
  5620. MYSQL_ERROR::WARN_LEVEL_WARN,
  5621. ER_CANT_GET_STAT,
  5622. "InnoDB: Trying to get the free "
  5623. "space for table %s but its "
  5624. "tablespace has been discarded or "
  5625. "the .ibd file is missing. Setting "
  5626. "the free space to zero.",
  5627. ib_table->name);
  5628. stats.delete_length = 0;
  5629. }
  5630. row_mysql_unlock_data_dictionary(prebuilt->trx);
  5631. }
  5632. stats.check_time = 0;
  5633. if (stats.records == 0) {
  5634. stats.mean_rec_length = 0;
  5635. } else {
  5636. stats.mean_rec_length = (ulong) (stats.data_file_length / stats.records);
  5637. }
  5638. }
  5639. if (flag & HA_STATUS_CONST) {
  5640. index = dict_table_get_first_index(ib_table);
  5641. if (prebuilt->clust_index_was_generated) {
  5642. index = dict_table_get_next_index(index);
  5643. }
  5644. for (i = 0; i < table->s->keys; i++) {
  5645. if (index == NULL) {
  5646. sql_print_error("Table %s contains fewer "
  5647. "indexes inside InnoDB than "
  5648. "are defined in the MySQL "
  5649. ".frm file. Have you mixed up "
  5650. ".frm files from different "
  5651. "installations? See "
  5652. "http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n",
  5653. ib_table->name);
  5654. break;
  5655. }
  5656. for (j = 0; j < table->key_info[i].key_parts; j++) {
  5657. if (j + 1 > index->n_uniq) {
  5658. sql_print_error(
  5659. "Index %s of %s has %lu columns unique inside InnoDB, but MySQL is asking "
  5660. "statistics for %lu columns. Have you mixed up .frm files from different "
  5661. "installations? "
  5662. "See http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n",
  5663. index->name,
  5664. ib_table->name,
  5665. (unsigned long)
  5666. index->n_uniq, j + 1);
  5667. break;
  5668. }
  5669. if (index->stat_n_diff_key_vals[j + 1] == 0) {
  5670. rec_per_key = stats.records;
  5671. } else {
  5672. rec_per_key = (ha_rows)(stats.records /
  5673. index->stat_n_diff_key_vals[j + 1]);
  5674. }
  5675. /* Since MySQL seems to favor table scans
  5676. too much over index searches, we pretend
  5677. index selectivity is 2 times better than
  5678. our estimate: */
  5679. rec_per_key = rec_per_key / 2;
  5680. if (rec_per_key == 0) {
  5681. rec_per_key = 1;
  5682. }
  5683. table->key_info[i].rec_per_key[j]=
  5684. rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
  5685. (ulong) rec_per_key;
  5686. }
  5687. index = dict_table_get_next_index(index);
  5688. }
  5689. }
  5690. if (flag & HA_STATUS_ERRKEY) {
  5691. const dict_index_t* err_index;
  5692. ut_a(prebuilt->trx);
  5693. ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
  5694. err_index = trx_get_error_info(prebuilt->trx);
  5695. if (err_index) {
  5696. errkey = (unsigned int)
  5697. row_get_mysql_key_number_for_index(err_index);
  5698. } else {
  5699. errkey = (unsigned int) prebuilt->trx->error_key_num;
  5700. }
  5701. }
  5702. if ((flag & HA_STATUS_AUTO) && table->found_next_number_field) {
  5703. stats.auto_increment_value = innobase_peek_autoinc();
  5704. }
  5705. prebuilt->trx->op_info = (char*)"";
  5706. DBUG_RETURN(0);
  5707. }
  5708. /**************************************************************************
  5709. Updates index cardinalities of the table, based on 8 random dives into
  5710. each index tree. This does NOT calculate exact statistics on the table. */
  5711. UNIV_INTERN
  5712. int
  5713. ha_innobase::analyze(
  5714. /*=================*/
  5715. /* out: returns always 0 (success) */
  5716. THD* thd, /* in: connection thread handle */
  5717. HA_CHECK_OPT* check_opt) /* in: currently ignored */
  5718. {
  5719. /* Simply call ::info() with all the flags */
  5720. info(HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE);
  5721. return(0);
  5722. }
  5723. /**************************************************************************
  5724. This is mapped to "ALTER TABLE tablename ENGINE=InnoDB", which rebuilds
  5725. the table in MySQL. */
  5726. UNIV_INTERN
  5727. int
  5728. ha_innobase::optimize(
  5729. /*==================*/
  5730. THD* thd, /* in: connection thread handle */
  5731. HA_CHECK_OPT* check_opt) /* in: currently ignored */
  5732. {
  5733. return(HA_ADMIN_TRY_ALTER);
  5734. }
  5735. /***********************************************************************
  5736. Tries to check that an InnoDB table is not corrupted. If corruption is
  5737. noticed, prints to stderr information about it. In case of corruption
  5738. may also assert a failure and crash the server. */
  5739. UNIV_INTERN
  5740. int
  5741. ha_innobase::check(
  5742. /*===============*/
  5743. /* out: HA_ADMIN_CORRUPT or
  5744. HA_ADMIN_OK */
  5745. THD* thd, /* in: user thread handle */
  5746. HA_CHECK_OPT* check_opt) /* in: check options, currently
  5747. ignored */
  5748. {
  5749. ulint ret;
  5750. DBUG_ASSERT(thd == ha_thd());
  5751. ut_a(prebuilt->trx);
  5752. ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
  5753. ut_a(prebuilt->trx == thd_to_trx(thd));
  5754. if (prebuilt->mysql_template == NULL) {
  5755. /* Build the template; we will use a dummy template
  5756. in index scans done in checking */
  5757. build_template(prebuilt, NULL, table, ROW_MYSQL_WHOLE_ROW);
  5758. }
  5759. ret = row_check_table_for_mysql(prebuilt);
  5760. if (ret == DB_SUCCESS) {
  5761. return(HA_ADMIN_OK);
  5762. }
  5763. return(HA_ADMIN_CORRUPT);
  5764. }
  5765. /*****************************************************************
  5766. Adds information about free space in the InnoDB tablespace to a table comment
  5767. which is printed out when a user calls SHOW TABLE STATUS. Adds also info on
  5768. foreign keys. */
  5769. UNIV_INTERN
  5770. char*
  5771. ha_innobase::update_table_comment(
  5772. /*==============================*/
  5773. /* out: table comment + InnoDB free space +
  5774. info on foreign keys */
  5775. const char* comment)/* in: table comment defined by user */
  5776. {
  5777. uint length = (uint) strlen(comment);
  5778. char* str;
  5779. long flen;
  5780. /* We do not know if MySQL can call this function before calling
  5781. external_lock(). To be safe, update the thd of the current table
  5782. handle. */
  5783. if (length > 64000 - 3) {
  5784. return((char*)comment); /* string too long */
  5785. }
  5786. update_thd(ha_thd());
  5787. prebuilt->trx->op_info = (char*)"returning table comment";
  5788. /* In case MySQL calls this in the middle of a SELECT query, release
  5789. possible adaptive hash latch to avoid deadlocks of threads */
  5790. trx_search_latch_release_if_reserved(prebuilt->trx);
  5791. str = NULL;
  5792. /* output the data to a temporary file */
  5793. mutex_enter(&srv_dict_tmpfile_mutex);
  5794. rewind(srv_dict_tmpfile);
  5795. fprintf(srv_dict_tmpfile, "InnoDB free: %llu kB",
  5796. fsp_get_available_space_in_free_extents(
  5797. prebuilt->table->space));
  5798. dict_print_info_on_foreign_keys(FALSE, srv_dict_tmpfile,
  5799. prebuilt->trx, prebuilt->table);
  5800. flen = ftell(srv_dict_tmpfile);
  5801. if (flen < 0) {
  5802. flen = 0;
  5803. } else if (length + flen + 3 > 64000) {
  5804. flen = 64000 - 3 - length;
  5805. }
  5806. /* allocate buffer for the full string, and
  5807. read the contents of the temporary file */
  5808. str = (char*) my_malloc(length + flen + 3, MYF(0));
  5809. if (str) {
  5810. char* pos = str + length;
  5811. if (length) {
  5812. memcpy(str, comment, length);
  5813. *pos++ = ';';
  5814. *pos++ = ' ';
  5815. }
  5816. rewind(srv_dict_tmpfile);
  5817. flen = (uint) fread(pos, 1, flen, srv_dict_tmpfile);
  5818. pos[flen] = 0;
  5819. }
  5820. mutex_exit(&srv_dict_tmpfile_mutex);
  5821. prebuilt->trx->op_info = (char*)"";
  5822. return(str ? str : (char*) comment);
  5823. }
  5824. /***********************************************************************
  5825. Gets the foreign key create info for a table stored in InnoDB. */
  5826. UNIV_INTERN
  5827. char*
  5828. ha_innobase::get_foreign_key_create_info(void)
  5829. /*==========================================*/
  5830. /* out, own: character string in the form which
  5831. can be inserted to the CREATE TABLE statement,
  5832. MUST be freed with ::free_foreign_key_create_info */
  5833. {
  5834. char* str = 0;
  5835. long flen;
  5836. ut_a(prebuilt != NULL);
  5837. /* We do not know if MySQL can call this function before calling
  5838. external_lock(). To be safe, update the thd of the current table
  5839. handle. */
  5840. update_thd(ha_thd());
  5841. prebuilt->trx->op_info = (char*)"getting info on foreign keys";
  5842. /* In case MySQL calls this in the middle of a SELECT query,
  5843. release possible adaptive hash latch to avoid
  5844. deadlocks of threads */
  5845. trx_search_latch_release_if_reserved(prebuilt->trx);
  5846. mutex_enter(&srv_dict_tmpfile_mutex);
  5847. rewind(srv_dict_tmpfile);
  5848. /* output the data to a temporary file */
  5849. dict_print_info_on_foreign_keys(TRUE, srv_dict_tmpfile,
  5850. prebuilt->trx, prebuilt->table);
  5851. prebuilt->trx->op_info = (char*)"";
  5852. flen = ftell(srv_dict_tmpfile);
  5853. if (flen < 0) {
  5854. flen = 0;
  5855. } else if (flen > 64000 - 1) {
  5856. flen = 64000 - 1;
  5857. }
  5858. /* allocate buffer for the string, and
  5859. read the contents of the temporary file */
  5860. str = (char*) my_malloc(flen + 1, MYF(0));
  5861. if (str) {
  5862. rewind(srv_dict_tmpfile);
  5863. flen = (uint) fread(str, 1, flen, srv_dict_tmpfile);
  5864. str[flen] = 0;
  5865. }
  5866. mutex_exit(&srv_dict_tmpfile_mutex);
  5867. return(str);
  5868. }
  5869. UNIV_INTERN
  5870. int
  5871. ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
  5872. {
  5873. dict_foreign_t* foreign;
  5874. DBUG_ENTER("get_foreign_key_list");
  5875. ut_a(prebuilt != NULL);
  5876. update_thd(ha_thd());
  5877. prebuilt->trx->op_info = (char*)"getting list of foreign keys";
  5878. trx_search_latch_release_if_reserved(prebuilt->trx);
  5879. mutex_enter(&(dict_sys->mutex));
  5880. foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
  5881. while (foreign != NULL) {
  5882. uint i;
  5883. FOREIGN_KEY_INFO f_key_info;
  5884. LEX_STRING *name= 0;
  5885. uint ulen;
  5886. char uname[NAME_LEN+1]; /* Unencoded name */
  5887. char db_name[NAME_LEN+1];
  5888. const char *tmp_buff;
  5889. tmp_buff= foreign->id;
  5890. i= 0;
  5891. while (tmp_buff[i] != '/')
  5892. i++;
  5893. tmp_buff+= i + 1;
  5894. f_key_info.forein_id = thd_make_lex_string(thd, 0,
  5895. tmp_buff, (uint) strlen(tmp_buff), 1);
  5896. tmp_buff= foreign->referenced_table_name;
  5897. /* Database name */
  5898. i= 0;
  5899. while (tmp_buff[i] != '/')
  5900. {
  5901. db_name[i]= tmp_buff[i];
  5902. i++;
  5903. }
  5904. db_name[i]= 0;
  5905. ulen= filename_to_tablename(db_name, uname, sizeof(uname));
  5906. f_key_info.referenced_db = thd_make_lex_string(thd, 0,
  5907. uname, ulen, 1);
  5908. /* Table name */
  5909. tmp_buff+= i + 1;
  5910. ulen= filename_to_tablename(tmp_buff, uname, sizeof(uname));
  5911. f_key_info.referenced_table = thd_make_lex_string(thd, 0,
  5912. uname, ulen, 1);
  5913. for (i= 0;;) {
  5914. tmp_buff= foreign->foreign_col_names[i];
  5915. name = thd_make_lex_string(thd, name,
  5916. tmp_buff, (uint) strlen(tmp_buff), 1);
  5917. f_key_info.foreign_fields.push_back(name);
  5918. tmp_buff= foreign->referenced_col_names[i];
  5919. name = thd_make_lex_string(thd, name,
  5920. tmp_buff, (uint) strlen(tmp_buff), 1);
  5921. f_key_info.referenced_fields.push_back(name);
  5922. if (++i >= foreign->n_fields)
  5923. break;
  5924. }
  5925. ulong length;
  5926. if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE)
  5927. {
  5928. length=7;
  5929. tmp_buff= "CASCADE";
  5930. }
  5931. else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL)
  5932. {
  5933. length=8;
  5934. tmp_buff= "SET NULL";
  5935. }
  5936. else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION)
  5937. {
  5938. length=9;
  5939. tmp_buff= "NO ACTION";
  5940. }
  5941. else
  5942. {
  5943. length=8;
  5944. tmp_buff= "RESTRICT";
  5945. }
  5946. f_key_info.delete_method = thd_make_lex_string(
  5947. thd, f_key_info.delete_method, tmp_buff, length, 1);
  5948. if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)
  5949. {
  5950. length=7;
  5951. tmp_buff= "CASCADE";
  5952. }
  5953. else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL)
  5954. {
  5955. length=8;
  5956. tmp_buff= "SET NULL";
  5957. }
  5958. else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION)
  5959. {
  5960. length=9;
  5961. tmp_buff= "NO ACTION";
  5962. }
  5963. else
  5964. {
  5965. length=8;
  5966. tmp_buff= "RESTRICT";
  5967. }
  5968. f_key_info.update_method = thd_make_lex_string(
  5969. thd, f_key_info.update_method, tmp_buff, length, 1);
  5970. if (foreign->referenced_index &&
  5971. foreign->referenced_index->name)
  5972. {
  5973. f_key_info.referenced_key_name = thd_make_lex_string(
  5974. thd, f_key_info.referenced_key_name,
  5975. foreign->referenced_index->name,
  5976. strlen(foreign->referenced_index->name), 1);
  5977. }
  5978. else
  5979. f_key_info.referenced_key_name= 0;
  5980. FOREIGN_KEY_INFO *pf_key_info = (FOREIGN_KEY_INFO *)
  5981. thd_memdup(thd, &f_key_info, sizeof(FOREIGN_KEY_INFO));
  5982. f_key_list->push_back(pf_key_info);
  5983. foreign = UT_LIST_GET_NEXT(foreign_list, foreign);
  5984. }
  5985. mutex_exit(&(dict_sys->mutex));
  5986. prebuilt->trx->op_info = (char*)"";
  5987. DBUG_RETURN(0);
  5988. }
  5989. /*********************************************************************
  5990. Checks if ALTER TABLE may change the storage engine of the table.
  5991. Changing storage engines is not allowed for tables for which there
  5992. are foreign key constraints (parent or child tables). */
  5993. UNIV_INTERN
  5994. bool
  5995. ha_innobase::can_switch_engines(void)
  5996. /*=================================*/
  5997. {
  5998. bool can_switch;
  5999. DBUG_ENTER("ha_innobase::can_switch_engines");
  6000. ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
  6001. prebuilt->trx->op_info =
  6002. "determining if there are foreign key constraints";
  6003. row_mysql_lock_data_dictionary(prebuilt->trx);
  6004. can_switch = !UT_LIST_GET_FIRST(prebuilt->table->referenced_list)
  6005. && !UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
  6006. row_mysql_unlock_data_dictionary(prebuilt->trx);
  6007. prebuilt->trx->op_info = "";
  6008. DBUG_RETURN(can_switch);
  6009. }
  6010. /***********************************************************************
  6011. Checks if a table is referenced by a foreign key. The MySQL manual states that
  6012. a REPLACE is either equivalent to an INSERT, or DELETE(s) + INSERT. Only a
  6013. delete is then allowed internally to resolve a duplicate key conflict in
  6014. REPLACE, not an update. */
  6015. UNIV_INTERN
  6016. uint
  6017. ha_innobase::referenced_by_foreign_key(void)
  6018. /*========================================*/
  6019. /* out: > 0 if referenced by a FOREIGN KEY */
  6020. {
  6021. if (dict_table_is_referenced_by_foreign_key(prebuilt->table)) {
  6022. return(1);
  6023. }
  6024. return(0);
  6025. }
  6026. /***********************************************************************
  6027. Frees the foreign key create info for a table stored in InnoDB, if it is
  6028. non-NULL. */
  6029. UNIV_INTERN
  6030. void
  6031. ha_innobase::free_foreign_key_create_info(
  6032. /*======================================*/
  6033. char* str) /* in, own: create info string to free */
  6034. {
  6035. if (str) {
  6036. my_free(str, MYF(0));
  6037. }
  6038. }
  6039. /***********************************************************************
  6040. Tells something additional to the handler about how to do things. */
  6041. UNIV_INTERN
  6042. int
  6043. ha_innobase::extra(
  6044. /*===============*/
  6045. /* out: 0 or error number */
  6046. enum ha_extra_function operation)
  6047. /* in: HA_EXTRA_FLUSH or some other flag */
  6048. {
  6049. /* Warning: since it is not sure that MySQL calls external_lock
  6050. before calling this function, the trx field in prebuilt can be
  6051. obsolete! */
  6052. switch (operation) {
  6053. case HA_EXTRA_FLUSH:
  6054. if (prebuilt->blob_heap) {
  6055. row_mysql_prebuilt_free_blob_heap(prebuilt);
  6056. }
  6057. break;
  6058. case HA_EXTRA_RESET_STATE:
  6059. reset_template(prebuilt);
  6060. break;
  6061. case HA_EXTRA_NO_KEYREAD:
  6062. prebuilt->read_just_key = 0;
  6063. break;
  6064. case HA_EXTRA_KEYREAD:
  6065. prebuilt->read_just_key = 1;
  6066. break;
  6067. case HA_EXTRA_KEYREAD_PRESERVE_FIELDS:
  6068. prebuilt->keep_other_fields_on_keyread = 1;
  6069. break;
  6070. /* IMPORTANT: prebuilt->trx can be obsolete in
  6071. this method, because it is not sure that MySQL
  6072. calls external_lock before this method with the
  6073. parameters below. We must not invoke update_thd()
  6074. either, because the calling threads may change.
  6075. CAREFUL HERE, OR MEMORY CORRUPTION MAY OCCUR! */
  6076. case HA_EXTRA_IGNORE_DUP_KEY:
  6077. thd_to_trx(ha_thd())->duplicates |= TRX_DUP_IGNORE;
  6078. break;
  6079. case HA_EXTRA_WRITE_CAN_REPLACE:
  6080. thd_to_trx(ha_thd())->duplicates |= TRX_DUP_REPLACE;
  6081. break;
  6082. case HA_EXTRA_WRITE_CANNOT_REPLACE:
  6083. thd_to_trx(ha_thd())->duplicates &= ~TRX_DUP_REPLACE;
  6084. break;
  6085. case HA_EXTRA_NO_IGNORE_DUP_KEY:
  6086. thd_to_trx(ha_thd())->duplicates &=
  6087. ~(TRX_DUP_IGNORE | TRX_DUP_REPLACE);
  6088. break;
  6089. default:/* Do nothing */
  6090. ;
  6091. }
  6092. return(0);
  6093. }
  6094. UNIV_INTERN
  6095. int
  6096. ha_innobase::reset()
  6097. {
  6098. if (prebuilt->blob_heap) {
  6099. row_mysql_prebuilt_free_blob_heap(prebuilt);
  6100. }
  6101. reset_template(prebuilt);
  6102. /* TODO: This should really be reset in reset_template() but for now
  6103. it's safer to do it explicitly here. */
  6104. /* This is a statement level counter. */
  6105. prebuilt->autoinc_last_value = 0;
  6106. return(0);
  6107. }
  6108. /**********************************************************************
  6109. MySQL calls this function at the start of each SQL statement inside LOCK
  6110. TABLES. Inside LOCK TABLES the ::external_lock method does not work to
  6111. mark SQL statement borders. Note also a special case: if a temporary table
  6112. is created inside LOCK TABLES, MySQL has not called external_lock() at all
  6113. on that table.
  6114. MySQL-5.0 also calls this before each statement in an execution of a stored
  6115. procedure. To make the execution more deterministic for binlogging, MySQL-5.0
  6116. locks all tables involved in a stored procedure with full explicit table
  6117. locks (thd_in_lock_tables(thd) holds in store_lock()) before executing the
  6118. procedure. */
  6119. UNIV_INTERN
  6120. int
  6121. ha_innobase::start_stmt(
  6122. /*====================*/
  6123. /* out: 0 or error code */
  6124. THD* thd, /* in: handle to the user thread */
  6125. thr_lock_type lock_type)
  6126. {
  6127. trx_t* trx;
  6128. update_thd(thd);
  6129. trx = prebuilt->trx;
  6130. /* Here we release the search latch and the InnoDB thread FIFO ticket
  6131. if they were reserved. They should have been released already at the
  6132. end of the previous statement, but because inside LOCK TABLES the
  6133. lock count method does not work to mark the end of a SELECT statement,
  6134. that may not be the case. We MUST release the search latch before an
  6135. INSERT, for example. */
  6136. innobase_release_stat_resources(trx);
  6137. /* Reset the AUTOINC statement level counter for multi-row INSERTs. */
  6138. trx->n_autoinc_rows = 0;
  6139. prebuilt->sql_stat_start = TRUE;
  6140. prebuilt->hint_need_to_fetch_extra_cols = 0;
  6141. reset_template(prebuilt);
  6142. if (!prebuilt->mysql_has_locked) {
  6143. /* This handle is for a temporary table created inside
  6144. this same LOCK TABLES; since MySQL does NOT call external_lock
  6145. in this case, we must use x-row locks inside InnoDB to be
  6146. prepared for an update of a row */
  6147. prebuilt->select_lock_type = LOCK_X;
  6148. } else {
  6149. if (trx->isolation_level != TRX_ISO_SERIALIZABLE
  6150. && thd_sql_command(thd) == SQLCOM_SELECT
  6151. && lock_type == TL_READ) {
  6152. /* For other than temporary tables, we obtain
  6153. no lock for consistent read (plain SELECT). */
  6154. prebuilt->select_lock_type = LOCK_NONE;
  6155. } else {
  6156. /* Not a consistent read: restore the
  6157. select_lock_type value. The value of
  6158. stored_select_lock_type was decided in:
  6159. 1) ::store_lock(),
  6160. 2) ::external_lock(),
  6161. 3) ::init_table_handle_for_HANDLER(), and
  6162. 4) ::transactional_table_lock(). */
  6163. prebuilt->select_lock_type =
  6164. prebuilt->stored_select_lock_type;
  6165. }
  6166. }
  6167. trx->detailed_error[0] = '\0';
  6168. /* Set the MySQL flag to mark that there is an active transaction */
  6169. if (trx->active_trans == 0) {
  6170. innobase_register_trx_and_stmt(ht, thd);
  6171. trx->active_trans = 1;
  6172. } else {
  6173. innobase_register_stmt(ht, thd);
  6174. }
  6175. return(0);
  6176. }
  6177. /**********************************************************************
  6178. Maps a MySQL trx isolation level code to the InnoDB isolation level code */
  6179. inline
  6180. ulint
  6181. innobase_map_isolation_level(
  6182. /*=========================*/
  6183. /* out: InnoDB isolation level */
  6184. enum_tx_isolation iso) /* in: MySQL isolation level code */
  6185. {
  6186. switch(iso) {
  6187. case ISO_REPEATABLE_READ: return(TRX_ISO_REPEATABLE_READ);
  6188. case ISO_READ_COMMITTED: return(TRX_ISO_READ_COMMITTED);
  6189. case ISO_SERIALIZABLE: return(TRX_ISO_SERIALIZABLE);
  6190. case ISO_READ_UNCOMMITTED: return(TRX_ISO_READ_UNCOMMITTED);
  6191. default: ut_a(0); return(0);
  6192. }
  6193. }
  6194. /**********************************************************************
  6195. As MySQL will execute an external lock for every new table it uses when it
  6196. starts to process an SQL statement (an exception is when MySQL calls
  6197. start_stmt for the handle) we can use this function to store the pointer to
  6198. the THD in the handle. We will also use this function to communicate
  6199. to InnoDB that a new SQL statement has started and that we must store a
  6200. savepoint to our transaction handle, so that we are able to roll back
  6201. the SQL statement in case of an error. */
  6202. UNIV_INTERN
  6203. int
  6204. ha_innobase::external_lock(
  6205. /*=======================*/
  6206. /* out: 0 */
  6207. THD* thd, /* in: handle to the user thread */
  6208. int lock_type) /* in: lock type */
  6209. {
  6210. trx_t* trx;
  6211. DBUG_ENTER("ha_innobase::external_lock");
  6212. DBUG_PRINT("enter",("lock_type: %d", lock_type));
  6213. update_thd(thd);
  6214. /* Statement based binlogging does not work in isolation level
  6215. READ UNCOMMITTED and READ COMMITTED since the necessary
  6216. locks cannot be taken. In this case, we print an
  6217. informative error message and return with an error. */
  6218. if (lock_type == F_WRLCK)
  6219. {
  6220. ulong const binlog_format= thd_binlog_format(thd);
  6221. ulong const tx_isolation = thd_tx_isolation(ha_thd());
  6222. if (tx_isolation <= ISO_READ_COMMITTED &&
  6223. binlog_format == BINLOG_FORMAT_STMT)
  6224. {
  6225. char buf[256];
  6226. my_snprintf(buf, sizeof(buf),
  6227. "Transaction level '%s' in"
  6228. " InnoDB is not safe for binlog mode '%s'",
  6229. tx_isolation_names[tx_isolation],
  6230. binlog_format_names[binlog_format]);
  6231. my_error(ER_BINLOG_LOGGING_IMPOSSIBLE, MYF(0), buf);
  6232. DBUG_RETURN(HA_ERR_LOGGING_IMPOSSIBLE);
  6233. }
  6234. }
  6235. trx = prebuilt->trx;
  6236. prebuilt->sql_stat_start = TRUE;
  6237. prebuilt->hint_need_to_fetch_extra_cols = 0;
  6238. reset_template(prebuilt);
  6239. if (lock_type == F_WRLCK) {
  6240. /* If this is a SELECT, then it is in UPDATE TABLE ...
  6241. or SELECT ... FOR UPDATE */
  6242. prebuilt->select_lock_type = LOCK_X;
  6243. prebuilt->stored_select_lock_type = LOCK_X;
  6244. }
  6245. if (lock_type != F_UNLCK) {
  6246. /* MySQL is setting a new table lock */
  6247. trx->detailed_error[0] = '\0';
  6248. /* Set the MySQL flag to mark that there is an active
  6249. transaction */
  6250. if (trx->active_trans == 0) {
  6251. innobase_register_trx_and_stmt(ht, thd);
  6252. trx->active_trans = 1;
  6253. } else if (trx->n_mysql_tables_in_use == 0) {
  6254. innobase_register_stmt(ht, thd);
  6255. }
  6256. if (trx->isolation_level == TRX_ISO_SERIALIZABLE
  6257. && prebuilt->select_lock_type == LOCK_NONE
  6258. && thd_test_options(thd,
  6259. OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  6260. /* To get serializable execution, we let InnoDB
  6261. conceptually add 'LOCK IN SHARE MODE' to all SELECTs
  6262. which otherwise would have been consistent reads. An
  6263. exception is consistent reads in the AUTOCOMMIT=1 mode:
  6264. we know that they are read-only transactions, and they
  6265. can be serialized also if performed as consistent
  6266. reads. */
  6267. prebuilt->select_lock_type = LOCK_S;
  6268. prebuilt->stored_select_lock_type = LOCK_S;
  6269. }
  6270. /* Starting from 4.1.9, no InnoDB table lock is taken in LOCK
  6271. TABLES if AUTOCOMMIT=1. It does not make much sense to acquire
  6272. an InnoDB table lock if it is released immediately at the end
  6273. of LOCK TABLES, and InnoDB's table locks in that case cause
  6274. VERY easily deadlocks.
  6275. We do not set InnoDB table locks if user has not explicitly
  6276. requested a table lock. Note that thd_in_lock_tables(thd)
  6277. can hold in some cases, e.g., at the start of a stored
  6278. procedure call (SQLCOM_CALL). */
  6279. if (prebuilt->select_lock_type != LOCK_NONE) {
  6280. if (thd_sql_command(thd) == SQLCOM_LOCK_TABLES
  6281. && THDVAR(thd, table_locks)
  6282. && thd_test_options(thd, OPTION_NOT_AUTOCOMMIT)
  6283. && thd_in_lock_tables(thd)) {
  6284. ulint error = row_lock_table_for_mysql(
  6285. prebuilt, NULL, 0);
  6286. if (error != DB_SUCCESS) {
  6287. error = convert_error_code_to_mysql(
  6288. (int) error, 0, thd);
  6289. DBUG_RETURN((int) error);
  6290. }
  6291. }
  6292. trx->mysql_n_tables_locked++;
  6293. }
  6294. trx->n_mysql_tables_in_use++;
  6295. prebuilt->mysql_has_locked = TRUE;
  6296. DBUG_RETURN(0);
  6297. }
  6298. /* MySQL is releasing a table lock */
  6299. trx->n_mysql_tables_in_use--;
  6300. prebuilt->mysql_has_locked = FALSE;
  6301. /* Release a possible FIFO ticket and search latch. Since we
  6302. may reserve the kernel mutex, we have to release the search
  6303. system latch first to obey the latching order. */
  6304. innobase_release_stat_resources(trx);
  6305. /* If the MySQL lock count drops to zero we know that the current SQL
  6306. statement has ended */
  6307. if (trx->n_mysql_tables_in_use == 0) {
  6308. trx->mysql_n_tables_locked = 0;
  6309. prebuilt->used_in_HANDLER = FALSE;
  6310. if (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  6311. if (trx->active_trans != 0) {
  6312. innobase_commit(ht, thd, TRUE);
  6313. }
  6314. } else {
  6315. if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
  6316. && trx->global_read_view) {
  6317. /* At low transaction isolation levels we let
  6318. each consistent read set its own snapshot */
  6319. read_view_close_for_mysql(trx);
  6320. }
  6321. }
  6322. }
  6323. DBUG_RETURN(0);
  6324. }
  6325. /**********************************************************************
  6326. With this function MySQL request a transactional lock to a table when
  6327. user issued query LOCK TABLES..WHERE ENGINE = InnoDB. */
  6328. UNIV_INTERN
  6329. int
  6330. ha_innobase::transactional_table_lock(
  6331. /*==================================*/
  6332. /* out: error code */
  6333. THD* thd, /* in: handle to the user thread */
  6334. int lock_type) /* in: lock type */
  6335. {
  6336. trx_t* trx;
  6337. DBUG_ENTER("ha_innobase::transactional_table_lock");
  6338. DBUG_PRINT("enter",("lock_type: %d", lock_type));
  6339. /* We do not know if MySQL can call this function before calling
  6340. external_lock(). To be safe, update the thd of the current table
  6341. handle. */
  6342. update_thd(thd);
  6343. if (prebuilt->table->ibd_file_missing && !thd_tablespace_op(thd)) {
  6344. ut_print_timestamp(stderr);
  6345. fprintf(stderr,
  6346. " InnoDB: MySQL is trying to use a table handle"
  6347. " but the .ibd file for\n"
  6348. "InnoDB: table %s does not exist.\n"
  6349. "InnoDB: Have you deleted the .ibd file"
  6350. " from the database directory under\n"
  6351. "InnoDB: the MySQL datadir?"
  6352. "InnoDB: See"
  6353. " http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n"
  6354. "InnoDB: how you can resolve the problem.\n",
  6355. prebuilt->table->name);
  6356. DBUG_RETURN(HA_ERR_CRASHED);
  6357. }
  6358. trx = prebuilt->trx;
  6359. prebuilt->sql_stat_start = TRUE;
  6360. prebuilt->hint_need_to_fetch_extra_cols = 0;
  6361. reset_template(prebuilt);
  6362. if (lock_type == F_WRLCK) {
  6363. prebuilt->select_lock_type = LOCK_X;
  6364. prebuilt->stored_select_lock_type = LOCK_X;
  6365. } else if (lock_type == F_RDLCK) {
  6366. prebuilt->select_lock_type = LOCK_S;
  6367. prebuilt->stored_select_lock_type = LOCK_S;
  6368. } else {
  6369. ut_print_timestamp(stderr);
  6370. fprintf(stderr, " InnoDB error:\n"
  6371. "MySQL is trying to set transactional table lock with corrupted lock type\n"
  6372. "to table %s, lock type %d does not exist.\n",
  6373. prebuilt->table->name, lock_type);
  6374. DBUG_RETURN(HA_ERR_CRASHED);
  6375. }
  6376. /* MySQL is setting a new transactional table lock */
  6377. /* Set the MySQL flag to mark that there is an active transaction */
  6378. if (trx->active_trans == 0) {
  6379. innobase_register_trx_and_stmt(ht, thd);
  6380. trx->active_trans = 1;
  6381. }
  6382. if (THDVAR(thd, table_locks) && thd_in_lock_tables(thd)) {
  6383. ulint error = DB_SUCCESS;
  6384. error = row_lock_table_for_mysql(prebuilt, NULL, 0);
  6385. if (error != DB_SUCCESS) {
  6386. error = convert_error_code_to_mysql(
  6387. (int) error, prebuilt->table->flags, thd);
  6388. DBUG_RETURN((int) error);
  6389. }
  6390. if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
  6391. /* Store the current undo_no of the transaction
  6392. so that we know where to roll back if we have
  6393. to roll back the next SQL statement */
  6394. trx_mark_sql_stat_end(trx);
  6395. }
  6396. }
  6397. DBUG_RETURN(0);
  6398. }
  6399. /****************************************************************************
  6400. Here we export InnoDB status variables to MySQL. */
  6401. static
  6402. int
  6403. innodb_export_status()
  6404. /*==================*/
  6405. {
  6406. if (innodb_inited) {
  6407. srv_export_innodb_status();
  6408. }
  6409. return(0);
  6410. }
  6411. /****************************************************************************
  6412. Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
  6413. Monitor to the client. */
  6414. static
  6415. bool
  6416. innodb_show_status(
  6417. /*===============*/
  6418. handlerton* hton, /* in: the innodb handlerton */
  6419. THD* thd, /* in: the MySQL query thread of the caller */
  6420. stat_print_fn *stat_print)
  6421. {
  6422. trx_t* trx;
  6423. static const char truncated_msg[] = "... truncated...\n";
  6424. const long MAX_STATUS_SIZE = 64000;
  6425. ulint trx_list_start = ULINT_UNDEFINED;
  6426. ulint trx_list_end = ULINT_UNDEFINED;
  6427. DBUG_ENTER("innodb_show_status");
  6428. DBUG_ASSERT(hton == innodb_hton_ptr);
  6429. trx = check_trx_exists(thd);
  6430. innobase_release_stat_resources(trx);
  6431. /* We let the InnoDB Monitor to output at most MAX_STATUS_SIZE
  6432. bytes of text. */
  6433. long flen, usable_len;
  6434. char* str;
  6435. mutex_enter(&srv_monitor_file_mutex);
  6436. rewind(srv_monitor_file);
  6437. srv_printf_innodb_monitor(srv_monitor_file,
  6438. &trx_list_start, &trx_list_end);
  6439. flen = ftell(srv_monitor_file);
  6440. os_file_set_eof(srv_monitor_file);
  6441. if (flen < 0) {
  6442. flen = 0;
  6443. }
  6444. if (flen > MAX_STATUS_SIZE) {
  6445. usable_len = MAX_STATUS_SIZE;
  6446. } else {
  6447. usable_len = flen;
  6448. }
  6449. /* allocate buffer for the string, and
  6450. read the contents of the temporary file */
  6451. if (!(str = (char*) my_malloc(usable_len + 1, MYF(0)))) {
  6452. mutex_exit(&srv_monitor_file_mutex);
  6453. DBUG_RETURN(TRUE);
  6454. }
  6455. rewind(srv_monitor_file);
  6456. if (flen < MAX_STATUS_SIZE) {
  6457. /* Display the entire output. */
  6458. flen = (long) fread(str, 1, flen, srv_monitor_file);
  6459. } else if (trx_list_end < (ulint) flen
  6460. && trx_list_start < trx_list_end
  6461. && trx_list_start + (flen - trx_list_end)
  6462. < MAX_STATUS_SIZE - sizeof truncated_msg - 1) {
  6463. /* Omit the beginning of the list of active transactions. */
  6464. long len = (long) fread(str, 1, trx_list_start, srv_monitor_file);
  6465. memcpy(str + len, truncated_msg, sizeof truncated_msg - 1);
  6466. len += sizeof truncated_msg - 1;
  6467. usable_len = (MAX_STATUS_SIZE - 1) - len;
  6468. fseek(srv_monitor_file, flen - usable_len, SEEK_SET);
  6469. len += (long) fread(str + len, 1, usable_len, srv_monitor_file);
  6470. flen = len;
  6471. } else {
  6472. /* Omit the end of the output. */
  6473. flen = (long) fread(str, 1, MAX_STATUS_SIZE - 1, srv_monitor_file);
  6474. }
  6475. mutex_exit(&srv_monitor_file_mutex);
  6476. bool result = FALSE;
  6477. if (stat_print(thd, innobase_hton_name, strlen(innobase_hton_name),
  6478. STRING_WITH_LEN(""), str, flen)) {
  6479. result= TRUE;
  6480. }
  6481. my_free(str, MYF(0));
  6482. DBUG_RETURN(FALSE);
  6483. }
  6484. /****************************************************************************
  6485. Implements the SHOW MUTEX STATUS command. . */
  6486. static
  6487. bool
  6488. innodb_mutex_show_status(
  6489. /*=====================*/
  6490. handlerton* hton, /* in: the innodb handlerton */
  6491. THD* thd, /* in: the MySQL query thread of the
  6492. caller */
  6493. stat_print_fn* stat_print)
  6494. {
  6495. char buf1[IO_SIZE], buf2[IO_SIZE];
  6496. mutex_t* mutex;
  6497. #ifdef UNIV_DEBUG
  6498. ulint rw_lock_count= 0;
  6499. ulint rw_lock_count_spin_loop= 0;
  6500. ulint rw_lock_count_spin_rounds= 0;
  6501. ulint rw_lock_count_os_wait= 0;
  6502. ulint rw_lock_count_os_yield= 0;
  6503. ulonglong rw_lock_wait_time= 0;
  6504. #endif /* UNIV_DEBUG */
  6505. uint hton_name_len= strlen(innobase_hton_name), buf1len, buf2len;
  6506. DBUG_ENTER("innodb_mutex_show_status");
  6507. DBUG_ASSERT(hton == innodb_hton_ptr);
  6508. mutex_enter(&mutex_list_mutex);
  6509. mutex = UT_LIST_GET_FIRST(mutex_list);
  6510. while (mutex != NULL) {
  6511. #ifdef UNIV_DEBUG
  6512. if (mutex->mutex_type != 1) {
  6513. if (mutex->count_using > 0) {
  6514. buf1len= my_snprintf(buf1, sizeof(buf1),
  6515. "%s:%s",
  6516. mutex->cmutex_name, mutex->cfile_name);
  6517. buf2len= my_snprintf(buf2, sizeof(buf2),
  6518. "count=%lu, spin_waits=%lu,"
  6519. " spin_rounds=%lu, "
  6520. "os_waits=%lu, os_yields=%lu,"
  6521. " os_wait_times=%lu",
  6522. mutex->count_using,
  6523. mutex->count_spin_loop,
  6524. mutex->count_spin_rounds,
  6525. mutex->count_os_wait,
  6526. mutex->count_os_yield,
  6527. (ulong) (mutex->lspent_time/1000));
  6528. if (stat_print(thd, innobase_hton_name,
  6529. hton_name_len, buf1, buf1len,
  6530. buf2, buf2len)) {
  6531. mutex_exit(&mutex_list_mutex);
  6532. DBUG_RETURN(1);
  6533. }
  6534. }
  6535. }
  6536. else {
  6537. rw_lock_count += mutex->count_using;
  6538. rw_lock_count_spin_loop += mutex->count_spin_loop;
  6539. rw_lock_count_spin_rounds += mutex->count_spin_rounds;
  6540. rw_lock_count_os_wait += mutex->count_os_wait;
  6541. rw_lock_count_os_yield += mutex->count_os_yield;
  6542. rw_lock_wait_time += mutex->lspent_time;
  6543. }
  6544. #else /* UNIV_DEBUG */
  6545. buf1len= my_snprintf(buf1, sizeof(buf1), "%s:%lu",
  6546. mutex->cfile_name, (ulong) mutex->cline);
  6547. buf2len= my_snprintf(buf2, sizeof(buf2), "os_waits=%lu",
  6548. mutex->count_os_wait);
  6549. if (stat_print(thd, innobase_hton_name,
  6550. hton_name_len, buf1, buf1len,
  6551. buf2, buf2len)) {
  6552. mutex_exit(&mutex_list_mutex);
  6553. DBUG_RETURN(1);
  6554. }
  6555. #endif /* UNIV_DEBUG */
  6556. mutex = UT_LIST_GET_NEXT(list, mutex);
  6557. }
  6558. mutex_exit(&mutex_list_mutex);
  6559. #ifdef UNIV_DEBUG
  6560. buf2len= my_snprintf(buf2, sizeof(buf2),
  6561. "count=%lu, spin_waits=%lu, spin_rounds=%lu, "
  6562. "os_waits=%lu, os_yields=%lu, os_wait_times=%lu",
  6563. rw_lock_count, rw_lock_count_spin_loop,
  6564. rw_lock_count_spin_rounds,
  6565. rw_lock_count_os_wait, rw_lock_count_os_yield,
  6566. (ulong) (rw_lock_wait_time/1000));
  6567. if (stat_print(thd, innobase_hton_name, hton_name_len,
  6568. STRING_WITH_LEN("rw_lock_mutexes"), buf2, buf2len)) {
  6569. DBUG_RETURN(1);
  6570. }
  6571. #endif /* UNIV_DEBUG */
  6572. DBUG_RETURN(FALSE);
  6573. }
  6574. static
  6575. bool innobase_show_status(handlerton *hton, THD* thd,
  6576. stat_print_fn* stat_print,
  6577. enum ha_stat_type stat_type)
  6578. {
  6579. DBUG_ASSERT(hton == innodb_hton_ptr);
  6580. switch (stat_type) {
  6581. case HA_ENGINE_STATUS:
  6582. return innodb_show_status(hton, thd, stat_print);
  6583. case HA_ENGINE_MUTEX:
  6584. return innodb_mutex_show_status(hton, thd, stat_print);
  6585. default:
  6586. return(FALSE);
  6587. }
  6588. }
  6589. /****************************************************************************
  6590. Handling the shared INNOBASE_SHARE structure that is needed to provide table
  6591. locking.
  6592. ****************************************************************************/
  6593. static uchar* innobase_get_key(INNOBASE_SHARE* share, size_t *length,
  6594. my_bool not_used __attribute__((unused)))
  6595. {
  6596. *length=share->table_name_length;
  6597. return (uchar*) share->table_name;
  6598. }
  6599. static INNOBASE_SHARE* get_share(const char* table_name)
  6600. {
  6601. INNOBASE_SHARE *share;
  6602. pthread_mutex_lock(&innobase_share_mutex);
  6603. uint length=(uint) strlen(table_name);
  6604. if (!(share=(INNOBASE_SHARE*) hash_search(&innobase_open_tables,
  6605. (uchar*) table_name,
  6606. length))) {
  6607. share = (INNOBASE_SHARE *) my_malloc(sizeof(*share)+length+1,
  6608. MYF(MY_FAE | MY_ZEROFILL));
  6609. share->table_name_length=length;
  6610. share->table_name=(char*) (share+1);
  6611. strmov(share->table_name,table_name);
  6612. if (my_hash_insert(&innobase_open_tables,
  6613. (uchar*) share)) {
  6614. pthread_mutex_unlock(&innobase_share_mutex);
  6615. my_free(share,0);
  6616. return(0);
  6617. }
  6618. thr_lock_init(&share->lock);
  6619. pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
  6620. }
  6621. share->use_count++;
  6622. pthread_mutex_unlock(&innobase_share_mutex);
  6623. return(share);
  6624. }
  6625. static void free_share(INNOBASE_SHARE* share)
  6626. {
  6627. pthread_mutex_lock(&innobase_share_mutex);
  6628. if (!--share->use_count) {
  6629. hash_delete(&innobase_open_tables, (uchar*) share);
  6630. thr_lock_delete(&share->lock);
  6631. pthread_mutex_destroy(&share->mutex);
  6632. my_free(share, MYF(0));
  6633. }
  6634. pthread_mutex_unlock(&innobase_share_mutex);
  6635. }
  6636. /*********************************************************************
  6637. Converts a MySQL table lock stored in the 'lock' field of the handle to
  6638. a proper type before storing pointer to the lock into an array of pointers.
  6639. MySQL also calls this if it wants to reset some table locks to a not-locked
  6640. state during the processing of an SQL query. An example is that during a
  6641. SELECT the read lock is released early on the 'const' tables where we only
  6642. fetch one row. MySQL does not call this when it releases all locks at the
  6643. end of an SQL statement. */
  6644. UNIV_INTERN
  6645. THR_LOCK_DATA**
  6646. ha_innobase::store_lock(
  6647. /*====================*/
  6648. /* out: pointer to the next
  6649. element in the 'to' array */
  6650. THD* thd, /* in: user thread handle */
  6651. THR_LOCK_DATA** to, /* in: pointer to an array
  6652. of pointers to lock structs;
  6653. pointer to the 'lock' field
  6654. of current handle is stored
  6655. next to this array */
  6656. enum thr_lock_type lock_type) /* in: lock type to store in
  6657. 'lock'; this may also be
  6658. TL_IGNORE */
  6659. {
  6660. trx_t* trx;
  6661. /* Note that trx in this function is NOT necessarily prebuilt->trx
  6662. because we call update_thd() later, in ::external_lock()! Failure to
  6663. understand this caused a serious memory corruption bug in 5.1.11. */
  6664. trx = check_trx_exists(thd);
  6665. /* NOTE: MySQL can call this function with lock 'type' TL_IGNORE!
  6666. Be careful to ignore TL_IGNORE if we are going to do something with
  6667. only 'real' locks! */
  6668. /* If no MySQL table is in use, we need to set the isolation level
  6669. of the transaction. */
  6670. if (lock_type != TL_IGNORE
  6671. && trx->n_mysql_tables_in_use == 0) {
  6672. trx->isolation_level = innobase_map_isolation_level(
  6673. (enum_tx_isolation) thd_tx_isolation(thd));
  6674. if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
  6675. && trx->global_read_view) {
  6676. /* At low transaction isolation levels we let
  6677. each consistent read set its own snapshot */
  6678. read_view_close_for_mysql(trx);
  6679. }
  6680. }
  6681. DBUG_ASSERT(EQ_CURRENT_THD(thd));
  6682. const bool in_lock_tables = thd_in_lock_tables(thd);
  6683. const uint sql_command = thd_sql_command(thd);
  6684. if (sql_command == SQLCOM_DROP_TABLE) {
  6685. /* MySQL calls this function in DROP TABLE though this table
  6686. handle may belong to another thd that is running a query. Let
  6687. us in that case skip any changes to the prebuilt struct. */
  6688. } else if ((lock_type == TL_READ && in_lock_tables)
  6689. || (lock_type == TL_READ_HIGH_PRIORITY && in_lock_tables)
  6690. || lock_type == TL_READ_WITH_SHARED_LOCKS
  6691. || lock_type == TL_READ_NO_INSERT
  6692. || (lock_type != TL_IGNORE
  6693. && sql_command != SQLCOM_SELECT)) {
  6694. /* The OR cases above are in this order:
  6695. 1) MySQL is doing LOCK TABLES ... READ LOCAL, or we
  6696. are processing a stored procedure or function, or
  6697. 2) (we do not know when TL_READ_HIGH_PRIORITY is used), or
  6698. 3) this is a SELECT ... IN SHARE MODE, or
  6699. 4) we are doing a complex SQL statement like
  6700. INSERT INTO ... SELECT ... and the logical logging (MySQL
  6701. binlog) requires the use of a locking read, or
  6702. MySQL is doing LOCK TABLES ... READ.
  6703. 5) we let InnoDB do locking reads for all SQL statements that
  6704. are not simple SELECTs; note that select_lock_type in this
  6705. case may get strengthened in ::external_lock() to LOCK_X.
  6706. Note that we MUST use a locking read in all data modifying
  6707. SQL statements, because otherwise the execution would not be
  6708. serializable, and also the results from the update could be
  6709. unexpected if an obsolete consistent read view would be
  6710. used. */
  6711. ulint isolation_level;
  6712. isolation_level = trx->isolation_level;
  6713. if ((srv_locks_unsafe_for_binlog
  6714. || isolation_level == TRX_ISO_READ_COMMITTED)
  6715. && isolation_level != TRX_ISO_SERIALIZABLE
  6716. && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
  6717. && (sql_command == SQLCOM_INSERT_SELECT
  6718. || sql_command == SQLCOM_UPDATE
  6719. || sql_command == SQLCOM_CREATE_TABLE)) {
  6720. /* If we either have innobase_locks_unsafe_for_binlog
  6721. option set or this session is using READ COMMITTED
  6722. isolation level and isolation level of the transaction
  6723. is not set to serializable and MySQL is doing
  6724. INSERT INTO...SELECT or UPDATE ... = (SELECT ...) or
  6725. CREATE ... SELECT... without FOR UPDATE or
  6726. IN SHARE MODE in select, then we use consistent
  6727. read for select. */
  6728. prebuilt->select_lock_type = LOCK_NONE;
  6729. prebuilt->stored_select_lock_type = LOCK_NONE;
  6730. } else if (sql_command == SQLCOM_CHECKSUM) {
  6731. /* Use consistent read for checksum table */
  6732. prebuilt->select_lock_type = LOCK_NONE;
  6733. prebuilt->stored_select_lock_type = LOCK_NONE;
  6734. } else {
  6735. prebuilt->select_lock_type = LOCK_S;
  6736. prebuilt->stored_select_lock_type = LOCK_S;
  6737. }
  6738. } else if (lock_type != TL_IGNORE) {
  6739. /* We set possible LOCK_X value in external_lock, not yet
  6740. here even if this would be SELECT ... FOR UPDATE */
  6741. prebuilt->select_lock_type = LOCK_NONE;
  6742. prebuilt->stored_select_lock_type = LOCK_NONE;
  6743. }
  6744. if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) {
  6745. /* Starting from 5.0.7, we weaken also the table locks
  6746. set at the start of a MySQL stored procedure call, just like
  6747. we weaken the locks set at the start of an SQL statement.
  6748. MySQL does set in_lock_tables TRUE there, but in reality
  6749. we do not need table locks to make the execution of a
  6750. single transaction stored procedure call deterministic
  6751. (if it does not use a consistent read). */
  6752. if (lock_type == TL_READ
  6753. && sql_command == SQLCOM_LOCK_TABLES) {
  6754. /* We come here if MySQL is processing LOCK TABLES
  6755. ... READ LOCAL. MyISAM under that table lock type
  6756. reads the table as it was at the time the lock was
  6757. granted (new inserts are allowed, but not seen by the
  6758. reader). To get a similar effect on an InnoDB table,
  6759. we must use LOCK TABLES ... READ. We convert the lock
  6760. type here, so that for InnoDB, READ LOCAL is
  6761. equivalent to READ. This will change the InnoDB
  6762. behavior in mysqldump, so that dumps of InnoDB tables
  6763. are consistent with dumps of MyISAM tables. */
  6764. lock_type = TL_READ_NO_INSERT;
  6765. }
  6766. /* If we are not doing a LOCK TABLE, DISCARD/IMPORT
  6767. TABLESPACE or TRUNCATE TABLE then allow multiple
  6768. writers. Note that ALTER TABLE uses a TL_WRITE_ALLOW_READ
  6769. < TL_WRITE_CONCURRENT_INSERT.
  6770. We especially allow multiple writers if MySQL is at the
  6771. start of a stored procedure call (SQLCOM_CALL) or a
  6772. stored function call (MySQL does have in_lock_tables
  6773. TRUE there). */
  6774. if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
  6775. && lock_type <= TL_WRITE)
  6776. && !(in_lock_tables
  6777. && sql_command == SQLCOM_LOCK_TABLES)
  6778. && !thd_tablespace_op(thd)
  6779. && sql_command != SQLCOM_TRUNCATE
  6780. && sql_command != SQLCOM_OPTIMIZE
  6781. && sql_command != SQLCOM_CREATE_TABLE) {
  6782. lock_type = TL_WRITE_ALLOW_WRITE;
  6783. }
  6784. /* In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
  6785. MySQL would use the lock TL_READ_NO_INSERT on t2, and that
  6786. would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
  6787. to t2. Convert the lock to a normal read lock to allow
  6788. concurrent inserts to t2.
  6789. We especially allow concurrent inserts if MySQL is at the
  6790. start of a stored procedure call (SQLCOM_CALL)
  6791. (MySQL does have thd_in_lock_tables() TRUE there). */
  6792. if (lock_type == TL_READ_NO_INSERT
  6793. && sql_command != SQLCOM_LOCK_TABLES) {
  6794. lock_type = TL_READ;
  6795. }
  6796. lock.type = lock_type;
  6797. }
  6798. *to++= &lock;
  6799. return(to);
  6800. }
  6801. /*******************************************************************************
  6802. Read the next autoinc value. Acquire the relevant locks before reading
  6803. the AUTOINC value. If SUCCESS then the table AUTOINC mutex will be locked
  6804. on return and all relevant locks acquired. */
  6805. UNIV_INTERN
  6806. ulint
  6807. ha_innobase::innobase_get_autoinc(
  6808. /*==============================*/
  6809. /* out: DB_SUCCESS or error code */
  6810. ulonglong* value) /* out: autoinc value */
  6811. {
  6812. *value = 0;
  6813. prebuilt->autoinc_error = innobase_lock_autoinc();
  6814. if (prebuilt->autoinc_error == DB_SUCCESS) {
  6815. /* Determine the first value of the interval */
  6816. *value = dict_table_autoinc_read(prebuilt->table);
  6817. /* It should have been initialized during open. */
  6818. ut_a(*value != 0);
  6819. }
  6820. return(prebuilt->autoinc_error);
  6821. }
  6822. /***********************************************************************
  6823. This function reads the global auto-inc counter. It doesn't use the
  6824. AUTOINC lock even if the lock mode is set to TRADITIONAL. */
  6825. UNIV_INTERN
  6826. ulonglong
  6827. ha_innobase::innobase_peek_autoinc(void)
  6828. /*====================================*/
  6829. /* out: the autoinc value */
  6830. {
  6831. ulonglong auto_inc;
  6832. dict_table_t* innodb_table;
  6833. ut_a(prebuilt != NULL);
  6834. ut_a(prebuilt->table != NULL);
  6835. innodb_table = prebuilt->table;
  6836. dict_table_autoinc_lock(innodb_table);
  6837. auto_inc = dict_table_autoinc_read(innodb_table);
  6838. ut_a(auto_inc > 0);
  6839. dict_table_autoinc_unlock(innodb_table);
  6840. return(auto_inc);
  6841. }
  6842. /*******************************************************************************
  6843. This function initializes the auto-inc counter if it has not been
  6844. initialized yet. This function does not change the value of the auto-inc
  6845. counter if it already has been initialized. Returns the value of the
  6846. auto-inc counter in *first_value, and ULONGLONG_MAX in *nb_reserved_values (as
  6847. we have a table-level lock). offset, increment, nb_desired_values are ignored.
  6848. *first_value is set to -1 if error (deadlock or lock wait timeout) */
  6849. UNIV_INTERN
  6850. void
  6851. ha_innobase::get_auto_increment(
  6852. /*============================*/
  6853. ulonglong offset, /* in: */
  6854. ulonglong increment, /* in: table autoinc increment */
  6855. ulonglong nb_desired_values, /* in: number of values reqd */
  6856. ulonglong *first_value, /* out: the autoinc value */
  6857. ulonglong *nb_reserved_values) /* out: count of reserved values */
  6858. {
  6859. trx_t* trx;
  6860. ulint error;
  6861. ulonglong autoinc = 0;
  6862. /* Prepare prebuilt->trx in the table handle */
  6863. update_thd(ha_thd());
  6864. error = innobase_get_autoinc(&autoinc);
  6865. if (error != DB_SUCCESS) {
  6866. *first_value = (~(ulonglong) 0);
  6867. return;
  6868. }
  6869. /* This is a hack, since nb_desired_values seems to be accurate only
  6870. for the first call to get_auto_increment() for multi-row INSERT and
  6871. meaningless for other statements e.g, LOAD etc. Subsequent calls to
  6872. this method for the same statement results in different values which
  6873. don't make sense. Therefore we store the value the first time we are
  6874. called and count down from that as rows are written (see write_row()).
  6875. */
  6876. trx = prebuilt->trx;
  6877. /* Note: We can't rely on *first_value since some MySQL engines,
  6878. in particular the partition engine, don't initialize it to 0 when
  6879. invoking this method. So we are not sure if it's guaranteed to
  6880. be 0 or not. */
  6881. /* Called for the first time ? */
  6882. if (trx->n_autoinc_rows == 0) {
  6883. trx->n_autoinc_rows = (ulint) nb_desired_values;
  6884. /* It's possible for nb_desired_values to be 0:
  6885. e.g., INSERT INTO T1(C) SELECT C FROM T2; */
  6886. if (nb_desired_values == 0) {
  6887. trx->n_autoinc_rows = 1;
  6888. }
  6889. set_if_bigger(*first_value, autoinc);
  6890. /* Not in the middle of a mult-row INSERT. */
  6891. } else if (prebuilt->autoinc_last_value == 0) {
  6892. set_if_bigger(*first_value, autoinc);
  6893. }
  6894. *nb_reserved_values = trx->n_autoinc_rows;
  6895. /* With old style AUTOINC locking we only update the table's
  6896. AUTOINC counter after attempting to insert the row. */
  6897. if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) {
  6898. ulonglong need;
  6899. ulonglong next_value;
  6900. ulonglong col_max_value;
  6901. /* We need the upper limit of the col type to check for
  6902. whether we update the table autoinc counter or not. */
  6903. col_max_value = innobase_get_int_col_max_value(
  6904. table->next_number_field);
  6905. need = *nb_reserved_values * increment;
  6906. /* Compute the last value in the interval */
  6907. next_value = innobase_next_autoinc(
  6908. *first_value, need, offset, col_max_value);
  6909. prebuilt->autoinc_last_value = next_value;
  6910. ut_a(prebuilt->autoinc_last_value >= *first_value);
  6911. /* Update the table autoinc variable */
  6912. dict_table_autoinc_update_if_greater(
  6913. prebuilt->table, prebuilt->autoinc_last_value);
  6914. } else {
  6915. /* This will force write_row() into attempting an update
  6916. of the table's AUTOINC counter. */
  6917. prebuilt->autoinc_last_value = 0;
  6918. }
  6919. /* The increment to be used to increase the AUTOINC value, we use
  6920. this in write_row() and update_row() to increase the autoinc counter
  6921. for columns that are filled by the user. We need the offset and
  6922. the increment. */
  6923. prebuilt->autoinc_offset = offset;
  6924. prebuilt->autoinc_increment = increment;
  6925. dict_table_autoinc_unlock(prebuilt->table);
  6926. }
  6927. /* See comment in handler.h */
  6928. UNIV_INTERN
  6929. int
  6930. ha_innobase::reset_auto_increment(
  6931. /*==============================*/
  6932. ulonglong value) /* in: new value for table autoinc */
  6933. {
  6934. DBUG_ENTER("ha_innobase::reset_auto_increment");
  6935. int error;
  6936. update_thd(ha_thd());
  6937. error = row_lock_table_autoinc_for_mysql(prebuilt);
  6938. if (error != DB_SUCCESS) {
  6939. error = convert_error_code_to_mysql(error,
  6940. prebuilt->table->flags,
  6941. user_thd);
  6942. DBUG_RETURN(error);
  6943. }
  6944. /* The next value can never be 0. */
  6945. if (value == 0) {
  6946. value = 1;
  6947. }
  6948. innobase_reset_autoinc(value);
  6949. DBUG_RETURN(0);
  6950. }
  6951. /* See comment in handler.cc */
  6952. UNIV_INTERN
  6953. bool
  6954. ha_innobase::get_error_message(int error, String *buf)
  6955. {
  6956. trx_t* trx = check_trx_exists(ha_thd());
  6957. buf->copy(trx->detailed_error, strlen(trx->detailed_error),
  6958. system_charset_info);
  6959. return(FALSE);
  6960. }
  6961. /***********************************************************************
  6962. Compares two 'refs'. A 'ref' is the (internal) primary key value of the row.
  6963. If there is no explicitly declared non-null unique key or a primary key, then
  6964. InnoDB internally uses the row id as the primary key. */
  6965. UNIV_INTERN
  6966. int
  6967. ha_innobase::cmp_ref(
  6968. /*=================*/
  6969. /* out: < 0 if ref1 < ref2, 0 if equal, else
  6970. > 0 */
  6971. const uchar* ref1, /* in: an (internal) primary key value in the
  6972. MySQL key value format */
  6973. const uchar* ref2) /* in: an (internal) primary key value in the
  6974. MySQL key value format */
  6975. {
  6976. enum_field_types mysql_type;
  6977. Field* field;
  6978. KEY_PART_INFO* key_part;
  6979. KEY_PART_INFO* key_part_end;
  6980. uint len1;
  6981. uint len2;
  6982. int result;
  6983. if (prebuilt->clust_index_was_generated) {
  6984. /* The 'ref' is an InnoDB row id */
  6985. return(memcmp(ref1, ref2, DATA_ROW_ID_LEN));
  6986. }
  6987. /* Do a type-aware comparison of primary key fields. PK fields
  6988. are always NOT NULL, so no checks for NULL are performed. */
  6989. key_part = table->key_info[table->s->primary_key].key_part;
  6990. key_part_end = key_part
  6991. + table->key_info[table->s->primary_key].key_parts;
  6992. for (; key_part != key_part_end; ++key_part) {
  6993. field = key_part->field;
  6994. mysql_type = field->type();
  6995. if (mysql_type == MYSQL_TYPE_TINY_BLOB
  6996. || mysql_type == MYSQL_TYPE_MEDIUM_BLOB
  6997. || mysql_type == MYSQL_TYPE_BLOB
  6998. || mysql_type == MYSQL_TYPE_LONG_BLOB) {
  6999. /* In the MySQL key value format, a column prefix of
  7000. a BLOB is preceded by a 2-byte length field */
  7001. len1 = innobase_read_from_2_little_endian(ref1);
  7002. len2 = innobase_read_from_2_little_endian(ref2);
  7003. ref1 += 2;
  7004. ref2 += 2;
  7005. result = ((Field_blob*)field)->cmp( ref1, len1,
  7006. ref2, len2);
  7007. } else {
  7008. result = field->key_cmp(ref1, ref2);
  7009. }
  7010. if (result) {
  7011. return(result);
  7012. }
  7013. ref1 += key_part->store_length;
  7014. ref2 += key_part->store_length;
  7015. }
  7016. return(0);
  7017. }
  7018. /***********************************************************************
  7019. Ask InnoDB if a query to a table can be cached. */
  7020. UNIV_INTERN
  7021. my_bool
  7022. ha_innobase::register_query_cache_table(
  7023. /*====================================*/
  7024. /* out: TRUE if query caching
  7025. of the table is permitted */
  7026. THD* thd, /* in: user thread handle */
  7027. char* table_key, /* in: concatenation of database name,
  7028. the null character '\0',
  7029. and the table name */
  7030. uint key_length, /* in: length of the full name, i.e.
  7031. len(dbname) + len(tablename) + 1 */
  7032. qc_engine_callback*
  7033. call_back, /* out: pointer to function for
  7034. checking if query caching
  7035. is permitted */
  7036. ulonglong *engine_data) /* in/out: data to call_back */
  7037. {
  7038. *call_back = innobase_query_caching_of_table_permitted;
  7039. *engine_data = 0;
  7040. return(innobase_query_caching_of_table_permitted(thd, table_key,
  7041. key_length,
  7042. engine_data));
  7043. }
  7044. UNIV_INTERN
  7045. char*
  7046. ha_innobase::get_mysql_bin_log_name()
  7047. {
  7048. return(trx_sys_mysql_bin_log_name);
  7049. }
  7050. UNIV_INTERN
  7051. ulonglong
  7052. ha_innobase::get_mysql_bin_log_pos()
  7053. {
  7054. /* trx... is ib_int64_t, which is a typedef for a 64-bit integer
  7055. (__int64 or longlong) so it's ok to cast it to ulonglong. */
  7056. return(trx_sys_mysql_bin_log_pos);
  7057. }
  7058. /**********************************************************************
  7059. This function is used to find the storage length in bytes of the first n
  7060. characters for prefix indexes using a multibyte character set. The function
  7061. finds charset information and returns length of prefix_len characters in the
  7062. index field in bytes.
  7063. NOTE: the prototype of this function is copied to data0type.c! If you change
  7064. this function, you MUST change also data0type.c! */
  7065. extern "C" UNIV_INTERN
  7066. ulint
  7067. innobase_get_at_most_n_mbchars(
  7068. /*===========================*/
  7069. /* out: number of bytes occupied by the first
  7070. n characters */
  7071. ulint charset_id, /* in: character set id */
  7072. ulint prefix_len, /* in: prefix length in bytes of the index
  7073. (this has to be divided by mbmaxlen to get the
  7074. number of CHARACTERS n in the prefix) */
  7075. ulint data_len, /* in: length of the string in bytes */
  7076. const char* str) /* in: character string */
  7077. {
  7078. ulint char_length; /* character length in bytes */
  7079. ulint n_chars; /* number of characters in prefix */
  7080. CHARSET_INFO* charset; /* charset used in the field */
  7081. charset = get_charset((uint) charset_id, MYF(MY_WME));
  7082. ut_ad(charset);
  7083. ut_ad(charset->mbmaxlen);
  7084. /* Calculate how many characters at most the prefix index contains */
  7085. n_chars = prefix_len / charset->mbmaxlen;
  7086. /* If the charset is multi-byte, then we must find the length of the
  7087. first at most n chars in the string. If the string contains less
  7088. characters than n, then we return the length to the end of the last
  7089. character. */
  7090. if (charset->mbmaxlen > 1) {
  7091. /* my_charpos() returns the byte length of the first n_chars
  7092. characters, or a value bigger than the length of str, if
  7093. there were not enough full characters in str.
  7094. Why does the code below work:
  7095. Suppose that we are looking for n UTF-8 characters.
  7096. 1) If the string is long enough, then the prefix contains at
  7097. least n complete UTF-8 characters + maybe some extra
  7098. characters + an incomplete UTF-8 character. No problem in
  7099. this case. The function returns the pointer to the
  7100. end of the nth character.
  7101. 2) If the string is not long enough, then the string contains
  7102. the complete value of a column, that is, only complete UTF-8
  7103. characters, and we can store in the column prefix index the
  7104. whole string. */
  7105. char_length = my_charpos(charset, str,
  7106. str + data_len, (int) n_chars);
  7107. if (char_length > data_len) {
  7108. char_length = data_len;
  7109. }
  7110. } else {
  7111. if (data_len < prefix_len) {
  7112. char_length = data_len;
  7113. } else {
  7114. char_length = prefix_len;
  7115. }
  7116. }
  7117. return(char_length);
  7118. }
  7119. /***********************************************************************
  7120. This function is used to prepare X/Open XA distributed transaction */
  7121. static
  7122. int
  7123. innobase_xa_prepare(
  7124. /*================*/
  7125. /* out: 0 or error number */
  7126. handlerton *hton,
  7127. THD* thd, /* in: handle to the MySQL thread of the user
  7128. whose XA transaction should be prepared */
  7129. bool all) /* in: TRUE - commit transaction
  7130. FALSE - the current SQL statement ended */
  7131. {
  7132. int error = 0;
  7133. trx_t* trx = check_trx_exists(thd);
  7134. DBUG_ASSERT(hton == innodb_hton_ptr);
  7135. if (thd_sql_command(thd) != SQLCOM_XA_PREPARE &&
  7136. (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
  7137. {
  7138. /* For ibbackup to work the order of transactions in binlog
  7139. and InnoDB must be the same. Consider the situation
  7140. thread1> prepare; write to binlog; ...
  7141. <context switch>
  7142. thread2> prepare; write to binlog; commit
  7143. thread1> ... commit
  7144. To ensure this will not happen we're taking the mutex on
  7145. prepare, and releasing it on commit.
  7146. Note: only do it for normal commits, done via ha_commit_trans.
  7147. If 2pc protocol is executed by external transaction
  7148. coordinator, it will be just a regular MySQL client
  7149. executing XA PREPARE and XA COMMIT commands.
  7150. In this case we cannot know how many minutes or hours
  7151. will be between XA PREPARE and XA COMMIT, and we don't want
  7152. to block for undefined period of time.
  7153. */
  7154. pthread_mutex_lock(&prepare_commit_mutex);
  7155. trx->active_trans = 2;
  7156. }
  7157. if (!THDVAR(thd, support_xa)) {
  7158. return(0);
  7159. }
  7160. thd_get_xid(thd, (MYSQL_XID*) &trx->xid);
  7161. /* Release a possible FIFO ticket and search latch. Since we will
  7162. reserve the kernel mutex, we have to release the search system latch
  7163. first to obey the latching order. */
  7164. innobase_release_stat_resources(trx);
  7165. if (trx->active_trans == 0 && trx->conc_state != TRX_NOT_STARTED) {
  7166. sql_print_error("trx->active_trans == 0, but trx->conc_state != "
  7167. "TRX_NOT_STARTED");
  7168. }
  7169. if (all
  7170. || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
  7171. /* We were instructed to prepare the whole transaction, or
  7172. this is an SQL statement end and autocommit is on */
  7173. ut_ad(trx->active_trans);
  7174. error = (int) trx_prepare_for_mysql(trx);
  7175. } else {
  7176. /* We just mark the SQL statement ended and do not do a
  7177. transaction prepare */
  7178. /* If we had reserved the auto-inc lock for some
  7179. table in this SQL statement we release it now */
  7180. row_unlock_table_autoinc_for_mysql(trx);
  7181. /* Store the current undo_no of the transaction so that we
  7182. know where to roll back if we have to roll back the next
  7183. SQL statement */
  7184. trx_mark_sql_stat_end(trx);
  7185. }
  7186. /* Tell the InnoDB server that there might be work for utility
  7187. threads: */
  7188. srv_active_wake_master_thread();
  7189. return(error);
  7190. }
  7191. /***********************************************************************
  7192. This function is used to recover X/Open XA distributed transactions */
  7193. static
  7194. int
  7195. innobase_xa_recover(
  7196. /*================*/
  7197. /* out: number of prepared transactions
  7198. stored in xid_list */
  7199. handlerton *hton,
  7200. XID* xid_list, /* in/out: prepared transactions */
  7201. uint len) /* in: number of slots in xid_list */
  7202. {
  7203. DBUG_ASSERT(hton == innodb_hton_ptr);
  7204. if (len == 0 || xid_list == NULL) {
  7205. return(0);
  7206. }
  7207. return(trx_recover_for_mysql(xid_list, len));
  7208. }
  7209. /***********************************************************************
  7210. This function is used to commit one X/Open XA distributed transaction
  7211. which is in the prepared state */
  7212. static
  7213. int
  7214. innobase_commit_by_xid(
  7215. /*===================*/
  7216. /* out: 0 or error number */
  7217. handlerton *hton,
  7218. XID* xid) /* in: X/Open XA transaction identification */
  7219. {
  7220. trx_t* trx;
  7221. DBUG_ASSERT(hton == innodb_hton_ptr);
  7222. trx = trx_get_trx_by_xid(xid);
  7223. if (trx) {
  7224. innobase_commit_low(trx);
  7225. return(XA_OK);
  7226. } else {
  7227. return(XAER_NOTA);
  7228. }
  7229. }
  7230. /***********************************************************************
  7231. This function is used to rollback one X/Open XA distributed transaction
  7232. which is in the prepared state */
  7233. static
  7234. int
  7235. innobase_rollback_by_xid(
  7236. /*=====================*/
  7237. /* out: 0 or error number */
  7238. handlerton *hton,
  7239. XID *xid) /* in: X/Open XA transaction identification */
  7240. {
  7241. trx_t* trx;
  7242. DBUG_ASSERT(hton == innodb_hton_ptr);
  7243. trx = trx_get_trx_by_xid(xid);
  7244. if (trx) {
  7245. return(innobase_rollback_trx(trx));
  7246. } else {
  7247. return(XAER_NOTA);
  7248. }
  7249. }
  7250. /***********************************************************************
  7251. Create a consistent view for a cursor based on current transaction
  7252. which is created if the corresponding MySQL thread still lacks one.
  7253. This consistent view is then used inside of MySQL when accessing records
  7254. using a cursor. */
  7255. static
  7256. void*
  7257. innobase_create_cursor_view(
  7258. /*========================*/
  7259. /* out: pointer to cursor view or NULL */
  7260. handlerton *hton, /* in: innobase hton */
  7261. THD* thd) /* in: user thread handle */
  7262. {
  7263. DBUG_ASSERT(hton == innodb_hton_ptr);
  7264. return(read_cursor_view_create_for_mysql(check_trx_exists(thd)));
  7265. }
  7266. /***********************************************************************
  7267. Close the given consistent cursor view of a transaction and restore
  7268. global read view to a transaction read view. Transaction is created if the
  7269. corresponding MySQL thread still lacks one. */
  7270. static
  7271. void
  7272. innobase_close_cursor_view(
  7273. /*=======================*/
  7274. handlerton *hton,
  7275. THD* thd, /* in: user thread handle */
  7276. void* curview)/* in: Consistent read view to be closed */
  7277. {
  7278. DBUG_ASSERT(hton == innodb_hton_ptr);
  7279. read_cursor_view_close_for_mysql(check_trx_exists(thd),
  7280. (cursor_view_t*) curview);
  7281. }
  7282. /***********************************************************************
  7283. Set the given consistent cursor view to a transaction which is created
  7284. if the corresponding MySQL thread still lacks one. If the given
  7285. consistent cursor view is NULL global read view of a transaction is
  7286. restored to a transaction read view. */
  7287. static
  7288. void
  7289. innobase_set_cursor_view(
  7290. /*=====================*/
  7291. handlerton *hton,
  7292. THD* thd, /* in: user thread handle */
  7293. void* curview)/* in: Consistent cursor view to be set */
  7294. {
  7295. DBUG_ASSERT(hton == innodb_hton_ptr);
  7296. read_cursor_set_for_mysql(check_trx_exists(thd),
  7297. (cursor_view_t*) curview);
  7298. }
  7299. UNIV_INTERN
  7300. bool
  7301. ha_innobase::check_if_incompatible_data(
  7302. HA_CREATE_INFO* info,
  7303. uint table_changes)
  7304. {
  7305. if (table_changes != IS_EQUAL_YES) {
  7306. return(COMPATIBLE_DATA_NO);
  7307. }
  7308. /* Check that auto_increment value was not changed */
  7309. if ((info->used_fields & HA_CREATE_USED_AUTO) &&
  7310. info->auto_increment_value != 0) {
  7311. return(COMPATIBLE_DATA_NO);
  7312. }
  7313. /* Check that row format didn't change */
  7314. if ((info->used_fields & HA_CREATE_USED_ROW_FORMAT) &&
  7315. get_row_type() != info->row_type) {
  7316. return(COMPATIBLE_DATA_NO);
  7317. }
  7318. /* Specifying KEY_BLOCK_SIZE requests a rebuild of the table. */
  7319. if (info->used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE) {
  7320. return(COMPATIBLE_DATA_NO);
  7321. }
  7322. return(COMPATIBLE_DATA_YES);
  7323. }
  7324. /****************************************************************
  7325. Validate the file format name and return its corresponding id. */
  7326. static
  7327. uint
  7328. innobase_file_format_name_lookup(
  7329. /*=============================*/
  7330. /* out: valid file format id*/
  7331. const char* format_name) /* in: pointer to file format name */
  7332. {
  7333. char* endp;
  7334. uint format_id;
  7335. ut_a(format_name != NULL);
  7336. /* The format name can contain the format id itself instead of
  7337. the name and we check for that. */
  7338. format_id = (uint) strtoul(format_name, &endp, 10);
  7339. /* Check for valid parse. */
  7340. if (*endp == '\0' && *format_name != '\0') {
  7341. if (format_id <= DICT_TF_FORMAT_MAX) {
  7342. return(format_id);
  7343. }
  7344. } else {
  7345. for (format_id = 0; format_id <= DICT_TF_FORMAT_MAX;
  7346. format_id++) {
  7347. const char* name;
  7348. name = trx_sys_file_format_id_to_name(format_id);
  7349. if (!innobase_strcasecmp(format_name, name)) {
  7350. return(format_id);
  7351. }
  7352. }
  7353. }
  7354. return(DICT_TF_FORMAT_MAX + 1);
  7355. }
  7356. /****************************************************************
  7357. Validate the file format check value, is it one of "on" or "off",
  7358. as a side effect it sets the srv_check_file_format_at_startup variable. */
  7359. static
  7360. bool
  7361. innobase_file_format_check_on_off(
  7362. /*==============================*/
  7363. /* out: true if config value one
  7364. of "on" or "off" */
  7365. const char* format_check) /* in: parameter value */
  7366. {
  7367. bool ret = true;
  7368. if (!innobase_strcasecmp(format_check, "off")) {
  7369. /* Set the value to disable checking. */
  7370. srv_check_file_format_at_startup = DICT_TF_FORMAT_MAX + 1;
  7371. } else if (!innobase_strcasecmp(format_check, "on")) {
  7372. /* Set the value to the lowest supported format. */
  7373. srv_check_file_format_at_startup = DICT_TF_FORMAT_51;
  7374. } else {
  7375. ret = FALSE;
  7376. }
  7377. return(ret);
  7378. }
  7379. /****************************************************************
  7380. Validate the file format check config parameters, as a side effect it
  7381. sets the srv_check_file_format_at_startup variable. */
  7382. static
  7383. bool
  7384. innobase_file_format_check_validate(
  7385. /*================================*/
  7386. /* out: true if valid config value */
  7387. const char* format_check) /* in: parameter value */
  7388. {
  7389. uint format_id;
  7390. bool ret = true;
  7391. format_id = innobase_file_format_name_lookup(format_check);
  7392. if (format_id < DICT_TF_FORMAT_MAX + 1) {
  7393. srv_check_file_format_at_startup = format_id;
  7394. } else {
  7395. ret = false;
  7396. }
  7397. return(ret);
  7398. }
  7399. /*****************************************************************
  7400. Check if it is a valid file format. This function is registered as
  7401. a callback with MySQL. */
  7402. static
  7403. int
  7404. innodb_file_format_name_validate(
  7405. /*=============================*/
  7406. /* out: 0 for valid file
  7407. format */
  7408. THD* thd, /* in: thread handle */
  7409. struct st_mysql_sys_var* var, /* in: pointer to system
  7410. variable */
  7411. void* save, /* out: immediate result
  7412. for update function */
  7413. struct st_mysql_value* value) /* in: incoming string */
  7414. {
  7415. const char* file_format_input;
  7416. char buff[STRING_BUFFER_USUAL_SIZE];
  7417. int len = sizeof(buff);
  7418. ut_a(save != NULL);
  7419. ut_a(value != NULL);
  7420. file_format_input = value->val_str(value, buff, &len);
  7421. if (file_format_input != NULL) {
  7422. uint format_id;
  7423. format_id = innobase_file_format_name_lookup(
  7424. file_format_input);
  7425. if (format_id <= DICT_TF_FORMAT_MAX) {
  7426. *(uint*) save = format_id;
  7427. return(0);
  7428. }
  7429. }
  7430. return(1);
  7431. }
  7432. /********************************************************************
  7433. Update the system variable innodb_file_format using the "saved"
  7434. value. This function is registered as a callback with MySQL. */
  7435. static
  7436. void
  7437. innodb_file_format_name_update(
  7438. /*===========================*/
  7439. THD* thd, /* in: thread handle */
  7440. struct st_mysql_sys_var* var, /* in: pointer to
  7441. system variable */
  7442. void* var_ptr, /* out: where the
  7443. formal string goes */
  7444. const void* save) /* in: immediate result
  7445. from check function */
  7446. {
  7447. ut_a(var_ptr != NULL);
  7448. ut_a(save != NULL);
  7449. ut_a((*(const uint*) save) <= DICT_TF_FORMAT_MAX);
  7450. srv_file_format = *(const uint*) save;
  7451. *(const char**) var_ptr
  7452. = trx_sys_file_format_id_to_name(srv_file_format);
  7453. }
  7454. /*****************************************************************
  7455. Check if valid argument to innodb_file_format_check. This
  7456. function is registered as a callback with MySQL. */
  7457. static
  7458. int
  7459. innodb_file_format_check_validate(
  7460. /*==============================*/
  7461. /* out: 0 for valid file
  7462. format */
  7463. THD* thd, /* in: thread handle */
  7464. struct st_mysql_sys_var* var, /* in: pointer to system
  7465. variable */
  7466. void* save, /* out: immediate result
  7467. for update function */
  7468. struct st_mysql_value* value) /* in: incoming string */
  7469. {
  7470. const char* file_format_input;
  7471. char buff[STRING_BUFFER_USUAL_SIZE];
  7472. int len = sizeof(buff);
  7473. ut_a(save != NULL);
  7474. ut_a(value != NULL);
  7475. file_format_input = value->val_str(value, buff, &len);
  7476. if (file_format_input != NULL) {
  7477. /* Check if user set on/off, we want to print a suitable
  7478. message if they did so. */
  7479. if (innobase_file_format_check_on_off(file_format_input)) {
  7480. sql_print_warning(
  7481. "InnoDB: invalid innodb_file_format_check "
  7482. "value; on/off can only be set at startup or "
  7483. "in the configuration file");
  7484. } else if (innobase_file_format_check_validate(
  7485. file_format_input)) {
  7486. uint format_id;
  7487. format_id = innobase_file_format_name_lookup(
  7488. file_format_input);
  7489. ut_a(format_id <= DICT_TF_FORMAT_MAX);
  7490. *(uint*) save = format_id;
  7491. return(0);
  7492. } else {
  7493. sql_print_warning(
  7494. "InnoDB: invalid innodb_file_format_check "
  7495. "value; can be any format up to %s "
  7496. "or its equivalent numeric id",
  7497. trx_sys_file_format_id_to_name(
  7498. DICT_TF_FORMAT_MAX));
  7499. }
  7500. }
  7501. return(1);
  7502. }
  7503. /********************************************************************
  7504. Update the system variable innodb_file_format_check using the "saved"
  7505. value. This function is registered as a callback with MySQL. */
  7506. static
  7507. void
  7508. innodb_file_format_check_update(
  7509. /*============================*/
  7510. THD* thd, /* in: thread handle */
  7511. struct st_mysql_sys_var* var, /* in: pointer to
  7512. system variable */
  7513. void* var_ptr, /* out: where the
  7514. formal string goes */
  7515. const void* save) /* in: immediate result
  7516. from check function */
  7517. {
  7518. uint format_id;
  7519. ut_a(save != NULL);
  7520. ut_a(var_ptr != NULL);
  7521. format_id = *(const uint*) save;
  7522. /* Update the max format id in the system tablespace. */
  7523. if (trx_sys_file_format_max_set(format_id, (const char**) var_ptr)) {
  7524. ut_print_timestamp(stderr);
  7525. fprintf(stderr,
  7526. " [Info] InnoDB: the file format in the system "
  7527. "tablespace is now set to %s.\n", *(char**) var_ptr);
  7528. }
  7529. }
  7530. static int show_innodb_vars(THD *thd, SHOW_VAR *var, char *buff)
  7531. {
  7532. innodb_export_status();
  7533. var->type= SHOW_ARRAY;
  7534. var->value= (char *) &innodb_status_variables;
  7535. return 0;
  7536. }
  7537. static SHOW_VAR innodb_status_variables_export[]= {
  7538. {"Innodb", (char*) &show_innodb_vars, SHOW_FUNC},
  7539. {NullS, NullS, SHOW_LONG}
  7540. };
  7541. static struct st_mysql_storage_engine innobase_storage_engine=
  7542. { MYSQL_HANDLERTON_INTERFACE_VERSION };
  7543. /* plugin options */
  7544. static MYSQL_SYSVAR_BOOL(checksums, innobase_use_checksums,
  7545. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  7546. "Enable InnoDB checksums validation (enabled by default). "
  7547. "Disable with --skip-innodb-checksums.",
  7548. NULL, NULL, TRUE);
  7549. static MYSQL_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
  7550. PLUGIN_VAR_READONLY,
  7551. "The common part for InnoDB table spaces.",
  7552. NULL, NULL, NULL);
  7553. static MYSQL_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite,
  7554. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  7555. "Enable InnoDB doublewrite buffer (enabled by default). "
  7556. "Disable with --skip-innodb-doublewrite.",
  7557. NULL, NULL, TRUE);
  7558. static MYSQL_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
  7559. PLUGIN_VAR_OPCMDARG,
  7560. "Speeds up the shutdown process of the InnoDB storage engine. Possible "
  7561. "values are 0, 1 (faster)"
  7562. /*
  7563. NetWare can't close unclosed files, can't automatically kill remaining
  7564. threads, etc, so on this OS we disable the crash-like InnoDB shutdown.
  7565. */
  7566. IF_NETWARE("", " or 2 (fastest - crash-like)")
  7567. ".",
  7568. NULL, NULL, 1, 0, IF_NETWARE(1,2), 0);
  7569. static MYSQL_SYSVAR_BOOL(file_per_table, srv_file_per_table,
  7570. PLUGIN_VAR_NOCMDARG,
  7571. "Stores each InnoDB table to an .ibd file in the database dir.",
  7572. NULL, NULL, FALSE);
  7573. static MYSQL_SYSVAR_STR(file_format, innobase_file_format_name,
  7574. PLUGIN_VAR_RQCMDARG,
  7575. "File format to use for new tables in .ibd files.",
  7576. innodb_file_format_name_validate,
  7577. innodb_file_format_name_update, "Antelope");
  7578. static MYSQL_SYSVAR_STR(file_format_check, innobase_file_format_check,
  7579. PLUGIN_VAR_OPCMDARG,
  7580. "The highest file format in the tablespace.",
  7581. innodb_file_format_check_validate,
  7582. innodb_file_format_check_update,
  7583. "on");
  7584. static MYSQL_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
  7585. PLUGIN_VAR_OPCMDARG,
  7586. "Set to 0 (write and flush once per second),"
  7587. " 1 (write and flush at each commit)"
  7588. " or 2 (write at commit, flush once per second).",
  7589. NULL, NULL, 1, 0, 2, 0);
  7590. static MYSQL_SYSVAR_STR(flush_method, innobase_unix_file_flush_method,
  7591. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7592. "With which method to flush data.", NULL, NULL, NULL);
  7593. static MYSQL_SYSVAR_BOOL(locks_unsafe_for_binlog, innobase_locks_unsafe_for_binlog,
  7594. PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
  7595. "Force InnoDB to not use next-key locking, to use only row-level locking.",
  7596. NULL, NULL, FALSE);
  7597. #ifdef UNIV_LOG_ARCHIVE
  7598. static MYSQL_SYSVAR_STR(log_arch_dir, innobase_log_arch_dir,
  7599. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7600. "Where full logs should be archived.", NULL, NULL, NULL);
  7601. static MYSQL_SYSVAR_BOOL(log_archive, innobase_log_archive,
  7602. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  7603. "Set to 1 if you want to have logs archived.", NULL, NULL, FALSE);
  7604. #endif /* UNIV_LOG_ARCHIVE */
  7605. static MYSQL_SYSVAR_STR(log_group_home_dir, innobase_log_group_home_dir,
  7606. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7607. "Path to InnoDB log files.", NULL, NULL, NULL);
  7608. static MYSQL_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
  7609. PLUGIN_VAR_RQCMDARG,
  7610. "Percentage of dirty pages allowed in bufferpool.",
  7611. NULL, NULL, 90, 0, 100, 0);
  7612. static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
  7613. PLUGIN_VAR_RQCMDARG,
  7614. "Desired maximum length of the purge queue (0 = no limit)",
  7615. NULL, NULL, 0, 0, ~0L, 0);
  7616. static MYSQL_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
  7617. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  7618. "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
  7619. NULL, NULL, FALSE);
  7620. static MYSQL_SYSVAR_BOOL(status_file, innobase_create_status_file,
  7621. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_NOSYSVAR,
  7622. "Enable SHOW INNODB STATUS output in the innodb_status.<pid> file",
  7623. NULL, NULL, FALSE);
  7624. static MYSQL_SYSVAR_BOOL(stats_on_metadata, innobase_stats_on_metadata,
  7625. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_NOSYSVAR,
  7626. "Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)",
  7627. NULL, NULL, TRUE);
  7628. static MYSQL_SYSVAR_ULONGLONG(stats_sample_pages, srv_stats_sample_pages,
  7629. PLUGIN_VAR_RQCMDARG,
  7630. "The number of index pages to sample when calculating statistics (default 8)",
  7631. NULL, NULL, 8, 1, ~0ULL, 0);
  7632. static MYSQL_SYSVAR_BOOL(adaptive_hash_index, innobase_adaptive_hash_index,
  7633. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  7634. "Enable InnoDB adaptive hash index (enabled by default). "
  7635. "Disable with --skip-innodb-adaptive-hash-index.",
  7636. NULL, NULL, TRUE);
  7637. static MYSQL_SYSVAR_ULONG(replication_delay, srv_replication_delay,
  7638. PLUGIN_VAR_RQCMDARG,
  7639. "Replication thread delay (ms) on the slave server if "
  7640. "innodb_thread_concurrency is reached (0 by default)",
  7641. NULL, NULL, 0, 0, ~0UL, 0);
  7642. static MYSQL_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
  7643. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7644. "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.",
  7645. NULL, NULL, 1*1024*1024L, 512*1024L, ~0L, 1024);
  7646. static MYSQL_SYSVAR_ULONG(autoextend_increment, srv_auto_extend_increment,
  7647. PLUGIN_VAR_RQCMDARG,
  7648. "Data file autoextend increment in megabytes",
  7649. NULL, NULL, 8L, 1L, 1000L, 0);
  7650. static MYSQL_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
  7651. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7652. "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
  7653. NULL, NULL, 8*1024*1024L, 5*1024*1024L, LONGLONG_MAX, 1024*1024L);
  7654. static MYSQL_SYSVAR_ULONG(commit_concurrency, srv_commit_concurrency,
  7655. PLUGIN_VAR_RQCMDARG,
  7656. "Helps in performance tuning in heavily concurrent environments.",
  7657. NULL, NULL, 0, 0, 1000, 0);
  7658. static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter,
  7659. PLUGIN_VAR_RQCMDARG,
  7660. "Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket",
  7661. NULL, NULL, 500L, 1L, ~0L, 0);
  7662. static MYSQL_SYSVAR_LONG(file_io_threads, innobase_file_io_threads,
  7663. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7664. "Number of file I/O threads in InnoDB.",
  7665. NULL, NULL, 4, 4, 64, 0);
  7666. static MYSQL_SYSVAR_LONG(force_recovery, innobase_force_recovery,
  7667. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7668. "Helps to save your data in case the disk image of the database becomes corrupt.",
  7669. NULL, NULL, 0, 0, 6, 0);
  7670. static MYSQL_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
  7671. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7672. "The size of the buffer which InnoDB uses to write log to the log files on disk.",
  7673. NULL, NULL, 1024*1024L, 256*1024L, ~0L, 1024);
  7674. static MYSQL_SYSVAR_LONGLONG(log_file_size, innobase_log_file_size,
  7675. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7676. "Size of each log file in a log group.",
  7677. NULL, NULL, 5*1024*1024L, 1*1024*1024L, LONGLONG_MAX, 1024*1024L);
  7678. static MYSQL_SYSVAR_LONG(log_files_in_group, innobase_log_files_in_group,
  7679. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7680. "Number of log files in the log group. InnoDB writes to the files in a circular fashion. Value 3 is recommended here.",
  7681. NULL, NULL, 2, 2, 100, 0);
  7682. static MYSQL_SYSVAR_LONG(mirrored_log_groups, innobase_mirrored_log_groups,
  7683. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7684. "Number of identical copies of log groups we keep for the database. Currently this should be set to 1.",
  7685. NULL, NULL, 1, 1, 10, 0);
  7686. static MYSQL_SYSVAR_LONG(open_files, innobase_open_files,
  7687. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7688. "How many files at the maximum InnoDB keeps open at the same time.",
  7689. NULL, NULL, 300L, 10L, ~0L, 0);
  7690. static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
  7691. PLUGIN_VAR_RQCMDARG,
  7692. "Count of spin-loop rounds in InnoDB mutexes",
  7693. NULL, NULL, 20L, 0L, ~0L, 0);
  7694. static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
  7695. PLUGIN_VAR_RQCMDARG,
  7696. "Helps in performance tuning in heavily concurrent environments. Sets the maximum number of threads allowed inside InnoDB. Value 0 will disable the thread throttling.",
  7697. NULL, NULL, 8, 0, 1000, 0);
  7698. static MYSQL_SYSVAR_ULONG(thread_sleep_delay, srv_thread_sleep_delay,
  7699. PLUGIN_VAR_RQCMDARG,
  7700. "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0 disable a sleep",
  7701. NULL, NULL, 10000L, 0L, ~0L, 0);
  7702. static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path,
  7703. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7704. "Path to individual files and their sizes.",
  7705. NULL, NULL, NULL);
  7706. static MYSQL_SYSVAR_LONG(autoinc_lock_mode, innobase_autoinc_lock_mode,
  7707. PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  7708. "The AUTOINC lock modes supported by InnoDB: "
  7709. "0 => Old style AUTOINC locking (for backward"
  7710. " compatibility) "
  7711. "1 => New style AUTOINC locking "
  7712. "2 => No AUTOINC locking (unsafe for SBR)",
  7713. NULL, NULL,
  7714. AUTOINC_NEW_STYLE_LOCKING, /* Default setting */
  7715. AUTOINC_OLD_STYLE_LOCKING, /* Minimum value */
  7716. AUTOINC_NO_LOCKING, 0); /* Maximum value */
  7717. static MYSQL_SYSVAR_STR(version, innodb_version_str,
  7718. PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_READONLY,
  7719. "InnoDB version", NULL, NULL, INNODB_VERSION_STR);
  7720. static struct st_mysql_sys_var* innobase_system_variables[]= {
  7721. MYSQL_SYSVAR(additional_mem_pool_size),
  7722. MYSQL_SYSVAR(autoextend_increment),
  7723. MYSQL_SYSVAR(buffer_pool_size),
  7724. MYSQL_SYSVAR(checksums),
  7725. MYSQL_SYSVAR(commit_concurrency),
  7726. MYSQL_SYSVAR(concurrency_tickets),
  7727. MYSQL_SYSVAR(data_file_path),
  7728. MYSQL_SYSVAR(data_home_dir),
  7729. MYSQL_SYSVAR(doublewrite),
  7730. MYSQL_SYSVAR(fast_shutdown),
  7731. MYSQL_SYSVAR(file_io_threads),
  7732. MYSQL_SYSVAR(file_per_table),
  7733. MYSQL_SYSVAR(file_format),
  7734. MYSQL_SYSVAR(file_format_check),
  7735. MYSQL_SYSVAR(flush_log_at_trx_commit),
  7736. MYSQL_SYSVAR(flush_method),
  7737. MYSQL_SYSVAR(force_recovery),
  7738. MYSQL_SYSVAR(locks_unsafe_for_binlog),
  7739. MYSQL_SYSVAR(lock_wait_timeout),
  7740. #ifdef UNIV_LOG_ARCHIVE
  7741. MYSQL_SYSVAR(log_arch_dir),
  7742. MYSQL_SYSVAR(log_archive),
  7743. #endif /* UNIV_LOG_ARCHIVE */
  7744. MYSQL_SYSVAR(log_buffer_size),
  7745. MYSQL_SYSVAR(log_file_size),
  7746. MYSQL_SYSVAR(log_files_in_group),
  7747. MYSQL_SYSVAR(log_group_home_dir),
  7748. MYSQL_SYSVAR(max_dirty_pages_pct),
  7749. MYSQL_SYSVAR(max_purge_lag),
  7750. MYSQL_SYSVAR(mirrored_log_groups),
  7751. MYSQL_SYSVAR(open_files),
  7752. MYSQL_SYSVAR(rollback_on_timeout),
  7753. MYSQL_SYSVAR(stats_on_metadata),
  7754. MYSQL_SYSVAR(stats_sample_pages),
  7755. MYSQL_SYSVAR(adaptive_hash_index),
  7756. MYSQL_SYSVAR(replication_delay),
  7757. MYSQL_SYSVAR(status_file),
  7758. MYSQL_SYSVAR(strict_mode),
  7759. MYSQL_SYSVAR(support_xa),
  7760. MYSQL_SYSVAR(sync_spin_loops),
  7761. MYSQL_SYSVAR(table_locks),
  7762. MYSQL_SYSVAR(thread_concurrency),
  7763. MYSQL_SYSVAR(thread_sleep_delay),
  7764. MYSQL_SYSVAR(autoinc_lock_mode),
  7765. MYSQL_SYSVAR(version),
  7766. NULL
  7767. };
  7768. #ifdef MYSQL_DYNAMIC_PLUGIN
  7769. struct st_mysql_sys_var
  7770. {
  7771. MYSQL_PLUGIN_VAR_HEADER;
  7772. void* value;
  7773. };
  7774. struct param_mapping
  7775. {
  7776. const char* server; /* Parameter name in the server. */
  7777. const char* plugin; /* Paramater name in the plugin. */
  7778. };
  7779. /********************************************************************
  7780. Match the parameters from the static and dynamic versions. */
  7781. static
  7782. bool
  7783. innobase_match_parameter(
  7784. /*=====================*/
  7785. /* out: true if names match */
  7786. const char* from_server, /* in: variable name from server */
  7787. const char* from_plugin) /* in: variable name from plugin */
  7788. {
  7789. static const param_mapping param_map[] = {
  7790. {"use_adaptive_hash_indexes", "adaptive_hash_index"}
  7791. };
  7792. if (strcmp(from_server, from_plugin) == 0) {
  7793. return(true);
  7794. }
  7795. const param_mapping* param = param_map;
  7796. int n_elems = sizeof(param_map) / sizeof(param_map[0]);
  7797. for (int i = 0; i < n_elems; ++i, ++param) {
  7798. if (strcmp(param->server, from_server) == 0
  7799. && strcmp(param->plugin, from_plugin) == 0) {
  7800. return(true);
  7801. }
  7802. }
  7803. return(false);
  7804. }
  7805. /********************************************************************
  7806. Copy InnoDB system variables from the static InnoDB to the dynamic
  7807. plugin. */
  7808. static
  7809. bool
  7810. innodb_plugin_init(void)
  7811. /*====================*/
  7812. /* out: TRUE if the dynamic InnoDB plugin should start */
  7813. {
  7814. #if !MYSQL_STORAGE_ENGINE_PLUGIN
  7815. #error "MYSQL_STORAGE_ENGINE_PLUGIN must be nonzero."
  7816. #endif
  7817. switch (builtin_innobase_plugin) {
  7818. case 0:
  7819. return(true);
  7820. case MYSQL_STORAGE_ENGINE_PLUGIN:
  7821. break;
  7822. default:
  7823. return(false);
  7824. }
  7825. /* Copy the system variables. */
  7826. struct st_mysql_plugin* builtin;
  7827. struct st_mysql_sys_var** sta; /* static parameters */
  7828. struct st_mysql_sys_var** dyn; /* dynamic parameters */
  7829. builtin = (struct st_mysql_plugin*) &builtin_innobase_plugin;
  7830. for (sta = builtin->system_vars; *sta != NULL; sta++) {
  7831. /* do not copy session variables */
  7832. if ((*sta)->flags & PLUGIN_VAR_THDLOCAL) {
  7833. continue;
  7834. }
  7835. for (dyn = innobase_system_variables; *dyn != NULL; dyn++) {
  7836. if (innobase_match_parameter((*sta)->name,
  7837. (*dyn)->name)) {
  7838. /* found the corresponding parameter */
  7839. /* check if the flags are the same,
  7840. ignoring differences in the READONLY flag;
  7841. e.g. we are not copying string variable to
  7842. an integer one */
  7843. if (((*sta)->flags & ~PLUGIN_VAR_READONLY)
  7844. != ((*dyn)->flags & ~PLUGIN_VAR_READONLY)) {
  7845. fprintf(stderr,
  7846. "InnoDB: %s in static InnoDB "
  7847. "(flags=0x%x) differs from "
  7848. "%s in dynamic InnoDB "
  7849. "(flags=0x%x)\n",
  7850. (*sta)->name, (*sta)->flags,
  7851. (*dyn)->name, (*dyn)->flags);
  7852. /* we could break; here leaving this
  7853. parameter uncopied */
  7854. return(false);
  7855. }
  7856. /* assign the value of the static parameter
  7857. to the dynamic one, according to their type */
  7858. #define COPY_VAR(label, type) \
  7859. case label: \
  7860. *(type*)(*dyn)->value = *(type*)(*sta)->value; \
  7861. break;
  7862. switch ((*sta)->flags
  7863. & ~(PLUGIN_VAR_MASK
  7864. | PLUGIN_VAR_UNSIGNED)) {
  7865. COPY_VAR(PLUGIN_VAR_BOOL, char);
  7866. COPY_VAR(PLUGIN_VAR_INT, int);
  7867. COPY_VAR(PLUGIN_VAR_LONG, long);
  7868. COPY_VAR(PLUGIN_VAR_LONGLONG, long long);
  7869. COPY_VAR(PLUGIN_VAR_STR, char*);
  7870. default:
  7871. fprintf(stderr,
  7872. "InnoDB: unknown flags "
  7873. "0x%x for %s\n",
  7874. (*sta)->flags, (*sta)->name);
  7875. }
  7876. /* Make the static InnoDB variable point to
  7877. the dynamic one */
  7878. (*sta)->value = (*dyn)->value;
  7879. break;
  7880. }
  7881. }
  7882. }
  7883. return(true);
  7884. }
  7885. #endif /* MYSQL_DYNAMIC_PLUGIN */
  7886. mysql_declare_plugin(innobase)
  7887. {
  7888. MYSQL_STORAGE_ENGINE_PLUGIN,
  7889. &innobase_storage_engine,
  7890. innobase_hton_name,
  7891. "Innobase Oy",
  7892. "Supports transactions, row-level locking, and foreign keys",
  7893. PLUGIN_LICENSE_GPL,
  7894. innobase_init, /* Plugin Init */
  7895. NULL, /* Plugin Deinit */
  7896. INNODB_VERSION_SHORT,
  7897. innodb_status_variables_export,/* status variables */
  7898. innobase_system_variables, /* system variables */
  7899. NULL /* reserved */
  7900. },
  7901. i_s_innodb_trx,
  7902. i_s_innodb_locks,
  7903. i_s_innodb_lock_waits,
  7904. i_s_innodb_cmp,
  7905. i_s_innodb_cmp_reset,
  7906. i_s_innodb_cmpmem,
  7907. i_s_innodb_cmpmem_reset
  7908. mysql_declare_plugin_end;
  7909. #ifdef UNIV_COMPILE_TEST_FUNCS
  7910. typedef struct innobase_convert_name_test_struct {
  7911. char* buf;
  7912. ulint buflen;
  7913. const char* id;
  7914. ulint idlen;
  7915. void* thd;
  7916. ibool file_id;
  7917. const char* expected;
  7918. } innobase_convert_name_test_t;
  7919. void
  7920. test_innobase_convert_name()
  7921. {
  7922. char buf[1024];
  7923. ulint i;
  7924. innobase_convert_name_test_t test_input[] = {
  7925. {buf, sizeof(buf), "abcd", 4, NULL, TRUE, "\"abcd\""},
  7926. {buf, 7, "abcd", 4, NULL, TRUE, "\"abcd\""},
  7927. {buf, 6, "abcd", 4, NULL, TRUE, "\"abcd\""},
  7928. {buf, 5, "abcd", 4, NULL, TRUE, "\"abc\""},
  7929. {buf, 4, "abcd", 4, NULL, TRUE, "\"ab\""},
  7930. {buf, sizeof(buf), "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  7931. {buf, 9, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  7932. {buf, 8, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  7933. {buf, 7, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
  7934. {buf, 6, "ab@0060cd", 9, NULL, TRUE, "\"ab`c\""},
  7935. {buf, 5, "ab@0060cd", 9, NULL, TRUE, "\"ab`\""},
  7936. {buf, 4, "ab@0060cd", 9, NULL, TRUE, "\"ab\""},
  7937. {buf, sizeof(buf), "ab\"cd", 5, NULL, TRUE,
  7938. "\"#mysql50#ab\"\"cd\""},
  7939. {buf, 17, "ab\"cd", 5, NULL, TRUE,
  7940. "\"#mysql50#ab\"\"cd\""},
  7941. {buf, 16, "ab\"cd", 5, NULL, TRUE,
  7942. "\"#mysql50#ab\"\"c\""},
  7943. {buf, 15, "ab\"cd", 5, NULL, TRUE,
  7944. "\"#mysql50#ab\"\"\""},
  7945. {buf, 14, "ab\"cd", 5, NULL, TRUE,
  7946. "\"#mysql50#ab\""},
  7947. {buf, 13, "ab\"cd", 5, NULL, TRUE,
  7948. "\"#mysql50#ab\""},
  7949. {buf, 12, "ab\"cd", 5, NULL, TRUE,
  7950. "\"#mysql50#a\""},
  7951. {buf, 11, "ab\"cd", 5, NULL, TRUE,
  7952. "\"#mysql50#\""},
  7953. {buf, 10, "ab\"cd", 5, NULL, TRUE,
  7954. "\"#mysql50\""},
  7955. {buf, sizeof(buf), "ab/cd", 5, NULL, TRUE, "\"ab\".\"cd\""},
  7956. {buf, 9, "ab/cd", 5, NULL, TRUE, "\"ab\".\"cd\""},
  7957. {buf, 8, "ab/cd", 5, NULL, TRUE, "\"ab\".\"c\""},
  7958. {buf, 7, "ab/cd", 5, NULL, TRUE, "\"ab\".\"\""},
  7959. {buf, 6, "ab/cd", 5, NULL, TRUE, "\"ab\"."},
  7960. {buf, 5, "ab/cd", 5, NULL, TRUE, "\"ab\"."},
  7961. {buf, 4, "ab/cd", 5, NULL, TRUE, "\"ab\""},
  7962. {buf, 3, "ab/cd", 5, NULL, TRUE, "\"a\""},
  7963. {buf, 2, "ab/cd", 5, NULL, TRUE, "\"\""},
  7964. /* XXX probably "" is a better result in this case
  7965. {buf, 1, "ab/cd", 5, NULL, TRUE, "."},
  7966. */
  7967. {buf, 0, "ab/cd", 5, NULL, TRUE, ""},
  7968. };
  7969. for (i = 0; i < sizeof(test_input) / sizeof(test_input[0]); i++) {
  7970. char* end;
  7971. ibool ok = TRUE;
  7972. size_t res_len;
  7973. fprintf(stderr, "TESTING %lu, %s, %lu, %s\n",
  7974. test_input[i].buflen,
  7975. test_input[i].id,
  7976. test_input[i].idlen,
  7977. test_input[i].expected);
  7978. end = innobase_convert_name(
  7979. test_input[i].buf,
  7980. test_input[i].buflen,
  7981. test_input[i].id,
  7982. test_input[i].idlen,
  7983. test_input[i].thd,
  7984. test_input[i].file_id);
  7985. res_len = (size_t) (end - test_input[i].buf);
  7986. if (res_len != strlen(test_input[i].expected)) {
  7987. fprintf(stderr, "unexpected len of the result: %u, "
  7988. "expected: %u\n", (unsigned) res_len,
  7989. (unsigned) strlen(test_input[i].expected));
  7990. ok = FALSE;
  7991. }
  7992. if (memcmp(test_input[i].buf,
  7993. test_input[i].expected,
  7994. strlen(test_input[i].expected)) != 0
  7995. || !ok) {
  7996. fprintf(stderr, "unexpected result: %.*s, "
  7997. "expected: %s\n", (int) res_len,
  7998. test_input[i].buf,
  7999. test_input[i].expected);
  8000. ok = FALSE;
  8001. }
  8002. if (ok) {
  8003. fprintf(stderr, "OK: res: %.*s\n\n", (int) res_len,
  8004. buf);
  8005. } else {
  8006. fprintf(stderr, "FAILED\n\n");
  8007. return;
  8008. }
  8009. }
  8010. }
  8011. #endif /* UNIV_COMPILE_TEST_FUNCS */