Re: Sequential Scans On Complex Query With UNION - see why this fails - Mailing list pgsql-novice

From Tom Lane
Subject Re: Sequential Scans On Complex Query With UNION - see why this fails
Date
Msg-id 1060.1137040938@sss.pgh.pa.us
Whole thread Raw
In response to Re: Sequential Scans On Complex Query With UNION - see why this fails  (Michael Glaesemann <grzm@myrealbox.com>)
List pgsql-novice
Michael Glaesemann <grzm@myrealbox.com> writes:
> On Jan 12, 2006, at 12:21 , Tom Lane wrote:
>> I think what's happening is that the parser implicitly parenthesizes
>> like this:
>>
>> from ((a join b on a.x=b.y) join c on b.y=c.z)

> Any idea off hand if the SQL spec has anything to say on the subject?

SQL92 has this BNF:

         <from clause> ::= FROM <table reference> [ { <comma> <table reference> }... ]

         <table reference> ::=
                <table name> [ [ AS ] <correlation name>
                    [ <left paren> <derived column list> <right paren> ] ]
              | <derived table> [ AS ] <correlation name>
                    [ <left paren> <derived column list> <right paren> ]
              | <joined table>

         <derived table> ::= <table subquery>

         <derived column list> ::= <column name list>

         <joined table> ::=
                <cross join>
              | <qualified join>
              | <left paren> <joined table> <right paren>

         <cross join> ::=
              <table reference> CROSS JOIN <table reference>

         <qualified join> ::=
              <table reference> [ NATURAL ] [ <join type> ] JOIN
                <table reference> [ <join specification> ]

         <join specification> ::=
                <join condition>
              | <named columns join>

         <join condition> ::= ON <search condition>

         <named columns join> ::=
              USING <left paren> <join column list> <right paren>

         <join type> ::=
                INNER
              | <outer join type> [ OUTER ]
              | UNION

         <outer join type> ::=
                LEFT
              | RIGHT
              | FULL

What we're talking about is the <qualified join> production, whose
inputs are <table reference>s, and a <table reference> can be another
<qualified join> with or without surrounding parentheses.  So AFAICS
SQL92 specifically allows both of these constructions.

            regards, tom lane

pgsql-novice by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Sequential Scans On Complex Query With UNION - see why this fails
Next
From: Michael Fuhr
Date:
Subject: Re: Removing duplicate entries