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 MDEV-7635: Update tests to adapt to the new default sql_mode 2017-02-10 06:30:42 -05:00
binlog.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
charsets.result Merge branch '10.1' into 10.2 2016-09-09 08:33:08 +02:00
cross_db.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
delayed.result store/show vcols as item->print() 2016-12-12 20:35:41 +01:00
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 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.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 MDEV-7635: Update tests to adapt to the new default sql_mode 2017-02-10 06:30:42 -05:00
mrr.result bugfix: move vcol calculations down into the handler 2016-12-12 20:27:38 +01:00
myisam_repair_prefix_varchar.result MDEV-11605 Assertion `(longlong) thd->status_var.local_memory_used >= 0 || !debug_assert_on_not_freed_memory' failed in my_malloc_size_cb_func 2017-03-29 00:40:22 +02:00
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 MDEV-17349 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed on concurrent SELECT and DELETE after RENAME from table with index on virtual column 2018-11-04 08:12:28 +01:00
range.result Ensure that table->vcol_set is properly restored if used 2018-01-01 14:44:20 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_blackhole.result MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_handler_aria.result MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_handler_innodb.result MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_handler_myisam.result MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 Aria: test for ER_KEY_BASED_ON_GENERATED_VIRTUAL_COLUMN 2016-12-12 20:44:46 +01:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_merge.result MDEV-11066 use MySQL terminology for "virtual columns" 2016-12-12 20:35:51 +01:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_partition_myisam.result MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 Merge 10.4 into 10.5 2019-09-24 10:07:56 +03:00
vcol_sql_mode_time.result Merge 10.4 into 10.5 2019-09-24 10:07:56 +03:00
vcol_sql_mode_timestamp.result Merge remote-tracking branch 'origin/10.4' into 10.5 2019-10-01 11:44:27 +04:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
vcol_trigger_sp_myisam.result MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
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 MDEV-18650: Options deprecated in previous versions - storage_engine 2020-02-13 13:42:01 +02:00
wrong_arena.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00