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
e51b015f
Commit
e51b015f
authored
Feb 04, 2017
by
Igor Babaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug mdev-11138.
Supported usage of expressions with window functions in SELECTs without tables.
parent
20aae56e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
4 deletions
+52
-4
mysql-test/r/win.result
mysql-test/r/win.result
+24
-0
mysql-test/t/win.test
mysql-test/t/win.test
+12
-0
sql/sql_select.cc
sql/sql_select.cc
+11
-4
sql/sql_window.cc
sql/sql_window.cc
+5
-0
No files found.
mysql-test/r/win.result
View file @
e51b015f
...
@@ -2521,3 +2521,27 @@ id rnk
...
@@ -2521,3 +2521,27 @@ id rnk
2 2
2 2
drop view v1;
drop view v1;
drop table t1;
drop table t1;
#
# MDEV-11138: window function in the query without tables
#
select row_number() over ();
row_number() over ()
1
select count(*) over ();
count(*) over ()
1
select sum(5) over ();
sum(5) over ()
5
select row_number() over (), sum(5) over ();
row_number() over () sum(5) over ()
1 5
select row_number() over (order by 2);
row_number() over (order by 2)
1
select row_number() over (partition by 2);
row_number() over (partition by 2)
1
select row_number() over (partition by 4 order by 1+2);
row_number() over (partition by 4 order by 1+2)
1
mysql-test/t/win.test
View file @
e51b015f
...
@@ -1535,3 +1535,15 @@ select * from v1;
...
@@ -1535,3 +1535,15 @@ select * from v1;
drop
view
v1
;
drop
view
v1
;
drop
table
t1
;
drop
table
t1
;
--
echo
#
--
echo
# MDEV-11138: window function in the query without tables
--
echo
#
select
row_number
()
over
();
select
count
(
*
)
over
();
select
sum
(
5
)
over
();
select
row_number
()
over
(),
sum
(
5
)
over
();
select
row_number
()
over
(
order
by
2
);
select
row_number
()
over
(
partition
by
2
);
select
row_number
()
over
(
partition
by
4
order
by
1
+
2
);
sql/sql_select.cc
View file @
e51b015f
...
@@ -1439,6 +1439,13 @@ JOIN::optimize_inner()
...
@@ -1439,6 +1439,13 @@ JOIN::optimize_inner()
{
{
DBUG_PRINT
(
"info"
,(
"No tables"
));
DBUG_PRINT
(
"info"
,(
"No tables"
));
error
=
0
;
error
=
0
;
if
(
select_lex
->
have_window_funcs
())
{
if
(
!
join_tab
&&
!
(
join_tab
=
(
JOIN_TAB
*
)
thd
->
alloc
(
sizeof
(
JOIN_TAB
))))
DBUG_RETURN
(
1
);
need_tmp
=
1
;
}
if
(
make_aggr_tables_info
())
if
(
make_aggr_tables_info
())
DBUG_RETURN
(
1
);
DBUG_RETURN
(
1
);
goto
setup_subq_exit
;
goto
setup_subq_exit
;
...
@@ -2186,7 +2193,7 @@ bool JOIN::make_aggr_tables_info()
...
@@ -2186,7 +2193,7 @@ bool JOIN::make_aggr_tables_info()
Setup last table to provide fields and all_fields lists to the next
Setup last table to provide fields and all_fields lists to the next
node in the plan.
node in the plan.
*/
*/
if
(
join_tab
)
if
(
join_tab
&&
top_join_tab_count
)
{
{
join_tab
[
top_join_tab_count
-
1
].
fields
=
&
fields_list
;
join_tab
[
top_join_tab_count
-
1
].
fields
=
&
fields_list
;
join_tab
[
top_join_tab_count
-
1
].
all_fields
=
&
all_fields
;
join_tab
[
top_join_tab_count
-
1
].
all_fields
=
&
all_fields
;
...
@@ -2310,7 +2317,8 @@ bool JOIN::make_aggr_tables_info()
...
@@ -2310,7 +2317,8 @@ bool JOIN::make_aggr_tables_info()
single table queries, thus it is sufficient to test only the first
single table queries, thus it is sufficient to test only the first
join_tab element of the plan for its access method.
join_tab element of the plan for its access method.
*/
*/
if
(
join_tab
&&
join_tab
->
is_using_loose_index_scan
())
if
(
join_tab
&&
top_join_tab_count
&&
join_tab
->
is_using_loose_index_scan
())
tmp_table_param
.
precomputed_group_by
=
tmp_table_param
.
precomputed_group_by
=
!
join_tab
->
is_using_agg_loose_index_scan
();
!
join_tab
->
is_using_agg_loose_index_scan
();
...
@@ -2770,7 +2778,7 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
...
@@ -2770,7 +2778,7 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
tmp_table_param
.
using_outer_summary_function
=
tmp_table_param
.
using_outer_summary_function
=
tab
->
tmp_table_param
->
using_outer_summary_function
;
tab
->
tmp_table_param
->
using_outer_summary_function
;
tab
->
join
=
this
;
tab
->
join
=
this
;
DBUG_ASSERT
(
tab
>
tab
->
join
->
join_tab
);
DBUG_ASSERT
(
tab
>
tab
->
join
->
join_tab
||
!
top_join_tab_count
);
(
tab
-
1
)
->
next_select
=
sub_select_postjoin_aggr
;
(
tab
-
1
)
->
next_select
=
sub_select_postjoin_aggr
;
tab
->
aggr
=
new
(
thd
->
mem_root
)
AGGR_OP
(
tab
);
tab
->
aggr
=
new
(
thd
->
mem_root
)
AGGR_OP
(
tab
);
if
(
!
tab
->
aggr
)
if
(
!
tab
->
aggr
)
...
@@ -3424,7 +3432,6 @@ JOIN::destroy()
...
@@ -3424,7 +3432,6 @@ JOIN::destroy()
if
(
join_tab
)
if
(
join_tab
)
{
{
DBUG_ASSERT
(
table_count
+
aggr_tables
>
0
);
for
(
JOIN_TAB
*
tab
=
first_linear_tab
(
this
,
WITH_BUSH_ROOTS
,
for
(
JOIN_TAB
*
tab
=
first_linear_tab
(
this
,
WITH_BUSH_ROOTS
,
WITH_CONST_TABLES
);
WITH_CONST_TABLES
);
tab
;
tab
=
next_linear_tab
(
this
,
tab
,
WITH_BUSH_ROOTS
))
tab
;
tab
=
next_linear_tab
(
this
,
tab
,
WITH_BUSH_ROOTS
))
...
...
sql/sql_window.cc
View file @
e51b015f
...
@@ -2801,6 +2801,11 @@ bool Window_funcs_sort::setup(THD *thd, SQL_SELECT *sel,
...
@@ -2801,6 +2801,11 @@ bool Window_funcs_sort::setup(THD *thd, SQL_SELECT *sel,
sort_order
=
order
;
sort_order
=
order
;
}
}
filesort
=
new
(
thd
->
mem_root
)
Filesort
(
sort_order
,
HA_POS_ERROR
,
true
,
NULL
);
filesort
=
new
(
thd
->
mem_root
)
Filesort
(
sort_order
,
HA_POS_ERROR
,
true
,
NULL
);
if
(
!
join_tab
->
join
->
top_join_tab_count
)
{
filesort
->
tracker
=
new
(
thd
->
mem_root
)
Filesort_tracker
(
thd
->
lex
->
analyze_stmt
);
}
/* Apply the same condition that the subsequent sort has. */
/* Apply the same condition that the subsequent sort has. */
filesort
->
select
=
sel
;
filesort
->
select
=
sel
;
...
...
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