Commit 95056a0b authored by unknown's avatar unknown

Fix for bug #6516 (Server crash loading spatial data)

(after discussion with SerG)


include/my_base.h:
  Handler error code added
myisam/mi_write.c:
  New error code handled
myisam/rt_index.c:
  check for zero length added
myisam/sp_key.c:
  zero length check added
mysql-test/r/gis-rtree.result:
  appropriate test result
mysql-test/t/gis-rtree.test:
  test case
sql/handler.cc:
  new error code handling added
parent 7a60d155
...@@ -291,6 +291,7 @@ enum ha_base_keytype { ...@@ -291,6 +291,7 @@ enum ha_base_keytype {
#define HA_ERR_NO_SUCH_TABLE 155 /* The table does not exist in engine */ #define HA_ERR_NO_SUCH_TABLE 155 /* The table does not exist in engine */
#define HA_ERR_TABLE_EXIST 156 /* The table existed in storage engine */ #define HA_ERR_TABLE_EXIST 156 /* The table existed in storage engine */
#define HA_ERR_NO_CONNECTION 157 /* Could not connect to storage engine */ #define HA_ERR_NO_CONNECTION 157 /* Could not connect to storage engine */
#define HA_ERR_NULL_IN_SPATIAL 158 /* NULLs are not supported in spatial index */
/* Other constants */ /* Other constants */
......
...@@ -124,8 +124,8 @@ int mi_write(MI_INFO *info, byte *record) ...@@ -124,8 +124,8 @@ int mi_write(MI_INFO *info, byte *record)
{ {
if (local_lock_tree) if (local_lock_tree)
rw_unlock(&share->key_root_lock[i]); rw_unlock(&share->key_root_lock[i]);
DBUG_PRINT("error",("Got error: %d on write",my_errno)); DBUG_PRINT("error",("Got error: %d on write",my_errno));
goto err; goto err;
} }
} }
if (local_lock_tree) if (local_lock_tree)
...@@ -159,7 +159,8 @@ int mi_write(MI_INFO *info, byte *record) ...@@ -159,7 +159,8 @@ int mi_write(MI_INFO *info, byte *record)
err: err:
save_errno=my_errno; save_errno=my_errno;
if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL) if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL ||
my_errno == HA_ERR_NULL_IN_SPATIAL)
{ {
if (info->bulk_insert) if (info->bulk_insert)
{ {
......
...@@ -710,7 +710,8 @@ static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key, ...@@ -710,7 +710,8 @@ static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key,
int rtree_insert(MI_INFO *info, uint keynr, uchar *key, uint key_length) int rtree_insert(MI_INFO *info, uint keynr, uchar *key, uint key_length)
{ {
return (rtree_insert_level(info, keynr, key, key_length, -1) == -1) ? -1 : 0; return (!key_length ||
(rtree_insert_level(info, keynr, key, key_length, -1) == -1)) ? -1 : 0;
} }
......
...@@ -50,6 +50,11 @@ uint sp_make_key(register MI_INFO *info, uint keynr, uchar *key, ...@@ -50,6 +50,11 @@ uint sp_make_key(register MI_INFO *info, uint keynr, uchar *key,
dlen = _mi_calc_blob_length(keyseg->bit_start, pos); dlen = _mi_calc_blob_length(keyseg->bit_start, pos);
memcpy_fixed(&dptr, pos + keyseg->bit_start, sizeof(char*)); memcpy_fixed(&dptr, pos + keyseg->bit_start, sizeof(char*));
if (!dptr)
{
my_errno= HA_ERR_NULL_IN_SPATIAL;
return 0;
}
sp_mbr_from_wkb(dptr + 4, dlen - 4, SPDIMS, mbr); /* SRID */ sp_mbr_from_wkb(dptr + 4, dlen - 4, SPDIMS, mbr); /* SRID */
for (i = 0, keyseg = keyinfo->seg; keyseg->type; keyseg++, i++) for (i = 0, keyseg = keyinfo->seg; keyseg->type; keyseg++, i++)
......
...@@ -798,3 +798,9 @@ INSERT INTO t1 (name, kind, line) VALUES ...@@ -798,3 +798,9 @@ INSERT INTO t1 (name, kind, line) VALUES
ALTER TABLE t1 ENABLE KEYS; ALTER TABLE t1 ENABLE KEYS;
INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)')); INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)'));
drop table t1; drop table t1;
CREATE TABLE t1 (st varchar(100));
INSERT INTO t1 VALUES ("Fake string");
CREATE TABLE t2 (geom GEOMETRY NOT NULL, SPATIAL KEY gk(geom));
INSERT INTO t2 SELECT GeomFromText(st) FROM t1;
ERROR HY000: Unknown error
drop table t1, t2;
...@@ -165,3 +165,10 @@ INSERT INTO t1 (name, kind, line) VALUES ...@@ -165,3 +165,10 @@ INSERT INTO t1 (name, kind, line) VALUES
ALTER TABLE t1 ENABLE KEYS; ALTER TABLE t1 ENABLE KEYS;
INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)')); INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)'));
drop table t1; drop table t1;
CREATE TABLE t1 (st varchar(100));
INSERT INTO t1 VALUES ("Fake string");
CREATE TABLE t2 (geom GEOMETRY NOT NULL, SPATIAL KEY gk(geom));
--error 1105
INSERT INTO t2 SELECT GeomFromText(st) FROM t1;
drop table t1, t2;
...@@ -1083,6 +1083,9 @@ void handler::print_error(int error, myf errflag) ...@@ -1083,6 +1083,9 @@ void handler::print_error(int error, myf errflag)
textno=ER_DUP_KEY; textno=ER_DUP_KEY;
break; break;
} }
case HA_ERR_NULL_IN_SPATIAL:
textno= ER_UNKNOWN_ERROR;
DBUG_VOID_RETURN;
case HA_ERR_FOUND_DUPP_UNIQUE: case HA_ERR_FOUND_DUPP_UNIQUE:
textno=ER_DUP_UNIQUE; textno=ER_DUP_UNIQUE;
break; break;
...@@ -1196,7 +1199,8 @@ uint handler::get_dup_key(int error) ...@@ -1196,7 +1199,8 @@ uint handler::get_dup_key(int error)
{ {
DBUG_ENTER("handler::get_dup_key"); DBUG_ENTER("handler::get_dup_key");
table->file->errkey = (uint) -1; table->file->errkey = (uint) -1;
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE) if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE ||
error == HA_ERR_NULL_IN_SPATIAL)
info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK); info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
DBUG_RETURN(table->file->errkey); DBUG_RETURN(table->file->errkey);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment