Bug #307 InnoDB UNION with WHERE on indexed TIMESTAMP crashes everytime
Submitted: 18 Apr 2003 11:28 Modified: 21 Apr 2003 10:56
Reporter: Ronald Jeremy Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S2 (Serious)
Version:4.1 OS:Linux (Redhat Linux 8)
Assigned to: CPU Architecture:Any

[18 Apr 2003 11:28] Ronald Jeremy
Description:
The following circumstances lead to the crash:
-a UNION query
-on 2 or more InnoDB tables (MyISAM tables dont cause the crash)
-crash only occurs if an indexed TIMESTAMP is part of a WHERE and the query contains a GROUP BY
-crashing only occurs if the indexed TIMESTAMP query is after the first query of the UNION

How to repeat:
CREATE TABLE test1 (col1 int(1))TYPE=InnoDB;
CREATE TABLE test2 (col1 int(1),stamp TIMESTAMP(+0),INDEX stamp_idx (stamp))TYPE=InnoDB;
SELECT col1 FROM test1 UNION SELECT col1 FROM test2 WHERE stamp < '20020204120000' GROUP BY col1;
[18 Apr 2003 11:45] MySQL Verification Team
Works just fine here with latest 4.1.1.
[18 Apr 2003 12:25] Ronald Jeremy
Upgraded to 4.1.1 and still the same result.  Here is the crash output:

Version: '4.1.1-alpha-log'  socket: '/tmp/mysql.sock'  port: 3306
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=8388600
read_buffer_size=131072
sort_buffer_size=2097144
max_used_connections=0
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 = 225791 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x8685a88
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=0x41e1b098, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x811f3cc
0x4003447e
0x4212b274
0x814b365
0x81b414d
0x81b330b
0x8148930
0x812c788
0x8130b2d
0x812b583
0x812b1ee
0x812ab41
0x4002e941
0x420da1ca
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://www.mysql.com/doc/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 0x8696a10 = SELECT col1 FROM test1 UNION SELECT col1 FROM test2 WHERE stamp < '20020204120000' GROUP BY col1
thd->thread_id=1

Successfully dumped variables, if you ran with --log, take a look at the
details of what thread 1 did to cause the crash.  In some cases of really
bad corruption, the values shown above may be invalid.

The manual page at http://www.mysql.com/doc/C/r/Crashing.html contains
information that should help you find out what is causing the crash.
[18 Apr 2003 12:44] MySQL Verification Team
Bug is there, only it requires some data to be added.
[21 Apr 2003 10:56] MySQL Verification Team
Fixed. 

This is a patch:

===== sql/sql_select.cc 1.217 vs edited =====
*** /tmp/sql_select.cc-1.217-2560       Fri Apr  4 07:06:47 2003
--- edited/sql/sql_select.cc    Mon Apr 21 20:26:38 2003
***************
*** 1281,1289 ****
        JOIN_TAB *tab, *end;
        for (tab= join_tab, end= tab+tables ; tab != end ; tab++)
        {
!       delete tab->select;
!       delete tab->quick;
        x_free(tab->cache.buff);
        }
      }
      tmp_join->tmp_join= 0;
--- 1281,1298 ----
        JOIN_TAB *tab, *end;
        for (tab= join_tab, end= tab+tables ; tab != end ; tab++)
        {
!       if (tab->select)
!       {
!         delete tab->select;
!         tab->select=0;
!       }
!       if (tab->quick)
!       {
!         delete tab->quick;
!         tab->quick=0;
!       }
        x_free(tab->cache.buff);
+       tab->cache.buff= 0;
        }
      }
      tmp_join->tmp_join= 0;
***************
*** 3283,3290 ****
      {
        for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++)
        {
!       delete tab->select;
!       delete tab->quick;
        x_free(tab->cache.buff);
        tab->cache.buff= 0;
        if (tab->table)
--- 3292,3307 ----
      {
        for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++)
        {
!       if (tab->select)
!       {
!         delete tab->select;
!         tab->select=0;
!       }
!       if (tab->quick)
!       {
!         delete tab->quick;
!         tab->quick=0;
!       }
        x_free(tab->cache.buff);
        tab->cache.buff= 0;
        if (tab->table)