From c258ca2463947fcc3d69bb50a8b5cf6906778508 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 7 Jun 2017 12:45:09 -0700 Subject: Fixed the bug mdev-12838. If the optimizer chose an execution plan where a semi-join nest were materialized and the result of materialization was scanned to access other tables by ref access it could build a key over columns of the tables from the nest that were actually inaccessible. The patch performs a proper check whether a key that uses columns of the tables from a materialized semi-join nest can be employed to access outer tables. --- sql/sql_select.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 0623672840e..1bc1e4c2b7a 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -540,6 +540,8 @@ typedef struct st_join_table { !(used_sjm_lookup_tables & ~emb_sj_nest->sj_inner_tables)); } + bool keyuse_is_valid_for_access_in_chosen_plan(JOIN *join, KEYUSE *keyuse); + } JOIN_TAB; @@ -1003,6 +1005,11 @@ public: to materialize and access by lookups */ table_map sjm_lookup_tables; + /** + Bitmap of semijoin tables that the chosen plan decided + to materialize to scan the results of materialization + */ + table_map sjm_scan_tables; /* Constant tables for which we have found a row (as opposed to those for which we didn't). @@ -1331,6 +1338,7 @@ public: pre_sort_join_tab= NULL; emb_sjm_nest= NULL; sjm_lookup_tables= 0; + sjm_scan_tables= 0; /* The following is needed because JOIN::cleanup(true) may be called for joins for which JOIN::optimize was aborted with an error before a proper -- cgit v1.2.1