From ce10e6ca133194632940a622fa94709a1a21a3c8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Dec 2006 15:04:26 +0200 Subject: [PATCH] Bug #23578: Corruption prevents Optimize table from working properly with a spatial index While executing OPTIMIZE TABLE on MyISAM tables the server re-creates the index file(s) in order to sort them physically by the key. This cannot be done for R-tree indexes as it makes no sense. The server was not checking the type of the index and was accessing an R-tree index as if it was a B-tree. Fixed by preventing sorting the index file if it contains an R-tree index. myisam/mi_check.c: Bug #23578: Corruption prevents Optimize table from working properly with a spatial index - disable sorting the index file if it contains an R-tree index. mysql-test/r/gis-rtree.result: Bug #23578: Corruption prevents Optimize table from working properly with a spatial index - test case mysql-test/t/gis-rtree.test: Bug #23578: Corruption prevents Optimize table from working properly with a spatial index - test case --- myisam/mi_check.c | 8 ++++++++ mysql-test/r/gis-rtree.result | 11 +++++++++++ mysql-test/t/gis-rtree.test | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/myisam/mi_check.c b/myisam/mi_check.c index 06fdd3bff4c..68e5860a6d1 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -1758,6 +1758,12 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name) MI_STATE_INFO old_state; DBUG_ENTER("mi_sort_index"); + /* cannot sort index files with R-tree indexes */ + for (key= 0,keyinfo= &share->keyinfo[0]; key < share->base.keys ; + key++,keyinfo++) + if (keyinfo->key_alg == HA_KEY_ALG_RTREE) + return 0; + if (!(param->testflag & T_SILENT)) printf("- Sorting index for MyISAM-table '%s'\n",name); @@ -1850,6 +1856,8 @@ static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, char llbuff[22]; DBUG_ENTER("sort_one_index"); + /* cannot walk over R-tree indices */ + DBUG_ASSERT(keyinfo->key_alg != HA_KEY_ALG_RTREE); new_page_pos=param->new_file_pos; param->new_file_pos+=keyinfo->block_length; diff --git a/mysql-test/r/gis-rtree.result b/mysql-test/r/gis-rtree.result index e8134a50496..05d0d5634e6 100644 --- a/mysql-test/r/gis-rtree.result +++ b/mysql-test/r/gis-rtree.result @@ -881,3 +881,14 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field INSERT INTO t1(foo) VALUES (''); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field DROP TABLE t1; +CREATE TABLE t1 (a INT AUTO_INCREMENT, b POINT NOT NULL, KEY (a), SPATIAL KEY (b)); +INSERT INTO t1 (b) VALUES (GeomFromText('POINT(1 2)')); +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +DROP TABLE t1; diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test index e34dd14dbfc..1704fe7dc80 100644 --- a/mysql-test/t/gis-rtree.test +++ b/mysql-test/t/gis-rtree.test @@ -254,3 +254,20 @@ INSERT INTO t1() VALUES (); --error 1416 INSERT INTO t1(foo) VALUES (''); DROP TABLE t1; + +# +# Bug #23578: Corruption prevents Optimize table from working properly with a +# spatial index +# + +CREATE TABLE t1 (a INT AUTO_INCREMENT, b POINT NOT NULL, KEY (a), SPATIAL KEY (b)); + +INSERT INTO t1 (b) VALUES (GeomFromText('POINT(1 2)')); +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; +INSERT INTO t1 (b) SELECT b FROM t1; + +OPTIMIZE TABLE t1; +DROP TABLE t1;