diff options
author | unknown <monty@mishka.local> | 2004-09-15 22:10:31 +0300 |
---|---|---|
committer | unknown <monty@mishka.local> | 2004-09-15 22:10:31 +0300 |
commit | ffc0d185da3c80f713b541cb52934712c24ce8cb (patch) | |
tree | d4323a7f81c07c98095c922e124755d6ac3253b8 /sql/ha_innodb.cc | |
parent | b15004a800770c3bdfc85f69c86629573669e1d0 (diff) | |
download | mariadb-git-ffc0d185da3c80f713b541cb52934712c24ce8cb.tar.gz |
Added options --auto-increment-increment and --auto-increment-offset.
This allows one to setup a master <-> master replication with non conflicting auto-increment series.
Cleaned up binary log code to make it easyer to add new state variables.
Added simpler 'upper level' logic for artificial events (events that should not cause cleanups on slave).
Simplified binary log handling.
Changed how auto_increment works together with to SET INSERT_ID=# to make it more predictable: Now the inserted rows in a multi-row statement are set independent of the existing rows in the table. (Before only InnoDB did this correctly)
mysql-test/r/mix_innodb_myisam_binlog.result:
Disable End_log_pos column from 'show binlog events' as this is now different from before
mysql-test/t/mix_innodb_myisam_binlog.test:
Disable End_log_pos column from 'show binlog events' as this is now different from before
sql/ha_berkeley.cc:
Changed prototype for get_auto_increment()
sql/ha_berkeley.h:
Changed prototype for get_auto_increment()
sql/ha_heap.cc:
Changed prototype for get_auto_increment()
sql/ha_heap.h:
Changed prototype for get_auto_increment()
sql/ha_innodb.cc:
Change how auto-increment is calculated.
Now the auto-increment logic is done in 'update_auto_increment()' to ensure that all handlers has the same auto-increment usage
sql/ha_innodb.h:
Changed prototype for get_auto_increment()
sql/ha_myisam.cc:
Changed prototype for get_auto_increment()
sql/ha_myisam.h:
Changed prototype for get_auto_increment()
sql/ha_ndbcluster.cc:
Changed prototype for get_auto_increment()
sql/ha_ndbcluster.h:
Changed prototype for get_auto_increment()
sql/handler.cc:
Remove some usage of current_thd
Changed how auto_increment works with SET INSERT_ID to make it more predictable
(Now we should generate same auto-increment serie on a slave, even if the table has rows that was not on the master.
Use auto_increment_increment and auto_increment_offset
sql/handler.h:
Changed prototype for get_auto_increment()
sql/log.cc:
Remove usage of 'set_log_pos()' to make code simpler. (Now log_pos is set in write_header())
Use 'data_written' instead of 'get_event_len()' to calculate how much data was written in the log
sql/log_event.cc:
Simple optimizations.
Remove cached_event_len (not used variable)
Made comments fit into 79 chars
Removed Log_event::set_log_pos(). Now we calculate log_pos in write_header().
Renamed write_data() to write() as the original write() function was not needed anymore.
Call writing of event header from event::write() functions. This made it easier to calculate the length of an event.
Simplified 'write_header' and remove 'switches' from it.
Changed all write() functions to return 'bool'. (The previous return values where not consistent)
Store auto_increment_increment and auto_increment_offset in binary log
Simplified how Query_log_event's where written and read. Now it's much easier to add now status variables for a query event to the binary log.
Removed some old MySQL 4.x code to make it easier to grep for functions used in 5.0
sql/log_event.h:
Changed return type of write() functions to bool. (Before we returned -1 or 1 for errors)
write_data() -> write()
Added 'data_written' member to make it easier to get length of written event.
Removed 'cached_event_len' and 'get_event_len()'
Added usage of auto_increment_increment and auto_increment_offset
Added 'artifical_event' to Start_log_event_v3, to hide logic that we in the binary log use log_pos=0 as a flag for an artifical event.
sql/mysqld.cc:
Added options --auto-increment-increment and --auto-increment-offset
sql/set_var.cc:
Added variables auto_increment_increment and auto_increment_offset
sql/slave.cc:
Changed errors -> warnings & information (in error log)
sql/sql_class.cc:
Added THD::cleanup_after_query(). This makes some code simpler and allows us to clean up 'next_insert_id' after query
sql/sql_class.h:
Added new auto_increment_xxx variables
Moved some functions/variables in THD class
sql/sql_help.cc:
Removed compiler warning
sql/sql_insert.cc:
Call 'restore_auto_increment()' if row was not inserted.
This makes it easier for handler to reuse the last generated auto-incrment value that was not used (for example in case of duplicate key)
sql/sql_parse.cc:
Use cleanup_after_query()
sql/sql_prepare.cc:
Use cleanup_after_query()
sql/sql_table.cc:
R
Diffstat (limited to 'sql/ha_innodb.cc')
-rw-r--r-- | sql/ha_innodb.cc | 157 |
1 files changed, 33 insertions, 124 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 3003425a489..8da04ed0ab1 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -1627,8 +1627,6 @@ ha_innobase::open( } } - auto_inc_counter_for_this_stat = 0; - block_size = 16 * 1024; /* Index block size in InnoDB: used by MySQL in query optimization */ @@ -2198,7 +2196,7 @@ ha_innobase::write_row( longlong dummy; ibool incremented_auto_inc_for_stat = FALSE; ibool incremented_auto_inc_counter = FALSE; - ibool skip_auto_inc_decr; + ibool skip_auto_inc_decr, auto_inc_used= FALSE; DBUG_ENTER("ha_innobase::write_row"); @@ -2260,39 +2258,34 @@ ha_innobase::write_row( prebuilt->sql_stat_start = TRUE; } - /* Fetch the value the user possibly has set in the - autoincrement field */ + /* + We must use the handler code to update the auto-increment + value to be sure that increment it correctly. + */ + update_auto_increment(); + auto_inc_used= 1; - auto_inc = table->next_number_field->val_int(); + } - /* In replication and also otherwise the auto-inc column - can be set with SET INSERT_ID. Then we must look at - user_thd->next_insert_id. If it is nonzero and the user - has not supplied a value, we must use it, and use values - incremented by 1 in all subsequent inserts within the - same SQL statement! */ + if (prebuilt->mysql_template == NULL + || prebuilt->template_type != ROW_MYSQL_WHOLE_ROW) { + /* Build the template used in converting quickly between + the two database formats */ - if (auto_inc == 0 && user_thd->next_insert_id != 0) { - auto_inc = user_thd->next_insert_id; - auto_inc_counter_for_this_stat = auto_inc; - } + build_template(prebuilt, NULL, table, ROW_MYSQL_WHOLE_ROW); + } - if (auto_inc == 0 && auto_inc_counter_for_this_stat) { - /* The user set the auto-inc counter for - this SQL statement with SET INSERT_ID. We must - assign sequential values from the counter. */ + innodb_srv_conc_enter_innodb(prebuilt->trx); - auto_inc_counter_for_this_stat++; - incremented_auto_inc_for_stat = TRUE; + error = row_insert_for_mysql((byte*) record, prebuilt); - auto_inc = auto_inc_counter_for_this_stat; + if (error == DB_SUCCESS && auto_inc_used) { - /* We give MySQL a new value to place in the - auto-inc column */ - user_thd->next_insert_id = auto_inc; - } + /* Fetch the value that was set in the autoincrement field */ - if (auto_inc != 0) { + auto_inc = table->next_number_field->val_int(); + + if (auto_inc != 0) { /* This call will calculate the max of the current value and the value supplied by the user and update the counter accordingly */ @@ -2304,104 +2297,19 @@ ha_innobase::write_row( The lock is released at each SQL statement's end. */ - innodb_srv_conc_enter_innodb(prebuilt->trx); - error = row_lock_table_autoinc_for_mysql(prebuilt); - innodb_srv_conc_exit_innodb(prebuilt->trx); - - if (error != DB_SUCCESS) { - - error = convert_error_code_to_mysql(error, - user_thd); - goto func_exit; - } - - dict_table_autoinc_update(prebuilt->table, auto_inc); - } else { - innodb_srv_conc_enter_innodb(prebuilt->trx); - - if (!prebuilt->trx->auto_inc_lock) { - - error = row_lock_table_autoinc_for_mysql( - prebuilt); - if (error != DB_SUCCESS) { - innodb_srv_conc_exit_innodb( - prebuilt->trx); - - error = convert_error_code_to_mysql( - error, user_thd); - goto func_exit; - } - } - - /* The following call gets the value of the auto-inc - counter of the table and increments it by 1 */ - - auto_inc = dict_table_autoinc_get(prebuilt->table); - incremented_auto_inc_counter = TRUE; + error = row_lock_table_autoinc_for_mysql(prebuilt); - innodb_srv_conc_exit_innodb(prebuilt->trx); + if (error != DB_SUCCESS) { - /* We can give the new value for MySQL to place in - the field */ - - user_thd->next_insert_id = auto_inc; - } - - /* This call of a handler.cc function places - user_thd->next_insert_id to the column value, if the column - value was not set by the user */ - - update_auto_increment(); - } - - if (prebuilt->mysql_template == NULL - || prebuilt->template_type != ROW_MYSQL_WHOLE_ROW) { - /* Build the template used in converting quickly between - the two database formats */ - - build_template(prebuilt, NULL, table, ROW_MYSQL_WHOLE_ROW); - } - - innodb_srv_conc_enter_innodb(prebuilt->trx); - - error = row_insert_for_mysql((byte*) record, prebuilt); + error = convert_error_code_to_mysql(error, user_thd); + goto func_exit; + } + dict_table_autoinc_update(prebuilt->table, auto_inc); + } + } innodb_srv_conc_exit_innodb(prebuilt->trx); - if (error != DB_SUCCESS) { - /* If the insert did not succeed we restore the value of - the auto-inc counter we used; note that this behavior was - introduced only in version 4.0.4. - NOTE that a REPLACE command handles a duplicate key error - itself, and we must not decrement the autoinc counter - if we are performing a REPLACE statement. - NOTE 2: if there was an error, for example a deadlock, - which caused InnoDB to roll back the whole transaction - already in the call of row_insert_for_mysql(), we may no - longer have the AUTO-INC lock, and cannot decrement - the counter here. */ - - skip_auto_inc_decr = FALSE; - - if (error == DB_DUPLICATE_KEY - && (user_thd->lex->sql_command == SQLCOM_REPLACE - || user_thd->lex->sql_command - == SQLCOM_REPLACE_SELECT)) { - - skip_auto_inc_decr= TRUE; - } - - if (!skip_auto_inc_decr && incremented_auto_inc_counter - && prebuilt->trx->auto_inc_lock) { - dict_table_autoinc_decrement(prebuilt->table); - } - - if (!skip_auto_inc_decr && incremented_auto_inc_for_stat - && prebuilt->trx->auto_inc_lock) { - auto_inc_counter_for_this_stat--; - } - } - error = convert_error_code_to_mysql(error, user_thd); /* Tell InnoDB server that there might be work for @@ -2412,6 +2320,7 @@ func_exit: DBUG_RETURN(error); } + /****************************************************************** Converts field data for storage in an InnoDB update vector. */ inline @@ -5217,7 +5126,7 @@ initialized yet. This function does not change the value of the auto-inc counter if it already has been initialized. Returns the value of the auto-inc counter. */ -longlong +ulonglong ha_innobase::get_auto_increment() /*=============================*/ /* out: auto-increment column value, -1 if error @@ -5230,10 +5139,10 @@ ha_innobase::get_auto_increment() if (error) { - return(-1); + return(~(ulonglong) 0); } - return(nr); + return((ulonglong) nr); } /*********************************************************************** |