Skip to content

planner: allow the optimizer to cache query plans accessing generated columns #45798

Description

@qw4990

Enhancement

Work Item Tracking

Description

Currently, queries below are not allowed to be cached since these queries are accessing generated columns:

create table t1 (
    a int,
    info json,
    city varchar(64) as (JSON_UNQUOTE(JSON_EXTRACT(info, '$.city')))
);
prepare s1 from 'select * from t1 where a=?';
show warnings;

create table t2 (
    a int,
    info json,
    city varchar(64) as (JSON_UNQUOTE(JSON_EXTRACT(info, '$.city'))) virtual
);
prepare s2 from 'select * from t2 where a=?';
show warnings;

create table t3 (
    a int,
    info json,
    city varchar(64) as (JSON_UNQUOTE(JSON_EXTRACT(info, '$.city'))) stored
);
prepare s3 from 'select * from t3 where a=?';
show warnings;

create table t4 (
    a int,
    info json,
    index zips( (CAST(info->'$.zipcode' AS UNSIGNED ARRAY)))
);
prepare s4 from 'select * from t4 where a=?';
show warnings;
mysql> show warnings;
+---------+------+----------------------------------------------------------------------------+
| Level   | Code | Message                                                                    |
+---------+------+----------------------------------------------------------------------------+
| Warning | 1105 | skip prepared plan-cache: query accesses generated columns is un-cacheable |
+---------+------+----------------------------------------------------------------------------+
1 row in set (0.00 sec)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions