diff options
| author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-12-01 19:51:14 +0200 |
|---|---|---|
| committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-12-01 19:51:14 +0200 |
| commit | 589cf8dbf3accf57673d7e2f7a4435f7eaf33565 (patch) | |
| tree | aa38a67d10f71fc781188341857e34d437fa9199 /sql/sql_derived.cc | |
| parent | a3531775b1efe06e2439a0c8ab668a2b69c859eb (diff) | |
| parent | e30a05f4540b581df2e7d98bd7e812aeff603744 (diff) | |
| download | mariadb-git-589cf8dbf3accf57673d7e2f7a4435f7eaf33565.tar.gz | |
Merge 10.3 into 10.4
Diffstat (limited to 'sql/sql_derived.cc')
| -rw-r--r-- | sql/sql_derived.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 3b312225937..1e416c307cf 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -1402,7 +1402,8 @@ bool pushdown_cond_for_derived(THD *thd, Item *cond, TABLE_LIST *derived) DBUG_RETURN(false); st_select_lex_unit *unit= derived->get_unit(); - st_select_lex *sl= unit->first_select(); + st_select_lex *first_sl= unit->first_select(); + st_select_lex *sl= first_sl; if (derived->prohibit_cond_pushdown) DBUG_RETURN(false); @@ -1461,6 +1462,20 @@ bool pushdown_cond_for_derived(THD *thd, Item *cond, TABLE_LIST *derived) if (!extracted_cond_copy) continue; + /* + Rename the columns of all non-first selects of a union to be compatible + by names with the columns of the first select. It will allow to use copies + of the same expression pushed into having clauses of different selects. + */ + if (sl != first_sl) + { + DBUG_ASSERT(sl->item_list.elements == first_sl->item_list.elements); + List_iterator_fast<Item> it(sl->item_list); + List_iterator_fast<Item> nm_it(unit->types); + while (Item *item= it++) + item->share_name_with(nm_it++); + } + /* Collect fields that are used in the GROUP BY of sl */ if (sl->have_window_funcs()) { @@ -1481,7 +1496,7 @@ bool pushdown_cond_for_derived(THD *thd, Item *cond, TABLE_LIST *derived) &remaining_cond, &Item::derived_field_transformer_for_where, (uchar *) sl); - + if (!remaining_cond) continue; /* |
