Loading mysql-test/r/having.result +13 −0 Original line number Diff line number Diff line Loading @@ -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); Loading mysql-test/r/view.result +29 −0 Original line number Diff line number Diff line Loading @@ -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; mysql-test/t/having.test +12 −0 Original line number Diff line number Diff line Loading @@ -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 # Loading mysql-test/t/view.test +24 −0 Original line number Diff line number Diff line Loading @@ -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; sql/opt_sum.cc +5 −5 Original line number Diff line number Diff line Loading @@ -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; /* Loading Loading @@ -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; 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; /* Loading Loading
mysql-test/r/having.result +13 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
mysql-test/r/view.result +29 −0 Original line number Diff line number Diff line Loading @@ -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;
mysql-test/t/having.test +12 −0 Original line number Diff line number Diff line Loading @@ -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 # Loading
mysql-test/t/view.test +24 −0 Original line number Diff line number Diff line Loading @@ -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;
sql/opt_sum.cc +5 −5 Original line number Diff line number Diff line Loading @@ -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; /* Loading Loading @@ -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; 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; /* Loading