Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-7745 - Stored procedure execution fails if contains a functional index #4854

Open
wants to merge 2 commits into
base: 8.0
Choose a base branch
from

Commits on Feb 8, 2023

  1. Fixed(PS-7745) - (Stored procedure execution fails if contains a func…

    …tional index)
    
    https://jira.percona.com/browse/PS-7745
    
    **Problem:**
    
    A Stored Procedure execution fails after some executions when a functional index is present in the SP definition. The error behaves differently depending on the versions I tested:
    
    8.0.23 (PS, Community): It only fails when using a temporary table. After the third execution, all the subsequent executions fail.
    
    8.0.25 (Community): It also fails on normal tables.
    
    How to Repeat
    
    ```
    DROP PROCEDURE IF EXISTS `sproc`;
    DELIMITER $$
    CREATE PROCEDURE `sproc`()
    BEGIN
    DROP TEMPORARY TABLE IF EXISTS `T1`;
    CREATE TEMPORARY TABLE `T1`(
    `C1` INT,
    KEY ( ( `C1` > 0 ) )
    );
    
    SELECT 1 FROM ( SELECT 1 `C2` ) `T2`;
    END$$
    DELIMITER ;
    Now if you invoke that procedure 3 times in a row:
    
    mysql> CALL `sproc`(); CALL `sproc`(); CALL `sproc`();
    +---+
    | 1 |
    +---+
    | 1 |
    +---+
    1 row in set (0.00 sec)
    
    Query OK, 0 rows affected (0.00 sec)
    
    +---+
    | 1 |
    +---+
    | 1 |
    +---+
    1 row in set (0.00 sec)
    
    Query OK, 0 rows affected (0.00 sec)
    
    ERROR 3107 (HY000): Generated column can refer only to generated columns defined prior to it.
    On 8.0.25 (Community) The error is
    
    ERROR 3754 (HY000): Functional index 'functional_index' cannot refer to an auto-increment column.
    ```
    
    **Cause:**
    
    The issue happens when checks are performed again during a query
    in the function `pre_validate_value_generator_expr()`
    and column index of the functional index is not available.
    
    **Solution:**
    
    This solution disables some checks if a column index is not available
    in the function `pre_validate_value_generator_expr()` during the second
    and later queries.
    It is safe because these checks are done in the function
    `validate_value_generator_expr()` during the first query.
    The column index is available there.
    Daniel R. Fiala committed Feb 8, 2023
    Configuration menu
    Copy the full SHA
    4e6484d View commit details
    Browse the repository at this point in the history

Commits on Mar 22, 2023

  1. fixup! Fixed(PS-7745) - (Stored procedure execution fails if contains…

    … a functional index)
    Daniel R. Fiala committed Mar 22, 2023
    Configuration menu
    Copy the full SHA
    9c09504 View commit details
    Browse the repository at this point in the history