Bug #15516 Selecting from the view causes server to crash on 2nd, 4th,6th, etc executions.
Submitted: 6 Dec 2005 10:14 Modified: 30 Dec 2005 18:05
Reporter: Nick Mahoney Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.16 OS:Windows (Windows, Linux)
Assigned to: Konstantin Osipov CPU Architecture:Any

[6 Dec 2005 10:14] Nick Mahoney
Description:
v5.0.16 Selecting from the view (see below) causes server to crash on 2nd, 4th,
6th, etc executions. 

View created from the following sql
SELECT ztblProductFamilyClass.ProductFamilyClassID,
ztblProductFamily.ProductFamilyID, tblProduct.ProductID
FROM ztblProductFamilyClass INNER JOIN ((ztblProductFamily INNER JOIN
((ztblProduct INNER JOIN tblProduct ON ztblProduct.ProductID =
tblProduct.ProductID) LEFT JOIN ztblProductInStock ON tblProduct.ProductID =
ztblProductInStock.ProductID) ON ztblProductFamily.ProductFamilyID =
ztblProduct.ProductFamilyID) INNER JOIN ztblProductFamilyToClass ON
ztblProductFamily.ProductFamilyID = ztblProductFamilyToClass.ProductFamilyID) ON
ztblProductFamilyClass.ProductFamilyClassID =
ztblProductFamilyToClass.ProdFamilyClassID
WHERE (((ztblProductFamilyClass.QCPass)<>0) AND
((ztblProductFamilyClass.ChainForSale)<>0) AND ((ztblProductFamily.QCPass)<>0)
AND ((tblProduct.IsDropShipped)<>0)) OR (((ztblProductFamilyClass.QCPass)<>0)
AND ((ztblProductFamilyClass.ChainForSale)<>0) AND
((ztblProductFamily.QCPass)<>0) AND ((tblProduct.IsDropShipped)=0) 
AND ((If(Not
IsNull(ztblProductInStock.ProductID),ztblProductInStock.QInStock-ztblProductInSt
ock.QAllocated,Null)) Is Not Null 
And  (If(Not
IsNull(ztblProductInStock.ProductID),ztblProductInStock.QInStock-ztblProductInSt
ock.QAllocated,Null))>0))
ORDER BY ztblProductFamilyClass.ProductFamilyClassID,
ztblProductFamily.ProductFamilyID, tblProduct.ProductID;

How to repeat:
See description on how to repeat
[6 Dec 2005 10:25] Valeriy Kravchuk
Thank you for a crash report. Please, send the SHOW CREATE TABLE results for all tables used to build a view. We need a complete test case to check.
[6 Dec 2005 21:20] Ryan Findley
I've been experiencing this same problem, and I've been able to simplify the conditions needed to reproduce the crash. 

Here's the query that causes the crash on even numbered executions (2, 4, 6, etc.)
SELECT * FROM c;

