From 015165add56c53c9aeba6a986058658e090244db Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Aug 2005 11:31:01 -0700 Subject: [PATCH 1/5] Fix parsing of dates with 'T' between date and time, as in ISO-8601 date format. (Bug #7308) mysql-test/r/type_datetime.result: Add new results mysql-test/t/type_datetime.test: Add new test sql-common/my_time.c: Fix handling of field_length for each field in date, especially for dates not in the internal_format. --- mysql-test/r/type_datetime.result | 10 ++++++++++ mysql-test/t/type_datetime.test | 10 ++++++++++ sql-common/my_time.c | 12 +++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 7b101d31fc5..8d28504d790 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -153,3 +153,13 @@ dt 0000-00-00 00:00:00 0000-00-00 00:00:00 drop table t1; +create table t1 (dt datetime); +insert into t1 values ("20010101T010101"); +insert into t1 values ("2001-01-01T01:01:01"); +insert into t1 values ("2001-1-1T1:01:01"); +select * from t1; +dt +2001-01-01 01:01:01 +2001-01-01 01:01:01 +2001-01-01 01:01:01 +drop table t1; diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index f60bc5adb16..ca70e35d3cd 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -102,4 +102,14 @@ insert into t1 values ("00-00-00"), ("00-00-00 00:00:00"); select * from t1; drop table t1; +# +# Bug #7308: ISO-8601 date format not handled correctly +# +create table t1 (dt datetime); +insert into t1 values ("20010101T010101"); +insert into t1 values ("2001-01-01T01:01:01"); +insert into t1 values ("2001-1-1T1:01:01"); +select * from t1; +drop table t1; + # End of 4.1 tests diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 8dd4801b562..1726a9a6e78 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -147,7 +147,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, { /* Found date in internal format (only numbers like YYYYMMDD) */ year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2; - field_length=year_length-1; + field_length= year_length; is_internal_format= 1; format_position= internal_format_positions; } @@ -177,6 +177,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, start_loop= 5; /* Start with first date part */ } } + + field_length= format_position[0] == 0 ? 4 : 2; } /* @@ -201,7 +203,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, const char *start= str; ulong tmp_value= (uint) (uchar) (*str++ - '0'); while (str != end && my_isdigit(&my_charset_latin1,str[0]) && - (!is_internal_format || field_length--)) + --field_length) { tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0'); str++; @@ -215,8 +217,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, date[i]=tmp_value; not_zero_date|= tmp_value; - /* Length-1 of next field */ - field_length= format_position[i+1] == 0 ? 3 : 1; + /* Length of next field */ + field_length= format_position[i+1] == 0 ? 4 : 2; if ((last_field_pos= str) == end) { @@ -234,7 +236,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, if (*str == '.') /* Followed by part seconds */ { str++; - field_length= 5; /* 5 digits after first (=6) */ + field_length= 6; /* 6 digits */ } continue; From 9942ad0108d8e94491a6e4b390b150951fecc81e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Aug 2005 17:38:55 -0700 Subject: [PATCH 2/5] Skip two tests that fail on Windows that just reflect limitations of that platform, not real failures. (Bug #12328, Bug #11569) mysql-test/t/packet.test: Skip this test on Windows mysql-test/t/rpl_flush_tables.test: Skip this test on Windows mysql-test/include/not_windows.inc: Add include for skipping tests on Windows --- mysql-test/include/not_windows.inc | 4 ++++ mysql-test/t/packet.test | 3 +++ mysql-test/t/rpl_flush_tables.test | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 mysql-test/include/not_windows.inc diff --git a/mysql-test/include/not_windows.inc b/mysql-test/include/not_windows.inc new file mode 100644 index 00000000000..54e9e0e817a --- /dev/null +++ b/mysql-test/include/not_windows.inc @@ -0,0 +1,4 @@ +--require r/true.require +disable_query_log; +select convert(@@version_compile_os using latin1) NOT IN ("Win32","Win64","Windows") as "TRUE"; +enable_query_log; diff --git a/mysql-test/t/packet.test b/mysql-test/t/packet.test index 04122b42b44..4de284b7824 100644 --- a/mysql-test/t/packet.test +++ b/mysql-test/t/packet.test @@ -1,5 +1,8 @@ # Embedded server doesn't support external clients --source include/not_embedded.inc +# Windows fails because it disconnects on too-large packets instead of just +# swallowing them and returning an error +--source include/not_windows.inc # # Check protocol handling diff --git a/mysql-test/t/rpl_flush_tables.test b/mysql-test/t/rpl_flush_tables.test index 846e2cd56ee..04158aed9e0 100644 --- a/mysql-test/t/rpl_flush_tables.test +++ b/mysql-test/t/rpl_flush_tables.test @@ -3,7 +3,10 @@ # RENAME TABLE work with MERGE tables on the slave. # Test of FLUSH NO_WRITE_TO_BINLOG by the way. # -source include/master-slave.inc; +--source include/master-slave.inc +# Skipped on Windows because it can't handle a table underlying an open +# merge table getting renamed. +--source include/not_windows.inc create table t1 (a int); insert into t1 values (10); From b2dc376afe3a3f37ab11bfa292c1bf041fd89db1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Aug 2005 18:05:33 +0400 Subject: [PATCH 3/5] Fix bug#12266 GROUP BY DATE(LEFT(column,8)) returns result strings with reduced length. When temporary field created for DATE(LEFT(column,8)) expression, max_length value is taken from Item_date_typecast, and it is getting it from underlaid Item_func_left and it's max_length is 8 in given expression. And all this results in stripping last 2 digits. To Item_date_typecast class added its own fix_length_and_dec() function that sets max_length value to 10, which is proper for DATE field. mysql-test/t/group_by.test: Test case for bug#12266 GROUP BY DATE(LEFT(column,8)) returns result strings with reduced length. mysql-test/r/group_by.result: Test case for bug#12266 GROUP BY DATE(LEFT(column,8)) returns result strings with reduced length. sql/item_timefunc.h: Fix bug#12266 GROUP BY DATE(LEFT(column,8)) returns result strings with reduced length. To Item_date_typecast class added its own fix_length_and_dec() which sets proper max_length value. --- mysql-test/r/group_by.result | 7 +++++++ mysql-test/t/group_by.test | 10 ++++++++++ sql/item_timefunc.h | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 295663fe1d3..8287a042d60 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -757,3 +757,10 @@ SELECT n+1 AS n FROM t1 GROUP BY n; n 2 DROP TABLE t1; +create table t1 (f1 date); +insert into t1 values('2005-06-06'); +insert into t1 values('2005-06-06'); +select date(left(f1+0,8)) from t1 group by 1; +date(left(f1+0,8)) +2005-06-06 +drop table t1; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index c07d309005e..815da66c717 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -590,4 +590,14 @@ INSERT INTO t1 VALUES (1); SELECT n+1 AS n FROM t1 GROUP BY n; DROP TABLE t1; +# +# Bug #12266 GROUP BY expression on DATE column produces result with +# reduced length +# +create table t1 (f1 date); +insert into t1 values('2005-06-06'); +insert into t1 values('2005-06-06'); +select date(left(f1+0,8)) from t1 group by 1; +drop table t1; + # End of 4.1 tests diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 1a30b24b7ce..0df84d14bea 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -709,6 +709,12 @@ public: { return (new Field_date(maybe_null, name, t_arg, &my_charset_bin)); } + void fix_length_and_dec() + { + collation.set(&my_charset_bin); + max_length= 10; + maybe_null= 1; + } }; From 1beb95e3e43c7ae56a75e9206fa2b904480d0604 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Aug 2005 12:45:32 -0700 Subject: [PATCH 4/5] Update test to deal with more relaxed datetime parsing. mysql-test/r/query_cache.result: Updated results mysql-test/t/query_cache.test: Change test to use a truly invalid date, now that dates like '20050327 0:0:0' are handled as they are in 4.0. --- mysql-test/r/query_cache.result | 18 +++++++++--------- mysql-test/t/query_cache.test | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index 13ba2f3b0ca..ed87e2be2b4 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -902,24 +902,24 @@ KEY `date` (`date`) ) ENGINE=MyISAM; INSERT INTO t1 VALUES ('20050326'); INSERT INTO t1 VALUES ('20050325'); -SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 0:0:0'; +SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 invalid'; COUNT(*) 0 Warnings: -Warning 1292 Truncated incorrect datetime value: '20050327 0:0:0' -Warning 1292 Truncated incorrect datetime value: '20050327 0:0:0' -SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050328 0:0:0'; +Warning 1292 Truncated incorrect datetime value: '20050327 invalid' +Warning 1292 Truncated incorrect datetime value: '20050327 invalid' +SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050328 invalid'; COUNT(*) 0 Warnings: -Warning 1292 Truncated incorrect datetime value: '20050328 0:0:0' -Warning 1292 Truncated incorrect datetime value: '20050328 0:0:0' -SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 0:0:0'; +Warning 1292 Truncated incorrect datetime value: '20050328 invalid' +Warning 1292 Truncated incorrect datetime value: '20050328 invalid' +SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 invalid'; COUNT(*) 0 Warnings: -Warning 1292 Truncated incorrect datetime value: '20050327 0:0:0' -Warning 1292 Truncated incorrect datetime value: '20050327 0:0:0' +Warning 1292 Truncated incorrect datetime value: '20050327 invalid' +Warning 1292 Truncated incorrect datetime value: '20050327 invalid' show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 0 diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index 4c2711ae833..d08dc5fb352 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -679,9 +679,9 @@ CREATE TABLE t1 ( INSERT INTO t1 VALUES ('20050326'); INSERT INTO t1 VALUES ('20050325'); -SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 0:0:0'; -SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050328 0:0:0'; -SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 0:0:0'; +SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 invalid'; +SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050328 invalid'; +SELECT COUNT(*) FROM t1 WHERE date BETWEEN '20050326' AND '20050327 invalid'; show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; show status like "Qcache_hits"; From b9e04cf1efa45a717832cd2500502edb4c318858 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 7 Aug 2005 21:03:45 +0000 Subject: [PATCH 5/5] BUG#11869: part2: post-review fixes: In init_prepare_fake_select_lex() don't empty ftfunc_list. UNION's ORDER BY clause may contain MATCH(...), for which fix_index() should be called. mysql-test/r/fulltext_order_by.result: BUG#11869 part2 : added another test case mysql-test/t/fulltext_order_by.test: BUG#11869 part2 : added another test case --- mysql-test/r/fulltext_order_by.result | 4 ++++ mysql-test/t/fulltext_order_by.test | 5 +++++ sql/sql_union.cc | 5 ++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/fulltext_order_by.result b/mysql-test/r/fulltext_order_by.result index 5f40e43f0c0..0b77153248e 100644 --- a/mysql-test/r/fulltext_order_by.result +++ b/mysql-test/r/fulltext_order_by.result @@ -163,6 +163,10 @@ text id betreff (select b.id, b.betreff from t3 b) order by match(betreff) against ('+abc' in boolean mode) desc; id betreff +(select b.id, b.betreff from t3 b) union +(select b.id, b.betreff from t3 b) +order by match(betreff) against ('+abc') desc; +ERROR HY000: Can't find FULLTEXT index matching the column list select distinct b.id, b.betreff from t3 b order by match(betreff) against ('+abc' in boolean mode) desc; id betreff diff --git a/mysql-test/t/fulltext_order_by.test b/mysql-test/t/fulltext_order_by.test index fec74b5dc54..da05fd494c4 100644 --- a/mysql-test/t/fulltext_order_by.test +++ b/mysql-test/t/fulltext_order_by.test @@ -138,6 +138,11 @@ order by (select b.id, b.betreff from t3 b) order by match(betreff) against ('+abc' in boolean mode) desc; +--error 1191 +(select b.id, b.betreff from t3 b) union +(select b.id, b.betreff from t3 b) +order by match(betreff) against ('+abc') desc; + select distinct b.id, b.betreff from t3 b order by match(betreff) against ('+abc' in boolean mode) desc; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index eeb8dfdfef5..c33444fd73e 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -132,8 +132,6 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd) options_tmp&= ~OPTION_FOUND_ROWS; else if (found_rows_for_union && !thd->lex->describe) options_tmp|= OPTION_FOUND_ROWS; - fake_select_lex->ftfunc_list_alloc.empty(); - fake_select_lex->ftfunc_list= &fake_select_lex->ftfunc_list_alloc; fake_select_lex->table_list.link_in_list((byte *)&result_table_list, (byte **) &result_table_list.next); @@ -302,7 +300,8 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, /* Force the temporary table to be a MyISAM table if we're going to use fullext functions (MATCH ... AGAINST .. IN BOOLEAN MODE) when reading - from it. + from it (this should be removed in 5.2 when fulltext search is moved + out of MyISAM). */ if (global_parameters->ftfunc_list->elements) create_options= create_options | TMP_TABLE_FORCE_MYISAM;