mariadb/mysql-test/suite/vcol/t
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.test
binlog.test [1/2] MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols 2021-07-12 22:00:39 +03:00
charsets.test
cross_db.test
delayed.test
func_regexp.test MDEV-21058 CREATE TABLE with generated column and RLIKE results in sigabrt 2024-04-29 11:08:07 +04:00
index.test
innodb_autoinc_vcol.test
innodb_virtual_fk.test MDEV-31853 Assertion failure in Column_definition::check_vcol_for_key upon adding FK 2023-08-06 20:08:51 +02:00
load_data.test cleanup: select ... into tests 2025-02-11 20:31:25 +01:00
mrr.test
myisam_repair_prefix_varchar.test
not_supported.test MDEV-29155 CREATE OR REPLACE with self-referencing CHECK hangs 2025-05-29 12:34:07 +03:00
order_by_group_by_subst.test 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.test MDEV-36132 Substitute vcol expressions with indexed vcol fields in ORDER BY and GROUP BY 2025-07-22 10:44:12 +10:00
partition.test MDEV-28127 EXCHANGE PARTITION with non-matching vcol expression segfault 2023-11-10 15:46:15 +03:00
races.test
range.test
rpl_vcol.test
update.test MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
update_binlog.test
upgrade.test
vcol_archive.test
vcol_blackhole.test
vcol_blocked_sql_funcs.test
vcol_blocked_sql_funcs_main.inc MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
vcol_column_def_options_innodb.test
vcol_column_def_options_myisam.test
vcol_csv.test
vcol_handler_aria.test
vcol_handler_innodb.test
vcol_handler_myisam.test
vcol_ins_upd_innodb.test
vcol_ins_upd_myisam.test
vcol_keys_aria.test
vcol_keys_innodb.opt
vcol_keys_innodb.test
vcol_keys_myisam.test cleanup: select ... into tests 2025-02-11 20:31:25 +01:00
vcol_memory.test
vcol_merge.test
vcol_misc.opt vcols: cannot use CONTEXT_ANALYSIS_ONLY_VCOL_EXPR on fix_fields 2022-04-19 17:10:05 +02:00
vcol_misc.test Merge branch '10.11 into 11.4 2025-01-30 12:01:11 +01:00
vcol_non_stored_columns_innodb.test
vcol_non_stored_columns_myisam.test
vcol_partition_innodb.test
vcol_partition_myisam.test
vcol_sargable.test Merge remote-tracking branch 'github/bb-11.4-release' into bb-11.8-serg 2025-04-27 19:40:00 +02:00
vcol_sargable_debug.test MDEV-35616: Add basic optimizer support for virtual column 2025-01-25 10:50:52 +02:00
vcol_select_innodb.test MDEV-4750 follow-up: Reduce disabling innodb_stats_persistent 2021-08-31 13:55:02 +03:00
vcol_select_myisam.test
vcol_sql_mode.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
vcol_sql_mode_datetime.test
vcol_sql_mode_time.test
vcol_sql_mode_timestamp.test
vcol_sql_mode_upgrade.test
vcol_supported_sql_funcs.test
vcol_supported_sql_funcs_main.inc
vcol_syntax.test Merge branch '10.5' into 10.6 2023-12-17 11:20:43 +01:00
vcol_trigger_sp_innodb.test
vcol_trigger_sp_myisam.test
vcol_utf32.test MDEV-27966 Assertion fixed()' failed and Assertion fixed == 1' failed, both in Item_func_concat::val_str on SELECT after INSERT with collation utf32_bin on utf8_bin table 2024-06-19 10:01:30 +04:00
vcol_view_innodb.test MDEV-4750 follow-up: Reduce disabling innodb_stats_persistent 2021-08-31 13:55:02 +03:00
vcol_view_myisam.test
wrong_arena.test MDEV-31003: Second execution for ps-protocol 2023-07-26 17:15:00 +07:00