You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug#36542023: Simplify the find_field function interfaces
The existing functions for resolving column references are still
present, but interfaces have been simplified and made more consistent.
Error handling is separated out and an error is now indicated with
a true function return, as usual.
Generally, a successful resolver function call will return one out of
three responses:
- column was not found, or
- column was found and resolved to a field reference, or
- column was found and resolved to an indirect reference (Item_ref).
The arguments could be simpler, but this subdivision is there for
efficiency: a field reference is usually used to resolve an Item_field
object, however it may also be used to populate some indirect
reference object (Item_ref) later on. Thus, it makes sense to keep the
field reference until we know what to do with it.
Interfaces for iterating over natural join columns and view columns have
been changed from operating on Item pointers to Item_ident pointers,
since they only work with field objects and reference objects.
This simplified the code, since some asserts and casts could be removed.
The old slightly confusing enum find_item_error_report_type for
reporting or ignoring certain error conditions has been replaced with
a bitmask specifying which errors to possibly return.
Old asserts marked 'WL#6570 remove-after-qa' are deleted.
The patch also fixes the problem in bug 36704815 by not checking
derived tables when the column reference contains a database name.
New tests are added for this case.
Specific changes, per function:
find_field_in_tables()
- Irrelevant argument register_tree_change is deleted.
- Improved asserts for valid column name search.
- Shortcut for item->m_table_ref != nullptr is removed.
find_field_in_table_ref()
- Irrelevant arguments register_tree_change and cached_field_index_ptr
are deleted.
find_field_in_table()
- Irrelevant arguments field_index_ptr, register_tree_change and
actual_table have been deleted.
- Improved asserts of input arguments (Table_ref argument).
- Removed check for empty database name.
find_field_in_table_sef()
- Only cosmetic changes.
find_field_in_view()
- Irrelevant arguments register_tree_change and actual_table are
deleted.
- The possible alias name of a column is passed explicitly, instead of
being picked up from the "ref" argument.
- ps_arena_holder is removed since this function is only called during
resolving.
- Successful outcome is reported as field not found, base table field
found or reference found.
find_field_in_natural_join()
- Irrelevant arguments register_tree_change and actual_table are
deleted.
- ps_arena_holder was deleted, since function is only called by resolver.
- Explicit call to nj_col->table_field->fix_fields() was irrelevant and
has been removed.
Item_field::fix_fields()
- Special call to rf->fix_fields() was irrelevant and hence deleted.
Item_field::fix_outer_field()
- A new argument "complete" is used to signal that the object returned
from this function is fully resolved.
- The field_found variable is removed since it is no longer used.
- The field upward_lookup is replaced with has_outer_context, since it
better describes what is being tested. (It is used to report error
in the case that Item_field::fix_fields() did not find a field
reference and there are no possible outer references to resolve).
Item_ref::fix_fields()
- Mostly unchanged, only adapted to new call interfaces.
- ps_arena_holder was deleted, since function is only called by resolver.
- Some redundant code is removed and substituted with asserts.
Change-Id: I11c51c25f30c4f85abefa9d326c2336bc31bb7d7
Copy file name to clipboardexpand all lines: mysql-test/r/with_non_recursive.result
+8-14
Original file line number
Diff line number
Diff line change
@@ -244,12 +244,10 @@ inner outer
244
244
# Qualified name isn't allowed after WITH:
245
245
with test.qn as (select "with") select * from test.qn;
246
246
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.qn as (select "with") select * from test.qn' at line 1
247
-
# Adding a db. prefix to a field still resolves to the QN; it's a bit awkward as
248
-
# the QN doesn't belong to a db, but it's the same with derived table:
247
+
# Adding a database prefix to a field does not resolve to the QN:
249
248
select test.qn.a from (select "with" as a) qn;
250
-
a
251
-
with
252
-
# OTOH, db. prefix in FROM doesn't resolve to QN, which is good
249
+
ERROR 42S22: Unknown column 'test.qn.a' in 'field list'
250
+
# database prefix in FROM does not resolve to QN:
253
251
with qn as (select "with") select * from qn;
254
252
with
255
253
with
@@ -263,8 +261,7 @@ with qn as (select "with" as a) select qn.a from qn;
263
261
a
264
262
with
265
263
with qn as (select "with" as a) select test.qn.a from qn;
266
-
a
267
-
with
264
+
ERROR 42S22: Unknown column 'test.qn.a' in 'field list'
268
265
with qn as (select "with" as a) select a from test.qn;
269
266
a
270
267
tmp
@@ -1355,12 +1352,10 @@ inner outer
1355
1352
# Qualified name isn't allowed after WITH:
1356
1353
with test.qn as (select "with") select * from test.qn;
1357
1354
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.qn as (select "with") select * from test.qn' at line 1
1358
-
# Adding a db. prefix to a field still resolves to the QN; it's a bit awkward as
1359
-
# the QN doesn't belong to a db, but it's the same with derived table:
1355
+
# Adding a database prefix to a field does not resolve to the QN:
1360
1356
select test.qn.a from (select "with" as a) qn;
1361
-
a
1362
-
with
1363
-
# OTOH, db. prefix in FROM doesn't resolve to QN, which is good
1357
+
ERROR 42S22: Unknown column 'test.qn.a' in 'field list'
1358
+
# database prefix in FROM does not resolve to QN:
1364
1359
with qn as (select "with") select * from qn;
1365
1360
with
1366
1361
with
@@ -1374,8 +1369,7 @@ with qn as (select "with" as a) select qn.a from qn;
1374
1369
a
1375
1370
with
1376
1371
with qn as (select "with" as a) select test.qn.a from qn;
1377
-
a
1378
-
with
1372
+
ERROR 42S22: Unknown column 'test.qn.a' in 'field list'
1379
1373
with qn as (select "with" as a) select a from test.qn;
0 commit comments