Bug #233 Spatial index on non GIS-Data
Submitted: 5 Apr 2003 8:56 Modified: 17 Mar 2004 1:10
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.1 OS:Linux (Linux/Win XP)
Assigned to: Alexey Botchkov CPU Architecture:Any

[5 Apr 2003 8:56] Georg Richter
Description:
Strange behaviour (segfault) when adding a spatial index to a column which 
contains garbage.

There are some more segfaults, but I guess they have the same reason. (if not 
I'll report them later).

How to repeat:
mysql> create table gis_8 (a geometry not null);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into gis_8 values (GeomFromText('Point(1 2)'));
Query OK, 1 row affected (0.00 sec)

mysql> insert into gis_8 values ('Garbage');
Query OK, 1 row affected (0.00 sec)

mysql> alter table gis_8 add spatial index(a);
ERROR 2013: Lost connection to MySQL server during query
[7 Apr 2003 6:09] MySQL Verification Team
Thanks for the report.

BACK TRACE:

/usr/local/mysql/libexec/mysqld: ready for connections.
Version: '4.1.0-alpha-debug'  socket: '/tmp/mysql.sock'  port: 3306
[New Thread 2051 (LWP 4218)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 2051 (LWP 4218)]
0x0835e52b in sp_get_geometry_mbr (wkb=0xbf5fea2c, end=0x0, n_dims=2,
    mbr=0xbf5fea6c, top=1) at sp_key.c:200
200     sp_key.c: No such file or directory.
        in sp_key.c
Current language:  auto; currently c
(gdb) backtrace full
#0  0x0835e52b in sp_get_geometry_mbr (wkb=0xbf5fea2c, end=0x0,
    n_dims=2, mbr=0xbf5fea6c, top=1) at sp_key.c:200
        res = 4
        byte_order = 108 'l'
        wkb_type = 2
#1  0x0835e3a6 in sp_mbr_from_wkb (wkb=0x4 <Address 0x4 out of bounds>,
    size=4, n_dims=2, mbr=0xbf5fea6c) at sp_key.c:115
        i = 2
#2  0x0835e265 in sp_make_key (info=0x852e688, keynr=2,
    key=0x852f108 "?ð", record=0x852b6b8 "", filepos=32) at sp_key.c:50
        keyseg = (struct st_HA_KEYSEG *) 0x852bcf8
        keyinfo = (struct st_mi_keydef *) 0x852bcc0
        len = 0
        pos = (byte *) 0x852b6b8 ""
        dlen = 4
        mbr = {1.7976931348623157e+308, -1.7976931348623157e+308,
  1.7976931348623157e+308, -1.7976931348623157e+308}
#3  0x083370f2 in _mi_make_key (info=0x852e688, keynr=0,
    key=0x852f108 "?ð", record=0x852b6b8 "", filepos=32) at mi_key.c:48
        pos = (byte *) 0x852b9c0 "þþ\a\001"
        end = (byte *) 0x2 <Address 0x2 out of bounds>
        start = (uchar *) 0x1 <Address 0x1 out of bounds>
        keyseg = (struct st_HA_KEYSEG *) 0x852bcc0
---Type <return> to continue, or q <return> to quit---
        _db_func_ = 0xbf5feafc "À¼R\bÀ¹R\bdë_¿gù3\b\210æR\b"
        _db_file_ = 0xbf5feb00 "À¹R\bdë_¿gù3\b\210æR\b"
        _db_level_ = 139624984
        _db_framep_ = (char **) 0x16
#4  0x0833f967 in mi_write (info=0x852e688, record=0x852b6b8 "")
    at mi_write.c:126
        local_lock_tree = 0 '\0'
        share = (struct st_mi_isam_share *) 0x852b9c0
        i = 0
        save_errno = 139640000
        filepos = 32
        buff = (uchar *) 0x852f108 "?ð"
        lock_tree = 0 '\0'
        _db_func_ = 0xbf5feb64 "\204ë_¿,\234\031\b\210æR\b¸¶R\b\n"
        _db_file_ = 0x819b360 "\213K\004\203Ä\020\205À\017\225Â\201âÿ"
        _db_level_ = 139648648
        _db_framep_ = (char **) 0x852d7a8
