Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mysql-test/main/aggregates-filter.combinations
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[innodb]
innodb
default-storage-engine=innodb

[myisam]
default-storage-engine=myisam

[aria]
default-storage-engine=aria
696 changes: 696 additions & 0 deletions mysql-test/main/aggregates-filter.result

Large diffs are not rendered by default.

1,235 changes: 1,235 additions & 0 deletions mysql-test/main/aggregates-filter.test

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions mysql-test/main/join_outer_reorder.result
Original file line number Diff line number Diff line change
Expand Up @@ -5595,13 +5595,13 @@ a b c d
# Oracle outer join not in WHERE clause
#
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c GROUP BY tj2.c(+);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c GROUP BY tj2.c HAVING tj2.c(+) > 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') > 1' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '> 1' at line 1
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c ORDER BY tj2.c(+);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
SELECT tj2.c(+) FROM tj2;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') FROM tj2' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM tj2' at line 1
#
# Mix ANSI and Oracle outer join
# ORA-25156
Expand Down Expand Up @@ -5643,7 +5643,7 @@ BEGIN
SELECT * FROM tj1 WHERE tj1.a = v1.a(+);
END
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ');
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ';
END' at line 4
#
# Unspecified table used in WHERE clause that contains (+)
Expand Down Expand Up @@ -5926,7 +5926,7 @@ a b
1 1
3 NULL
select t1.a, t2.b from t1, t2 where t1.a = t2.b(+);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
set SQL_MODE= oracle;
drop view v1;
drop table t1,t2;
Expand Down
12 changes: 6 additions & 6 deletions mysql-test/suite/compat/oracle/r/ora_outer_join.result
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ a b c d
# Oracle outer join not in WHERE clause
#
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c GROUP BY tj2.c(+);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c GROUP BY tj2.c HAVING tj2.c(+) > 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') > 1' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '> 1' at line 1
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c ORDER BY tj2.c(+);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
SELECT tj2.c(+) FROM tj2;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') FROM tj2' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM tj2' at line 1
#
# Mix ANSI and Oracle outer join
# ORA-25156
Expand Down Expand Up @@ -362,7 +362,7 @@ BEGIN
SELECT * FROM tj1 WHERE tj1.a = v1.a(+);
END
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ');
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ';
END' at line 4
#
# Unspecified table used in WHERE clause that contains (+)
Expand Down Expand Up @@ -645,7 +645,7 @@ a b
1 1
3 NULL
select t1.a, t2.b from t1, t2 where t1.a = t2.b(+);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
set SQL_MODE= oracle;
drop view v1;
drop table t1,t2;
Expand Down
6 changes: 3 additions & 3 deletions mysql-test/suite/compat/oracle/r/ora_outer_join_err.result
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ DROP TABLE t1,t2,t3;
create table t1 (a int);
create table t2 (a int);
select t1.a(+), t2.a from t1,t2;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '), t2.a from t1,t2' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' t2.a from t1,t2' at line 1
select t1.a, t2.a from t1,t2 HAVING t1.a(+) = t2.a;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') = t2.a' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= t2.a' at line 1
select t1.a, t2.a from t1 join t2 on (t1.a(+) = t2.a);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') = t2.a)' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= t2.a)' at line 1
DROP TABLE t1,t2;
#
# outer reference
Expand Down
50 changes: 25 additions & 25 deletions mysql-test/suite/perfschema/r/digest_view.result
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ SELECT SCHEMA_NAME, DIGEST, DIGEST_TEXT, COUNT_STAR
FROM performance_schema.events_statements_summary_by_digest
ORDER BY DIGEST_TEXT;
SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR
test cc5e38c5a702f49627052e59a2603818 EXPLAIN SELECT * FROM `test` . `v1` 1
test 264b69debfd30bbfe374cdca018fa4f9 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 1
test 75f31bf60b75a4f851ff9c9ee4e19d96 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 1
test a8f8a85697afacda9f2f3d3b023f9ed0 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 1
test 512598992d37826136f3f1292bb32e1e EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 1
test 54342cc19df16ce54b3ba43d1fd7552d SELECT * FROM `test` . `v1` 1
test 3750b7d8c33e040b90a2cdccb4c642a3 SELECT * FROM `test` . `v1` WHERE `a` = ? 1
test 94af70ef76a31364845f534863d99da8 SELECT * FROM `test` . `v1` WHERE `b` > ? 1
test 0c87d86b62e664a81a23d4f176fbb377 SELECT `a` , `b` FROM `test` . `v1` 1
test de7e6f1350ff14a952b97b373d76c1a4 SELECT `b` , `a` FROM `test` . `v1` 1
test 3468091e6d6ce474aded20beaec36b53 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1
test 983c118738efc2378bb2a15495c7e6c9 EXPLAIN SELECT * FROM `test` . `v1` 1
test f34ab36bba7121e7953b5c6ca8f58e11 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 1
test ee2356b394246ac8b7fc5faa97b0c1ad EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 1
test 3e70e03c91932264badade3cb1f2e66e EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 1
test 021f3cff6701828a7f017af34d29ce1c EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 1
test d2e11df922514a25243fc04ebf839825 SELECT * FROM `test` . `v1` 1
test c967f871a7c1bc86a7667b83a17ca6e1 SELECT * FROM `test` . `v1` WHERE `a` = ? 1
test 7c87fc30bf915208e69006449a702b7a SELECT * FROM `test` . `v1` WHERE `b` > ? 1
test 258f5bff705a10fe1c43fd25c29c61fd SELECT `a` , `b` FROM `test` . `v1` 1
test 518f87edc2c96f2b022d6ab3c767df7b SELECT `b` , `a` FROM `test` . `v1` 1
test d972cde0f9bbec28c84e4dcca8ef3281 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1
DROP TABLE test.v1;
CREATE VIEW test.v1 AS SELECT * FROM test.t1;
EXPLAIN SELECT * from test.v1;
Expand Down Expand Up @@ -248,19 +248,19 @@ SELECT SCHEMA_NAME, DIGEST, DIGEST_TEXT, COUNT_STAR
FROM performance_schema.events_statements_summary_by_digest
ORDER BY DIGEST_TEXT;
SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR
test ef8b10f452e117fa96af49687a93a10f CREATE VIEW `test` . `v1` AS SELECT * FROM `test` . `t1` 1
test 6b99f4d2ad410f9fa4ee1d501b0db571 DROP TABLE `test` . `v1` 1
test cc5e38c5a702f49627052e59a2603818 EXPLAIN SELECT * FROM `test` . `v1` 2
test 264b69debfd30bbfe374cdca018fa4f9 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 2
test 75f31bf60b75a4f851ff9c9ee4e19d96 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 2
test a8f8a85697afacda9f2f3d3b023f9ed0 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 2
test 512598992d37826136f3f1292bb32e1e EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 2
test 54342cc19df16ce54b3ba43d1fd7552d SELECT * FROM `test` . `v1` 2
test 3750b7d8c33e040b90a2cdccb4c642a3 SELECT * FROM `test` . `v1` WHERE `a` = ? 2
test 94af70ef76a31364845f534863d99da8 SELECT * FROM `test` . `v1` WHERE `b` > ? 2
test 187a846fafe04b746eddaaab80b6a766 SELECT SCHEMA_NAME , `DIGEST` , `DIGEST_TEXT` , `COUNT_STAR` FROM `performance_schema` . `events_statements_summary_by_digest` ORDER BY `DIGEST_TEXT` 1
test 0c87d86b62e664a81a23d4f176fbb377 SELECT `a` , `b` FROM `test` . `v1` 2
test de7e6f1350ff14a952b97b373d76c1a4 SELECT `b` , `a` FROM `test` . `v1` 2
test 3468091e6d6ce474aded20beaec36b53 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1
test bd4716657502ce7922d2ed7e20043b76 CREATE VIEW `test` . `v1` AS SELECT * FROM `test` . `t1` 1
test 2d14a4845ee825e3a1a21bd5799cba3c DROP TABLE `test` . `v1` 1
test 983c118738efc2378bb2a15495c7e6c9 EXPLAIN SELECT * FROM `test` . `v1` 2
test f34ab36bba7121e7953b5c6ca8f58e11 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 2
test ee2356b394246ac8b7fc5faa97b0c1ad EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 2
test 3e70e03c91932264badade3cb1f2e66e EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 2
test 021f3cff6701828a7f017af34d29ce1c EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 2
test d2e11df922514a25243fc04ebf839825 SELECT * FROM `test` . `v1` 2
test c967f871a7c1bc86a7667b83a17ca6e1 SELECT * FROM `test` . `v1` WHERE `a` = ? 2
test 7c87fc30bf915208e69006449a702b7a SELECT * FROM `test` . `v1` WHERE `b` > ? 2
test aa329bcb29afc39d9793e4fd6e108722 SELECT SCHEMA_NAME , `DIGEST` , `DIGEST_TEXT` , `COUNT_STAR` FROM `performance_schema` . `events_statements_summary_by_digest` ORDER BY `DIGEST_TEXT` 1
test 258f5bff705a10fe1c43fd25c29c61fd SELECT `a` , `b` FROM `test` . `v1` 2
test 518f87edc2c96f2b022d6ab3c767df7b SELECT `b` , `a` FROM `test` . `v1` 2
test d972cde0f9bbec28c84e4dcca8ef3281 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1
DROP VIEW test.v1;
DROP TABLE test.t1;
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ SELECT 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
####################################
SELECT event_name, digest, digest_text, sql_text FROM events_statements_history_long;
event_name digest digest_text sql_text
statement/sql/select c9e142fe40c43498607ca5310e11d2ce SELECT ? + ? + SELECT ...
statement/sql/truncate 506e3496d92689cd2367329dc7725165 TRUNCATE TABLE truncat...
statement/sql/select 3e19ece73d286977122b52fb027c180c SELECT ? + ? + SELECT ...
statement/sql/truncate 7ab36a94986dd98b93370b025166a946 TRUNCATE TABLE truncat...
28 changes: 26 additions & 2 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6700,7 +6700,8 @@ longlong Item_func_row_count::val_int()

