Bug #5590 Database server hangs when select from derived table is executed
Submitted: 15 Sep 2004 11:08 Modified: 26 Sep 2004 15:50
Reporter: Dmitry L Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.4gamma OS:Windows (Win2000)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[15 Sep 2004 11:08] Dmitry L
Description:
Selects from derived tables hang database server

How to repeat:
This works fine
 SELECT (SELECT a.access
           FROM objects_access a
          WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac
   FROM objects_path op
  WHERE op.id = 12 AND op.map = 0;

But this doesn't
SELECT b.sc
  FROM (SELECT (SELECT a.access
                  FROM objects_access a
                 WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac
          FROM objects_path op
         WHERE op.id = 12 AND op.map = 0) b

###################################         
Tables:

CREATE TABLE `objects_access` (
  `master` int(10) unsigned NOT NULL default '0',
  `map` smallint(6) unsigned NOT NULL default '0',
  `slave` int(10) unsigned NOT NULL default '0',
  `access` int(10) unsigned NOT NULL default '0',
  UNIQUE KEY `access_u` (`master`,`map`,`slave`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `objects_path` (
  `id` int(10) unsigned NOT NULL default '0',
  `pid` int(10) unsigned NOT NULL default '0',
  `map` smallint(6) unsigned NOT NULL default '0',
  `level` tinyint(4) unsigned NOT NULL default '0',
  `title` varchar(255) default NULL,
  PRIMARY KEY  (`id`,`pid`,`map`),
  KEY `level` (`level`),
  KEY `id` (`id`,`map`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I know this queries look strange (i.e second one), but  server goes down :(((
[16 Sep 2004 11:14] MySQL Verification Team
Verified with the latest BK 4.1 tree.

(gdb) bt
#0  0x40254a21 in kill () from /lib/libc.so.6
#1  0x40177051 in pthread_kill () from /lib/libpthread.so.0
#2  0x4017742b in raise () from /lib/libpthread.so.0
#3  0x402547b4 in raise () from /lib/libc.so.6
#4  0x40255c7d in abort () from /lib/libc.so.6
#5  0x4024ddef in __assert_fail () from /lib/libc.so.6
#6  0x08184825 in close_thread_table (thd=0x8cb6fe8, table_ptr=0x8cb804c) at sql_base.cc:429
#7  0x08184722 in close_thread_tables (thd=0x8cb6fe8, lock_in_use=false, skip_derived=false) at sql_base.cc:403
#8  0x0816a296 in dispatch_command (command=COM_QUERY, thd=0x8cb6fe8, packet=0x8cb8ab9 "", packet_length=239)
    at sql_parse.cc:1763
#9  0x081691e2 in do_command (thd=0x8cb6fe8) at sql_parse.cc:1272
#10 0x081687b7 in handle_one_connection (arg=0x8cb6fe8) at sql_parse.cc:1016
#11 0x4017414b in pthread_start_thread () from /lib/libpthread.so.0
#12 0x401741df in pthread_start_thread_event () from /lib/libpthread.so.0
#13 0x402df50a in clone () from /lib/libc.so.6
[16 Sep 2004 20:47] MySQL Verification Team
MySQL server  (v4.1.4) hangs on Windows and this query crashes MySQL server (latest BK 4.1 tree) on Linux.
[17 Sep 2004 11:01] MySQL Verification Team
test case

Attachment: test.txt (text/plain), 1.25 KiB.

[17 Sep 2004 16:10] Oleksandr Byelkin
ChangeSet 
  1.2019 04/09/17 19:08:46 bell@sanja.is.com.ua +5 -0 
  fixed error handling if creating derived table failed 
  single row subquery always can return NULL (no rows found) (BUG#5590)
[24 Sep 2004 11:58] Konstantin Osipov
OK to push (Dmitri and Konstantin reviewed this patch at the Malta conference)
[26 Sep 2004 15:50] Oleksandr Byelkin
Thank You for bugreport! bugfix is pushed in our source repository.