#5  0x08199c2c in ha_myisam::write_row(char*) (this=0x852b620,
    buf=0x852b6b8 "") at ha_myisam.cc:264
No locals.
#6  0x081b1c50 in copy_data_between_tables (from=0x852d390,
    to=0x852aec0, create=@0x0, handle_duplicates=DUP_ERROR, order_num=0,
    order=0x0, copied=0x4, deleted=0x4) at sql_table.cc:2392
---Type <return> to continue, or q <return> to quit---
        error = 0
        copy = (class Copy_field *) 0x8528f24
        copy_end = (Copy_field *) 0x8528f6c
        found_count = 1
        delete_count = 0
        thd = (class THD *) 0x8526cd8
        length = 1074004078
        sortorder = (class st_sort_field *) 0x2
        info = {table = 0x852d390, file = 0x852d710, forms = 0xbf5fec4c,
  read_record = 0x819460e <rr_sequential>, thd = 0x8526cd8,
  select = 0x0, cache_records = 0, ref_length = 4, struct_length = 0,
  reclength = 0, rec_cache_size = 0, error_offset = 0, index = 0,
  ref_pos = 0x0, record = 0x852d7a8 "", cache = 0x0, cache_pos = 0x0,
  cache_end = 0x0, read_positions = 0x0, io_cache = 0x0,
  print_error = true, ignore_not_found_rows = false}
        next_field = (class Field *) 0x0
        tables = {next = 0x402933c0,
  db = 0x368 <Address 0x368 out of bounds>, alias = 0x40292fa0 "",
  real_name = 0x40296c90 "¤\213\021", on_expr = 0x40296c90,
  natural_join = 0x40292fa0, use_index = 0xbf5fec44,
  ignore_index = 0x401ebe74, {table = 0x402933b0,
    table_list = 0x402933b0}, derived = 0x0, grant = {
    grant_table = 0xffffffff, version = 0, privilege = 3210737148,
---Type <return> to continue, or q <return> to quit---
    want_privilege = 1076440992}, lock_type = 139636408,
  outer_join = 3210737148, shared = 861, db_length = 139636416,
  real_name_length = 3210734724, straight = 138, updating = 170,
  force_index = 54}
        fields = {<base_list> = {<Sql_alloc> = {<No data fields>},
    first = 0x84cb2c8, last = 0xbf5febec,
    elements = 0}, <No data fields>}
        all_fields = {<base_list> = {<Sql_alloc> = {<No data fields>},
    first = 0x84cb2c8, last = 0xbf5febdc,
    elements = 0}, <No data fields>}
        examined_rows = 3210734548
        _db_func_ = 0xbf5fed4c "./test/#sql-1068_1"
        _db_file_ = 0xbf5febec "ȲL\bìë_¿"
        _db_level_ = 3210734756
        _db_framep_ = (char **) 0x401ebfce
        it = {<base_list_iterator> = {list = 0xbf5fefbc, el = 0x8528ca8,
    prev = 0xbf5fefbc, current = 0x8528ca8}, <No data fields>}
        tmp_error = 3210734188
#7  0x081b103a in mysql_alter_table(THD*, char*, char*, st_ha_create_information*, st_table_list*, List<create_field>&, List<Key>&, List<Alter_drop>&, List<Alter_column>&, unsigned, st_order*, bool, enum_duplicates, enum_enable_or_disable, bool) (thd=0x8526cd8, new_db=0x8528b48 "test",
    new_name=0x8528ba0 "gis_8", create_info=0x8527178,
