Commit 1d0b5392 authored by monty@narttu.mysql.fi's avatar monty@narttu.mysql.fi

Fix for bug in ROLLUP when all tables where 'const' tables (Bug #714)

parent 7b994129
...@@ -254,3 +254,18 @@ ERROR 42000: This version of MySQL doesn't yet support 'CUBE' ...@@ -254,3 +254,18 @@ ERROR 42000: This version of MySQL doesn't yet support 'CUBE'
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube union all select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube union all select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup;
ERROR 42000: This version of MySQL doesn't yet support 'CUBE' ERROR 42000: This version of MySQL doesn't yet support 'CUBE'
drop table t1,t2; drop table t1,t2;
CREATE TABLE t1 (i int);
INSERT INTO t1 VALUES(100);
CREATE TABLE t2 (i int);
INSERT INTO t2 VALUES (100),(200);
SELECT i, COUNT(*) FROM t1 GROUP BY i WITH ROLLUP;
i COUNT(*)
100 1
NULL 1
SELECT t1.i, t2.i, COUNT(*) FROM t1,t2 GROUP BY t1.i,t2.i WITH ROLLUP;
i i COUNT(*)
100 100 1
100 200 1
100 NULL 2
NULL NULL 2
drop table t1,t2;
...@@ -77,3 +77,14 @@ select product, country_id , year, sum(profit) from t1 group by product, country ...@@ -77,3 +77,14 @@ select product, country_id , year, sum(profit) from t1 group by product, country
drop table t1,t2; drop table t1,t2;
#
# Test bug with const tables
#
CREATE TABLE t1 (i int);
INSERT INTO t1 VALUES(100);
CREATE TABLE t2 (i int);
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;
...@@ -587,7 +587,7 @@ net_safe_read(MYSQL *mysql) ...@@ -587,7 +587,7 @@ net_safe_read(MYSQL *mysql)
DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d", DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d",
vio_description(net->vio),len)); vio_description(net->vio),len));
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
if (socket_errno == SOCKET_EINTR) if (vio_errno(net->vio) == SOCKET_EINTR)
return (packet_error); return (packet_error);
#endif /*MYSQL_SERVER*/ #endif /*MYSQL_SERVER*/
end_server(mysql); end_server(mysql);
......
...@@ -117,10 +117,8 @@ static Item* part_of_refkey(TABLE *form,Field *field); ...@@ -117,10 +117,8 @@ static Item* part_of_refkey(TABLE *form,Field *field);
static uint find_shortest_key(TABLE *table, key_map usable_keys); static uint find_shortest_key(TABLE *table, key_map usable_keys);
static bool test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order, static bool test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,
ha_rows select_limit, bool no_changes); ha_rows select_limit, bool no_changes);
static int create_sort_index(THD *thd, JOIN_TAB *tab,ORDER *order, static int create_sort_index(THD *thd, JOIN *join, ORDER *order,
ha_rows filesort_limit, ha_rows select_limit); ha_rows filesort_limit, ha_rows select_limit);
static int create_sort_index(THD *thd, JOIN_TAB *tab,ORDER *order,
ha_rows select_limit);
static int remove_duplicates(JOIN *join,TABLE *entry,List<Item> &fields, static int remove_duplicates(JOIN *join,TABLE *entry,List<Item> &fields,
Item *having); Item *having);
static int remove_dup_with_compare(THD *thd, TABLE *entry, Field **field, static int remove_dup_with_compare(THD *thd, TABLE *entry, Field **field,
...@@ -916,7 +914,7 @@ JOIN::optimize() ...@@ -916,7 +914,7 @@ JOIN::optimize()
{ {
DBUG_PRINT("info",("Sorting for group")); DBUG_PRINT("info",("Sorting for group"));
thd->proc_info="Sorting for group"; thd->proc_info="Sorting for group";
if (create_sort_index(thd, &join_tab[const_tables], group_list, if (create_sort_index(thd, this, group_list,
HA_POS_ERROR, HA_POS_ERROR) || HA_POS_ERROR, HA_POS_ERROR) ||
alloc_group_fields(this, group_list) || alloc_group_fields(this, group_list) ||
make_sum_func_list(all_fields, fields_list, 1)) make_sum_func_list(all_fields, fields_list, 1))
...@@ -931,7 +929,7 @@ JOIN::optimize() ...@@ -931,7 +929,7 @@ JOIN::optimize()
{ {
DBUG_PRINT("info",("Sorting for order")); DBUG_PRINT("info",("Sorting for order"));
thd->proc_info="Sorting for order"; thd->proc_info="Sorting for order";
if (create_sort_index(thd, &join_tab[const_tables], order, if (create_sort_index(thd, this, order,
HA_POS_ERROR, HA_POS_ERROR)) HA_POS_ERROR, HA_POS_ERROR))
DBUG_RETURN(1); DBUG_RETURN(1);
order=0; order=0;
...@@ -1235,7 +1233,7 @@ JOIN::exec() ...@@ -1235,7 +1233,7 @@ JOIN::exec()
if (curr_join->group_list) if (curr_join->group_list)
{ {
thd->proc_info= "Creating sort index"; thd->proc_info= "Creating sort index";
if (create_sort_index(thd, curr_join->join_tab, curr_join->group_list, if (create_sort_index(thd, curr_join, curr_join->group_list,
HA_POS_ERROR, HA_POS_ERROR) || HA_POS_ERROR, HA_POS_ERROR) ||
make_group_fields(this, curr_join)) make_group_fields(this, curr_join))
{ {
...@@ -1416,7 +1414,7 @@ JOIN::exec() ...@@ -1416,7 +1414,7 @@ JOIN::exec()
} }
} }
} }
if (create_sort_index(thd, &curr_join->join_tab[curr_join->const_tables], if (create_sort_index(thd, curr_join,
curr_join->group_list ? curr_join->group_list ?
curr_join->group_list : curr_join->order, curr_join->group_list : curr_join->order,
curr_join->select_limit, unit->select_limit_cnt)) curr_join->select_limit, unit->select_limit_cnt))
...@@ -6770,16 +6768,23 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, ...@@ -6770,16 +6768,23 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
*/ */
static int static int
create_sort_index(THD *thd, JOIN_TAB *tab, ORDER *order, create_sort_index(THD *thd, JOIN *join, ORDER *order,
ha_rows filesort_limit, ha_rows select_limit) ha_rows filesort_limit, ha_rows select_limit)
{ {
SORT_FIELD *sortorder; SORT_FIELD *sortorder;
uint length; uint length;
ha_rows examined_rows; ha_rows examined_rows;
TABLE *table=tab->table; TABLE *table;
SQL_SELECT *select=tab->select; SQL_SELECT *select;
JOIN_TAB *tab;
DBUG_ENTER("create_sort_index"); DBUG_ENTER("create_sort_index");
if (join->tables == join->const_tables)
DBUG_RETURN(0); // One row, no need to sort
tab= join->join_tab + join->const_tables;
table= tab->table;
select= tab->select;
if (test_if_skip_sort_order(tab,order,select_limit,0)) if (test_if_skip_sort_order(tab,order,select_limit,0))
DBUG_RETURN(0); DBUG_RETURN(0);
if (!(sortorder=make_unireg_sortorder(order,&length))) if (!(sortorder=make_unireg_sortorder(order,&length)))
......
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