Thread: Invalid explain output for multi-plan statements
-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 The new explain formats break if you have a multi-query statement. I don't have time to fix at the moment, but I'll try and explain the problem. For YAML, the forced leading space in all output means that the first "- Plan:" has two spaces, and all other ones have a single space. This leads to an inconsistent indentation error when parsing. For JSON, I'm not sure where the exact problem lies, but it also will not parse as it produces something like this: [ { ...plan 1 },, { ...plan2 } ] The XML output looks valid, but I've not tried to parse it. To duplicate: CREATE TABLE abc(a int); INSERT INTO abc VALUES (1); CREATE TABLE def(a int); CREATE RULE foo AS ON UPDATE TO abc DO ALSO SELECT 1 FROM def; EXPLAIN (format YAML) UPDATE abc SET a=a; EXPLAIN (format JSON) UPDATE abc SET a=a; EXPLAIN (format XML) UPDATE abc SET a=a; - -- Greg Sabino Mullane greg@turnstep.com End Point Corporation PGP Key: 0x14964AC8 200912141230 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -----BEGIN PGP SIGNATURE----- iEYEAREDAAYFAksmdisACgkQvJuQZxSWSsjaZACfeErCQbAU3a4DK3WqNBCaQMPI oe8AoKDsP+bIvsV2e2qD/Jx1NhrQw4ui =5lky -----END PGP SIGNATURE-----
On Mon, Dec 14, 2009 at 12:32 PM, Greg Sabino Mullane <greg@turnstep.com> w= rote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: RIPEMD160 > > > The new explain formats break if you have a multi-query statement. > I don't have time to fix at the moment, but I'll try and explain > the problem. For YAML, the forced leading space in all output > means that the first "- Plan:" has two spaces, and all other ones > have a single space. This leads to an inconsistent indentation > error when parsing. For JSON, I'm not sure where the exact problem > lies, but it also will not parse as it produces something like this: > > [ > =A0{ > =A0 ...plan 1 > =A0},, > =A0{ > =A0 ...plan2 > =A0} > ] > > The XML output looks valid, but I've not tried to parse it. > > To duplicate: > > CREATE TABLE abc(a int); > INSERT INTO abc VALUES (1); > CREATE TABLE def(a int); > CREATE RULE foo AS ON UPDATE TO abc DO ALSO SELECT 1 FROM def; > > EXPLAIN (format YAML) UPDATE abc SET a=3Da; > EXPLAIN (format JSON) UPDATE abc SET a=3Da; > EXPLAIN (format XML) UPDATE abc SET a=3Da; I will fix this, unless someone else beats me to it. ...Robert
On Mon, Dec 14, 2009 at 12:59 PM, Robert Haas <robertmhaas@gmail.com> wrote: >> The new explain formats break if you have a multi-query statement. > I will fix this, unless someone else beats me to it. Proposed patch attached. The problem with JSON output is pretty simple - ExplainSeparatePlans() still thinks it's responsible for comma-separating JSON plans, but in fact the new grouping_stack machinery is smart enough to handle that on its own, so they each add a comma. The YAML format also inserts a needless separator, but the real problem is that ExplainBeginGroup() and ExplainYAMLLineStarting() have an odd division of labor for marking each list element with "- ", with each providing one character. That fails to work as expected. I also noticed that ExplainDummyGroup() is hosed for the YAML format, so I fixed that as well. Along the way, I also made the YAML format use escape_yaml() in situations where the JSON format uses escape_json(). Right now it doesn't matter because all the values are known to not need escaping, but it seems safer this way. And, it took me a bit of time to understand the YAML format as it was not really commented, so I added some comments here as well. ...Robert
Attachment
On Mon, Dec 14, 2009 at 10:06 PM, Robert Haas <robertmhaas@gmail.com> wrote: > On Mon, Dec 14, 2009 at 12:59 PM, Robert Haas <robertmhaas@gmail.com> wrote: >>> The new explain formats break if you have a multi-query statement. >> I will fix this, unless someone else beats me to it. > > Proposed patch attached. [...discussion...] Hearing no objections, I have committed this, or more accurately the reverse of this, since it seems that I did the diff backwards when I posted it. ...Robert