---Type <return> to continue, or q <return> to quit---
    table_list=0x8528bc8, fields=@0x0, keys=@0x85270a4,
    drop_list=@0x8527068, alter_list=@0x8527074, order_num=0, order=0x0,
    drop_primary=false, handle_duplicates=DUP_ERROR,
    keys_onoff=LEAVE_AS_IS, simple_alter=false) at sql_table.cc:2093
        table = (st_table *) 0x852d390
        new_table = (st_table *) 0x852aec0
        error = 0
        tmp_name = "#sql-1068_1\0?<\003", '\0' <repeats 21 times>, "¼rR\bdö_¿\0\0\0\0\022\0\0\0ØlR\b\204ö_¿\022\0\0\0ØlR\b\004÷_¿\204ö_¿\032¶\023\b"
        old_name = "\214ö_¿\004\0\0\0¤ø_¿ø¸\032\b^\002\0\0\fö_¿\020ö_¿\024ö_¿"
        new_name_buff = "\0\001\0\002\0\0\0\b\024ô_¿T\2317\bxÝR\b\003\b\0\0\024ô_¿îü\003@ØÚR\b\210ÞR\bTô_¿n\0\004@Ù\0\0\08ô_¿<ô_¿@ô_¿\0\0\0\0¨\003?\b\0\0\0\0\0\0\0\0ôÜR\b\a\0\0\0\0\0\0\0À\232\004@°3)@ /)@dô_¿^Ä\003@À3)@\0\0\0\0 /)@\220l)@\220l)@\230®R\b\204ô_¿\030Æ\036@°3)@ØlR\b´ô_¿ ®R\bØlR\b\a\0\0\0´ô_¿\016«6\b=\0\0\0 ô_¿¤ô_¿ ®R\bØlR\b\a\0\0\0"...
        table_name = 0x8528ba0 "gis_8"
        db = 0x8528b48 "test"
        index_file = "<ò_¿ìö_¿\0\0\0\0Tò_¿ðö_¿\024\0\0\0Dò_¿d", '\0' <repeats 16 times>, "ò_¿@zL\b<ò_¿\0\0\0\0\0\0\0\0ÐÆ?\bh\213R\b\005\0\0\0\230\214R\b\215\213R\b\001\0\0\0\005\0\0\0<ó_¿ÿÿÿÿ\0\0\0\0¤ó_¿ÐÆ?\bh\213R\b\005\0\0\0\215\213R\b\001\0\0\0\005\0\0\0°Ú?\bn\213R\b\005\0\0\0¨\213R\b\005\0\0---Type <return> to continue, or q <return> to quit---
