Commit 9912892
committed
Bug#35184353: Refactor order of subquery resolving and transformation
In general, layout of classes has been enhanced. Member variables and
functions have been renamed and made private and protected where
reasonable. Constructors have been made minimal. Friend declarations
are removed when possible.
Changes in class Item_subselect
- Function init() is renamed as bind() and will now bind subquery with
query expression and update parsing_place. It will no longer update
query result pointer, which is now done as part of fix_fields().
Notice it will no longer set place = CTX_NONE. This eliminated one case
of "Unknown column" in tests like main.subquery_all.
- Property functions assigned() are renamed as is_value_assigned(),
set_value_assigned() and reset_value_assigned().
- reset_value_registration() is renamed as reset_has_values().
- m_subquery_used_tables is made private and accessor function
subquery_used_tables() is added.
- Helper pointers "substitution" and "optimizer", and field "changed"
have been eliminated.
Changes in class Item_singlerow_subselect
- Function select_transformer() has been removed and functionality
moved to fix_fields().
Changes in class Item_maxmin_subselect
- Function reset_value_registration() is renamed as reset_has_values().
Changes in class Item_exists_subselect
- Function select_transformer() is renamed as transformer().
Changes in class Item_in_subselect
- Field left_expr is moved to base class, which leads to improved
generalization.
Removed class SubqueryWithResult
- Class SubqueryWithResult has been removed as it was redundant.
The resolver parts of it is now taken care of by class
Item_singlerow_subselect. Preparation of underlying query expression
has been moved to Item_subselect::fix_fields().
- Function set_row() has been moved to class Item_singlerow_subselect
and renamed to create_row(). It will also update the data type of
class Item_singlerow_subselect.
- Functionality of function fix_length_and_dec() has been incorporated
in Item_singlerow_subselect::fix_fields().
Changes in sequence of operations.
- Previously, resolving and transformation of subqueries and predicates
over subqueries were intertwined operations. Transformations were
started from the function Query_block::resolve_subquery() which was
called deep in the call hierarchy from Item_subselect::fix_fields(),
just after the query block was resolved. Even worse, for a subquery
that contained set operations, the transformer function would be
called once for each query block. This has been refactored so that
each subquery and subquery predicate is now fully resolved through
its fix_fields() function, and possible transformations are performed
as the last stage of fix_fields(). This fulfills the goal of
performing resolving and transformation in distinct stages.
- Item_singlerow_subselect::fix_fields() may transform a subquery that
is a single query block and does not have tables, aggregation,
WHERE clause nor HAVING clause by completely eliminating the subquery.
- Item_exists_subselect::fix_fields() resolves all predicates involving
table subqueries. After a complete resolving, it will either perform
a direct transformation, or pass the predicate into a queue for
later processing. (We cannot process all transformations immediately
because some transformations may have to be done in priority order,
and transformations that add new Table_ref objects should only be done
after the outer query block is fully resolved).
- The queue for later processing will contain predicates that are
candidates for semijoin transformation and candidates for derived
table transformation. The complex conditions for these transformations
have been split out into dedicated functions on the class
Item_exists_subselect and are called is_semijoin_candidate() and
is_derived_candidate(), respectively.
- If neither of these apply, the predicate is transformed using a
virtual transformer() function. These functions are renamed from
select_transformer() and no longer contain a query block argument,
as they now handle the transformation of a complete subquery.
- Item_exists_subselect::transformer() is called for EXISTS and
NOT EXISTS predicates. It only adds a LIMIT 1 clause to the query
expression.
- Item_in_subselect::transformer() and
Item_allany_subselect::transformer() both call
quantified_comp_transformer(). This function has a specific
transformation for predicates like x IN (SELECT expr), which is
converted to a simple equality. Other subqueries are transformed
by functions single_value_transformer() and row_value_transformer().
These functions are not changed a lot, except they now perform some
general work first and then apply transformations to each contained
query block. The latter work is done in functions
single_value_in_to_exists_transformer() and
row_value_in_to_exists_transformer().
Test changes
subquery.inc
A query used to report ER_BAD_FIELD_ERROR but is now accepted.
The problem was that the parsing place of the inner query expression
was CTX_NONE but this has now been corrected to CTX_SELECT_LIST.
For another query, error was changed from ER_BAD_FIELD_ERROR to
ER_INVALID_GROUP_FUNC_USE.
Optimizer trace tests
These are all adjusted since the resolving and transformation of
subquery predicates are all performed in a different order.
i_main.subquery-bug32593846
Error is changed from ER_OPERAND_COLUMNS to
ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT because now the UNION is inspected
before the subquery LHS.
Change-Id: I32d98fa443383d61a12fbd8227d1bf52e93565b01 parent da1a9fd commit 9912892
File tree
47 files changed
+2117
-2346
lines changed- mysql-test
- include
- r
- suite/opt_trace/r
- t
- sql
- join_optimizer
- unittest/gunit
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
47 files changed
+2117
-2346
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2886 | 2886 | | |
2887 | 2887 | | |
2888 | 2888 | | |
2889 | | - | |
2890 | | - | |
2891 | | - | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
2892 | 2892 | | |
2893 | 2893 | | |
2894 | 2894 | | |
| |||
3189 | 3189 | | |
3190 | 3190 | | |
3191 | 3191 | | |
3192 | | - | |
3193 | 3192 | | |
3194 | 3193 | | |
3195 | 3194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1336 | 1336 | | |
1337 | 1337 | | |
1338 | 1338 | | |
1339 | | - | |
1340 | 1339 | | |
| 1340 | + | |
1341 | 1341 | | |
1342 | 1342 | | |
1343 | 1343 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
576 | | - | |
577 | 576 | | |
| 577 | + | |
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | | - | |
600 | 599 | | |
| 600 | + | |
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2086 | 2086 | | |
2087 | 2087 | | |
2088 | 2088 | | |
2089 | | - | |
| 2089 | + | |
2090 | 2090 | | |
2091 | 2091 | | |
2092 | 2092 | | |
2093 | 2093 | | |
2094 | 2094 | | |
2095 | | - | |
| 2095 | + | |
2096 | 2096 | | |
2097 | 2097 | | |
2098 | 2098 | | |
| |||
4125 | 4125 | | |
4126 | 4126 | | |
4127 | 4127 | | |
4128 | | - | |
4129 | | - | |
| 4128 | + | |
| 4129 | + | |
4130 | 4130 | | |
4131 | | - | |
| 4131 | + | |
4132 | 4132 | | |
4133 | 4133 | | |
4134 | 4134 | | |
| |||
4444 | 4444 | | |
4445 | 4445 | | |
4446 | 4446 | | |
4447 | | - | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
4448 | 4450 | | |
4449 | 4451 | | |
4450 | 4452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2087 | 2087 | | |
2088 | 2088 | | |
2089 | 2089 | | |
2090 | | - | |
| 2090 | + | |
2091 | 2091 | | |
2092 | 2092 | | |
2093 | 2093 | | |
2094 | 2094 | | |
2095 | 2095 | | |
2096 | | - | |
| 2096 | + | |
2097 | 2097 | | |
2098 | 2098 | | |
2099 | 2099 | | |
| |||
4126 | 4126 | | |
4127 | 4127 | | |
4128 | 4128 | | |
4129 | | - | |
4130 | | - | |
| 4129 | + | |
| 4130 | + | |
4131 | 4131 | | |
4132 | | - | |
| 4132 | + | |
4133 | 4133 | | |
4134 | 4134 | | |
4135 | 4135 | | |
| |||
4445 | 4445 | | |
4446 | 4446 | | |
4447 | 4447 | | |
4448 | | - | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
4449 | 4451 | | |
4450 | 4452 | | |
4451 | 4453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2087 | 2087 | | |
2088 | 2088 | | |
2089 | 2089 | | |
2090 | | - | |
| 2090 | + | |
2091 | 2091 | | |
2092 | 2092 | | |
2093 | 2093 | | |
2094 | 2094 | | |
2095 | 2095 | | |
2096 | | - | |
| 2096 | + | |
2097 | 2097 | | |
2098 | 2098 | | |
2099 | 2099 | | |
| |||
4126 | 4126 | | |
4127 | 4127 | | |
4128 | 4128 | | |
4129 | | - | |
4130 | | - | |
| 4129 | + | |
| 4130 | + | |
4131 | 4131 | | |
4132 | | - | |
| 4132 | + | |
4133 | 4133 | | |
4134 | 4134 | | |
4135 | 4135 | | |
| |||
4445 | 4445 | | |
4446 | 4446 | | |
4447 | 4447 | | |
4448 | | - | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
4449 | 4451 | | |
4450 | 4452 | | |
4451 | 4453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1523 | 1523 | | |
1524 | 1524 | | |
1525 | 1525 | | |
1526 | | - | |
| 1526 | + | |
1527 | 1527 | | |
1528 | 1528 | | |
1529 | 1529 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2086 | 2086 | | |
2087 | 2087 | | |
2088 | 2088 | | |
2089 | | - | |
| 2089 | + | |
2090 | 2090 | | |
2091 | 2091 | | |
2092 | 2092 | | |
2093 | 2093 | | |
2094 | 2094 | | |
2095 | | - | |
| 2095 | + | |
2096 | 2096 | | |
2097 | 2097 | | |
2098 | 2098 | | |
| |||
4125 | 4125 | | |
4126 | 4126 | | |
4127 | 4127 | | |
4128 | | - | |
4129 | | - | |
| 4128 | + | |
| 4129 | + | |
4130 | 4130 | | |
4131 | | - | |
| 4131 | + | |
4132 | 4132 | | |
4133 | 4133 | | |
4134 | 4134 | | |
| |||
4444 | 4444 | | |
4445 | 4445 | | |
4446 | 4446 | | |
4447 | | - | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
4448 | 4450 | | |
4449 | 4451 | | |
4450 | 4452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2087 | 2087 | | |
2088 | 2088 | | |
2089 | 2089 | | |
2090 | | - | |
| 2090 | + | |
2091 | 2091 | | |
2092 | 2092 | | |
2093 | 2093 | | |
2094 | 2094 | | |
2095 | 2095 | | |
2096 | | - | |
| 2096 | + | |
2097 | 2097 | | |
2098 | 2098 | | |
2099 | 2099 | | |
| |||
4126 | 4126 | | |
4127 | 4127 | | |
4128 | 4128 | | |
4129 | | - | |
4130 | | - | |
| 4129 | + | |
| 4130 | + | |
4131 | 4131 | | |
4132 | | - | |
| 4132 | + | |
4133 | 4133 | | |
4134 | 4134 | | |
4135 | 4135 | | |
| |||
4445 | 4445 | | |
4446 | 4446 | | |
4447 | 4447 | | |
4448 | | - | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
4449 | 4451 | | |
4450 | 4452 | | |
4451 | 4453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2087 | 2087 | | |
2088 | 2088 | | |
2089 | 2089 | | |
2090 | | - | |
| 2090 | + | |
2091 | 2091 | | |
2092 | 2092 | | |
2093 | 2093 | | |
2094 | 2094 | | |
2095 | 2095 | | |
2096 | | - | |
| 2096 | + | |
2097 | 2097 | | |
2098 | 2098 | | |
2099 | 2099 | | |
| |||
4126 | 4126 | | |
4127 | 4127 | | |
4128 | 4128 | | |
4129 | | - | |
4130 | | - | |
| 4129 | + | |
| 4130 | + | |
4131 | 4131 | | |
4132 | | - | |
| 4132 | + | |
4133 | 4133 | | |
4134 | 4134 | | |
4135 | 4135 | | |
| |||
4445 | 4445 | | |
4446 | 4446 | | |
4447 | 4447 | | |
4448 | | - | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
4449 | 4451 | | |
4450 | 4452 | | |
4451 | 4453 | | |
| |||
0 commit comments