1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-35616: Add basic optimizer support for virtual column

(Review input addressed)

After this patch, the optimizer can handle virtual column expressions
in WHERE/ON clauses. If the table has an indexed virtual column:

  ALTER TABLE t1
    ADD COLUMN vcol INT AS (col1+1),
    ADD INDEX idx1(vcol);

and the query uses the exact virtual column expression:

  SELECT * FROM t1 WHERE col1+1 <= 100

then the optimizer will be able use index idx1 for it.

This is achieved by walking the WHERE/ON clauses and replacing instances
of virtual column expression (like "col1+1" above) with virtual column's
Item_field (like "vcol"). The latter can be processed by the optimizer.

Replacement is considered (and done) only in items that are potentially
usable to the range optimizer.
This commit is contained in:
Sergei Petrunia
2024-11-26 14:50:41 +02:00
parent 759df4cc5f
commit 1c2a83179d
17 changed files with 1057 additions and 18 deletions

View File

@@ -470,6 +470,9 @@ bool Sql_cmd_update::update_single_table(THD *thd)
(uchar *) 0);
}
if (conds && substitute_indexed_vcols_for_table(table, conds))
DBUG_RETURN(1); // Fatal error
// Don't count on usage of 'only index' when calculating which key to use
table->covering_keys.clear_all();
transactional_table= table->file->has_transactions_and_rollback();