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 Merge branch '10.1' into 10.2 2016-09-09 08:33:08 +02:00
cross_db.test Updated mtr files to support different compiled in options 2019-09-01 19:17:35 +03:00
delayed.test store/show vcols as item->print() 2016-12-12 20:35:41 +01:00
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 MDEV-16961 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed upon concurrent DELETE and DDL with virtual blob column 2018-08-22 22:18:44 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_blackhole.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_blocked_sql_funcs.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_column_def_options_myisam.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_csv.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_handler_aria.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_handler_innodb.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_handler_myisam.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_ins_upd_innodb.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_ins_upd_myisam.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_keys_aria.test
vcol_keys_innodb.opt MDEV-20799 DROP Virtual Column crashes MariaDB 2019-10-28 08:40:48 +01:00
vcol_keys_innodb.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_keys_myisam.test cleanup: select ... into tests 2025-02-11 20:31:25 +01:00
vcol_memory.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_non_stored_columns_myisam.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_partition_innodb.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_partition_myisam.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_sql_mode.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
vcol_sql_mode_datetime.test Merge 10.4 into 10.5 2019-09-24 10:07:56 +03:00
vcol_sql_mode_time.test Merge 10.4 into 10.5 2019-09-24 10:07:56 +03:00
vcol_sql_mode_timestamp.test Merge remote-tracking branch 'origin/10.4' into 10.5 2019-10-01 11:44:27 +04:00
vcol_sql_mode_upgrade.test Revert "Part3: MDEV-18156 Assertion 0' failed or btr_validate_index(index, 0, false)' in row_upd_sec_index_entry or error code 126: Index is corrupted upon DELETE with PAD_CHAR_TO_FULL_LENGTH" 2019-09-11 13:52:33 +04:00
vcol_supported_sql_funcs.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_trigger_sp_myisam.test MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
wrong_arena.test MDEV-31003: Second execution for ps-protocol 2023-07-26 17:15:00 +07:00