BUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: felix(at)felixge(dot)de
Subject: BUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays
Date: 2020-06-08 19:06:48
Message-ID: 16487-c253609c5d095ff1@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16487
Logged by: Felix Geisendörfer
Email address: felix(at)felixge(dot)de
PostgreSQL version: 12.1
Operating system: Any
Description:

Hi all,

I believe I found a bug that causes EXPLAIN to produce JSON with
duplicate "Workers" arrays when the following conditions are met:

- The options ANALYZE, VERBOSE and FORMAT JSON are used together.
- There is a Sort node in the plan that is executed in parallel.

Below is an example that should reproduce the issue in all version of
PostgreSQL >= 10. I tested with 12.1 and 11.6.

-- Create a sample table and nudge the planner to use a parallel plan
CREATE TABLE foo AS
SELECT * FROM generate_series(1, 10000) val;
SET parallel_setup_cost = 0;
SET parallel_tuple_cost = 0;
SET min_parallel_table_scan_size=0;
-- Run the actual query that causes the invalid JSON output
EXPLAIN (ANALYZE, VERBOSE, FORMAT JSON)
SELECT * FROM foo ORDER BY val;

Below is the relevant subset of the JSON produced by the query above.
Note the duplicate "Workers" arrays:

{
"Node Type": "Sort",
"Workers": [
{
"Worker Number": 0,
"Sort Method": "quicksort",
"Sort Space Used": 25,
"Sort Space Type": "Memory"
},
{
"Worker Number": 1,
"Sort Method": "quicksort",
"Sort Space Used": 25,
"Sort Space Type": "Memory"
}
],
"Workers": [
{
"Worker Number": 0,
"Actual Startup Time": 0.230,
"Actual Total Time": 0.230,
"Actual Rows": 0,
"Actual Loops": 1
},
{
"Worker Number": 1,
"Actual Startup Time": 0.231,
"Actual Total Time": 0.231,
"Actual Rows": 0,
"Actual Loops": 1
}
]
}

According to RFC 8259, I think this is technically still valid JSON:

> When the names within an object are not unique, the behavior of
> software that receives such an object is unpredictable.

However, I'm still reporting this as a bug since I assume that the
FORMAT JSON option is intended to have good interoperability with other
software.

I've also had a look in the code, and believe the issue was introduced
into backend/commands/explain.c in bf11e7e.

If somebody is willing to guide me a little, I'd also be interested in
attempting to create a patch to fix this. I haven't contributed to
PostgreSQL before and this seems like a nice opportunity.

Cheers
Felix

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message legrand legrand 2020-06-08 21:28:45 pg_stat_statements: duplicated external query texts with MSY2
Previous Message PG Bug reporting form 2020-06-08 19:00:06 BUG #16486: Prompted password is ignored when password specified in connection string