From e681418face9a763a5ad50b5b24834545067bc27 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Sep 2011 23:53:12 +0300 Subject: Fix for bug lp:834492 Analysis: In the test query semi-join merges the inner-most subquery into the outer subquery, and the optimization of the merged subquery finds some new index access methods. Later the IN-EXISTS transformation is applied to the unmerged subquery. Since the optimizer is instructed to not consider materialization, it reoptimizes the plan in-place to take into account the new IN-EXISTS conditions. Just before reoptimization JOIN::choose_subquery_plan resets the query plan, which also resets the access methods found during the semi-join merge. Then reoptimization discovers there are no new access methods, but it leaves the query plan in its reset state. Later semi-join crashes because it assumes these access methods are present. Solution: When reoptimizing in-place, reset the query plan only after new access methods were discovered. If no new access methods were discovered, leave the current plan as it was. --- sql/sql_select.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index bbf390aaf7e..9b8e60e9cc1 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -698,6 +698,7 @@ protected: enum_reopt_result reoptimize(Item *added_where, table_map join_tables, Join_plan_state *save_to); void save_query_plan(Join_plan_state *save_to); + void reset_query_plan(); void restore_query_plan(Join_plan_state *restore_from); /* Choose a subquery plan for a table-less subquery. */ bool choose_tableless_subquery_plan(); -- cgit v1.2.1 From 613db7c56f6a2af985eedfdd7bd6d00ab8f757df Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Fri, 2 Sep 2011 22:43:35 +0400 Subject: BUG#836523: Crash in JOIN::get_partial_cost_and_fanout with semijoin+materialization - Make JOIN::get_partial_cost_and_fanout() be able to handle join plans with semi-join-materialization nests. --- sql/sql_select.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 9b8e60e9cc1..9b53c53f690 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1154,7 +1154,7 @@ public: max_allowed_join_cache_level > JOIN_CACHE_HASHED_BIT; } bool choose_subquery_plan(table_map join_tables); - void get_partial_cost_and_fanout(uint end_tab_idx, + void get_partial_cost_and_fanout(int end_tab_idx, table_map filter_map, double *read_time_arg, double *record_count_arg); -- cgit v1.2.1 From 1d960d7651719bf8e4403081358054f69b6a6616 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Mon, 5 Sep 2011 20:51:37 +0400 Subject: BUG#834739: Wrong result with 3-way inner join, LooseScan,multipart keys - Don't use join buffering for tables that are within ranges that are covered by LooseScan strategy. --- sql/sql_select.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 9b53c53f690..15711dca7b3 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -347,6 +347,9 @@ typedef struct st_join_table { NULL - Not doing a loose scan on this join tab. */ struct st_join_table *loosescan_match_tab; + + /* TRUE <=> we are inside LooseScan range */ + bool inside_loosescan_range; /* Buffer to save index tuple to be able to skip duplicates */ uchar *loosescan_buf; -- cgit v1.2.1 From 1c46ce9592a44972268930a9d419319b5d15343f Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 8 Sep 2011 19:48:14 +0400 Subject: BUG#830993: Crash in end_read_record with derived table - Let join buffering code correctly take into account rowids needed by DuplicateElimination when it is calculating minimum record sizes. - In JOIN_CACHE::write_record_data, added asserts that prevent us from writing beyond the end of the buffer. --- sql/sql_select.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 15711dca7b3..676cc7452f4 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -288,7 +288,6 @@ typedef struct st_join_table { ulong max_used_fieldlength; uint used_blobs; uint used_null_fields; - uint used_rowid_fields; uint used_uneven_bit_fields; enum join_type type; bool cached_eq_ref_table,eq_ref_table,not_used_in_distinct; @@ -387,15 +386,6 @@ typedef struct st_join_table { (select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX)); } - bool check_rowid_field() - { - if (keep_current_rowid && !used_rowid_fields) - { - used_rowid_fields= 1; - used_fieldlength+= table->file->ref_length; - } - return test(used_rowid_fields); - } bool is_inner_table_of_semi_join_with_first_match() { return first_sj_inner_tab != NULL; -- cgit v1.2.1 From 6e236b7b0a3f93ee008a972fabfe870a77feb1b4 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Sat, 1 Oct 2011 00:10:03 +0400 Subject: BUG#860553: Crash in create_ref_for_key with semijoin + materialization - The problem was that JOIN::save/restore_query_plan() did not save/restore parts of the query plan that are located inside SJ_MATERIALIZATION_INFO structures. This could cause parts of one plan to be used with another, which led get_best_combination() to constructing non-sensical join plans (and crash). Fixed by saving/restoring SJM parts of the query plans. - check_and_do_in_subquery_rewrites() will not set SUBS_MATERIALIZATION flag when it records that the subquery predicate is to be converted into semi-join. If convert_join_subqueries_to_semijoins() later decides not to convert to semi-join, let it set SUBS_MATERIALIZATION flag, if appropriate. --- sql/sql_select.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 676cc7452f4..0a416966995 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -666,6 +666,7 @@ protected: KEYUSE *join_tab_keyuse[MAX_TABLES]; /* Copies of JOIN_TAB::checked_keys for each JOIN_TAB. */ key_map join_tab_checked_keys[MAX_TABLES]; + SJ_MATERIALIZATION_INFO *sj_mat_info[MAX_TABLES]; public: Join_plan_state() { -- cgit v1.2.1 From ef254e55461a9e03ae5b999017a1b6322741be5a Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Mon, 7 Nov 2011 23:30:03 +0400 Subject: BUG#887026: Wrong result with ICP, outer join, subquery in maria-5.3-icp - Do not push index condition if we're using a triggered ref access. --- sql/sql_select.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 0a416966995..5476ef9b46c 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -136,6 +136,7 @@ typedef struct st_table_ref bool tmp_table_index_lookup_init(THD *thd, KEY *tmp_key, Item_iterator &it, bool value, uint skip= 0); + bool is_access_triggered(); } TABLE_REF; -- cgit v1.2.1 From 315b13a6f43a66b446c43d8c05a0893c2830702c Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 15 Nov 2011 13:03:00 -0800 Subject: Fixed LP bug #889750. If the optimizer switch 'semijoin_with_cache' is set to 'off' then join cache cannot be used to join inner tables of a semijoin. Also fixed a bug in the function check_join_cache_usage() that led to wrong output of the EXPLAIN commands for some test cases. --- sql/sql_select.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 5476ef9b46c..1d18b80d72e 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -391,6 +391,10 @@ typedef struct st_join_table { { return first_sj_inner_tab != NULL; } + bool is_inner_table_of_semijoin() + { + return emb_sj_nest != NULL; + } bool is_inner_table_of_outer_join() { return first_inner != NULL; -- cgit v1.2.1