[MDEV-22781] CREATE VIEW containing WITH clause Signal 11 Created: 2020-06-02  Updated: 2021-11-29  Resolved: 2020-12-08

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - CTE
Affects Version/s: 10.3.17, 10.4.12, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.2.37, 10.3.28, 10.4.18, 10.5.9

Type: Bug Priority: Critical
Reporter: Sal Gonzalez Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None
Environment:

Reproducible on OpenSUSE Tumbleweed (10.4.12) and CentOS 8.1.1911 (Core) (10.3.17)


Issue Links:
Blocks
is blocked by MDEV-24314 Unexpected error message when selecti... Closed
Duplicate
is duplicated by MDEV-23847 Server crash during view creation Closed
Relates
relates to MDEV-15907 ASAN heap-use-after-free in strnmov /... Closed
relates to MDEV-16473 WITH statement throws 'no database se... Closed

 Description   

Attempting to create a view with a WITH clause crashes every time.

Steps to reproduce:

 
MariaDB [(none)]> CREATE TABLE test.tbl1 ( f CHAR(1));
Query OK, 0 rows affected (0.019 sec)
 
MariaDB [(none)]> CREATE VIEW test.vw1 AS WITH t1 AS (SELECT * FROM test.tbl1) SELECT * FROM t1;
ERROR 2013 (HY000): Lost connection to MySQL server during query

I have grabbed the core file, will provide if needed

mysql log:

200602 13:14:42 [ERROR] mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
 
To report this bug, see https://mariadb.com/kb/en/reporting-bugs
 
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.
 
Server version: 10.4.12-MariaDB
key_buffer_size=134217728
read_buffer_size=131072
max_used_connections=1
max_threads=153
thread_count=7
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 467756 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
 
Thread pointer: 0x7f5dd0000c48
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x7f5e3c0c8de8 thread_stack 0x49000
/usr/sbin/mysqld(my_print_stacktrace+0x38)[0x5589fbb90b68]
/usr/sbin/mysqld(handle_fatal_signal+0x4dd)[0x5589fc0220dd]
/lib64/libpthread.so.0(+0x141e0)[0x7f5e3fe181e0]
/usr/sbin/mysqld(strnmov+0x10)[0x5589fbb3a5a0]
/usr/sbin/mysqld(_Z7acl_getPKcS0_S0_S0_c+0x85)[0x5589fc2bb1c5]
/usr/sbin/mysqld(_Z31fill_effective_table_privilegesP3THDP13st_grant_infoPKcS4_+0x79)[0x5589fc2a8669]
/usr/sbin/mysqld(_Z20create_view_precheckP3THDP10TABLE_LISTS2_21enum_view_create_mode+0xe1)[0x5589fc185d11]
/usr/sbin/mysqld(_Z17mysql_create_viewP3THDP10TABLE_LIST21enum_view_create_mode+0x89)[0x5589fc18de09]
/usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x3199)[0x5589fc23c919]
/usr/sbin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_statebb+0x25f)[0x5589fbadaf0f]
/usr/sbin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcjbb+0x129b)[0x5589fc243bab]
/usr/sbin/mysqld(_Z10do_commandP3THD+0x14f)[0x5589fc245d3f]
/usr/sbin/mysqld(_Z24do_handle_one_connectionP7CONNECT+0x1d4)[0x5589fc145154]
/usr/sbin/mysqld(handle_one_connection+0x32)[0x5589fc1452a2]
/lib64/libpthread.so.0(+0x8efa)[0x7f5e3fe0cefa]
/lib64/libc.so.6(clone+0x3f)[0x7f5e3f45e3df]
 
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7f5dd000ff70): CREATE VIEW test.vw1 AS WITH t1 AS (SELECT * FROM test.tbl1) SELECT * FROM t1
Connection ID (thread ID): 9
Status: NOT_KILLED
 
Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on
 
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
Writing a core file...
Working directory at /var/lib/mysql
Resource Limits:
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        unlimited            unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             15625                15625                processes 
Max open files            4186                 4186                 files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       15625                15625                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        
Core pattern: /tmp/corefiles/core



 Comments   
