From bfa027e72e99c2cd27df3cf3869289ddc9bff5a3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jul 2007 01:23:33 +0400 Subject: Bug#29461: Sort order of the collation wasn't used when comparing characters with the space character. When the my_strnncollsp_simple function compares two strings and one is a prefix of another then this function compares characters in the rest of longer key with the space character to find whether the longer key is greater or less. But the sort order of the collation isn't used in this comparison. This may lead to a wrong comparison result, wrongly created index or wrong order of the result set of a query with the ORDER BY clause. Now the my_strnncollsp_simple function uses collation sort order to compare the characters in the rest of longer key with the space character. mysql-test/t/ctype_collate.test: Added a test case for the bug#29461: Sort order of the collation wasn't used when comparing characters with the space character. mysql-test/r/ctype_collate.result: Added a test case for the bug#29461: Sort order of the collation wasn't used when comparing characters with the space character. strings/ctype-simple.c: Bug#29461: Sort order of the collation wasn't used when comparing characters with the space character.Now the my_strnncollsp_simple function uses collation sort order to compare the characters in the rest of longer key with the space character. --- mysql-test/r/ctype_collate.result | 8 ++++++++ mysql-test/t/ctype_collate.test | 11 +++++++++++ strings/ctype-simple.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ctype_collate.result b/mysql-test/r/ctype_collate.result index 52ee76d1948..5c9bb93103e 100644 --- a/mysql-test/r/ctype_collate.result +++ b/mysql-test/r/ctype_collate.result @@ -603,3 +603,11 @@ check table t1 extended; Table Op Msg_type Msg_text test.t1 check status OK drop table t1; +create table t1 (a varchar(2) character set latin7 collate latin7_general_ci,key(a)); +insert into t1 set a=0x4c20; +insert into t1 set a=0x6c; +insert into t1 set a=0x4c98; +check table t1 extended; +Table Op Msg_type Msg_text +test.t1 check status OK +drop table t1; diff --git a/mysql-test/t/ctype_collate.test b/mysql-test/t/ctype_collate.test index 4bbae42559a..cfef8dfe81a 100644 --- a/mysql-test/t/ctype_collate.test +++ b/mysql-test/t/ctype_collate.test @@ -218,3 +218,14 @@ insert into t1 set f1=0x3F3F1E563F; insert into t1 set f1=0x3F3F; check table t1 extended; drop table t1; + +# +# Bug#29461: Sort order of the collation wasn't used when comparing characters +# with the space character. +# +create table t1 (a varchar(2) character set latin7 collate latin7_general_ci,key(a)); +insert into t1 set a=0x4c20; +insert into t1 set a=0x6c; +insert into t1 set a=0x4c98; +check table t1 extended; +drop table t1; diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index fca5607e152..8b1b0d6790d 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -179,7 +179,7 @@ int my_strnncollsp_simple(CHARSET_INFO * cs, const uchar *a, uint a_length, } for (end= a + a_length-length; a < end ; a++) { - if (*a != ' ') + if (map[*a] != ' ') return (map[*a] < ' ') ? -swap : swap; } } -- cgit v1.2.1 From 2ad26498cfc368cfed46323e05883ee736778ca6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jul 2007 17:41:24 +0300 Subject: Bug #29070: Error in spatial index 1. Threat MBR for a key as double[] and convert it only when about to store it on disk. 2. Remove the redundant function get_double(). myisam/sp_key.c: Bug #29070: 1. threat MBR for a key as double[] and convert it only when about to store it on disk. 2. remove the redundant function get_double() mysql-test/r/gis-rtree.result: Bug #29070: test case mysql-test/t/gis-rtree.test: Bug #29070: test case --- myisam/sp_key.c | 71 ++++++++++++++++++------------------------- mysql-test/r/gis-rtree.result | 13 ++++++++ mysql-test/t/gis-rtree.test | 19 ++++++++++++ 3 files changed, 61 insertions(+), 42 deletions(-) diff --git a/myisam/sp_key.c b/myisam/sp_key.c index 34c96a219c7..e9728df4a14 100644 --- a/myisam/sp_key.c +++ b/myisam/sp_key.c @@ -31,11 +31,6 @@ static int sp_get_geometry_mbr(uchar *(*wkb), uchar *end, uint n_dims, double *mbr, int top); static int sp_mbr_from_wkb(uchar (*wkb), uint size, uint n_dims, double *mbr); -static void get_double(double *d, const byte *pos) -{ - float8get(*d, pos); -} - uint sp_make_key(register MI_INFO *info, uint keynr, uchar *key, const byte *record, my_off_t filepos) { @@ -62,48 +57,40 @@ uint sp_make_key(register MI_INFO *info, uint keynr, uchar *key, for (i = 0, keyseg = keyinfo->seg; keyseg->type; keyseg++, i++) { - uint length = keyseg->length; + uint length = keyseg->length, start= keyseg->start; + double val; + + DBUG_ASSERT(length == sizeof(double)); + DBUG_ASSERT(!(start % sizeof(double))); + DBUG_ASSERT(start < sizeof(mbr)); + DBUG_ASSERT(keyseg->type == HA_KEYTYPE_DOUBLE); - pos = ((byte*)mbr) + keyseg->start; - if (keyseg->flag & HA_SWAP_KEY) - { + val= mbr[start / sizeof (double)]; #ifdef HAVE_ISNAN - if (keyseg->type == HA_KEYTYPE_FLOAT) - { - float nr; - float4get(nr, pos); - if (isnan(nr)) - { - /* Replace NAN with zero */ - bzero(key, length); - key+= length; - continue; - } - } - else if (keyseg->type == HA_KEYTYPE_DOUBLE) - { - double nr; - get_double(&nr, pos); - if (isnan(nr)) - { - bzero(key, length); - key+= length; - continue; - } - } + if (isnan(val)) + { + bzero(key, length); + key+= length; + len+= length; + continue; + } #endif - pos += length; - while (length--) - { + + if (keyseg->flag & HA_SWAP_KEY) + { + char buf[sizeof(double)]; + + float8store(buf, val); + pos= &buf[length]; + while (pos > buf) *key++ = *--pos; - } } else { - memcpy((byte*)key, pos, length); - key += keyseg->length; + float8store((byte *)key, val); + key += length; } - len += keyseg->length; + len+= length; } _mi_dpointer(info, key, filepos); return len; @@ -141,13 +128,13 @@ static int sp_add_point_to_mbr(uchar *(*wkb), uchar *end, uint n_dims, { if ((*wkb) > end - 8) return -1; - get_double(&ord, (const byte*) *wkb); + float8get(ord, (const byte*) *wkb); (*wkb)+= 8; if (ord < *mbr) - float8store((char*) mbr, ord); + *mbr= ord; mbr++; if (ord > *mbr) - float8store((char*) mbr, ord); + *mbr= ord; mbr++; } return 0; diff --git a/mysql-test/r/gis-rtree.result b/mysql-test/r/gis-rtree.result index e4b52fc0392..8476ea9e838 100644 --- a/mysql-test/r/gis-rtree.result +++ b/mysql-test/r/gis-rtree.result @@ -1444,3 +1444,16 @@ OPTIMIZE TABLE t1; Table Op Msg_type Msg_text test.t1 optimize status OK DROP TABLE t1; +CREATE TABLE t1 (a INT, b GEOMETRY NOT NULL, SPATIAL KEY b(b)); +INSERT INTO t1 VALUES (1, GEOMFROMTEXT('LINESTRING(1102218.456 1,2000000 2)')); +INSERT INTO t1 VALUES (2, GEOMFROMTEXT('LINESTRING(1102218.456 1,2000000 2)')); +SELECT COUNT(*) FROM t1 WHERE +MBRINTERSECTS(b, GEOMFROMTEXT('LINESTRING(1 1,1102219 2)') ); +COUNT(*) +2 +SELECT COUNT(*) FROM t1 IGNORE INDEX (b) WHERE +MBRINTERSECTS(b, GEOMFROMTEXT('LINESTRING(1 1,1102219 2)') ); +COUNT(*) +2 +DROP TABLE t1; +End of 5.0 tests. diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test index 3368aea9741..74b12caca41 100644 --- a/mysql-test/t/gis-rtree.test +++ b/mysql-test/t/gis-rtree.test @@ -827,3 +827,22 @@ INSERT INTO t1 (b) SELECT b FROM t1; OPTIMIZE TABLE t1; DROP TABLE t1; + + +# +# Bug #29070: Error in spatial index +# + +CREATE TABLE t1 (a INT, b GEOMETRY NOT NULL, SPATIAL KEY b(b)); +INSERT INTO t1 VALUES (1, GEOMFROMTEXT('LINESTRING(1102218.456 1,2000000 2)')); +INSERT INTO t1 VALUES (2, GEOMFROMTEXT('LINESTRING(1102218.456 1,2000000 2)')); + +# must return the same number as the next select +SELECT COUNT(*) FROM t1 WHERE + MBRINTERSECTS(b, GEOMFROMTEXT('LINESTRING(1 1,1102219 2)') ); +SELECT COUNT(*) FROM t1 IGNORE INDEX (b) WHERE + MBRINTERSECTS(b, GEOMFROMTEXT('LINESTRING(1 1,1102219 2)') ); + +DROP TABLE t1; + +--echo End of 5.0 tests. -- cgit v1.2.1 From 21474cd11e70511b7e82170d7f00d41f0c53e5fe Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jul 2007 10:43:12 +0300 Subject: Bug #29469: Client dies if a query is issued after hitting Ctrl + C The Ctrl-C handler in mysql closes the console while ReadConsole() waits for console input. But the main thread was detecting that ReadConsole() haven't read anything and was processing as if there're data in the buffer. Fixed to handle correctly this error condition. No test case added as the test relies on Ctrl-C sent to the client from its console. client/mysql.cc: Bug #29469: handle correctly console read error mysys/my_conio.c: Bug #29469: 1. handle correctly console read error 2. add boundry checks for console buffer. --- client/mysql.cc | 7 ++++++- mysys/my_conio.c | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 368fce30d67..277b56328a6 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1086,7 +1086,12 @@ static int read_and_execute(bool interactive) something else is still in console input buffer */ } while (tmpbuf.alloced_length() <= clen); - line= buffer.c_ptr(); + /* + An empty line is returned from my_cgets when there's error reading : + Ctrl-c for example + */ + if (line) + line= buffer.c_ptr(); #else /* OS2 */ buffer.length(0); /* _cgets() expects the buffer size - 3 as the first byte */ diff --git a/mysys/my_conio.c b/mysys/my_conio.c index 23b0c55e7a9..def15674f26 100644 --- a/mysys/my_conio.c +++ b/mysys/my_conio.c @@ -184,16 +184,19 @@ char* my_cgets(char *buffer, unsigned long clen, unsigned long* plen) } while (GetLastError() == ERROR_NOT_ENOUGH_MEMORY); + /* We go here on error reading the string (Ctrl-C for example) */ + if (!*plen) + result= NULL; /* purecov: inspected */ if (result != NULL) { - if (buffer[*plen - 2] == '\r') + if (*plen > 1 && buffer[*plen - 2] == '\r') { *plen= *plen - 2; } else { - if (buffer[*plen - 1] == '\r') + if (*plen > 0 && buffer[*plen - 1] == '\r') { char tmp[3]; int tmplen= sizeof(tmp); -- cgit v1.2.1 From 3881f2a24dd531077d99b9a646c437d98e05c994 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jul 2007 12:37:47 +0300 Subject: fixed uninitialized variable introduced by the fix for bug 29325 --- myisam/mi_create.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/myisam/mi_create.c b/myisam/mi_create.c index dd8a5b0d525..75863ed976f 100644 --- a/myisam/mi_create.c +++ b/myisam/mi_create.c @@ -586,8 +586,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, 32 : 0)); linkname_ptr=0; /* Replace the current file */ - if (!(flags & HA_CREATE_KEEP_FILES)) - create_flag=MY_DELETE_OLD; + create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; } /* @@ -648,8 +647,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, { fn_format(filename,name,"",MI_NAME_DEXT,4); linkname_ptr=0; - if (!(flags & HA_CREATE_KEEP_FILES)) - create_flag=MY_DELETE_OLD; + create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; } if ((dfile= my_create_with_symlink(linkname_ptr, filename, 0, create_mode, -- cgit v1.2.1