Commit 95fe71af authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-9707 MAX(timestamp(6) column) in correlated sub-query returns...

MDEV-9707 MAX(timestamp(6) column) in correlated sub-query returns non-existent row data in original table

special treatment for  temporal values in
create_tmp_field_from_item().

old code only did it when result_type() was STRING_RESULT,
but Item_cache_temporal::result_type() is INT_RESULT
parent 3294cd11
......@@ -7,4 +7,17 @@ a
2002-03-04
Warnings:
Note 1003 2000-01-01
set debug_dbug='';
drop table t1;
create table t1 (id int not null, ut timestamp(6) not null);
insert into t1 values(1, '2001-01-01 00:00:00.2');
insert into t1 values(1, '2001-01-01 00:00:00.1');
select * from t1;
id ut
1 2001-01-01 00:00:00.200000
1 2001-01-01 00:00:00.100000
select (select max(m2.ut) from t1 m2 where m1.id <> 0) from t1 m1;
(select max(m2.ut) from t1 m2 where m1.id <> 0)
2001-01-01 00:00:00.200000
2001-01-01 00:00:00.200000
drop table t1;
......@@ -7,5 +7,16 @@ create table t1 (a date);
insert t1 values ('2000-01-02'), ('2001-02-03'), ('2002-03-04');
set debug_dbug='d,str_to_datetime_warn';
select * from t1 where a > date_add('2000-01-01', interval 5 day);
set debug_dbug='';
drop table t1;
#
# MDEV-9707 MAX(timestamp(6) column) in correlated sub-query returns non-existent row data in original table
#
create table t1 (id int not null, ut timestamp(6) not null);
insert into t1 values(1, '2001-01-01 00:00:00.2');
insert into t1 values(1, '2001-01-01 00:00:00.1');
select * from t1;
select (select max(m2.ut) from t1 m2 where m1.id <> 0) from t1 m1;
drop table t1;
......@@ -14544,6 +14544,14 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
Field *new_field;
LINT_INIT(new_field);
/*
To preserve type or DATE/TIME and GEOMETRY fields,
they need to be handled separately.
*/
if (item->cmp_type() == TIME_RESULT ||
item->field_type() == MYSQL_TYPE_GEOMETRY)
new_field= item->tmp_table_field_from_field_type(table, 1);
else
switch (item->result_type()) {
case REAL_RESULT:
new_field= new Field_double(item->max_length, maybe_null,
......@@ -14566,18 +14574,11 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
case STRING_RESULT:
DBUG_ASSERT(item->collation.collation);
/*
DATE/TIME and GEOMETRY fields have STRING_RESULT result type.
To preserve type they needed to be handled separately.
*/
if (item->cmp_type() == TIME_RESULT ||
item->field_type() == MYSQL_TYPE_GEOMETRY)
new_field= item->tmp_table_field_from_field_type(table, 1);
/*
Make sure that the blob fits into a Field_varstring which has
2-byte lenght.
*/
else if (item->max_length/item->collation.collation->mbmaxlen > 255 &&
if (item->max_length/item->collation.collation->mbmaxlen > 255 &&
convert_blob_length <= Field_varstring::MAX_SIZE &&
convert_blob_length)
new_field= new Field_varstring(convert_blob_length, maybe_null,
......
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