diff options
author | unknown <igor@rurik.mysql.com> | 2005-04-19 16:54:30 -0700 |
---|---|---|
committer | unknown <igor@rurik.mysql.com> | 2005-04-19 16:54:30 -0700 |
commit | 6a97b07994f8d67c0f14b3979c932d69452ff94f (patch) | |
tree | db2b83233b9c2e77c8be4330a4d8273a61999aa3 | |
parent | 254dfb2be0075b15af30778b51321f784bf45ef5 (diff) | |
download | mariadb-git-6a97b07994f8d67c0f14b3979c932d69452ff94f.tar.gz |
sql_select.cc:
Fixed bug #9681.
The bug happened with queries using derived tables specified by
a SELECT with ROLLUP, such as:
SELECT * FROM (SELECT a, SUM(a) FROM t1 GROUP BY a WITH ROLLUP) t2,
if column a of table t1 is declared as NOT NULL.
This was to the fact that the first column of the temporary table
created to contain the derived table erroneously inherited the NOT NULL
attribute from column a.
olap.result, olap.test:
Added a test case for bug #9681.
mysql-test/t/olap.test:
Added a test case for bug #9681.
mysql-test/r/olap.result:
Added a test case for bug #9681.
sql/sql_select.cc:
Fixed bug #9681.
The bug happened with queries using derived tables specified by
a SELECT with ROLLUP, such as:
SELECT * FROM (SELECT a, SUM(a) FROM t1 GROUP BY a WITH ROLLUP) t2,
if column a of table t1 is declared as NOT NULL.
This was to the fact that the first column of the temporary table
created to contain the derived table erroneously inherited the NOT NULL
attribute from column a.
-rw-r--r-- | mysql-test/r/olap.result | 13 | ||||
-rw-r--r-- | mysql-test/t/olap.test | 13 | ||||
-rw-r--r-- | sql/sql_select.cc | 14 |
3 files changed, 39 insertions, 1 deletions
diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result index 6500edf478f..341d51033f2 100644 --- a/mysql-test/r/olap.result +++ b/mysql-test/r/olap.result @@ -392,3 +392,16 @@ SELECT SQL_CALC_FOUND_ROWS a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1; a SUM(b) 1 4 DROP TABLE t1; +CREATE TABLE t1 (a int(11) NOT NULL); +INSERT INTO t1 VALUES (1),(2); +SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP; +a m +1 1 +2 2 +NULL 3 +SELECT * FROM ( SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP ) t2; +a m +1 1 +2 2 +NULL 3 +DROP TABLE t1; diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index 3aac0f45ead..4f3b0f51286 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -171,3 +171,16 @@ SELECT a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1; SELECT SQL_CALC_FOUND_ROWS a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1; DROP TABLE t1; + +# +# Tests for bug #9681: ROLLUP in subquery for derived table wiht +# a group by field declared as NOT NULL +# + +CREATE TABLE t1 (a int(11) NOT NULL); +INSERT INTO t1 VALUES (1),(2); + +SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP; +SELECT * FROM ( SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP ) t2; + +DROP TABLE t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3f133a473ac..39698d6f1f7 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4779,7 +4779,7 @@ static Field* create_tmp_field_from_field(THD *thd, Field* org_field, item->result_field= new_field; else new_field->field_name= name; - if (org_field->maybe_null()) + if (org_field->maybe_null() || (item && item->maybe_null)) new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join if (org_field->type() == FIELD_TYPE_VAR_STRING) table->db_create_options|= HA_OPTION_PACK_RECORD; @@ -9192,7 +9192,19 @@ bool JOIN::rollup_init() for (j=0 ; j < fields_list.elements ; j++) rollup.fields[i].push_back(rollup.null_items[i]); } + List_iterator_fast<Item> it(fields_list); + Item *item; + while ((item= it++)) + { + ORDER *group_tmp; + for (group_tmp= group_list; group_tmp; group_tmp= group_tmp->next) + { + if (*group_tmp->item == item) + item->maybe_null= 1; + } + } return 0; + } |