Commit f935c6a2 authored by unknown's avatar unknown

Fixes for binary protocol (complement to last push)

Changed timestamp to return string in YYYY-MM-DD HH:MM:SS format.
DATE_ADD() and related functions now returns correct DATE/DATETIME type depending on argument types.
Now all tests passes, still some work left to remove warnings in log files from mysql-test-run


mysql-test/r/cast.result:
  New result for time
mysql-test/r/delayed.result:
  Timestamp update
mysql-test/r/derived.result:
  Fix after bulk insert change
mysql-test/r/explain.result:
  Fix after bulk insert change
mysql-test/r/func_date_add.result:
  Timestamp change
mysql-test/r/func_str.result:
  Timestamp change
mysql-test/r/func_time.result:
  Timestamp change
mysql-test/r/innodb.result:
  Timestamp change
mysql-test/r/join_outer.result:
  Fix after bulk insert change
mysql-test/r/key_primary.result:
  Fix after bulk insert change
mysql-test/r/keywords.result:
  Timestamp change
mysql-test/r/merge.result:
  Removed warning
mysql-test/r/odbc.result:
  Fix after bulk insert change
mysql-test/r/range.result:
  Fix after bulk insert change
mysql-test/r/select.result:
  Fix after bulk insert change
mysql-test/r/subselect.result:
  Fixed EXPLAIN output
mysql-test/r/type_datetime.result:
  Timestamp update
mysql-test/r/type_ranges.result:
  Timestamp update
mysql-test/r/type_timestamp.result:
  Timestamp update
mysql-test/r/union.result:
  EXPLAIN UPDATE
mysql-test/t/func_str.test:
  Timestamp update
mysql-test/t/func_time.test:
  New test for interval type result
mysql-test/t/merge.test:
  Remove warnings of wrong drop table
mysql-test/t/type_datetime.test:
  Timestamp change
mysql-test/t/type_timestamp.test:
  Timestamp change
sql/field.cc:
  Changed timestamp to return string in YYYY-MM-DD HH:MM:SS format
sql/field.h:
  Changed timestamp to return string in YYYY-MM-DD HH:MM:SS format
sql/item.cc:
  Binary protocol update
sql/item.h:
  Binary protocol update
sql/item_func.cc:
  Added comment
sql/item_func.h:
  @variables are always returned to the client as strings
sql/item_timefunc.cc:
  Changed INTERVAL to return correct type
sql/item_timefunc.h:
  Changed INTERVAL to return correct type
sql/mysqld.cc:
  Changed default pthread_attr_setstacksize to 129K
sql/protocol.cc:
  More type checking
sql/set_var.cc:
  Fixed that @convert works ok with new protocol
sql/sql_analyse.cc:
  Fixed bug in analyze
sql/sql_class.cc:
  Fixed bug from last push in LIMIT
sql/sql_error.cc:
  More optimal types
sql/sql_repl.cc:
  Binary protocol changes
sql/sql_select.cc:
  Fixed bug in multi-table-update
  Changed EXPLAIN to return NULL instead of empty strings
sql/sql_show.cc:
  Binary protocol
