Commit b549af69 authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Oleksandr Byelkin

MDEV-26220 Server crashes with indexed by prefix virtual column

Server crashes in Field::register_field_in_read_map upon select from
partitioned table with indexed by prefix virtual column.

After several read-mark fixes a problem has surfaced:
Since KEY (c(10),a) uses only a prefix of c, a new field is created,
duplicated from table->field[3], with a new length. However,
vcol_inco->expr is not copied.

Therefore, (*key_info)->key_part[i].field->vcol_info->expr was left NULL
in ha_partition::index_init().

Solution: copy vcol_info from table field when it's set up.
parent 8b6c8a6c
...@@ -169,3 +169,15 @@ CREATE TABLE t1 ( ...@@ -169,3 +169,15 @@ CREATE TABLE t1 (
INSERT INTO t1 () VALUES (),(); INSERT INTO t1 () VALUES (),();
UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk; UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-26220 Server crashes with indexed by prefix virtual column
--echo #
CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b CHAR(20), c CHAR(20) AS (b),
KEY (c(10),a)) PARTITION BY HASH(pk);
INSERT INTO t1 (pk,a,b) VALUES (1,10,'foo'),(2,11,'baz');
SELECT a FROM t1;
# Cleanup
DROP TABLE t1;
...@@ -104,6 +104,17 @@ INSERT INTO t1 () VALUES (),(); ...@@ -104,6 +104,17 @@ INSERT INTO t1 () VALUES (),();
UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk; UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-26220 Server crashes with indexed by prefix virtual column
#
CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b CHAR(20), c CHAR(20) AS (b),
KEY (c(10),a)) PARTITION BY HASH(pk);
INSERT INTO t1 (pk,a,b) VALUES (1,10,'foo'),(2,11,'baz');
SELECT a FROM t1;
a
11
10
DROP TABLE t1;
#
# MDEV-16980 Wrongly set tablename len while opening the # MDEV-16980 Wrongly set tablename len while opening the
# table for purge thread # table for purge thread
# #
......
...@@ -101,6 +101,17 @@ KEY (b,d) ...@@ -101,6 +101,17 @@ KEY (b,d)
INSERT INTO t1 () VALUES (),(); INSERT INTO t1 () VALUES (),();
UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk; UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-26220 Server crashes with indexed by prefix virtual column
#
CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b CHAR(20), c CHAR(20) AS (b),
KEY (c(10),a)) PARTITION BY HASH(pk);
INSERT INTO t1 (pk,a,b) VALUES (1,10,'foo'),(2,11,'baz');
SELECT a FROM t1;
a
11
10
DROP TABLE t1;
DROP VIEW IF EXISTS v1,v2; DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2,t3; DROP TABLE IF EXISTS t1,t2,t3;
DROP PROCEDURE IF EXISTS p1; DROP PROCEDURE IF EXISTS p1;
......
...@@ -3284,6 +3284,21 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, ...@@ -3284,6 +3284,21 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
/* Update to use trigger fields */ /* Update to use trigger fields */
switch_defaults_to_nullable_trigger_fields(outparam); switch_defaults_to_nullable_trigger_fields(outparam);
for (uint k= 0; k < share->keys; k++)
{
KEY &key_info= outparam->key_info[k];
uint parts = (share->use_ext_keys ? key_info.ext_key_parts :
key_info.user_defined_key_parts);
for (uint p= 0; p < parts; p++)
{
KEY_PART_INFO &kp= key_info.key_part[p];
if (kp.field != outparam->field[kp.fieldnr - 1])
{
kp.field->vcol_info = outparam->field[kp.fieldnr - 1]->vcol_info;
}
}
}
} }
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
......
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