This is an iterator which emits leaf Table_ref nodes in an order suitable for expansion of 'table_name.
More...
This is an iterator which emits leaf Table_ref nodes in an order suitable for expansion of 'table_name.
*' (qualified asterisk) or '*' (unqualified), fur use by insert_fields().
First here is some background.
1. SELECT T1.*, T2.* FROM T1 NATURAL JOIN T2; has to return all columns of T1 and then all of T2's; whereas SELECT * FROM T1 NATURAL JOIN T2; has to return all columns of T1 and then only those of T2's which are not common with T1. Thus, in the first case a NATURAL JOIN isn't considered a leaf (we have to see through it to find T1.* and T2.*), in the second case it is (we have to ask it for its column set). In the first case, the place to search for tables is thus the Table_ref::next_local list; in the second case it is Table_ref::next_name_resolution_table.
2. SELECT * FROM T1 RIGHT JOIN T2 ON < cond >; is converted, during contextualization, to: SELECT * FROM T2 LEFT JOIN T1 ON < cond >; however the former has to return columns of T1 then of T2, while the latter has to return T2's then T1's. The conversion has been complete: the lists 'next_local', 'next_name_resolution_table' and Query_block::m_current_table_nest are as if the user had typed the second query.
Now to the behaviour of this iterator.
A. If qualified asterisk, the emission order is irrelevant as the caller tests the table's name; and a NATURAL JOIN isn't a leaf. So, we just follow the Table_ref::next_local pointers.
B. If non-qualified asterisk, the order must be the left-to-right order as it was in the query entered by the user. And a NATURAL JOIN is a leaf. So:
B.i. if there was no RIGHT JOIN, then the user-input order is just that of the 'next_name_resolution' pointers.
B.ii. otherwise, then the order has to be found by a more complex procedure (function build_vec()):
- first we traverse the join operators, taking into account operators which had a conversion from RIGHT to LEFT JOIN, we recreate the user-input order and store leaf TABLE_LISTs in that order in a vector.
- then, in the emission phase, we just emit tables from the vector.
Sequence of calls: constructor, init(), [get_next() N times], destructor.