parent 4a817065
...@@ -27,7 +27,7 @@ cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME) ...@@ -27,7 +27,7 @@ cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME)
2001-01-01 2001-01-01 00:00:00 2001-01-01 2001-01-01 00:00:00
select cast("1:2:3" as TIME); select cast("1:2:3" as TIME);
cast("1:2:3" as TIME) cast("1:2:3" as TIME)
1:02:03 01:02:03
select cast("2001-1-1" as date) = "2001-01-01"; select cast("2001-1-1" as date) = "2001-01-01";
cast("2001-1-1" as date) = "2001-01-01" cast("2001-1-1" as date) = "2001-01-01"
0 0
......
...@@ -12,9 +12,9 @@ select * from t1 where tmsp=0; ...@@ -12,9 +12,9 @@ select * from t1 where tmsp=0;
a tmsp a tmsp
select * from t1 where tmsp=19711006010203; select * from t1 where tmsp=19711006010203;
a tmsp a tmsp
5 19711006010203 5 1971-10-06 01:02:03
6 19711006010203 6 1971-10-06 01:02:03
8 19711006010203 8 1971-10-06 01:02:03
drop table t1; drop table t1;
create table t1 (a int not null auto_increment primary key, b char(10)); create table t1 (a int not null auto_increment primary key, b char(10));
insert delayed into t1 values (1,"b"); insert delayed into t1 values (1,"b");
......
...@@ -89,7 +89,7 @@ a t ...@@ -89,7 +89,7 @@ a t
20 20 20 20
explain select count(*) from t1 as tt1, (select * from t1) as tt2; explain select count(*) from t1 as tt1, (select * from t1) as tt2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY Select tables optimized away 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
2 DERIVED tt1 index NULL a 4 NULL 10000 Using index 2 DERIVED tt1 index NULL a 4 NULL 10000 Using index
drop table if exists t1; drop table if exists t1;
SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b; SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
......
...@@ -27,4 +27,4 @@ Key column 'foo' doesn't exist in table ...@@ -27,4 +27,4 @@ Key column 'foo' doesn't exist in table
drop table t1; drop table t1;
explain select 1; explain select 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
...@@ -31,17 +31,17 @@ INSERT INTO t1 VALUES (357917728,7,2,2,20000319145027); ...@@ -31,17 +31,17 @@ INSERT INTO t1 VALUES (357917728,7,2,2,20000319145027);
select visitor_id,max(ts) as mts from t1 group by visitor_id select visitor_id,max(ts) as mts from t1 group by visitor_id
having mts < DATE_SUB(NOW(),INTERVAL 3 MONTH); having mts < DATE_SUB(NOW(),INTERVAL 3 MONTH);
visitor_id mts visitor_id mts
48985536 20000319013932 48985536 2000-03-19 01:39:32
173865424 20000318233615 173865424 2000-03-18 23:36:15
357917728 20000319145027 357917728 2000-03-19 14:50:27
465931136 20000318160953 465931136 2000-03-18 16:09:53
1092858576 20000319013445 1092858576 2000-03-19 01:34:45
select visitor_id,max(ts) as mts from t1 group by visitor_id select visitor_id,max(ts) as mts from t1 group by visitor_id
having DATE_ADD(mts,INTERVAL 3 MONTH) < NOW(); having DATE_ADD(mts,INTERVAL 3 MONTH) < NOW();
visitor_id mts visitor_id mts
48985536 20000319013932 48985536 2000-03-19 01:39:32
173865424 20000318233615 173865424 2000-03-18 23:36:15
357917728 20000319145027 357917728 2000-03-19 14:50:27
465931136 20000318160953 465931136 2000-03-18 16:09:53
1092858576 20000319013445 1092858576 2000-03-19 01:34:45
drop table t1; drop table t1;
...@@ -213,14 +213,14 @@ bugstatus int(10) unsigned default NULL, ...@@ -213,14 +213,14 @@ bugstatus int(10) unsigned default NULL,
submitter int(10) unsigned default NULL submitter int(10) unsigned default NULL
) TYPE=MyISAM; ) TYPE=MyISAM;
INSERT INTO t1 VALUES (1,'Link',1,1,1,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','2001-02-28 08:40:16',20010228084016,0,4); INSERT INTO t1 VALUES (1,'Link',1,1,1,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','2001-02-28 08:40:16',20010228084016,0,4);
SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter), '"') FROM t1; SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter), '"') FROM t1;
CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter), '"') CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter), '"')
"Link";"1";"1";"1";"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";"2001-02-28 08:40:16";"20010228084016";"0";"4" "Link";"1";"1";"1";"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";"2001-02-28 08:40:16";"20010228084016";"0";"4"
SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') FROM t1; SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') FROM t1;
CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"')
"Link";"1";"1";"1";"0";"4" "Link";"1";"1";"1";"0";"4"
SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter) FROM t1; SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter) FROM t1;
CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter) CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter)
Link";"1";"1";"1";"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";"2001-02-28 08:40:16";"20010228084016";"0";"4 Link";"1";"1";"1";"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";"2001-02-28 08:40:16";"20010228084016";"0";"4
drop table t1; drop table t1;
CREATE TABLE t1 (id int(11) NOT NULL auto_increment, tmp text NOT NULL, KEY id (id)) TYPE=MyISAM; CREATE TABLE t1 (id int(11) NOT NULL auto_increment, tmp text NOT NULL, KEY id (id)) TYPE=MyISAM;
......
...@@ -392,11 +392,71 @@ CREATE TABLE t3 (ctime1 char(19) NOT NULL, ctime2 char(19) NOT NULL); ...@@ -392,11 +392,71 @@ CREATE TABLE t3 (ctime1 char(19) NOT NULL, ctime2 char(19) NOT NULL);
INSERT INTO t3 VALUES ("2002-10-29 16:51:06","2002-11-05 16:47:31"); INSERT INTO t3 VALUES ("2002-10-29 16:51:06","2002-11-05 16:47:31");
select * from t1, t2 where t1.start between t2.ctime1 and t2.ctime2; select * from t1, t2 where t1.start between t2.ctime1 and t2.ctime2;
start ctime1 ctime2 start ctime1 ctime2
2002-11-04 00:00:00 20021029165106 20021105164731 2002-11-04 00:00:00 2002-10-29 16:51:06 2002-11-05 16:47:31
select * from t1, t2 where t1.start >= t2.ctime1 and t1.start <= t2.ctime2; select * from t1, t2 where t1.start >= t2.ctime1 and t1.start <= t2.ctime2;
start ctime1 ctime2 start ctime1 ctime2
2002-11-04 00:00:00 20021029165106 20021105164731 2002-11-04 00:00:00 2002-10-29 16:51:06 2002-11-05 16:47:31
select * from t1, t3 where t1.start between t3.ctime1 and t3.ctime2; select * from t1, t3 where t1.start between t3.ctime1 and t3.ctime2;
start ctime1 ctime2 start ctime1 ctime2
2002-11-04 00:00:00 2002-10-29 16:51:06 2002-11-05 16:47:31 2002-11-04 00:00:00 2002-10-29 16:51:06 2002-11-05 16:47:31
drop table t1,t2,t3; drop table t1,t2,t3;
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date, time time);
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02", "06:07:08");
SELECT * from t1;
datetime timestamp date time
2001-01-02 03:04:05 2002-01-02 03:04:05 2003-01-02 06:07:08
select date_add("1997-12-31",INTERVAL 1 SECOND);
date_add("1997-12-31",INTERVAL 1 SECOND)
1997-12-31 00:00:01
select date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH);
date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH)
1999-01-31
select date_add(datetime, INTERVAL 1 SECOND) from t1;
date_add(datetime, INTERVAL 1 SECOND)
2001-01-02 03:04:06
select date_add(datetime, INTERVAL 1 YEAR) from t1;
date_add(datetime, INTERVAL 1 YEAR)
2002-01-02 03:04:05
select date_add(date,INTERVAL 1 SECOND) from t1;
date_add(date,INTERVAL 1 SECOND)
2003-01-02 00:00:01
select date_add(date,INTERVAL 1 MINUTE) from t1;
date_add(date,INTERVAL 1 MINUTE)
2003-01-02 00:01:00
select date_add(date,INTERVAL 1 HOUR) from t1;
date_add(date,INTERVAL 1 HOUR)
2003-01-02 01:00:00
select date_add(date,INTERVAL 1 DAY) from t1;
date_add(date,INTERVAL 1 DAY)
2003-01-03
select date_add(date,INTERVAL 1 MONTH) from t1;
date_add(date,INTERVAL 1 MONTH)
2003-02-02
select date_add(date,INTERVAL 1 YEAR) from t1;
date_add(date,INTERVAL 1 YEAR)
2004-01-02
select date_add(date,INTERVAL "1:1" MINUTE_SECOND) from t1;
date_add(date,INTERVAL "1:1" MINUTE_SECOND)
2003-01-02 00:01:01
select date_add(date,INTERVAL "1:1" HOUR_MINUTE) from t1;
date_add(date,INTERVAL "1:1" HOUR_MINUTE)
2003-01-02 01:01:00
select date_add(date,INTERVAL "1:1" DAY_HOUR) from t1;
date_add(date,INTERVAL "1:1" DAY_HOUR)
2003-01-03 01:00:00
select date_add(date,INTERVAL "1 1" YEAR_MONTH) from t1;
date_add(date,INTERVAL "1 1" YEAR_MONTH)
2004-02-02
select date_add(date,INTERVAL "1:1:1" HOUR_SECOND) from t1;
date_add(date,INTERVAL "1:1:1" HOUR_SECOND)
2003-01-02 01:01:01
select date_add(date,INTERVAL "1 1:1" DAY_MINUTE) from t1;
date_add(date,INTERVAL "1 1:1" DAY_MINUTE)
2003-01-03 01:01:00
select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
date_add(date,INTERVAL "1 1:1:1" DAY_SECOND)
2003-01-03 01:01:01
select date_add(time,INTERVAL 1 SECOND) from t1;
date_add(time,INTERVAL 1 SECOND)
2006-07-08 00:00:01
drop table t1;
...@@ -959,29 +959,29 @@ INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,0000000000000 ...@@ -959,29 +959,29 @@ INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,0000000000000
INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0); INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
select * from t1; select * from t1;
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
4077711111 SeanWheeler 90 2 20020111112846 500 00000000000000 -1 2 3 1 4077711111 SeanWheeler 90 2 2002-01-11 11:28:46 500 0000-00-00 00:00:00 -1 2 3 1
9197722223 berry 90 3 20020111112809 500 20020102114532 501 4 10 0 9197722223 berry 90 3 2002-01-11 11:28:09 500 2002-01-02 11:45:32 501 4 10 0
650 San Francisco 0 0 20011227111336 342 00000000000000 -1 1 24 1 650 San Francisco 0 0 2001-12-27 11:13:36 342 0000-00-00 00:00:00 -1 1 24 1
302467 Sue's Subshop 90 3 20020109113241 500 20020102115111 501 7 24 0 302467 Sue's Subshop 90 3 2002-01-09 11:32:41 500 2002-01-02 11:51:11 501 7 24 0
6014911113 SudzCarwash 520 1 20020102115234 500 20020102115259 501 33 32768 0 6014911113 SudzCarwash 520 1 2002-01-02 11:52:34 500 2002-01-02 11:52:59 501 33 32768 0
333 tubs 99 2 20020109113440 501 20020109113440 500 3 10 0 333 tubs 99 2 2002-01-09 11:34:40 501 2002-01-09 11:34:40 500 3 10 0
select * from t2; select * from t2;
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
4077711111 SeanWheeler 0 2 20020111112853 500 00000000000000 -1 2 3 1 4077711111 SeanWheeler 0 2 2002-01-11 11:28:53 500 0000-00-00 00:00:00 -1 2 3 1
9197722223 berry 90 3 20020111112818 500 20020102114532 501 4 10 0 9197722223 berry 90 3 2002-01-11 11:28:18 500 2002-01-02 11:45:32 501 4 10 0
650 San Francisco 90 0 20020109113158 342 00000000000000 -1 1 24 1 650 San Francisco 90 0 2002-01-09 11:31:58 342 0000-00-00 00:00:00 -1 1 24 1
333 tubs 99 2 20020109113453 501 20020109113453 500 3 10 0 333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or (t1.carrier_id=90 and t2.number is null); delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or (t1.carrier_id=90 and t2.number is null);
select * from t1; select * from t1;
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
6014911113 SudzCarwash 520 1 20020102115234 500 20020102115259 501 33 32768 0 6014911113 SudzCarwash 520 1 2002-01-02 11:52:34 500 2002-01-02 11:52:59 501 33 32768 0
333 tubs 99 2 20020109113440 501 20020109113440 500 3 10 0 333 tubs 99 2 2002-01-09 11:34:40 501 2002-01-09 11:34:40 500 3 10 0
select * from t2; select * from t2;
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
333 tubs 99 2 20020109113453 501 20020109113453 500 3 10 0 333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
select * from t2; select * from t2;
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
333 tubs 99 2 20020109113453 501 20020109113453 500 3 10 0 333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
drop table t1,t2; drop table t1,t2;
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) type=innodb; create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) type=innodb;
BEGIN; BEGIN;
......
...@@ -91,7 +91,7 @@ grp a c id a c d ...@@ -91,7 +91,7 @@ grp a c id a c d
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Impossible WHERE noticed after reading const tables 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 1 SIMPLE t1 ALL NULL NULL NULL NULL 7
......
...@@ -16,5 +16,5 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -16,5 +16,5 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 3 const 1 1 SIMPLE t1 const PRIMARY PRIMARY 3 const 1
describe select * from t1 where t1="ABCD"; describe select * from t1 where t1="ABCD";
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Impossible WHERE noticed after reading const tables 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
drop table t1; drop table t1;
...@@ -3,7 +3,7 @@ create table t1 (time time, date date, timestamp timestamp); ...@@ -3,7 +3,7 @@ create table t1 (time time, date date, timestamp timestamp);
insert into t1 values ("12:22:22","97:02:03","1997-01-02"); insert into t1 values ("12:22:22","97:02:03","1997-01-02");
select * from t1; select * from t1;
time date timestamp time date timestamp
12:22:22 1997-02-03 19970102000000 12:22:22 1997-02-03 1997-01-02 00:00:00
select t1.time+0,t1.date+0,t1.timestamp+0,concat(date," ",time) from t1; select t1.time+0,t1.date+0,t1.timestamp+0,concat(date," ",time) from t1;
t1.time+0 t1.date+0 t1.timestamp+0 concat(date," ",time) t1.time+0 t1.date+0 t1.timestamp+0 concat(date," ",time)
122222 19970203 19970102000000 1997-02-03 12:22:22 122222 19970203 19970102000000 1997-02-03 12:22:22
......
...@@ -560,7 +560,7 @@ select * from t6; ...@@ -560,7 +560,7 @@ select * from t6;
a a
1 1
2 2
drop table if exists t1, t2, t3, t4, t5, t6; drop table if exists t6, t3, t1, t2, t4, t5;
DROP TABLE IF EXISTS t1, t2; DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 ( CREATE TABLE t1 (
fileset_id tinyint(3) unsigned NOT NULL default '0', fileset_id tinyint(3) unsigned NOT NULL default '0',
...@@ -595,4 +595,4 @@ EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2 ...@@ -595,4 +595,4 @@ EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code = '0000000115' LIMIT 1; AND file_code = '0000000115' LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY,files PRIMARY 33 const,const 1 1 SIMPLE t2 const PRIMARY,files PRIMARY 33 const,const 1
DROP TABLE IF EXISTS t1, t2; DROP TABLE IF EXISTS t2, t1;
...@@ -12,5 +12,5 @@ select * from t1 where a is null; ...@@ -12,5 +12,5 @@ select * from t1 where a is null;
a b a b
explain select * from t1 where b is null; explain select * from t1 where b is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Impossible WHERE noticed after reading const tables 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
drop table t1; drop table t1;
...@@ -16,7 +16,7 @@ event_date type event_id ...@@ -16,7 +16,7 @@ event_date type event_id
1999-07-14 100600 10 1999-07-14 100600 10
explain select event_date,type,event_id from t1 WHERE type = 100601 and event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date; explain select event_date,type,event_id from t1 WHERE type = 100601 and event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Impossible WHERE 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND (type=100600 OR type=100100) or event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND type=100099; select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND (type=100600 OR type=100100) or event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND type=100099;
event_date type event_id event_date type event_id
1999-07-10 100100 24 1999-07-10 100100 24
......
...@@ -3097,7 +3097,7 @@ fld1 sum(price) ...@@ -3097,7 +3097,7 @@ fld1 sum(price)
038008 234298 038008 234298
explain select fld3 from t2 where 1>2 or 2>3; explain select fld3 from t2 where 1>2 or 2>3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Impossible WHERE 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
explain select fld3 from t2 where fld1=fld1; explain select fld3 from t2 where fld1=fld1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
...@@ -3152,7 +3152,7 @@ count(*) ...@@ -3152,7 +3152,7 @@ count(*)
4181 4181
explain select min(fld1),max(fld1),count(*) from t2; explain select min(fld1),max(fld1),count(*) from t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Select tables optimized away 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
select min(fld1),max(fld1),count(*) from t2; select min(fld1),max(fld1),count(*) from t2;
min(fld1) max(fld1) count(*) min(fld1) max(fld1) count(*)
0 1232609 1199 0 1232609 1199
......
...@@ -20,8 +20,8 @@ Reference 'a' not supported (forward reference in item list) ...@@ -20,8 +20,8 @@ Reference 'a' not supported (forward reference in item list)
EXPLAIN SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; EXPLAIN SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 1 PRIMARY <derived2> system NULL NULL NULL NULL 1
3 DEPENDENT SUBSELECT No tables used 3 DEPENDENT SUBSELECT NULL NULL NULL NULL NULL NULL NULL No tables used
2 DERIVED No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1 1
1 1
...@@ -280,7 +280,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -280,7 +280,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 41 NULL 2 Using where; Using index 1 SIMPLE t1 index NULL PRIMARY 41 NULL 2 Using where; Using index
EXPLAIN SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); EXPLAIN SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY No tables used 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
2 SUBSELECT t1 index NULL PRIMARY 41 NULL 2 Using where; Using index 2 SUBSELECT t1 index NULL PRIMARY 41 NULL 2 Using where; Using index
SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
date date
...@@ -298,8 +298,8 @@ Subselect returns more than 1 record ...@@ -298,8 +298,8 @@ Subselect returns more than 1 record
EXPLAIN SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1); EXPLAIN SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL topic 3 NULL 2 Using index 1 PRIMARY t1 index NULL topic 3 NULL 2 Using index
2 SUBSELECT No tables used 2 SUBSELECT NULL NULL NULL NULL NULL NULL NULL No tables used
3 UNION No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
drop table t1; drop table t1;
CREATE TABLE `t1` ( CREATE TABLE `t1` (
`numeropost` mediumint(8) unsigned NOT NULL auto_increment, `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
...@@ -394,11 +394,11 @@ EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 ...@@ -394,11 +394,11 @@ EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1
Subselect returns more than 1 record Subselect returns more than 1 record
EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Select tables optimized away 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1
2 SUBSELECT Select tables optimized away 2 SUBSELECT NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
drop table t1; drop table t1;
CREATE TABLE t1 (a int(1)); CREATE TABLE t1 (a int(1));
INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (1);
...@@ -574,14 +574,14 @@ id ...@@ -574,14 +574,14 @@ id
EXPLAIN SELECT * FROM t WHERE id IN (SELECT 1+(select 1)); EXPLAIN SELECT * FROM t WHERE id IN (SELECT 1+(select 1));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t ref id id 5 const 1 Using where; Using index 1 PRIMARY t ref id id 5 const 1 Using where; Using index
3 SUBSELECT No tables used 3 SUBSELECT NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1247 Select 2 was reduced during optimisation Note 1247 Select 2 was reduced during optimisation
EXPLAIN SELECT * FROM t WHERE id IN (SELECT 1 UNION SELECT 3); EXPLAIN SELECT * FROM t WHERE id IN (SELECT 1 UNION SELECT 3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t index NULL id 5 NULL 2 Using where; Using index 1 PRIMARY t index NULL id 5 NULL 2 Using where; Using index
2 DEPENDENT SUBSELECT No tables used 2 DEPENDENT SUBSELECT NULL NULL NULL NULL NULL NULL NULL No tables used
3 UNION No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
SELECT * FROM t WHERE id IN (SELECT 5 UNION SELECT 3); SELECT * FROM t WHERE id IN (SELECT 5 UNION SELECT 3);
id id
SELECT * FROM t WHERE id IN (SELECT 5 UNION SELECT 2); SELECT * FROM t WHERE id IN (SELECT 5 UNION SELECT 2);
......
...@@ -41,8 +41,8 @@ t ...@@ -41,8 +41,8 @@ t
drop table t1; drop table t1;
CREATE TABLE t1 (a timestamp, b date, c time, d datetime); CREATE TABLE t1 (a timestamp, b date, c time, d datetime);
insert into t1 (b,c,d) values(now(),curtime(),now()); insert into t1 (b,c,d) values(now(),curtime(),now());
select date_format(a,"%Y-%m-%d")=b,right(a,6)=c+0,a=d+0 from t1; select date_format(a,"%Y-%m-%d")=b,right(a+0,6)=c+0,a=d+0 from t1;
date_format(a,"%Y-%m-%d")=b right(a,6)=c+0 a=d+0 date_format(a,"%Y-%m-%d")=b right(a+0,6)=c+0 a=d+0
1 1 1 1 1 1
drop table t1; drop table t1;
CREATE TABLE t1 (a datetime not null); CREATE TABLE t1 (a datetime not null);
......
...@@ -53,7 +53,7 @@ ushort smallint(5) unsigned zerofill MUL 00000 select,insert,update,references ...@@ -53,7 +53,7 @@ ushort smallint(5) unsigned zerofill MUL 00000 select,insert,update,references
umedium mediumint(8) unsigned MUL 0 select,insert,update,references umedium mediumint(8) unsigned MUL 0 select,insert,update,references
ulong int(11) unsigned MUL 0 select,insert,update,references ulong int(11) unsigned MUL 0 select,insert,update,references
ulonglong bigint(13) unsigned MUL 0 select,insert,update,references ulonglong bigint(13) unsigned MUL 0 select,insert,update,references
time_stamp timestamp(14) YES NULL select,insert,update,references time_stamp timestamp YES NULL select,insert,update,references
date_field date YES NULL select,insert,update,references date_field date YES NULL select,insert,update,references
time_field time YES NULL select,insert,update,references time_field time YES NULL select,insert,update,references
date_time datetime YES NULL select,insert,update,references date_time datetime YES NULL select,insert,update,references
...@@ -183,7 +183,7 @@ ushort smallint(5) unsigned zerofill 00000 select,insert,update,references ...@@ -183,7 +183,7 @@ ushort smallint(5) unsigned zerofill 00000 select,insert,update,references
umedium mediumint(8) unsigned MUL 0 select,insert,update,references umedium mediumint(8) unsigned MUL 0 select,insert,update,references
ulong int(11) unsigned MUL 0 select,insert,update,references ulong int(11) unsigned MUL 0 select,insert,update,references
ulonglong bigint(13) unsigned MUL 0 select,insert,update,references ulonglong bigint(13) unsigned MUL 0 select,insert,update,references
time_stamp timestamp(14) YES NULL select,insert,update,references time_stamp timestamp YES NULL select,insert,update,references
date_field varchar(10) character set latin1 YES NULL select,insert,update,references date_field varchar(10) character set latin1 YES NULL select,insert,update,references
time_field time YES NULL select,insert,update,references time_field time YES NULL select,insert,update,references
date_time datetime YES NULL select,insert,update,references date_time datetime YES NULL select,insert,update,references
...@@ -209,7 +209,7 @@ ushort smallint(5) unsigned zerofill 00000 select,insert,update,references ...@@ -209,7 +209,7 @@ ushort smallint(5) unsigned zerofill 00000 select,insert,update,references
umedium mediumint(8) unsigned 0 select,insert,update,references umedium mediumint(8) unsigned 0 select,insert,update,references
ulong int(11) unsigned 0 select,insert,update,references ulong int(11) unsigned 0 select,insert,update,references
ulonglong bigint(13) unsigned 0 select,insert,update,references ulonglong bigint(13) unsigned 0 select,insert,update,references
time_stamp timestamp(14) YES NULL select,insert,update,references time_stamp timestamp YES NULL select,insert,update,references
date_field varchar(10) character set latin1 YES NULL select,insert,update,references date_field varchar(10) character set latin1 YES NULL select,insert,update,references
time_field time YES NULL select,insert,update,references time_field time YES NULL select,insert,update,references
date_time datetime YES NULL select,insert,update,references date_time datetime YES NULL select,insert,update,references
......
...@@ -15,26 +15,26 @@ SET TIMESTAMP=1238; ...@@ -15,26 +15,26 @@ SET TIMESTAMP=1238;
insert into t1 (a) select a+1 from t2 where a=8; insert into t1 (a) select a+1 from t2 where a=8;
select * from t1; select * from t1;
a t a t
1 19700101032034 1 1970-01-01 03:20:34
2 20020303000000 2 2002-03-03 00:00:00
3 19700101032035 3 1970-01-01 03:20:35
4 19700101032036 4 1970-01-01 03:20:36
5 20020304000000 5 2002-03-04 00:00:00
6 19700101032037 6 1970-01-01 03:20:37
7 20020305000000 7 2002-03-05 00:00:00
8 00000000000000 8 0000-00-00 00:00:00
9 19700101032038 9 1970-01-01 03:20:38
drop table t1,t2; drop table t1,t2;
SET TIMESTAMP=1234; SET TIMESTAMP=1234;
CREATE TABLE t1 (value TEXT NOT NULL, id VARCHAR(32) NOT NULL, stamp timestamp, PRIMARY KEY (id)); CREATE TABLE t1 (value TEXT NOT NULL, id VARCHAR(32) NOT NULL, stamp timestamp, PRIMARY KEY (id));
INSERT INTO t1 VALUES ("my value", "myKey","1999-04-02 00:00:00"); INSERT INTO t1 VALUES ("my value", "myKey","1999-04-02 00:00:00");
SELECT stamp FROM t1 WHERE id="myKey"; SELECT stamp FROM t1 WHERE id="myKey";
stamp stamp
19990402000000 1999-04-02 00:00:00
UPDATE t1 SET value="my value" WHERE id="myKey"; UPDATE t1 SET value="my value" WHERE id="myKey";
SELECT stamp FROM t1 WHERE id="myKey"; SELECT stamp FROM t1 WHERE id="myKey";
stamp stamp
19990402000000 1999-04-02 00:00:00
drop table t1; drop table t1;
create table t1 (a timestamp); create table t1 (a timestamp);
insert into t1 values (now()); insert into t1 values (now());
...@@ -44,8 +44,8 @@ date_format(a,"%Y %y") year(a) year(now()) ...@@ -44,8 +44,8 @@ date_format(a,"%Y %y") year(a) year(now())
drop table t1; drop table t1;
create table t1 (ix timestamp); create table t1 (ix timestamp);
insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000); insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000);
select * from t1; select ix+0 from t1;
ix ix+0
19991101000000 19991101000000
19990102030405 19990102030405
19990630232922 19990630232922
...@@ -71,16 +71,16 @@ INSERT INTO t1 VALUES ("2005-01-01","2005-01-01 00:00:00",20050101000000); ...@@ -71,16 +71,16 @@ INSERT INTO t1 VALUES ("2005-01-01","2005-01-01 00:00:00",20050101000000);
INSERT INTO t1 VALUES ("2030-01-01","2030-01-01 00:00:00",20300101000000); INSERT INTO t1 VALUES ("2030-01-01","2030-01-01 00:00:00",20300101000000);
SELECT * FROM t1; SELECT * FROM t1;
date date_time time_stamp date date_time time_stamp
1998-12-31 1998-12-31 23:59:59 19981231235959 1998-12-31 1998-12-31 23:59:59 1998-12-31 23:59:59
1999-01-01 1999-01-01 00:00:00 19990101000000 1999-01-01 1999-01-01 00:00:00 1999-01-01 00:00:00
1999-09-09 1999-09-09 23:59:59 19990909235959 1999-09-09 1999-09-09 23:59:59 1999-09-09 23:59:59
2000-01-01 2000-01-01 00:00:00 20000101000000 2000-01-01 2000-01-01 00:00:00 2000-01-01 00:00:00
2000-02-28 2000-02-28 00:00:00 20000228000000 2000-02-28 2000-02-28 00:00:00 2000-02-28 00:00:00
2000-02-29 2000-02-29 00:00:00 20000229000000 2000-02-29 2000-02-29 00:00:00 2000-02-29 00:00:00
2000-03-01 2000-03-01 00:00:00 20000301000000 2000-03-01 2000-03-01 00:00:00 2000-03-01 00:00:00
2000-12-31 2000-12-31 23:59:59 20001231235959 2000-12-31 2000-12-31 23:59:59 2000-12-31 23:59:59
2001-01-01 2001-01-01 00:00:00 20010101000000 2001-01-01 2001-01-01 00:00:00 2001-01-01 00:00:00
2004-12-31 2004-12-31 23:59:59 20041231235959 2004-12-31 2004-12-31 23:59:59 2004-12-31 23:59:59
2005-01-01 2005-01-01 00:00:00 20050101000000 2005-01-01 2005-01-01 00:00:00 2005-01-01 00:00:00
2030-01-01 2030-01-01 00:00:00 20300101000000 2030-01-01 2030-01-01 00:00:00 2030-01-01 00:00:00
drop table t1; drop table t1;
...@@ -102,16 +102,16 @@ Unknown column 'xx' in 'field list' ...@@ -102,16 +102,16 @@ Unknown column 'xx' in 'field list'
explain select a,b from t1 union select 1; explain select a,b from t1 union select 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 UNION No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
explain select 1 union select a,b from t1 union select 1; explain select 1 union select a,b from t1 union select 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY No tables used 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
2 UNION t1 ALL NULL NULL NULL NULL 4 2 UNION t1 ALL NULL NULL NULL NULL 4
3 UNION No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
explain select a,b from t1 union select 1 limit 0; explain select a,b from t1 union select 1 limit 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY Impossible WHERE 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 UNION Impossible WHERE 2 UNION NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
select a,b from t1 into outfile 'skr' union select a,b from t2; select a,b from t1 into outfile 'skr' union select a,b from t2;
Wrong usage of UNION and INTO Wrong usage of UNION and INTO
select a,b from t1 order by a union select a,b from t2; select a,b from t1 order by a union select a,b from t2;
......
...@@ -110,9 +110,9 @@ CREATE TABLE t1 ( ...@@ -110,9 +110,9 @@ CREATE TABLE t1 (
) TYPE=MyISAM; ) TYPE=MyISAM;
INSERT INTO t1 VALUES (1,'Link',1,1,1,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','2001-02-28 08:40:16',20010228084016,0,4); INSERT INTO t1 VALUES (1,'Link',1,1,1,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','2001-02-28 08:40:16',20010228084016,0,4);
SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter), '"') FROM t1; SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter), '"') FROM t1;
SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') FROM t1; SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') FROM t1;
SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter) FROM t1; SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter) FROM t1;
drop table t1; drop table t1;
# #
......
...@@ -183,3 +183,34 @@ select * from t1, t2 where t1.start between t2.ctime1 and t2.ctime2; ...@@ -183,3 +183,34 @@ select * from t1, t2 where t1.start between t2.ctime1 and t2.ctime2;
select * from t1, t2 where t1.start >= t2.ctime1 and t1.start <= t2.ctime2; select * from t1, t2 where t1.start >= t2.ctime1 and t1.start <= t2.ctime2;
select * from t1, t3 where t1.start between t3.ctime1 and t3.ctime2; select * from t1, t3 where t1.start between t3.ctime1 and t3.ctime2;
drop table t1,t2,t3; drop table t1,t2,t3;
#
# Test types from + INTERVAL
#
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date, time time);
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02", "06:07:08");
SELECT * from t1;
select date_add("1997-12-31",INTERVAL 1 SECOND);
select date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH);
select date_add(datetime, INTERVAL 1 SECOND) from t1;
select date_add(datetime, INTERVAL 1 YEAR) from t1;
select date_add(date,INTERVAL 1 SECOND) from t1;
select date_add(date,INTERVAL 1 MINUTE) from t1;
select date_add(date,INTERVAL 1 HOUR) from t1;
select date_add(date,INTERVAL 1 DAY) from t1;
select date_add(date,INTERVAL 1 MONTH) from t1;
select date_add(date,INTERVAL 1 YEAR) from t1;
select date_add(date,INTERVAL "1:1" MINUTE_SECOND) from t1;
select date_add(date,INTERVAL "1:1" HOUR_MINUTE) from t1;
select date_add(date,INTERVAL "1:1" DAY_HOUR) from t1;
select date_add(date,INTERVAL "1 1" YEAR_MONTH) from t1;
select date_add(date,INTERVAL "1:1:1" HOUR_SECOND) from t1;
select date_add(date,INTERVAL "1 1:1" DAY_MINUTE) from t1;
select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
# The following is not as one would expect...
select date_add(time,INTERVAL 1 SECOND) from t1;
drop table t1;
...@@ -202,7 +202,7 @@ insert into t4 values (1); ...@@ -202,7 +202,7 @@ insert into t4 values (1);
insert into t5 values (2); insert into t5 values (2);
create temporary table t6 (a int not null) TYPE=MERGE UNION=(t4,t5); create temporary table t6 (a int not null) TYPE=MERGE UNION=(t4,t5);
select * from t6; select * from t6;
drop table if exists t1, t2, t3, t4, t5, t6; drop table if exists t6, t3, t1, t2, t4, t5;
# #
# testing merge::records_in_range and optimizer # testing merge::records_in_range and optimizer
...@@ -235,5 +235,5 @@ EXPLAIN SELECT * FROM t1 WHERE fileset_id = 2 ...@@ -235,5 +235,5 @@ EXPLAIN SELECT * FROM t1 WHERE fileset_id = 2
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1; AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2 EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code = '0000000115' LIMIT 1; AND file_code = '0000000115' LIMIT 1;
DROP TABLE IF EXISTS t1, t2; DROP TABLE IF EXISTS t2, t1;
...@@ -19,7 +19,7 @@ drop table t1; ...@@ -19,7 +19,7 @@ drop table t1;
CREATE TABLE t1 (a timestamp, b date, c time, d datetime); CREATE TABLE t1 (a timestamp, b date, c time, d datetime);
insert into t1 (b,c,d) values(now(),curtime(),now()); insert into t1 (b,c,d) values(now(),curtime(),now());
select date_format(a,"%Y-%m-%d")=b,right(a,6)=c+0,a=d+0 from t1; select date_format(a,"%Y-%m-%d")=b,right(a+0,6)=c+0,a=d+0 from t1;
drop table t1; drop table t1;
# #
......
...@@ -35,7 +35,7 @@ drop table t1; ...@@ -35,7 +35,7 @@ drop table t1;
create table t1 (ix timestamp); create table t1 (ix timestamp);
insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000); insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000);
select * from t1; select ix+0 from t1;
drop table t1; drop table t1;
CREATE TABLE t1 (date date, date_time datetime, time_stamp timestamp); CREATE TABLE t1 (date date, date_time datetime, time_stamp timestamp);
......
...@@ -2585,10 +2585,10 @@ void Field_double::sql_type(String &res) const ...@@ -2585,10 +2585,10 @@ void Field_double::sql_type(String &res) const
Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg, Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg,
enum utype unireg_check_arg, enum utype unireg_check_arg,
const char *field_name_arg, const char *field_name_arg,
struct st_table *table_arg) struct st_table *table_arg,
:Field_num(ptr_arg, len_arg, (uchar*) 0,0, CHARSET_INFO *cs)
unireg_check_arg, field_name_arg, table_arg, :Field_str(ptr_arg, 19, (uchar*) 0,0,
0, 1, 1) unireg_check_arg, field_name_arg, table_arg, cs)
{ {
if (table && !table->timestamp_field) if (table && !table->timestamp_field)
{ {
...@@ -2613,35 +2613,6 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -2613,35 +2613,6 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs)
return 0; return 0;
} }
void Field_timestamp::fill_and_store(char *from,uint len)
{
uint res_length;
if (len <= field_length)
res_length=field_length;
else if (len <= 12)
res_length=12; /* purecov: inspected */
else if (len <= 14)
res_length=14; /* purecov: inspected */
else
res_length=(len+1)/2*2; // must be even
if (res_length != len)
{
bmove_upp(from+res_length,from+len,len);
bfill(from,res_length-len,'0');
len=res_length;
}
long tmp=(long) str_to_timestamp(from,len);
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
{
int4store(ptr,tmp);
}
else
#endif
longstore(ptr,tmp);
}
int Field_timestamp::store(double nr) int Field_timestamp::store(double nr)
{ {
int error= 0; int error= 0;
...@@ -2752,44 +2723,34 @@ longlong Field_timestamp::val_int(void) ...@@ -2752,44 +2723,34 @@ longlong Field_timestamp::val_int(void)
time_arg=(time_t) temp; time_arg=(time_t) temp;
localtime_r(&time_arg,&tm_tmp); localtime_r(&time_arg,&tm_tmp);
l_time=&tm_tmp; l_time=&tm_tmp;
res=(longlong) 0;
for (pos=len=0; len+1 < (uint) field_length ; len+=2,pos++) part_time= l_time->tm_year % 100;
{ res= ((longlong) (part_time+ ((part_time < YY_PART_YEAR) ? 2000 : 1900))*
bool year_flag=0; LL(10000000000));
switch (dayord.pos[pos]) { part_time= l_time->tm_mon+1;
case 0: part_time=l_time->tm_year % 100; year_flag=1 ; break; res+= (longlong) part_time * LL(100000000);
case 1: part_time=l_time->tm_mon+1; break; part_time=l_time->tm_mday;
case 2: part_time=l_time->tm_mday; break; res+= (longlong) ((long) part_time * 1000000L);
case 3: part_time=l_time->tm_hour; break; part_time=l_time->tm_hour;
case 4: part_time=l_time->tm_min; break; res+= (longlong) (part_time * 10000L);
case 5: part_time=l_time->tm_sec; break; part_time=l_time->tm_min;
default: part_time=0; break; /* purecov: deadcode */ res+= (longlong) (part_time * 100);
} part_time=l_time->tm_sec;
if (year_flag && (field_length == 8 || field_length == 14)) return res+part_time;
{
res=res*(longlong) 10000+(part_time+
((part_time < YY_PART_YEAR) ? 2000 : 1900));
len+=2;
}
else
res=res*(longlong) 100+part_time;
}
return (longlong) res;
} }
String *Field_timestamp::val_str(String *val_buffer, String *Field_timestamp::val_str(String *val_buffer,
String *val_ptr __attribute__((unused))) String *val_ptr __attribute__((unused)))
{ {
uint pos; uint32 temp, temp2;
int part_time;
uint32 temp;
time_t time_arg; time_t time_arg;
struct tm *l_time; struct tm *l_time;
struct tm tm_tmp; struct tm tm_tmp;
val_buffer->alloc(field_length+1); val_buffer->alloc(field_length+1);
char *to=(char*) val_buffer->ptr(),*end=to+field_length; char *to=(char*) val_buffer->ptr(),*end=to+field_length;
val_buffer->length(field_length);
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
...@@ -2800,41 +2761,53 @@ String *Field_timestamp::val_str(String *val_buffer, ...@@ -2800,41 +2761,53 @@ String *Field_timestamp::val_str(String *val_buffer,
if (temp == 0L) if (temp == 0L)
{ /* Zero time is "000000" */ { /* Zero time is "000000" */
VOID(strfill(to,field_length,'0')); strmov(to, "0000-00-00 00:00:00");
val_buffer->length(field_length);
return val_buffer; return val_buffer;
} }
time_arg=(time_t) temp; time_arg=(time_t) temp;
localtime_r(&time_arg,&tm_tmp); localtime_r(&time_arg,&tm_tmp);
l_time=&tm_tmp; l_time=&tm_tmp;
for (pos=0; to < end ; pos++)
{ temp= l_time->tm_year % 100;
bool year_flag=0; if (temp < YY_PART_YEAR)
switch (dayord.pos[pos]) { {
case 0: part_time=l_time->tm_year % 100; year_flag=1; break; *to++= '2';
case 1: part_time=l_time->tm_mon+1; break; *to++= '0';
case 2: part_time=l_time->tm_mday; break; }
case 3: part_time=l_time->tm_hour; break; else
case 4: part_time=l_time->tm_min; break; {
case 5: part_time=l_time->tm_sec; break; *to++= '1';
default: part_time=0; break; /* purecov: deadcode */ *to++= '9';
} }
if (year_flag && (field_length == 8 || field_length == 14)) temp2=temp/10; temp=temp-temp2*10;
{ *to++= (char) ('0'+(char) (temp2));
if (part_time < YY_PART_YEAR) *to++= (char) ('0'+(char) (temp));
{ *to++= '-';
*to++='2'; *to++='0'; /* purecov: inspected */ temp=l_time->tm_mon+1;
} temp2=temp/10; temp=temp-temp2*10;
else *to++= (char) ('0'+(char) (temp2));
{ *to++= (char) ('0'+(char) (temp));
*to++='1'; *to++='9'; *to++= '-';
} temp=l_time->tm_mday;
} temp2=temp/10; temp=temp-temp2*10;
*to++=(char) ('0'+((uint) part_time/10)); *to++= (char) ('0'+(char) (temp2));
*to++=(char) ('0'+((uint) part_time % 10)); *to++= (char) ('0'+(char) (temp));
} *to++= ' ';
*to=0; // Safeguard temp=l_time->tm_hour;
val_buffer->length((uint) (to-val_buffer->ptr())); temp2=temp/10; temp=temp-temp2*10;
*to++= (char) ('0'+(char) (temp2));
*to++= (char) ('0'+(char) (temp));
*to++= ':';
temp=l_time->tm_min;
temp2=temp/10; temp=temp-temp2*10;
*to++= (char) ('0'+(char) (temp2));
*to++= (char) ('0'+(char) (temp));
*to++= ':';
temp=l_time->tm_sec;
temp2=temp/10; temp=temp-temp2*10;
*to++= (char) ('0'+(char) (temp2));
*to++= (char) ('0'+(char) (temp));
*to= 0;
return val_buffer; return val_buffer;
} }
...@@ -2929,10 +2902,7 @@ void Field_timestamp::sort_string(char *to,uint length __attribute__((unused))) ...@@ -2929,10 +2902,7 @@ void Field_timestamp::sort_string(char *to,uint length __attribute__((unused)))
void Field_timestamp::sql_type(String &res) const void Field_timestamp::sql_type(String &res) const
{ {
ulong length= my_sprintf((char*) res.ptr(), res.set("timestamp", 9, default_charset_info);
((char*) res.ptr(),"timestamp(%d)",
(int) field_length));
res.length(length);
} }
...@@ -5310,7 +5280,7 @@ Field *make_field(char *ptr, uint32 field_length, ...@@ -5310,7 +5280,7 @@ Field *make_field(char *ptr, uint32 field_length,
f_is_dec(pack_flag) == 0); f_is_dec(pack_flag) == 0);
case FIELD_TYPE_TIMESTAMP: case FIELD_TYPE_TIMESTAMP:
return new Field_timestamp(ptr,field_length, return new Field_timestamp(ptr,field_length,
unireg_check, field_name, table); unireg_check, field_name, table, field_charset);
case FIELD_TYPE_YEAR: case FIELD_TYPE_YEAR:
return new Field_year(ptr,field_length,null_pos,null_bit, return new Field_year(ptr,field_length,null_pos,null_bit,
unireg_check, field_name, table); unireg_check, field_name, table);
......
...@@ -561,14 +561,15 @@ class Field_null :public Field_str { ...@@ -561,14 +561,15 @@ class Field_null :public Field_str {
}; };
class Field_timestamp :public Field_num { class Field_timestamp :public Field_str {
public: public:
Field_timestamp(char *ptr_arg, uint32 len_arg, Field_timestamp(char *ptr_arg, uint32 len_arg,
enum utype unireg_check_arg, const char *field_name_arg, enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg); struct st_table *table_arg,
enum Item_result result_type () const { return field_length == 8 || field_length == 14 ? INT_RESULT : STRING_RESULT; } CHARSET_INFO *cs);
enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;} enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
enum Item_result cmp_type () const { return INT_RESULT; }
int store(const char *to,uint length,CHARSET_INFO *charset); int store(const char *to,uint length,CHARSET_INFO *charset);
int store(double nr); int store(double nr);
int store(longlong nr); int store(longlong nr);
...@@ -598,7 +599,6 @@ class Field_timestamp :public Field_num { ...@@ -598,7 +599,6 @@ class Field_timestamp :public Field_num {
longget(tmp,ptr); longget(tmp,ptr);
return tmp; return tmp;
} }
void fill_and_store(char *from,uint len);
bool get_date(TIME *ltime,bool fuzzydate); bool get_date(TIME *ltime,bool fuzzydate);
bool get_time(TIME *ltime); bool get_time(TIME *ltime);
}; };
......
...@@ -873,8 +873,15 @@ bool Item::send(Protocol *protocol, String *buffer) ...@@ -873,8 +873,15 @@ bool Item::send(Protocol *protocol, String *buffer)
switch ((type=field_type())) { switch ((type=field_type())) {
default: default:
DBUG_ASSERT(1); case MYSQL_TYPE_NULL:
/* If not assert on, send as a string */ case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_SET:
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_STRING: case MYSQL_TYPE_STRING:
case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_VAR_STRING:
{ {
...@@ -899,6 +906,7 @@ bool Item::send(Protocol *protocol, String *buffer) ...@@ -899,6 +906,7 @@ bool Item::send(Protocol *protocol, String *buffer)
result= protocol->store_short(nr); result= protocol->store_short(nr);
break; break;
} }
case MYSQL_TYPE_INT24:
case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONG:
{ {
longlong nr; longlong nr;
...@@ -925,6 +933,7 @@ bool Item::send(Protocol *protocol, String *buffer) ...@@ -925,6 +933,7 @@ bool Item::send(Protocol *protocol, String *buffer)
} }
case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATE:
case MYSQL_TYPE_TIMESTAMP:
{ {
TIME tm; TIME tm;
get_date(&tm, 1); get_date(&tm, 1);
......
...@@ -565,6 +565,7 @@ class Item_int_with_ref :public Item_int ...@@ -565,6 +565,7 @@ class Item_int_with_ref :public Item_int
class Item_copy_string :public Item class Item_copy_string :public Item
{ {
enum enum_field_types cached_field_type;
public: public:
Item *item; Item *item;
Item_copy_string(Item *i) :item(i) Item_copy_string(Item *i) :item(i)
...@@ -573,11 +574,12 @@ class Item_copy_string :public Item ...@@ -573,11 +574,12 @@ class Item_copy_string :public Item
decimals=item->decimals; decimals=item->decimals;
max_length=item->max_length; max_length=item->max_length;
name=item->name; name=item->name;
cached_field_type= item->field_type();
} }
~Item_copy_string() { delete item; } ~Item_copy_string() { delete item; }
enum Type type() const { return COPY_STR_ITEM; } enum Type type() const { return COPY_STR_ITEM; }
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_STRING; } enum_field_types field_type() const { return cached_field_type; }
double val() double val()
{ return null_value ? 0.0 : my_strntod(str_value.charset(),str_value.ptr(),str_value.length(),NULL); } { return null_value ? 0.0 : my_strntod(str_value.charset(),str_value.ptr(),str_value.length(),NULL); }
longlong val_int() longlong val_int()
......
...@@ -1945,6 +1945,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, ...@@ -1945,6 +1945,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables, bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables,
Item **ref) Item **ref)
{ {
/* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
if (Item_func::fix_fields(thd, tables, ref) || if (Item_func::fix_fields(thd, tables, ref) ||
!(entry= get_variable(&thd->user_vars, name, 1))) !(entry= get_variable(&thd->user_vars, name, 1)))
return 1; return 1;
......
...@@ -940,6 +940,11 @@ class Item_func_get_user_var :public Item_func ...@@ -940,6 +940,11 @@ class Item_func_get_user_var :public Item_func
void fix_length_and_dec(); void fix_length_and_dec();
void print(String *str); void print(String *str);
enum Item_result result_type() const; enum Item_result result_type() const;
/*
We must always return variables as strings to guard against selects of type
select @t1:=1,@t1,@t:="hello",@t from foo where (@t1:= t2.b)
*/
enum_field_types field_type() const { return MYSQL_TYPE_STRING; }
const char *func_name() const { return "get_user_var"; } const char *func_name() const { return "get_user_var"; }
bool const_item() const { return const_var_flag; } bool const_item() const { return const_var_flag; }
table_map used_tables() const table_map used_tables() const
......
...@@ -295,8 +295,8 @@ longlong Item_func_time_to_sec::val_int() ...@@ -295,8 +295,8 @@ longlong Item_func_time_to_sec::val_int()
/* /*
** Convert a string to a interval value Convert a string to a interval value
** To make code easy, allow interval objects without separators. To make code easy, allow interval objects without separators.
*/ */
static bool get_interval_value(Item *args,interval_type int_type, static bool get_interval_value(Item *args,interval_type int_type,
...@@ -516,12 +516,14 @@ void Item_func_curtime::fix_length_and_dec() ...@@ -516,12 +516,14 @@ void Item_func_curtime::fix_length_and_dec()
(int) start->tm_sec); (int) start->tm_sec);
} }
String *Item_func_now::val_str(String *str) String *Item_func_now::val_str(String *str)
{ {
str_value.set(buff,buff_length,thd_charset()); str_value.set(buff,buff_length,thd_charset());
return &str_value; return &str_value;
} }
void Item_func_now::fix_length_and_dec() void Item_func_now::fix_length_and_dec()
{ {
struct tm tm_tmp,*start; struct tm tm_tmp,*start;
...@@ -540,13 +542,14 @@ void Item_func_now::fix_length_and_dec() ...@@ -540,13 +542,14 @@ void Item_func_now::fix_length_and_dec()
(ulong) (((uint) start->tm_min)*100L+ (ulong) (((uint) start->tm_min)*100L+
(uint) start->tm_sec))); (uint) start->tm_sec)));
buff_length= (uint) cs->snprintf(cs,buff, sizeof(buff),"%04d-%02d-%02d %02d:%02d:%02d", buff_length= (uint) cs->snprintf(cs,buff, sizeof(buff),
((int) (start->tm_year+1900)) % 10000, "%04d-%02d-%02d %02d:%02d:%02d",
(int) start->tm_mon+1, ((int) (start->tm_year+1900)) % 10000,
(int) start->tm_mday, (int) start->tm_mon+1,
(int) start->tm_hour, (int) start->tm_mday,
(int) start->tm_min, (int) start->tm_hour,
(int) start->tm_sec); (int) start->tm_min,
(int) start->tm_sec);
/* For getdate */ /* For getdate */
ltime.year= start->tm_year+1900; ltime.year= start->tm_year+1900;
ltime.month= start->tm_mon+1; ltime.month= start->tm_mon+1;
...@@ -995,7 +998,42 @@ bool Item_func_from_unixtime::get_date(TIME *ltime, ...@@ -995,7 +998,42 @@ bool Item_func_from_unixtime::get_date(TIME *ltime,
return 0; return 0;
} }
/* Here arg[1] is a Item_interval object */
void Item_date_add_interval::fix_length_and_dec()
{
enum_field_types arg0_field_type;
set_charset(thd_charset());
maybe_null=1;
max_length=19*thd_charset()->mbmaxlen;
value.alloc(32);
/*
The field type for the result of an Item_date function is defined as
follows:
- If first arg is a MYSQL_TYPE_DATETIME result is MYSQL_TYPE_DATETIME
- If first arg is a MYSQL_TYPE_DATE and the interval type uses hours,
minutes or seconds then type is MYSQL_TYPE_DATETIME.
- Otherwise the result is MYSQL_TYPE_STRING
(This is because you can't know if the string contains a DATE, TIME or
DATETIME argument)
*/
cached_field_type= MYSQL_TYPE_STRING;
arg0_field_type= args[0]->field_type();
if (arg0_field_type == MYSQL_TYPE_DATETIME ||
arg0_field_type == MYSQL_TYPE_TIMESTAMP)
cached_field_type= MYSQL_TYPE_DATETIME;
else if (arg0_field_type == MYSQL_TYPE_DATE)
{
if (int_type <= INTERVAL_MONTH || int_type == INTERVAL_YEAR_MONTH)
cached_field_type= arg0_field_type;
else
cached_field_type= MYSQL_TYPE_DATETIME;
}
}
/* Here arg[1] is a Item_interval object */
bool Item_date_add_interval::get_date(TIME *ltime, bool fuzzy_date) bool Item_date_add_interval::get_date(TIME *ltime, bool fuzzy_date)
{ {
......
...@@ -443,7 +443,6 @@ class Item_func_from_unixtime :public Item_date_func ...@@ -443,7 +443,6 @@ class Item_func_from_unixtime :public Item_date_func
decimals=0; decimals=0;
max_length=19*thd_charset()->mbmaxlen; max_length=19*thd_charset()->mbmaxlen;
} }
// enum Item_result result_type () const { return STRING_RESULT; }
bool get_date(TIME *res,bool fuzzy_date); bool get_date(TIME *res,bool fuzzy_date);
}; };
...@@ -470,32 +469,34 @@ class Item_func_sec_to_time :public Item_str_func ...@@ -470,32 +469,34 @@ class Item_func_sec_to_time :public Item_str_func
} }
}; };
/*
The following must be sorted so that simple intervals comes first.
(get_interval_value() depends on this)
*/
enum interval_type
{
INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR, INTERVAL_MINUTE,
INTERVAL_SECOND, INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE,
INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND,
INTERVAL_MINUTE_SECOND
};
enum interval_type { INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY,
INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND,
INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR,
INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND,
INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND,
INTERVAL_MINUTE_SECOND};
class Item_date_add_interval :public Item_date_func class Item_date_add_interval :public Item_date_func
{ {
const interval_type int_type; const interval_type int_type;
String value; String value;
const bool date_sub_interval; const bool date_sub_interval;
enum_field_types cached_field_type;
public: public:
Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg) Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
:Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {} :Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
String *val_str(String *); String *val_str(String *);
const char *func_name() const { return "date_add_interval"; } const char *func_name() const { return "date_add_interval"; }
void fix_length_and_dec() void fix_length_and_dec();
{ enum_field_types field_type() const { return cached_field_type; }
set_charset(thd_charset());
maybe_null=1;
max_length=19*thd_charset()->mbmaxlen;
value.alloc(32);
}
double val() { return (double) val_int(); } double val() { return (double) val_int(); }
longlong val_int(); longlong val_int();
bool get_date(TIME *res,bool fuzzy_date); bool get_date(TIME *res,bool fuzzy_date);
......
...@@ -1537,7 +1537,7 @@ static void start_signal_handler(void) ...@@ -1537,7 +1537,7 @@ static void start_signal_handler(void)
(void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); (void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
if (!(opt_specialflag & SPECIAL_NO_PRIOR)) if (!(opt_specialflag & SPECIAL_NO_PRIOR))
my_pthread_attr_setprio(&thr_attr,INTERRUPT_PRIOR); my_pthread_attr_setprio(&thr_attr,INTERRUPT_PRIOR);
pthread_attr_setstacksize(&thr_attr,32768); pthread_attr_setstacksize(&thr_attr, 129*1024);
#endif #endif
(void) pthread_mutex_lock(&LOCK_thread_count); (void) pthread_mutex_lock(&LOCK_thread_count);
......
...@@ -577,18 +577,19 @@ bool Protocol::store(I_List<i_string>* str_list) ...@@ -577,18 +577,19 @@ bool Protocol::store(I_List<i_string>* str_list)
{ {
char buf[256]; char buf[256];
String tmp(buf, sizeof(buf), default_charset_info); String tmp(buf, sizeof(buf), default_charset_info);
tmp.length(0); uint32 len;
I_List_iterator<i_string> it(*str_list); I_List_iterator<i_string> it(*str_list);
i_string* s; i_string* s;
tmp.length(0);
while ((s=it++)) while ((s=it++))
{ {
if (tmp.length())
tmp.append(',');
tmp.append(s->ptr); tmp.append(s->ptr);
tmp.append(',');
} }
if ((len= tmp.length()))
return store((char*) tmp.ptr(), tmp.length()); len--; // Remove last ','
return store((char*) tmp.ptr(), len);
} }
...@@ -623,8 +624,9 @@ bool Protocol_simple::store(const char *from, uint length) ...@@ -623,8 +624,9 @@ bool Protocol_simple::store(const char *from, uint length)
{ {
#ifndef DEBUG_OFF #ifndef DEBUG_OFF
DBUG_ASSERT(field_types == 0 || DBUG_ASSERT(field_types == 0 ||
field_types[field_pos] == MYSQL_TYPE_STRING || field_types[field_pos] == MYSQL_TYPE_DECIMAL ||
field_types[field_pos] == MYSQL_TYPE_VAR_STRING); (field_types[field_pos] >= MYSQL_TYPE_ENUM &&
field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));
field_pos++; field_pos++;
#endif #endif
if (convert) if (convert)
...@@ -702,11 +704,11 @@ bool Protocol_simple::store(double from, uint32 decimals, String *buffer) ...@@ -702,11 +704,11 @@ bool Protocol_simple::store(double from, uint32 decimals, String *buffer)
bool Protocol_simple::store(Field *field) bool Protocol_simple::store(Field *field)
{ {
if (field->is_null())
return store_null();
#ifndef DEBUG_OFF #ifndef DEBUG_OFF
field_pos++; field_pos++;
#endif #endif
if (field->is_null())
return store_null();
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),default_charset_info); String tmp(buff,sizeof(buff),default_charset_info);
field->val_str(&tmp,&tmp); field->val_str(&tmp,&tmp);
...@@ -720,7 +722,9 @@ bool Protocol_simple::store(TIME *tm) ...@@ -720,7 +722,9 @@ bool Protocol_simple::store(TIME *tm)
{ {
#ifndef DEBUG_OFF #ifndef DEBUG_OFF
DBUG_ASSERT(field_types == 0 || DBUG_ASSERT(field_types == 0 ||
field_types[field_pos++] == MYSQL_TYPE_DATETIME); field_types[field_pos] == MYSQL_TYPE_DATETIME ||
field_types[field_pos] == MYSQL_TYPE_TIMESTAMP);
field_pos++;
#endif #endif
char buff[40]; char buff[40];
uint length; uint length;
...@@ -759,7 +763,7 @@ bool Protocol_simple::store_time(TIME *tm) ...@@ -759,7 +763,7 @@ bool Protocol_simple::store_time(TIME *tm)
#endif #endif
char buff[40]; char buff[40];
uint length; uint length;
length= my_sprintf(buff,(buff, "%s%ld:%02d:%02d", length= my_sprintf(buff,(buff, "%s%02ld:%02d:%02d",
tm->neg ? "-" : "", tm->neg ? "-" : "",
(long) tm->day*3600L+(long) tm->hour, (long) tm->day*3600L+(long) tm->hour,
(int) tm->minute, (int) tm->minute,
...@@ -796,8 +800,9 @@ bool Protocol_prep::store(const char *from,uint length) ...@@ -796,8 +800,9 @@ bool Protocol_prep::store(const char *from,uint length)
{ {
#ifndef DEBUG_OFF #ifndef DEBUG_OFF
DBUG_ASSERT(field_types == 0 || DBUG_ASSERT(field_types == 0 ||
field_types[field_pos] == MYSQL_TYPE_STRING || field_types[field_pos] == MYSQL_TYPE_DECIMAL ||
field_types[field_pos] == MYSQL_TYPE_VAR_STRING); (field_types[field_pos] >= MYSQL_TYPE_ENUM &&
field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));
#endif #endif
field_pos++; field_pos++;
if (convert) if (convert)
...@@ -922,7 +927,8 @@ bool Protocol_prep::store(TIME *tm) ...@@ -922,7 +927,8 @@ bool Protocol_prep::store(TIME *tm)
#ifndef DEBUG_OFF #ifndef DEBUG_OFF
DBUG_ASSERT(field_types == 0 || DBUG_ASSERT(field_types == 0 ||
field_types[field_pos] == MYSQL_TYPE_DATETIME || field_types[field_pos] == MYSQL_TYPE_DATETIME ||
field_types[field_pos] == MYSQL_TYPE_DATE); field_types[field_pos] == MYSQL_TYPE_DATE ||
field_types[field_pos] == MYSQL_TYPE_TIMESTAMP);
#endif #endif
char buff[12],*pos; char buff[12],*pos;
uint length; uint length;
......
...@@ -992,8 +992,12 @@ bool sys_var_thd_conv_charset::update(THD *thd, set_var *var) ...@@ -992,8 +992,12 @@ bool sys_var_thd_conv_charset::update(THD *thd, set_var *var)
if (var->type == OPT_GLOBAL) if (var->type == OPT_GLOBAL)
global_system_variables.convert_set= var->save_result.convert; global_system_variables.convert_set= var->save_result.convert;
else else
{
thd->lex.convert_set= thd->variables.convert_set= thd->lex.convert_set= thd->variables.convert_set=
var->save_result.convert; var->save_result.convert;
thd->protocol_simple.init(thd);
thd->protocol_prep.init(thd);
}
return 0; return 0;
} }
......
...@@ -310,30 +310,7 @@ void field_str::add() ...@@ -310,30 +310,7 @@ void field_str::add()
was_maybe_zerofill = num_info.maybe_zerofill; was_maybe_zerofill = num_info.maybe_zerofill;
} }
if (room_in_tree) /* Update min and max arguments */
{
if (res != &s)
s.copy(*res);
if (!tree_search(&tree, (void*) &s, tree.custom_arg)) // If not in tree
{
s.copy(); // slow, when SAFE_MALLOC is in use
if (!tree_insert(&tree, (void*) &s, 0, tree.custom_arg))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
}
else
{
bzero((char*) &s, sizeof(s)); // Let tree handle free of this
if ((treemem += length) > pc->max_treemem)
{
room_in_tree = 0; // Remove tree, too big tree
delete_tree(&tree);
}
}
}
}
if (!found) if (!found)
{ {
found = 1; found = 1;
...@@ -364,6 +341,31 @@ void field_str::add() ...@@ -364,6 +341,31 @@ void field_str::add()
max_arg.copy(*res); max_arg.copy(*res);
} }
} }
if (room_in_tree)
{
if (res != &s)
s.copy(*res);
if (!tree_search(&tree, (void*) &s, tree.custom_arg)) // If not in tree
{
s.copy(); // slow, when SAFE_MALLOC is in use
if (!tree_insert(&tree, (void*) &s, 0, tree.custom_arg))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
}
else
{
bzero((char*) &s, sizeof(s)); // Let tree handle free of this
if ((treemem += length) > pc->max_treemem)
{
room_in_tree = 0; // Remove tree, too big tree
delete_tree(&tree);
}
}
}
}
if ((num_info.zerofill && (max_length != min_length)) || if ((num_info.zerofill && (max_length != min_length)) ||
(was_zero_fill && (max_length != min_length))) (was_zero_fill && (max_length != min_length)))
can_be_still_num = 0; // zerofilled numbers must be of same length can_be_still_num = 0; // zerofilled numbers must be of same length
......
...@@ -520,6 +520,7 @@ bool select_send::send_data(List<Item> &items) ...@@ -520,6 +520,7 @@ bool select_send::send_data(List<Item> &items)
if (unit->offset_limit_cnt) if (unit->offset_limit_cnt)
{ // using limit offset,count { // using limit offset,count
unit->offset_limit_cnt--; unit->offset_limit_cnt--;
return 0;
} }
List_iterator_fast<Item> li(items); List_iterator_fast<Item> li(items);
......
...@@ -158,7 +158,7 @@ my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show) ...@@ -158,7 +158,7 @@ my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
DBUG_ENTER("mysqld_show_warnings"); DBUG_ENTER("mysqld_show_warnings");
field_list.push_back(new Item_empty_string("Level", 7)); field_list.push_back(new Item_empty_string("Level", 7));
field_list.push_back(new Item_int("Code",0,4)); field_list.push_back(new Item_return_int("Code",4, MYSQL_TYPE_LONG));
field_list.push_back(new Item_empty_string("Message",MYSQL_ERRMSG_SIZE)); field_list.push_back(new Item_empty_string("Message",MYSQL_ERRMSG_SIZE));
if (thd->protocol->send_fields(&field_list,1)) if (thd->protocol->send_fields(&field_list,1))
......
...@@ -1043,7 +1043,6 @@ int show_binlog_info(THD* thd) ...@@ -1043,7 +1043,6 @@ int show_binlog_info(THD* thd)
DBUG_RETURN(-1); DBUG_RETURN(-1);
protocol->prepare_for_resend(); protocol->prepare_for_resend();
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
LOG_INFO li; LOG_INFO li;
...@@ -1103,8 +1102,8 @@ int show_binlogs(THD* thd) ...@@ -1103,8 +1102,8 @@ int show_binlogs(THD* thd)
/* The file ends with EOF or empty line */ /* The file ends with EOF or empty line */
while ((length=my_b_gets(index_file, fname, sizeof(fname))) > 1) while ((length=my_b_gets(index_file, fname, sizeof(fname))) > 1)
{ {
protocol->prepare_for_resend();
int dir_len = dirname_length(fname); int dir_len = dirname_length(fname);
packet->length(0);
/* The -1 is for removing newline from fname */ /* The -1 is for removing newline from fname */
protocol->store(fname + dir_len, length-1-dir_len); protocol->store(fname + dir_len, length-1-dir_len);
if (protocol->write()) if (protocol->write())
......
...@@ -3047,6 +3047,7 @@ join_free(JOIN *join, bool full) ...@@ -3047,6 +3047,7 @@ join_free(JOIN *join, bool full)
if (join->tables > join->const_tables) // Test for not-const tables if (join->tables > join->const_tables) // Test for not-const tables
free_io_cache(join->table[join->const_tables]); free_io_cache(join->table[join->const_tables]);
if (join->select_lex->dependent && !full) if (join->select_lex->dependent && !full)
{
for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++) for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++)
{ {
if (tab->table) if (tab->table)
...@@ -3061,6 +3062,7 @@ join_free(JOIN *join, bool full) ...@@ -3061,6 +3062,7 @@ join_free(JOIN *join, bool full)
tab->table->file->index_end(); tab->table->file->index_end();
} }
} }
}
else else
{ {
for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++) for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++)
...@@ -3078,6 +3080,11 @@ join_free(JOIN *join, bool full) ...@@ -3078,6 +3080,11 @@ join_free(JOIN *join, bool full)
/* Don't free index if we are using read_record */ /* Don't free index if we are using read_record */
if (!tab->read_record.table) if (!tab->read_record.table)
tab->table->file->index_end(); tab->table->file->index_end();
/*
We need to reset this for next select
(Tested in part_of_refkey)
*/
tab->table->reginfo.join_tab= 0;
} }
end_read_record(&tab->read_record); end_read_record(&tab->read_record);
} }
...@@ -7487,9 +7494,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, ...@@ -7487,9 +7494,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
item_list.push_back(new Item_string(join->select_lex->type, item_list.push_back(new Item_string(join->select_lex->type,
strlen(join->select_lex->type), strlen(join->select_lex->type),
default_charset_info)); default_charset_info));
Item *empty= new Item_empty_string("",0);
for (uint i=0 ; i < 7; i++) for (uint i=0 ; i < 7; i++)
item_list.push_back(empty); item_list.push_back(item_null);
item_list.push_back(new Item_string(message,strlen(message), item_list.push_back(new Item_string(message,strlen(message),
default_charset_info)); default_charset_info));
if (result->send_data(item_list)) if (result->send_data(item_list))
......
...@@ -802,6 +802,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) ...@@ -802,6 +802,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
DBUG_RETURN(1); DBUG_RETURN(1);
protocol->prepare_for_resend(); protocol->prepare_for_resend();
protocol->store(table->table_name); protocol->store(table->table_name);
buffer.length(0);
if (store_create_info(thd, table, &buffer)) if (store_create_info(thd, table, &buffer))
DBUG_RETURN(-1); DBUG_RETURN(-1);
protocol->store(buffer.ptr(), buffer.length()); protocol->store(buffer.ptr(), buffer.length());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment