summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-06-19 17:28:08 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2017-06-19 17:28:08 +0300
commit1e3886ae80c44a39ec3e4061b4ea3131cdcef213 (patch)
treece95518792d1432b669ba13a248928e74e81a9bb /sql/sql_select.cc
parent0fe7d8a2a221196d977e5efe3f3dedb22806bb53 (diff)
parent3a7201ea922f6d3373924c413fdb4b108f6208c5 (diff)
downloadmariadb-git-1e3886ae80c44a39ec3e4061b4ea3131cdcef213.tar.gz
Merge bb-10.2-ext into 10.3
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc60
1 files changed, 37 insertions, 23 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c6613facde7..15082cdd0c1 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -648,17 +648,15 @@ setup_without_group(THD *thd, Ref_ptr_array ref_pointer_array,
thd->lex->allow_sum_func|= (nesting_map)1 << select->nest_level;
- save_place= thd->lex->current_select->parsing_place;
- thd->lex->current_select->parsing_place= IN_ORDER_BY;
+ save_place= thd->lex->current_select->context_analysis_place;
+ thd->lex->current_select->context_analysis_place= IN_ORDER_BY;
res= res || setup_order(thd, ref_pointer_array, tables, fields, all_fields,
order);
- thd->lex->current_select->parsing_place= save_place;
- thd->lex->allow_sum_func&= ~((nesting_map)1 << select->nest_level);
- save_place= thd->lex->current_select->parsing_place;
- thd->lex->current_select->parsing_place= IN_GROUP_BY;
+ thd->lex->allow_sum_func&= ~((nesting_map)1 << select->nest_level);
+ thd->lex->current_select->context_analysis_place= IN_GROUP_BY;
res= res || setup_group(thd, ref_pointer_array, tables, fields, all_fields,
group, hidden_group_fields);
- thd->lex->current_select->parsing_place= save_place;
+ thd->lex->current_select->context_analysis_place= save_place;
thd->lex->allow_sum_func|= (nesting_map)1 << select->nest_level;
res= res || setup_windows(thd, ref_pointer_array, tables, fields, all_fields,
win_specs, win_funcs);
@@ -712,6 +710,7 @@ JOIN::prepare(TABLE_LIST *tables_init,
if (select_lex->handle_derived(thd->lex, DT_PREPARE))
DBUG_RETURN(1);
+ thd->lex->current_select->context_analysis_place= NO_MATTER;
thd->lex->current_select->is_item_list_lookup= 1;
/*
If we have already executed SELECT, then it have not sense to prevent
@@ -801,12 +800,13 @@ JOIN::prepare(TABLE_LIST *tables_init,
ref_ptrs= ref_ptr_array_slice(0);
- enum_parsing_place save_place= thd->lex->current_select->parsing_place;
- thd->lex->current_select->parsing_place= SELECT_LIST;
+ enum_parsing_place save_place=
+ thd->lex->current_select->context_analysis_place;
+ thd->lex->current_select->context_analysis_place= SELECT_LIST;
if (setup_fields(thd, ref_ptrs, fields_list, MARK_COLUMNS_READ,
&all_fields, 1))
DBUG_RETURN(-1);
- thd->lex->current_select->parsing_place= save_place;
+ thd->lex->current_select->context_analysis_place= save_place;
if (setup_without_group(thd, ref_ptrs, tables_list,
select_lex->leaf_tables, fields_list,
@@ -1991,7 +1991,8 @@ JOIN::optimize_inner()
having= new (thd->mem_root) Item_int(thd, (longlong) 0,1);
zero_result_cause= "Impossible HAVING noticed after reading const tables";
error= 0;
- DBUG_RETURN(0);
+ select_lex->mark_const_derived(zero_result_cause);
+ goto setup_subq_exit;
}
}
@@ -3384,7 +3385,8 @@ void JOIN::exec_inner()
condtions may be arbitrarily costly, and because the optimize phase
might not have produced a complete executable plan for EXPLAINs.
*/
- if (exec_const_cond && !(select_options & SELECT_DESCRIBE) &&
+ if (!zero_result_cause &&
+ exec_const_cond && !(select_options & SELECT_DESCRIBE) &&
!exec_const_cond->val_int())
zero_result_cause= "Impossible WHERE noticed after reading const tables";
@@ -9725,12 +9727,20 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
/*
Step #2: Extract WHERE/ON parts
*/
+ uint i;
+ for (i= join->top_join_tab_count - 1; i >= join->const_tables; i--)
+ {
+ if (!join->join_tab[i].bush_children)
+ break;
+ }
+ uint last_top_base_tab_idx= i;
+
table_map save_used_tables= 0;
used_tables=((select->const_tables=join->const_table_map) |
OUTER_REF_TABLE_BIT | RAND_TABLE_BIT);
JOIN_TAB *tab;
table_map current_map;
- uint i= join->const_tables;
+ i= join->const_tables;
for (tab= first_depth_first_tab(join); tab;
tab= next_depth_first_tab(join, tab), i++)
{
@@ -9769,7 +9779,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
Following force including random expression in last table condition.
It solve problem with select like SELECT * FROM t1 WHERE rand() > 0.5
*/
- if (tab == join->join_tab + join->top_join_tab_count - 1)
+ if (tab == join->join_tab + last_top_base_tab_idx)
current_map|= RAND_TABLE_BIT;
used_tables|=current_map;
@@ -9809,10 +9819,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
save_used_tables= 0;
}
else
- {
- tmp= make_cond_for_table(thd, cond, used_tables, current_map, i,
+ {
+ tmp= make_cond_for_table(thd, cond, used_tables, current_map, i,
FALSE, FALSE);
- }
+ }
/* Add conditions added by add_not_null_conds(). */
if (tab->select_cond)
add_cond_and_fix(thd, &tmp, tab->select_cond);
@@ -14517,7 +14527,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
table->table->maybe_null= FALSE;
table->outer_join= 0;
if (!(straight_join || table->straight))
- table->dep_tables= table->embedding? table->embedding->dep_tables: 0;
+ table->dep_tables= table->embedding && !table->embedding->sj_subq_pred ?
+ table->embedding->dep_tables : 0;
if (table->on_expr)
{
/* Add ON expression to the WHERE or upper-level ON condition. */
@@ -22206,14 +22217,16 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List<Item> &all_fields, ORDER *order,
bool from_window_spec)
{
- enum_parsing_place parsing_place= thd->lex->current_select->parsing_place;
+ enum_parsing_place context_analysis_place=
+ thd->lex->current_select->context_analysis_place;
thd->where="order clause";
for (; order; order=order->next)
{
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
all_fields, FALSE, from_window_spec))
return 1;
- if ((*order->item)->with_window_func && parsing_place != IN_ORDER_BY)
+ if ((*order->item)->with_window_func &&
+ context_analysis_place != IN_ORDER_BY)
{
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));
return 1;
@@ -22255,7 +22268,8 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List<Item> &all_fields, ORDER *order,
bool *hidden_group_fields, bool from_window_spec)
{
- enum_parsing_place parsing_place= thd->lex->current_select->parsing_place;
+ enum_parsing_place context_analysis_place=
+ thd->lex->current_select->context_analysis_place;
*hidden_group_fields=0;
ORDER *ord;
@@ -22271,14 +22285,14 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
all_fields, TRUE, from_window_spec))
return 1;
(*ord->item)->marker= UNDEF_POS; /* Mark found */
- if ((*ord->item)->with_sum_func && parsing_place == IN_GROUP_BY)
+ if ((*ord->item)->with_sum_func && context_analysis_place == IN_GROUP_BY)
{
my_error(ER_WRONG_GROUP_FIELD, MYF(0), (*ord->item)->full_name());
return 1;
}
if ((*ord->item)->with_window_func)
{
- if (parsing_place == IN_GROUP_BY)
+ if (context_analysis_place == IN_GROUP_BY)
my_error(ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION, MYF(0));
else
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));