From c9f7948bc47edc7ddc3b3693b9a3e4b623a97ca6 Mon Sep 17 00:00:00 2001 From: Mithun C Y Date: Fri, 30 Jan 2015 16:36:23 +0530 Subject: [PATCH] Bug #19892803: ASSERTION FAILED: N < M_SIZE WITH DISTINCT TIME ISSUE: ------ We pre-allocate the ref_pointer_array before we resolve outer references. This means that in some cases the ref_pointer_array may not be large enough to hold all references created. One such case is aggregate functions in having clause of a subquery which may add items to select list of outer query. So it is necessary to consider select_n_having_items for subqueries while allocating ref_pointer_array else we will get buffer overflow. SOLUTION: --------- Allocate a larger ref_pointer_array by aggregating select_n_having_items for subqueries. The fix in sql_yacc.yy is a backport from bug fix 18782905. --- sql/sql_yacc.yy | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 74a21c9f6b6..b32f7d26cf3 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14128,6 +14128,13 @@ subselect_end: */ lex->current_select->select_n_where_fields+= child->select_n_where_fields; + + /* + Aggregate functions in having clause may add fields to an outer + select. Count them also. + */ + lex->current_select->select_n_having_items+= + child->select_n_having_items; } ;