[Commits] f8b41f9: Fixed bug mdev-12336.

IgorBabaev igor at mariadb.com
Wed Mar 29 01:08:50 EEST 2017


revision-id: f8b41f9664ba1fa4a7fe879fc11eaa48f722f618 (mariadb-10.2.4-86-gf8b41f9)
parent(s): 96ec87d2cebc6e5b0b236aaaece79bd81bf4fcef
author: Igor Babaev
committer: Igor Babaev
timestamp: 2017-03-28 15:08:50 -0700
message:

Fixed bug mdev-12336.

The function Item::split_sum_func2() incorrectly processed the function
items with window functions that were not window functions themselfes
and were used as arguments of other functions.

---
 mysql-test/r/win.result | 26 ++++++++++++++++++++++++++
 mysql-test/t/win.test   | 26 ++++++++++++++++++++++++++
 sql/item.cc             |  3 +++
 3 files changed, 55 insertions(+)

diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result
index d48bb34..26194bc 100644
--- a/mysql-test/r/win.result
+++ b/mysql-test/r/win.result
@@ -3029,3 +3029,29 @@ show warnings;
 Level	Code	Message
 set sql_mode=@sql_mode_save;
 drop table t1;
+#
+# MDEV-12336: several functions over a window function 
+#
+create table t1 (name varchar(10), cnt int);
+insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
+select q.name, q.row_cnt, 
+round( 100 * ( q.row_cnt /
+sum(q.row_cnt) over
+( 
+order by q.name 
+rows between
+unbounded preceding and
+unbounded following
+)
+),2
+) pct_of_total
+from 
+( 
+select name, count(*) row_cnt, sum(cnt) sum_cnt 
+from t1 
+group by 1
+) q;
+name	row_cnt	pct_of_total
+Fred	2	66.67
+Joe	1	33.33
+drop table t1;
diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test
index 3cd17ae..82c1dad 100644
--- a/mysql-test/t/win.test
+++ b/mysql-test/t/win.test
@@ -1830,3 +1830,29 @@ set sql_mode=@sql_mode_save;
 
 drop table t1;
 
+--echo #
+--echo # MDEV-12336: several functions over a window function 
+--echo #
+  
+create table t1 (name varchar(10), cnt int);
+insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
+
+select q.name, q.row_cnt, 
+       round( 100 * ( q.row_cnt /
+                      sum(q.row_cnt) over
+                        ( 
+                          order by q.name 
+                          rows between
+                            unbounded preceding and
+                            unbounded following
+                        )
+                    ),2
+            ) pct_of_total
+from 
+( 
+  select name, count(*) row_cnt, sum(cnt) sum_cnt 
+  from t1 
+  group by 1
+) q;
+
+drop table t1;
diff --git a/sql/item.cc b/sql/item.cc
index c34d27f..2ff9d4e 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1986,6 +1986,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
                                         &ref_pointer_array[el], 0, name))))
       return;                                   // fatal_error is set
   }
+  else if (type() == FUNC_ITEM && 
+           ((Item_func *) this)->with_window_func)
+    return;
   else
   {
     if (!(item_ref= (new (thd->mem_root)


More information about the commits mailing list