\0\005\0\0\0¨\213R\b\005\0\0\0\005\0\0\0 Æ?\bz\213R\b\003\0\0\0\004\0\0\0~\213R\b\a\0\0\0\0\0\0\0~\213R\b\a\0\0\0\0\0"...
        data_file = "\214ñ_¿\0\0\0\0is_8Üð_¿Øð_¿Ôð_¿ °L\b\0\0\0.", '\0' <repeats 76 times>, "\001", '\0' <repeats 43 times>, "\214ñ_¿", '\0' <repeats 36 times>, "\001", '\0' <repeats 11 times>, "%Ó(@\0\0\0)\0\0\0\0\001\0\0\0\001\0\0\0@\214R\bA\214R\b\002\0\0\0\214õ\t@\n", '\0' <repeats 11 times>, "\001\0\0\0\0\0\0\0\0\0\020\0óæ\030@Õ\205\f\b\0\0\0\0\0\0\0\0 \0\0\0zç\030@è\225\030@(\022\030@Èõ\t@\f\0\0\0\224ø\t@\220*\001@\0241\001@\214ñ_¿Üñ_¿°r\0"...
        use_timestamp = false
        copied = 0
        deleted = 0
        next_insert_id = 0
        save_time_stamp = 0
        db_create_options = 139636416
        used_fields = 0
        old_db_type = DB_TYPE_MYISAM
        new_db_type = DB_TYPE_MYISAM
        _db_func_ = 0x65742f2e <Address 0x65742f2e out of bounds>
        _db_file_ = 0x672f7473 <Address 0x672f7473 out of bounds>
        _db_level_ = 945779561
        _db_framep_ = (char **) 0x6d726600
        drop_it = {<base_list_iterator> = {list = 0x8527068,
---Type <return> to continue, or q <return> to quit---
    el = 0x84cb2c8, prev = 0x8527068,
    current = 0x84cb2c8}, <No data fields>}
        def_it = {<base_list_iterator> = {list = 0x85270b0,
    el = 0x84cb2c8, prev = 0x85270b0,
    current = 0x84cb2c8}, <No data fields>}
        alter_it = {<base_list_iterator> = {list = 0x8527074,
    el = 0x84cb2c8, prev = 0x8527074,
    current = 0x84cb2c8}, <No data fields>}
        create_list = {<base_list> = {<Sql_alloc> = {<No data fields>},
    first = 0x8528ca8, last = 0x8528ca8, elements = 1}, <No data fields>}
        key_list = {<base_list> = {<Sql_alloc> = {<No data fields>},
    first = 0x8528cb0, last = 0x8528cb0, elements = 1}, <No data fields>}
        def = (class create_field *) 0x0
        f_ptr = (Field **) 0x852d7e4
        field = (Field *) 0x0
        find_it = {<base_list_iterator> = {list = 0xbf5fefbc,
    el = 0xbf5fefbc, prev = 0x0, current = 0x0}, <No data fields>}
        key_it = {<base_list_iterator> = {list = 0x85270a4,
    el = 0x84cb2c8, prev = 0x8528c50,
    current = 0x84cb2c8}, <No data fields>}
        field_it = {<base_list_iterator> = {list = 0xbf5fefbc,
    el = 0xbf5fefbc, prev = 0x0, current = 0x0}, <No data fields>}
        key_parts = {<base_list> = {<Sql_alloc> = {<No data fields>},
---Type <return> to continue, or q <return> to quit---
    first = 0x84cb2c8, last = 0xbf5fef4c,
    elements = 0}, <No data fields>}
        key_info = (st_key *) 0x852d708
#8  0x081394c1 in mysql_execute_command(THD*) (thd=0x8526cd8)
    at sql_parse.cc:2204
        create_info = {table_charset = 0x40d, comment = 0xbf5ff74c "",
  password = 0xbf5ff750 "`÷_\002d÷_¿\216ú\003@",
  data_file_name = 0xbf5ff754 "d÷_¿\216ú\003@",
  index_file_name = 0x17c <Address 0x17c out of bounds>,
  max_rows = 13790012544571668308, min_rows = 599696251570879726,
  auto_increment_value = 13790012661759662808,
  table_options = 1074004078, avg_row_length = 0,
  raid_chunksize = 39843680, used_fields = 3210737508, merge_list = {
    elements = 1074002574, first = 0x0, next = 0x40292fa0},
  db_type = DB_TYPE_UNKNOWN, row_type = 1074002078, options = 139645840,
  raid_type = 0, raid_chunks = 3210737556,
  merge_insert_method = 135072928, if_not_exists = 4}
        table = (st_table_list *) 0x8526cd8
        res = -1
        lex = (st_lex *) 0x8526e10
        tables = (st_table_list *) 0x8528bc8
        select_lex = (class st_select_lex *) 0x8526f04
        unit = (class st_select_lex_unit *) 0x8526e1c
---Type <return> to continue, or q <return> to quit---
        _db_func_ = 0x84cbf00 ""
        _db_file_ = 0x8528b68 "alter table gis_8 add spatial index(a)"
        _db_level_ = 3210737604
        _db_framep_ = (char **) 0x81c4c95
#9  0x0813c028 in mysql_parse(THD*, char*, unsigned) (thd=0x8526cd8,
    inBuf=0x8528b68 "alter table gis_8 add spatial index(a)",
    length=139619856) at sql_parse.cc:3362
        lex = (st_lex *) 0x8526e10
        _db_func_ = 0x8526cd8 "8\\A\b@ÇL\bDÇL\b°yR\b\bzR\b\b\202R\b\bzR\b\bzR\b\t"
        _db_file_ = 0x3 <Address 0x3 out of bounds>
        _db_level_ = 139619544
        _db_framep_ = (char **) 0xbf5ff9f4
