mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 21:42:35 +01:00
Merge ibabaev@bk-internal.mysql.com:/home/bk/mysql-5.1-new
into rurik.mysql.com:/home/igor/mysql-5.1
This commit is contained in:
commit
366d7afc67
7 changed files with 106 additions and 11 deletions
|
@ -847,3 +847,28 @@ timestampdiff(year,'2004-02-28','2005-02-28')
|
|||
select timestampdiff(year,'2004-02-29','2005-02-28');
|
||||
timestampdiff(year,'2004-02-29','2005-02-28')
|
||||
0
|
||||
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date);
|
||||
CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date);
|
||||
INSERT INTO t1 VALUES
|
||||
(1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01');
|
||||
INSERT INTO t2 VALUES
|
||||
(1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15');
|
||||
SELECT * FROM t1, t2
|
||||
WHERE t1.day BETWEEN
|
||||
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
|
||||
id day id day
|
||||
1 2005-06-01 1 2005-08-01
|
||||
3 2005-07-01 1 2005-08-01
|
||||
1 2005-06-01 2 2005-06-15
|
||||
1 2005-06-01 3 2005-07-15
|
||||
3 2005-07-01 3 2005-07-15
|
||||
SELECT * FROM t1, t2
|
||||
WHERE CAST(t1.day AS DATE) BETWEEN
|
||||
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
|
||||
id day id day
|
||||
1 2005-06-01 1 2005-08-01
|
||||
3 2005-07-01 1 2005-08-01
|
||||
1 2005-06-01 2 2005-06-15
|
||||
1 2005-06-01 3 2005-07-15
|
||||
3 2005-07-01 3 2005-07-15
|
||||
DROP TABLE t1,t2;
|
||||
|
|
|
@ -3194,6 +3194,15 @@ drop trigger t2t;
|
|||
drop trigger t3t;
|
||||
drop trigger t4t;
|
||||
drop table t1, t2, t3, t4, t5;
|
||||
create table t1(a date) engine=innodb;
|
||||
create table t2(a date, key(a)) engine=innodb;
|
||||
insert into t1 values('2005-10-01');
|
||||
insert into t2 values('2005-10-01');
|
||||
select * from t1, t2
|
||||
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
|
||||
a a
|
||||
2005-10-01 2005-10-01
|
||||
drop table t1, t2;
|
||||
CREATE TABLE t1 (
|
||||
field1 varchar(8) NOT NULL DEFAULT '',
|
||||
field2 varchar(8) NOT NULL DEFAULT '',
|
||||
|
|
|
@ -446,4 +446,26 @@ select timestampdiff(year,'1999-09-11','2001-9-11');
|
|||
select timestampdiff(year,'2004-02-28','2005-02-28');
|
||||
select timestampdiff(year,'2004-02-29','2005-02-28');
|
||||
|
||||
#
|
||||
# Bug #18618: BETWEEN for dates with the second argument being a constant
|
||||
# expression and the first and the third arguments being fields
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date);
|
||||
CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date);
|
||||
|
||||
INSERT INTO t1 VALUES
|
||||
(1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01');
|
||||
INSERT INTO t2 VALUES
|
||||
(1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15');
|
||||
|
||||
SELECT * FROM t1, t2
|
||||
WHERE t1.day BETWEEN
|
||||
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
|
||||
SELECT * FROM t1, t2
|
||||
WHERE CAST(t1.day AS DATE) BETWEEN
|
||||
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
|
||||
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
# End of 5.0 tests
|
||||
|
|
|
@ -2085,6 +2085,18 @@ connection default;
|
|||
disconnect a;
|
||||
disconnect b;
|
||||
|
||||
#
|
||||
# Bug #14360: problem with intervals
|
||||
#
|
||||
|
||||
create table t1(a date) engine=innodb;
|
||||
create table t2(a date, key(a)) engine=innodb;
|
||||
insert into t1 values('2005-10-01');
|
||||
insert into t2 values('2005-10-01');
|
||||
select * from t1, t2
|
||||
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
|
||||
drop table t1, t2;
|
||||
|
||||
#
|
||||
# Test that cascading updates leading to duplicate keys give the correct
|
||||
# error message (bug #9680)
|
||||
|
@ -2137,4 +2149,3 @@ alter table t1 drop foreign key c2_fk;
|
|||
show create table t1;
|
||||
#
|
||||
drop table t1, t2;
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems)
|
|||
{
|
||||
uint i;
|
||||
Field *field= NULL;
|
||||
bool all_constant= TRUE;
|
||||
|
||||
/* If the first argument is a FIELD_ITEM, pull out the field. */
|
||||
if (items[0]->real_item()->type() == Item::FIELD_ITEM)
|
||||
|
@ -65,16 +64,9 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems)
|
|||
for (i= 1; i < nitems; i++)
|
||||
{
|
||||
type[0]= item_cmp_type(type[0], items[i]->result_type());
|
||||
if (field && !convert_constant_item(thd, field, &items[i]))
|
||||
all_constant= FALSE;
|
||||
if (field && convert_constant_item(thd, field, &items[i]))
|
||||
type[0]= INT_RESULT;
|
||||
}
|
||||
|
||||
/*
|
||||
If we had a field that can be compared as a longlong, and all constant
|
||||
items, then the aggregate result will be an INT_RESULT.
|
||||
*/
|
||||
if (field && all_constant)
|
||||
type[0]= INT_RESULT;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2002,6 +2002,41 @@ longlong Item_date_add_interval::val_int()
|
|||
((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Item_date_add_interval::eq(const Item *item, bool binary_cmp) const
|
||||
{
|
||||
INTERVAL interval, other_interval;
|
||||
String val= value; // Because of const
|
||||
|
||||
if (this == item)
|
||||
return TRUE;
|
||||
|
||||
if ((item->type() != FUNC_ITEM) ||
|
||||
(arg_count != ((Item_func*) item)->arg_count) ||
|
||||
(func_name() != ((Item_func*) item)->func_name()))
|
||||
return FALSE;
|
||||
|
||||
Item_date_add_interval *other= (Item_date_add_interval*) item;
|
||||
|
||||
if ((int_type != other->int_type) ||
|
||||
(!args[0]->eq(other->args[0], binary_cmp)) ||
|
||||
(get_interval_value(args[1], int_type, &val, &interval)))
|
||||
return FALSE;
|
||||
|
||||
val= other->value;
|
||||
|
||||
if ((get_interval_value(other->args[1], other->int_type, &val,
|
||||
&other_interval)) ||
|
||||
((date_sub_interval ^ interval.neg) ^
|
||||
(other->date_sub_interval ^ other_interval.neg)))
|
||||
return FALSE;
|
||||
|
||||
// Assume comparing same types here due to earlier check
|
||||
return memcmp(&interval, &other_interval, sizeof(INTERVAL)) == 0;
|
||||
}
|
||||
|
||||
|
||||
static const char *interval_names[]=
|
||||
{
|
||||
"year", "quarter", "month", "day", "hour",
|
||||
|
|
|
@ -647,6 +647,7 @@ public:
|
|||
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
|
||||
longlong val_int();
|
||||
bool get_date(TIME *res, uint fuzzy_date);
|
||||
bool eq(const Item *item, bool binary_cmp) const;
|
||||
void print(String *str);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue