Commit ebd4b0be authored by unknown's avatar unknown

Optimize thai character handling

Remove sel000xxxx tests
After merge fixes


BitKeeper/deleted/.del-sel000033.test~3971fbe746eec069:
  Delete: mysql-test/t/sel000033.test
BitKeeper/deleted/.del-sel000033.result~56d1d02d72b94602:
  Delete: mysql-test/r/sel000033.result
BitKeeper/deleted/.del-sel000100.result~84ed46856cb3a69f:
  Delete: mysql-test/r/sel000100.result
BitKeeper/deleted/.del-sel000100.test~548501cad19a1a59:
  Delete: mysql-test/t/sel000100.test
mysql-test/r/distinct.result:
  Merge test with sel000100
mysql-test/r/grant.result:
  Update result after merge
mysql-test/r/range.result:
  After merge fix
  Merge test with sel000033
mysql-test/t/distinct.test:
  Merge test with sel000100
mysql-test/t/range.test:
  Merge test with sel000033
sql/log_event.cc:
  Remove duplicate allocation
sql/sql_select.cc:
  After merge fixes
strings/ctype-tis620.c:
  Remove usage of strnlen
  Optimize code and make it \0 safe
parent 12787aa3
...@@ -427,3 +427,40 @@ name ...@@ -427,3 +427,40 @@ name
a a
e e
drop table t1; drop table t1;
CREATE TABLE t1 (
ID int(11) NOT NULL auto_increment,
NAME varchar(75) DEFAULT '' NOT NULL,
LINK_ID int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME),
KEY LINK_ID (LINK_ID)
);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (2,'Jack',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (3,'Bill',0);
CREATE TABLE t2 (
ID int(11) NOT NULL auto_increment,
NAME varchar(150) DEFAULT '' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME)
);
SELECT DISTINCT
t2.id AS key_link_id,
t2.name AS link
FROM t1
LEFT JOIN t2 ON t1.link_id=t2.id
GROUP BY t1.id
ORDER BY link;
key_link_id link
NULL NULL
drop table t1,t2;
CREATE TABLE t1 (
html varchar(5) default NULL,
rin int(11) default '0',
out int(11) default '0'
) TYPE=MyISAM;
INSERT INTO t1 VALUES ('1',1,0);
SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
html prod
1 0.00
drop table t1;
...@@ -145,7 +145,7 @@ show grants for drop_user@localhost; ...@@ -145,7 +145,7 @@ show grants for drop_user@localhost;
Grants for drop_user@localhost Grants for drop_user@localhost
GRANT ALL PRIVILEGES ON *.* TO 'drop_user'@'localhost' WITH GRANT OPTION GRANT ALL PRIVILEGES ON *.* TO 'drop_user'@'localhost' WITH GRANT OPTION
GRANT ALL PRIVILEGES ON `test`.* TO 'drop_user'@'localhost' WITH GRANT OPTION GRANT ALL PRIVILEGES ON `test`.* TO 'drop_user'@'localhost' WITH GRANT OPTION
GRANT USAGE ON `test`.`t1` TO 'drop_user'@'localhost' GRANT SELECT (a) ON `test`.`t1` TO 'drop_user'@'localhost'
revoke all privileges, grant from drop_user@localhost; revoke all privileges, grant from drop_user@localhost;
show grants for drop_user@localhost; show grants for drop_user@localhost;
Grants for drop_user@localhost Grants for drop_user@localhost
......
...@@ -265,11 +265,24 @@ INSERT INTO t1 VALUES (0),(0),(1),(1); ...@@ -265,11 +265,24 @@ INSERT INTO t1 VALUES (0),(0),(1),(1);
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya)); CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2); INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3; explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
t2 ref j1 j1 4 const 1 Using where; Using index 1 SIMPLE t2 ref j1 j1 4 const 1 Using where; Using index
t1 ALL i1,i2 NULL NULL NULL 4 Range checked for each record (index map: 3) 1 SIMPLE t1 ALL i1,i2 NULL NULL NULL 4 Range checked for each record (index map: 3)
explain select * from t1 force index(i2), t2 where (t1.key1 <t2.keya + 1) and t2.keya=3; explain select * from t1 force index(i2), t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
t2 ref j1 j1 4 const 1 Using where; Using index 1 SIMPLE t2 ref j1 j1 4 const 1 Using where; Using index
t1 ALL i2 NULL NULL NULL 4 Range checked for each record (index map: 2) 1 SIMPLE t1 ALL i2 NULL NULL NULL 4 Range checked for each record (index map: 2)
DROP TABLE t1,t2; DROP TABLE t1,t2;
create table t1 (id int(10) primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
select id from t1 where id in (2,5,9) ;
id
2
5
9
select id from t1 where id=2 or id=5 or id=9 ;
id
2
5
9
drop table t1;
drop table if exists t1;
create table t1 (id int(10) primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
select id from t1 where id in (2,5,9) ;
id
2
5
9
select id from t1 where id=2 or id=5 or id=9 ;
id
2
5
9
drop table t1;
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (
ID int(11) NOT NULL auto_increment,
NAME varchar(75) DEFAULT '' NOT NULL,
LINK_ID int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME),
KEY LINK_ID (LINK_ID)
);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (2,'Jack',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (3,'Bill',0);
CREATE TABLE t2 (
ID int(11) NOT NULL auto_increment,
NAME varchar(150) DEFAULT '' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME)
);
SELECT DISTINCT
t2.id AS key_link_id,
t2.name AS link
FROM t1
LEFT JOIN t2 ON t1.link_id=t2.id
GROUP BY t1.id
ORDER BY link;
key_link_id link
NULL NULL
drop table t1,t2;
CREATE TABLE t1 (
html varchar(5) default NULL,
rin int(11) default '0',
out int(11) default '0'
) TYPE=MyISAM;
INSERT INTO t1 VALUES ('1',1,0);
SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
html prod
1 0.00
drop table t1;
...@@ -285,3 +285,50 @@ INSERT INTO t1 VALUES (3, 'aaaaa'); ...@@ -285,3 +285,50 @@ INSERT INTO t1 VALUES (3, 'aaaaa');
INSERT INTO t1 VALUES (2, 'eeeeeee'); INSERT INTO t1 VALUES (2, 'eeeeeee');
select distinct left(name,1) as name from t1; select distinct left(name,1) as name from t1;
drop table t1; drop table t1;
#
# Test case from sel000100
#
CREATE TABLE t1 (
ID int(11) NOT NULL auto_increment,
NAME varchar(75) DEFAULT '' NOT NULL,
LINK_ID int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME),
KEY LINK_ID (LINK_ID)
);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (2,'Jack',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (3,'Bill',0);
CREATE TABLE t2 (
ID int(11) NOT NULL auto_increment,
NAME varchar(150) DEFAULT '' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME)
);
SELECT DISTINCT
t2.id AS key_link_id,
t2.name AS link
FROM t1
LEFT JOIN t2 ON t1.link_id=t2.id
GROUP BY t1.id
ORDER BY link;
drop table t1,t2;
#
# test case for #674
#
CREATE TABLE t1 (
html varchar(5) default NULL,
rin int(11) default '0',
out int(11) default '0'
) TYPE=MyISAM;
INSERT INTO t1 VALUES ('1',1,0);
SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
drop table t1;
...@@ -217,3 +217,11 @@ explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3; ...@@ -217,3 +217,11 @@ explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
explain select * from t1 force index(i2), t2 where (t1.key1 <t2.keya + 1) and t2.keya=3; explain select * from t1 force index(i2), t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
DROP TABLE t1,t2; DROP TABLE t1,t2;
# test for a bug with in() and unique key
create table t1 (id int(10) primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
select id from t1 where id in (2,5,9) ;
select id from t1 where id=2 or id=5 or id=9 ;
drop table t1;
# sel000033
#
# Versions
# --------
# 3.22
# 3.23
#
# Description
# -----------
# test for a bug with in() and unique key
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1 (id int(10) primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
select id from t1 where id in (2,5,9) ;
select id from t1 where id=2 or id=5 or id=9 ;
drop table t1;
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
CREATE TABLE t1 (
ID int(11) NOT NULL auto_increment,
NAME varchar(75) DEFAULT '' NOT NULL,
LINK_ID int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME),
KEY LINK_ID (LINK_ID)
);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (2,'Jack',0);
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (3,'Bill',0);
CREATE TABLE t2 (
ID int(11) NOT NULL auto_increment,
NAME varchar(150) DEFAULT '' NOT NULL,
PRIMARY KEY (ID),
KEY NAME (NAME)
);
SELECT DISTINCT
t2.id AS key_link_id,
t2.name AS link
FROM t1
LEFT JOIN t2 ON t1.link_id=t2.id
GROUP BY t1.id
ORDER BY link;
drop table t1,t2;
#
# test case for #674
#
CREATE TABLE t1 (
html varchar(5) default NULL,
rin int(11) default '0',
out int(11) default '0'
) TYPE=MyISAM;
INSERT INTO t1 VALUES ('1',1,0);
SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
drop table t1;
...@@ -875,7 +875,6 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) ...@@ -875,7 +875,6 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db)
int Query_log_event::exec_event(struct st_relay_log_info* rli) int Query_log_event::exec_event(struct st_relay_log_info* rli)
{ {
int expected_error,actual_error= 0; int expected_error,actual_error= 0;
init_sql_alloc(&thd->mem_root, 8192,0);
thd->db= (char*) rewrite_db(db); thd->db= (char*) rewrite_db(db);
/* /*
...@@ -1589,7 +1588,6 @@ void Load_log_event::set_fields(List<Item> &field_list) ...@@ -1589,7 +1588,6 @@ void Load_log_event::set_fields(List<Item> &field_list)
int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
bool use_rli_only_for_errors) bool use_rli_only_for_errors)
{ {
init_sql_alloc(&thd->mem_root, 8192,0);
thd->db= (char*) rewrite_db(db); thd->db= (char*) rewrite_db(db);
DBUG_ASSERT(thd->query == 0); DBUG_ASSERT(thd->query == 0);
thd->query = 0; // Should not be needed thd->query = 0; // Should not be needed
......
...@@ -2185,9 +2185,9 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, ...@@ -2185,9 +2185,9 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM && if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM &&
!(cond_func->used_tables() & OUTER_REF_TABLE_BIT)) !(cond_func->used_tables() & OUTER_REF_TABLE_BIT))
add_key_field(key_fields,*and_level, add_key_field(key_fields,*and_level,
((Item_field*) (cond_func->key_item()->real_item()))->field, 0, ((Item_field*) (cond_func->key_item()->real_item()))->
field, 0,
cond_func->arguments()+1, cond_func->argument_count()-1, cond_func->arguments()+1, cond_func->argument_count()-1,
#endif
usable_tables); usable_tables);
break; break;
case Item_func::OPTIMIZE_OP: case Item_func::OPTIMIZE_OP:
...@@ -3356,8 +3356,11 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -3356,8 +3356,11 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
OPTION_FOUND_ROWS ? OPTION_FOUND_ROWS ?
HA_POS_ERROR : HA_POS_ERROR :
join->unit->select_limit_cnt)) < 0) join->unit->select_limit_cnt)) < 0)
{ /* before reporting "Impossible WHERE" for the whole query {
we have to check isn't it only "impossible ON" instead */ /*
Before reporting "Impossible WHERE" for the whole query
we have to check isn't it only "impossible ON" instead
*/
sel->cond=orig_cond; sel->cond=orig_cond;
if (!tab->on_expr || if (!tab->on_expr ||
sel->test_quick_select(tab->keys, sel->test_quick_select(tab->keys,
...@@ -3365,8 +3368,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -3365,8 +3368,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
(join->select_options & (join->select_options &
OPTION_FOUND_ROWS ? OPTION_FOUND_ROWS ?
HA_POS_ERROR : HA_POS_ERROR :
join->thd->select_limit)) < 0) join->unit->select_limit_cnt)) < 0)
DBUG_RETURN(1); // Impossible WHERE DBUG_RETURN(1); // Impossible WHERE
} }
else else
sel->cond=orig_cond; sel->cond=orig_cond;
......
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000-2003 MySQL AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -51,10 +51,7 @@ ...@@ -51,10 +51,7 @@
#ifdef HAVE_CHARSET_tis620 #ifdef HAVE_CHARSET_tis620
static uchar* thai2sortable(const uchar *tstr,int len);
#define BUFFER_MULTIPLY 4 #define BUFFER_MULTIPLY 4
#define buffsize(s) (BUFFER_MULTIPLY * (strlen(s) + 1))
#define M L_MIDDLE #define M L_MIDDLE
#define U L_UPPER #define U L_UPPER
#define L L_LOWER #define L L_LOWER
...@@ -451,34 +448,50 @@ uchar NEAR sort_order_tis620[]= ...@@ -451,34 +448,50 @@ uchar NEAR sort_order_tis620[]=
(uchar) '\370',(uchar) '\371',(uchar) '\372',(uchar) '\373',(uchar) '\374',(uchar) '\375',(uchar) '\376',(uchar) '\377', (uchar) '\370',(uchar) '\371',(uchar) '\372',(uchar) '\373',(uchar) '\374',(uchar) '\375',(uchar) '\376',(uchar) '\377',
}; };
/* Convert thai string to "Standard C String Function" sortable string
Arg: const source string and length of converted string
Ret: Sortable string
*/
/* /*
NOTE: isn't it faster to alloc buffer in calling function? Convert thai string to "Standard C String Function" sortable string
*/
static uchar* thai2sortable(const uchar * tstr,int len)
{
/* We use only 3 levels (neglect capitalization). */
const uchar* p= tstr; SYNOPSIS
thai2sortable()
tstr String to convert. Does not have to end with \0
len Length of tstr
out_length Will contain length of sortable string
NOTE
We use only 3 levels (neglect capitalization).
OPTIMIZE SUGGESTION
Should be faster to alloc buffer in calling function.
RETURN
Pointer to sortable string. Should be freed with 'free'
*/
static uchar *thai2sortable(const uchar *tstr, uint len, uint *out_length)
{
const uchar *p= tstr;
uchar *outBuf; uchar *outBuf;
uchar *pRight1, *pRight2, *pRight3; uchar *pRight1, *pRight2, *pRight3;
uchar *pLeft1, *pLeft2, *pLeft3; uchar *pLeft1, *pLeft2, *pLeft3;
uint bufSize; uint bufSize;
uint RightSize; uint RightSize;
len= (int) strnlen((char*) tstr,len); bufSize= (uint) (len + 1) * BUFFER_MULTIPLY;
bufSize= (uint) buffsize((char*) tstr);
RightSize= sizeof(uchar) * (len + 1); RightSize= sizeof(uchar) * (len + 1);
if (!(outBuf= pLeft1= pRight1= if (!(outBuf= pLeft1= pRight1=
(uchar *)malloc(sizeof(uchar) * bufSize + RightSize*2))) (uchar *)malloc(sizeof(uchar) * bufSize + RightSize*2)))
{
/*
Can't allocate buffer; Use original string for sorting
This is not perfect, but better than nothing...
*/
*out_length= len;
return (uchar*) tstr; return (uchar*) tstr;
}
pLeft2= pRight2= pRight1 + sizeof(uchar) * bufSize; pLeft2= pRight2= pRight1 + sizeof(uchar) * bufSize;
pLeft3= pRight3= pRight2 + RightSize; pLeft3= pRight3= pRight2 + RightSize;
while (--len > 0) while ((int) --len > 0)
{ {
int *t_ctype0= t_ctype[p[0]]; int *t_ctype0= t_ctype[p[0]];
if (isldvowel(*p) && isconsnt(p[1])) if (isldvowel(*p) && isconsnt(p[1]))
...@@ -507,17 +520,14 @@ static uchar* thai2sortable(const uchar * tstr,int len) ...@@ -507,17 +520,14 @@ static uchar* thai2sortable(const uchar * tstr,int len)
p++; p++;
} }
} }
if (!len) if (!len) /* If last was not double byte */
{ {
int *t_ctype0= t_ctype[p[0]]; int *t_ctype0= t_ctype[p[0]];
*pRight1= t_ctype0[0]; if ((*pRight1= t_ctype0[0] != IGNORE))
if (*pRight1 != IGNORE)
pRight1++; pRight1++;
*pRight2= t_ctype0[1]; if ((*pRight2= t_ctype0[1]) != IGNORE)
if (*pRight2 != IGNORE)
pRight2++; pRight2++;
*pRight3= t_ctype0[2]; if ((*pRight3= t_ctype0[2]) != IGNORE)
if (*pRight3 != IGNORE)
pRight3++; pRight3++;
} }
*pRight1++= L2_BLANK; *pRight1++= L2_BLANK;
...@@ -526,31 +536,45 @@ static uchar* thai2sortable(const uchar * tstr,int len) ...@@ -526,31 +536,45 @@ static uchar* thai2sortable(const uchar * tstr,int len)
memcpy(pRight1, pLeft2, pRight2 - pLeft2); memcpy(pRight1, pLeft2, pRight2 - pLeft2);
pRight1+= pRight2 - pLeft2; pRight1+= pRight2 - pLeft2;
memcpy(pRight1, pLeft3, pRight3 - pLeft3); memcpy(pRight1, pLeft3, pRight3 - pLeft3);
*out_length= (uint) ((pRight1+ (uint) (pRight3 - pLeft3)) - outBuf);
return outBuf; return outBuf;
} }
/* strncoll() replacement, compare 2 string, both are conveted to sortable string
Arg: 2 Strings and it compare length /*
Ret: strcmp result strncoll() replacement, compare 2 string, both are conveted to sortable
string
Arg: 2 Strings and it compare length
Ret: strcmp result
*/ */
int my_strnncoll_tis620(CHARSET_INFO *cs __attribute__((unused)), int my_strnncoll_tis620(CHARSET_INFO *cs __attribute__((unused)),
const uchar * s1, uint len1, const uchar * s1, uint len1,
const uchar * s2, uint len2) const uchar * s2, uint len2)
{ {
uchar *tc1, *tc2; uchar *tc1, *tc2;
int i; uint tc1_length, tc2_length, length;
tc1= thai2sortable(s1, len1); int res;
tc2= thai2sortable(s2, len2);
i= strcmp((char*)tc1, (char*)tc2); tc1= thai2sortable(s1, len1, &tc1_length);
free(tc1); tc2= thai2sortable(s2, len2, &tc2_length);
free(tc2); length= min(tc1_length, tc2_length);
return i;
res= memcmp((char*)tc1, (char*) tc2, length);
if (tc1 != s1)
free(tc1);
if (tc2 != s2)
free(tc2);
return (res || tc1_length == tc2_length ? res :
(tc1_length < tc2_length ? -1 : 1));
} }
static static
int my_strnncollsp_tis620(CHARSET_INFO * cs, int my_strnncollsp_tis620(CHARSET_INFO * cs,
const uchar *s, uint slen, const uchar *s, uint slen,
const uchar *t, uint tlen) const uchar *t, uint tlen)
{ {
for ( ; slen && my_isspace(cs, s[slen-1]) ; slen--); for ( ; slen && my_isspace(cs, s[slen-1]) ; slen--);
for ( ; tlen && my_isspace(cs, t[tlen-1]) ; tlen--); for ( ; tlen && my_isspace(cs, t[tlen-1]) ; tlen--);
...@@ -566,63 +590,48 @@ int my_strnxfrm_tis620(CHARSET_INFO *cs __attribute__((unused)), ...@@ -566,63 +590,48 @@ int my_strnxfrm_tis620(CHARSET_INFO *cs __attribute__((unused)),
uchar * dest, uint len, uchar * dest, uint len,
const uchar * src, uint srclen) const uchar * src, uint srclen)
{ {
uint bufSize; uint out_length;
uchar *tmp; uchar *tmp= thai2sortable(src, srclen, &out_length);
bufSize= (uint) buffsize((char*)src);
tmp= thai2sortable(src,srclen); set_if_smaller(out_length, len);
set_if_smaller(bufSize,(uint) len); memcpy(dest, tmp, out_length);
memcpy((uchar *)dest, tmp, bufSize); if (tmp != src)
free(tmp); free(tmp);
return (int)bufSize; return (int) out_length;
} }
/* strcoll replacment, compare 2 strings /* strcoll replacment, compare 2 strings
Arg: 2 strings Arg: 2 strings
Ret: strcmp result Ret: memcmp result
*/ */
int my_strcoll_tis620(const uchar * s1, const uchar * s2) int my_strcoll_tis620(const uchar * s1, const uchar * s2)
{ {
uchar *tc1, *tc2; return my_strnncoll_tis620((CHARSET_INFO *) 0, s1, strlen(s1), s2,
int i; strlen(s1));
tc1= thai2sortable(s1, (int) strlen((char*)s1));
tc2= thai2sortable(s2, (int) strlen((char*)s2));
i= strcmp((char*)tc1, (char*)tc2);
free(tc1);
free(tc2);
return i;
} }
/* strxfrm replacment, convert Thai string to sortable string
Arg: Destination buffer, String and dest buffer size
Ret: Converting string size
*/
int my_strxfrm_tis620(uchar * dest, const uchar * src, int len)
{
uint bufSize;
uchar *tmp;
bufSize= (uint)buffsize((char*) src);
tmp= thai2sortable(src, len);
memcpy((uchar *)dest, tmp, bufSize);
free(tmp);
return bufSize;
}
/* Convert SQL like string to C string /*
Arg: String, its length, escape character, resource length, minimal string and maximum string Convert SQL LIKE string to C string
Ret: Alway 0
IMPLEMENTATION
We just copy this function from opt_range.cc. No need to convert to
thai2sortable string. min_str and max_str will be use for comparison and
converted there.
RETURN VALUES
0
*/ */
/* We just copy this function from opt_range.cc. No need to convert to
thai2sortable string. min_str and max_str will be use for comparison and
converted there. */
#define max_sort_chr ((char) 255) #define max_sort_chr ((char) 255)
my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)), my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)),
const char *ptr, uint ptr_length, const char *ptr, uint ptr_length,
int escape, int w_one, int w_many, int escape, int w_one, int w_many,
uint res_length, char *min_str, char *max_str, uint res_length, char *min_str, char *max_str,
uint *min_length, uint *max_length) uint *min_length, uint *max_length)
{ {
const char *end=ptr+ptr_length; const char *end=ptr+ptr_length;
char *min_org=min_str; char *min_org=min_str;
...@@ -636,18 +645,18 @@ my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)), ...@@ -636,18 +645,18 @@ my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)),
*min_str++ = *max_str++ = *ptr; *min_str++ = *max_str++ = *ptr;
continue; continue;
} }
if (*ptr == w_one) /* '_' in SQL */ if (*ptr == w_one) /* '_' in SQL */
{ {
*min_str++='\0'; /* This should be min char */ *min_str++='\0'; /* This should be min char */
*max_str++=max_sort_chr; *max_str++=max_sort_chr;
continue; continue;
} }
if (*ptr == w_many) /* '%' in SQL */ if (*ptr == w_many) /* '%' in SQL */
{ {
*min_length= (uint) (min_str - min_org); *min_length= (uint) (min_str - min_org);
*max_length=res_length; *max_length=res_length;
do { do {
*min_str++ = ' '; /* Because if key compression */ *min_str++ = ' '; /* For key compression */
*max_str++ = max_sort_chr; *max_str++ = max_sort_chr;
} while (min_str != min_end); } while (min_str != min_end);
return 0; return 0;
...@@ -657,14 +666,18 @@ my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)), ...@@ -657,14 +666,18 @@ my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)),
*min_length= *max_length = (uint) (min_str - min_org); *min_length= *max_length = (uint) (min_str - min_org);
while (min_str != min_end) while (min_str != min_end)
*min_str++ = *max_str++ = ' '; /* Because if key compression */ *min_str++ = *max_str++ = ' '; /* For key compression */
return 0; return 0;
} }
/* Thai normalization for input sub system #ifdef NOT_NEEDED
Arg: Buffer, 's length, String, 'length
Ret: Void /*
Thai normalization for input sub system
Arg: Buffer, 's length, String, 'length
Ret: Void
*/ */
void ThNormalize(uchar* ptr, uint field_length, const uchar* from, uint length) void ThNormalize(uchar* ptr, uint field_length, const uchar* from, uint length)
{ {
const uchar* fr= from; const uchar* fr= from;
...@@ -686,6 +699,7 @@ void ThNormalize(uchar* ptr, uint field_length, const uchar* from, uint length) ...@@ -686,6 +699,7 @@ void ThNormalize(uchar* ptr, uint field_length, const uchar* from, uint length)
else else
*p++ = *fr++; *p++ = *fr++;
} }
#endif /* NOT_NEEDED */
static MY_COLLATION_HANDLER my_collation_ci_handler = static MY_COLLATION_HANDLER my_collation_ci_handler =
......
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