[MDEV-2162] LP:578782 - Crash when virtual column uses stored function Created: 2010-05-11  Updated: 2015-02-02  Resolved: 2012-10-04

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Sergei Petrunia Assignee: Oleksandr Byelkin
Resolution: Not a Bug Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug578782.xml    

 Description   

mysqld will crash when one tries to create a table with virtual column that uses stored function.

== How to repeat ==
mysql> delimiter //
mysql> create function f1(a int) returns int begin return a+1; end //
Query OK, 0 rows affected (0.04 sec)

mysql> delimiter ;
mysql> create table tv1 (a int, b int as (f1(a)) persistent);
ERROR 2013 (HY000): Lost connection to MySQL server during query

== Crash details ==
mysqld: field.cc:9611: bool Create_field::init(THD*, char*, enum_field_types, char*, char*, uint, Item*, Item*, LEX_STRING*, char*, List<String>, const CHARSET_INFO, uint, Virtual_column_info*): Assertion `vcol_info && vcol_info->expr_item' failed.

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x9e921bb0 (LWP 8264)]
0xb7d51947 in raise () from /lib/tls/libc.so.6
(gdb) wher
#0 0xb7d51947 in raise () from /lib/tls/libc.so.6
#1 0xb7d530c9 in abort () from /lib/tls/libc.so.6
#2 0xb7d4b05f in __assert_fail () from /lib/tls/libc.so.6
#3 0x0823a734 in Create_field::init (this=0x9db3730, thd=0x9cc7588, fld_name=0x9db2bb0 "b", fld_type=245, fld_length=0x0, fld_decimals=0x0, fld_type_modifier=0, fld_default_value=0x0, fld_on_update_value=0x0, fld_comment=0x9cc905c, fld_change=0x0, fld_interval_list=0x9cc910c, fld_charset=0x0, fld_geom_type=2779096485, fld_vcol_info=0x9db3710) at field.cc:9611
#4 0x0827db2a in add_field_to_list (thd=0x9cc7588, field_name=0x9e91f944, type=245, length=0x0, decimals=0x0, type_modifier=0, default_value=0x0, on_update_value=0x0, comment=0x9cc905c, change=0x0, interval_list=0x9cc910c, cs=0x0, uint_geom_type=2779096485, vcol_info=0x9db3710) at sql_parse.cc:6243
#5 0x082a9749 in MYSQLparse (yythd=0x9cc7588) at sql_yacc.yy:4957
#6 0x0827a5be in parse_sql (thd=0x9cc7588, parser_state=0x9e920cb0, creation_ctx=0x0) at sql_parse.cc:7998
#7 0x0828baf7 in mysql_parse (thd=0x9cc7588, inBuf=0x9db2850 "create table tv1 (a int, b int as (f1(a)) persistent)", length=53, found_semicolon=0x9e921300) at sql_parse.cc:6042
#8 0x0828cbdd in dispatch_command (command=COM_QUERY, thd=0x9cc7588, packet=0x9d9ab41 "create table tv1 (a int, b int as (f1(a)) persistent)", packet_length=53) at sql_parse.cc:1253
#9 0x0828df3e in do_command (thd=0x9cc7588) at sql_parse.cc:891
#10 0x08278cf6 in handle_one_connection (arg=0x9cc7588) at sql_connect.cc:1599
#11 0xb7edf0bd in start_thread () from /lib/tls/libpthread.so.0
#12 0xb7df49ee in clone () from /lib/tls/libc.so.6
(gdb) up
#1 0xb7d530c9 in abort () from /lib/tls/libc.so.6
(gdb) up
#2 0xb7d4b05f in __assert_fail () from /lib/tls/libc.so.6
(gdb) up
#3 0x0823a734 in Create_field::init (this=0x9db3730, thd=0x9cc7588, fld_name=0x9db2bb0 "b", fld_type=245, fld_length=0x0, fld_decimals=0x0, fld_type_modifier=0, fld_default_value=0x0, fld_on_update_value=0x0, fld_comment=0x9cc905c, fld_change=0x0, fld_interval_list=0x9cc910c, fld_charset=0x0, fld_geom_type=2779096485, fld_vcol_info=0x9db3710) at field.cc:9611
(gdb) list
9606 stored_in_db= TRUE;
9607
9608 /* Initialize data for a computed field */
9609 if ((uchar)fld_type == (uchar)MYSQL_TYPE_VIRTUAL)
9610 {
9611 DBUG_ASSERT(vcol_info && vcol_info->expr_item);
9612 vcol_info= fld_vcol_info;
9613 stored_in_db= vcol_info->is_stored();
9614 /*
9615 Walk through the Item tree checking if all items are valid

(gdb) print vcol_info
$1 = (Virtual_column_info *) 0xa5a5a5a5



 Comments   
Comment by Sergei Petrunia [ 2010-05-11 ]

Re: Crash when virtual column uses stored function
I can see the following "problematic" queries.
1. subquery expressions
2. references to user/system variables
3. items that evaluate differently depending on current charset, collation,
timezone, sql_mode setting, etc.

AFAIR, partitioning code solves the problem by disallowing #1 and #2, and using
some pre-defined parameters for #3 (need to check the last part).

VIEW definitions allow #1 but disallow #2. For #3, it seems that @@character_set_client and
@@collation_connection are saved together with the VIEW definition.

Comment by Hakan Küçükyılmaz (Inactive) [ 2010-06-01 ]

Re: Crash when virtual column uses stored function
Seems like this is fixed already:

mysql> delimiter //

mysql> create schema test//
Query OK, 1 row affected (0.00 sec)

mysql> use test
Database changed

mysql> create function f1(a int) returns int begin return a+1; end //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
mysql> create table tv1 (a int, b int as (f1(a)) persistent);
ERROR 1640 (HY000): Function or expression is not allowed for column 'b'.

Comment by Hakan Küçükyılmaz (Inactive) [ 2010-06-01 ]

Re: Crash when virtual column uses stored function
I tested this with the latest lp:maria code

Comment by Hakan Küçükyılmaz (Inactive) [ 2010-06-16 ]

Re: Crash when virtual column uses stored function
With lp:maria/5.2 and BUILD/compile-amd64-debug-max

we get

au0013:local hakan$ mysql -uroot test
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.2.1-MariaDB-beta-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> delimiter //
mysql> create function f1(a int) returns int begin return a+1; end //
Query OK, 0 rows affected (0.07 sec)

mysql> delimiter ;
mysql> create table tv1 (a int, b int as (f1(a)) persistent);
ERROR 1640 (HY000): Function or expression is not allowed for column 'b'.

With lp:maria/5.2 and BUILD/compile-amd64-max

we get

mysql> use test;
Database changed
mysql> delimiter //
mysql> create function f1(a int) returns int begin return a+1; end //
Query OK, 0 rows affected (0.26 sec)

mysql> delimiter ;
mysql> create table tv1 (a int, b int as (f1(a)) persistent);
ERROR 1640 (HY000): Function or expression is not allowed for column 'b'.

I tried it on Mac OS X and Ubuntu.

Comment by Hakan Küçükyılmaz (Inactive) [ 2010-06-16 ]

Re: Crash when virtual column uses stored function
Can't repeat the problem.

Comment by Oleksandr Byelkin [ 2011-06-23 ]

Re: Crash when virtual column uses stored function
I checked in it in 5.2:
mysqltest: At line 4: query 'create table tv1 (a int, b int as (f1(a)) persistent)' failed: 1642: Function or expression is not allowed for column 'b'

Comment by Rasmus Johansson (Inactive) [ 2011-06-23 ]

Launchpad bug id: 578782

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