Item_func_sp::Item_func_sp(THD *thd, Name_resolution_context *context_arg,
sp_name *name, const Sp_handler *sph):
Item_func(thd), Item_sp(thd, context_arg, name), m_handler(sph)
Item_func(thd), Item_sp(thd, context_arg, name), m_handler(sph),
m_filter(NULL)
{
set_maybe_null();
}
Expand All @@ -6709,7 +6710,8 @@ Item_func_sp::Item_func_sp(THD *thd, Name_resolution_context *context_arg,
Item_func_sp::Item_func_sp(THD *thd, Name_resolution_context *context_arg,
sp_name *name_arg, const Sp_handler *sph,
List<Item> &list):
Item_func(thd, list), Item_sp(thd, context_arg, name_arg), m_handler(sph)
Item_func(thd, list), Item_sp(thd, context_arg, name_arg), m_handler(sph),
m_filter(NULL)
{
set_maybe_null();
}
Expand All @@ -6729,6 +6731,18 @@ Item_func_sp::func_name_cstring() const
m_handler == &sp_handler_package_function);
}

void
Item_func_sp::print(String *str, enum_query_type query_type)
{
Item_func::print(str, query_type);
if (m_filter)
{
str->append(STRING_WITH_LEN(" FILTER(WHERE "));
m_filter->print(str, query_type);
str->append(')');
}
}


