diff options
author | unknown <kostja@dipika.(none)> | 2008-02-19 14:43:01 +0300 |
---|---|---|
committer | unknown <kostja@dipika.(none)> | 2008-02-19 14:43:01 +0300 |
commit | 526798dbb55c79b62e795a1cf40062030e2342bd (patch) | |
tree | e540052e63f7376b653b6418116db3340c22b891 /sql/sql_insert.cc | |
parent | 4e1be6221e8d683e525c9e0113ab48ae78e99f39 (diff) | |
download | mariadb-git-526798dbb55c79b62e795a1cf40062030e2342bd.tar.gz |
A fix and a test case for Bug#12713 "Error in a stored function called from
a SELECT doesn't cause ROLLBACK of statem".
The idea of the fix is to ensure that we always commit the current
statement at the end of dispatch_command(). In order to not issue
redundant disc syncs, an optimization of the two-phase commit
protocol is implemented to bypass the two phase commit if
the transaction is read-only.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
Update test results.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
Update test results.
mysql-test/suite/rpl_ndb/t/disabled.def:
Disable the tests, for which this changeset reveals a bug:
the injector thread does not always add 'statement commit' to the
rows injected in circular replication set up.
To be investigated separately.
sql/ha_ndbcluster_binlog.cc:
Add close_thread_tables() to run_query: this ensures
that all tables are closed and there is no pending statement transaction.
sql/handler.cc:
Implement optimisation of read-only transactions.
If a transaction consists only of DML statements that do not change
data, we do not perform a two-phase commit for it
(run one phase commit only).
sql/handler.h:
Implement optimisation of read-only transactions.
If a transaction consists only of DML statements that do not change
data, we do not perform a two-phase commit for it
(run one phase commit only).
sql/log.cc:
Mark the binlog transaction read-write whenever it's started.
We never read from binlog, so it's safe and least intrusive to add
this mark up here.
sql/log_event.cc:
Update to the new layout of thd->transaction.
sql/rpl_injector.cc:
Always commit statement transaction before committing the global one.
sql/sp.cc:
Ad comments.
sql/sp_head.cc:
Add comments.
sql/sql_base.cc:
Commit transaction at the end of the statement. Always.
sql/sql_class.cc:
Update thd_ha_data to return the right pointer in the new layout.
Fix select_dumpvar::send_data to properly return operation status.
A test case from commit.inc would lead to an assertion failure in the
diagnostics area (double assignment). Not test otherwise by the test suite.
sql/sql_class.h:
Implement a new layout of storage engine transaction info in which
it is easy to access all members related to the handlerton only
based on ht->slot.
sql/sql_cursor.cc:
Update to the new layout of thd->transaction.
sql/sql_delete.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_do.cc:
Add DO always clears the error, we must rollback the current
statement before this happens. Otherwise the statement will be committed,
and not rolled back in the end.
sql/sql_insert.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_load.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_parse.cc:
Implement optimisation of read-only transactions: bypass 2-phase
commit for them.
Always commit statement transaction before commiting the global one.
Fix an unrelated crash in check_table_access, when called from
information_schema.
sql/sql_partition.cc:
Partitions commit at the end of a DDL operation.
Make sure that send_ok() is done only if the commit has succeeded.
sql/sql_table.cc:
Use ha_autocommit_or_rollback and end_active_trans everywhere.
Add end_trans to mysql_admin_table, so that it leaves no pending
transaction.
sql/sql_udf.cc:
Remvove a redundant call to close_thread_tables()
sql/sql_update.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
mysql-test/include/commit.inc:
New BitKeeper file ``mysql-test/include/commit.inc''
mysql-test/r/commit_1innodb.result:
New BitKeeper file ``mysql-test/r/commit_1innodb.result''
mysql-test/t/commit_1innodb.test:
New BitKeeper file ``mysql-test/t/commit_1innodb.test''
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r-- | sql/sql_insert.cc | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index c2b1990f6c7..b03e786d1a1 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -541,6 +541,10 @@ bool open_and_lock_for_insert_delayed(THD *thd, TABLE_LIST *table_list) /** INSERT statement implementation + + @note Like implementations of other DDL/DML in MySQL, this function + relies on the caller to close the thread tables. This is done in the + end of dispatch_command(). */ bool mysql_insert(THD *thd,TABLE_LIST *table_list, @@ -893,12 +897,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, } DBUG_ASSERT(transactional_table || !changed || thd->transaction.stmt.modified_non_trans_table); - if (transactional_table) - error=ha_autocommit_or_rollback(thd,error); - + if (thd->lock) { - mysql_unlock_tables(thd, thd->lock); /* Invalidate the table in the query cache if something changed after unlocking when changes become fisible. @@ -909,7 +910,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, { query_cache_invalidate3(thd, table_list, 1); } - thd->lock=0; } } thd_proc_info(thd, "end"); @@ -2445,7 +2445,7 @@ err: first call to ha_*_row() instead. Remove code that are used to cover for the case outlined above. */ - ha_rollback_stmt(thd); + ha_autocommit_or_rollback(thd, 1); #ifndef __WIN__ end: @@ -3139,18 +3139,6 @@ bool select_insert::send_eof() thd->query, thd->query_length, trans_table, FALSE, killed_status); } - /* - We will call ha_autocommit_or_rollback() also for - non-transactional tables under row-based replication: there might - be events in the binary logs transaction, and we need to write - them to the binary log. - */ - if (trans_table || thd->current_stmt_binlog_row_based) - { - int error2= ha_autocommit_or_rollback(thd, error); - if (error2 && !error) - error= error2; - } table->file->ha_release_auto_increment(); if (error) @@ -3228,7 +3216,6 @@ void select_insert::abort() { table->file->ha_release_auto_increment(); } - ha_rollback_stmt(thd); DBUG_VOID_RETURN; } @@ -3667,7 +3654,10 @@ bool select_create::send_eof() nevertheless. */ if (!table->s->tmp_table) - ha_commit(thd); // Can fail, but we proceed anyway + { + ha_autocommit_or_rollback(thd, 0); + end_active_trans(thd); + } table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); @@ -3691,12 +3681,9 @@ void select_create::abort() by removing the table, even for non-transactional tables. */ tmp_disable_binlog(thd); - select_insert::abort(); - reenable_binlog(thd); - /* - We roll back the statement, including truncating the transaction - cache of the binary log, if the statement failed. + In select_insert::abort() we roll back the statement, including + truncating the transaction cache of the binary log. We roll back the statement prior to deleting the table and prior to releasing the lock on the table, since there might be potential @@ -3707,8 +3694,9 @@ void select_create::abort() of the table succeeded or not, since we need to reset the binary log state. */ - if (thd->current_stmt_binlog_row_based) - ha_rollback_stmt(thd); + select_insert::abort(); + reenable_binlog(thd); + if (m_plock) { |