Обсуждение: BUG #16487: EXPLAIN produces JSON with duplicate "Workers" arrays

Поиск
Список
Период
Сортировка

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

От
PG Bug reporting form
Дата:
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


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

От
Tom Lane
Дата:
PG Bug reporting form <noreply@postgresql.org> writes:
> I believe I found a bug that causes EXPLAIN to produce JSON with
> duplicate "Workers" arrays when the following conditions are met:

Yeah ... this is fixed for v13 but we felt that back-patching such a
change might cause more pain than benefit.  See

https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=100136849

            regards, tom lane



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

От
Felix Geisendörfer
Дата:
> On 8. Jun 2020, at 23:41, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> PG Bug reporting form <noreply@postgresql.org> writes:
>> I believe I found a bug that causes EXPLAIN to produce JSON with
>> duplicate "Workers" arrays when the following conditions are met:
>
> Yeah ... this is fixed for v13 but we felt that back-patching such a
> change might cause more pain than benefit.  See
>
> https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=100136849
>
>             regards, tom lane


Thanks, that's great : ).

I should have checked the latest code first before posting this.

Cheers
Felix