summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/win.result11
-rw-r--r--mysql-test/t/win.test15
-rw-r--r--sql/sql_select.cc4
3 files changed, 28 insertions, 2 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result
index f693d6641df..b863ee4ddd6 100644
--- a/mysql-test/r/win.result
+++ b/mysql-test/r/win.result
@@ -2842,3 +2842,14 @@ max(i) min(i) f
16 14 2
20 17 3
drop table t1;
+#
+# MDEV-12015: window function over select with WHERE
+# that is always FALSE
+#
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (3), (1), (2);
+SELECT i, ROW_NUMBER() OVER () FROM t1 WHERE 1 = 2;
+i ROW_NUMBER() OVER ()
+SELECT i, COUNT(*) OVER () FROM t1 WHERE 1 = 2;
+i COUNT(*) OVER ()
+DROP TABLE t1;
diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test
index c231c1eeecf..f92334e4079 100644
--- a/mysql-test/t/win.test
+++ b/mysql-test/t/win.test
@@ -1636,3 +1636,18 @@ select max(i), min(i), min(max(i)-min(i)) over (partition by count(i)) f
group by b;
drop table t1;
+
+--echo #
+--echo # MDEV-12015: window function over select with WHERE
+--echo # that is always FALSE
+--echo #
+
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (3), (1), (2);
+
+SELECT i, ROW_NUMBER() OVER () FROM t1 WHERE 1 = 2;
+
+SELECT i, COUNT(*) OVER () FROM t1 WHERE 1 = 2;
+
+DROP TABLE t1;
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 865d852d371..38752a153b5 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2779,8 +2779,8 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
tmp_table_param.using_outer_summary_function=
tab->tmp_table_param->using_outer_summary_function;
tab->join= this;
- DBUG_ASSERT(tab > tab->join->join_tab || !tables_list);
- if (tables_list)
+ DBUG_ASSERT(tab > join_tab || select_lex->have_window_funcs());
+ if (tab > join_tab)
(tab - 1)->next_select= sub_select_postjoin_aggr;
tab->aggr= new (thd->mem_root) AGGR_OP(tab);
if (!tab->aggr)