1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

fixed zero result case for group functions in subquery (Bug #3505)

fixed LIMIT 0 for zero rows optimisation
This commit is contained in:
bell@sanja.is.com.ua
2004-05-02 13:03:49 +03:00
parent 809f040617
commit 25d815cde6
3 changed files with 34 additions and 0 deletions

View File

@@ -1707,3 +1707,15 @@ create table t3(flag int);
select (select * from t3 where id not null) from t1, t2; select (select * from t3 where id not null) from t1, t2;
ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'null) from t1, t2' at line 1 ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'null) from t1, t2' at line 1
drop table t1,t2,t3; drop table t1,t2,t3;
CREATE TABLE t1 (id INT);
CREATE TABLE t2 (id INT);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1);
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
id c
1 1
2 0
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id;
id c
1 1
2 0

View File

@@ -1115,3 +1115,14 @@ create table t3(flag int);
-- error 1064 -- error 1064
select (select * from t3 where id not null) from t1, t2; select (select * from t3 where id not null) from t1, t2;
drop table t1,t2,t3; drop table t1,t2,t3;
#
# aggregate functions (Bug #3505)
#
CREATE TABLE t1 (id INT);
CREATE TABLE t2 (id INT);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1);
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id;
DROP TABLE t1,t2

View File

@@ -1051,6 +1051,13 @@ JOIN::reinit()
if (tmp_join) if (tmp_join)
restore_tmp(); restore_tmp();
if (sum_funcs)
{
Item_sum *func, **func_ptr= sum_funcs;
while ((func= *(func_ptr++)))
func->clear();
}
DBUG_RETURN(0); DBUG_RETURN(0);
} }
@@ -1115,6 +1122,7 @@ JOIN::exec()
if (zero_result_cause) if (zero_result_cause)
{ {
(void) return_zero_rows(this, result, tables_list, fields_list, (void) return_zero_rows(this, result, tables_list, fields_list,
do_send_rows &&
tmp_table_param.sum_func_count != 0 && tmp_table_param.sum_func_count != 0 &&
!group_list, !group_list,
select_options, select_options,
@@ -5666,6 +5674,9 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
if (!(error=(*end_select)(join,join_tab,0)) || error == -3) if (!(error=(*end_select)(join,join_tab,0)) || error == -3)
error=(*end_select)(join,join_tab,1); error=(*end_select)(join,join_tab,1);
} }
else if (join->do_send_rows && join->tmp_table_param.sum_func_count != 0 &&
!join->group_list)
error= join->result->send_data(*join->fields);
} }
else else
{ {