From e57cccc65ca6d6a7da8f1fa7e7efb9826defebd1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Sep 2007 10:24:51 +0200 Subject: Optimization (useful at least for the Maria engine): we disable logging of insertions made by CREATE SELECT. sql/sql_insert.cc: If error during the CREATE SELECT we drop the table, so no need for engines to do logging of the insertions (optimization). Engines require that disabling is done before locking and re-enabling is done before unlocking; as table creation and locking is done as one function (create_table_from_items()) we disable before calling this function and re-enable before unlocking, in send_eof() (called if success) and abort() (called if error). Question for reviewer: would it be better to do the disabling between creation and locking, so inside create_table_from_items(), given that this function is used only by CREATE SELECT? --- sql/sql_insert.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 11db88d8f5e..d7267e6ecf6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3458,6 +3458,13 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) thd->binlog_start_trans_and_stmt(); } + /* + If error during the CREATE SELECT we drop the table, so no need for + engines to do logging of insertions (optimization). + */ + if (ha_enable_transaction(thd, FALSE)) + DBUG_RETURN(-1); + if (!(table= create_table_from_items(thd, create_info, create_table, alter_info, &values, &thd->extra_lock, hook_ptr))) @@ -3602,6 +3609,7 @@ bool select_create::send_eof() table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); + ha_enable_transaction(thd, TRUE); if (thd->extra_lock) { mysql_unlock_tables(thd, thd->extra_lock); @@ -3640,6 +3648,8 @@ void select_create::abort() if (thd->current_stmt_binlog_row_based) ha_rollback_stmt(thd); + ha_enable_transaction(thd, TRUE); + if (thd->extra_lock) { mysql_unlock_tables(thd, thd->extra_lock); -- cgit v1.2.1 From ca12435fe11e558e548b5178ff69339336b7acc3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Oct 2007 19:39:16 +0200 Subject: Fix for "innodb_mysql" and "events" failures: we can disable transactionality in CREATE SELECT only if the table is not temporary (because re-enabling causes a commit). In the future we should disable again for temporary tables; that will probably require changing ha_enable_transaction(). sql/sql_insert.cc: When we disable transactionality in CREATE SELECT, we re-enable it at the end and this causes a commit (inside ha_enable_transaction()); but this is undesired if the created table is temporary (we don't want CREATE TEMPORARY TABLE SELECT to commit all previous statements). So we disable logging only if the table is not temporary. Ideally in the future we would want to lift this restriction which sounds stupid, but for Maria it does not matter now (temporary tables are not transactional yet). --- sql/sql_insert.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index d7267e6ecf6..ecaab5638cc 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3460,10 +3460,12 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) /* If error during the CREATE SELECT we drop the table, so no need for - engines to do logging of insertions (optimization). + engines to do logging of insertions (optimization). We don't do it for + temporary tables (yet) as re-enabling causes an undesirable commit. */ - if (ha_enable_transaction(thd, FALSE)) - DBUG_RETURN(-1); + if (((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) && + ha_enable_transaction(thd, FALSE)) + DBUG_RETURN(-1); if (!(table= create_table_from_items(thd, create_info, create_table, alter_info, &values, @@ -3605,11 +3607,12 @@ bool select_create::send_eof() nevertheless. */ if (!table->s->tmp_table) + { + ha_enable_transaction(thd, TRUE); ha_commit(thd); // Can fail, but we proceed anyway - + } table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); - ha_enable_transaction(thd, TRUE); if (thd->extra_lock) { mysql_unlock_tables(thd, thd->extra_lock); @@ -3632,6 +3635,9 @@ void select_create::abort() select_insert::abort(); reenable_binlog(thd); + if (table && !table->s->tmp_table) + ha_enable_transaction(thd, TRUE); + /* We roll back the statement, including truncating the transaction cache of the binary log, if the statement failed. @@ -3648,8 +3654,6 @@ void select_create::abort() if (thd->current_stmt_binlog_row_based) ha_rollback_stmt(thd); - ha_enable_transaction(thd, TRUE); - if (thd->extra_lock) { mysql_unlock_tables(thd, thd->extra_lock); -- cgit v1.2.1 From 0825c48549dd2c959de6afd083d4968190230645 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 20 Jan 2008 05:25:26 +0100 Subject: - fix for segfault in rpl_trigger/rpl_found_rows with default engine=maria (fix is keeping the real TRN through a disable_logging/reenable cycle) - fix for pagecache assertion failure in ps/type_ranges with default engine=maria (fix is in sql_insert.cc) - when reenabling logging we must either flush all dirty pages, or at least verify (in debug build) that there are none. For example a bulk insert with single UNDO_BULK_INSERT must flush them, no matter if it uses repair or not (bugfix) - UNDO_BULK_INSERT_WITH_REPAIR is also used with repair, changes name mysql-test/r/maria.result: tests for bugs fixed mysql-test/t/maria.test: tests for bugs fixed sql/sql_insert.cc: Bugfix: even if select_create::prepare() failed to create the 'table' object we still have to re-enable logging. storage/maria/ha_maria.cc: Bugfix: when a transactional table does a bulk insert without repair, it still sometimes skips logging of REDOs thus needs a full flush and sync at the end. Not if repair is done, as repair does it internally already (see end of maria_repair*()). storage/maria/ha_maria.h: variable now can have 3 states not 2 storage/maria/ma_bitmap.c: name change storage/maria/ma_blockrec.c: name change storage/maria/ma_blockrec.h: name change storage/maria/ma_check.c: * When maria_repair() re-enables logging it does not need to ask for a flush&sync as it did it by itself already a few lines before. * the log record of bulk insert can be used even without repair * disable logging in maria_zerofill(): without that, it puts LSN pages in the cache, so when it flushes them it flushes the log; the change makes auto-ha_maria::zerofill-if-moved faster (no log flush). storage/maria/ma_key_recover.c: name change storage/maria/ma_loghandler.c: name change storage/maria/ma_loghandler.h: name change storage/maria/ma_pagecache.c: A function, to check in debug builds that no dirty pages exist for a file. storage/maria/ma_pagecache.h: new function (nothing in non-debug) storage/maria/ma_recovery.c: _ma_tmp_disable_logging() sets info->trn to dummy_transaction_object when needed now. The changes done here about info->trn are to allow a table to retain its original, real TRN through a disable/reenable cycle (see replication scenario in _ma_reenable_logging_for_table()). When we reenable, we offer the caller to flush and sync the table; if the caller doesn't accept our offer, we verify that it's ok (no REDOs => no dirty pages are allowed to exist). storage/maria/maria_chk.c: comment storage/maria/maria_def.h: new names mysql-test/suite/rpl/r/rpl_stm_maria.result: result (it used to crash) mysql-test/suite/rpl/t/rpl_stm_maria.test: Test of replication-specific Maria bug fixed --- sql/sql_insert.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 6a7356f17ee..f4084c12c1f 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3705,7 +3705,7 @@ void select_create::abort() select_insert::abort(); reenable_binlog(thd); - if (table && !table->s->tmp_table) + if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) ha_enable_transaction(thd, TRUE); /* -- cgit v1.2.1 From d66157e30f83aa7e7cf4f7a02a60f710785b114d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Jan 2008 11:56:37 +0100 Subject: An assertion added (transaction must be re-enabled before end of top-level statement) and fixes for the bugs it finds. Fix for non-serious Valgrind warning. sql/sql_insert.cc: When CREATE TABLE IF NOT EXISTS finds the table already exists, 'table' is the existing table. So if that table is temporary we don't re-enable transactions which is a bug. sql/sql_parse.cc: verify that at the end of each top-statement transactions have been re-enabled. Does not apply to substatements (consider CREATE TABLE t1 SELECT stored_func() : the substatements inside stored_func() run with transaction disabled). I am not putting the assertion into ha_external_lock(F_UNLCK) because performance schema tables get closed in the middle of a statement sometimes while transaction is disabled. sql/sql_table.cc: copy_data_between_tables() forgot to clean-up several things in error conditions (ha_enable_transaction(), free-ing 'copy', etc) as found by the assertion added to sql_parse.cc. storage/maria/ha_maria.cc: Comment storage/maria/ma_blockrec.c: fix for Valgrind warning: a temporary table was created, a blob page of its was flushed to disk and had random bytes in the checksum area ("write of uninitialized bytes in pwrite") storage/maria/ma_pagecrc.c: typo --- sql/sql_insert.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f4084c12c1f..1dc256bb7c3 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3670,16 +3670,16 @@ bool select_create::send_eof() abort(); else { + if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) + ha_enable_transaction(thd, TRUE); /* Do an implicit commit at end of statement for non-temporary tables. This can fail, but we should unlock the table nevertheless. */ if (!table->s->tmp_table) - { - ha_enable_transaction(thd, TRUE); ha_commit(thd); // Can fail, but we proceed anyway - } + table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); if (m_plock) -- cgit v1.2.1 From e771ee75e7d186119dbbcd88d1b0d6d9a94b775b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 14 May 2008 09:50:16 +0300 Subject: Manual merge and some fixes. mysql-test/include/varchar.inc: Manual merge between 5.1 and maria. Added a comment. mysql-test/r/maria.result: Temporary fix. mysql-test/suite/binlog/r/binlog_unsafe.result: Manual merge. mysql-test/suite/binlog/t/binlog_unsafe.test: Manual merge. sql/handler.h: Manual merge + fix. sql/item.h: Manual merge + fix. sql/log.cc: Manual merge + fix. sql/sql_insert.cc: Manual merge + fix. A commit was done when using create table ... select from for transactional tables other than maria, when an error occurred and transaction should have been aborted. --- sql/sql_insert.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 394a3d2e7b3..dbfe3cc6d79 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3533,15 +3533,17 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) engines to do logging of insertions (optimization). We don't do it for temporary tables (yet) as re-enabling causes an undesirable commit. */ - if (((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) && - ha_enable_transaction(thd, FALSE)) - DBUG_RETURN(-1); if (!(table= create_table_from_items(thd, create_info, create_table, alter_info, &values, &extra_lock, hook_ptr))) DBUG_RETURN(-1); // abort() deletes table + if (((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) && + !create_info->table_existed && + ha_enable_transaction(thd, FALSE)) + DBUG_RETURN(-1); + if (extra_lock) { DBUG_ASSERT(m_plock == NULL); @@ -3682,7 +3684,8 @@ bool select_create::send_eof() abort(); else { - if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) + if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 && + !create_info->table_existed) ha_enable_transaction(thd, TRUE); /* Do an implicit commit at end of statement for non-temporary @@ -3712,9 +3715,6 @@ void select_create::abort() { DBUG_ENTER("select_create::abort"); - if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) - ha_enable_transaction(thd, TRUE); - /* In select_insert::abort() we roll back the statement, including truncating the transaction cache of the binary log. To do this, we @@ -3731,11 +3731,13 @@ void select_create::abort() log state. */ tmp_disable_binlog(thd); + if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 && + !create_info->table_existed) + ha_enable_transaction(thd, TRUE); select_insert::abort(); thd->transaction.stmt.modified_non_trans_table= FALSE; reenable_binlog(thd); - if (m_plock) { mysql_unlock_tables(thd, *m_plock); -- cgit v1.2.1 From 5099033c26826fd2625b6424134999853e33a29d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 May 2008 18:33:33 +0300 Subject: WL#3138: Maria - fast "SELECT COUNT(*) FROM t;" and "CHECKSUM TABLE t" Added argument to maria_end_bulk_insert() to know if the table will be deleted after the operation Fixed wrong call to strmake Don't call bulk insert in case of inserting only one row (speed optimization as starting/stopping bulk insert Allow storing year 2155 in year field When running with purify/valgrind avoid copying structures over themself Added hook 'trnnam_end_trans_hook' that is called when transaction ends Added trn->used_tables that is used to an entry for all tables used by transaction Fixed that ndb doesn't crash on duplicate key error when start_bulk_insert/end_bulk_insert are not called include/maria.h: Added argument to maria_end_bulk_insert() to know if the table will be deleted after the operation include/my_tree.h: Added macro 'reset_free_element()' to be able to ignore calls to the external free function. Is used to optimize end-bulk-insert in case of failures, in which case we don't want write the remaining keys in the tree mysql-test/install_test_db.sh: Upgrade to new mysql_install_db options mysql-test/r/maria-mvcc.result: New tests mysql-test/r/maria.result: New tests mysql-test/suite/ndb/r/ndb_auto_increment.result: Fixed error message now when bulk insert is not always called mysql-test/suite/ndb/t/ndb_auto_increment.test: Fixed error message now when bulk insert is not always called mysql-test/t/maria-mvcc.test: Added testing of versioning of count(*) mysql-test/t/maria-page-checksum.test: Added comment mysql-test/t/maria.test: More tests mysys/hash.c: Code style change sql/field.cc: Allow storing year 2155 in year field sql/ha_ndbcluster.cc: Added new argument to end_bulk_insert() to signal if the bulk insert should ignored sql/ha_ndbcluster.h: Added new argument to end_bulk_insert() to signal if the bulk insert should ignored sql/ha_partition.cc: Added new argument to end_bulk_insert() to signal if the bulk insert should ignored sql/ha_partition.h: Added new argument to end_bulk_insert() to signal if the bulk insert should ignored sql/handler.cc: Don't call get_dup_key() if there is no table object. This can happen if the handler generates a duplicate key error on commit sql/handler.h: Added new argument to end_bulk_insert() to signal if the bulk insert should ignored (ie, the table will be deleted) sql/item.cc: Style fix Removed compiler warning sql/log_event.cc: Added new argument to ha_end_bulk_insert() sql/log_event_old.cc: Added new argument to ha_end_bulk_insert() sql/mysqld.cc: Removed compiler warning sql/protocol.cc: Added DBUG sql/sql_class.cc: Added DBUG Fixed wrong call to strmake sql/sql_insert.cc: Don't call bulk insert in case of inserting only one row (speed optimization as starting/stopping bulk insert involves a lot of if's) Added new argument to ha_end_bulk_insert() sql/sql_load.cc: Added new argument to ha_end_bulk_insert() sql/sql_parse.cc: Style fixes Avoid goto in common senario sql/sql_select.cc: When running with purify/valgrind avoid copying structures over themself. This is not a real bug in itself, but it's a waste of cycles and causes valgrind warnings sql/sql_select.h: Avoid copying structures over themself. This is not a real bug in itself, but it's a waste of cycles and causes valgrind warnings sql/sql_table.cc: Call HA_EXTRA_PREPARE_FOR_DROP if table created by ALTER TABLE is going to be dropped Added new argument to ha_end_bulk_insert() storage/archive/ha_archive.cc: Added new argument to end_bulk_insert() storage/archive/ha_archive.h: Added new argument to end_bulk_insert() storage/federated/ha_federated.cc: Added new argument to end_bulk_insert() storage/federated/ha_federated.h: Added new argument to end_bulk_insert() storage/maria/Makefile.am: Added ma_state.c and ma_state.h storage/maria/ha_maria.cc: Versioning of count(*) and checksum - share->state.state is now assumed to be correct, not handler->state - Call _ma_setup_live_state() in external lock to get count(*)/checksum versioning. In case of not versioned and not concurrent insertable table, file->s->state.state contains the correct state information Other things: - file->s -> share - Added DBUG_ASSERT() for unlikely case - Optimized end_bulk_insert() to not write anything if table is going to be deleted (as in failed alter table) - Indentation changes in external_lock becasue of removed 'goto' caused a big conflict even if very little was changed storage/maria/ha_maria.h: New argument to end_bulk_insert() storage/maria/ma_blockrec.c: Update for versioning of count(*) and checksum Keep share->state.state.data_file_length up to date (not info->state->data_file_length) Moved _ma_block_xxxx_status() and maria_versioning() functions to ma_state.c storage/maria/ma_check.c: Update and use share->state.state instead of info->state info->s to share Update info->state at end of repair Call _ma_reset_state() to update share->state_history at end of repair storage/maria/ma_checkpoint.c: Call _ma_remove_not_visible_states() on checkpoint to clean up not visible state history from tables storage/maria/ma_close.c: Remember state history for running transaction even if table is closed storage/maria/ma_commit.c: Ensure we always call trnman_commit_trn() even if other calls fails. If we don't do that, the translog and state structures will not be freed storage/maria/ma_delete.c: Versioning of count(*) and checksum: - Always update info->state->checksum and info->state->records storage/maria/ma_delete_all.c: Versioning of count(*) and checksum: - Ensure that share->state.state is updated, as here is where we store the primary information storage/maria/ma_dynrec.c: Use lock_key_trees instead of concurrent_insert to check if trees should be locked. This allows us to lock trees both for concurrent_insert and for index versioning. storage/maria/ma_extra.c: Versioning of count(*) and checksum: - Use share->state.state instead of info->state - share->concurrent_insert -> share->non_transactional_concurrent_insert - Don't update share->state.state from info->state if transactional table Optimization: - Don't flush io_cache or bitmap if we are using FLUSH_IGNORE_CHANGED storage/maria/ma_info.c: Get most state information from current state storage/maria/ma_init.c: Add hash table and free function to store states for closed tables Install hook for transaction commit/rollback to update history state storage/maria/ma_key_recover.c: Versioning of count(*) and checksum: - Use share->state.state instead of info->state storage/maria/ma_locking.c: Versioning of count(*) and checksum: - Call virtual functions (if exists) to restore/update status - Move _ma_xxx_status() functions to ma_state.c info->s -> share storage/maria/ma_open.c: Versioning of count(*) and checksum: - For not transactional tables, set info->state to point to new allocated state structure. - Initialize new info->state_start variable that points to state at start of transaction - Copy old history states from hash table (maria_stored_states) first time the table is opened - Split flag share->concurrent_insert to non_transactional_concurrent_insert & lock_key_tree - For now, only enable versioning of tables without keys (to be fixed in soon!) - Added new virtual function to restore status in maria_lock_database) More DBUG storage/maria/ma_page.c: Versioning of count(*) and checksum: - Use share->state.state instead of info->state - Modify share->state.state.key_file_length under share->intern_lock storage/maria/ma_range.c: Versioning of count(*) and checksum: - Lock trees based on share->lock_key_trees info->s -> share storage/maria/ma_recovery.c: Versioning of count(*) and checksum: - Use share->state.state instead of info->state - Update state information on close and when reenabling logging storage/maria/ma_rkey.c: Versioning of count(*) and checksum: - Lock trees based on share->lock_key_trees storage/maria/ma_rnext.c: Versioning of count(*) and checksum: - Lock trees based on share->lock_key_trees storage/maria/ma_rnext_same.c: Versioning of count(*) and checksum: - Lock trees based on share->lock_key_trees - Only skip rows based on file length if non_transactional_concurrent_insert is set storage/maria/ma_rprev.c: Versioning of count(*) and checksum: - Lock trees based on share->lock_key_trees storage/maria/ma_rsame.c: Versioning of count(*) and checksum: - Lock trees based on share->lock_key_trees storage/maria/ma_sort.c: Use share->state.state instead of info->state Fixed indentation storage/maria/ma_static.c: Added maria_stored_state storage/maria/ma_update.c: Versioning of count(*) and checksum: - Always update info->state->checksum and info->state->records - Remove optimization for index file update as it doesn't work for transactional tables storage/maria/ma_write.c: Versioning of count(*) and checksum: - Always update info->state->checksum and info->state->records storage/maria/maria_def.h: Move MARIA_STATUS_INFO to ma_state.h Changes to MARIA_SHARE: - Added state_history to store count(*)/checksum states - Added in_trans as counter if table is used by running transactions - Split concurrent_insert into lock_key_trees and on_transactional_concurrent_insert. - Added virtual function lock_restore_status Changes to MARIA_HA: - save_state -> state_save - Added state_start to store state at start of transaction storage/maria/maria_pack.c: Versioning of count(*) and checksum: - Use share->state.state instead of info->state Indentation fixes storage/maria/trnman.c: Added hook 'trnnam_end_trans_hook' that is called when transaction ends Added trn->used_tables that is used to an entry for all tables used by transaction More DBUG Changed return type of trnman_end_trn() to my_bool Added trnman_get_min_trid() to get minimum trid in use. Added trnman_exists_active_transactions() to check if there exist a running transaction started between two commit id storage/maria/trnman.h: Added 'used_tables' Moved all pointers into same groups to get better memory alignment storage/maria/trnman_public.h: Added prototypes for new functions and variables Chagned return type of trnman_end_trn() to my_bool storage/myisam/ha_myisam.cc: Added argument to end_bulk_insert() if operation should be aborted storage/myisam/ha_myisam.h: Added argument to end_bulk_insert() if operation should be aborted storage/maria/ma_state.c: Functions to handle state of count(*) and checksum storage/maria/ma_state.h: Structures and declarations to handle state of count(*) and checksum --- sql/sql_insert.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index cb0728490b7..cc2e311cc9e 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -555,6 +555,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, bool transactional_table, joins_freed= FALSE; bool changed; bool was_insert_delayed= (table_list->lock_type == TL_WRITE_DELAYED); + bool using_bulk_insert= 0; uint value_count; ulong counter = 1; ulonglong id; @@ -716,8 +717,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, values_list.elements, and - if nothing else - to initialize the code to make the call of end_bulk_insert() below safe. */ - if (lock_type != TL_WRITE_DELAYED && !thd->prelocked_mode) + if (lock_type != TL_WRITE_DELAYED && !thd->prelocked_mode && + values_list.elements > 1) + { + using_bulk_insert= 1; table->file->ha_start_bulk_insert(values_list.elements); + } thd->abort_on_warning= (!ignore && (thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES | @@ -831,7 +836,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, auto_inc values from the delayed_insert thread as they share TABLE. */ table->file->ha_release_auto_increment(); - if (!thd->prelocked_mode && table->file->ha_end_bulk_insert() && !error) + if (using_bulk_insert && table->file->ha_end_bulk_insert(0) && !error) { table->file->print_error(my_errno,MYF(0)); error=1; @@ -1167,7 +1172,7 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, bool res= 0; table_map map= 0; DBUG_ENTER("mysql_prepare_insert"); - DBUG_PRINT("enter", ("table_list 0x%lx, table 0x%lx, view %d", + DBUG_PRINT("enter", ("table_list 0x%lx table 0x%lx view %d", (ulong)table_list, (ulong)table, (int)insert_into_view)); /* INSERT should have a SELECT or VALUES clause */ @@ -3108,7 +3113,7 @@ bool select_insert::send_eof() DBUG_PRINT("enter", ("trans_table=%d, table_type='%s'", trans_table, table->file->table_type())); - error= (!thd->prelocked_mode) ? table->file->ha_end_bulk_insert():0; + error= (!thd->prelocked_mode) ? table->file->ha_end_bulk_insert(0) : 0; table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); @@ -3195,7 +3200,7 @@ void select_insert::abort() { before. */ if (!thd->prelocked_mode) - table->file->ha_end_bulk_insert(); + table->file->ha_end_bulk_insert(0); /* If at least one row has been inserted/modified and will stay in -- cgit v1.2.1 From cd8f6a1e16407d157cfde82cd4344a98fd7d3f2e Mon Sep 17 00:00:00 2001 From: Guilhem Bichot Date: Tue, 3 Jun 2008 21:35:39 +0200 Subject: Fix for BUG#36104 "INFORMATION_SCHEMA.TABLES shows TRANSACTIONAL=1 twice in CREATE_OPTIONS" mysql-test/r/maria.result: result; before the bugfix it would be "TRANSACTIONAL=1 transactional=1" mysql-test/t/maria.test: test for BUG#36104 "INFORMATION_SCHEMA.TABLES shows TRANSACTIONAL=1 twice in CREATE_OPTIONS" sql-bench/example: doblewrite->doublewrite sql/mysqld.cc: fix of a wrong 5.1->maria merge of the past sql/sql_insert.cc: removing my old idea of disabling transactionality in CREATE SELECT: 1) it caused bugs because re-enabling (ha_enable_transaction()) causes implicit commit, so in complex cases like "CREATE SELECT some_func())", where some_func() would want to insert two rows in another table, and fail on the second row, the implicit commit would commit the inserted row, while it should roll back. 2) it's not needed anymore, because CREATE SELECT uses bulk insert, and Maria has transactionality disabled by bulk insert. sql/sql_show.cc: This was duplicate code, causing BUG#36104 "INFORMATION_SCHEMA.TABLES shows TRANSACTIONAL=1 twice in CREATE_OPTIONS" --- sql/sql_insert.cc | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 61ce6b04832..a3610385725 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3532,22 +3532,11 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) thd->binlog_start_trans_and_stmt(); } - /* - If error during the CREATE SELECT we drop the table, so no need for - engines to do logging of insertions (optimization). We don't do it for - temporary tables (yet) as re-enabling causes an undesirable commit. - */ - if (!(table= create_table_from_items(thd, create_info, create_table, alter_info, &values, &extra_lock, hook_ptr))) DBUG_RETURN(-1); // abort() deletes table - if (((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) && - !create_info->table_existed && - ha_enable_transaction(thd, FALSE)) - DBUG_RETURN(-1); - if (extra_lock) { DBUG_ASSERT(m_plock == NULL); @@ -3688,9 +3677,6 @@ bool select_create::send_eof() abort(); else { - if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 && - !create_info->table_existed) - ha_enable_transaction(thd, TRUE); /* Do an implicit commit at end of statement for non-temporary tables. This can fail, but we should unlock the table @@ -3724,7 +3710,7 @@ void select_create::abort() truncating the transaction cache of the binary log. To do this, we pretend that the statement is transactional, even though it might be the case that it was not. - + We roll back the statement prior to deleting the table and prior to releasing the lock on the table, since there might be potential for failure if the rollback is executed after the drop or after @@ -3735,13 +3721,11 @@ void select_create::abort() log state. */ tmp_disable_binlog(thd); - if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 && - !create_info->table_existed) - ha_enable_transaction(thd, TRUE); select_insert::abort(); thd->transaction.stmt.modified_non_trans_table= FALSE; reenable_binlog(thd); + if (m_plock) { mysql_unlock_tables(thd, *m_plock); -- cgit v1.2.1 From 2a9d33f07d18a7180cb02a4f74f42d208dc0e2c0 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 26 Sep 2008 16:49:51 +0300 Subject: Fixed for Bug #39248 Maria: INSERT ON DUPLICATE KEY UPDATE gives error if using a view The bug was that prepared statements didn't downgrade TL_WRITE_CONCURRENT properly mysql-test/r/maria.result: Added test case mysql-test/t/maria.test: Added test case sql/mysql_priv.h: Make upgrade_lock_type() global sql/sql_base.cc: Fixed indentation sql/sql_insert.cc: Make upgrade_lock_type() global sql/sql_prepare.cc: Call upgrade_lock_type_for_insert() to get right lock to use sql/sql_view.cc: Indentation fix --- sql/sql_insert.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index a3610385725..8ea912ac13f 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -387,10 +387,9 @@ void prepare_triggers_for_insert_stmt(TABLE *table) downgrade the lock in handler::store_lock() method. */ -static -void upgrade_lock_type(THD *thd, thr_lock_type *lock_type, - enum_duplicates duplic, - bool is_multi_insert) +void upgrade_lock_type_for_insert(THD *thd, thr_lock_type *lock_type, + enum_duplicates duplic, + bool is_multi_insert) { if (duplic == DUP_UPDATE || duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT) @@ -587,8 +586,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, Upgrade lock type if the requested lock is incompatible with the current connection mode or table operation. */ - upgrade_lock_type(thd, &table_list->lock_type, duplic, - values_list.elements > 1); + upgrade_lock_type_for_insert(thd, &table_list->lock_type, duplic, + values_list.elements > 1); /* We can't write-delayed into a table locked with LOCK TABLES: -- cgit v1.2.1 From 32f81bab7d3ed46ddc2863c7be8d69f8dcf698c3 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 3 Dec 2008 00:02:52 +0200 Subject: WL#3262 add mutex lock order checking to safemutex (also called safe_mutex_deadlock_detector) This writes a warning on stderr if one uses mutex in different order, like if one in one case would lock mutex in the order A,B and in another case would lock mutex in the order B,A This is inspired by and loosely based on the LOCKDEP patch by Jonas Wrong mutex order is either fixed or mutex are marked with MYF_NO_DEADLOCK_DETECTION if used inconsistently (need to be fixed by server team) KNOWN_BUGS.txt: Added information that one need to dump and restore Maria tables include/hash.h: Added prototype function for walking over all elements in a hash include/my_pthread.h: Added my_pthread_mutex_init() and my_pthread_mutex_lock(); These should be used if one wants to disable mutex order checking. Changed names of the nonposix mutex_init functions to not conflict with my_phread_mutex_init() Added and extended structures for mutex deadlock detection. New arguments to sage_mutex_init() and safe_mutex_lock() to allow one to disable mutex order checking. Added variable 'safe_mutex_deadlock_detector' to enable/disable deadlock detection for all pthread_mutex_init() mysys/Makefile.am: Added cleaning of test files Added test_thr_mutex mysys/hash.c: Added hash_iterate() to iterate over all elements in a hash More comments mysys/my_init.c: Added calls to destory all mutex uses by mysys() Added waiting for threads to end before calling TERMINATE() to list not freed memory mysys/my_pthread.c: Changed names to free my_pthread_mutex_init() for mutex-lock-order-checking mysys/my_sleep.c: Fixed too long wait if using 1000000L as argument mysys/my_thr_init.c: Mark THR_LOCK_threads and THR_LOCK_malloc to not have mutex deadlock detection. (We can't have it enabled for this as these are internal mutex used by the detector Call my_thread_init() early as we need thread specific variables enabled for the following pthread_mutex_init() Move code to wait for threads to end to my_wait_for_other_threads_to_die() Don't destroy mutex and conditions unless all threads have died Added my_thread_destroy_mutex() to destroy all mutex used by the mysys thread system Name the thread specific mutex as "mysys_var->mutex" Added my_thread_var_mutex_in_use() to return pointer to mutex in use or 0 if thread variables are not initialized mysys/mysys_priv.h: Added prototypes for functions used internally with mutex-wrong-usage detection mysys/thr_mutex.c: Added runtime detection of mutex used in conflicting order See WL#3262 or test_thr_mutex.c for examples The base idea is for each mutex have two hashes: - mutex->locked_mutex points to all mutex used after this one - mutex->used_mutex points to all mutex which has this mutex in it's mutex->locked_mutex There is a wrong mutex order if any mutex currently locked before this mutex is in the mutex->locked_mutex hash sql/event_queue.cc: Mark mutex used inconsistently (need to be fixed by server team) sql/event_scheduler.cc: Declare the right order to take the mutex sql/events.cc: Mark mutex used inconsistently (need to be fixed by server team) sql/ha_ndbcluster_binlog.cc: Mark mutex used inconsistently (need to be fixed by server team) sql/log.cc: Mark mutex used inconsistently (need to be fixed by server team) sql/mysqld.cc: Use pthread_mutex_trylock instead of pthread_mutex_unlock() when sending kill signal to thread This is needed to avoid wrong mutex order as normally one takes 'current_mutex' before mysys_var->mutex. Added call to free sp cache. Add destruction of LOCK_server_started and COND_server_started. Added register_mutex_order() function to register in which order mutex should be taken (to initiailize mutex_deadlock_detector). Added option to turn off safe_mutex_deadlock_detector sql/protocol.cc: Fixed wrong argument to DBUG_PRINT (found by valgrind) sql/rpl_mi.cc: Mark mutex used inconsistently (need to be fixed by server team) sql/set_var.cc: Remove wrong locking of LOCK_global_system_variables when reading and setting log variables (would cause inconsistent mutex order). Update global variables outside of logger.unlock() as LOCK_global_system_variables has to be taken before logger locks Reviewed by gluh sql/sp_cache.cc: Added function to destroy mutex used by sp cache sql/sp_cache.h: Added function to destroy mutex used by sp cache sql/sql_class.cc: Use pthread_mutex_trylock instead of pthread_mutex_unlock() when sending kill signal to thread This is needed to avoid wrong mutex order as normally one takes 'current_mutex' before mysys_var->mutex. Register order in which LOCK_delete and mysys_var->mutex is taken sql/sql_insert.cc: Give a name for Delayed_insert::mutex Mark mutex used inconsistently (need to be fixed by server team) Move closing of tables outside of di->mutex (to avoid wrong mutex order) sql/sql_show.cc: Don't keep LOCK_global_system_variables locked over value->show_type() as this leads to wrong mutex order storage/innobase/handler/ha_innodb.cc: Disable safe_muted_deadlock_detector for innobase intern mutex (to speed up page cache initialization) storage/maria/ha_maria.cc: Added flag to ha_maria::info() to signal if we need to lock table share or not. This is needed to avoid locking mutex in wrong order storage/maria/ha_maria.h: Added flag to ha_maria::info() to signal if we need to lock table share or not. storage/maria/ma_close.c: Destroy key_del_lock Simplify freeing ftparser_param storage/maria/ma_key.c: Better comment storage/maria/ma_loghandler.c: Mark mutex used inconsistently (need to be fixed by sanja) storage/maria/ma_state.c: More comments storage/maria/ma_test1.c: Ensure that safe_mutex_deadlock_detector is always on (should be, this is just for safety) storage/maria/ma_test2.c: Ensure that safe_mutex_deadlock_detector is always on (should be, this is just for safety) --- sql/sql_insert.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index a275c680cb5..d8838b3b03d 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1719,7 +1719,8 @@ public: thd.system_thread= SYSTEM_THREAD_DELAYED_INSERT; thd.security_ctx->host_or_ip= ""; bzero((char*) &info,sizeof(info)); - pthread_mutex_init(&mutex,MY_MUTEX_INIT_FAST); + my_pthread_mutex_init(&mutex, MY_MUTEX_INIT_FAST, "Delayed_insert::mutex", + 0); pthread_cond_init(&cond,NULL); pthread_cond_init(&cond_client,NULL); VOID(pthread_mutex_lock(&LOCK_thread_count)); @@ -2224,7 +2225,8 @@ void kill_delayed_threads(void) in handle_delayed_insert() */ if (&di->mutex != di->thd.mysys_var->current_mutex) - pthread_mutex_lock(di->thd.mysys_var->current_mutex); + my_pthread_mutex_lock(di->thd.mysys_var->current_mutex, + MYF_NO_DEADLOCK_DETECTION); pthread_cond_broadcast(di->thd.mysys_var->current_cond); if (&di->mutex != di->thd.mysys_var->current_mutex) pthread_mutex_unlock(di->thd.mysys_var->current_mutex); @@ -2470,13 +2472,14 @@ end: clients */ - close_thread_tables(thd); // Free the table di->table=0; di->dead= 1; // If error thd->killed= THD::KILL_CONNECTION; // If error - pthread_cond_broadcast(&di->cond_client); // Safety pthread_mutex_unlock(&di->mutex); + close_thread_tables(thd); // Free the table + pthread_cond_broadcast(&di->cond_client); // Safety + pthread_mutex_lock(&LOCK_delayed_create); // Because of delayed_get_table pthread_mutex_lock(&LOCK_delayed_insert); delete di; -- cgit v1.2.1 From 910284e6e6203b8d2d2f454823b1ae7ecd759651 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sat, 27 Dec 2008 04:05:16 +0200 Subject: Fixed bugs found by pushbuild Added code to detect and give error when doing an insert into a view where we accessed fields in a not yet read table Disabled test in subselect.test as the CHECK_OPTION for views doesn't work for insert. This needs to be fixed properly later. The problem with views are described in Bug #41760 Inserting into multiple-table views is not working mysql-test/r/insert.result: Fixed wrong usage of insert into view. mysql-test/r/subselect.result: Disabled wrong test (temporary) mysql-test/suite/maria/r/maria.result: Added test of size of table mysql-test/suite/maria/t/maria.test: Added test of size of table mysql-test/t/insert.test: Fixed wrong usage of insert into view The bug is that during insert/update we currently don't read any of the referenced tables of the view. This means that we can't get a value from another table to use as part of the update. mysql-test/t/subselect.test: Disabled not working test until someone has time to fix insert into view properly Here we where refering to last used value in t2, which is wrong. sql/sql_insert.cc: Detect if we are trying to update one table in a view based on value in another, not yet read, table. This fixes the problem discovered in insert.test storage/maria/ma_blockrec.c: Don't ignore not critical changes to the last page in the table. We need to write the last page as otherwise we can during aborting of a row with a duplicate key get state.data_file_length and the real length of file out of sync storage/maria/ma_check.c: Flush the page cache even if we got an error during zerofill. (This fixes a call to assert() in case of a too short data file) storage/maria/ma_pagecache.c: Mark page as read when we do a write of a full page. This fixes a bug when we got an error during read and then used direct write to page to update it storage/maria/ma_state.c: Restore info->lock.type after call to maria_versioning. Fixed crash in maria_recover.test storage/maria/maria_read_log.c: Don't write thread id in debug log. (Not needed as maria_read_log is a single treaded program) --- sql/sql_insert.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 16aa59d992e..b3a74b15652 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -107,8 +107,8 @@ static bool check_view_insertability(THD *thd, TABLE_LIST *view); 1 Error */ -bool check_view_single_update(List &fields, TABLE_LIST *view, - table_map *map) +bool check_view_single_update(List &fields, List &values, + TABLE_LIST *view, table_map *map) { /* it is join view => we need to find the table for update */ List_iterator_fast it(fields); @@ -116,6 +116,10 @@ bool check_view_single_update(List &fields, TABLE_LIST *view, TABLE_LIST *tbl= 0; // reset for call to check_single_table() table_map tables= 0; + while ((item= it++)) + tables|= item->used_tables(); + + it.init(values); while ((item= it++)) tables|= item->used_tables(); @@ -238,7 +242,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, if (table_list->effective_algorithm == VIEW_ALGORITHM_MERGE) { - if (check_view_single_update(fields, table_list, map)) + if (check_view_single_update(fields, values, table_list, map)) return -1; table= table_list->table; } @@ -298,7 +302,8 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, */ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list, - List &update_fields, table_map *map) + List &update_fields, + List &update_values, table_map *map) { TABLE *table= insert_table_list->table; my_bool timestamp_mark; @@ -320,7 +325,8 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list, return -1; if (insert_table_list->effective_algorithm == VIEW_ALGORITHM_MERGE && - check_view_single_update(update_fields, insert_table_list, map)) + check_view_single_update(update_fields, update_values, insert_table_list, + map)) return -1; if (table->timestamp_field) @@ -1246,7 +1252,8 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, if (!res && duplic == DUP_UPDATE) { select_lex->no_wrap_view_item= TRUE; - res= check_update_fields(thd, context->table_list, update_fields, &map); + res= check_update_fields(thd, context->table_list, update_fields, + update_values, &map); select_lex->no_wrap_view_item= FALSE; } @@ -2912,7 +2919,8 @@ select_insert::prepare(List &values, SELECT_LEX_UNIT *u) lex->select_lex.no_wrap_view_item= TRUE; res= res || check_update_fields(thd, context->table_list, - *info.update_fields, &map); + *info.update_fields, *info.update_values, + &map); lex->select_lex.no_wrap_view_item= FALSE; /* When we are not using GROUP BY and there are no ungrouped aggregate functions @@ -3580,7 +3588,7 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) DBUG_RETURN(-1); } - /* First field to copy */ + /* First field to copy */ field= table->field+table->s->fields - values.elements; /* Mark all fields that are given values */ -- cgit v1.2.1 From 7dc83c50436a36280e99f9c71006b05452d0b9fe Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 9 Jan 2009 06:11:37 +0200 Subject: Fixed bugs from my latest patch found by pushbuild: Bug #41962 Maria: view-related test failures (insert, view, maria, trigger tests) Added error handling for wrong update of view. See Bug #41760 Inserting into multiple-table views is not working mysql-test/r/delayed.result: Fixed test as we are now testing values before fields. Added new tests to test all error combinations mysql-test/suite/maria/r/maria.result: Added error handling for not supported update of view. mysql-test/suite/maria/t/maria.test: Added error handling for not supported update of view. mysql-test/t/delayed.test: Fixed test as we are now testing values before fields. Added new tests to test all error combinations sql/sql_base.cc: Fixed warning from valgrind sql/sql_insert.cc: Don't test from which table values are in case of INSERT ... SELECT Run fix_fields() in values before we do it on fields. This is needed becasue check_view_single_update() are accessing values. storage/maria/ma_blockrec.c: Don't call pagecache_delete_pages() if no pages to delete. This fixes a DBUG_ASSERT() error in maria_test_recovery --- sql/sql_insert.cc | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index b3a74b15652..175358140e1 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -88,6 +88,7 @@ static bool check_view_insertability(THD *thd, TABLE_LIST *view); SYNOPSIS check_view_single_update() fields The insert/update fields to be checked. + values Values to use for update view The view for insert. map [in/out] The insert table map. @@ -107,7 +108,7 @@ static bool check_view_insertability(THD *thd, TABLE_LIST *view); 1 Error */ -bool check_view_single_update(List &fields, List &values, +bool check_view_single_update(List &fields, List *values, TABLE_LIST *view, table_map *map) { /* it is join view => we need to find the table for update */ @@ -119,10 +120,15 @@ bool check_view_single_update(List &fields, List &values, while ((item= it++)) tables|= item->used_tables(); - it.init(values); - while ((item= it++)) - tables|= item->used_tables(); + if (values) + { + it.init(*values); + while ((item= it++)) + tables|= item->used_tables(); + } + /* Convert to real table bits */ + tables&= ~PSEUDO_TABLE_BITS; /* Check found map against provided map */ if (*map) { @@ -156,6 +162,10 @@ error: fields The insert fields. values The insert values. check_unique If duplicate values should be rejected. + fields_and_values_from_different_maps + Set to 1 if fields and values are using + different table maps, like on select ... insert + map Store here table map for used fields NOTE Clears TIMESTAMP_AUTO_SET_ON_INSERT from table->timestamp_field_type @@ -169,7 +179,9 @@ error: static int check_insert_fields(THD *thd, TABLE_LIST *table_list, List &fields, List &values, - bool check_unique, table_map *map) + bool check_unique, + bool fields_and_values_from_different_maps, + table_map *map) { TABLE *table= table_list->table; @@ -242,7 +254,10 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, if (table_list->effective_algorithm == VIEW_ALGORITHM_MERGE) { - if (check_view_single_update(fields, values, table_list, map)) + if (check_view_single_update(fields, + fields_and_values_from_different_maps ? + (List*) 0 : &values, + table_list, map)) return -1; table= table_list->table; } @@ -325,8 +340,8 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list, return -1; if (insert_table_list->effective_algorithm == VIEW_ALGORITHM_MERGE && - check_view_single_update(update_fields, update_values, insert_table_list, - map)) + check_view_single_update(update_fields, &update_values, + insert_table_list, map)) return -1; if (table->timestamp_field) @@ -1234,9 +1249,9 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, table_list->next_local= 0; context->resolve_in_table_list_only(table_list); - res= check_insert_fields(thd, context->table_list, fields, *values, - !insert_into_view, &map) || - setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0); + res= (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0) || + check_insert_fields(thd, context->table_list, fields, *values, + !insert_into_view, 0, &map)); if (!res && check_fields) { @@ -1249,6 +1264,9 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, thd->abort_on_warning= saved_abort_on_warning; } + if (!res) + res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0); + if (!res && duplic == DUP_UPDATE) { select_lex->no_wrap_view_item= TRUE; @@ -1259,9 +1277,6 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, /* Restore the current context. */ ctx_state.restore_state(context, table_list); - - if (!res) - res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0); } if (res) @@ -2890,10 +2905,9 @@ select_insert::prepare(List &values, SELECT_LEX_UNIT *u) we are fixing fields from insert list. */ lex->current_select= &lex->select_lex; - res= check_insert_fields(thd, table_list, *fields, values, - !insert_into_view, &map) || - setup_fields(thd, 0, values, MARK_COLUMNS_READ, 0, 0); - + res= (setup_fields(thd, 0, values, MARK_COLUMNS_READ, 0, 0) || + check_insert_fields(thd, table_list, *fields, values, + !insert_into_view, 1, &map)); if (!res && fields->elements) { bool saved_abort_on_warning= thd->abort_on_warning; -- cgit v1.2.1 From 3fca23902cdf36bdc52f2d5826bfd24c2024feb8 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 16 Jan 2009 00:25:53 +0200 Subject: Log queries to maria_log if compiled with EXTRA_DEBUG Added DBUG_ASSERT() to unlikely error senario Don't use errno == 0 in maria_create() / myisam_create() sql/sql_insert.cc: Added DBUG_ASSERT() for case that should never happen in real life Added my_error() to avoid assert if mysql_lock() or postlock() doesn't call my_error() storage/maria/ha_maria.cc: Log queries to maria_log if compiled with EXTRA_DEBUG storage/maria/ma_create.c: Don't use errno == 0 storage/maria/ma_loghandler.c: Added logging of debug info to maria_log storage/maria/ma_loghandler.h: Added logging of debug info to maria_log storage/maria/ma_recovery.c: Added printing of debug info from maria_log storage/maria/trnman.c: Added functions to read/store state in TRN storage/maria/trnman.h: Added functions to read/store state in TRN storage/maria/trnman_public.h: Added state in TRN to remmeber if we have already logged the query storage/myisam/mi_create.c: Don't use errno == 0 --- sql/sql_insert.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 175358140e1..1831e13dcf2 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3493,6 +3493,9 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, MYSQL_LOCK_IGNORE_FLUSH, ¬_used)) || hooks->postlock(&table, 1)) { + DBUG_ASSERT(0); // This should never happen + /* purecov: begin tested */ + my_error(ER_CANT_LOCK, MYF(0), my_errno); if (*lock) { mysql_unlock_tables(thd, *lock); @@ -3502,6 +3505,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, if (!create_info->table_existed) drop_open_table(thd, table, create_table->db, create_table->table_name); DBUG_RETURN(0); + /* purecov: end */ } DBUG_RETURN(table); } -- cgit v1.2.1 From 364f8611b0035e404b4acc137361176dea7a45bd Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 16 Jan 2009 11:38:02 +0200 Subject: Fixed issues in last push found by pushbuild sql/sql_insert.cc: Removed DBUG_ASSERT() that is triggered by deadlock-innodb test storage/maria/ma_loghandler.c: Removed compiler warnings storage/maria/trnman_public.h: Fixed wrong code from last push --- sql/sql_insert.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 1831e13dcf2..b10a7789079 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3493,8 +3493,11 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, MYSQL_LOCK_IGNORE_FLUSH, ¬_used)) || hooks->postlock(&table, 1)) { - DBUG_ASSERT(0); // This should never happen /* purecov: begin tested */ + /* + This can happen in innodb when you get a deadlock when using same table + in insert and select + */ my_error(ER_CANT_LOCK, MYF(0), my_errno); if (*lock) { -- cgit v1.2.1 From bd4e65515f556b6bca45d06d81370d99cf649647 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sat, 31 Jan 2009 23:22:44 +0200 Subject: Fixed compiler warnings found by gcc 4.3.2 - Added braces around expressions with &&, ||, & and | - Added empty line before ; for empty while and for loops - Added () around if with assignments - Removed const before function returning simple type Changed BUILD scripts to not build with NDB BUILD/SETUP.sh: By default, don't build ndb with --max in Maria tree. NDB is not kept up to date anyway in 5.1 client/mysql.cc: Added braces around && to get rid of compiler warnings sql/event_db_repository.cc: Added braces around && to get rid of compiler warnings sql/events.cc: Added braces around && to get rid of compiler warnings sql/field.cc: Added braces around && to get rid of compiler warnings Fixed for loops sql/field.h: Added braces around & to get rid of compiler warnings sql/field_conv.cc: Added braces around && to get rid of compiler warnings Fixed bug when copying between DATETIME fields and strict dates are used Removed not needeed else sql/gstream.cc: Added braces around && to get rid of compiler warnings sql/ha_ndbcluster.cc: Added braces around && to get rid of compiler warnings Added {} to get rid of compiler warnings sql/handler.cc: Added braces around && to get rid of compiler warnings sql/item.cc: Added braces around && to get rid of compiler warnings sql/item_cmpfunc.cc: Added braces around && to get rid of compiler warnings Removed some not needed space sql/item_func.cc: Added braces around && to get rid of compiler warnings sql/item_strfunc.cc: Added braces around && to get rid of compiler warnings sql/item_subselect.cc: Added braces around && to get rid of compiler warnings sql/item_sum.cc: Added braces around && to get rid of compiler warnings sql/item_timefunc.cc: Added braces around && to get rid of compiler warnings sql/item_xmlfunc.cc: Added empty line before ; for empty while and for loops sql/log.cc: Added braces around && to get rid of compiler warnings sql/log_event.cc: Added braces around && to get rid of compiler warnings Removed not needed else sql/log_event_old.cc: Added braces around && to get rid of compiler warnings sql/opt_range.cc: Added braces around && to get rid of compiler warnings sql/opt_sum.cc: Added braces around && to get rid of compiler warnings sql/set_var.cc: Added empty line before ; for empty while and for loops Added () around if with assignments sql/slave.cc: Added braces around && to get rid of compiler warnings Added empty line before ; for empty while and for loops sql/spatial.h: Added braces around && to get rid of compiler warnings sql/sql_acl.cc: Added braces around && to get rid of compiler warnings sql/sql_analyse.cc: Added empty line before ; for empty while and for loops sql/sql_base.cc: Added braces around && to get rid of compiler warnings sql/sql_connect.cc: Added braces around && to get rid of compiler warnings sql/sql_db.cc: Added braces around && to get rid of compiler warnings sql/sql_delete.cc: Added braces around && to get rid of compiler warnings sql/sql_help.cc: Added empty line before ; for empty while and for loops sql/sql_insert.cc: Added braces around && to get rid of compiler warnings Added () around if with assignments sql/sql_lex.cc: Cast char array references to uchar; Fixed wrong array referencing when using characters > ASCII 128 in SQL statments Added empty line before ; for empty while and for loops Trivial indent fixes Added braces around && to get rid of compiler warnings sql/sql_load.cc: Added braces around && to get rid of compiler warnings sql/sql_parse.cc: Added braces around && to get rid of compiler warnings sql/sql_partition.cc: Added braces around && to get rid of compiler warnings sql/sql_plugin.cc: Fixed bug in detecing if option variable should be readonly Added empty line before ; for empty while and for loops sql/sql_prepare.cc: Added braces around && to get rid of compiler warnings sql/sql_select.cc: Added braces around && to get rid of compiler warnings Added () around if with assignments Added empty line before ; for empty while and for loops sql/sql_show.cc: Added braces around && to get rid of compiler warnings sql/sql_table.cc: Added braces around && to get rid of compiler warnings sql/sql_trigger.cc: Added braces around && to get rid of compiler warnings sql/sql_update.cc: Added braces around && to get rid of compiler warnings sql/sql_yacc.yy: Added braces around && to get rid of compiler warnings sql/table.cc: Added braces around && to get rid of compiler warnings sql/table.h: Added braces around && to get rid of compiler warnings sql/time.cc: Added braces around && to get rid of compiler warnings sql/tztime.cc: Added braces around && to get rid of compiler warnings sql/uniques.cc: Added braces around && to get rid of compiler warnings storage/federated/ha_federated.cc: Fixed bug in testing of variable to ha_info() (Not critical) storage/heap/ha_heap.cc: Added braces around && to get rid of compiler warnings storage/maria/ha_maria.cc: Fixed bug: Mark that maria_log_dir_path is readonly Added braces around && to get rid of compiler warnings storage/ndb/include/ndbapi/NdbEventOperation.hpp: Removed const before function returning simple type storage/ndb/include/ndbapi/NdbOperation.hpp: Removed const before function returning simple type storage/ndb/src/ndbapi/Ndb.cpp: Added empty line before ; for empty while and for loops storage/ndb/src/ndbapi/NdbEventOperation.cpp: Removed const before function returning simple type storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp: Removed const before function returning simple type storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp: Removed const before function returning simple type storage/ndb/src/ndbapi/NdbRecAttr.cpp: Added empty line before ; for empty while and for loops storage/ndb/src/ndbapi/TransporterFacade.hpp: Added braces around && to get rid of compiler warnings --- sql/sql_insert.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index b10a7789079..0c3ea8bd731 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -413,7 +413,7 @@ void upgrade_lock_type_for_insert(THD *thd, thr_lock_type *lock_type, bool is_multi_insert) { if (duplic == DUP_UPDATE || - duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT) + (duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT)) { *lock_type= TL_WRITE_DEFAULT; return; @@ -882,8 +882,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, */ query_cache_invalidate3(thd, table_list, 1); } - if (changed && error <= 0 || thd->transaction.stmt.modified_non_trans_table - || was_insert_delayed) + if ((changed && error <= 0) || + thd->transaction.stmt.modified_non_trans_table || + was_insert_delayed) { if (mysql_bin_log.is_open()) { @@ -3187,7 +3188,7 @@ bool select_insert::send_eof() table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); - if (changed= (info.copied || info.deleted || info.updated)) + if ((changed= (info.copied || info.deleted || info.updated))) { /* We must invalidate the table in the query cache before binlog writing -- cgit v1.2.1 From f7a75b999b4b0e51c647fa19df35db517e0b6721 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 16 Oct 2009 15:57:48 -0700 Subject: The main commit of Andrey Zhakov's patch introducing vurtual(computed) columns. The original patch has been ameliorated by Sanja and Igor. --- sql/sql_insert.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 710da7067e4..31bf2ddd4d8 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -280,6 +280,9 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, } } } + /* Mark virtual columns used in the insert statement */ + if (table->vfield) + table->mark_virtual_columns_for_write(); // For the values we need select_priv #ifndef NO_EMBEDDED_ACCESS_CHECKS table->grant.want_privilege= (SELECT_ACL & ~table->grant.privilege); -- cgit v1.2.1 From ab0905c6d7041928b260adb60ff551275e8153bc Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 19 Oct 2009 20:14:48 +0300 Subject: This is based on the userstatv2 patch from Percona and OurDelta. The original code comes, as far as I know, from Google (Mark Callaghan's team) with additional work from Percona, Ourdelta and Weldon Whipple. This code provides the same functionallity, but with a lot of changes to make it faster and better fit the MariaDB infrastucture. Added new status variables: - Com_show_client_statistics, Com_show_index_statistics, Com_show_table_statistics, Com_show_user_statistics - Access_denied_errors, Busy_time (clock time), Binlog_bytes_written, Cpu_time, Empty_queries, Rows_sent, Rows_read Added new variable / startup option 'userstat' to control if user statistics should be enabled or not Added my_getcputime(); Returns cpu time used by this thread. New FLUSH commands: - FLUSH SLOW QUERY LOG - FLUSH TABLE_STATISTICS - FLUSH INDEX_STATISTICS - FLUSH USER_STATISTICS - FLUSH CLIENT_STATISTICS New SHOW commands: - SHOW CLIENT_STATISTICS - SHOW USER_STATISTICS - SHOW TABLE_STATISTICS - SHOW INDEX_STATISTICS New Information schemas: - CLIENT_STATISTICS - USER_STATISTICS - INDEX_STATISTICS - TABLE_STATISTICS Added support for all new flush commands to mysqladmin Added handler::ha_... wrappers for all handler read calls to do statistics counting - Changed all code to use new ha_... calls - Count number of read rows, changed rows and rows read trough an index Added counting of number of bytes sent to binary log (status variable Binlog_bytes_written) Added counting of access denied errors (status variable Access_denied_erors) Bugs fixed: - Fixed bug in add_to_status() and add_diff_to_status() where longlong variables where threated as long - CLOCK_GETTIME was not propely working on Linuxm client/mysqladmin.cc: Added support for all new flush commmands and some common combinations: flush-slow-log flush-table-statistics flush-index-statistics flush-user-statistics flush-client-statistics flush-all-status flush-all-statistics configure.in: Added checking if clock_gettime needs the librt. (Fixes Bug #37639 clock_gettime is never used/enabled in Linux/Unix) include/my_sys.h: Added my_getcputime() include/mysql_com.h: Added LIST_PROCESS_HOST_LEN & new REFRESH target defines mysql-test/r/information_schema.result: New information schema tables added mysql-test/r/information_schema_all_engines.result: New information schema tables added mysql-test/r/information_schema_db.result: New information schema tables added mysql-test/r/log_slow.result: Added testing that flosh slow query logs is accepted mysql-test/r/status_user.result: Basic testing of user, client, table and index statistics mysql-test/t/log_slow.test: Added testing that flosh slow query logs is accepted mysql-test/t/status_user-master.opt: Ensure that we get a fresh restart before running status_user.test mysql-test/t/status_user.test: Basic testing of user, client, table and index statistics mysys/my_getsystime.c: Added my_getcputime() Returns cpu time used by this thread. sql/authors.h: Updated authors to have core and original MySQL developers first. sql/event_data_objects.cc: Updated call to mysql_reset_thd_for_next_command() sql/event_db_repository.cc: Changed to use new ha_... calls sql/filesort.cc: Changed to use new ha_... calls sql/ha_partition.cc: Changed to use new ha_... calls Fixed comment syntax sql/handler.cc: Changed to use new ha_... calls Reset table statistics Added code to update global table and index status Added counting of rows changed sql/handler.h: Added table and index statistics variables Added function reset_statistics() Added handler::ha_... wrappers for all handler read calls to do statistics counting Protected all normal read calls to ensure we use the new calls in the server. Made ha_partition a friend class so that partition code can call the old read functions sql/item_subselect.cc: Changed to use new ha_... calls sql/lex.h: Added keywords for new information schema tables and flush commands sql/log.cc: Added flush_slow_log() Added counting of number of bytes sent to binary log Removed not needed test of thd (It's used before, so it's safe to use) Added THD object to MYSQL_BIN_LOG::write_cache() to simplify statistics counting sql/log.h: Added new parameter to write_cache() Added flush_slow_log() functions. sql/log_event.cc: Updated call to mysql_reset_thd_for_next_command() Changed to use new ha_... calls sql/log_event_old.cc: Updated call to mysql_reset_thd_for_next_command() Changed to use new ha_... calls sql/mysql_priv.h: Updated call to mysql_reset_thd_for_next_command() Added new statistics functions and variables needed by these. sql/mysqld.cc: Added new statistics variables and structures to handle these Added new status variables: - Com_show_client_statistics, Com_show_index_statistics, Com_show_table_statistics, Com_show_user_statistics - Access_denied_errors, Busy_time (clock time), Binlog_bytes_written, Cpu_time, Empty_queries, Rows_set, Rows_read Added new option 'userstat' to control if user statistics should be enabled or not sql/opt_range.cc: Changed to use new ha_... calls sql/opt_range.h: Changed to use new ha_... calls sql/opt_sum.cc: Changed to use new ha_... calls sql/records.cc: Changed to use new ha_... calls sql/set_var.cc: Added variable 'userstat' sql/sp.cc: Changed to use new ha_... calls sql/sql_acl.cc: Changed to use new ha_... calls Added counting of access_denied_errors sql/sql_base.cc: Added call to statistics functions sql/sql_class.cc: Added usage of org_status_var, to store status variables at start of command Added functions THD::update_stats(), THD::update_all_stats() Fixed bug in add_to_status() and add_diff_to_status() where longlong variables where threated as long sql/sql_class.h: Added new status variables to status_var Moved variables that was not ulong in status_var last. Added variables to THD for storing temporary values during statistics counting sql/sql_connect.cc: Variables and functions to calculate user and client statistics Added counting of access_denied_errors and lost_connections sql/sql_cursor.cc: Changed to use new ha_... calls sql/sql_handler.cc: Changed to use new ha_... calls sql/sql_help.cc: Changed to use new ha_... calls sql/sql_insert.cc: Changed to use new ha_... calls sql/sql_lex.h: Added SQLCOM_SHOW_USER_STATS, SQLCOM_SHOW_TABLE_STATS, SQLCOM_SHOW_INDEX_STATS, SQLCOM_SHOW_CLIENT_STATS sql/sql_parse.cc: Added handling of: - SHOW CLIENT_STATISTICS - SHOW USER_STATISTICS - SHOW TABLE_STATISTICS - SHOW INDEX_STATISTICS Added handling of new FLUSH commands: - FLUSH SLOW QUERY LOGS - FLUSH TABLE_STATISTICS - FLUSH INDEX_STATISTICS - FLUSH USER_STATISTICS - FLUSH CLIENT_STATISTICS Added THD parameter to mysql_reset_thd_for_next_command() Added initialization and calls to user statistics functions Added increment of statistics variables empty_queries, rows_sent and access_denied_errors. Added counting of cpu time per query sql/sql_plugin.cc: Changed to use new ha_... calls sql/sql_prepare.cc: Updated call to mysql_reset_thd_for_next_command() sql/sql_select.cc: Changed to use new ha_... calls Indentation changes sql/sql_servers.cc: Changed to use new ha_... calls sql/sql_show.cc: Added counting of access denied errors Added function for new information schema tables: - CLIENT_STATISTICS - USER_STATISTICS - INDEX_STATISTICS - TABLE_STATISTICS Changed to use new ha_... calls sql/sql_table.cc: Changed to use new ha_... calls sql/sql_udf.cc: Changed to use new ha_... calls sql/sql_update.cc: Changed to use new ha_... calls sql/sql_yacc.yy: Add new show and flush commands sql/structs.h: Add name_length to KEY to avoid some strlen Added cache_name to KEY for fast storage of keyvalue in cache Added structs USER_STATS, TABLE_STATS, INDEX_STATS Added function prototypes for statistics functions sql/table.cc: Store db+table+index name into keyinfo->cache_name sql/table.h: Added new information schema tables sql/tztime.cc: Changed to use new ha_... calls --- sql/sql_insert.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 710da7067e4..571ce84a7f1 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1425,7 +1425,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) goto err; if (table->file->ha_table_flags() & HA_DUPLICATE_POS) { - if (table->file->rnd_pos(table->record[1],table->file->dup_ref)) + if (table->file->ha_rnd_pos(table->record[1],table->file->dup_ref)) goto err; } else @@ -1446,9 +1446,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) } } key_copy((uchar*) key,table->record[0],table->key_info+key_nr,0); - if ((error=(table->file->index_read_idx_map(table->record[1],key_nr, - (uchar*) key, HA_WHOLE_KEY, - HA_READ_KEY_EXACT)))) + if ((error= (table->file->ha_index_read_idx_map(table->record[1], + key_nr, (uchar*) key, + HA_WHOLE_KEY, + HA_READ_KEY_EXACT)))) goto err; } if (info->handle_duplicates == DUP_UPDATE) -- cgit v1.2.1 From 166e0683c0d45a79716d8913ec9ecaf3177343fa Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sat, 7 Nov 2009 12:34:19 +0200 Subject: Added error handling for my_seek() & my_tell() failures mysys/my_seek.c: Give error if MY_WME is used sql/sql_insert.cc: Fixed compiler warning storage/maria/ha_maria.cc: Changed driver of Maria storage engine project --- sql/sql_insert.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 85b77bbb326..0cd67a16a25 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3437,10 +3437,12 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, Create_field *cr_field; Field *field, *def_field; if (item->type() == Item::FUNC_ITEM) + { if (item->result_type() != STRING_RESULT) field= item->tmp_table_field(&tmp_table); else field= item->tmp_table_field_from_field_type(&tmp_table, 0); + } else field= create_tmp_field(thd, &tmp_table, item, item->type(), (Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0, -- cgit v1.2.1 From d210df50a21d82a1f20c6bc786149478801e91c6 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 26 Nov 2009 22:19:33 +0200 Subject: Added protection around usage of thd->mysys_var (May be changed to 0 by scheduler) --- sql/sql_insert.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 0cd67a16a25..3e32209f956 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2279,6 +2279,7 @@ void kill_delayed_threads(void) while ((di= it++)) { di->thd.killed= THD::KILL_CONNECTION; + pthread_mutex_lock(&di->thd.LOCK_thd_data); if (di->thd.mysys_var) { pthread_mutex_lock(&di->thd.mysys_var->mutex); @@ -2297,6 +2298,7 @@ void kill_delayed_threads(void) } pthread_mutex_unlock(&di->thd.mysys_var->mutex); } + pthread_mutex_unlock(&di->thd.LOCK_thd_data); } VOID(pthread_mutex_unlock(&LOCK_delayed_insert)); // For unlink from list } -- cgit v1.2.1 From d8e44ef589964a7afc28ffd7c1398be168a9d693 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 4 Dec 2009 17:12:22 +0200 Subject: Fixed Bug#47017 rpl_timezone fails on PB-2 with mismatch error Fixed coredump in sql_plugin.cc:intern_plugin_lock() on mysqld start with PBXT sql/mysqld.cc: Fixed coredump in sql_plugin.cc:intern_plugin_lock() on mysqld start with PBXT sql/share/errmsg.txt: Row numbers are always positive sql/sql_base.cc: Fixed race condition in lock tables when killing insert_delayed thread. This fixes Bug#47017 rpl_timezone fails on PB-2 with mismatch error (Note that the patch only adds a continue; The rest is (required) indentation changes) sql/sql_class.cc: Fixed wrong output for high end machines in outfile_loaddata. (Problem was that ER_TRUNCATED_WRONG_VALUE_FOR_FIELD expects ulong, not ulonglong) sql/sql_insert.cc: Ensure that if we get a lock problem with delayed_insert, the error is logged. --- sql/sql_insert.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 937576f4a68..8b78114716a 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2618,7 +2618,7 @@ bool Delayed_insert::handle_inserts(void) or if another thread is removing the current table definition from the table cache. */ - my_error(ER_DELAYED_CANT_CHANGE_LOCK,MYF(ME_FATALERROR), + my_error(ER_DELAYED_CANT_CHANGE_LOCK, MYF(ME_FATALERROR | ME_NOREFRESH), table->s->table_name.str); goto err; } @@ -2791,10 +2791,11 @@ bool Delayed_insert::handle_inserts(void) query_cache_invalidate3(&thd, table, 1); if (thr_reschedule_write_lock(*thd.lock->locks)) { - /* This is not known to happen. */ - my_error(ER_DELAYED_CANT_CHANGE_LOCK,MYF(ME_FATALERROR), - table->s->table_name.str); - goto err; + /* This is not known to happen. */ + my_error(ER_DELAYED_CANT_CHANGE_LOCK, + MYF(ME_FATALERROR | ME_NOREFRESH), + table->s->table_name.str); + goto err; } if (!using_bin_log) table->file->extra(HA_EXTRA_WRITE_CACHE); -- cgit v1.2.1 From 291fd9698340f3d83ff096542720f7335cb078d2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 29 Mar 2010 17:13:53 +0200 Subject: pluggable auth with plugin examples Makefile.am: add new API files to the check_abi rule, remove duplicates client/CMakeLists.txt: now a client can use dlopen too client/Makefile.am: be csh-friendly include/my_global.h: add dummy plugs for dlopen and co. for the code that needs them to work in static builds mysys/Makefile.am: be csh-friendly plugin/auth/dialog.c: typo fixed --- sql/sql_insert.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index afc86ef6d4f..78cc103793d 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1778,8 +1778,10 @@ public: table(0),tables_in_use(0),stacked_inserts(0), status(0), dead(0), group_count(0) { - thd.security_ctx->user=thd.security_ctx->priv_user=(char*) delayed_user; + thd.security_ctx->user=(char*) delayed_user; thd.security_ctx->host=(char*) my_localhost; + strmake(thd.security_ctx->priv_user, thd.security_ctx->user, + USERNAME_LENGTH); thd.current_tablenr=0; thd.version=refresh_version; thd.command=COM_DELAYED_INSERT; -- cgit v1.2.1 From e24e1668bc112afe4b4f6b3dc4d5b8d10635f60b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 8 Apr 2010 14:10:05 +0200 Subject: MWL#43 CREATE TABLE options (by Sanja) Docs/sp-imp-spec.txt: New sql_mode added. include/my_base.h: Flag in frm of create options. libmysqld/CMakeLists.txt: New files added. libmysqld/Makefile.am: New files added. mysql-test/r/events_bugs.result: New sql_mode added. mysql-test/r/information_schema.result: New sql_mode added. mysql-test/r/sp.result: New sql_mode added. mysql-test/r/system_mysql_db.result: New sql_mode added. mysql-test/suite/funcs_1/r/is_columns_mysql.result: New sql_mode added. mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: New sql_mode added. mysql-test/t/events_bugs.test: New sql_mode added. mysql-test/t/sp.test: New sql_mode added. scripts/mysql_system_tables.sql: New sql_mode added. scripts/mysql_system_tables_fix.sql: New sql_mode added. sql/CMakeLists.txt: New files added. sql/Makefile.am: New files added. sql/event_db_repository.cc: New sql_mode added. sql/field.cc: Create options support added. sql/field.h: Create options support added. sql/ha_partition.cc: Create options support added. sql/handler.cc: Create options support added. sql/handler.h: Create options support added. sql/log_event.h: New sql_mode added. sql/mysql_priv.h: New sql_mode added. sql/mysqld.cc: New sql_mode added. sql/share/errmsg.txt: New error messages added. sql/sp.cc: New sql_mode added. sql/sp_head.cc: Create options support added. sql/sql_class.cc: Create options support added. Debug added. sql/sql_class.h: Create options support added. sql/sql_insert.cc: my_safe_a* moved to mysqld_priv.h sql/sql_lex.h: Create options support added. sql/sql_parse.cc: Create options support added. sql/sql_show.cc: Create options support added. sql/sql_table.cc: Create options support added. sql/sql_view.cc: New sql_mode added. sql/sql_yacc.yy: Create options support added. sql/structs.h: Create options support added. sql/table.cc: Create options support added. sql/table.h: Create options support added. sql/unireg.cc: Create options support added. storage/example/ha_example.cc: Create options example. storage/example/ha_example.h: Create options example. storage/pbxt/src/discover_xt.cc: Create options support added. --- sql/sql_insert.cc | 9 --------- 1 file changed, 9 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 78cc103793d..eec271d6e13 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -72,15 +72,6 @@ static void unlink_blobs(register TABLE *table); #endif static bool check_view_insertability(THD *thd, TABLE_LIST *view); -/* Define to force use of my_malloc() if the allocated memory block is big */ - -#ifndef HAVE_ALLOCA -#define my_safe_alloca(size, min_length) my_alloca(size) -#define my_safe_afree(ptr, size, min_length) my_afree(ptr) -#else -#define my_safe_alloca(size, min_length) ((size <= min_length) ? my_alloca(size) : my_malloc(size,MYF(0))) -#define my_safe_afree(ptr, size, min_length) if (size > min_length) my_free(ptr,MYF(0)) -#endif /* Check that insert/update fields are from the same single table of a view. -- cgit v1.2.1 From 40901007434a30882e1f51171551ff287fbe540c Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 15 Jul 2010 16:51:05 -0700 Subject: Fixed bug #603186. There were two problems that caused wrong results reported with this bug. 1. In some cases stored(persistent) virtual columns were not marked in the write_set and in the vcol_set bitmaps. 2. If the list of fields in an insert command was empty then the values of the stored virtual columns were set to default. To fix the first problem the function st_table::mark_virtual_columns_for_write was modified. Now the function has a parameter that says whether the virtual columns are to be marked for insert or for update. To fix the second problem a special handling of empty insert lists is added in the function fill_record(). --- sql/sql_insert.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 54234eb8ab4..4ce13374d03 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -273,7 +273,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, } /* Mark virtual columns used in the insert statement */ if (table->vfield) - table->mark_virtual_columns_for_write(); + table->mark_virtual_columns_for_write(TRUE); // For the values we need select_priv #ifndef NO_EMBEDDED_ACCESS_CHECKS table->grant.want_privilege= (SELECT_ACL & ~table->grant.privilege); @@ -1267,7 +1267,6 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, if (mysql_prepare_insert_check_table(thd, table_list, fields, select_insert)) DBUG_RETURN(TRUE); - /* Prepare the fields in the statement. */ if (values) { @@ -1320,6 +1319,18 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, if (!table) table= table_list->table; + if (!fields.elements && table->vfield) + { + for (Field **vfield_ptr= table->vfield; *vfield_ptr; vfield_ptr++) + { + if ((*vfield_ptr)->stored_in_db) + { + thd->lex->unit.insert_table_with_stored_vcol= table; + break; + } + } + } + if (!select_insert) { Item *fake_conds= 0; -- cgit v1.2.1 From f78b870c9bd11d5e25f6d423718b8f623f712377 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 19 Jul 2010 22:41:24 -0700 Subject: Fixed bug #607566. For queries with order by clauses that employed filesort usage of virtual column references in select lists could trigger assertion failures. It happened because a wrong vcol_set bitmap was used for filesort. It turned out that filesort required its own vcol_set bitmap. Made management of the vcol_set bitmaps similar to the management of the read_set and write_set bitmaps. --- sql/sql_insert.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 4ce13374d03..44dc7308292 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2109,7 +2109,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) copy= (TABLE*) client_thd->alloc(sizeof(*copy)+ (share->fields+1)*sizeof(Field**)+ share->reclength + - share->column_bitmap_size*2); + share->column_bitmap_size*3); if (!copy) goto error; @@ -2119,7 +2119,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) /* Assign the pointers for the field pointers array and the record. */ field= copy->field= (Field**) (copy + 1); bitmap= (uchar*) (field + share->fields + 1); - copy->record[0]= (bitmap + share->column_bitmap_size * 2); + copy->record[0]= (bitmap + share->column_bitmap_size*3); memcpy((char*) copy->record[0], (char*) table->record[0], share->reclength); /* Make a copy of all fields. @@ -2161,10 +2161,13 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) copy->def_read_set.bitmap= (my_bitmap_map*) bitmap; copy->def_write_set.bitmap= ((my_bitmap_map*) (bitmap + share->column_bitmap_size)); + copy->def_vcol_set.bitmap= ((my_bitmap_map*) + (bitmap + 2*share->column_bitmap_size)); copy->tmp_set.bitmap= 0; // To catch errors - bzero((char*) bitmap, share->column_bitmap_size*2); + bzero((char*) bitmap, share->column_bitmap_size*3); copy->read_set= ©->def_read_set; copy->write_set= ©->def_write_set; + copy->vcol_set= ©->def_vcol_set; DBUG_RETURN(copy); -- cgit v1.2.1 From 069a068c90d8fa6ccb8028f3f2cd42c238b04699 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 23 Jul 2010 22:37:21 +0200 Subject: restore the unintentinally broken ABI --- sql/sql_insert.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 3836b259396..100bda421b2 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -887,7 +887,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, auto_inc values from the delayed_insert thread as they share TABLE. */ table->file->ha_release_auto_increment(); - if (using_bulk_insert && table->file->ha_end_bulk_insert(0) && !error) + if (using_bulk_insert && table->file->ha_end_bulk_insert() && !error) { table->file->print_error(my_errno,MYF(0)); error=1; @@ -3277,7 +3277,7 @@ bool select_insert::send_eof() DBUG_PRINT("enter", ("trans_table=%d, table_type='%s'", trans_table, table->file->table_type())); - error= (!thd->prelocked_mode) ? table->file->ha_end_bulk_insert(0) : 0; + error= (!thd->prelocked_mode) ? table->file->ha_end_bulk_insert() : 0; table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); @@ -3360,7 +3360,7 @@ void select_insert::abort() { before. */ if (!thd->prelocked_mode) - table->file->ha_end_bulk_insert(0); + table->file->ha_end_bulk_insert(); /* If at least one row has been inserted/modified and will stay in -- cgit v1.2.1 From cd9706b27ee113e0d448cb9c509fa9a4d553c5ee Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 4 Aug 2010 16:01:13 +0300 Subject: Fixes bug when we run bcmp() on row when the storage engine hasn't filled in all fields in the row. This was triggered by innodb.innodb_multi_update, where we had a static length row without nulls and xtradb didn't fill in the delete-marker byte include/my_bitmap.h: Added prototype for bitmap_union_is_set_all() mysys/my_bitmap.c: Added function to check if union of two bit maps covers all bits. sql/mysql_priv.h: Updated protype for compare_record() sql/sql_insert.cc: Send to compare_record() flag if all fields are used. sql/sql_select.cc: Set share->null_bytes_for_compare. sql/sql_update.cc: In compare_record() don't use the fast cmp_record() (which is basically memcmp) if we don't know that all fields exists. Don't compare the null_bytes if there is no data there. sql/table.cc: Store in share->null_bytes_for_compare the number of bytes that has null or bit fields (but not delete marker) Store in can_cmp_whole_record if we can use memcmp() (assuming all rows are read) to compare rows in compare_record() sql/table.h: Added two elements in table->share to speed up checking how updated rows can be compared. --- sql/sql_insert.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 100bda421b2..6dd19f6e203 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1509,9 +1509,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) table->file->adjust_next_insert_id_after_explicit_value( table->next_number_field->val_int()); info->touched++; - if ((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ && + if (((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) && !bitmap_is_subset(table->write_set, table->read_set)) || - compare_record(table)) + compare_record(table, bitmap_union_is_set_all(table->write_set, + table->read_set))) { if ((error=table->file->ha_update_row(table->record[1], table->record[0])) && -- cgit v1.2.1 From 1f5b93e7720874c2b4a31e11af3fd8729d2beea7 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 4 Aug 2010 21:36:11 +0300 Subject: Fixed compiler warnings Fixed some wrong test cases Fixed bug in null handling in XtraDB extra/comp_err.c: Fixed compiler warnings extra/my_print_defaults.c: Fixed compiler warnings mysql-test/suite/binlog/t/binlog_killed.test: Added support for timeouts mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results (INNODB_SYS_TABLES had got new column) scripts/mysql_install_db.sh: Fixed typo sql/mysql_priv.h: Removed not needed argument for compare_record() sql/sql_insert.cc: Removed not needed argument for compare_record() sql/sql_update.cc: Removed not needed argument for compare_record() The argument is not needed becasue we copy the full record[0] to record[1] and the comparison should work even if all columns are not read sql/table.cc: The comparison of rows is independent of HA_PARTIAL_COLUMN_READ storage/maria/maria_chk.c: Fixed compiler warnings storage/maria/maria_read_log.c: Fixed compiler warnings storage/myisam/myisamchk.c: Fixed compiler warnings storage/myisam/myisampack.c: Fixed compiler warnings storage/xtradb/dict/dict0load.c: Fixed compiler warnings storage/xtradb/row/row0sel.c: Fixed null handling in XtraDB. (See comment) storage/xtradb/trx/trx0sys.c: Fixed compiler warnings support-files/compiler_warnings.supp: Fixed compiler warnings --- sql/sql_insert.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 6dd19f6e203..6b5d60d8613 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1511,8 +1511,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) info->touched++; if (((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) && !bitmap_is_subset(table->write_set, table->read_set)) || - compare_record(table, bitmap_union_is_set_all(table->write_set, - table->read_set))) + compare_record(table)) { if ((error=table->file->ha_update_row(table->record[1], table->record[0])) && -- cgit v1.2.1 From bdba1d11c4f3f2b1e2fe391a036ecdb703b8812f Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 24 Sep 2010 01:00:32 +0300 Subject: Change some my_bool in C++ classes and a few functions to bool to detect wrong usage of bool/my_bool. Fix some bugs where we stored values other than 0 or 1 in my_bool Fixed some compiler warnings client/mysql.cc: Changed interrupted_query from my_bool to int, as we stored 2 in it. client/mysqladmin.cc: Changed return variable type to same type as function value type client/mysqltest.cc: Changed 'found' to int as we store other values than 0 or 1 into it Changed type for parameter of set_reconnect() to match usage. extra/libevent/evbuffer.c: Added __attribute__((unused)) extra/libevent/event.c: Added __attribute__((unused)) extra/libevent/signal.c: Added __attribute__((unused)) sql/event_data_objects.h: my_bool -> bool sql/event_db_repository.cc: my_bool -> bool sql/event_db_repository.h: my_bool -> bool sql/event_parse_data.h: my_bool -> bool sql/events.cc: my_bool -> bool sql/events.h: my_bool -> bool sql/field.cc: my_bool -> bool sql/field.h: my_bool -> bool sql/hash_filo.h: my_bool -> bool sql/item.cc: my_bool -> bool sql/item.h: my_bool -> bool sql/item_cmpfunc.h: my_bool -> bool Changed result_for_null_param from my_bool to int as we stored -1 in it. sql/item_func.cc: my_bool -> bool Modified udf wrapper functions so that the UDF functions would continue to use my_bool. (To keep compatibility with UDF:s) sql/item_func.h: my_bool -> bool sql/item_subselect.h: my_bool -> bool sql/item_sum.cc: Modified udf wrapper functions so that the UDF functions would continue to use my_bool. (To keep compatibility with UDF:s) sql/parse_file.h: my_bool -> bool sql/rpl_mi.h: my_bool -> bool sql/sp_rcontext.h: my_bool -> bool sql/sql_analyse.h: my_bool -> bool sql/sql_base.cc: Change some assignments so that we don't initialize bool variables with int's. sql/sql_bitmap.h: my_bool -> bool sql/sql_cache.cc: my_bool -> bool sql/sql_cache.h: my_bool -> bool sql/sql_class.h: my_bool -> bool sql/sql_insert.cc: Change some assignments so that we don't initialize bool variables with int's. sql/sql_prepare.cc: my_bool -> bool sql/table.h: my_bool -> bool storage/maria/ma_check.c: Removed duplicate assignment strings/decimal.c: Fixed wrong variable usage. Don't do complex arithmetic on bool when simple works. --- sql/sql_insert.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index ea138807122..8399cec1a23 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3487,7 +3487,8 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, tmp_table.s->db_low_byte_first= test(create_info->db_type == myisam_hton || create_info->db_type == heap_hton); - tmp_table.null_row=tmp_table.maybe_null=0; + tmp_table.null_row= 0; + tmp_table.maybe_null= 0; while ((item=it++)) { -- cgit v1.2.1