Hi Varun
This generally looks good, 2 comments inline.
Vicentiu
diff --git a/mysql-test/t/custom_aggregate_functions.test b/mysql-test/t/custom_aggregate_functions.test
index 20fcc35f39f..a93ec545f01 100644
--- a/mysql-test/t/custom_aggregate_functions.test
+++ b/mysql-test/t/custom_aggregate_functions.test
@@ -16,7 +16,9 @@ create table t1 (sal int(10),id int(10));
INSERT INTO t1 (sal,id) VALUES (5000,1);
INSERT INTO t1 (sal,id) VALUES (2000,1);
INSERT INTO t1 (sal,id) VALUES (1000,1);
# Please test that this works with subqueries, views, ctes and when calling from
# other stored procedures.
+show global status like "Feature_custom_aggregate_functions";
select f1(sal) from t1 where id>= 1;
+show global status like "Feature_custom_aggregate_functions";
select * from t2;
drop table t2;
drop function f1;
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index d4abdfc614f..7c0390e543f 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -313,6 +313,8 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref)
}
}
aggr_sel->set_agg_func_used(true);
+ if (sum_func() == SP_AGGREGATE_FUNC)
+ aggr_sel->set_custom_agg_func_used(true);
update_used_tables();
thd->lex->in_sum_func= in_sum_func;
return FALSE;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index c7fbf0a594c..75ccda408b1 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -8491,6 +8491,7 @@ SHOW_VAR status_vars[]= {
{"Executed_triggers", (char*) offsetof(STATUS_VAR, executed_triggers), SHOW_LONG_STATUS},
{"Feature_check_constraint", (char*) &feature_check_constraint, SHOW_LONG },
{"Feature_delay_key_write", (char*) &feature_files_opened_with_delayed_keys, SHOW_LONG },
Please move this up so the variable names are ordered alphabetically.
+ {"Feature_custom_aggregate_functions", (char*) offsetof(STATUS_VAR, feature_custom_aggregate_functions), SHOW_LONG_STATUS},
{"Feature_dynamic_columns", (char*) offsetof(STATUS_VAR, feature_dynamic_columns), SHOW_LONG_STATUS},
{"Feature_fulltext", (char*) offsetof(STATUS_VAR, feature_fulltext), SHOW_LONG_STATUS},
{"Feature_gis", (char*) offsetof(STATUS_VAR, feature_gis), SHOW_LONG_STATUS},
revision-id: c9ae12348143f59e875a52e2eb285c5ed7d7af56 (mariadb-10.3.0-285-gc9ae1234814)
parent(s): c60095a818dce92838940525899a13a05633d148
author: Varun Gupta
committer: Varun Gupta
timestamp: 2017-12-09 12:22:26 +0530
message:
MDEV-14592: Custom Aggregates Usage Status Variable
---
mysql-test/r/custom_aggregate_functions.result | 6 ++++++
mysql-test/t/custom_aggregate_functions.test | 2 ++
sql/item_sum.cc | 2 ++
sql/mysqld.cc | 1 +
sql/sql_lex.cc | 2 ++
sql/sql_lex.h | 3 +++
sql/sql_select.cc | 2 ++
7 files changed, 18 insertions(+)
diff --git a/mysql-test/r/custom_aggregate_functions.result b/mysql-test/r/custom_aggregate_functions.result
index ca8612ba652..f70675fa4db 100644
--- a/mysql-test/r/custom_aggregate_functions.result
+++ b/mysql-test/r/custom_aggregate_functions.result
@@ -11,6 +11,9 @@ create table t1 (sal int(10),id int(10));
INSERT INTO t1 (sal,id) VALUES (5000,1);
INSERT INTO t1 (sal,id) VALUES (2000,1);
INSERT INTO t1 (sal,id) VALUES (1000,1);
+show global status like "Feature_custom_aggregate_functions";
+Variable_name Value
+Feature_custom_aggregate_functions 0
select f1(sal) from t1 where id>= 1;
f1(sal)
0
@@ -18,6 +21,9 @@ Warnings:
Note 4093 At line 5 in test.f1
Note 4093 At line 5 in test.f1
Note 4093 At line 5 in test.f1
+show global status like "Feature_custom_aggregate_functions";
+Variable_name Value
+Feature_custom_aggregate_functions 1
select * from t2;
sal
5000
diff --git a/mysql-test/t/custom_aggregate_functions.test b/mysql-test/t/custom_aggregate_functions.test
index 20fcc35f39f..a93ec545f01 100644
--- a/mysql-test/t/custom_aggregate_functions.test
+++ b/mysql-test/t/custom_aggregate_functions.test
@@ -16,7 +16,9 @@ create table t1 (sal int(10),id int(10));
INSERT INTO t1 (sal,id) VALUES (5000,1);
INSERT INTO t1 (sal,id) VALUES (2000,1);
INSERT INTO t1 (sal,id) VALUES (1000,1);
+show global status like "Feature_custom_aggregate_functions";
select f1(sal) from t1 where id>= 1;
+show global status like "Feature_custom_aggregate_functions";
select * from t2;
drop table t2;
drop function f1;
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index d4abdfc614f..7c0390e543f 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -313,6 +313,8 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref)
}
}
aggr_sel->set_agg_func_used(true);
+ if (sum_func() == SP_AGGREGATE_FUNC)
+ aggr_sel->set_custom_agg_func_used(true);
update_used_tables();
thd->lex->in_sum_func= in_sum_func;
return FALSE;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index c7fbf0a594c..75ccda408b1 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -8491,6 +8491,7 @@ SHOW_VAR status_vars[]= {
{"Executed_triggers", (char*) offsetof(STATUS_VAR, executed_triggers), SHOW_LONG_STATUS},
{"Feature_check_constraint", (char*) &feature_check_constraint, SHOW_LONG },
{"Feature_delay_key_write", (char*) &feature_files_opened_with_delayed_keys, SHOW_LONG },
+ {"Feature_custom_aggregate_functions", (char*) offsetof(STATUS_VAR, feature_custom_aggregate_functions), SHOW_LONG_STATUS},
{"Feature_dynamic_columns", (char*) offsetof(STATUS_VAR, feature_dynamic_columns), SHOW_LONG_STATUS},
{"Feature_fulltext", (char*) offsetof(STATUS_VAR, feature_fulltext), SHOW_LONG_STATUS},
{"Feature_gis", (char*) offsetof(STATUS_VAR, feature_gis), SHOW_LONG_STATUS},
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 6cb065c3985..277469cc0aa 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2241,6 +2241,7 @@ void st_select_lex::init_query()
select_list_tables= 0;
m_non_agg_field_used= false;
m_agg_func_used= false;
+ m_custom_agg_func_used= false;
window_specs.empty();
window_funcs.empty();
tvc= 0;
@@ -2278,6 +2279,7 @@ void st_select_lex::init_select()
merged_into= 0;
m_non_agg_field_used= false;
m_agg_func_used= false;
+ m_custom_agg_func_used= false;
name_visibility_map= 0;
with_dep= 0;
join= 0;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 069b75628e3..9b40529d3e2 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1213,9 +1213,11 @@ class st_select_lex: public st_select_lex_node
*/
bool non_agg_field_used() const { return m_non_agg_field_used; }
bool agg_func_used() const { return m_agg_func_used; }
+ bool custom_agg_func_used() const { return m_custom_agg_func_used; }
void set_non_agg_field_used(bool val) { m_non_agg_field_used= val; }
void set_agg_func_used(bool val) { m_agg_func_used= val; }
+ void set_custom_agg_func_used(bool val) { m_custom_agg_func_used= val; }
inline void set_with_clause(With_clause *with_clause);
With_clause *get_with_clause()
{
@@ -1259,6 +1261,7 @@ class st_select_lex: public st_select_lex_node
private:
bool m_non_agg_field_used;
bool m_agg_func_used;
+ bool m_custom_agg_func_used;
/* current index hint kind. used in filling up index_hints */
enum index_hint_type current_index_hint_type;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 96aa227b439..c0d7c720910 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2909,6 +2909,8 @@ bool JOIN::make_aggr_tables_info()
/* Count that we're using window functions. */
status_var_increment(thd->status_var.feature_window_functions);
}
+ if (select_lex->custom_agg_func_used())
+ status_var_increment(thd->status_var.feature_custom_aggregate_functions);
fields= curr_fields_list;
// Reset before execution
_______________________________________________
commits mailing list
commits@mariadb.org
https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits