mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Also expand vcol field index coverings to include indexes covering all the fields in the expression. The reasoning goes as follows: let f(c1, c2, ..., cn) be a function on applied to columns c1, c2, ..., cn, if f(...) is covered by an index, so should vc whose expression is f(...). For example, if t.vf = t.c1 + t.c2, and t has three indexes (vf), (c1, c2), (c1). Before this change, vf's index covering is a singleton {(vf)}. Let's call that the "conventional" index covering. After this change vf's index covering is now {(vf), (c1, c2)}, since (c1, c2) covers both c1 and c2. Let's call (c1, c2) in this case the "extra" covering. With the coverings updated, when an index in the "extra" covering is chosen for keyread, the vcol also needs to be calculated. In this case we mark vcol in the table read_set, and ensure it is computed. With these changes, we see various improvements, including from using full table scan + filesort to full index scan + filesort when ORDER BY an indexed vcol (here vc = c + 1 is a vcol and both c and vc are indexes): explain select c + 1 from t order by vc; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t ALL NULL NULL NULL NULL 10000 Using filesort +1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using filesort The substitutions are followed updates to all_fields which include a copy of the ORDER BY/GROUP BY item pointers, as well as corresponding updates to ref_pointer_array so that the all_fields and ref_pointer_array remain in sync. Another, related change is the recomputation of table index covering on substitutions. It not only reflects the correct table index covering after the substitutions, but also improve executions where the vcol index can be chosen, such as this example (here vc = c + 1 and vc is the only index in the table), from full table scan + filesort to full index scan: select vc from t order by c + 1; We do it in SELECT as well as in single table DELETE/UPDATE.