[Commits] 19d277e9542: MDEV-15846: Sever crashed with MEDIAN() window function
revision-id: 19d277e95420d14a22eda3ced99f277a68be7cbb (mariadb-10.3.0-765-g19d277e9542) parent(s): 91245909a2f0c89444ecb5af587284f53b7196ee author: Varun Gupta committer: Varun Gupta timestamp: 2018-04-12 06:42:39 +0530 message: MDEV-15846: Sever crashed with MEDIAN() window function For an empty list we expect list.next == &list.first but this does not happen when we have multiple calls to median functions to the select list. This condition satisfies for the first call and not for the subsequent ones and therefore the serve crashes as we are not able to insert an element into order list of the median function. Fixed by adding prepare_add_window_spec(thd) call that initialises the order list. --- mysql-test/main/win_percentile.result | 9 +++++++++ mysql-test/main/win_percentile.test | 11 +++++++++++ sql/sql_yacc.yy | 1 + 3 files changed, 21 insertions(+) diff --git a/mysql-test/main/win_percentile.result b/mysql-test/main/win_percentile.result index c51e2e6bd51..bab8abbab12 100644 --- a/mysql-test/main/win_percentile.result +++ b/mysql-test/main/win_percentile.result @@ -324,3 +324,12 @@ median(score) over (partition by name) c 4.0000000000 4.0000000000 4.0000000000 4.0000000000 drop table t1; +# +# MDEV-15846: Sever crashed with MEDIAN() window function +# +CREATE TABLE t1 ( pk int PRIMARY KEY, a1 int, a2 int); +SELECT MEDIAN(a1) OVER (), +MEDIAN(a2) OVER (PARTITION BY pk) +FROM t1; +MEDIAN(a1) OVER () MEDIAN(a2) OVER (PARTITION BY pk) +DROP TABLE t1; diff --git a/mysql-test/main/win_percentile.test b/mysql-test/main/win_percentile.test index 468d8cff56b..b9631a2f710 100644 --- a/mysql-test/main/win_percentile.test +++ b/mysql-test/main/win_percentile.test @@ -102,3 +102,14 @@ select median(score) over (partition by name), percentile_cont(0.8) within grou select median(score) over (partition by name), percentile_cont(0.9) within group(order by score) over (partition by name) as c from t1; select median(score) over (partition by name), percentile_cont(1) within group(order by score) over (partition by name) as c from t1; drop table t1; + +--echo # +--echo # MDEV-15846: Sever crashed with MEDIAN() window function +--echo # + +CREATE TABLE t1 ( pk int PRIMARY KEY, a1 int, a2 int); + +SELECT MEDIAN(a1) OVER (), + MEDIAN(a2) OVER (PARTITION BY pk) +FROM t1; +DROP TABLE t1; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d69156ced9b..7e90b9b4cd2 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -11261,6 +11261,7 @@ percentile_function: { MYSQL_YYABORT; } + Select->prepare_add_window_spec(thd); if (add_order_to_list(thd, $3,FALSE)) MYSQL_YYABORT; $$= new (thd->mem_root) Item_sum_percentile_cont(thd, args);
participants (1)
-
varunraiko1803@gmail.com