From 5bb5e0f25e083368fa919631426aa66afb98484f Mon Sep 17 00:00:00 2001 From: Staale Smedseng Date: Wed, 12 May 2010 13:19:12 +0200 Subject: Bug #49756 Rows_examined is always 0 in the slow query log for update statements Only SELECT statements report any examined rows in the slow log. Slow UPDATE, DELETE and INSERT statements report 0 rows examined, unless the statement has a condition including a SELECT substatement. This patch adds counting of examined rows for the UPDATE and DELETE statements. An INSERT ... VALUES statement will still not report any rows as examined. sql/sql_class.h: Added more docs for THD::examined_row_count. sql/sql_delete.cc: Add incrementing thd->examined_row_count. sql/sql_update.cc: Add incrementing thd->examined_row_count. --- sql/sql_delete.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 7e91a37257b..cc29b6f1b6b 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -248,6 +248,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, free_underlaid_joins(thd, &thd->lex->select_lex); DBUG_RETURN(TRUE); } + thd->examined_row_count+= examined_rows; /* Filesort has already found and selected the rows we want to delete, so we don't need the where clause @@ -304,6 +305,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, while (!(error=info.read_record(&info)) && !thd->killed && ! thd->is_error()) { + thd->examined_row_count++; // thd->is_error() is tested to disallow delete row on error if (!(select && select->skip_record())&& ! thd->is_error() ) { -- cgit v1.2.1 From 2cfa397dff19c6215dbcb8b40f87e8fe3ce9328f Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Fri, 14 May 2010 15:36:27 +0400 Subject: Bug #53450: Crash / assertion "virtual int ha_myisam::index_first(uchar*)") at assert.c:81 Single-table DELETE crash/assertion similar to single-table UPDATE bug 14272. Same resolution as for the bug 14272: Don't run index scan when we should use quick select. This could cause failures because there are table handlers (like federated) that support quick select scanning but do not support index scanning. mysql-test/r/delete.result: Test case for bug #53450. mysql-test/t/delete.test: Test case for bug #53450. sql/sql_delete.cc: Bug #53450: Crash / assertion "virtual int ha_myisam::index_first(uchar*)") at assert.c:81 The mysql_delete function has been modified to not to use init_read_record_idx instead of init_read_record for the quick select. --- sql/sql_delete.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index cc29b6f1b6b..07421ca55a6 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -266,7 +266,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, free_underlaid_joins(thd, select_lex); DBUG_RETURN(TRUE); } - if (usable_index==MAX_KEY) + if (usable_index==MAX_KEY || (select && select->quick)) init_read_record(&info, thd, table, select, 1, 1, FALSE); else init_read_record_idx(&info, thd, table, 1, usable_index); -- cgit v1.2.1 From fd4b3c6c1c7ee47af58e9abd84818809053b7c86 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 10 Jun 2010 17:45:22 -0300 Subject: Bug#42733: Type-punning warnings when compiling MySQL -- strict aliasing violations. One somewhat major source of strict-aliasing violations and related warnings is the SQL_LIST structure. For example, consider its member function `link_in_list` which takes a pointer to pointer of type T (any type) as a pointer to pointer to unsigned char. Dereferencing this pointer, which is done to reset the next field, violates strict-aliasing rules and might cause problems for surrounding code that uses the next field of the object being added to the list. The solution is to use templates to parametrize the SQL_LIST structure in order to deference the pointers with compatible types. As a side bonus, it becomes possible to remove quite a few casts related to acessing data members of SQL_LIST. sql/handler.h: Use the appropriate template type argument. sql/item.cc: Remove now-unnecessary cast. sql/item_subselect.cc: Remove now-unnecessary casts. sql/item_sum.cc: Use the appropriate template type argument. Remove now-unnecessary cast. sql/mysql_priv.h: Move SQL_LIST structure to sql_list.h Use the appropriate template type argument. sql/sp.cc: Remove now-unnecessary casts. sql/sql_delete.cc: Use the appropriate template type argument. Remove now-unnecessary casts. sql/sql_derived.cc: Remove now-unnecessary casts. sql/sql_lex.cc: Remove now-unnecessary casts. sql/sql_lex.h: SQL_LIST now takes a template type argument which must match the type of the elements of the list. Use forward declaration when the type is not available, it is used in pointers anyway. sql/sql_list.h: Rename SQL_LIST to SQL_I_List. The template parameter is the type of object that is stored in the list. sql/sql_olap.cc: Remove now-unnecessary casts. sql/sql_parse.cc: Remove now-unnecessary casts. sql/sql_prepare.cc: Remove now-unnecessary casts. sql/sql_select.cc: Remove now-unnecessary casts. sql/sql_show.cc: Remove now-unnecessary casts. sql/sql_table.cc: Remove now-unnecessary casts. sql/sql_trigger.cc: Remove now-unnecessary casts. sql/sql_union.cc: Remove now-unnecessary casts. sql/sql_update.cc: Remove now-unnecessary casts. sql/sql_view.cc: Remove now-unnecessary casts. sql/sql_yacc.yy: Remove now-unnecessary casts. storage/myisammrg/ha_myisammrg.cc: Remove now-unnecessary casts. --- sql/sql_delete.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 07421ca55a6..eb0fd4b5332 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -33,7 +33,7 @@ */ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, - SQL_LIST *order, ha_rows limit, ulonglong options, + SQL_I_List *order, ha_rows limit, ulonglong options, bool reset_auto_increment) { bool will_batch; @@ -84,7 +84,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (select_lex->setup_ref_array(thd, order->elements) || setup_order(thd, select_lex->ref_pointer_array, &tables, - fields, all_fields, (ORDER*) order->first)) + fields, all_fields, order->first)) { delete select; free_underlaid_joins(thd, &thd->lex->select_lex); @@ -230,14 +230,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ha_rows examined_rows; if ((!select || table->quick_keys.is_clear_all()) && limit != HA_POS_ERROR) - usable_index= get_index_for_order(table, (ORDER*)(order->first), limit); + usable_index= get_index_for_order(table, order->first, limit); if (usable_index == MAX_KEY) { table->sort.io_cache= (IO_CACHE *) my_malloc(sizeof(IO_CACHE), MYF(MY_FAE | MY_ZEROFILL)); - if (!(sortorder= make_unireg_sortorder((ORDER*) order->first, + if (!(sortorder= make_unireg_sortorder(order->first, &length, NULL)) || (table->sort.found_records = filesort(thd, table, sortorder, length, select, HA_POS_ERROR, 1, @@ -547,7 +547,7 @@ extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b) int mysql_multi_delete_prepare(THD *thd) { LEX *lex= thd->lex; - TABLE_LIST *aux_tables= (TABLE_LIST *)lex->auxiliary_table_list.first; + TABLE_LIST *aux_tables= lex->auxiliary_table_list.first; TABLE_LIST *target_tbl; DBUG_ENTER("mysql_multi_delete_prepare"); -- cgit v1.2.1 From cb25707c404036dabc0ebe1f7f962f9594270130 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 2 Jul 2010 20:24:39 -0700 Subject: Fixed bug #601164. The functions mysql_delete and mysql_update lacked calls of updated_virtual_fields(). This caused wrong results for some DELETEs/UPDATEs. Added test cases for this bug. --- sql/sql_delete.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index ddb6af97865..eb05077f17a 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -304,6 +304,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, while (!(error=info.read_record(&info)) && !thd->killed && ! thd->is_error()) { + update_virtual_fields(table); // thd->is_error() is tested to disallow delete row on error if (!select || select->skip_record(thd) > 0) { -- cgit v1.2.1 From b55104d92590e18d0874fd6e9f27cbb3a2c6d8f0 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sat, 17 Jul 2010 01:41:44 +0300 Subject: Fix for LP#588251: doStartTableScan() result not checked. The issue was that we didn't always check result of ha_rnd_init() which caused a problem for handlers that returned an error in this code. - Changed prototype of ha_rnd_init() to ensure that we get a compile warning if result is not checked. - Added ha_rnd_init_with_error() that prints error on failure. - Checked all usage of ha_rnd_init() and ensure we generate an error message on failures. - Changed init_read_record() to return 1 on failure. sql/create_options.cc: Fixed wrong printf sql/event_db_repository.cc: Check result from init_read_record() sql/events.cc: Check result from init_read_record() sql/filesort.cc: Check result from ha_rnd_init() sql/ha_partition.cc: Check result from ha_rnd_init() sql/ha_partition.h: Fixed compiler warning sql/handler.cc: Added ha_rnd_init_with_error() Check result from ha_rnd_init() sql/handler.h: Added ha_rnd_init_with_error() Changed prototype of ha_rnd_init() to ensure that we get a compile warning if result is not checked sql/item_subselect.cc: Check result from ha_rnd_init() sql/log.cc: Check result from ha_rnd_init() sql/log_event.cc: Check result from ha_rnd_init() sql/log_event_old.cc: Check result from ha_rnd_init() sql/mysql_priv.h: init_read_record() now returns error code on failure sql/opt_range.cc: Check result from ha_rnd_init() sql/records.cc: init_read_record() now returns error code on failure Check result from ha_rnd_init() sql/sql_acl.cc: Check result from init_read_record() sql/sql_cursor.cc: Print error if ha_rnd_init() fails sql/sql_delete.cc: Check result from init_read_record() sql/sql_help.cc: Check result from init_read_record() sql/sql_plugin.cc: Check result from init_read_record() sql/sql_select.cc: Check result from ha_rnd_init() Print error if ha_rnd_init() fails. sql/sql_servers.cc: Check result from init_read_record() sql/sql_table.cc: Check result from init_read_record() sql/sql_udf.cc: Check result from init_read_record() sql/sql_update.cc: Check result from init_read_record() storage/example/ha_example.cc: Don't return error on rnd_init() storage/ibmdb2i/ha_ibmdb2i.cc: Removed not relevant comment --- sql/sql_delete.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index eb05077f17a..8fba48f54cc 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -266,7 +266,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, DBUG_RETURN(TRUE); } if (usable_index==MAX_KEY) - init_read_record(&info, thd, table, select, 1, 1, FALSE); + { + if (init_read_record(&info, thd, table, select, 1, 1, FALSE)) + { + delete select; + free_underlaid_joins(thd, select_lex); + DBUG_RETURN(TRUE); + } + } else init_read_record_idx(&info, thd, table, 1, usable_index); @@ -944,7 +951,10 @@ int multi_delete::do_table_deletes(TABLE *table, bool ignore) READ_RECORD info; ha_rows last_deleted= deleted; DBUG_ENTER("do_deletes_for_table"); - init_read_record(&info, thd, table, NULL, 0, 1, FALSE); + + if (init_read_record(&info, thd, table, NULL, 0, 1, FALSE)) + DBUG_RETURN(1); + /* Ignore any rows not found in reference tables as they may already have been deleted by foreign key handling -- cgit v1.2.1 From 1b165329862ef2522619807edc19d74070ab9af8 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 17 Jul 2010 11:16:16 -0700 Subject: Fixed bug #604503. If the expression for a virtual column of table contained datetime comparison then the execution of the second query that used this virtual column caused a crash. It happened because the execution of the first query that used this virtual column inserted a cached item into the expression tree. The cached tree was allocated in the statement memory while the expression tree was allocated in the table memory. Now the cached items that are inserted into expressions for virtual columns with datetime comparisons are always allocated in the same mem_root as the expressions for virtual columns. So now the inserted cached items are valid for any queries that use these virtual columns. --- sql/sql_delete.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index eb05077f17a..8a016295eaa 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -304,7 +304,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, while (!(error=info.read_record(&info)) && !thd->killed && ! thd->is_error()) { - update_virtual_fields(table); + update_virtual_fields(thd, table); // thd->is_error() is tested to disallow delete row on error if (!select || select->skip_record(thd) > 0) { -- cgit v1.2.1 From ddfe2129571643d92f906e1f3236dc32b857877d Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 23 Sep 2010 19:30:44 +0300 Subject: Fix usage of mysqld option --new, --old, --safe and --skip_new to not disable things that are proven stable or enable things that are not usefull. sql/field.cc: Remove feature of 'new_mode' that was never implemtented in a newer MySQL version. sql/item_cmpfunc.cc: Boyer more is stable; Don't have to be protected by --skip-new anymore sql/mysqld.cc: Don't disable some proven stable functions with --skip-new sql/records.cc: Don't disable record caching with --safe-mode anymore sql/sql_delete.cc: Do fast truncate even if --skip-new or --safe is used sql/sql_parse.cc: Use always mysql_optimizer() for optimizer (instead of mysql_recreate_table() in case of --safe or --skip-new) sql/sql_select.cc: Don't disable 'only_eq_ref_tables' if --safe is used. sql/sql_yacc.yy: Removed not meaningfull test of --old --- sql/sql_delete.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 361a5db1f2c..5564d628594 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -130,7 +130,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, - there should be no delete triggers associated with the table. */ if (!using_limit && const_cond_result && - !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) && (thd->lex->sql_command == SQLCOM_TRUNCATE || (!thd->current_stmt_binlog_row_based && !(table->triggers && table->triggers->has_delete_triggers())))) -- cgit v1.2.1