void my_missing_function_error(const LEX_CSTRING &token, const char *func_name)
{
Expand Down Expand Up @@ -6921,6 +6935,12 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
if (res)
DBUG_RETURN(TRUE);

if (m_filter && m_sp->agg_type() != GROUP_AGGREGATE)
{
my_error(ER_WRONG_USAGE, MYF(0), "FILTER", "non-aggregate function");
DBUG_RETURN(TRUE);
}

if (m_sp->agg_type() == GROUP_AGGREGATE)
{
Item_sum_sp *item_sp;
Expand All @@ -6943,6 +6963,10 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
DBUG_RETURN(TRUE);
*ref= item_sp;
item_sp->name= name;
if (m_filter)
{
item_sp->set_filter(m_filter);
}
bool err= item_sp->fix_fields(thd, ref);
if (err)
DBUG_RETURN(TRUE);
Expand Down
5 changes: 5 additions & 0 deletions sql/item_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -4193,6 +4193,7 @@ class Item_func_sp :public Item_func,
{
private:
const Sp_handler *m_handler;
Item *m_filter;

bool execute();

Expand All @@ -4215,6 +4216,10 @@ class Item_func_sp :public Item_func,

virtual ~Item_func_sp() = default;

void set_filter(Item *filter) { m_filter= filter; }

void print(String *str, enum_query_type query_type) override;

void update_used_tables() override;

void cleanup() override;
Expand Down
5 changes: 4 additions & 1 deletion sql/item_jsonfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4910,6 +4910,9 @@ Item_func_json_objectagg::fix_fields(THD *thd, Item **ref)
* collation.collation->mbmaxlen, UINT_MAX32);


if (fix_filter(thd))
return TRUE;

if (check_sum_func(thd, ref))
return TRUE;

Expand Down Expand Up @@ -4947,7 +4950,7 @@ bool Item_func_json_objectagg::add()
String *key;

key= args[0]->val_str(&buf);
if (args[0]->is_null())
if (args[0]->is_null() || !filter_passed())
return 0;

null_value= 0;
Expand Down
Loading