Bug #4407 mysql-4.1.3 assertion in ha_myisam.cc
Submitted: 5 Jul 2004 9:18 Modified: 6 Jul 2004 17:52
Reporter: Alexander Y. Fomichev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version: OS:
Assigned to: Antony Curtis CPU Architecture:Any

[5 Jul 2004 9:18] Alexander Y. Fomichev
Description:
        following assertion was gotten on my development server with latest 
        mysql-4.1.3 compiled with debug=full. 
	Initially it was compiled without debug, and i got a hang (or somethig 	 
	similar) of two of four mysqld process (mysqld_multi is used), 
        ( i.e. clients hangs at attempt to connect to this mysqld). 
        When compiled with debug and started up with --one-thread option 
        mysqld asserts: 
 
        dev mysql-4.1.3-beta # ./sql/mysqld --one-thread 
`/usr/bin/my_print_defaults 
 --config-file=/etc/my.cnf mysqld2` 040702 20:54:59  InnoDB: Started; log 
 sequence number 140 432793420 mysqld: ha_myisam.cc:1094: virtual int 
 ha_myisam::index_next(byte*): Assertion `inited==INDEX' failed. mysqld got 
 signal 6; 
        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=119537664 
        read_buffer_size=507904 
        max_used_connections=0 
        max_connections=100 
        threads_connected=0 
        It is possible that mysqld could use up to 
        key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 
 216332 K bytes of memory 
        Hope that's ok; if not, decrease some variables in the equation. 
 
 
        dev mysql-4.1.3-beta # /usr/bin/my_print_defaults 
--config-file=/etc/my.cnf 
 mysqld2 --socket=/var/lib/mysql/2/mysql.sock 
        --port=3307 
        --pid-file=/var/lib/mysql/2/dev.srv.ehouse.ru.pid 
        --datadir=/var/lib/mysql/2 
        --user=mysql 
        --skip-locking 
        --set-variable=key_buffer=114M 
        --set-variable=max_allowed_packet=4M 
        --set-variable=table_cache=512 
        --set-variable=sort_buffer=500K 
        --set-variable=read_buffer_size=500K 
        --set-variable=thread_cache=8 
        --set-variable=thread_stack=65536 
        --set-variable=tmp_table_size=4M 
        --set-variable=thread_concurrency=2 
        --set-variable=myisam_sort_buffer_size=32M 
        --max_heap_table_size=300M 
        --skip-name-resolve 
        --server-id=22 
        --log-bin=/var/log/mysql/unishop_bo 
        --binlog-do-db=unishop_bo 
        --query_cache_type=0 
        --default-character-set=cp1251 
        --ft_min_word_len=2 
        --tmpdir=/var/tmp 
        --innodb_data_home_dir=/var/lib/mysql-innodb/2 
        --innodb_log_group_home_dir=/var/lib/mysql-innodb/2 
        --innodb_log_arch_dir=/var/lib/mysql-innodb/2 
        --innodb_data_file_path=ibdata1:100M:autoextend:max:7900M 
        --set-variable=innodb_mirrored_log_groups=1 
        --set-variable=innodb_log_files_in_group=3 
        --set-variable=innodb_log_file_size=5M 
        --set-variable=innodb_log_buffer_size=8M 
        --innodb_flush_log_at_trx_commit=1 
        --innodb_log_archive=0 
        --set-variable=innodb_buffer_pool_size=26M 
        --set-variable=innodb_additional_mem_pool_size=2M 
        --set-variable=innodb_file_io_threads=4 
        --set-variable=innodb_lock_wait_timeout=90 
 
some (probably useful) info produced by mysqlbug: 
 
>Release:       mysql-4.1.3-beta (Source distribution) 
> 
>C compiler:    gcc (GCC) 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, 
> pie-8.7.6) C++ compiler:  gcc (GCC) 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, 
> ssp-3.3.2-2, pie-8.7.6) Environment: 
 
System: Linux dev.srv.ehouse.ru 2.6.7 #1 Wed Jun 16 12:11:52 MSD 2004 i686 
 Pentium III (Katmai) GenuineIntel GNU/Linux Architecture: i686 
 
Some paths:  /usr/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc 
 /usr/bin/cc GCC: Reading specs from 
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs Configured with: 
 /var/tmp/portage/gcc-3.3.3-r6/work/gcc-3.3.3/configure --prefix=/usr 
 --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3 
 --includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/include 
 --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3 
 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/man 
 --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/info --enable-shared 
 --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib 
 --enable-languages=c,c++ --enable-threads=posix --enable-long-long 
 --disable-checking --disable-libunwind-exceptions --enable-cstdio=stdio 
 --enable-version-specific-runtime-libs 
 --with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/include/g++- 
v3 --with-local-prefix=/usr/local --enable-shared --enable-nls 
 --without-included-gettext --disable-multilib --enable-__cxa_atexit 
 --enable-clocale=generic Thread model: posix 
gcc version 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6) 
Compilation info: CC='gcc'  CFLAGS='-O4 -march=pentium3 -mcpu=pentium3 
-msse 
 -pipe -D_GNU_SOURCE'  CXX='gcc'  CXXFLAGS='-O4 -march=pentium3 
 -mcpu=pentium3 -msse -pipe -felide-constructors -fno-exceptions -fno-rtti 
 -DUSE_MYSYS_NEW -D_GNU_SOURCE'  LDFLAGS=''  ASFLAGS='' LIBC: 
lrwxrwxrwx  1 root root 13 Jun 10 18:17 /lib/libc.so.6 -> libc-2.3.3.so 
-rwxr-xr-x  1 root root 1183880 Jun 10 18:17 /lib/libc-2.3.3.so 
-rw-r--r--  1 root root 2676330 Jun 10 18:17 /usr/lib/libc.a 
-rwxr-xr-x  1 root root 204 Jun 10 18:17 /usr/lib/libc.so 
-rwxr-xr-x  1 root root 580404 Nov  4  2003 /usr/lib/libc.so.5 
lrwxrwxrwx  1 root root 19 Feb 24 22:29 /usr/lib/libc-client.a -> 
 /usr/lib/c-client.a Configure command: ./configure 
 '--build=i686-pc-linux-gnu' '--prefix=/usr' 
 '--localstatedir=/var/lib/mysql/3' '--enable-assembler' 
 '--with-mysql-user=mysql' '--with-innodb' 
 '--with-unix-socket-path=/var/lib/mysql/mysql.sock' 
 '--with-extra-charsets=latin1,koi8r,cp1251,utf8' '--without-ndbcluster' 
 '--with-named-thread-libs=-lpthread' '--enable-thread-safe-client' 
 '--with-debug=full' 'CC=gcc' 'CFLAGS=-O4 -march=pentium3 -mcpu=pentium3 
 -msse -pipe -D_GNU_SOURCE' 'CXXFLAGS=-O4 -march=pentium3 
-mcpu=pentium3 
 -msse -pipe -felide-constructors -fno-exceptions -fno-rtti -DUSE_MYSYS_NEW 
 -D_GNU_SOURCE' 'CXX=gcc' 'build_alias=i686-pc-linux-gnu' 

How to repeat:
compile and run mysqld in appropriate environment
[5 Jul 2004 22:29] Antony Curtis
Hi, 
 
Are you able to provide an example of queries which can trigger the assertion 
that you reported? It would help us a lot when trying to trace this bug. 
 
I think it is possible for this bug to occur when using subqueries. 
To test this, in item_subselect.cc near line 1271, can you try the following 
patch: 
 
--- item_subselect.cc.orig	Mon Jul  5 21:26:12 2004 
+++ item_subselect.cc	Mon Jul  5 21:27:14 2004 
@@ -1268,7 +1268,8 @@ 
 subselect_uniquesubquery_engine::~subselect_uniquesubquery_engine() 
 { 
   /* Tell handler we don't need the index anymore */ 
-  tab->table->file->ha_index_end(); 
+  if (tab->table->file->inited) 
+    tab->table->file->ha_index_end(); 
 }
[6 Jul 2004 8:52] Sergey Kostyliov
Hello Antony!   
 
Unfortunately the patch you provide doesn't change anything. I believe that the   
problem itself has nothing to do with user queries and it seems for me that the bug is   
somewhere in the grant sybsystem (If I understand mysqld correctly).   
I could not provide simple `mysql test < tc.sql' but the following sequence is enough to   
reproduce this problem for me:   
1) Create fresh mysql grant db (via mysql_install_db).   
2) Load mysql grant db dump (obtained from within mysql-4.1.2):   
`bzcat bug4407.sql.bz2 | mysql --socket=/var/lib/mysq/2/mysql.sock mysql'   
3) Restart mysql:   
`mysqladmin --socket=/var/lib/mysq/2/mysql.sock shutdown   
&& /usr/local/src/mysql-4.1.3-beta/sql/mysqld `my_print_defaults mysqld2` --debug'   
InnoDB: Warning: we did not need to do crash recovery, but log scan   
InnoDB: progressed past the checkpoint lsn 144 558394761 up to lsn 144 558394808   
040706 10:24:33  InnoDB: Started; log sequence number 144 558394761   
mysqld: ha_myisam.cc:1094: virtual int ha_myisam::index_next(byte*): Assertion   
`inited==INDEX' failed.   
...   
 
Thank you!
[6 Jul 2004 9:01] Alexander Y. Fomichev
mysql grant db has been attached (see file: bug4407.sql.bz2) 
 
Thank you!
[6 Jul 2004 14:08] Antony Curtis
Problem occurs when index_read_idx() is called, followed by index_next(). index_read_idx() does not 
set inited and active_index . 
 
This occurs in GRANT_TABLE::GRANT_TABLE(TABLE *, TABLE *)
[6 Jul 2004 14:25] Antony Curtis
The following patch fixes it for me.... 
 
--- sql_acl.cc.orig     Tue Jul  6 13:22:38 2004 
+++ sql_acl.cc  Tue Jul  6 13:23:36 2004 
@@ -1790,11 +1790,13 @@ 
              col_privs->field[3]->pack_length()); 
     key_copy(key,col_privs,0,key_len); 
     col_privs->field[4]->store("",0, &my_charset_latin1); 
-    if (col_privs->file->index_read_idx(col_privs->record[0],0, 
+    col_privs->file->ha_index_init(0); 
+    if (col_privs->file->index_read(col_privs->record[0], 
                                     (byte*) col_privs->field[0]->ptr, 
                                     key_len, HA_READ_KEY_EXACT)) 
     { 
       cols = 0; /* purecov: deadcode */ 
+      col_privs->file->ha_index_end(); 
       return; 
     } 
     do 
@@ -1814,6 +1816,7 @@ 
       my_hash_insert(&hash_columns, (byte *) mem_check); 
     } while (!col_privs->file->index_next(col_privs->record[0]) && 
              !key_cmp_if_same(col_privs,key,0,key_len)); 
+    col_privs->file->ha_index_end(); 
   } 
 }
[6 Jul 2004 17:52] Antony Curtis
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html