Here's my create table statements:
+-------+--------------------------------------------------------------------------------------------+
| Table | Create Table                                                                               |
+-------+--------------------------------------------------------------------------------------------+
| a     | CREATE TABLE `a` (
  `id` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------+  

+-------+--------------------------------------------------------------------------------------------+
| Table | Create Table                                                                               |
+-------+--------------------------------------------------------------------------------------------+
| b     | CREATE TABLE `b` (
  `id` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------+  

+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| View | Create View                                                                                                                                                        |
+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| c    | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `c` AS (select `a`.`id` AS `id` from `a`) union (select `b`.`id` AS `id` from `b`) |
+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 

You may be interested to know that the crashes also occur if I'm using MyISAM table types.

If I paste the following 4 queries into my mysql CLI, the server crashes every time:
CREATE TABLE a (id int unsigned not null);
CREATE TABLE b (id int unsigned not null);
CREATE VIEW c AS (SELECT * FROM a) UNION (SELECT * FROM b);
SELECT * FROM c;
SELECT * FROM c;

Here's the output from my error log:
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.
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.

key_buffer_size=268435456
read_buffer_size=1044480
max_used_connections=2
max_connections=100
threads_connected=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 466543 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x8974fc0
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...
Cannot determine thread, fp=0xbfe5f178, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x809e122
0x82da628
0x815c68f
0x80b6002
0x80adf03
0x80ad823
0x80acd84
0x82d7ddc
0x83016da
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/mysql/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved
stack trace is much more helpful in diagnosing the problem, so please do 
resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x89a1948 = SELECT * FROM c
thd->thread_id=211
The manual page at http://www.mysql.com/doc/en/Crashing.html contains
information that should help you find out what is causing the crash.

Number of processes running now: 0
051206 16:14:51  mysqld restarted
051206 16:14:51  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
051206 16:14:52  InnoDB: Starting log scan based on checkpoint at
InnoDB: log sequence number 11 1055075895.
InnoDB: Doing recovery: scanned up to log sequence number 11 1055075895
InnoDB: Last MySQL binlog file position 0 808412681, file name ./mysql-bin.000001
051206 16:14:52  InnoDB: Started; log sequence number 11 1055075895
051206 16:14:52 [Note] Recovering after a crash using mysql-bin
051206 16:14:52 [Note] Starting crash recovery...
051206 16:14:52 [Note] Crash recovery finished.
051206 16:14:52 [Note] /usr/local/mysql/bin/mysqld: ready for connections. 

I've reproduced this reliably on Mandrake 10.0 Kernel 2.6.3-7 on a dual core Intel P4 and on
RedHat Enterprise ES 2 on a dual processor, dual core Intel Xeon.

Thanks for your help!
[6 Dec 2005 21:26] Ryan Findley
FWIW, its possible this bug is related to <a href="http://bugs.mysql.com/bug.php?id=15396">#15396</a> and <a href="http://bugs.mysql.com/bug.php?id=15427">#15427</a>
[7 Dec 2005 8:11] Valeriy Kravchuk
Thank you for the additional information.
[9 Dec 2005 11:03] Valeriy Kravchuk
Ryan,

Thank you for a simple test case. I was able to repeat the crash on 5.0.16 on Windows:

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.0.16-nt |
+-----------+
1 row in set (0.02 sec)

mysql> CREATE TABLE a (id int unsigned not null);
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE b (id int unsigned not null);
Query OK, 0 rows affected (0.03 sec)

mysql> CREATE VIEW c AS (SELECT * FROM a) UNION (SELECT * FROM b);
Query OK, 0 rows affected (0.03 sec)

mysql> SELECT * FROM c;
Empty set (0.00 sec)

mysql> SELECT * FROM c;
ERROR 2013 (HY000): Lost connection to MySQL server during query

Please, send the resolved stack trace from your Redhat box - it may be useful for the developers. 

Because of the simpler test case, I'd mark bug #15427 as a duplicate of this one. Please, note, that next version, 5.0.17, is not affected by this bug.
[9 Dec 2005 11:06] Valeriy Kravchuk
There is no such bug in 5.0.17 and today's 5.0.18-BK (ChangeSet@1.1992, 2005-12-09 00:58:59+03:00):

mysql> CREATE TABLE a (id int unsigned not null);
CREATE TABLE b (id int unsigned not null);
CRQuery OK, 0 rows affected (0.09 sec)

Emysql> CREATE TABLE b (id int unsigned not null);
VIQuery OK, 0 rows affected (0.01 sec)
E
mysql> CREATE VIEW c AS (SELECT * FROM a) UNION (SELECT * FROM b);
SELECT * FROQuery OK, 0 rows affected (0.03 sec)

Mmysql> SELECT * FROM c;
SEEmpty set (0.01 sec)

mysql> SELECT * FROM c;
Empty set (0.00 sec)

mysql> SELECT * FROM c;
Empty set (0.00 sec)

mysql> SELECT * FROM c;
Empty set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.0.18    |
+-----------+
1 row in set (0.02 sec)

So, please, just wait for the 5.0.17 to be officially released soon.
[9 Dec 2005 14:16] Ryan Findley
Thanks for your help, I'm excited for the release of 5.0.17.

Here's that stack trace, just incase it will be useful:
ld.stack
0x809e122 handle_segfault + 430
0x82da628 pthread_sighandler + 184
0x815c68f send_result_to_client__11Query_cacheP3THDPcUi + 791
0x80b6002 mysql_parse__FP3THDPcUi + 42
0x80adf03 dispatch_command__F19enum_server_commandP3THDPcUi + 1747
0x80ad823 do_command__FP3THD + 195
0x80acd84 handle_one_connection + 764
0x82d7ddc pthread_start_thread + 220
0x83016da thread_start + 4
[30 Dec 2005 18:05] Konstantin Osipov
I can't repeat it against the latest 5.0-bk (5.0.19). The test suite just passes.
kostja@dragonfly:~> cat bar.sql  
drop table if exists a,b;
drop view if exists c;
create table a (id int unsigned not null);
create table b (id int unsigned not null);
create view c as (select * from a) union (select * from b);
select * from c;
select * from c;
kostja@dragonfly:~> mysql5 test < bar.sql
kostja@dragonfly:~>