summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2006-01-10 00:14:39 -0800
committerunknown <igor@rurik.mysql.com>2006-01-10 00:14:39 -0800
commit1e1f3743c656f45f2a77c1345ee2bcd384894087 (patch)
treee915c4ef86a85958eb947e5d9192609cb5361393
parent874fea6d2859b6796713c4f127a2f37fe83f58a2 (diff)
parent0b8089536252310754c20facc4d12be3d7ef48ec (diff)
downloadmariadb-git-1e1f3743c656f45f2a77c1345ee2bcd384894087.tar.gz
Merge rurik.mysql.com:/home/igor/mysql-5.1
into rurik.mysql.com:/home/igor/dev/mysql-5.1-0
-rw-r--r--mysql-test/r/having.result13
-rw-r--r--mysql-test/r/view.result29
-rw-r--r--mysql-test/t/having.test12
-rw-r--r--mysql-test/t/view.test24
-rw-r--r--sql/opt_sum.cc10
-rw-r--r--sql/sql_select.cc3
6 files changed, 85 insertions, 6 deletions
diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result
index 35a1358dd0c..379c2f83c78 100644
--- a/mysql-test/r/having.result
+++ b/mysql-test/r/having.result
@@ -128,6 +128,19 @@ id description c
1 test 0
2 test2 0
drop table t1,t2,t3;
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES (3), (4), (1), (3), (1);
+SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a)>0;
+SUM(a)
+2
+6
+4
+SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a);
+SUM(a)
+2
+6
+4
+DROP TABLE t1;
create table t1 (col1 int, col2 varchar(5), col_t1 int);
create table t2 (col1 int, col2 varchar(5), col_t2 int);
create table t3 (col1 int, col2 varchar(5), col_t3 int);
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 029daa14256..b10d4302776 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -2475,3 +2475,32 @@ alias1 alias2
5 5
drop view v2, v1;
drop table t1;
+CREATE TABLE t1 (a int PRIMARY KEY, b int);
+INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10);
+CREATE VIEW v1 AS SELECT * FROM t1;
+SELECT MAX(a) FROM t1;
+MAX(a)
+5
+SELECT MAX(a) FROM v1;
+MAX(a)
+5
+EXPLAIN SELECT MAX(a) FROM t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+EXPLAIN SELECT MAX(a) FROM v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+SELECT MIN(a) FROM t1;
+MIN(a)
+0
+SELECT MIN(a) FROM v1;
+MIN(a)
+0
+EXPLAIN SELECT MIN(a) FROM t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+EXPLAIN SELECT MIN(a) FROM v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index fb223d2a9af..1cc894697f9 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -123,6 +123,18 @@ group by a.id, a.description
having (a.description is not null) and (c=0);
drop table t1,t2,t3;
+#
+# Bug #14274: HAVING clause containing only set function
+#
+
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES (3), (4), (1), (3), (1);
+
+SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a)>0;
+SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a);
+
+DROP TABLE t1;
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index bfa12a1ee33..3fed763e3af 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -2343,3 +2343,27 @@ order by v2.receipt_id;
drop view v2, v1;
drop table t1;
+
+#
+# Bug#16016: MIN/MAX optimization for views
+#
+
+CREATE TABLE t1 (a int PRIMARY KEY, b int);
+INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10);
+
+CREATE VIEW v1 AS SELECT * FROM t1;
+
+SELECT MAX(a) FROM t1;
+SELECT MAX(a) FROM v1;
+
+EXPLAIN SELECT MAX(a) FROM t1;
+EXPLAIN SELECT MAX(a) FROM v1;
+
+SELECT MIN(a) FROM t1;
+SELECT MIN(a) FROM v1;
+
+EXPLAIN SELECT MIN(a) FROM t1;
+EXPLAIN SELECT MIN(a) FROM v1;
+
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 2e87f9cf0db..4158031b9a9 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -180,14 +180,14 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
indexes to find the key.
*/
Item *expr=item_sum->args[0];
- if (expr->type() == Item::FIELD_ITEM)
+ if (expr->real_item()->type() == Item::FIELD_ITEM)
{
byte key_buff[MAX_KEY_LENGTH];
TABLE_REF ref;
uint range_fl, prefix_len;
ref.key_buff= key_buff;
- Item_field *item_field= ((Item_field*) expr);
+ Item_field *item_field= (Item_field*) (expr->real_item());
TABLE *table= item_field->field->table;
/*
@@ -267,14 +267,14 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
indexes to find the key.
*/
Item *expr=item_sum->args[0];
- if (expr->type() == Item::FIELD_ITEM)
+ if (expr->real_item()->type() == Item::FIELD_ITEM)
{
byte key_buff[MAX_KEY_LENGTH];
TABLE_REF ref;
- uint range_fl, prefix_len;
+ uint range_fl, prefix_len;
ref.key_buff= key_buff;
- Item_field *item_field= ((Item_field*) expr);
+ Item_field *item_field= (Item_field*) (expr->real_item());
TABLE *table= item_field->field->table;
/*
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 8c954297f42..1a217df2878 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -365,7 +365,8 @@ JOIN::prepare(Item ***rref_pointer_array,
if (having_fix_rc || thd->net.report_error)
DBUG_RETURN(-1); /* purecov: inspected */
if (having->with_sum_func)
- having->split_sum_func(thd, ref_pointer_array, all_fields);
+ having->split_sum_func2(thd, ref_pointer_array, all_fields,
+ &having, TRUE);
thd->lex->allow_sum_func= save_allow_sum_func;
}
if (select_lex->inner_sum_func_list)