Skip site navigation (1) Skip section navigation (2)

Re: Invalid YAML output from EXPLAIN

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Invalid YAML output from EXPLAIN
Date: 2010-06-09 02:48:57
Message-ID: AANLkTilNAp1wWVfkh_UoaheXoC-jA4Mr6l5lQcoZnod9@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
On Tue, Jun 8, 2010 at 10:47 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Mon, Jun 7, 2010 at 4:14 AM, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>> Testing 9.0 beta, I found that EXPLAINing certain queries in YAML
>> format will produce invalid YAML, for example:
>>
>> explain (format yaml) select * from foo where str_val = 'a: b';
>>
>> The problem in this case is that a colon followed by whitespace is not
>> allowed in an unquoted plain YAML string because a parser would
>> interpret it as the start of a map.
>>
>> So the current code in escape_yaml() is inadequate for producing valid
>> YAML. I think it would have to also consider at least the following
>> characters as special "-"  ":"  "["  "]"  "{"  "}"  ","  "\""  "'"
>> "|"  "*"  "&". Technically, it would also need to trap empty strings,
>> and strings with leading or trailing whitespace.
>>
>> Making escape_yaml() completely bulletproof with this approach would
>> be quite difficult, and (IMO) not worth the effort, especially given
>> that an important requirement is that the output be machine readable,
>> and in my experience YAML parsers are often far from perfect.
>>
>> I would therefore argue for simply calling escape_json() to produce
>> double quoted output for all string values, and only have numeric
>> values unquoted. This is not really any less human readable, and is
>> far more machine readable.
>>
>> Patch attached.
>
> I've committed a patch which I think will address this issue without
> uglifying the output quite so much.  Also, I didn't like the idea of
> not applying escaping to both the keys and values, even though we
> think we'll never have a key that requires escaping.  With this
> approach, that change isn't needed.

Er, I should also say, thanks for the report, and please test.  I am
definitely not an expert on YAML.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

In response to

Responses

pgsql-hackers by date

Next:From: Robert HaasDate: 2010-06-09 02:58:32
Subject: Re: Command to prune archive at restartpoints
Previous:From: Robert HaasDate: 2010-06-09 02:47:58
Subject: Re: Invalid YAML output from EXPLAIN

pgsql-bugs by date

Next:From: Robert HaasDate: 2010-06-09 03:04:12
Subject: Re: BUG #5492: Query performs slowly and sequence corrupted
Previous:From: Robert HaasDate: 2010-06-09 02:47:58
Subject: Re: Invalid YAML output from EXPLAIN

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group