IMPALA-2320: Use a separate MemPool for the FunctionContexts in AnalyticEvalNode.

The bug:
There was a MemPool in AnalyticEvalNode with a dual purpose:
(1) Allocate temporary tuples.
(2) Back the FunctionContexts of the aggregate function evaluators.
FunctionContexts use FreePools to do their own memory management using a
pointer-based structure that is stored in the memory blocks themselves.
When calling AnalyticEvalNode::Reset() we reset that mem pool backing
that pointer-based structure. Those pointers were then clobbered by
subsequent allocations (and writes) for temporary tuples, ultimately
resulting in the FreePool incorrectly reporting a double free
while doing a Finalize() of an aggregate function.

The fix:
While there are several other ways to address this issue, I chose to
use a different MemPool for the FunctionContexts because that seemed
to be the most sane and minimally invasive fix. That MemPool is not
reset during AnalyticEvalNode::Reset() because the memory is
ultimately managed by the FreePools of the FunctionContexts.

Change-Id: I42fd60785d3c6dec93436cd9ca64de58d1b15c7e
Reviewed-on: http://gerrit.cloudera.org:8080/857
Reviewed-by: Alex Behm <alex.behm@cloudera.com>
Tested-by: Internal Jenkins
This commit is contained in:
Alex Behm
2015-09-11 08:49:43 -07:00
committed by ishaan
parent 057b0b7dba
commit ef29c976df
3 changed files with 62 additions and 3 deletions

View File

@@ -200,6 +200,59 @@ where c_custkey < 4
bigint,string,bigint,decimal,decimal,string,string
====
---- QUERY
# Test analytic functions without partition by and order by inside a subplan.
select c_custkey, v.* from customer c,
(select count(o_orderkey) over() c, sum(o_totalprice) over() s,
avg(o_totalprice) over() a, max(o_orderstatus) over() mx,
min(o_orderdate) over() mn
from c.c_orders) v
where c_custkey < 4
---- RESULTS
1,6,587762.91,97960.48,'O','1992-04-19'
1,6,587762.91,97960.48,'O','1992-04-19'
1,6,587762.91,97960.48,'O','1992-04-19'
1,6,587762.91,97960.48,'O','1992-04-19'
1,6,587762.91,97960.48,'O','1992-04-19'
1,6,587762.91,97960.48,'O','1992-04-19'
2,7,1028273.43,146896.20,'P','1992-04-05'
2,7,1028273.43,146896.20,'P','1992-04-05'
2,7,1028273.43,146896.20,'P','1992-04-05'
2,7,1028273.43,146896.20,'P','1992-04-05'
2,7,1028273.43,146896.20,'P','1992-04-05'
2,7,1028273.43,146896.20,'P','1992-04-05'
2,7,1028273.43,146896.20,'P','1992-04-05'
---- TYPES
bigint,bigint,decimal,decimal,string,string
====
---- QUERY
# Test analytic functions with partition by inside a subplan.
select c_custkey, v.* from customer c,
(select o_orderstatus,
count(o_orderkey) over(partition by o_orderstatus) c,
sum(o_totalprice) over(partition by o_orderstatus) s,
avg(o_totalprice) over(partition by o_orderstatus) a,
max(o_orderstatus) over(partition by o_orderstatus) mx,
min(o_orderdate) over(partition by o_orderstatus) mn
from c.c_orders) v
where c_custkey < 4
---- RESULTS
1,'F',2,197679.65,98839.82,'F','1992-04-19'
1,'F',2,197679.65,98839.82,'F','1992-04-19'
1,'O',4,390083.26,97520.81,'O','1996-06-29'
1,'O',4,390083.26,97520.81,'O','1996-06-29'
1,'O',4,390083.26,97520.81,'O','1996-06-29'
1,'O',4,390083.26,97520.81,'O','1996-06-29'
2,'F',4,319892.45,79973.11,'F','1992-04-05'
2,'F',4,319892.45,79973.11,'F','1992-04-05'
2,'F',4,319892.45,79973.11,'F','1992-04-05'
2,'F',4,319892.45,79973.11,'F','1992-04-05'
2,'O',2,486983.63,243491.81,'O','1996-08-05'
2,'O',2,486983.63,243491.81,'O','1996-08-05'
2,'P',1,221397.35,221397.35,'P','1995-03-10'
---- TYPES
bigint,string,bigint,decimal,decimal,string,string
====
---- QUERY
# Test left outer join of a relative table ref.
select c_custkey, c_mktsegment, o_orderkey, o_orderdate
from customer c left outer join c.c_orders