Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
cbc45d29
Commit
cbc45d29
authored
Mar 30, 2018
by
Varun Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-14592: Custom Aggregates Usage Status Variable
Introduced new status variable for custom aggregate functions.
parent
87ee8563
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
180 additions
and
0 deletions
+180
-0
mysql-test/main/custom_aggregates_i_s.result
mysql-test/main/custom_aggregates_i_s.result
+94
-0
mysql-test/main/custom_aggregates_i_s.test
mysql-test/main/custom_aggregates_i_s.test
+73
-0
mysql-test/main/features.result
mysql-test/main/features.result
+1
-0
sql/item_sum.cc
sql/item_sum.cc
+2
-0
sql/mysqld.cc
sql/mysqld.cc
+1
-0
sql/sql_class.h
sql/sql_class.h
+2
-0
sql/sql_lex.cc
sql/sql_lex.cc
+2
-0
sql/sql_lex.h
sql/sql_lex.h
+3
-0
sql/sql_select.cc
sql/sql_select.cc
+2
-0
No files found.
mysql-test/main/custom_aggregates_i_s.result
0 → 100644
View file @
cbc45d29
flush status;
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 0
create table t2 (sal int(10));
create table t3 (sal int(10),id int);
insert into t3 values (0,1),(1,2),(2,3),(3,4);
create aggregate function f1(x INT) returns int
begin
declare tot_sum int default 0;
declare continue handler for not found return tot_sum;
loop
fetch group next row;
set tot_sum= tot_sum + x;
end loop;
end|
create aggregate function f2 (x int) returns int
begin
declare counter int default 0;
declare continue handler for not found return 0;
loop
fetch group next row;
set counter =counter + (select f1(sal) from t1);
end loop;
end|
create table t1 (sal int(10),id int(10));
INSERT INTO t1 (sal,id) VALUES (5000,1);
INSERT INTO t1 (sal,id) VALUES (2000,2);
INSERT INTO t1 (sal,id) VALUES (1000,3);
Normal select with custom aggregate function
select f1(sal) from t1 where id>= 1;
f1(sal)
8000
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 1
subqueries with custom aggregates
explain
select * from t1, (select f1(sal) as a from t1 where id>= 1) q where q.a=t1.sal;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t1.sal 2
2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 2
explain
select * from t1, (select sal as a from t1 where (select f1(t3.sal) from t3) >=-1 ) q where q.a=t1.sal;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 4
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 3
explain
select (select f1(sal) as a from t3 where t3.id= t1.id ) from t1 ;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 Using where
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 4
explain
select (select f1(sal) as a from t3 where t3.id= t1.id ) from t1 ;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 Using where
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 5
custom aggregates inside other customm aggregates
explain
select f2(sal) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 6
cte with custom aggregates
with agg_sum as (
select f1(sal) from t1 where t1.id >=1 group by t1.id
)
select * from agg_sum;
f1(sal)
5000
2000
1000
show status like "%custom_aggregate%";
Variable_name Value
Feature_custom_aggregate_functions 7
drop table t2,t1,t3;
drop function f1;
drop function f2;
mysql-test/main/custom_aggregates_i_s.test
0 → 100644
View file @
cbc45d29
flush
status
;
show
status
like
"%custom_aggregate%"
;
create
table
t2
(
sal
int
(
10
));
create
table
t3
(
sal
int
(
10
),
id
int
);
insert
into
t3
values
(
0
,
1
),(
1
,
2
),(
2
,
3
),(
3
,
4
);
delimiter
|
;
create
aggregate
function
f1
(
x
INT
)
returns
int
begin
declare
tot_sum
int
default
0
;
declare
continue
handler
for
not
found
return
tot_sum
;
loop
fetch
group
next
row
;
set
tot_sum
=
tot_sum
+
x
;
end
loop
;
end
|
create
aggregate
function
f2
(
x
int
)
returns
int
begin
declare
counter
int
default
0
;
declare
continue
handler
for
not
found
return
0
;
loop
fetch
group
next
row
;
set
counter
=
counter
+
(
select
f1
(
sal
)
from
t1
);
end
loop
;
end
|
delimiter
;
|
create
table
t1
(
sal
int
(
10
),
id
int
(
10
));
INSERT
INTO
t1
(
sal
,
id
)
VALUES
(
5000
,
1
);
INSERT
INTO
t1
(
sal
,
id
)
VALUES
(
2000
,
2
);
INSERT
INTO
t1
(
sal
,
id
)
VALUES
(
1000
,
3
);
--
echo
Normal
select
with
custom
aggregate
function
select
f1
(
sal
)
from
t1
where
id
>=
1
;
show
status
like
"%custom_aggregate%"
;
--
echo
subqueries
with
custom
aggregates
explain
select
*
from
t1
,
(
select
f1
(
sal
)
as
a
from
t1
where
id
>=
1
)
q
where
q
.
a
=
t1
.
sal
;
show
status
like
"%custom_aggregate%"
;
explain
select
*
from
t1
,
(
select
sal
as
a
from
t1
where
(
select
f1
(
t3
.
sal
)
from
t3
)
>=-
1
)
q
where
q
.
a
=
t1
.
sal
;
show
status
like
"%custom_aggregate%"
;
explain
select
(
select
f1
(
sal
)
as
a
from
t3
where
t3
.
id
=
t1
.
id
)
from
t1
;
show
status
like
"%custom_aggregate%"
;
explain
select
(
select
f1
(
sal
)
as
a
from
t3
where
t3
.
id
=
t1
.
id
)
from
t1
;
show
status
like
"%custom_aggregate%"
;
--
echo
custom
aggregates
inside
other
customm
aggregates
explain
select
f2
(
sal
)
from
t1
;
show
status
like
"%custom_aggregate%"
;
--
echo
cte
with
custom
aggregates
with
agg_sum
as
(
select
f1
(
sal
)
from
t1
where
t1
.
id
>=
1
group
by
t1
.
id
)
select
*
from
agg_sum
;
show
status
like
"%custom_aggregate%"
;
drop
table
t2
,
t1
,
t3
;
drop
function
f1
;
drop
function
f2
;
mysql-test/main/features.result
View file @
cbc45d29
...
...
@@ -4,6 +4,7 @@ flush status;
show status like "feature%";
Variable_name Value
Feature_check_constraint 0
Feature_custom_aggregate_functions 0
Feature_delay_key_write 0
Feature_dynamic_columns 0
Feature_fulltext 0
...
...
sql/item_sum.cc
View file @
cbc45d29
...
...
@@ -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
;
...
...
sql/mysqld.cc
View file @
cbc45d29
...
...
@@ -8527,6 +8527,7 @@ SHOW_VAR status_vars[]= {
{
"Executed_events"
,
(
char
*
)
&
executed_events
,
SHOW_LONG_NOFLUSH
},
{
"Executed_triggers"
,
(
char
*
)
offsetof
(
STATUS_VAR
,
executed_triggers
),
SHOW_LONG_STATUS
},
{
"Feature_check_constraint"
,
(
char
*
)
&
feature_check_constraint
,
SHOW_LONG
},
{
"Feature_custom_aggregate_functions"
,
(
char
*
)
offsetof
(
STATUS_VAR
,
feature_custom_aggregate_functions
),
SHOW_LONG_STATUS
},
{
"Feature_delay_key_write"
,
(
char
*
)
&
feature_files_opened_with_delayed_keys
,
SHOW_LONG
},
{
"Feature_dynamic_columns"
,
(
char
*
)
offsetof
(
STATUS_VAR
,
feature_dynamic_columns
),
SHOW_LONG_STATUS
},
{
"Feature_fulltext"
,
(
char
*
)
offsetof
(
STATUS_VAR
,
feature_fulltext
),
SHOW_LONG_STATUS
},
...
...
sql/sql_class.h
View file @
cbc45d29
...
...
@@ -814,6 +814,8 @@ typedef struct system_status_var
ulong
filesort_pq_sorts_
;
/* Features used */
ulong
feature_custom_aggregate_functions
;
/* +1 when custom aggregate
functions are used */
ulong
feature_dynamic_columns
;
/* +1 when creating a dynamic column */
ulong
feature_fulltext
;
/* +1 when MATCH is used */
ulong
feature_gis
;
/* +1 opening a table with GIS features */
...
...
sql/sql_lex.cc
View file @
cbc45d29
...
...
@@ -2266,6 +2266,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
;
...
...
@@ -2305,6 +2306,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
;
...
...
sql/sql_lex.h
View file @
cbc45d29
...
...
@@ -1221,9 +1221,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
()
{
...
...
@@ -1267,6 +1269,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
;
...
...
sql/sql_select.cc
View file @
cbc45d29
...
...
@@ -3255,6 +3255,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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment