Commit a5f2c752 authored by igor@rurik.mysql.com's avatar igor@rurik.mysql.com

func_gconcat.result, func_gconcat.test:

  Added a test case for bug #12095.
sql_class.h:
  Fixed bug #12095: a join query with GROUP_CONCAT over a single row table.
  Added a flag to the TMP_TABLE_PARAM class forcing to put constant
  items generated after elimination of a single row table into temp table
  in some cases (e.g. when GROUP_CONCAT is calculated over a single row
  table).
  bk ci sql/item_sum.cc
  Fixed bug #12095: a join query with GROUP_CONCAT over a single row table.
  If GROUP_CONCAT is calculated we always put its argument into a temp
  table, even when the argument is a constant item.
sql_select.cc:
  Fixed bug #12095: a join query with GROUP_CONCAT over one row table.
  If temp table is used to calculate GROUP_CONCAT the argument should
  be always put into this table, even when it is a constant item.
parent f503c415
...@@ -517,3 +517,34 @@ a group_concat(distinct b order by b) ...@@ -517,3 +517,34 @@ a group_concat(distinct b order by b)
2 3,7 2 3,7
NULL 1,2,3,4,7 NULL 1,2,3,4,7
drop table t1; drop table t1;
CREATE TABLE t1 (
aID smallint(5) unsigned NOT NULL auto_increment,
sometitle varchar(255) NOT NULL default '',
bID smallint(5) unsigned NOT NULL,
PRIMARY KEY (aID),
UNIQUE KEY sometitle (sometitle)
);
INSERT INTO t1 SET sometitle = 'title1', bID = 1;
INSERT INTO t1 SET sometitle = 'title2', bID = 1;
CREATE TABLE t2 (
bID smallint(5) unsigned NOT NULL auto_increment,
somename varchar(255) NOT NULL default '',
PRIMARY KEY (bID),
UNIQUE KEY somename (somename)
);
INSERT INTO t2 SET somename = 'test';
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
FROM t1 JOIN t2 ON t1.bID = t2.bID;
COUNT(*) GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
2 test
INSERT INTO t2 SET somename = 'test2';
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
FROM t1 JOIN t2 ON t1.bID = t2.bID;
COUNT(*) GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
2 test
DELETE FROM t2 WHERE somename = 'test2';
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
FROM t1 JOIN t2 ON t1.bID = t2.bID;
COUNT(*) GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
2 test
DROP TABLE t1,t2;
...@@ -310,4 +310,37 @@ select a, group_concat(b order by b) from t1 group by a with rollup; ...@@ -310,4 +310,37 @@ select a, group_concat(b order by b) from t1 group by a with rollup;
select a, group_concat(distinct b order by b) from t1 group by a with rollup; select a, group_concat(distinct b order by b) from t1 group by a with rollup;
drop table t1; drop table t1;
#
# Bug #12095: GROUP_CONCAT for one row table
#
CREATE TABLE t1 (
aID smallint(5) unsigned NOT NULL auto_increment,
sometitle varchar(255) NOT NULL default '',
bID smallint(5) unsigned NOT NULL,
PRIMARY KEY (aID),
UNIQUE KEY sometitle (sometitle)
);
INSERT INTO t1 SET sometitle = 'title1', bID = 1;
INSERT INTO t1 SET sometitle = 'title2', bID = 1;
CREATE TABLE t2 (
bID smallint(5) unsigned NOT NULL auto_increment,
somename varchar(255) NOT NULL default '',
PRIMARY KEY (bID),
UNIQUE KEY somename (somename)
);
INSERT INTO t2 SET somename = 'test';
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
FROM t1 JOIN t2 ON t1.bID = t2.bID;
INSERT INTO t2 SET somename = 'test2';
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
FROM t1 JOIN t2 ON t1.bID = t2.bID;
DELETE FROM t2 WHERE somename = 'test2';
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
FROM t1 JOIN t2 ON t1.bID = t2.bID;
DROP TABLE t1,t2;
# End of 4.1 tests # End of 4.1 tests
...@@ -1325,10 +1325,12 @@ public: ...@@ -1325,10 +1325,12 @@ public:
bool using_indirect_summary_function; bool using_indirect_summary_function;
/* If >0 convert all blob fields to varchar(convert_blob_length) */ /* If >0 convert all blob fields to varchar(convert_blob_length) */
uint convert_blob_length; uint convert_blob_length;
bool need_const; /* <=> const items are saved in tmp table */
TMP_TABLE_PARAM() TMP_TABLE_PARAM()
:copy_field(0), group_parts(0), :copy_field(0), group_parts(0),
group_length(0), group_null_parts(0), convert_blob_length(0) group_length(0), group_null_parts(0), convert_blob_length(0),
need_const(0)
{} {}
~TMP_TABLE_PARAM() ~TMP_TABLE_PARAM()
{ {
......
...@@ -5201,7 +5201,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -5201,7 +5201,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
param->using_indirect_summary_function=1; param->using_indirect_summary_function=1;
continue; continue;
} }
if (item->const_item() && (int) hidden_field_count <= 0) if (item->const_item() && (int) hidden_field_count <= 0 &&
!param->need_const)
continue; // We don't have to store this continue; // We don't have to store this
} }
if (type == Item::SUM_FUNC_ITEM && !group && !save_sum_fields) if (type == Item::SUM_FUNC_ITEM && !group && !save_sum_fields)
......
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