summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2022-07-04 15:23:01 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2022-09-27 09:56:21 +0200
commit47e967898283a1fef44a7b84467cf26ff6bd63a3 (patch)
tree480c35919eda08e58a6a456ccc42bd33a1c515f7 /sql
parent2b89598fe017d8ae1898a97071d00581b7ba6271 (diff)
downloadmariadb-git-47e967898283a1fef44a7b84467cf26ff6bd63a3.tar.gz
MDEV-29022 add_slave destroy child list and has dead code
Nowdays subquery in a UNION's ORDER BY placed correctly in fake select, the only problem was incorrect Name_resolution_contect is fixed by this patch in parsing, so we do not need scanning/reseting of ORDER BY of a union.
Diffstat (limited to 'sql')
-rw-r--r--sql/item.h1
-rw-r--r--sql/item_subselect.cc44
-rw-r--r--sql/item_subselect.h1
-rw-r--r--sql/sql_lex.cc18
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_tvc.cc2
-rw-r--r--sql/sql_union.cc9
-rw-r--r--sql/sql_yacc.yy7
8 files changed, 10 insertions, 74 deletions
diff --git a/sql/item.h b/sql/item.h
index b16456372d4..f28e4fb4bd7 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1758,7 +1758,6 @@ public:
virtual bool enumerate_field_refs_processor(void *arg) { return 0; }
virtual bool mark_as_eliminated_processor(void *arg) { return 0; }
virtual bool eliminate_subselect_processor(void *arg) { return 0; }
- virtual bool set_fake_select_as_master_processor(void *arg) { return 0; }
virtual bool view_used_tables_processor(void *arg) { return 0; }
virtual bool eval_not_null_tables(void *arg) { return 0; }
virtual bool is_subquery_processor(void *arg) { return 0; }
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index ee36ee2fae9..6472bb86a37 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -386,50 +386,6 @@ bool Item_subselect::eliminate_subselect_processor(void *arg)
}
-/**
- Adjust the master select of the subquery to be the fake_select which
- represents the whole UNION right above the subquery, instead of the
- last query of the UNION.
-
- @param arg pointer to the fake select
-
- @return
- FALSE to force the evaluation of the processor for the subsequent items.
-*/
-
-bool Item_subselect::set_fake_select_as_master_processor(void *arg)
-{
- SELECT_LEX *fake_select= (SELECT_LEX*) arg;
- /*
- Move the st_select_lex_unit of a subquery from a global ORDER BY clause to
- become a direct child of the fake_select of a UNION. In this way the
- ORDER BY that is applied to the temporary table that contains the result of
- the whole UNION, and all columns in the subquery are resolved against this
- table. The transformation is applied only for immediate child subqueries of
- a UNION query.
- */
- if (unit->outer_select()->master_unit()->fake_select_lex == fake_select)
- {
- /*
- Set the master of the subquery to be the fake select (i.e. the whole
- UNION), instead of the last query in the UNION.
- */
- fake_select->add_slave(unit);
- DBUG_ASSERT(unit->outer_select() == fake_select);
- /* Adjust the name resolution context hierarchy accordingly. */
- for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
- sl->context.outer_context= &(fake_select->context);
- /*
- Undo Item_subselect::eliminate_subselect_processor because at that phase
- we don't know yet that the ORDER clause will be moved to the fake select.
- */
- unit->item= this;
- eliminated= FALSE;
- }
- return FALSE;
-}
-
-
bool Item_subselect::mark_as_dependent(THD *thd, st_select_lex *select,
Item *item)
{
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 16c683b27e0..b95a02d28b2 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -238,7 +238,6 @@ public:
bool walk(Item_processor processor, bool walk_subquery, void *arg);
bool mark_as_eliminated_processor(void *arg);
bool eliminate_subselect_processor(void *arg);
- bool set_fake_select_as_master_processor(void *arg);
bool enumerate_field_refs_processor(void *arg);
bool check_vcol_func_processor(void *arg)
{
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 3400e31fd5c..c5bdfb596eb 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2434,23 +2434,9 @@ void st_select_lex_node::include_down(st_select_lex_node *upper)
}
-void st_select_lex_node::add_slave(st_select_lex_node *slave_arg)
+void st_select_lex_node::attach_single(st_select_lex_node *slave_arg)
{
- for (; slave; slave= slave->next)
- if (slave == slave_arg)
- return;
-
- if (slave)
- {
- st_select_lex_node *slave_arg_slave= slave_arg->slave;
- /* Insert in the front of list of slaves if any. */
- slave_arg->include_neighbour(slave);
- /* include_neighbour() sets slave_arg->slave=0, restore it. */
- slave_arg->slave= slave_arg_slave;
- /* Count on include_neighbour() setting the master. */
- DBUG_ASSERT(slave_arg->master == this);
- }
- else
+ DBUG_ASSERT(slave == 0);
{
slave= slave_arg;
slave_arg->master= this;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index d720d902bd7..bdc8b5476b2 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -705,7 +705,7 @@ public:
inline st_select_lex_node* get_master() { return master; }
void include_down(st_select_lex_node *upper);
- void add_slave(st_select_lex_node *slave_arg);
+ void attach_single(st_select_lex_node *slave_arg);
void include_neighbour(st_select_lex_node *before);
void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
void include_global(st_select_lex_node **plink);
diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc
index 13efd973326..43c25db5097 100644
--- a/sql/sql_tvc.cc
+++ b/sql/sql_tvc.cc
@@ -708,7 +708,7 @@ st_select_lex *wrap_tvc(THD *thd, st_select_lex *tvc_sl,
Attach the select used of TVC as the only slave to the unit for
the derived table tvc_x of the transformation
*/
- derived_unit->add_slave(tvc_sl);
+ derived_unit->attach_single(tvc_sl);
tvc_sl->linkage= DERIVED_TABLE_TYPE;
/*
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 32d307de5e8..e831e2a479c 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -633,15 +633,6 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg,
order= order->next)
order->item= &order->item_ptr;
}
- for (ORDER *order= global_parameters()->order_list.first;
- order;
- order=order->next)
- {
- (*order->item)->walk(&Item::change_context_processor, 0,
- &fake_select_lex->context);
- (*order->item)->walk(&Item::set_fake_select_as_master_processor, 0,
- fake_select_lex);
- }
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 577405725ca..d89ef534486 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -12910,11 +12910,16 @@ order_clause:
*/
DBUG_ASSERT(sel->master_unit()->fake_select_lex);
lex->current_select= sel->master_unit()->fake_select_lex;
+ lex->push_context(&sel->master_unit()->fake_select_lex->context, thd->mem_root);
}
}
order_list
{
-
+ if (Lex->current_select ==
+ Lex->current_select->master_unit()->fake_select_lex)
+ {
+ Lex->pop_context();
+ }
}
;