Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with histogram function in parallel #1503

Merged
merged 1 commit into from Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/histogram.c
Expand Up @@ -119,16 +119,18 @@ ts_hist_combinefunc(PG_FUNCTION_ARGS)
elog(ERROR, "ts_hist_combinefunc called in non-aggregate context");
}

if (state2 == NULL)
if (state1 == NULL && state2 == NULL)
{
PG_RETURN_NULL();
}
else if (state2 == NULL)
{
result = copy_state(aggcontext, state1);
}

else if (state1 == NULL)
{
result = copy_state(aggcontext, state2);
}

else
{
Size i;
Expand Down
20 changes: 20 additions & 0 deletions test/expected/parallel-10.out
Expand Up @@ -205,6 +205,26 @@ SELECT histogram(i, 10, 100000, 5) FROM "test";
{1,2000,2000,2000,2000,1999,90000}
(1 row)

EXPLAIN (costs off) SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);
QUERY PLAN
------------------------------------------------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 2
-> Partial Aggregate
-> Append
-> Parallel Seq Scan on _hyper_1_1_chunk
Filter: ((i)::double precision = '-1'::double precision)
-> Parallel Seq Scan on _hyper_1_2_chunk
Filter: ((i)::double precision = '-1'::double precision)
(9 rows)

SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);
histogram
-----------

(1 row)

-- test parallel ChunkAppend
:PREFIX SELECT i FROM "test" WHERE length(version()) > 0;
QUERY PLAN
Expand Down
20 changes: 20 additions & 0 deletions test/expected/parallel-11.out
Expand Up @@ -203,6 +203,26 @@ SELECT histogram(i, 10, 100000, 5) FROM "test";
{1,2000,2000,2000,2000,1999,90000}
(1 row)

EXPLAIN (costs off) SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);
QUERY PLAN
------------------------------------------------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 2
-> Partial Aggregate
-> Parallel Append
-> Parallel Seq Scan on _hyper_1_1_chunk
Filter: ((i)::double precision = '-1'::double precision)
-> Parallel Seq Scan on _hyper_1_2_chunk
Filter: ((i)::double precision = '-1'::double precision)
(9 rows)

SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);
histogram
-----------

(1 row)

-- test parallel ChunkAppend
:PREFIX SELECT i FROM "test" WHERE length(version()) > 0;
QUERY PLAN
Expand Down
20 changes: 20 additions & 0 deletions test/expected/parallel-9.6.out
Expand Up @@ -205,6 +205,26 @@ SELECT histogram(i, 10, 100000, 5) FROM "test";
{1,2000,2000,2000,2000,1999,90000}
(1 row)

EXPLAIN (costs off) SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);
QUERY PLAN
------------------------------------------------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 2
-> Partial Aggregate
-> Append
-> Parallel Seq Scan on _hyper_1_1_chunk
Filter: ((i)::double precision = '-1'::double precision)
-> Parallel Seq Scan on _hyper_1_2_chunk
Filter: ((i)::double precision = '-1'::double precision)
(9 rows)

SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);
histogram
-----------

(1 row)

-- test parallel ChunkAppend
:PREFIX SELECT i FROM "test" WHERE length(version()) > 0;
QUERY PLAN
Expand Down
3 changes: 3 additions & 0 deletions test/sql/parallel.sql.in
Expand Up @@ -70,6 +70,9 @@ SELECT histogram(i, 0, 100000, 5) FROM "test";
EXPLAIN (costs off) SELECT histogram(i, 10,100000,5) FROM "test";
SELECT histogram(i, 10, 100000, 5) FROM "test";

EXPLAIN (costs off) SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);
SELECT histogram(NULL, 10,100000,5) FROM "test" WHERE i = coalesce(-1,j);

-- test parallel ChunkAppend
:PREFIX SELECT i FROM "test" WHERE length(version()) > 0;

Expand Down