mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed bug mdev-11138.
Supported usage of expressions with window functions in SELECTs without tables.
This commit is contained in:
@ -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
|
||||||
|
@ -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);
|
||||||
|
@ -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()
|
|||||||
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()
|
|||||||
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,
|
|||||||
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()
|
|||||||
|
|
||||||
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))
|
||||||
|
@ -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;
|
||||||
|
Reference in New Issue
Block a user