Bug #6643 incorrect response with partial utf8 index
Submitted: 15 Nov 2004 19:29 Modified: 19 Nov 2004 15:02
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.7 OS:Linux (linux and windows)
Assigned to: Alexander Barkov CPU Architecture:Any

[15 Nov 2004 19:29] [ name withheld ]
Description:
incorrect result on query which use of partial index in utf-8 charset with WHERE like 'xx%' query

How to repeat:
CREATE TABLE `test` (
`nom` varchar(15) character set utf8 collate utf8_swedish_ci NOT NULL default 'FR',
KEY `nom` (`nom`(2))
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `test` VALUES ('location');
INSERT INTO `test` VALUES ('loberge');
INSERT INTO `test` VALUES ('lotre');
INSERT INTO `test` VALUES ('boabab'); 

SELECT * from test where nom like *****
'l%' => 4 results OK
'lo%' => 0 results KO
'loc%' => 0 results KO
'loca%' => 1 result OK
'locat%' => 1 result OK
'locati%' => 1 result OK
[15 Nov 2004 20:28] MySQL Verification Team
Verified with 4.1.8-debug-log
[15 Nov 2004 21:53] Heikki Tuuri
Hi!

I can repeat this with 4.1.8, InnoDB, and 'lo%'. The reason the query returns an empty set is that MySQL starts the range scan with a nonsensical 4-byte start key value 'lo\t\t' where \t = 0x09.

Maybe those \t\t are garbage?

Regards,

Heikki

#0  row_search_for_mysql (buf=0x8b488d8 "location", ' ' <repeats 22 times>,
    mode=2, prebuilt=0x402caa68, match_mode=0, direction=0) at row0sel.c:2788
#1  0x08200f2a in ha_innobase::index_read(char*, char const*, unsigned, ha_rkey_
function) (this=0x8b487d0, buf=0x402cb168 "", key_ptr=0x8b57e90 "lo\t\t",
    key_len=1076670824, find_flag=HA_READ_KEY_OR_NEXT) at ha_innodb.cc:3014
#2  0x081f6b91 in handler::read_range_first(st_key_range const*, st_key_range co
nst*, bool, bool) (this=0x8b487d0, start_key=0x4e7e638c, end_key=0x4e7e637c)
    at handler.cc:1549
#3  0x081ee280 in QUICK_SELECT::get_next() (this=0x8b472a8)
    at opt_range.cc:2672
#4  0x081f1000 in rr_quick (info=0x8b46424) at records.cc:178
#5  0x081b192f in join_init_read_record (tab=0x8b46400) at sql_select.cc:6202
#6  0x081b0bda in sub_select (join=0x8b455e8, join_tab=0x8b46400,
    end_of_records=144) at sql_select.cc:5766
#7  0x081b089e in do_select (join=0x8b455e8, fields=0x8b46400, table=0x0,
    procedure=0x402cb168) at sql_select.cc:5674
#8  0x081a6113 in JOIN::exec() (this=0x8b455e8) at sql_select.cc:1463
#9  0x081a6580 in mysql_select(THD*, Item***, st_table_list*, unsigned, List<Ite
m>&, Item*, unsigned, st_order*, st_order*, Item*, st_order*, unsigned long, sel
ect_result*, st_select_lex_unit*, st_select_lex*) (thd=0x8b473b8,
    rref_pointer_array=0x8b475c8, tables=0x8b45388, wild_num=1,
    fields=@0x402cb168, conds=0x8b454f8, og_num=0, order=0x0, group=0x0,
    having=0x0, proc_param=0x0, select_options=8669696, result=0x8b455d8,
    unit=0x8b47400, select_lex=0x8b474e0) at sql_select.cc:1584
#10 0x081a283f in handle_select(THD*, st_lex*, select_result*) (thd=0x8b473b8,
    lex=0x8b473f4, result=0x8b455d8) at sql_select.cc:182
#11 0x081798e1 in mysql_execute_command(THD*) (thd=0x8b473b8)
    at sql_parse.cc:2006
#12 0x0817ed59 in mysql_parse(THD*, char*, unsigned) (thd=0x8b473b8,
    inBuf=0x8b452a0 "SELECT * from test where nom like 'lo%'",
    length=146043892) at sql_parse.cc:4063
#13 0x08178287 in dispatch_command(enum_server_command, THD*, char*, unsigned)
    (command=COM_QUERY, thd=0x8b473b8, packet=0x8b41269 "", packet_length=40)
    at sql_parse.cc:1466
#14 0x08177b93 in do_command(THD*) (thd=0x8b473b8) at sql_parse.cc:1280
#15 0x0817707b in handle_one_connection (arg=0x402cb168) at sql_parse.cc:1024
#16 0x40062f60 in pthread_start_thread () from /lib/i686/libpthread.so.0
#17 0x400630fe in pthread_start_thread_event () from /lib/i686/libpthread.so.0
#18 0x401f5327 in clone () from /lib/i686/libc.so.6
(gdb)
[19 Nov 2004 15:02] Alexander Barkov
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

Additional info:

Fixed in 4.1.8