Bug #8776 MyISAM: Connection to server LOST while creating a spatial index on MyISAM
Submitted: 24 Feb 2005 11:55 Modified: 30 Apr 2005 13:32
Reporter: Disha Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S2 (Serious)
Version:5.0.2 OS:Any (Any)
Assigned to: Alexey Botchkov CPU Architecture:Any

[24 Feb 2005 11:55] Disha
Description:
While creating Spatial index using either 'CREATE INDEX' or 'ALTER TABLE' the MySQL Server connection is lost.

Following are the 'steps to repeat' in case of CREATE INDEX.

How to repeat:
1. Use database 'test' i.e. execute the following SQL statement:
             use test;

2. Create and Run the follwing query:

	create table tb1 (
		f1 geometry not null, 
		f2 point not null 
		) type = MyISAM;

	INSERT INTO tb1 VALUES (1,2);
	INSERT INTO tb1 VALUES (8,9);
	SELECT * FROM tb1;
	CREATE SPATIAL INDEX Index_1 ON tb1 (f1);				

Actual Results  : 
The connection to the MySQL Server is lost and the following error is displayed:	ERROR 2013 (HY000): Lost connection to MySQL server during query

Suggested fix:
The spatial index should be created without any errors.
Connection to server should not be lost.
[24 Feb 2005 13:15] Alexander Keremidarski
Disha,

Connection to server lost message  is often caused by the server crash. 
Whenever you experience this message check with error log to see if the server is crashing.

With the test case I get crash on first INSERT statement. 

CREATE SPATIAL INDEX Index_1 ON tb1 (f1);
succeeds without any problem.

CREATE TABLE `tb1` (
  `f1` geometry NOT NULL,
  `f2` point NOT NULL,
  SPATIAL KEY `Index_1` (`f1`(32))
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO tb1 VALUES (1,2);

crash with the backtrace below 5.0 from BK tree
ChangeSet@1.1892, 2005-02-23 20:22:51+03:00, gluh@gluh.mysql.r18.ru

(gdb) bt
#0  0x4ccdd0cc in memcpy () from /lib/tls/libc.so.6
#1  0x084943b5 in _mi_rec_pack (info=0x8d83eb8, to=0x672bb039 "", from=0x8d83818 "") at mi_dynrec.c:721
#2  0x08491d89 in _mi_write_blob_record (info=0x8d83eb8, record=0x8d83818 "") at mi_dynrec.c:87
#3  0x084980fd in mi_write (info=0x8d83eb8, record=0x8d83818 "") at mi_write.c:142
#4  0x0829e71c in ha_myisam::write_row(char*) (this=0x8d83730, buf=0x8d83818 "") at ha_myisam.cc:264
#5  0x0823dec7 in write_record(THD*, st_table*, st_copy_info*) (thd=0x8d58188, table=0x8d86840, info=0xb279fac0) at sql_insert.cc:856
#6  0x0823cad7 in mysql_insert(THD*, st_table_list*, List<Item>&, List<List<Item> >&, List<Item>&, List<Item>&, enum_duplicates, bool) (thd=0x8d58188, table_list=0x8d86fc0, fields=@0x8d585b8, values_list=@0x8d585dc, update_fields=@0x8d585d0, update_values=@0x8d585c4, duplic=DUP_ERROR, ignore=false) at sql_insert.cc:386
#7  0x081eb695 in mysql_execute_command(THD*) (thd=0x8d58188) at sql_parse.cc:3213
#8  0x081f1119 in mysql_parse(THD*, char*, unsigned) (thd=0x8d58188, inBuf=0x8d86f50 "INSERT INTO tb1 VALUES (1,2)", length=28) at sql_parse.cc:5173
#9  0x081e72be in dispatch_command(enum_server_command, THD*, char*, unsigned) (command=COM_QUERY, thd=0x8d58188, packet=0x8d7eef1 "INSERT INTO tb1 VALUES (1,2)", packet_length=29) at sql_parse.cc:1644
#10 0x081e6b11 in do_command(THD*) (thd=0x8d58188) at sql_parse.cc:1451
#11 0x081e5c94 in handle_one_connection (arg=0x8d58188) at sql_parse.cc:1107
#12 0x4cebb3ae in start_thread () from /lib/tls/libpthread.so.0
#13 0x4cd39b6e in clone () from /lib/tls/libc.so.6

mysql> CREATE SPATIAL INDEX Index_1 ON tb1 (f1); 
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

SHOW CREATE TABLE tb1;

CREATE TABLE `tb1` (
  `f1` geometry NOT NULL,
  `f2` point NOT NULL,
  SPATIAL KEY `Index_1` (`f1`(32))
) ENGINE=MyISAM DEFAULT CHARSET=latin1

mysql> ALTER TABLE tb1 DROP INDEX Index_1;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> SET @g = GeomFromText('POINT(1 1)');
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO tb1 VALUES(@g, @g), (@g, @g);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> SELECT AsText(f1), AsText(f2) FROM tb1;
+------------+------------+
| AsText(f1) | AsText(f2) |
+------------+------------+
| POINT(1 1) | POINT(1 1) |
| POINT(1 1) | POINT(1 1) |
+------------+------------+
2 rows in set (0.00 sec)

mysql> CREATE SPATIAL INDEX Index_1 ON tb1 (f1); Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0
[24 Feb 2005 13:15] MySQL Verification Team
Tested with 5.0.3-alpha-log. It just hangs for me after CREATE SPATIAL INDEX Index_1 ON tb1 (f1);
[14 Mar 2005 10:50] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/22985
[30 Apr 2005 13:32] Alexey Botchkov
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