[MDEV-25879] Problem with modifing tables with STORED columns used in procedures Created: 2021-06-08  Updated: 2021-06-21  Resolved: 2021-06-08

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 10.5
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Anton Avramov Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: generated, regression, stored_procedures
Environment:

Debian 10, Ubuntu 20.04, Windows


Issue Links:
Duplicate
is duplicated by MDEV-25672 table alias from previous statement i... Closed

 Description   

After starting to install 10.5 on some instances we've noticed a problem with inserting and upgrading old databases.
Meaning the same procedure would work on 10.4 but it would throw and error Unknown column on 10.5.
We've striped down a simple SQL to reproduce the problem:

CREATE TABLE `A` (
  `AC1` int(11) PRIMARY KEY,
  `U_ID` int(11) NOT NULL,
  `U_N` int(11) GENERATED ALWAYS AS (`U_ID`) STORED
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
CREATE TABLE IF NOT EXISTS B(
  B_ID int(11) AUTO_INCREMENT PRIMARY KEY,
  BC1 int(11) NOT NULL
);
 
DELIMITER ;;
CREATE OR REPLACE PROCEDURE proc_migrate()
BEGIN
  DECLARE done INT DEFAULT 0;
  DECLARE p_AC1 int(11);
  DECLARE cur1 CURSOR FOR SELECT AC1 FROM A BU;
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
 
  OPEN cur1;
  REPEAT
    FETCH cur1 INTO p_AC1;
    IF NOT done THEN
      BEGIN
        INSERT INTO B (BC1) VALUES(p_AC1);
      END;
    END IF;
  UNTIL done END REPEAT;
  CLOSE cur1;
END;;
DELIMITER ;
 
CALL proc_migrate();
 
ALTER TABLE A MODIFY COLUMN AC1 int(11) NOT NULL;

This would throw 'Unknown column '`MDEV_NEW`.`BU`.`U_ID`' in 'GENERATED ALWAYS' on 10.5, but will work fine on 10.4



 Comments   
Comment by Alice Sherepa [ 2021-06-08 ]

Thank you for the report! There was a regression in the latest release - MDEV-25672 (10.4 was also affected).

Generated at Thu Feb 08 09:41:06 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.