[MDEV-26220] Server crashes with indexed by prefix virtual column Created: 2021-07-22  Updated: 2021-08-02  Resolved: 2021-07-28

Status: Closed
Project: MariaDB Server
Component/s: Partitioning, Virtual Columns
Affects Version/s: 10.2, 10.3
Fix Version/s: 10.2.40, 10.3.31, 10.4.21, 10.5.12, 10.6.4

Type: Bug Priority: Blocker
Reporter: Elena Stepanova Assignee: Nikita Malyavin
Resolution: Fixed Votes: 0
Labels: regression


 Description   

--source include/have_partition.inc
 
CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b CHAR(20), c CHAR(20) AS (b) VIRTUAL, 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;

10.2 debug 4aeb2b1c

#3  <signal handler called>
#4  0x0000564fa8eb47be in Field::register_field_in_read_map (this=0x7fbafc0a3200) at /data/src/10.2/sql/field.cc:11251
#5  0x0000564fa95e39aa in ha_partition::index_init (this=0x7fbafc0a20e8, inx=1, sorted=true) at /data/src/10.2/sql/ha_partition.cc:5258
#6  0x0000564fa8bc2a79 in handler::ha_index_init (this=0x7fbafc0a20e8, idx=1, sorted=true) at /data/src/10.2/sql/handler.h:2837
#7  0x0000564fa8cb3391 in join_read_first (tab=0x7fbafc014150) at /data/src/10.2/sql/sql_select.cc:19881
#8  0x0000564fa8cb0db0 in sub_select (join=0x7fbafc013008, join_tab=0x7fbafc014150, end_of_records=false) at /data/src/10.2/sql/sql_select.cc:18892
#9  0x0000564fa8cb0374 in do_select (join=0x7fbafc013008, procedure=0x0) at /data/src/10.2/sql/sql_select.cc:18439
#10 0x0000564fa8c89e85 in JOIN::exec_inner (this=0x7fbafc013008) at /data/src/10.2/sql/sql_select.cc:3651
#11 0x0000564fa8c8932c in JOIN::exec (this=0x7fbafc013008) at /data/src/10.2/sql/sql_select.cc:3446
#12 0x0000564fa8c8a506 in mysql_select (thd=0x7fbafc000d90, tables=0x7fbafc0128e8, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fbafc012fe8, unit=0x7fbafc004988, select_lex=0x7fbafc0050d8) at /data/src/10.2/sql/sql_select.cc:3849
#13 0x0000564fa8c7e65a in handle_select (thd=0x7fbafc000d90, lex=0x7fbafc0048c8, result=0x7fbafc012fe8, setup_tables_done_option=0) at /data/src/10.2/sql/sql_select.cc:361
#14 0x0000564fa8c48cc0 in execute_sqlcom_select (thd=0x7fbafc000d90, all_tables=0x7fbafc0128e8) at /data/src/10.2/sql/sql_parse.cc:6271
#15 0x0000564fa8c3f834 in mysql_execute_command (thd=0x7fbafc000d90) at /data/src/10.2/sql/sql_parse.cc:3582
#16 0x0000564fa8c4ca7c in mysql_parse (thd=0x7fbafc000d90, rawbuf=0x7fbafc012708 "SELECT a FROM t1", length=16, parser_state=0x7fbb0e30c560, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7793
#17 0x0000564fa8c3acd7 in dispatch_command (command=COM_QUERY, thd=0x7fbafc000d90, packet=0x7fbafc008b61 "", packet_length=16, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1827
#18 0x0000564fa8c397d2 in do_command (thd=0x7fbafc000d90) at /data/src/10.2/sql/sql_parse.cc:1381
#19 0x0000564fa8d95453 in do_handle_one_connection (connect=0x564fabc34110) at /data/src/10.2/sql/sql_connect.cc:1336
#20 0x0000564fa8d951b8 in handle_one_connection (arg=0x564fabc34110) at /data/src/10.2/sql/sql_connect.cc:1241
#21 0x0000564fa95c18f4 in pfs_spawn_thread (arg=0x564fabc17440) at /data/src/10.2/storage/perfschema/pfs.cc:1869
#22 0x00007fbb14810609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#23 0x00007fbb143eb293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

The failure started happening after this commit:

commit 7d9ba57da4843c05a4d11e63159a961c4eb79a04
Author: Nikita Malyavin
Date:   Mon Jun 21 17:48:45 2021 +0300
 
    [1/2] MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
    
    This is a 10.2+ part of a jira task

Reproducible with at least MyISAM and InnoDB, on debug and non-debug builds, currently on 10.2 and 10.3 (the commit hasn't been merged into higher versions yet).



 Comments   
Comment by Nikita Malyavin [ 2021-07-23 ]

This is a nice one. 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

Comment by Nikita Malyavin [ 2021-07-23 ]

Commit for review:

https://github.com/MariaDB/server/commit/b58bebfeb4d6812c0a55091ebf2a45ff53c3fea0

Comment by Oleksandr Byelkin [ 2021-07-26 ]

https://github.com/MariaDB/server/commit/8fcc1e199327078bf4fd9054b19c0a1ace6a8bf2 OK to push

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