mariadb/mysql-test/suite/vcol/r
Yuchen Pei 8cdee25952
MDEV-36132 Substitute vcol expressions with indexed vcol fields in ORDER BY and GROUP BY
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.
2025-07-22 10:44:12 +10:00
..
alter_inplace-9045.result
binlog.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
charsets.result
cross_db.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
delayed.result
func_regexp.result MDEV-21058 CREATE TABLE with generated column and RLIKE results in sigabrt 2024-04-29 11:08:07 +04:00
index.result
innodb_autoinc_vcol.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
innodb_virtual_fk.result MDEV-28933: Per-table unique FOREIGN KEY constraint names 2025-07-08 12:30:27 +03:00
load_data.result
mrr.result
myisam_repair_prefix_varchar.result
not_supported.result MDEV-29155 CREATE OR REPLACE with self-referencing CHECK hangs 2025-05-29 12:34:07 +03:00
order_by_group_by_subst.result MDEV-36132 Substitute vcol expressions with indexed vcol fields in ORDER BY and GROUP BY 2025-07-22 10:44:12 +10:00
order_by_group_by_subst_notembedded.result MDEV-36132 Substitute vcol expressions with indexed vcol fields in ORDER BY and GROUP BY 2025-07-22 10:44:12 +10:00
partition.result fix incorrect merge 15700f54c2 2025-04-18 09:41:24 +02:00
races.result
range.result
rpl_vcol.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
update.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
update_binlog.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
upgrade.result MDEV-30016 Virtual columns do not support autoincrement columns 2022-12-02 16:19:13 +01:00
vcol_archive.result
vcol_blackhole.result
vcol_blocked_sql_funcs.result MDEV-15751 CURRENT_TIMESTAMP should return a TIMESTAMP [WITH TIME ZONE?] 2024-10-19 22:48:23 +02:00
vcol_column_def_options_innodb.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
vcol_column_def_options_myisam.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
vcol_csv.result
vcol_handler_aria.result
vcol_handler_innodb.result
vcol_handler_myisam.result
vcol_ins_upd_innodb.result MDEV-28933: Per-table unique FOREIGN KEY constraint names 2025-07-08 12:30:27 +03:00
vcol_ins_upd_myisam.result Added test cases for preceding test 2023-02-03 00:00:35 +03:00
vcol_keys_aria.result
vcol_keys_innodb.result Merge branch '11.5' into 11.6 2024-08-21 15:13:47 +02:00
vcol_keys_myisam.result Merge branch '11.5' into 11.6 2024-08-21 15:13:47 +02:00
vcol_memory.result
vcol_merge.result
vcol_misc.result Merge branch '11.4' into 11.7 2025-02-06 16:46:36 +01:00
vcol_non_stored_columns_innodb.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
vcol_non_stored_columns_myisam.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
vcol_partition_innodb.result
vcol_partition_myisam.result
vcol_sargable.result MDEV-36132 Substitute vcol expressions with indexed vcol fields in ORDER BY and GROUP BY 2025-07-22 10:44:12 +10:00
vcol_sargable_debug.result MDEV-35616: Add basic optimizer support for virtual column 2025-01-25 10:50:52 +02:00
vcol_select_innodb.result MDEV-36132 Substitute vcol expressions with indexed vcol fields in ORDER BY and GROUP BY 2025-07-22 10:44:12 +10:00
vcol_select_myisam.result MDEV-36132 Substitute vcol expressions with indexed vcol fields in ORDER BY and GROUP BY 2025-07-22 10:44:12 +10:00
vcol_sql_mode.result Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
vcol_sql_mode_datetime.result
vcol_sql_mode_time.result
vcol_sql_mode_timestamp.result
vcol_sql_mode_upgrade.result MDEV-31853 Assertion failure in Column_definition::check_vcol_for_key upon adding FK 2023-08-06 20:08:51 +02:00
vcol_supported_sql_funcs.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
vcol_syntax.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
vcol_trigger_sp_innodb.result
vcol_trigger_sp_myisam.result
vcol_utf32.result Merge 10.5 into 10.6 2024-06-24 13:09:47 +03:00
vcol_view_innodb.result MDEV-4750 follow-up: Reduce disabling innodb_stats_persistent 2021-08-31 13:55:02 +03:00
vcol_view_myisam.result
wrong_arena.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00