summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2004-08-20 12:31:57 -0700
committerunknown <igor@rurik.mysql.com>2004-08-20 12:31:57 -0700
commitb9120c197964e0bd799a93465e548d7e6cc4d021 (patch)
treebaa113a7bbce64712af6de6ff5b8852954583dd5
parent8f68a9eb6f62183742d8f37bc5ec94a48e831a5d (diff)
parent090bc713a4ebae95ac07a862800a69e723833b29 (diff)
downloadmariadb-git-b9120c197964e0bd799a93465e548d7e6cc4d021.tar.gz
Merge rurik.mysql.com:/home/igor/mysql-4.1
into rurik.mysql.com:/home/igor/dev/mysql-4.1-0 sql/item_sum.cc: Auto merged sql/sql_select.cc: Auto merged
-rw-r--r--mysql-test/r/olap.result36
-rw-r--r--mysql-test/t/olap.test37
-rw-r--r--sql/item_sum.cc3
-rw-r--r--sql/sql_select.cc2
4 files changed, 78 insertions, 0 deletions
diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result
index 50048808c39..bcbe5a8791c 100644
--- a/mysql-test/r/olap.result
+++ b/mysql-test/r/olap.result
@@ -271,3 +271,39 @@ i i COUNT(*)
100 NULL 2
NULL NULL 2
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;
diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test
index 7443aeee6f4..674b4ade097 100644
--- a/mysql-test/t/olap.test
+++ b/mysql-test/t/olap.test
@@ -88,3 +88,40 @@ INSERT INTO t2 VALUES (100),(200);
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;
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;
+
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index c256055d5bb..8e869f5492b 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -159,7 +159,10 @@ Item *Item_sum::get_tmp_table_item(THD *thd)
if (!arg->const_item())
{
if (arg->type() == Item::FIELD_ITEM)
+ {
+ arg->maybe_null= result_field_tmp->maybe_null();
((Item_field*) arg)->field= result_field_tmp++;
+ }
else
sum_item->args[i]= new Item_field(result_field_tmp++);
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 908b28155c7..cdf1050181b 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -4997,6 +4997,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
blob_count++;
}
((Item_sum*) item)->args[i]= new Item_field(new_field);
+ if (((Item_sum*) item)->arg_count == 1)
+ ((Item_sum*) item)->result_field= new_field;
}
}
}