#10 0x081371a8 in dispatch_command(enum_server_command, THD*, char*, unsigned) (command=COM_QUERY, thd=0x8526cd8,
    packet=0x8527a09 "alter table gis_8 add spatial index(a)",
    packet_length=39) at sql_parse.cc:1249
        net = (st_net *) 0x8526ce4
        error = false
        slow_command = false
        _db_func_ = 0x3f <Address 0x3f out of bounds>
        _db_file_ = 0xbf5ff948 "þì\003@\220l)@ÿÿÿÿdù_¿'"
        _db_level_ = 3210737996
---Type <return> to continue, or q <return> to quit---
        _db_framep_ = (char **) 0xbf5ff950
        start_of_query = 139619544
#11 0x08136b46 in do_command(THD*) (thd=0x8526cd8) at sql_parse.cc:1049
        packet = 0x8527a08 "\003alter table gis_8 add spatial index(a)"
        old_timeout = 30
        packet_length = 39
        net = (st_net *) 0x8526ce4
        command = COM_QUERY
        _db_func_ = 0x811b77b "\203Ä\020\213]ü\211ì]Ã\220U\211åS\203ì\020\213]\bSè<"
        _db_file_ = 0x85276dc "xÃR\b"
        _db_level_ = 4096
        _db_framep_ = (char **) 0x1000
#12 0x081361e5 in handle_one_connection (arg=0x4) at sql_parse.cc:838
        error = 2
        net = (st_net *) 0x8526ce4
        thd = (THD *) 0x8526cd8
        launch_time = 4
        set = {__val = {0 <repeats 32 times>}}
#13 0x4003b1b0 in pthread_start_thread () from /lib/libpthread.so.0
No symbol table info available.
#14 0x4003b22f in pthread_start_thread_event () from /lib/libpthread.so.0
No symbol table info available.
[27 Aug 2003 4:06] Ramil Kalimullin
The proper solution is to add NULLs support for spatial indexes.
We'll add this feature in the near future.
[10 Feb 2004 19:03] MySQL Verification Team
Tested again on 4.1.1a/5.0 (latest bk) on Linux and the bug continues the
same:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.1-alpha-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use test;
Database changed
mysql> create table gis_8 (a geometry not null);
Query OK, 0 rows affected (0.08 sec)

mysql> insert into gis_8 values (GeomFromText('Point(1 2)'));
Query OK, 1 row affected (0.00 sec)

mysql> insert into gis_8 values ('Garbage');
Query OK, 1 row affected (0.01 sec)

mysql> alter table gis_8 add spatial index(a);
ERROR 2013 (HY000): Lost connection to MySQL server during query
[17 Feb 2004 5:04] Sergei Golubchik
Crashing bug is not a "feature request" !
[13 Mar 2004 7:07] Alexey Botchkov
bk commit - 4.1 tree (hf:1.1783)
[16 Mar 2004 6:01] Alexey Botchkov
bk commit - 4.1 tree (hf:1.1795) &
bk commit - 4.1 tree (hf:1.1778)
[17 Mar 2004 1:10] 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
[15 Sep 2006 11:27] Sveta Smirnova
If one changes string

insert into gis_8 values ('Garbage');
to
insert into gis_8 values ();

he could not create index again:

mysql>  create table gis_8 (a geometry not null);
Query OK, 0 rows affected (0.06 sec)

mysql>  insert into gis_8 values (GeomFromText('Point(1 2)'));
Query OK, 1 row affected (0.00 sec)

mysql> insert into gis_8 values ();
Query OK, 1 row affected (0.00 sec)

mysql>  alter table gis_8 add spatial index(a);
ERROR 1105 (HY000): Unknown error
mysql> \q

See also bug #22372