Fix partial aggregation for variance(int4) and related aggregates.
A typo in numeric_poly_combine caused bogus results for queries using it, but of course would only manifest if parallel aggregation is performed. Reported by Rajkumar Raghuwanshi. David Rowley did the diagnosis and the fix; I editorialized rather heavily on his regression test additions. Back-patch to v10 where the breakage was introduced (by 9cca11c91). Discussion: https://postgr.es/m/CAKcux6nU4E2x8nkSBpLOT2DPvQ5LviJ3SGyAN6Sz7qDH4G4+Pw@mail.gmail.com
This commit is contained in:
parent
a4c95b0b80
commit
b8a1d03020
@ -4054,8 +4054,8 @@ numeric_poly_combine(PG_FUNCTION_ARGS)
|
||||
state1->sumX = state2->sumX;
|
||||
state1->sumX2 = state2->sumX2;
|
||||
#else
|
||||
accum_sum_copy(&state2->sumX, &state1->sumX);
|
||||
accum_sum_copy(&state2->sumX2, &state1->sumX2);
|
||||
accum_sum_copy(&state1->sumX, &state2->sumX);
|
||||
accum_sum_copy(&state1->sumX2, &state2->sumX2);
|
||||
#endif
|
||||
|
||||
MemoryContextSwitchTo(old_context);
|
||||
|
@ -2054,3 +2054,30 @@ SELECT balk(hundred) FROM tenk1;
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
-- test coverage for aggregate combine/serial/deserial functions
|
||||
BEGIN ISOLATION LEVEL REPEATABLE READ;
|
||||
SET parallel_setup_cost = 0;
|
||||
SET parallel_tuple_cost = 0;
|
||||
SET min_parallel_table_scan_size = 0;
|
||||
SET max_parallel_workers_per_gather = 4;
|
||||
SET enable_indexonlyscan = off;
|
||||
-- variance(int4) covers numeric_poly_combine
|
||||
-- sum(int8) covers int8_avg_combine
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT variance(unique1::int4), sum(unique1::int8) FROM tenk1;
|
||||
QUERY PLAN
|
||||
----------------------------------------------
|
||||
Finalize Aggregate
|
||||
-> Gather
|
||||
Workers Planned: 4
|
||||
-> Partial Aggregate
|
||||
-> Parallel Seq Scan on tenk1
|
||||
(5 rows)
|
||||
|
||||
SELECT variance(unique1::int4), sum(unique1::int8) FROM tenk1;
|
||||
variance | sum
|
||||
----------------------+----------
|
||||
8334166.666666666667 | 49995000
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
|
@ -900,3 +900,21 @@ EXPLAIN (COSTS OFF) SELECT balk(hundred) FROM tenk1;
|
||||
SELECT balk(hundred) FROM tenk1;
|
||||
|
||||
ROLLBACK;
|
||||
|
||||
-- test coverage for aggregate combine/serial/deserial functions
|
||||
BEGIN ISOLATION LEVEL REPEATABLE READ;
|
||||
|
||||
SET parallel_setup_cost = 0;
|
||||
SET parallel_tuple_cost = 0;
|
||||
SET min_parallel_table_scan_size = 0;
|
||||
SET max_parallel_workers_per_gather = 4;
|
||||
SET enable_indexonlyscan = off;
|
||||
|
||||
-- variance(int4) covers numeric_poly_combine
|
||||
-- sum(int8) covers int8_avg_combine
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT variance(unique1::int4), sum(unique1::int8) FROM tenk1;
|
||||
|
||||
SELECT variance(unique1::int4), sum(unique1::int8) FROM tenk1;
|
||||
|
||||
ROLLBACK;
|
||||
|
Loading…
x
Reference in New Issue
Block a user