PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16487
PG Version12.1
OSAny
Opened2020-06-08 19:06:48+00
Reported byFelix Geisendörfer
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16487
Logged by:          Felix Geisendörfer
Email address:      (redacted)
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

Messages

DateAuthorSubject
2020-06-08 19:06:48+00PG Bug reporting formBUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays
2020-06-08 21:41:00+00Tom LaneRe: BUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays
2020-06-09 06:21:29+00=?utf-8?Q?Felix_Geisend=C3=B6rfer?=Re: BUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays