pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: felix@felixge.de
Subject: BUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays
Date: Mon, 08 Jun 2020 19:06:48 +0000
Message-ID: <16487-c253609c5d095ff1@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16487
Logged by:          Felix Geisendörfer
Email address:      felix@felixge.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



view thread (3+ messages)  latest in thread

Message-ID: <16487-c253609c5d095ff1@postgresql.org>
Permalink:  ../16487-c253609c5d095ff1@postgresql.org/
Also on:    postgresql.org/message-id/16487-c253609c5d095ff1@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, felix@felixge.de
  Subject: Re: BUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays
  In-Reply-To: <16487-c253609c5d095ff1@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox