From de82433c209d2fad6a17ff62ae91bb4cf4e86408 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jul 2007 12:04:57 +0500 Subject: [PATCH 01/34] Bug#29499 Converting 'del' from ascii to Unicode results in 'question mark' mysql-test/r/ctype_latin1.result: Adding tests mysql-test/r/ctype_ucs.result: Adding tests mysql-test/t/ctype_latin1.test: Adding tests mysql-test/t/ctype_ucs.test: Adding tests sql/share/charsets/ascii.xml: Changing mapping of 0x7F from "unassigned" to U+007F. strings/ctype-extra.c: Regenerating ctype-extra.c from new ascii.xml --- mysql-test/r/ctype_latin1.result | 4 ++++ mysql-test/r/ctype_ucs.result | 10 ++++++++++ mysql-test/t/ctype_latin1.test | 7 +++++++ mysql-test/t/ctype_ucs.test | 10 ++++++++++ sql/share/charsets/ascii.xml | 2 +- strings/ctype-extra.c | 4 ++-- 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index f8e07e1eb6f..0c0b7f81b69 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -391,3 +391,7 @@ ABC SELECT convert(@str collate latin1_swedish_ci using utf8); convert(@str collate latin1_swedish_ci using utf8) ABC €°§ß²³µ~ äöüÄÖÜ áéíóú ÀÈÌÒÙ @ abc +select hex(cast(_ascii 0x7f as char(1) character set latin1)); +hex(cast(_ascii 0x7f as char(1) character set latin1)) +7F +End of 5.0 tests diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index 0183a0c5c4b..006f4193ca1 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -886,4 +886,14 @@ collation(group_concat(a separator ',')) latin1_swedish_ci drop table t1; set names latin1; +create table t1 (s1 char(1) character set ascii, s2 char(1) character set ucs2); +insert into t1 (s1) values (0x7f); +update t1 set s2 = s1; +select hex(s2) from t1; +hex(s2) +007F +select hex(convert(s1 using latin1)) from t1; +hex(convert(s1 using latin1)) +7F +drop table t1; End of 5.0 tests diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test index dead9a7a0bc..5727603f1d3 100644 --- a/mysql-test/t/ctype_latin1.test +++ b/mysql-test/t/ctype_latin1.test @@ -110,3 +110,10 @@ SELECT convert(@str collate latin1_german2_ci using utf8); SELECT convert(@str collate latin1_swedish_ci using utf8); # End of 4.1 tests + +# +# Bug#29499 Converting 'del' from ascii to Unicode results in 'question mark' +# +select hex(cast(_ascii 0x7f as char(1) character set latin1)); + +--echo End of 5.0 tests diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index 8828cd10eec..18a18d6c632 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -612,4 +612,14 @@ select collation(group_concat(a separator ',')) from t1; drop table t1; set names latin1; +# +# Bug#29499 Converting 'del' from ascii to Unicode results in 'question mark' +# +create table t1 (s1 char(1) character set ascii, s2 char(1) character set ucs2); +insert into t1 (s1) values (0x7f); +update t1 set s2 = s1; +select hex(s2) from t1; +select hex(convert(s1 using latin1)) from t1; +drop table t1; + --echo End of 5.0 tests diff --git a/sql/share/charsets/ascii.xml b/sql/share/charsets/ascii.xml index 97006c53680..068fb84eeae 100644 --- a/sql/share/charsets/ascii.xml +++ b/sql/share/charsets/ascii.xml @@ -97,7 +97,7 @@ 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F -0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 0000 +0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 diff --git a/strings/ctype-extra.c b/strings/ctype-extra.c index 1c20828ea54..dbb53da5e17 100644 --- a/strings/ctype-extra.c +++ b/strings/ctype-extra.c @@ -922,7 +922,7 @@ uint16 to_uni_ascii_general_ci[] = { 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, -0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x0000, +0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, @@ -4603,7 +4603,7 @@ uint16 to_uni_ascii_bin[] = { 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, -0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x0000, +0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, From d64e738396f30c28c236dbac6a2f0f8a6aa14a64 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jul 2007 14:21:29 +0500 Subject: [PATCH 02/34] Bug#29484 ctype_big5 fails on 'double whopper' in mysql-5.1-new-rpl Problem: "mysqldump" doesn exists when running "mysql-test-run --embedded-server". Fix: changing test to use "SELECT INTO OUTFILE" instead of "mysqldump -T". mysql-test/r/ctype_big5.result: Fixing tests to use "SELECT INTO OUTFILE" instead of "mysqldump -T" mysql-test/t/ctype_big5.test: Fixing tests to use "SELECT INTO OUTFILE" instead of "mysqldump -T" --- mysql-test/r/ctype_big5.result | 6 ++++-- mysql-test/t/ctype_big5.test | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/ctype_big5.result b/mysql-test/r/ctype_big5.result index 3f1a87838cf..6d318a445f5 100644 --- a/mysql-test/r/ctype_big5.result +++ b/mysql-test/r/ctype_big5.result @@ -193,11 +193,13 @@ select hex(convert(_big5 0xC84041 using ucs2)); hex(convert(_big5 0xC84041 using ucs2)) 003F0041 End of 4.1 tests +set names big5; create table t1 (a blob); insert into t1 values (0xEE00); +select * into outfile 'test/t1.txt' from t1; delete from t1; -select hex(load_file('test/t1.txt')); -hex(load_file('test/t1.txt')) +select hex(load_file('MYSQLTEST_VARDIR/master-data/test/t1.txt'));; +hex(load_file('MYSQLTEST_VARDIR/master-data/test/t1.txt')) 5CEE5C300A load data infile 't1.txt' into table t1; select hex(a) from t1; diff --git a/mysql-test/t/ctype_big5.test b/mysql-test/t/ctype_big5.test index 8e17a27c550..5f3357e0406 100644 --- a/mysql-test/t/ctype_big5.test +++ b/mysql-test/t/ctype_big5.test @@ -68,15 +68,16 @@ select hex(convert(_big5 0xC84041 using ucs2)); # # Bug#26711 "binary content 0x00 sometimes becomes 0x5C 0x00 after dump/load" # +set names big5; create table t1 (a blob); insert into t1 values (0xEE00); ---exec $MYSQL_DUMP --default-character-set=big5 -T $MYSQLTEST_VARDIR/master-data/test test t1 +select * into outfile 'test/t1.txt' from t1; delete from t1; -select hex(load_file('test/t1.txt')); +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--eval select hex(load_file('$MYSQLTEST_VARDIR/master-data/test/t1.txt')); load data infile 't1.txt' into table t1; select hex(a) from t1; --exec rm $MYSQLTEST_VARDIR/master-data/test/t1.txt ---exec rm $MYSQLTEST_VARDIR/master-data/test/t1.sql drop table t1; --echo End of 5.0 tests From 89a9835b71bde662522b18f71b89e1119d4230e5 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jul 2007 14:53:08 +0500 Subject: [PATCH 03/34] Bug#29382 Collation 'utf8_test_ci' not found in tests Problem: "mysql-test-run ctype_ldml" failed in binary distributions because mysql-test/std_data/Index.xml was included into distribution. Fix: adding missing file. scripts/make_binary_distribution.sh: Adding missing file into distribution --- scripts/make_binary_distribution.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh index 77f51c51c19..eee5ed99fa5 100644 --- a/scripts/make_binary_distribution.sh +++ b/scripts/make_binary_distribution.sh @@ -295,6 +295,7 @@ $CP mysql-test/t/*.def $BASE/mysql-test/t $CP mysql-test/std_data/*.dat mysql-test/std_data/*.frm \ mysql-test/std_data/*.MYD mysql-test/std_data/*.MYI \ mysql-test/std_data/*.pem mysql-test/std_data/Moscow_leap \ + mysql-test/std_data/Index.xml \ mysql-test/std_data/des_key_file mysql-test/std_data/*.*001 \ mysql-test/std_data/*.cnf mysql-test/std_data/*.MY* \ $BASE/mysql-test/std_data From 3b1fefbf14c40feea638b210a40ad88b078fd628 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jul 2007 16:17:40 +0500 Subject: [PATCH 04/34] Bug#29333 myisam corruption with character set cp932 collate cp932_japanese_ci Problem: wrong comparison with trailing space. This problem was fixed for all other character sets under terms of bug 7788 ""Table is full" occurs during a multitable update". ctype-cp932.c was forgotten. Fix: applying the same fix for ctype-cp932.c. (see ctype-sjis.c as an example of a previously correctly fixed file) mysql-test/r/ctype_cp932.result: Adding test mysql-test/t/ctype_cp932.test: Adding test strings/ctype-cp932.c: Applying the same fix which was done for all other character sets under terms of bug 7788. strings/ctype-utf8.c: Fixing the same problem for utf8_general_cs, which was forgotten in bug 7788 as well. --- mysql-test/r/ctype_cp932.result | 16 ++++++++++++++++ mysql-test/t/ctype_cp932.test | 22 ++++++++++++++++++++++ strings/ctype-cp932.c | 14 +++++++++++--- strings/ctype-utf8.c | 29 ++++++++++++++++++----------- 4 files changed, 67 insertions(+), 14 deletions(-) diff --git a/mysql-test/r/ctype_cp932.result b/mysql-test/r/ctype_cp932.result index 6caf22645a8..e3598f00777 100755 --- a/mysql-test/r/ctype_cp932.result +++ b/mysql-test/r/ctype_cp932.result @@ -11335,6 +11335,22 @@ cp932_bin 6109 cp932_bin 61 cp932_bin 6120 drop table t1; +create table t2 (a char(1)); +insert into t2 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'); +insert into t2 values ('8'),('9'),('A'),('B'),('C'),('D'),('E'),('F'); +create table t1 ( +a varchar(2) character set cp932 +) engine=myisam; +insert into t1 +select unhex(concat(t24.a, t23.a, t22.a, t21.a)) +from t2 t21, t2 t22, t2 t23, t2 t24; +delete from t1 where a=''; +alter table t1 add key(a); +check table t1; +Table Op Msg_type Msg_text +test.t1 check status OK +drop table t1; +drop table t2; create table t1 (col1 varchar(1)) character set cp932; insert into t1 values ('a'); insert into t1 values ('ab'); diff --git a/mysql-test/t/ctype_cp932.test b/mysql-test/t/ctype_cp932.test index 48376b8e78f..633f3af0d2b 100644 --- a/mysql-test/t/ctype_cp932.test +++ b/mysql-test/t/ctype_cp932.test @@ -403,6 +403,28 @@ SET collation_connection='cp932_japanese_ci'; SET collation_connection='cp932_bin'; -- source include/ctype_filesort.inc +# +# Bug#29333 myisam corruption with +# character set cp932 collate cp932_japanese_ci +# +create table t2 (a char(1)); +insert into t2 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'); +insert into t2 values ('8'),('9'),('A'),('B'),('C'),('D'),('E'),('F'); +create table t1 ( + a varchar(2) character set cp932 +) engine=myisam; +--disable_warnings +insert into t1 +select unhex(concat(t24.a, t23.a, t22.a, t21.a)) +from t2 t21, t2 t22, t2 t23, t2 t24; +--enable_warnings +delete from t1 where a=''; +alter table t1 add key(a); +check table t1; +drop table t1; +drop table t2; + + # # Bug#12547: Inserting long string into varchar causes table crash in cp932 # diff --git a/strings/ctype-cp932.c b/strings/ctype-cp932.c index 0ece0ef1270..42325648037 100644 --- a/strings/ctype-cp932.c +++ b/strings/ctype-cp932.c @@ -250,9 +250,16 @@ static int my_strnncollsp_cp932(CHARSET_INFO *cs __attribute__((unused)), const uchar *a_end= a + a_length; const uchar *b_end= b + b_length; int res= my_strnncoll_cp932_internal(cs, &a, a_length, &b, b_length); + +#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE + diff_if_only_endspace_difference= 0; +#endif + if (!res && (a != a_end || b != b_end)) { - int swap= 0; + int swap= 1; + if (diff_if_only_endspace_difference) + res= 1; /* Assume 'a' is bigger */ /* Check the next not space character of the longer key. If it's < ' ', then it's smaller than the other key. @@ -263,11 +270,12 @@ static int my_strnncollsp_cp932(CHARSET_INFO *cs __attribute__((unused)), a_end= b_end; a= b; swap= -1; /* swap sign of result */ + res= -res; } for (; a < a_end ; a++) { - if (*a != ' ') - return ((int) *a - (int) ' ') ^ swap; + if (*a != (uchar) ' ') + return (*a < (uchar) ' ') ? -swap : swap; } } return res; diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index 387ce16a43d..4682868562f 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -2802,16 +2802,19 @@ static int my_strnncoll_utf8_cs(CHARSET_INFO *cs, static int my_strnncollsp_utf8_cs(CHARSET_INFO *cs, const uchar *s, uint slen, const uchar *t, uint tlen, - my_bool diff_if_only_endspace_difference - __attribute__((unused))) + my_bool diff_if_only_endspace_difference) { - int s_res,t_res; - my_wc_t s_wc,t_wc; - const uchar *se= s+slen; - const uchar *te= t+tlen; - int save_diff = 0; + int s_res, t_res, res; + my_wc_t s_wc, t_wc; + const uchar *se= s + slen; + const uchar *te= t + tlen; + int save_diff= 0; MY_UNICASE_INFO **uni_plane= cs->caseinfo; - + +#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE + diff_if_only_endspace_difference= 0; +#endif + while ( s < se && t < te ) { int plane; @@ -2843,16 +2846,20 @@ static int my_strnncollsp_utf8_cs(CHARSET_INFO *cs, slen= se-s; tlen= te-t; + res= 0; if (slen != tlen) { - int swap= 0; + int swap= 1; + if (diff_if_only_endspace_difference) + res= 1; /* Assume 'a' is bigger */ if (slen < tlen) { slen= tlen; s= t; se= te; swap= -1; + res= -res; } /* This following loop uses the fact that in UTF-8 @@ -2866,8 +2873,8 @@ static int my_strnncollsp_utf8_cs(CHARSET_INFO *cs, */ for ( ; s < se; s++) { - if (*s != ' ') - return ((int)*s - (int) ' ') ^ swap; + if (*s != (uchar) ' ') + return (*s < (uchar) ' ') ? -swap : swap; } } return save_diff; From 32bdbc6d853a2e1615bcae7e9bd7044a3ae934fc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Jul 2007 11:36:31 +0500 Subject: [PATCH 05/34] Printing copyright into ctype-extra.c --- strings/conf_to_src.c | 23 +++++++++++++++++++++++ strings/ctype-extra.c | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/strings/conf_to_src.c b/strings/conf_to_src.c index e2ac9846c85..75776d5e6d0 100644 --- a/strings/conf_to_src.c +++ b/strings/conf_to_src.c @@ -243,6 +243,28 @@ void dispcset(FILE *f,CHARSET_INFO *cs) } +static void +fprint_copyright(FILE *file) +{ + fprintf(file, +"/* Copyright (C) 2000-2007 MySQL AB\n" +"\n" +" This program is free software; you can redistribute it and/or modify\n" +" it under the terms of the GNU General Public License as published by\n" +" the Free Software Foundation; version 2 of the License.\n" +"\n" +" This program is distributed in the hope that it will be useful,\n" +" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +" GNU General Public License for more details.\n" +"\n" +" You should have received a copy of the GNU General Public License\n" +" along with this program; if not, write to the Free Software\n" +" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */\n" +"\n"); +} + + int main(int argc, char **argv __attribute__((unused))) { @@ -283,6 +305,7 @@ main(int argc, char **argv __attribute__((unused))) "directory:\n"); fprintf(f, " ./conf_to_src ../sql/share/charsets/ > FILE\n"); fprintf(f, "*/\n\n"); + fprint_copyright(f); fprintf(f,"#include \n"); fprintf(f,"#include \n\n"); diff --git a/strings/ctype-extra.c b/strings/ctype-extra.c index dbb53da5e17..bf45b5b5d75 100644 --- a/strings/ctype-extra.c +++ b/strings/ctype-extra.c @@ -5,7 +5,8 @@ To re-generate, run the following in the strings/ directory: ./conf_to_src ../sql/share/charsets/ > FILE */ -/* Copyright (C) 2000-2003 MySQL AB + +/* Copyright (C) 2000-2007 MySQL AB 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 From bfa027e72e99c2cd27df3cf3869289ddc9bff5a3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jul 2007 01:23:33 +0400 Subject: [PATCH 06/34] 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; } } From 2ad26498cfc368cfed46323e05883ee736778ca6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jul 2007 17:41:24 +0300 Subject: [PATCH 07/34] 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; + val= mbr[start / sizeof (double)]; +#ifdef HAVE_ISNAN + if (isnan(val)) + { + bzero(key, length); + key+= length; + len+= length; + continue; + } +#endif + if (keyseg->flag & HA_SWAP_KEY) { -#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; - } - } -#endif - pos += length; - while (length--) - { + 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. From 21474cd11e70511b7e82170d7f00d41f0c53e5fe Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jul 2007 10:43:12 +0300 Subject: [PATCH 08/34] 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); From 1abab6c7c7461bac95afd424e80b9a953fdf897b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jul 2007 10:49:54 +0300 Subject: [PATCH 09/34] Bug #29325: By default MyISAM overwrites .MYD and .MYI files no DATA DIRECTORY option is used. This can lead to two tables using the same .MYD and .MYI files (that can't be dropped). To prevent CREATE TABLE from overwriting a file a new option is introduced : keep_files_on_create When this is on the CREATE TABLE throws an error if either the .MYD or .MYI exists for a MyISAM table. The option is off by default (resulting in compatible behavior). include/my_base.h: Bug #29325: introduce keep_files_on_create myisam/mi_create.c: Bug #29325: introduce keep_files_on_create mysql-test/r/create.result: Bug #29325: test case mysql-test/t/create.test: Bug #29325: test case sql/ha_myisam.cc: Bug #29325: introduce keep_files_on_create sql/set_var.cc: Bug #29325: introduce keep_files_on_create sql/sql_class.h: Bug #29325: introduce keep_files_on_create sql/sql_table.cc: Bug #29325: introduce keep_files_on_create sql/unireg.cc: Bug #29325: introduce keep_files_on_create --- include/my_base.h | 1 + myisam/mi_create.c | 6 ++++-- mysql-test/r/create.result | 17 +++++++++++++++++ mysql-test/t/create.test | 31 +++++++++++++++++++++++++++++++ sql/ha_myisam.cc | 2 ++ sql/set_var.cc | 6 ++++++ sql/sql_class.h | 1 + sql/sql_table.cc | 2 ++ sql/unireg.cc | 2 ++ 9 files changed, 66 insertions(+), 2 deletions(-) diff --git a/include/my_base.h b/include/my_base.h index d07a4de8e6a..d8732808cee 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -279,6 +279,7 @@ enum ha_base_keytype { #define HA_PACK_RECORD 2 /* Request packed record format */ #define HA_CREATE_TMP_TABLE 4 #define HA_CREATE_CHECKSUM 8 +#define HA_CREATE_KEEP_FILES 16 /* don't overwrite .MYD and MYI */ #define HA_CREATE_DELAY_KEY_WRITE 64 /* diff --git a/myisam/mi_create.c b/myisam/mi_create.c index ea1d8c7b83e..dd8a5b0d525 100644 --- a/myisam/mi_create.c +++ b/myisam/mi_create.c @@ -586,7 +586,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, 32 : 0)); linkname_ptr=0; /* Replace the current file */ - create_flag=MY_DELETE_OLD; + if (!(flags & HA_CREATE_KEEP_FILES)) + create_flag=MY_DELETE_OLD; } /* @@ -647,7 +648,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, { fn_format(filename,name,"",MI_NAME_DEXT,4); linkname_ptr=0; - create_flag=MY_DELETE_OLD; + if (!(flags & HA_CREATE_KEEP_FILES)) + create_flag=MY_DELETE_OLD; } if ((dfile= my_create_with_symlink(linkname_ptr, filename, 0, create_mode, diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index e692dbf3938..16bc534ba92 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -1503,4 +1503,21 @@ t1 CREATE TABLE `t1` ( `c17` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +CREATE DATABASE db1; +CREATE DATABASE db2; +USE db2; +INSERT INTO db2.t1 VALUES (1); +SELECT * FROM db2.t1; +b +1 +RESET QUERY CACHE; +USE db1; +SET SESSION keep_files_on_create = TRUE; +CREATE TABLE t1 (a INT) ENGINE MYISAM; +ERROR HY000: Can't create/write to file './db1/t1.MYD' (Errcode: 17) +SET SESSION keep_files_on_create = DEFAULT; +DROP TABLE db2.t1; +DROP DATABASE db1; +DROP DATABASE db2; +USE test; End of 5.0 tests diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 99f3fea416a..610a208ebf0 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1118,5 +1118,36 @@ show create table t1; drop table t1; +# +# Bug #29325: create table overwrites .MYD file of other table (datadir) +# + +CREATE DATABASE db1; +CREATE DATABASE db2; + +USE db2; +--disable_query_log +eval CREATE TABLE t1 (b INT) ENGINE MYISAM +DATA DIRECTORY = '$MYSQLTEST_VARDIR/master-data/db1/'; +--enable_query_log + +INSERT INTO db2.t1 VALUES (1); +SELECT * FROM db2.t1; +RESET QUERY CACHE; + +USE db1; + +#no warning from create table +SET SESSION keep_files_on_create = TRUE; +--disable_abort_on_error +CREATE TABLE t1 (a INT) ENGINE MYISAM; +--enable_abort_on_error +SET SESSION keep_files_on_create = DEFAULT; + +DROP TABLE db2.t1; +DROP DATABASE db1; +DROP DATABASE db2; +USE test; + --echo End of 5.0 tests diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 5e953092436..4efa19bad78 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -1809,6 +1809,8 @@ int ha_myisam::create(const char *name, register TABLE *table_arg, if (ha_create_info->options & HA_LEX_CREATE_TMP_TABLE) create_flags|= HA_CREATE_TMP_TABLE; + if (ha_create_info->options & HA_CREATE_KEEP_FILES) + create_flags|= HA_CREATE_KEEP_FILES; if (options & HA_OPTION_PACK_RECORD) create_flags|= HA_PACK_RECORD; if (options & HA_OPTION_CHECKSUM) diff --git a/sql/set_var.cc b/sql/set_var.cc index 09cdc34f803..b30aa008366 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -592,6 +592,10 @@ sys_var_const_str sys_license("license", STRINGIFY_ARG(LICENSE)); /* Global read-only variable containing hostname */ sys_var_const_str sys_hostname("hostname", glob_hostname); +sys_var_thd_bool sys_keep_files_on_create("keep_files_on_create", + &SV::keep_files_on_create); + + /* @@ -637,6 +641,7 @@ sys_var *sys_variables[]= &sys_delayed_insert_limit, &sys_delayed_insert_timeout, &sys_delayed_queue_size, + &sys_keep_files_on_create, &sys_error_count, &sys_expire_logs_days, &sys_flush, @@ -849,6 +854,7 @@ struct show_var_st init_vars[]= { {sys_delayed_insert_timeout.name, (char*) &sys_delayed_insert_timeout, SHOW_SYS}, {sys_delayed_queue_size.name,(char*) &sys_delayed_queue_size, SHOW_SYS}, {sys_div_precincrement.name,(char*) &sys_div_precincrement,SHOW_SYS}, + {sys_keep_files_on_create.name,(char*) &sys_keep_files_on_create, SHOW_SYS}, {sys_engine_condition_pushdown.name, (char*) &sys_engine_condition_pushdown, SHOW_SYS}, {sys_expire_logs_days.name, (char*) &sys_expire_logs_days, SHOW_SYS}, diff --git a/sql/sql_class.h b/sql/sql_class.h index a5cbc21684f..112538cbe95 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -566,6 +566,7 @@ struct system_variables my_bool new_mode; my_bool query_cache_wlock_invalidate; my_bool engine_condition_pushdown; + my_bool keep_files_on_create; #ifdef HAVE_INNOBASE_DB my_bool innodb_table_locks; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 87f23097a66..e02595836ca 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2841,6 +2841,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST *src_table, and temporary tables). */ *fn_ext(dst_path)= 0; + if (thd->variables.keep_files_on_create) + create_info->options|= HA_CREATE_KEEP_FILES; err= ha_create_table(dst_path, create_info, 1); if (create_info->options & HA_LEX_CREATE_TMP_TABLE) diff --git a/sql/unireg.cc b/sql/unireg.cc index c01e6a0f00c..d8e63bb78e1 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -285,6 +285,8 @@ int rea_create_table(THD *thd, my_string file_name, if (mysql_create_frm(thd, file_name, db, table, create_info, create_fields, keys, key_info, NULL)) DBUG_RETURN(1); + if (thd->variables.keep_files_on_create) + create_info->options|= HA_CREATE_KEEP_FILES; if (!create_info->frm_only && ha_create_table(file_name,create_info,0)) { my_delete(file_name,MYF(0)); From 3881f2a24dd531077d99b9a646c437d98e05c994 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jul 2007 12:37:47 +0300 Subject: [PATCH 10/34] 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, From 2f0e00175b56af824f0946284053e5a5a30b2c82 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jul 2007 18:02:47 +0300 Subject: [PATCH 11/34] Addendum to bug 29325: test if TRUNCATE TABLE works with keep_files_on_create --- mysql-test/r/create.result | 7 ++++++- mysql-test/t/create.test | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 16bc534ba92..ff963892bc9 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -1515,8 +1515,13 @@ USE db1; SET SESSION keep_files_on_create = TRUE; CREATE TABLE t1 (a INT) ENGINE MYISAM; ERROR HY000: Can't create/write to file './db1/t1.MYD' (Errcode: 17) +CREATE TABLE t3 (a INT) Engine=MyISAM; +INSERT INTO t3 VALUES (1),(2),(3); +TRUNCATE TABLE t3; +SELECT * from t3; +a SET SESSION keep_files_on_create = DEFAULT; -DROP TABLE db2.t1; +DROP TABLE db2.t1, db1.t3; DROP DATABASE db1; DROP DATABASE db2; USE test; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 610a208ebf0..a1d3d488f1c 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1142,9 +1142,15 @@ SET SESSION keep_files_on_create = TRUE; --disable_abort_on_error CREATE TABLE t1 (a INT) ENGINE MYISAM; --enable_abort_on_error + +CREATE TABLE t3 (a INT) Engine=MyISAM; +INSERT INTO t3 VALUES (1),(2),(3); +TRUNCATE TABLE t3; +SELECT * from t3; + SET SESSION keep_files_on_create = DEFAULT; -DROP TABLE db2.t1; +DROP TABLE db2.t1, db1.t3; DROP DATABASE db1; DROP DATABASE db2; USE test; From 0920c75b5efa164253c546f88e30b9b4fe686e6b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jul 2007 00:03:08 +0500 Subject: [PATCH 12/34] Fixed bug #29360. The special `zero' enum value was coerced to the normal empty string enum value during a field-to-field copy. This bug affected CREATE ... SELECT statements and SELECT aggregate GROUP BY enum field statements. Also this bug made unnecessary warnings during the execution of CREATE ... SELECT statements: Warning 1265 Data truncated for column... sql/field_conv.cc: Fixed bug #29360. The field_conv function has been modified to properly convert the special `zero' enum value between enum fields. mysql-test/t/type_enum.test: Updated test case for bug #29360. mysql-test/r/type_enum.result: Updated test case for bug #29360. mysql-test/r/type_ranges.result: Updated test case for bug #29360. --- mysql-test/r/type_enum.result | 20 ++++++++++++++++++++ mysql-test/r/type_ranges.result | 4 ---- mysql-test/t/type_enum.test | 18 ++++++++++++++++++ sql/field_conv.cc | 16 +++++++++++----- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result index f537b7140ba..ca516f027ba 100644 --- a/mysql-test/r/type_enum.result +++ b/mysql-test/r/type_enum.result @@ -1809,3 +1809,23 @@ f1 drop table t1; +CREATE TABLE t1 (c1 ENUM('a', '', 'b')); +INSERT INTO t1 (c1) VALUES ('b'); +INSERT INTO t1 (c1) VALUES (''); +INSERT INTO t1 (c1) VALUES (0); +Warnings: +Warning 1265 Data truncated for column 'c1' at row 1 +INSERT INTO t1 (c1) VALUES (''); +SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1; +c1 + 0 COUNT(c1) +0 1 +2 2 +3 1 +CREATE TABLE t2 SELECT * FROM t1; +SELECT c1 + 0 FROM t2; +c1 + 0 +3 +2 +0 +2 +DROP TABLE t1,t2; diff --git a/mysql-test/r/type_ranges.result b/mysql-test/r/type_ranges.result index e949d734944..5c2d3b84d89 100644 --- a/mysql-test/r/type_ranges.result +++ b/mysql-test/r/type_ranges.result @@ -208,10 +208,6 @@ options flags one one drop table t2; create table t2 select * from t1; -Warnings: -Warning 1265 Data truncated for column 'options' at row 4 -Warning 1265 Data truncated for column 'options' at row 5 -Warning 1265 Data truncated for column 'options' at row 6 update t2 set string="changed" where auto=16; show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test index ecc945a3157..fbba38f926d 100644 --- a/mysql-test/t/type_enum.test +++ b/mysql-test/t/type_enum.test @@ -182,3 +182,21 @@ create table t1(f1 set('a','b'), index(f1)); insert into t1 values(''),(''),('a'),('b'); select * from t1 where f1=''; drop table t1; + +# +# Bug#29360: Confluence of the special 0 enum value with the normal empty string +# value during field to field copy. +# + +CREATE TABLE t1 (c1 ENUM('a', '', 'b')); +INSERT INTO t1 (c1) VALUES ('b'); +INSERT INTO t1 (c1) VALUES (''); +INSERT INTO t1 (c1) VALUES (0); +INSERT INTO t1 (c1) VALUES (''); + +SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1; + +CREATE TABLE t2 SELECT * FROM t1; +SELECT c1 + 0 FROM t2; + +DROP TABLE t1,t2; diff --git a/sql/field_conv.cc b/sql/field_conv.cc index a286255ec23..2df65b62de6 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -790,11 +790,17 @@ int field_conv(Field *to,Field *from) blob->value.copy(); return blob->store(blob->value.ptr(),blob->value.length(),from->charset()); } - if ((from->result_type() == STRING_RESULT && - (to->result_type() == STRING_RESULT || - (from->real_type() != FIELD_TYPE_ENUM && - from->real_type() != FIELD_TYPE_SET))) || - to->type() == FIELD_TYPE_DECIMAL) + if (from->real_type() == FIELD_TYPE_ENUM && + to->real_type() == FIELD_TYPE_ENUM && + from->val_int() == 0) + { + ((Field_enum *)(to))->store_type(0); + } + else if ((from->result_type() == STRING_RESULT && + (to->result_type() == STRING_RESULT || + (from->real_type() != FIELD_TYPE_ENUM && + from->real_type() != FIELD_TYPE_SET))) || + to->type() == FIELD_TYPE_DECIMAL) { char buff[MAX_FIELD_WIDTH]; String result(buff,sizeof(buff),from->charset()); From 25e28d4d28e7052d31079a9c8b6f65e4e94041ca Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jul 2007 23:18:02 +0400 Subject: [PATCH 13/34] Bug#29555: Comparing time values as strings may lead to a wrong result. Time values were compared as strings. This led to a wrong comparison result when comparing values one of which is under 100 hours and another is over 100 hours. Now when the Arg_comparator::set_cmp_func function sees that both items to compare are of the TIME type it sets the comparator to the Arg_comparator::compare_e_int or the Arg_comparator::compare_int_unsigned functions. sql/item_cmpfunc.cc: Bug#29555: Comparing time values as strings may lead to a wrong result. Now when the Arg_comparator::set_cmp_func function sees that both items to compare are of the TIME type it sets the comparator to the Arg_comparator::compare_e_int or the Arg_comparator::compare_int_unsigned functions. mysql-test/r/type_time.result: Added a test case for the bug#29555: Comparing time values as strings may lead to a wrong result. mysql-test/t/type_time.test: Added a test case for the bug#29555: Comparing time values as strings may lead to a wrong result. --- mysql-test/r/type_time.result | 18 ++++++++++++++++++ mysql-test/t/type_time.test | 10 ++++++++++ sql/item_cmpfunc.cc | 12 ++++++++++++ 3 files changed, 40 insertions(+) diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index 442435b0459..6124f6e39f1 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -85,3 +85,21 @@ sec_to_time(time_to_sec(t)) 13:00:00 09:00:00 drop table t1; +select cast('100:55:50' as time) < cast('24:00:00' as time); +cast('100:55:50' as time) < cast('24:00:00' as time) +0 +select cast('100:55:50' as time) < cast('024:00:00' as time); +cast('100:55:50' as time) < cast('024:00:00' as time) +0 +select cast('300:55:50' as time) < cast('240:00:00' as time); +cast('300:55:50' as time) < cast('240:00:00' as time) +0 +select cast('100:55:50' as time) > cast('24:00:00' as time); +cast('100:55:50' as time) > cast('24:00:00' as time) +1 +select cast('100:55:50' as time) > cast('024:00:00' as time); +cast('100:55:50' as time) > cast('024:00:00' as time) +1 +select cast('300:55:50' as time) > cast('240:00:00' as time); +cast('300:55:50' as time) > cast('240:00:00' as time) +1 diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index cb7e4f85ad1..d294e53a12f 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -40,3 +40,13 @@ drop table t1; # ########################################################## # End of 4.1 tests + +# +# Bug#29555: Comparing time values as strings may lead to a wrong result. +# +select cast('100:55:50' as time) < cast('24:00:00' as time); +select cast('100:55:50' as time) < cast('024:00:00' as time); +select cast('300:55:50' as time) < cast('240:00:00' as time); +select cast('100:55:50' as time) > cast('24:00:00' as time); +select cast('100:55:50' as time) > cast('024:00:00' as time); +select cast('300:55:50' as time) > cast('240:00:00' as time); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ed0c09f0b32..70df1b4d09c 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -706,6 +706,18 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg, func= &Arg_comparator::compare_datetime; return 0; } + else if (type == STRING_RESULT && (*a)->field_type() == MYSQL_TYPE_TIME && + (*b)->field_type() == MYSQL_TYPE_TIME) + { + /* Compare TIME values as integers. */ + thd= current_thd; + owner= owner_arg; + func= ((test(owner && owner->functype() == Item_func::EQUAL_FUNC)) ? + &Arg_comparator::compare_e_int : + &Arg_comparator::compare_int_unsigned); + return 0; + } + return set_compare_func(owner_arg, type); } From b6e01cbba30f2e951b5dcae1be65fc79c58ab088 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jul 2007 00:55:40 +0500 Subject: [PATCH 14/34] field_conv.cc: Additional fix for bug #29360. sql/field_conv.cc: Additional fix for bug #29360. --- sql/field_conv.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 2df65b62de6..2705d4f617b 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -795,6 +795,7 @@ int field_conv(Field *to,Field *from) from->val_int() == 0) { ((Field_enum *)(to))->store_type(0); + return 0; } else if ((from->result_type() == STRING_RESULT && (to->result_type() == STRING_RESULT || From b1e55680437cefcfa087fd7531c0d351da87306e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jul 2007 18:45:35 -0700 Subject: [PATCH 15/34] Fixed bug #29604. A bug in the restore_prev_nj_state function allowed interleaving inner tables of outer join operations with outer tables. With the current implementation of the nested loops algorithm it could lead to wrong result sets for queries with nested outer joins. Another bug in this procedure effectively blocked evaluation of some valid execution plans for queries with nested outer joins. mysql-test/r/join_nested.result: Added a test case for bug #29604. mysql-test/t/join_nested.test: Added a test case for bug #29604. --- mysql-test/r/join_nested.result | 111 +++++++++++++++++++++++++++++++ mysql-test/t/join_nested.test | 114 ++++++++++++++++++++++++++++++++ sql/sql_select.cc | 10 ++- 3 files changed, 233 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/join_nested.result b/mysql-test/r/join_nested.result index 006488f9d43..daf63579e9c 100644 --- a/mysql-test/r/join_nested.result +++ b/mysql-test/r/join_nested.result @@ -1632,4 +1632,115 @@ INSERT INTO t3 VALUES (1,1); SELECT * FROM t1 JOIN (t2 JOIN t3 USING (b)) USING (a); ERROR 23000: Column 'a' in from clause is ambiguous DROP TABLE t1,t2,t3; +CREATE TABLE t1 ( +carrier char(2) default NULL, +id int NOT NULL auto_increment PRIMARY KEY +); +INSERT INTO t1 VALUES +('CO',235371754),('CO',235376554),('CO',235376884),('CO',235377874), +('CO',231060394),('CO',231059224),('CO',231059314),('CO',231060484), +('CO',231060274),('CO',231060124),('CO',231060244),('CO',231058594), +('CO',231058924),('CO',231058504),('CO',231059344),('CO',231060424), +('CO',231059554),('CO',231060304),('CO',231059644),('CO',231059464), +('CO',231059764),('CO',231058294),('CO',231058624),('CO',231058864), +('CO',231059374),('CO',231059584),('CO',231059734),('CO',231059014), +('CO',231059854),('CO',231059494),('CO',231059794),('CO',231058534), +('CO',231058324),('CO',231058684),('CO',231059524),('CO',231059974); +CREATE TABLE t2 ( +scan_date date default NULL, +package_id int default NULL, +INDEX scan_date(scan_date), +INDEX package_id(package_id) +); +INSERT INTO t2 VALUES +('2008-12-29',231062944),('2008-12-29',231065764),('2008-12-29',231066124), +('2008-12-29',231060094),('2008-12-29',231061054),('2008-12-29',231065644), +('2008-12-29',231064384),('2008-12-29',231064444),('2008-12-29',231073774), +('2008-12-29',231058594),('2008-12-29',231059374),('2008-12-29',231066004), +('2008-12-29',231068494),('2008-12-29',231070174),('2008-12-29',231071884), +('2008-12-29',231063274),('2008-12-29',231063754),('2008-12-29',231064144), +('2008-12-29',231069424),('2008-12-29',231073714),('2008-12-29',231058414), +('2008-12-29',231060994),('2008-12-29',231069154),('2008-12-29',231068614), +('2008-12-29',231071464),('2008-12-29',231074014),('2008-12-29',231059614), +('2008-12-29',231059074),('2008-12-29',231059464),('2008-12-29',231069094), +('2008-12-29',231067294),('2008-12-29',231070144),('2008-12-29',231073804), +('2008-12-29',231072634),('2008-12-29',231058294),('2008-12-29',231065344), +('2008-12-29',231066094),('2008-12-29',231069034),('2008-12-29',231058594), +('2008-12-29',231059854),('2008-12-29',231059884),('2008-12-29',231059914), +('2008-12-29',231063664),('2008-12-29',231063814),('2008-12-29',231063904); +CREATE TABLE t3 ( +package_id int default NULL, +INDEX package_id(package_id) +); +INSERT INTO t3 VALUES +(231058294),(231058324),(231058354),(231058384),(231058414),(231058444), +(231058474),(231058504),(231058534),(231058564),(231058594),(231058624), +(231058684),(231058744),(231058804),(231058864),(231058924),(231058954), +(231059014),(231059074),(231059104),(231059134),(231059164),(231059194), +(231059224),(231059254),(231059284),(231059314),(231059344),(231059374), +(231059404),(231059434),(231059464),(231059494),(231059524),(231059554), +(231059584),(231059614),(231059644),(231059674),(231059704),(231059734), +(231059764),(231059794),(231059824),(231059854),(231059884),(231059914), +(231059944),(231059974),(231060004),(231060034),(231060064),(231060094), +(231060124),(231060154),(231060184),(231060214),(231060244),(231060274), +(231060304),(231060334),(231060364),(231060394),(231060424),(231060454), +(231060484),(231060514),(231060544),(231060574),(231060604),(231060634), +(231060664),(231060694),(231060724),(231060754),(231060784),(231060814), +(231060844),(231060874),(231060904),(231060934),(231060964),(231060994), +(231061024),(231061054),(231061084),(231061144),(231061174),(231061204), +(231061234),(231061294),(231061354),(231061384),(231061414),(231061474), +(231061564),(231061594),(231061624),(231061684),(231061714),(231061774), +(231061804),(231061894),(231061984),(231062074),(231062134),(231062224), +(231062254),(231062314),(231062374),(231062434),(231062494),(231062554), +(231062584),(231062614),(231062644),(231062704),(231062734),(231062794), +(231062854),(231062884),(231062944),(231063004),(231063034),(231063064), +(231063124),(231063154),(231063184),(231063214),(231063274),(231063334), +(231063394),(231063424),(231063454),(231063514),(231063574),(231063664); +CREATE TABLE t4 ( +carrier char(2) NOT NULL default '' PRIMARY KEY, +id int(11) default NULL, +INDEX id(id) +); +INSERT INTO t4 VALUES +('99',6),('SK',456),('UA',486),('AI',1081),('OS',1111),('VS',1510); +CREATE TABLE t5 ( +carrier_id int default NULL, +INDEX carrier_id(carrier_id) +); +INSERT INTO t5 VALUES +(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), +(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), +(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), +(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), +(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), +(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(456),(456),(456), +(456),(456),(456),(456),(456),(456),(456),(456),(456),(456),(456),(456), +(456),(486),(1081),(1111),(1111),(1111),(1111),(1510); +SELECT COUNT(*) +FROM((t2 JOIN t1 ON t2.package_id = t1.id) +JOIN t3 ON t3.package_id = t1.id); +COUNT(*) +6 +EXPLAIN +SELECT COUNT(*) +FROM ((t2 JOIN t1 ON t2.package_id = t1.id) +JOIN t3 ON t3.package_id = t1.id) +LEFT JOIN +(t5 JOIN t4 ON t5.carrier_id = t4.id) +ON t4.carrier = t1.carrier; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index package_id package_id 5 NULL 45 Using index +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.package_id 1 +1 SIMPLE t4 eq_ref PRIMARY,id PRIMARY 2 test.t1.carrier 1 +1 SIMPLE t5 ref carrier_id carrier_id 5 test.t4.id 22 Using index +1 SIMPLE t3 ref package_id package_id 5 test.t1.id 1 Using where; Using index +SELECT COUNT(*) +FROM ((t2 JOIN t1 ON t2.package_id = t1.id) +JOIN t3 ON t3.package_id = t1.id) +LEFT JOIN +(t5 JOIN t4 ON t5.carrier_id = t4.id) +ON t4.carrier = t1.carrier; +COUNT(*) +6 +DROP TABLE t1,t2,t3,t4,t5; End of 5.0 tests diff --git a/mysql-test/t/join_nested.test b/mysql-test/t/join_nested.test index f29366797f6..5b07d8966f1 100644 --- a/mysql-test/t/join_nested.test +++ b/mysql-test/t/join_nested.test @@ -1083,4 +1083,118 @@ SELECT * FROM t1 JOIN (t2 JOIN t3 USING (b)) USING (a); DROP TABLE t1,t2,t3; +# +# BUG#29604: inner nest of left join interleaves with outer tables +# + +CREATE TABLE t1 ( + carrier char(2) default NULL, + id int NOT NULL auto_increment PRIMARY KEY +); +INSERT INTO t1 VALUES + ('CO',235371754),('CO',235376554),('CO',235376884),('CO',235377874), + ('CO',231060394),('CO',231059224),('CO',231059314),('CO',231060484), + ('CO',231060274),('CO',231060124),('CO',231060244),('CO',231058594), + ('CO',231058924),('CO',231058504),('CO',231059344),('CO',231060424), + ('CO',231059554),('CO',231060304),('CO',231059644),('CO',231059464), + ('CO',231059764),('CO',231058294),('CO',231058624),('CO',231058864), + ('CO',231059374),('CO',231059584),('CO',231059734),('CO',231059014), + ('CO',231059854),('CO',231059494),('CO',231059794),('CO',231058534), + ('CO',231058324),('CO',231058684),('CO',231059524),('CO',231059974); + +CREATE TABLE t2 ( + scan_date date default NULL, + package_id int default NULL, + INDEX scan_date(scan_date), + INDEX package_id(package_id) +); +INSERT INTO t2 VALUES + ('2008-12-29',231062944),('2008-12-29',231065764),('2008-12-29',231066124), + ('2008-12-29',231060094),('2008-12-29',231061054),('2008-12-29',231065644), + ('2008-12-29',231064384),('2008-12-29',231064444),('2008-12-29',231073774), + ('2008-12-29',231058594),('2008-12-29',231059374),('2008-12-29',231066004), + ('2008-12-29',231068494),('2008-12-29',231070174),('2008-12-29',231071884), + ('2008-12-29',231063274),('2008-12-29',231063754),('2008-12-29',231064144), + ('2008-12-29',231069424),('2008-12-29',231073714),('2008-12-29',231058414), + ('2008-12-29',231060994),('2008-12-29',231069154),('2008-12-29',231068614), + ('2008-12-29',231071464),('2008-12-29',231074014),('2008-12-29',231059614), + ('2008-12-29',231059074),('2008-12-29',231059464),('2008-12-29',231069094), + ('2008-12-29',231067294),('2008-12-29',231070144),('2008-12-29',231073804), + ('2008-12-29',231072634),('2008-12-29',231058294),('2008-12-29',231065344), + ('2008-12-29',231066094),('2008-12-29',231069034),('2008-12-29',231058594), + ('2008-12-29',231059854),('2008-12-29',231059884),('2008-12-29',231059914), + ('2008-12-29',231063664),('2008-12-29',231063814),('2008-12-29',231063904); + +CREATE TABLE t3 ( + package_id int default NULL, + INDEX package_id(package_id) +); +INSERT INTO t3 VALUES + (231058294),(231058324),(231058354),(231058384),(231058414),(231058444), + (231058474),(231058504),(231058534),(231058564),(231058594),(231058624), + (231058684),(231058744),(231058804),(231058864),(231058924),(231058954), + (231059014),(231059074),(231059104),(231059134),(231059164),(231059194), + (231059224),(231059254),(231059284),(231059314),(231059344),(231059374), + (231059404),(231059434),(231059464),(231059494),(231059524),(231059554), + (231059584),(231059614),(231059644),(231059674),(231059704),(231059734), + (231059764),(231059794),(231059824),(231059854),(231059884),(231059914), + (231059944),(231059974),(231060004),(231060034),(231060064),(231060094), + (231060124),(231060154),(231060184),(231060214),(231060244),(231060274), + (231060304),(231060334),(231060364),(231060394),(231060424),(231060454), + (231060484),(231060514),(231060544),(231060574),(231060604),(231060634), + (231060664),(231060694),(231060724),(231060754),(231060784),(231060814), + (231060844),(231060874),(231060904),(231060934),(231060964),(231060994), + (231061024),(231061054),(231061084),(231061144),(231061174),(231061204), + (231061234),(231061294),(231061354),(231061384),(231061414),(231061474), + (231061564),(231061594),(231061624),(231061684),(231061714),(231061774), + (231061804),(231061894),(231061984),(231062074),(231062134),(231062224), + (231062254),(231062314),(231062374),(231062434),(231062494),(231062554), + (231062584),(231062614),(231062644),(231062704),(231062734),(231062794), + (231062854),(231062884),(231062944),(231063004),(231063034),(231063064), + (231063124),(231063154),(231063184),(231063214),(231063274),(231063334), + (231063394),(231063424),(231063454),(231063514),(231063574),(231063664); + +CREATE TABLE t4 ( + carrier char(2) NOT NULL default '' PRIMARY KEY, + id int(11) default NULL, + INDEX id(id) +); +INSERT INTO t4 VALUES + ('99',6),('SK',456),('UA',486),('AI',1081),('OS',1111),('VS',1510); + +CREATE TABLE t5 ( + carrier_id int default NULL, + INDEX carrier_id(carrier_id) +); +INSERT INTO t5 VALUES + (6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), + (6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), + (6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), + (6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), + (6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6), + (6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(456),(456),(456), + (456),(456),(456),(456),(456),(456),(456),(456),(456),(456),(456),(456), + (456),(486),(1081),(1111),(1111),(1111),(1111),(1510); + +SELECT COUNT(*) + FROM((t2 JOIN t1 ON t2.package_id = t1.id) + JOIN t3 ON t3.package_id = t1.id); + +EXPLAIN +SELECT COUNT(*) + FROM ((t2 JOIN t1 ON t2.package_id = t1.id) + JOIN t3 ON t3.package_id = t1.id) + LEFT JOIN + (t5 JOIN t4 ON t5.carrier_id = t4.id) + ON t4.carrier = t1.carrier; +SELECT COUNT(*) + FROM ((t2 JOIN t1 ON t2.package_id = t1.id) + JOIN t3 ON t3.package_id = t1.id) + LEFT JOIN + (t5 JOIN t4 ON t5.carrier_id = t4.id) + ON t4.carrier = t1.carrier; + +DROP TABLE t1,t2,t3,t4,t5; + --echo End of 5.0 tests + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9d27ab4bb4e..c62a19b2752 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8486,9 +8486,15 @@ static void restore_prev_nj_state(JOIN_TAB *last) { TABLE_LIST *last_emb= last->table->pos_in_table_list->embedding; JOIN *join= last->join; - while (last_emb && !(--last_emb->nested_join->counter)) + while (last_emb) { - join->cur_embedding_map &= last_emb->nested_join->nj_map; + if (!(--last_emb->nested_join->counter)) + join->cur_embedding_map&= ~last_emb->nested_join->nj_map; + else if (last_emb->nested_join->join_list.elements-1 == + last_emb->nested_join->counter) + join->cur_embedding_map|= last_emb->nested_join->nj_map; + else + break; last_emb= last_emb->embedding; } } From ad492a6db7582a35a95e7f0d9e9e7392efd353eb Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jul 2007 15:12:56 +0300 Subject: [PATCH 16/34] Bug 29325: test suite is not applicable on windows --- mysql-test/r/create.result | 22 --------------- mysql-test/r/create_not_windows.result | 22 +++++++++++++++ mysql-test/t/create.test | 37 ------------------------ mysql-test/t/create_not_windows.test | 39 ++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 59 deletions(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index ff963892bc9..e692dbf3938 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -1503,26 +1503,4 @@ t1 CREATE TABLE `t1` ( `c17` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; -CREATE DATABASE db1; -CREATE DATABASE db2; -USE db2; -INSERT INTO db2.t1 VALUES (1); -SELECT * FROM db2.t1; -b -1 -RESET QUERY CACHE; -USE db1; -SET SESSION keep_files_on_create = TRUE; -CREATE TABLE t1 (a INT) ENGINE MYISAM; -ERROR HY000: Can't create/write to file './db1/t1.MYD' (Errcode: 17) -CREATE TABLE t3 (a INT) Engine=MyISAM; -INSERT INTO t3 VALUES (1),(2),(3); -TRUNCATE TABLE t3; -SELECT * from t3; -a -SET SESSION keep_files_on_create = DEFAULT; -DROP TABLE db2.t1, db1.t3; -DROP DATABASE db1; -DROP DATABASE db2; -USE test; End of 5.0 tests diff --git a/mysql-test/r/create_not_windows.result b/mysql-test/r/create_not_windows.result index b975c98c2b1..a07ffa82610 100644 --- a/mysql-test/r/create_not_windows.result +++ b/mysql-test/r/create_not_windows.result @@ -12,3 +12,25 @@ about:text CREATE TABLE `about:text` ( PRIMARY KEY (`_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table `about:text`; +CREATE DATABASE db1; +CREATE DATABASE db2; +USE db2; +INSERT INTO db2.t1 VALUES (1); +SELECT * FROM db2.t1; +b +1 +RESET QUERY CACHE; +USE db1; +SET SESSION keep_files_on_create = TRUE; +CREATE TABLE t1 (a INT) ENGINE MYISAM; +ERROR HY000: Can't create/write to file './db1/t1.MYD' (Errcode: 17) +CREATE TABLE t3 (a INT) Engine=MyISAM; +INSERT INTO t3 VALUES (1),(2),(3); +TRUNCATE TABLE t3; +SELECT * from t3; +a +SET SESSION keep_files_on_create = DEFAULT; +DROP TABLE db2.t1, db1.t3; +DROP DATABASE db1; +DROP DATABASE db2; +USE test; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index a1d3d488f1c..99f3fea416a 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1118,42 +1118,5 @@ show create table t1; drop table t1; -# -# Bug #29325: create table overwrites .MYD file of other table (datadir) -# - -CREATE DATABASE db1; -CREATE DATABASE db2; - -USE db2; ---disable_query_log -eval CREATE TABLE t1 (b INT) ENGINE MYISAM -DATA DIRECTORY = '$MYSQLTEST_VARDIR/master-data/db1/'; ---enable_query_log - -INSERT INTO db2.t1 VALUES (1); -SELECT * FROM db2.t1; -RESET QUERY CACHE; - -USE db1; - -#no warning from create table -SET SESSION keep_files_on_create = TRUE; ---disable_abort_on_error -CREATE TABLE t1 (a INT) ENGINE MYISAM; ---enable_abort_on_error - -CREATE TABLE t3 (a INT) Engine=MyISAM; -INSERT INTO t3 VALUES (1),(2),(3); -TRUNCATE TABLE t3; -SELECT * from t3; - -SET SESSION keep_files_on_create = DEFAULT; - -DROP TABLE db2.t1, db1.t3; -DROP DATABASE db1; -DROP DATABASE db2; -USE test; - --echo End of 5.0 tests diff --git a/mysql-test/t/create_not_windows.test b/mysql-test/t/create_not_windows.test index 71ad9ccd7fe..c6547b1376b 100644 --- a/mysql-test/t/create_not_windows.test +++ b/mysql-test/t/create_not_windows.test @@ -17,4 +17,43 @@ primary key (_id) show create table `about:text`; drop table `about:text`; + +# +# Bug #29325: create table overwrites .MYD file of other table (datadir) +# + +CREATE DATABASE db1; +CREATE DATABASE db2; + +USE db2; +--disable_query_log +eval CREATE TABLE t1 (b INT) ENGINE MYISAM +DATA DIRECTORY = '$MYSQLTEST_VARDIR/master-data/db1/'; +--enable_query_log + +INSERT INTO db2.t1 VALUES (1); +SELECT * FROM db2.t1; +RESET QUERY CACHE; + +USE db1; + +#no warning from create table +SET SESSION keep_files_on_create = TRUE; +--disable_abort_on_error +CREATE TABLE t1 (a INT) ENGINE MYISAM; +--enable_abort_on_error + +CREATE TABLE t3 (a INT) Engine=MyISAM; +INSERT INTO t3 VALUES (1),(2),(3); +TRUNCATE TABLE t3; +SELECT * from t3; + +SET SESSION keep_files_on_create = DEFAULT; + +DROP TABLE db2.t1, db1.t3; +DROP DATABASE db1; +DROP DATABASE db2; +USE test; + + # End of 5.0 tests From e08e63b192ac37b372b1cbb9014ef8180527e48a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jul 2007 23:09:55 +0400 Subject: [PATCH 17/34] Bug#29739: Incorrect time comparison in BETWEEN. Time values were compared by the BETWEEN function as strings. This led to a wrong result in cases when some of arguments are less than 100 hours and other are greater. Now if all 3 arguments of the BETWEEN function are of the TIME type then they are compared as integers. mysql-test/t/type_time.test: Added a tes tcase for the bug#29739: Incorrect time comparison in BETWEEN. mysql-test/r/type_time.result: Added a tes tcase for the bug#29739: Incorrect time comparison in BETWEEN. sql/item_cmpfunc.cc: Bug#29739: Incorrect time comparison in BETWEEN. Now if all 3 arguments of the BETWEEN function are of the TIME type then they are compared as integers. --- mysql-test/r/type_time.result | 6 ++++++ mysql-test/t/type_time.test | 8 ++++++++ sql/item_cmpfunc.cc | 24 ++++++++++++++++-------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index 6124f6e39f1..71bd8b68a0b 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -103,3 +103,9 @@ cast('100:55:50' as time) > cast('024:00:00' as time) select cast('300:55:50' as time) > cast('240:00:00' as time); cast('300:55:50' as time) > cast('240:00:00' as time) 1 +create table t1(f1 time, f2 time); +insert into t1 values('20:00:00','150:00:00'); +select 1 from t1 where cast('100:00:00' as time) between f1 and f2; +1 +1 +drop table t1; diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index d294e53a12f..82d701e29b5 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -50,3 +50,11 @@ select cast('300:55:50' as time) < cast('240:00:00' as time); select cast('100:55:50' as time) > cast('24:00:00' as time); select cast('100:55:50' as time) > cast('024:00:00' as time); select cast('300:55:50' as time) > cast('240:00:00' as time); + +# +# Bug#29739: Incorrect time comparison in BETWEEN. +# +create table t1(f1 time, f2 time); +insert into t1 values('20:00:00','150:00:00'); +select 1 from t1 where cast('100:00:00' as time) between f1 and f2; +drop table t1; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 70df1b4d09c..555384b2bfc 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1728,6 +1728,7 @@ void Item_func_between::fix_length_and_dec() THD *thd= current_thd; int i; bool datetime_found= FALSE; + int time_items_found= 0; compare_as_dates= TRUE; /* @@ -1747,17 +1748,19 @@ void Item_func_between::fix_length_and_dec() At least one of items should be a DATE/DATETIME item and other items should return the STRING result. */ - for (i= 0; i < 3; i++) + if (cmp_type == STRING_RESULT) { - if (args[i]->is_datetime()) + for (i= 0; i < 3; i++) { - datetime_found= TRUE; - continue; + if (args[i]->is_datetime()) + { + datetime_found= TRUE; + continue; + } + if (args[i]->field_type() == MYSQL_TYPE_TIME && + args[i]->result_as_longlong()) + time_items_found++; } - if (args[i]->result_type() == STRING_RESULT) - continue; - compare_as_dates= FALSE; - break; } if (!datetime_found) compare_as_dates= FALSE; @@ -1767,6 +1770,11 @@ void Item_func_between::fix_length_and_dec() ge_cmp.set_datetime_cmp_func(args, args + 1); le_cmp.set_datetime_cmp_func(args, args + 2); } + else if (time_items_found == 3) + { + /* Compare TIME items as integers. */ + cmp_type= INT_RESULT; + } else if (args[0]->real_item()->type() == FIELD_ITEM && thd->lex->sql_command != SQLCOM_CREATE_VIEW && thd->lex->sql_command != SQLCOM_SHOW_CREATE) From b806ca22c6bcab929c0121d23f686a0484e64ed1 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Jul 2007 13:56:22 +0300 Subject: [PATCH 18/34] Bug 29325: moved the test from create_not_windows to symlink. --- mysql-test/r/create_not_windows.result | 22 --------------- mysql-test/r/symlink.result | 24 ++++++++++++++++ mysql-test/t/create_not_windows.test | 38 -------------------------- mysql-test/t/symlink.test | 36 ++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/mysql-test/r/create_not_windows.result b/mysql-test/r/create_not_windows.result index a07ffa82610..b975c98c2b1 100644 --- a/mysql-test/r/create_not_windows.result +++ b/mysql-test/r/create_not_windows.result @@ -12,25 +12,3 @@ about:text CREATE TABLE `about:text` ( PRIMARY KEY (`_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table `about:text`; -CREATE DATABASE db1; -CREATE DATABASE db2; -USE db2; -INSERT INTO db2.t1 VALUES (1); -SELECT * FROM db2.t1; -b -1 -RESET QUERY CACHE; -USE db1; -SET SESSION keep_files_on_create = TRUE; -CREATE TABLE t1 (a INT) ENGINE MYISAM; -ERROR HY000: Can't create/write to file './db1/t1.MYD' (Errcode: 17) -CREATE TABLE t3 (a INT) Engine=MyISAM; -INSERT INTO t3 VALUES (1),(2),(3); -TRUNCATE TABLE t3; -SELECT * from t3; -a -SET SESSION keep_files_on_create = DEFAULT; -DROP TABLE db2.t1, db1.t3; -DROP DATABASE db1; -DROP DATABASE db2; -USE test; diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index 4725bcc0ac9..02c3a085eef 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -133,4 +133,28 @@ a 42 drop table t1; End of 4.1 tests +CREATE DATABASE db1; +CREATE DATABASE db2; +USE db2; +CREATE TABLE t1 (b INT) ENGINE MYISAM +DATA DIRECTORY = '/home/kgeorge/mysql/work/B29325-winfix-5.0-opt/mysql-test/var/master-data/db1/'; +INSERT INTO db2.t1 VALUES (1); +SELECT * FROM db2.t1; +b +1 +RESET QUERY CACHE; +USE db1; +SET SESSION keep_files_on_create = TRUE; +CREATE TABLE t1 (a INT) ENGINE MYISAM; +ERROR HY000: Can't create/write to file './db1/t1.MYD' (Errcode: 17) +CREATE TABLE t3 (a INT) Engine=MyISAM; +INSERT INTO t3 VALUES (1),(2),(3); +TRUNCATE TABLE t3; +SELECT * from t3; +a +SET SESSION keep_files_on_create = DEFAULT; +DROP TABLE db2.t1, db1.t3; +DROP DATABASE db1; +DROP DATABASE db2; +USE test; End of 5.0 tests diff --git a/mysql-test/t/create_not_windows.test b/mysql-test/t/create_not_windows.test index c6547b1376b..7e51ff51024 100644 --- a/mysql-test/t/create_not_windows.test +++ b/mysql-test/t/create_not_windows.test @@ -18,42 +18,4 @@ show create table `about:text`; drop table `about:text`; -# -# Bug #29325: create table overwrites .MYD file of other table (datadir) -# - -CREATE DATABASE db1; -CREATE DATABASE db2; - -USE db2; ---disable_query_log -eval CREATE TABLE t1 (b INT) ENGINE MYISAM -DATA DIRECTORY = '$MYSQLTEST_VARDIR/master-data/db1/'; ---enable_query_log - -INSERT INTO db2.t1 VALUES (1); -SELECT * FROM db2.t1; -RESET QUERY CACHE; - -USE db1; - -#no warning from create table -SET SESSION keep_files_on_create = TRUE; ---disable_abort_on_error -CREATE TABLE t1 (a INT) ENGINE MYISAM; ---enable_abort_on_error - -CREATE TABLE t3 (a INT) Engine=MyISAM; -INSERT INTO t3 VALUES (1),(2),(3); -TRUNCATE TABLE t3; -SELECT * from t3; - -SET SESSION keep_files_on_create = DEFAULT; - -DROP TABLE db2.t1, db1.t3; -DROP DATABASE db1; -DROP DATABASE db2; -USE test; - - # End of 5.0 tests diff --git a/mysql-test/t/symlink.test b/mysql-test/t/symlink.test index d79b6905224..46a9ead5829 100644 --- a/mysql-test/t/symlink.test +++ b/mysql-test/t/symlink.test @@ -178,4 +178,40 @@ drop table t1; --echo End of 4.1 tests +# +# Bug #29325: create table overwrites .MYD file of other table (datadir) +# + +CREATE DATABASE db1; +CREATE DATABASE db2; + +USE db2; +eval CREATE TABLE t1 (b INT) ENGINE MYISAM +DATA DIRECTORY = '$MYSQLTEST_VARDIR/master-data/db1/'; + +INSERT INTO db2.t1 VALUES (1); +SELECT * FROM db2.t1; +RESET QUERY CACHE; + +USE db1; + +#no warning from create table +SET SESSION keep_files_on_create = TRUE; +--disable_abort_on_error +CREATE TABLE t1 (a INT) ENGINE MYISAM; +--enable_abort_on_error + +CREATE TABLE t3 (a INT) Engine=MyISAM; +INSERT INTO t3 VALUES (1),(2),(3); +TRUNCATE TABLE t3; +SELECT * from t3; + +SET SESSION keep_files_on_create = DEFAULT; + +DROP TABLE db2.t1, db1.t3; +DROP DATABASE db1; +DROP DATABASE db2; +USE test; + + --echo End of 5.0 tests From 2a0498c0f9a67676aedef2699fe5a14150ce5f4d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Jul 2007 16:32:29 +0300 Subject: [PATCH 19/34] disabled the output of the full path in tesing bug 29325 --- mysql-test/r/symlink.result | 2 -- mysql-test/t/symlink.test | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index 02c3a085eef..18299bf4298 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -136,8 +136,6 @@ End of 4.1 tests CREATE DATABASE db1; CREATE DATABASE db2; USE db2; -CREATE TABLE t1 (b INT) ENGINE MYISAM -DATA DIRECTORY = '/home/kgeorge/mysql/work/B29325-winfix-5.0-opt/mysql-test/var/master-data/db1/'; INSERT INTO db2.t1 VALUES (1); SELECT * FROM db2.t1; b diff --git a/mysql-test/t/symlink.test b/mysql-test/t/symlink.test index 46a9ead5829..8c67a4c1048 100644 --- a/mysql-test/t/symlink.test +++ b/mysql-test/t/symlink.test @@ -186,8 +186,10 @@ CREATE DATABASE db1; CREATE DATABASE db2; USE db2; +--disable_query_log eval CREATE TABLE t1 (b INT) ENGINE MYISAM DATA DIRECTORY = '$MYSQLTEST_VARDIR/master-data/db1/'; +--enable_query_log INSERT INTO db2.t1 VALUES (1); SELECT * FROM db2.t1; From 38f4c6137a64192a962ad9d357055ced0f9150fa Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Jul 2007 19:13:40 +0400 Subject: [PATCH 20/34] BUG#29740: Wrong query results for index_merge/union over HEAP table. - return HA_KEY_SCAN_NOT_ROR flag for HASH indexes; - Fix ha_heap::cmp_ref() to work with BTREE index scans. mysql-test/r/index_merge.result: BUG#29740: testcase mysql-test/t/index_merge.test: BUG#29740: testcase sql/ha_heap.h: BUG#29740: Wrong query results for index_merge/union over HEAP table. - make HEAP table engine return HA_KEY_SCAN_NOT_ROR flag for HASH indexes,as HASH index does not guarantee any ordering for rows within the hash bucket. - Fix BTREE indexes: make ha_heap::cmp_ref() compare the rowids in the same way as ha_key_cmp() does. sql/opt_range.cc: BUG#29740: Fix comment about ROR scans. --- mysql-test/r/index_merge.result | 61 +++++++++++++++++++++++++++++++++ mysql-test/t/index_merge.test | 43 +++++++++++++++++++++++ sql/ha_heap.h | 8 ++--- sql/opt_range.cc | 25 ++++++-------- 4 files changed, 118 insertions(+), 19 deletions(-) diff --git a/mysql-test/r/index_merge.result b/mysql-test/r/index_merge.result index 9456b4ec978..c7e4ead9eeb 100644 --- a/mysql-test/r/index_merge.result +++ b/mysql-test/r/index_merge.result @@ -455,3 +455,64 @@ a 1 UNLOCK TABLES; DROP TABLE t1, t2; +CREATE TABLE `t1` ( +`a` int(11) DEFAULT NULL, +`filler` char(200) DEFAULT NULL, +`b` int(11) DEFAULT NULL, +KEY `a` (`a`), +KEY `b` (`b`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1; +insert into t1 values +(0, 'filler', 0), (1, 'filler', 1), (2, 'filler', 2), (3, 'filler', 3), +(4, 'filler', 4), (5, 'filler', 5), (6, 'filler', 6), (7, 'filler', 7), +(8, 'filler', 8), (9, 'filler', 9), (0, 'filler', 0), (1, 'filler', 1), +(2, 'filler', 2), (3, 'filler', 3), (4, 'filler', 4), (5, 'filler', 5), +(6, 'filler', 6), (7, 'filler', 7), (8, 'filler', 8), (9, 'filler', 9), +(10, 'filler', 10), (11, 'filler', 11), (12, 'filler', 12), (13, 'filler', 13), +(14, 'filler', 14), (15, 'filler', 15), (16, 'filler', 16), (17, 'filler', 17), +(18, 'filler', 18), (19, 'filler', 19), (4, '5 ', 0), (5, '4 ', 0), +(4, '4 ', 0), (4, 'qq ', 5), (5, 'qq ', 4), (4, 'zz ', 4); +create table t2( +`a` int(11) DEFAULT NULL, +`filler` char(200) DEFAULT NULL, +`b` int(11) DEFAULT NULL, +KEY USING BTREE (`a`), +KEY USING BTREE (`b`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1; +insert into t2 select * from t1; +must use sort-union rather than union: +explain select * from t1 where a=4 or b=4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 4 Using sort_union(a,b); Using where +select * from t1 where a=4 or b=4; +a filler b +4 zz 4 +5 qq 4 +4 filler 4 +4 qq 5 +4 4 0 +4 filler 4 +4 5 0 +select * from t1 ignore index(a,b) where a=4 or b=4; +a filler b +4 filler 4 +4 filler 4 +4 5 0 +4 4 0 +4 qq 5 +5 qq 4 +4 zz 4 +must use union, not sort-union: +explain select * from t2 where a=4 or b=4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index_merge a,b a,b 5,5 NULL 7 Using union(a,b); Using where +select * from t2 where a=4 or b=4; +a filler b +4 5 0 +4 zz 4 +5 qq 4 +4 filler 4 +4 qq 5 +4 4 0 +4 filler 4 +drop table t1, t2; diff --git a/mysql-test/t/index_merge.test b/mysql-test/t/index_merge.test index 30eb0b40fca..7d9a4340b0f 100644 --- a/mysql-test/t/index_merge.test +++ b/mysql-test/t/index_merge.test @@ -415,3 +415,46 @@ INSERT INTO t2(a,b) VALUES(1,2); SELECT t2.a FROM t1,t2 WHERE t2.b=2 AND t2.a=1; UNLOCK TABLES; DROP TABLE t1, t2; + +# +# BUG#29740: HA_KEY_SCAN_NOT_ROR wasn't set for HEAP engine +# +CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `filler` char(200) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + KEY `a` (`a`), + KEY `b` (`b`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1; + +insert into t1 values +(0, 'filler', 0), (1, 'filler', 1), (2, 'filler', 2), (3, 'filler', 3), +(4, 'filler', 4), (5, 'filler', 5), (6, 'filler', 6), (7, 'filler', 7), +(8, 'filler', 8), (9, 'filler', 9), (0, 'filler', 0), (1, 'filler', 1), +(2, 'filler', 2), (3, 'filler', 3), (4, 'filler', 4), (5, 'filler', 5), +(6, 'filler', 6), (7, 'filler', 7), (8, 'filler', 8), (9, 'filler', 9), +(10, 'filler', 10), (11, 'filler', 11), (12, 'filler', 12), (13, 'filler', 13), +(14, 'filler', 14), (15, 'filler', 15), (16, 'filler', 16), (17, 'filler', 17), +(18, 'filler', 18), (19, 'filler', 19), (4, '5 ', 0), (5, '4 ', 0), +(4, '4 ', 0), (4, 'qq ', 5), (5, 'qq ', 4), (4, 'zz ', 4); + +create table t2( + `a` int(11) DEFAULT NULL, + `filler` char(200) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + KEY USING BTREE (`a`), + KEY USING BTREE (`b`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1; +insert into t2 select * from t1; + +--echo must use sort-union rather than union: +explain select * from t1 where a=4 or b=4; +select * from t1 where a=4 or b=4; +select * from t1 ignore index(a,b) where a=4 or b=4; + +--echo must use union, not sort-union: +explain select * from t2 where a=4 or b=4; +select * from t2 where a=4 or b=4; + +drop table t1, t2; + diff --git a/sql/ha_heap.h b/sql/ha_heap.h index 18389c1298d..27846ca4a8e 100644 --- a/sql/ha_heap.h +++ b/sql/ha_heap.h @@ -54,8 +54,8 @@ public: ulong index_flags(uint inx, uint part, bool all_parts) const { return ((table->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ? - HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE : - HA_ONLY_WHOLE_INDEX); + HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE : + HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR); } const key_map *keys_to_use_for_scanning() { return &btree_keys; } uint max_supported_keys() const { return MAX_KEY; } @@ -101,9 +101,7 @@ public: enum thr_lock_type lock_type); int cmp_ref(const byte *ref1, const byte *ref2) { - HEAP_PTR ptr1=*(HEAP_PTR*)ref1; - HEAP_PTR ptr2=*(HEAP_PTR*)ref2; - return ptr1 < ptr2? -1 : (ptr1 > ptr2? 1 : 0); + return memcmp(ref1, ref2, sizeof(HEAP_PTR)); } private: void update_key_stats(); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index c3aa1f52556..952e5abfd13 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -6007,27 +6007,24 @@ check_quick_keys(PARAM *param,uint idx,SEL_ARG *key_tree, ROR (Rowid Ordered Retrieval) key scan is a key scan that produces ordered sequence of rowids (ha_xxx::cmp_ref is the comparison function) - An index scan is a ROR scan if it is done using a condition in form + This function is needed to handle a practically-important special case: + an index scan is a ROR scan if it is done using a condition in form - "key1_1=c_1 AND ... AND key1_n=c_n" (1) + "key1_1=c_1 AND ... AND key1_n=c_n" where the index is defined on (key1_1, ..., key1_N [,a_1, ..., a_n]) - and the table has a clustered Primary Key + and the table has a clustered Primary Key defined as - PRIMARY KEY(a_1, ..., a_n, b1, ..., b_k) with first key parts being - identical to uncovered parts ot the key being scanned (2) - - Scans on HASH indexes are not ROR scans, - any range scan on clustered primary key is ROR scan (3) - - Check (1) is made in check_quick_keys() - Check (3) is made check_quick_select() - Check (2) is made by this function. + PRIMARY KEY(a_1, ..., a_n, b1, ..., b_k) + + i.e. the first key parts of it are identical to uncovered parts ot the + key being scanned. This function assumes that the index flags do not + include HA_KEY_SCAN_NOT_ROR flag (that is checked elsewhere). RETURN - TRUE If the scan is ROR-scan - FALSE otherwise + TRUE The scan is ROR-scan + FALSE Otherwise */ static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts) From 25545b4bfb56ed4581edddb47820f4c968bb1f1f Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Jul 2007 22:02:10 +0400 Subject: [PATCH 21/34] BUG#29740: Make the test result deterministic --- mysql-test/r/index_merge.result | 30 +++++++++++++++--------------- mysql-test/t/index_merge.test | 5 +++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/mysql-test/r/index_merge.result b/mysql-test/r/index_merge.result index c7e4ead9eeb..15aa636d740 100644 --- a/mysql-test/r/index_merge.result +++ b/mysql-test/r/index_merge.result @@ -483,36 +483,36 @@ insert into t2 select * from t1; must use sort-union rather than union: explain select * from t1 where a=4 or b=4; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 4 Using sort_union(a,b); Using where +1 SIMPLE t1 index_merge a,b a,b 5,5 NULL # Using sort_union(a,b); Using where select * from t1 where a=4 or b=4; a filler b -4 zz 4 -5 qq 4 +4 4 0 +4 5 0 +4 filler 4 4 filler 4 4 qq 5 -4 4 0 -4 filler 4 -4 5 0 +4 zz 4 +5 qq 4 select * from t1 ignore index(a,b) where a=4 or b=4; a filler b -4 filler 4 -4 filler 4 -4 5 0 4 4 0 +4 5 0 +4 filler 4 +4 filler 4 4 qq 5 -5 qq 4 4 zz 4 +5 qq 4 must use union, not sort-union: explain select * from t2 where a=4 or b=4; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index_merge a,b a,b 5,5 NULL 7 Using union(a,b); Using where +1 SIMPLE t2 index_merge a,b a,b 5,5 NULL # Using union(a,b); Using where select * from t2 where a=4 or b=4; a filler b +4 4 0 4 5 0 -4 zz 4 -5 qq 4 +4 filler 4 4 filler 4 4 qq 5 -4 4 0 -4 filler 4 +4 zz 4 +5 qq 4 drop table t1, t2; diff --git a/mysql-test/t/index_merge.test b/mysql-test/t/index_merge.test index 7d9a4340b0f..8c19ab4d7d6 100644 --- a/mysql-test/t/index_merge.test +++ b/mysql-test/t/index_merge.test @@ -448,12 +448,17 @@ create table t2( insert into t2 select * from t1; --echo must use sort-union rather than union: +--replace_column 9 # explain select * from t1 where a=4 or b=4; +--sorted_result select * from t1 where a=4 or b=4; +--sorted_result select * from t1 ignore index(a,b) where a=4 or b=4; --echo must use union, not sort-union: +--replace_column 9 # explain select * from t2 where a=4 or b=4; +--sorted_result select * from t2 where a=4 or b=4; drop table t1, t2; From 4f146f656c319f0ffb37f9f1428035aadf4acaf5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Jul 2007 22:43:58 +0400 Subject: [PATCH 22/34] Bug#29729: Wrong conversion error led to an empty result set. The Field_newdate::store when storing a DATETIME value was returning the 'value was cut' error even if the thd->count_cuted_fields flag is set to CHECK_FIELD_IGNORE. This made range optimizr think that there is no appropriate data in the table and thus to return an empty set. Now the Field_newdate::store function returns conversion error only if the thd->count_cuted_fields flag isn't set to CHECK_FIELD_IGNORE. mysql-test/t/type_time.test: Added a test case for the bug#29729: Wrong conversion error led to an empty result set. mysql-test/r/type_time.result: Added a test case for the bug#29729: Wrong conversion error led to an empty result set. sql/field.cc: Bug#29729: Wrong conversion error led to an empty result set. --- mysql-test/r/type_time.result | 13 +++++++++++++ mysql-test/t/type_time.test | 15 +++++++++++++++ sql/field.cc | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index 71bd8b68a0b..def94bd707b 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -109,3 +109,16 @@ select 1 from t1 where cast('100:00:00' as time) between f1 and f2; 1 1 drop table t1; +CREATE TABLE t1 ( +f2 date NOT NULL, +f3 int(11) unsigned NOT NULL default '0', +PRIMARY KEY (f3, f2) +); +insert into t1 values('2007-07-01', 1); +insert into t1 values('2007-07-01', 2); +insert into t1 values('2007-07-02', 1); +insert into t1 values('2007-07-02', 2); +SELECT sum(f3) FROM t1 where f2='2007-07-01 00:00:00' group by f2; +sum(f3) +3 +drop table t1; diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index 82d701e29b5..bc4f850dfee 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -58,3 +58,18 @@ create table t1(f1 time, f2 time); insert into t1 values('20:00:00','150:00:00'); select 1 from t1 where cast('100:00:00' as time) between f1 and f2; drop table t1; + +# +# Bug#29729: Wrong conversion error led to an empty result set. +# +CREATE TABLE t1 ( + f2 date NOT NULL, + f3 int(11) unsigned NOT NULL default '0', + PRIMARY KEY (f3, f2) +); +insert into t1 values('2007-07-01', 1); +insert into t1 values('2007-07-01', 2); +insert into t1 values('2007-07-02', 1); +insert into t1 values('2007-07-02', 2); +SELECT sum(f3) FROM t1 where f2='2007-07-01 00:00:00' group by f2; +drop table t1; diff --git a/sql/field.cc b/sql/field.cc index 2e227f0e67e..993c1fb3c4f 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5271,7 +5271,8 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) else { tmp= l_time.day + l_time.month*32 + l_time.year*16*32; - if (!error && (ret != MYSQL_TIMESTAMP_DATE)) + if (!error && (ret != MYSQL_TIMESTAMP_DATE) && + thd->count_cuted_fields != CHECK_FIELD_IGNORE) error= 3; // Datetime was cut (note) } From 6e078ff5433080699416ed473a332395d48a1bfa Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 15 Jul 2007 21:51:36 +0400 Subject: [PATCH 23/34] Extended fix for the bug#29555. The get_time_value function is added. It is used to obtain TIME values both from items the can return time as an integer and from items that can return time only as a string. The Arg_comparator::compare_datetime function now uses pointer to a getter function to obtain values to compare. Now this function is also used for comparison of TIME values. The get_value_func variable is added to the Arg_comparator class. It points to a getter function for the DATE/DATETIME/TIME comparator. mysql-test/t/type_time.test: Extended test case for the bug#29555. mysql-test/r/type_time.result: Extended test case for the bug#29555. sql/item_cmpfunc.cc: Extended fix for the bug#29555. The get_time_value function is added. It is used to obtain TIME values both from items the can return time as an integer and from items that can return time only as a string. The Arg_comparator::compare_datetime function now uses pointer to a getter function to obtain values to compare. Now this function is also used for comparison of TIME values. sql/item_cmpfunc.h: Extended fix for the bug#29555. The get_value_func variable is added to the Arg_comparator class. It points to a getter function for the DATE/DATETIME/TIME comparator. --- mysql-test/r/type_time.result | 6 +++ mysql-test/t/type_time.test | 4 ++ sql/item_cmpfunc.cc | 81 ++++++++++++++++++++++++++++++++--- sql/item_cmpfunc.h | 2 + 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index def94bd707b..96bf23109df 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -103,6 +103,12 @@ cast('100:55:50' as time) > cast('024:00:00' as time) select cast('300:55:50' as time) > cast('240:00:00' as time); cast('300:55:50' as time) > cast('240:00:00' as time) 1 +create table t1 (f1 time); +insert into t1 values ('24:00:00'); +select cast('24:00:00' as time) = (select f1 from t1); +cast('24:00:00' as time) = (select f1 from t1) +1 +drop table t1; create table t1(f1 time, f2 time); insert into t1 values('20:00:00','150:00:00'); select 1 from t1 where cast('100:00:00' as time) between f1 and f2; diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index bc4f850dfee..5fc763be7fe 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -50,6 +50,10 @@ select cast('300:55:50' as time) < cast('240:00:00' as time); select cast('100:55:50' as time) > cast('24:00:00' as time); select cast('100:55:50' as time) > cast('024:00:00' as time); select cast('300:55:50' as time) > cast('240:00:00' as time); +create table t1 (f1 time); +insert into t1 values ('24:00:00'); +select cast('24:00:00' as time) = (select f1 from t1); +drop table t1; # # Bug#29739: Incorrect time comparison in BETWEEN. diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 555384b2bfc..8e16dfb4145 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -666,6 +666,68 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value) } +/* + Retrieves correct TIME value from the given item. + + SYNOPSIS + get_time_value() + thd thread handle + item_arg [in/out] item to retrieve TIME value from + cache_arg [in/out] pointer to place to store the caching item to + warn_item [in] unused + is_null [out] TRUE <=> the item_arg is null + + DESCRIPTION + Retrieves the correct TIME value from given item for comparison by the + compare_datetime() function. + If item's result can be compared as longlong then its int value is used + and a value returned by get_time function is used otherwise. + If an item is a constant one then its value is cached and it isn't + get parsed again. An Item_cache_int object is used for caching values. It + seamlessly substitutes the original item. The cache item is marked as + non-constant to prevent re-caching it again. + + RETURN + obtained value +*/ + +ulonglong +get_time_value(THD *thd, Item ***item_arg, Item **cache_arg, + Item *warn_item, bool *is_null) +{ + ulonglong value; + Item *item= **item_arg; + MYSQL_TIME ltime; + + if (item->result_as_longlong()) + { + value= item->val_int(); + *is_null= item->null_value; + } + else + { + *is_null= item->get_time(<ime); + if (!is_null) + value= TIME_to_ulonglong_datetime(<ime); + } + /* + Do not cache GET_USER_VAR() function as its const_item() may return TRUE + for the current thread but it still may change during the execution. + */ + if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM || + ((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC)) + { + Item_cache_int *cache= new Item_cache_int(); + /* Mark the cache as non-const to prevent re-caching. */ + cache->set_used_tables(1); + cache->store(item, value); + *cache_arg= cache; + *item_arg= cache_arg; + } + return value; +} + + int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg, Item **a1, Item **a2, Item_result type) @@ -704,6 +766,7 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg, } is_nulls_eq= test(owner && owner->functype() == Item_func::EQUAL_FUNC); func= &Arg_comparator::compare_datetime; + get_value_func= &get_datetime_value; return 0; } else if (type == STRING_RESULT && (*a)->field_type() == MYSQL_TYPE_TIME && @@ -712,9 +775,11 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg, /* Compare TIME values as integers. */ thd= current_thd; owner= owner_arg; - func= ((test(owner && owner->functype() == Item_func::EQUAL_FUNC)) ? - &Arg_comparator::compare_e_int : - &Arg_comparator::compare_int_unsigned); + a_cache= 0; + b_cache= 0; + is_nulls_eq= test(owner && owner->functype() == Item_func::EQUAL_FUNC); + func= &Arg_comparator::compare_datetime; + get_value_func= &get_time_value; return 0; } @@ -735,8 +800,10 @@ void Arg_comparator::set_datetime_cmp_func(Item **a1, Item **b1) b_cache= 0; is_nulls_eq= FALSE; func= &Arg_comparator::compare_datetime; + get_value_func= &get_datetime_value; } + /* Retrieves correct DATETIME value from given item. @@ -850,8 +917,8 @@ int Arg_comparator::compare_datetime() bool is_null= FALSE; ulonglong a_value, b_value; - /* Get DATE/DATETIME value of the 'a' item. */ - a_value= get_datetime_value(thd, &a, &a_cache, *b, &is_null); + /* Get DATE/DATETIME/TIME value of the 'a' item. */ + a_value= (*get_value_func)(thd, &a, &a_cache, *b, &is_null); if (!is_nulls_eq && is_null) { if (owner) @@ -859,8 +926,8 @@ int Arg_comparator::compare_datetime() return -1; } - /* Get DATE/DATETIME value of the 'b' item. */ - b_value= get_datetime_value(thd, &b, &b_cache, *a, &is_null); + /* Get DATE/DATETIME/TIME value of the 'b' item. */ + b_value= (*get_value_func)(thd, &b, &b_cache, *a, &is_null); if (is_null) { if (owner) diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 79091b9c87d..9afc0507817 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -42,6 +42,8 @@ class Arg_comparator: public Sql_alloc bool is_nulls_eq; // TRUE <=> compare for the EQUAL_FUNC enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE, CMP_DATE_WITH_STR, CMP_STR_WITH_DATE }; + ulonglong (*get_value_func)(THD *thd, Item ***item_arg, Item **cache_arg, + Item *warn_item, bool *is_null); public: DTCollation cmp_collation; From 16135c7dca88e7ed0d78bf2e5d5cc748d6320dfb Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 15 Jul 2007 23:40:57 +0400 Subject: [PATCH 24/34] item_cmpfunc.cc: A comment changed. sql/item_cmpfunc.cc: A comment changed. --- sql/item_cmpfunc.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 8e16dfb4145..161a3f7bb19 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -673,7 +673,7 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value) get_time_value() thd thread handle item_arg [in/out] item to retrieve TIME value from - cache_arg [in/out] pointer to place to store the caching item to + cache_arg [in/out] pointer to place to store the cache item to warn_item [in] unused is_null [out] TRUE <=> the item_arg is null @@ -683,8 +683,8 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value) If item's result can be compared as longlong then its int value is used and a value returned by get_time function is used otherwise. If an item is a constant one then its value is cached and it isn't - get parsed again. An Item_cache_int object is used for caching values. It - seamlessly substitutes the original item. The cache item is marked as + get parsed again. An Item_cache_int object is used for for cached values. + It seamlessly substitutes the original item. The cache item is marked as non-constant to prevent re-caching it again. RETURN From 3e925554ece25332a21125233a13c0e10253d482 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Jul 2007 00:59:47 +0400 Subject: [PATCH 25/34] item_cmpfunc.cc: Fixed compiler warning. sql/item_cmpfunc.cc: Fixed compiler warning. --- sql/item_cmpfunc.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 161a3f7bb19..a89f6337f5f 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -707,8 +707,7 @@ get_time_value(THD *thd, Item ***item_arg, Item **cache_arg, else { *is_null= item->get_time(<ime); - if (!is_null) - value= TIME_to_ulonglong_datetime(<ime); + value= !is_null ? TIME_to_ulonglong_datetime(<ime) : 0; } /* Do not cache GET_USER_VAR() function as its const_item() may return TRUE From 56a65d7ad097ff9f2b0677338df059a6b96afd94 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Jul 2007 01:03:58 +0400 Subject: [PATCH 26/34] item_cmpfunc.cc: A typo fixed. sql/item_cmpfunc.cc: A typo fixed. --- sql/item_cmpfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index a89f6337f5f..86eb10d50b0 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -707,7 +707,7 @@ get_time_value(THD *thd, Item ***item_arg, Item **cache_arg, else { *is_null= item->get_time(<ime); - value= !is_null ? TIME_to_ulonglong_datetime(<ime) : 0; + value= !*is_null ? TIME_to_ulonglong_datetime(<ime) : 0; } /* Do not cache GET_USER_VAR() function as its const_item() may return TRUE From 9917ce268d41942e977e0cfe0f093c20bb4018a2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Jul 2007 19:08:07 +0500 Subject: [PATCH 27/34] Bug #29687 mysql_stmt_store_result memory leak in libmysqld In embedded server we use result->alloc to store field data for the result, but we didn't clean the result->alloc if the query returned an empty recordset. Cleaning for the empty recordset enabled libmysql/libmysql.c: Bug #29687 mysql_stmt_store_result memory leak in libmysqld we should clean result->alloc even if we have nothin in 'data' field --- libmysql/libmysql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 72bc4445d83..1a0aae414ed 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -4945,7 +4945,7 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags) Reset stored result set if so was requested or it's a part of cursor fetch. */ - if (result->data && (flags & RESET_STORE_RESULT)) + if (flags & RESET_STORE_RESULT) { /* Result buffered */ free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); From 955c19961df6f18cd0217b5522e69db7287af67c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Jul 2007 19:51:50 +0400 Subject: [PATCH 28/34] [pb problem]: ha_heap->clone() fails on windows because of mess with '/' and '\' in path delimiters: - Fix this by creating new handler with exactly the same path line as was passed to ha_create/ha_open. sql/opt_range.cc: Set thd->net.report_error on handler::clone() failure --- sql/ha_heap.cc | 20 ++++++++++++++++++++ sql/ha_heap.h | 1 + sql/opt_range.cc | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 8838aa99c1a..62e6d0c47ee 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -114,6 +114,26 @@ int ha_heap::close(void) } +/* + Create a copy of this table + + DESCRIPTION + Do same as default implementation but use file->s->name instead of + table->s->path. This is needed by Windows where the clone() call sees + '/'-delimited path in table->s->path, while ha_peap::open() was called + with '\'-delimited path. +*/ + +handler *ha_heap::clone(MEM_ROOT *mem_root) +{ + handler *new_handler= get_new_handler(table, mem_root, table->s->db_type); + if (new_handler && !new_handler->ha_open(file->s->name, table->db_stat, + HA_OPEN_IGNORE_IF_LOCKED)) + return new_handler; + return NULL; +} + + /* Compute which keys to use for scanning diff --git a/sql/ha_heap.h b/sql/ha_heap.h index 27846ca4a8e..23583d0a6a7 100644 --- a/sql/ha_heap.h +++ b/sql/ha_heap.h @@ -32,6 +32,7 @@ class ha_heap: public handler public: ha_heap(TABLE *table); ~ha_heap() {} + handler *clone(MEM_ROOT *mem_root); const char *table_type() const { return (table->in_use->variables.sql_mode & MODE_MYSQL323) ? diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 952e5abfd13..76e78c7e9b8 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1131,6 +1131,14 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) THD *thd= current_thd; if (!(file= head->file->clone(thd->mem_root))) { + /* + Manually set the error flag. Note: there seems to be quite a few + places where a failure could cause the server to "hang" the client by + sending no response to a query. ATM those are not real errors because + the storage engine calls in question happen to never fail with the + existing storage engines. + */ + thd->net.report_error= 1; /* Caller will free the memory */ goto failure; } From 2679e53a73f2dbc51326d3cf59fcca7bc933a8da Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Jul 2007 22:46:51 +0400 Subject: [PATCH 29/34] Small comments fix --- sql/opt_range.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 76e78c7e9b8..65acecc0b87 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -5824,6 +5824,11 @@ check_quick_select(PARAM *param,uint idx,SEL_ARG *tree) param->is_ror_scan is cleared if the function detects that the key scan is not a Rowid-Ordered Retrieval scan ( see comments for is_key_scan_ror function for description of which key scans are ROR scans) + + RETURN + #records E(#records) for given subtree + HA_POS_ERROR if subtree cannot be used for record retrieval + */ static ha_rows From 043f697aeecf0731fcc4e65263287b2953df6ee3 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jul 2007 00:29:25 +0400 Subject: [PATCH 30/34] Mark deadcode for gcov --- sql/ha_heap.cc | 2 +- sql/opt_range.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 62e6d0c47ee..9ebc5aecde2 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -129,7 +129,7 @@ handler *ha_heap::clone(MEM_ROOT *mem_root) handler *new_handler= get_new_handler(table, mem_root, table->s->db_type); if (new_handler && !new_handler->ha_open(file->s->name, table->db_stat, HA_OPEN_IGNORE_IF_LOCKED)) - return new_handler; + return new_handler; /* purecov: inspected */ return NULL; } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 65acecc0b87..247f0eada49 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1138,9 +1138,9 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) the storage engine calls in question happen to never fail with the existing storage engines. */ - thd->net.report_error= 1; + thd->net.report_error= 1; /* purecov: inspected */ /* Caller will free the memory */ - goto failure; + goto failure; /* purecov: inspected */ } if (file->external_lock(thd, F_RDLCK)) goto failure; From 06b446dae4a55b48108bb85bd3ca3f70924b9b8d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jul 2007 11:12:15 +0400 Subject: [PATCH 31/34] Mark deadcode for gcov --- sql/ha_heap.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 9ebc5aecde2..bf807407df1 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -129,8 +129,8 @@ handler *ha_heap::clone(MEM_ROOT *mem_root) handler *new_handler= get_new_handler(table, mem_root, table->s->db_type); if (new_handler && !new_handler->ha_open(file->s->name, table->db_stat, HA_OPEN_IGNORE_IF_LOCKED)) - return new_handler; /* purecov: inspected */ - return NULL; + return new_handler; + return NULL; /* purecov: inspected */ } From a266c16d14a82b601f60c1987f5a9c6c779215e4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jul 2007 15:33:41 +0300 Subject: [PATCH 32/34] Bug #29325: create table overwrites .MYD file of other table (datadir) Set errno when retunring an error in my_create_with_symlink. mysys/my_symlink2.c: Bug #29325: set errno when retunring an error in my_create_with_symlink --- mysys/my_symlink2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c index 2ad08ef67de..e2493874097 100644 --- a/mysys/my_symlink2.c +++ b/mysys/my_symlink2.c @@ -52,11 +52,13 @@ File my_create_with_symlink(const char *linkname, const char *filename, { if (!access(filename,F_OK)) { + my_errno= errno= EEXIST; my_error(EE_CANTCREATEFILE, MYF(0), filename, EEXIST); DBUG_RETURN(-1); } if (create_link && !access(linkname,F_OK)) { + my_errno= errno= EEXIST; my_error(EE_CANTCREATEFILE, MYF(0), linkname, EEXIST); DBUG_RETURN(-1); } From 2bfe84d434104fdc1a9b69c62a237e01043f865f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jul 2007 19:14:48 +0500 Subject: [PATCH 33/34] Fixed bug #28524. For each view the mysqldump utility creates a temporary table with the same name and the same columns as the view in order to satisfy views that depend on this view. After the creation of all tables, mysqldump drops all temporary tables and creates actual views. However, --skip-add-drop-table and --compact flags disable DROP TABLE statements for those temporary tables. Thus, it was impossible to create the views because of existence of the temporary tables with the same names. client/mysqldump.c: Fixed bug #28524. The mysqldump utility has been modified to unconditionally drop temporary tables before the creation of views. mysql-test/t/mysqldump.test: Updated test case for bug #28524 and updated result of previous tests. mysql-test/r/mysqldump.result: Updated test case for bug #28524 and updated result of previous tests. --- client/mysqldump.c | 3 +-- mysql-test/r/mysqldump.result | 33 +++++++++++++++++++++++---------- mysql-test/t/mysqldump.test | 13 +++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 1a024a923f5..f72cb0171e1 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -3673,10 +3673,9 @@ static my_bool get_view_structure(char *table, char* db) result_table); check_io(sql_file); } + fprintf(sql_file, "/*!50001 DROP TABLE %s*/;\n", opt_quoted_table); if (opt_drop) { - fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", - opt_quoted_table); fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", opt_quoted_table); check_io(sql_file); diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 8eac7c7e715..da05fe7bc5b 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1889,7 +1889,7 @@ DROP TABLE IF EXISTS `v2`; /*!50001 CREATE TABLE `v2` ( `a` varchar(30) ) */; -/*!50001 DROP TABLE IF EXISTS `v2`*/; +/*!50001 DROP TABLE `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ @@ -1968,7 +1968,7 @@ DROP TABLE IF EXISTS `v1`; /*!50001 CREATE TABLE `v1` ( `a` int(11) ) */; -/*!50001 DROP TABLE IF EXISTS `v1`*/; +/*!50001 DROP TABLE `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ @@ -2027,7 +2027,7 @@ DROP TABLE IF EXISTS `v2`; /*!50001 CREATE TABLE `v2` ( `a` varchar(30) ) */; -/*!50001 DROP TABLE IF EXISTS `v2`*/; +/*!50001 DROP TABLE `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ @@ -2137,17 +2137,17 @@ DROP TABLE IF EXISTS `v3`; `b` int(11), `c` varchar(30) ) */; -/*!50001 DROP TABLE IF EXISTS `v1`*/; +/*!50001 DROP TABLE `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50001 VIEW `v1` AS select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `v3` where (`v3`.`b` in (1,2,3,4,5,6,7)) */; -/*!50001 DROP TABLE IF EXISTS `v2`*/; +/*!50001 DROP TABLE `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50001 VIEW `v2` AS select `v3`.`a` AS `a` from (`v3` join `v1`) where ((`v1`.`a` = `v3`.`a`) and (`v3`.`b` = 3)) limit 1 */; -/*!50001 DROP TABLE IF EXISTS `v3`*/; +/*!50001 DROP TABLE `v3`*/; /*!50001 DROP VIEW IF EXISTS `v3`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ @@ -2721,17 +2721,17 @@ DROP TABLE IF EXISTS `v2`; ) */; USE `test`; -/*!50001 DROP TABLE IF EXISTS `v0`*/; +/*!50001 DROP TABLE `v0`*/; /*!50001 DROP VIEW IF EXISTS `v0`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50001 VIEW `v0` AS select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`c` AS `c` from `v1` */; -/*!50001 DROP TABLE IF EXISTS `v1`*/; +/*!50001 DROP TABLE `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50001 VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from `t1` */; -/*!50001 DROP TABLE IF EXISTS `v2`*/; +/*!50001 DROP TABLE `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ @@ -2941,11 +2941,13 @@ insert into t values(5, 51); create view v1 as select qty, price, qty*price as value from t; create view v2 as select qty from v1; mysqldump { +/*!50001 DROP TABLE `v1`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50001 VIEW `v1` AS select `t`.`qty` AS `qty`,`t`.`price` AS `price`,(`t`.`qty` * `t`.`price`) AS `value` from `t` */; } mysqldump { +/*!50001 DROP TABLE `v2`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50001 VIEW `v2` AS select `v1`.`qty` AS `qty` from `v1` */; @@ -3029,7 +3031,7 @@ DROP TABLE IF EXISTS `v1`; ) */; USE `mysqldump_test_db`; -/*!50001 DROP TABLE IF EXISTS `v1`*/; +/*!50001 DROP TABLE `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ @@ -3076,6 +3078,7 @@ USE `mysqldump_views`; USE `mysqldump_tables`; USE `mysqldump_views`; +/*!50001 DROP TABLE `nasishnasifu`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50001 VIEW `mysqldump_views`.`nasishnasifu` AS select `mysqldump_tables`.`basetable`.`id` AS `id` from `mysqldump_tables`.`basetable` */; @@ -3321,5 +3324,15 @@ CREATE TABLE `t1` ( INSERT INTO `t1` VALUES (11,0x7171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171717171); DROP TABLE t1; # +# Bug #28524: mysqldump --skip-add-drop-table is not +# compatible with views +# +CREATE VIEW v1 AS SELECT 1; +DROP VIEW v1; +SELECT * FROM v1; +1 +1 +DROP VIEW v1; +# # End of 5.0 tests # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 30c241d4096..d42162541de 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1541,6 +1541,19 @@ INSERT INTO t1 SET c1=11, c2=REPEAT('q',509); --exec $MYSQL_DUMP --skip-create --compact --hex-blob test t1 DROP TABLE t1; +--echo # +--echo # Bug #28524: mysqldump --skip-add-drop-table is not +--echo # compatible with views +--echo # + +CREATE VIEW v1 AS SELECT 1; +--exec $MYSQL_DUMP --skip-add-drop-table test > $MYSQLTEST_VARDIR/tmp/bug28524.sql +DROP VIEW v1; + +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug28524.sql +SELECT * FROM v1; +DROP VIEW v1; + --echo # --echo # End of 5.0 tests --echo # From 7f6a8164846da34a822e8f844d6ec9e1da3af412 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Jul 2007 20:21:23 +0400 Subject: [PATCH 34/34] Bug#29850: Wrong charset of GROUP_CONCAT result when the select employs a temporary table. The result string of the Item_func_group_concat wasn't initialized in the copying constructor of the Item_func_group_concat class. This led to a wrong charset of GROUP_CONCAT result when the select employs a temporary table. The copying constructor of the Item_func_group_concat class now correctly initializes the charset of the result string. mysql-test/t/func_gconcat.test: Added a test case for the bug#29850: Wrong charset of the GROUP_CONCAT result when the select employs a temporary table. mysql-test/r/func_gconcat.result: Added a test case for the bug#29850: Wrong charset of the GROUP_CONCAT result when the select employs a temporary table. sql/item_sum.cc: Bug#29850: Wrong charset of GROUP_CONCAT result when the select employs a temporary table. The copying constructor of the Item_func_group_concat class now correctly initializes the charset of the result string. --- mysql-test/r/func_gconcat.result | 9 +++++++++ mysql-test/t/func_gconcat.test | 11 +++++++++++ sql/item_sum.cc | 1 + 3 files changed, 21 insertions(+) diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result index 8b71ad1940e..35487c25ae3 100644 --- a/mysql-test/r/func_gconcat.result +++ b/mysql-test/r/func_gconcat.result @@ -810,4 +810,13 @@ LENGTH( GROUP_CONCAT( a ) ) 65535 SET group_concat_max_len= DEFAULT; DROP TABLE t1, t2, t3; +set names latin1; +create table t1 (id int, name varchar(20)) DEFAULT CHARSET=utf8; +insert into t1 (id, name) values (1, "óra"); +insert into t1 (id, name) values (2, "óra"); +select b.id, group_concat(b.name) from t1 a, t1 b group by b.id; +id group_concat(b.name) +1 óra,óra +2 óra,óra +drop table t1; End of 5.0 tests diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index 767df5ae233..ff3ba951870 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -551,4 +551,15 @@ SELECT LENGTH( GROUP_CONCAT( a ) ) FROM t3 WHERE b = 3; SET group_concat_max_len= DEFAULT; DROP TABLE t1, t2, t3; +# +# Bug#29850: Wrong charset of the GROUP_CONCAT result when the select employs +# a temporary table. +# +set names latin1; +create table t1 (id int, name varchar(20)) DEFAULT CHARSET=utf8; +insert into t1 (id, name) values (1, "óra"); +insert into t1 (id, name) values (2, "óra"); +select b.id, group_concat(b.name) from t1 a, t1 b group by b.id; +drop table t1; + --echo End of 5.0 tests diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 133f00039b0..fe9f58d84e1 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -3068,6 +3068,7 @@ Item_func_group_concat::Item_func_group_concat(THD *thd, original(item) { quick_group= item->quick_group; + result.set_charset(collation.collation); }