Commit 5569ac00 authored by Jan Lindström's avatar Jan Lindström

MDEV-11126: Crash while altering persistent virtual column

Problem was that if old virtual column is computed and stored there
was no check if new column is really virtual column.
parent 59a7bc35
...@@ -2021,3 +2021,58 @@ ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS event_id (event_id,market_id); ...@@ -2021,3 +2021,58 @@ ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS event_id (event_id,market_id);
Warnings: Warnings:
Note 1061 Multiple primary key defined Note 1061 Multiple primary key defined
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-11126 Crash while altering persistent virtual column
#
CREATE TABLE `tab1` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`field2` set('option1','option2','option3','option4') NOT NULL,
`field3` set('option1','option2','option3','option4','option5') NOT NULL,
`field4` set('option1','option2','option3','option4') NOT NULL,
`field5` varchar(32) NOT NULL,
`field6` varchar(32) NOT NULL,
`field7` varchar(32) NOT NULL,
`field8` varchar(32) NOT NULL,
`field9` int(11) NOT NULL DEFAULT '1',
`field10` varchar(16) NOT NULL,
`field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1',
`v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=latin1;
ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128);
SHOW CREATE TABLE `tab1`;
Table Create Table
tab1 CREATE TABLE `tab1` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`field2` set('option1','option2','option3','option4') NOT NULL,
`field3` set('option1','option2','option3','option4','option5') NOT NULL,
`field4` set('option1','option2','option3','option4') NOT NULL,
`field5` varchar(32) NOT NULL,
`field6` varchar(32) NOT NULL,
`field7` varchar(32) NOT NULL,
`field8` varchar(32) NOT NULL,
`field9` int(11) NOT NULL DEFAULT '1',
`field10` varchar(16) NOT NULL,
`field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1',
`v_col` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT;
SHOW CREATE TABLE `tab1`;
Table Create Table
tab1 CREATE TABLE `tab1` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`field2` set('option1','option2','option3','option4') NOT NULL,
`field3` set('option1','option2','option3','option4','option5') NOT NULL,
`field4` set('option1','option2','option3','option4') NOT NULL,
`field5` varchar(32) NOT NULL,
`field6` varchar(32) NOT NULL,
`field7` varchar(32) NOT NULL,
`field8` varchar(32) NOT NULL,
`field9` int(11) NOT NULL DEFAULT '1',
`field10` varchar(16) NOT NULL,
`field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1',
`v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE `tab1`;
...@@ -1712,3 +1712,28 @@ CREATE TABLE t1 ( ...@@ -1712,3 +1712,28 @@ CREATE TABLE t1 (
ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS event_id (event_id,market_id); ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS event_id (event_id,market_id);
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-11126 Crash while altering persistent virtual column
--echo #
CREATE TABLE `tab1` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`field2` set('option1','option2','option3','option4') NOT NULL,
`field3` set('option1','option2','option3','option4','option5') NOT NULL,
`field4` set('option1','option2','option3','option4') NOT NULL,
`field5` varchar(32) NOT NULL,
`field6` varchar(32) NOT NULL,
`field7` varchar(32) NOT NULL,
`field8` varchar(32) NOT NULL,
`field9` int(11) NOT NULL DEFAULT '1',
`field10` varchar(16) NOT NULL,
`field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1',
`v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=latin1;
ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128);
SHOW CREATE TABLE `tab1`;
ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT;
SHOW CREATE TABLE `tab1`;
DROP TABLE `tab1`;
...@@ -6274,6 +6274,7 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6274,6 +6274,7 @@ static bool fill_alter_inplace_info(THD *thd,
(field->stored_in_db || field->vcol_info->is_in_partitioning_expr())) (field->stored_in_db || field->vcol_info->is_in_partitioning_expr()))
{ {
if (is_equal == IS_EQUAL_NO || if (is_equal == IS_EQUAL_NO ||
!new_field->vcol_info ||
!field->vcol_info->is_equal(new_field->vcol_info)) !field->vcol_info->is_equal(new_field->vcol_info))
ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_COLUMN_VCOL; ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_COLUMN_VCOL;
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment