From da9aabbbb653274de997763b7f833ac6822f81bf Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 22 Mar 2012 19:56:17 -0700 Subject: Fixed LP bug #954900. If the first component of a ref key happened to be a constant appeared after constant row substitution then no store_key element should be created for such a component. Yet create_ref_for_key() erroneously could create such an element that caused construction of invalid ref keys and wrong results for some joins. --- sql/sql_select.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_select.cc') diff --git a/sql/sql_select.cc b/sql/sql_select.cc index b7c0156f65b..a526de5a256 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7498,7 +7498,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, if (keyuse->null_rejecting) j->ref.null_rejecting |= 1 << i; keyuse_uses_no_tables= keyuse_uses_no_tables && !keyuse->used_tables; - if (!keyuse->used_tables && !thd->lex->describe) + if (!keyuse->val->used_tables() && !thd->lex->describe) { // Compare against constant store_key_item tmp(thd, keyinfo->key_part[i].field, -- cgit v1.2.1 From 8e825a2249440e7df0fce0123f6d543b09b29194 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 23 Mar 2012 18:18:16 +0200 Subject: Fixes lp:941889 "JOIN constructors takes a long time in 5.3" - Remove all references of MAX_TABLES from JOIN struct and make these dynamic - Updated Join_plan_state to allocate just as many elements as it's needed sql/opt_subselect.cc: Optimized version of Join_plan_state sql/sql_select.cc: Set join->positions and join->best_positions dynamicly Don't call update_virtual_fields() if table->vfield is not set. sql/sql_select.h: Remove all references of MAX_TABLES from JOIN struct and Join_plan_state and make these dynamic --- sql/sql_select.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'sql/sql_select.cc') diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a526de5a256..9d04204848d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3046,12 +3046,11 @@ make_join_statistics(JOIN *join, List &tables_list, key_map const_ref, eq_part; bool has_expensive_keyparts; TABLE **table_vector; - JOIN_TAB *stat,*stat_end,*s,**stat_ref; + JOIN_TAB *stat,*stat_end,*s,**stat_ref, **stat_vector; KEYUSE *keyuse,*start_keyuse; table_map outer_join=0; table_map no_rows_const_tables= 0; SARGABLE_PARAM *sargables= 0; - JOIN_TAB *stat_vector[MAX_TABLES+1]; List_iterator ti(tables_list); TABLE_LIST *tables; DBUG_ENTER("make_join_statistics"); @@ -3060,9 +3059,19 @@ make_join_statistics(JOIN *join, List &tables_list, table_count=join->table_count; stat=(JOIN_TAB*) join->thd->calloc(sizeof(JOIN_TAB)*(table_count)); - stat_ref=(JOIN_TAB**) join->thd->alloc(sizeof(JOIN_TAB*)*MAX_TABLES); + stat_ref=(JOIN_TAB**) join->thd->alloc(sizeof(JOIN_TAB*)* + (MAX_TABLES + table_count + 1)); + stat_vector= stat_ref + MAX_TABLES; table_vector=(TABLE**) join->thd->alloc(sizeof(TABLE*)*(table_count*2)); - if (!stat || !stat_ref || !table_vector) + join->positions= new (join->thd->mem_root) POSITION[(table_count+1)]; + /* + best_positions is ok to allocate with alloc() as we copy things to it with + memcpy() + */ + join->best_positions= (POSITION*) join->thd->alloc(sizeof(POSITION)* + (table_count +1)); + + if (join->thd->is_fatal_error) DBUG_RETURN(1); // Eom /* purecov: inspected */ join->best_ref=stat_vector; @@ -15927,7 +15936,8 @@ join_read_system(JOIN_TAB *tab) empty_record(table); // Make empty record return -1; } - update_virtual_fields(tab->join->thd, table); + if (table->vfield) + update_virtual_fields(tab->join->thd, table); store_record(table,record[1]); } else if (!table->status) // Only happens with left join @@ -15976,7 +15986,8 @@ join_read_const(JOIN_TAB *tab) return report_error(table, error); return -1; } - update_virtual_fields(tab->join->thd, table); + if (table->vfield) + update_virtual_fields(tab->join->thd, table); store_record(table,record[1]); } else if (!(table->status & ~STATUS_NULL_ROW)) // Only happens with left join -- cgit v1.2.1