Comment by Alice Sherepa [ 2020-06-03 ]

Thanks a lot! I repeated on 10.2-10.5. (test uses CTE, so I checked only 10.2+ )
I could not reproduce the test at first as I didn't notice that in the demonstrated case client does not have a default database to use.
To run mtr-test I delete and recreate db test:

drop database test;
create database test;
 
CREATE TABLE test.tbl1 ( f CHAR(1));
CREATE VIEW test.vw1 AS WITH t1 AS (SELECT * FROM test.tbl1) SELECT * FROM t1;

10.2 50641db2d11ad8a2228f7938

#3  <signal handler called>
#4  strnmov (dst=0x7f593deeb477 "", src=0x1 <error: Cannot access memory at address 0x1>, n=587) at /10.2/strings/strnmov.c:41
#5  0x000056173132f917 in acl_get (host=0x561731e5b27d "localhost", ip=0x0, user=0x7f5920002920 "root", db=0x0, db_is_pattern=0 '\000') at /10.2/sql/sql_acl.cc:3046
#6  0x000056173134b982 in fill_effective_table_privileges (thd=0x7f5920000d50, grant=0x7f5920014740, db=0x0, table=0x7f5920014438 "t1") at /10.2/sql/sql_acl.cc:11845
#7  0x00005617314c1799 in create_view_precheck (thd=0x7f5920000d50, tables=0x7f5920014470, view=0x7f59200128f0, mode=VIEW_CREATE_NEW) at /10.2/sql/sql_view.cc:323
#8  0x00005617314c1ab9 in mysql_create_view (thd=0x7f5920000d50, views=0x7f59200128f0, mode=VIEW_CREATE_NEW) at /10.2/sql/sql_view.cc:427
#9  0x00005617313d1fae in mysql_execute_command (thd=0x7f5920000d50) at /10.2/sql/sql_parse.cc:5796
#10 0x00005617313d78fb in mysql_parse (thd=0x7f5920000d50, rawbuf=0x7f59200127a8 "CREATE VIEW test.vw1 AS WITH t1 AS (SELECT * FROM test.tbl1) SELECT * FROM t1", length=77, parser_state=0x7f593deec5f0, is_com_multi=false, is_next_command=false) at /10.2/sql/sql_parse.cc:7741
#11 0x00005617313c5d16 in dispatch_command (command=COM_QUERY, thd=0x7f5920000d50, packet=0x7f5920008c01 "CREATE VIEW test.vw1 AS WITH t1 AS (SELECT * FROM test.tbl1) SELECT * FROM t1", packet_length=77, is_com_multi=false, is_next_command=false) at /10.2/sql/sql_parse.cc:1831
#12 0x00005617313c479b in do_command (thd=0x7f5920000d50) at /10.2/sql/sql_parse.cc:1385
#13 0x0000561731518e36 in do_handle_one_connection (connect=0x5617338056c0) at /10.2/sql/sql_connect.cc:1336
#14 0x0000561731518ba1 in handle_one_connection (arg=0x5617338056c0) at /10.2/sql/sql_connect.cc:1241
#15 0x0000561731d19710 in pfs_spawn_thread (arg=0x56173380e440) at /10.2/storage/perfschema/pfs.cc:1869
#16 0x00007f594451bfa3 in start_thread (arg=<optimized out>) at pthread_create.c:486
#17 0x00007f5943e9f4cf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Comment by Igor Babaev [ 2020-12-01 ]

We have a problem already with derived tables used in views:
Here's a test case demonstrating the problem:

drop database test;
create database test;
create table test.t1 (a int);
insert into test.t1 values (3),(7),(1);
create view test.v2 as select * from (select * from test.t1) as t;
select test.v2.a from test.v2;

MariaDB [(none)]> select test.v2.a from test.v2;
ERROR 1356 (HY000): View 'test.v2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them                                                                                                                 

Comment by Oleksandr Byelkin [ 2020-12-07 ]

OK to push

Comment by Igor Babaev [ 2020-12-08 ]

A fix for this bug was pushed into 10.2

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