Commit 090bc713 authored by unknown's avatar unknown

olap.test, olap.result:

  Added test case for bug #4767.
item_sum.cc:
  Added a correct setting of the maybe_null flag for a copy of 
  an Item_sum object where the argument was a field of an inner table
  in an outer join read from a temporary table.
  It's part of the fix for bug #4767.
sql_select.cc:
  Made change_refs_to_tmp_fields work correctly
  for test case of bug #4767 where Item_sum::get_tmp_table_item
  failed to build a correct copy of an Item_sum object referring
  to a field in a temporary table.
  It looks like a hack yet.


sql/sql_select.cc:
  Made change_refs_to_tmp_fields work correctly
  for test case of bug #4767 where Item_sum::get_tmp_table_item
  failed to build a copy of an Item_sum object referring
  to a field in  a temporary table.
  It looks like a hack yet.
sql/item_sum.cc:
  Added a correct setting of maybe_null flag for copy of a
  Item_sum object where there argument is a field of nullable table
  read from the temporary table.
  It's part of the fix for bug #4767.
mysql-test/r/olap.result:
  Added test case for bug #4767.
mysql-test/t/olap.test:
  Added test case for bug #4767.
parent ec5c5691
...@@ -271,3 +271,39 @@ i i COUNT(*) ...@@ -271,3 +271,39 @@ i i COUNT(*)
100 NULL 2 100 NULL 2
NULL NULL 2 NULL NULL 2
drop table t1,t2; drop table t1,t2;
CREATE TABLE user_day(
user_id INT NOT NULL,
date DATE NOT NULL,
UNIQUE INDEX user_date (user_id, date)
);
INSERT INTO user_day VALUES
(1, '2004-06-06' ),
(1, '2004-06-07' ),
(2, '2004-06-06' );
SELECT
d.date AS day,
COUNT(d.user_id) as sample,
COUNT(next_day.user_id) AS not_cancelled
FROM user_day d
LEFT JOIN user_day next_day
ON next_day.user_id=d.user_id AND
next_day.date= DATE_ADD( d.date, interval 1 day )
GROUP BY day;
day sample not_cancelled
2004-06-06 2 1
2004-06-07 1 0
SELECT
d.date AS day,
COUNT(d.user_id) as sample,
COUNT(next_day.user_id) AS not_cancelled
FROM user_day d
LEFT JOIN user_day next_day
ON next_day.user_id=d.user_id AND
next_day.date= DATE_ADD( d.date, interval 1 day )
GROUP BY day
WITH ROLLUP;
day sample not_cancelled
2004-06-06 2 1
2004-06-07 1 0
NULL 3 1
DROP TABLE user_day;
...@@ -88,3 +88,40 @@ INSERT INTO t2 VALUES (100),(200); ...@@ -88,3 +88,40 @@ INSERT INTO t2 VALUES (100),(200);
SELECT i, COUNT(*) FROM t1 GROUP BY i WITH ROLLUP; SELECT i, COUNT(*) FROM t1 GROUP BY i WITH ROLLUP;
SELECT t1.i, t2.i, COUNT(*) FROM t1,t2 GROUP BY t1.i,t2.i WITH ROLLUP; SELECT t1.i, t2.i, COUNT(*) FROM t1,t2 GROUP BY t1.i,t2.i WITH ROLLUP;
drop table t1,t2; drop table t1,t2;
#bug #4767: ROLLUP with LEFT JOIN
CREATE TABLE user_day(
user_id INT NOT NULL,
date DATE NOT NULL,
UNIQUE INDEX user_date (user_id, date)
);
INSERT INTO user_day VALUES
(1, '2004-06-06' ),
(1, '2004-06-07' ),
(2, '2004-06-06' );
SELECT
d.date AS day,
COUNT(d.user_id) as sample,
COUNT(next_day.user_id) AS not_cancelled
FROM user_day d
LEFT JOIN user_day next_day
ON next_day.user_id=d.user_id AND
next_day.date= DATE_ADD( d.date, interval 1 day )
GROUP BY day;
SELECT
d.date AS day,
COUNT(d.user_id) as sample,
COUNT(next_day.user_id) AS not_cancelled
FROM user_day d
LEFT JOIN user_day next_day
ON next_day.user_id=d.user_id AND
next_day.date= DATE_ADD( d.date, interval 1 day )
GROUP BY day
WITH ROLLUP;
DROP TABLE user_day;
...@@ -159,7 +159,10 @@ Item *Item_sum::get_tmp_table_item(THD *thd) ...@@ -159,7 +159,10 @@ Item *Item_sum::get_tmp_table_item(THD *thd)
if (!arg->const_item()) if (!arg->const_item())
{ {
if (arg->type() == Item::FIELD_ITEM) if (arg->type() == Item::FIELD_ITEM)
{
arg->maybe_null= result_field_tmp->maybe_null();
((Item_field*) arg)->field= result_field_tmp++; ((Item_field*) arg)->field= result_field_tmp++;
}
else else
sum_item->args[i]= new Item_field(result_field_tmp++); sum_item->args[i]= new Item_field(result_field_tmp++);
} }
......
...@@ -4995,6 +4995,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -4995,6 +4995,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
blob_count++; blob_count++;
} }
((Item_sum*) item)->args[i]= new Item_field(new_field); ((Item_sum*) item)->args[i]= new Item_field(new_field);
if (((Item_sum*) item)->arg_count == 1)
((Item_sum*) item)->result_field= new_field;
} }
} }
} }
......
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