Common Table Expressions (WITH RECURSIVE) patch
These are my initial comments about the Common Table Expressions (CTE)
patch, also known as WITH [RECURSIVE]. These comments are based on the
patch here:
http://archives.postgresql.org/pgsql-patches/2008-08/msg00021.php
This is a semantically complex feature, and the standard is fairly
complex as well. So I'm approaching this by making my own
interpretations from the standard first (I included my interpretations
and section references at the end of this email) and comparing to the
behavior of the patch.
The following examples may be inconsistent with the standard. Some
have already been mentioned, and I don't think they all need to be
fixed for 8.4, but I mention them here for completeness.
* Mutual Recursion:
with recursive
foo(i) as (values(1) union all select i+1 from bar where i < 10),
bar(i) as (values(1) union all select i+1 from foo where i < 10)
select * from foo;
ERROR: mutual recursive call is not supported
The standard allows mutual recursion.
* Single Evaluation:
with
foo(i) as (select random() as i)
select * from foo union all select * from foo;
i
-------------------
0.233165248762816
0.62126633618027
(2 rows)
The standard specifies that non-recursive WITH should be evaluated
once.
* RHS only:
with recursive
foo(i) as (select i+1 from foo where i < 10 union all values(1))
select * from foo;
ERROR: Left hand side of UNION ALL must be a non-recursive term in a
recursive query
The standard does not require that the recursive term be on the RHS.
* UNION ALL only:
with recursive
foo(i) as (values(1) union select i+1 from foo where i < 10)
select * from foo;
ERROR: non-recursive term and recursive term must be combined with
UNION ALL
The standard seems to allow UNION ALL, UNION, INTERSECT, and EXCEPT
(when the recursive term is not on the RHS of the EXCEPT).
* Binary recursion and subselect strangeness:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
union all
select i+1 from foo where i < X) t)
select * from foo;
Produces 10 rows of output regardless of what "X" is. This should be
fixed for 8.4.
Also, this is non-linear recursion, which the standard seems to
disallow.
* Multiple recursive references:
with recursive foo(i) as
(values (1)
union all
select i+1 from foo where i < 10
union all
select i+1 from foo where i < 20)
select * from foo;
ERROR: Left hand side of UNION ALL must be a non-recursive term in a
recursive query
If we're going to allow non-linear recursion (which the standard
does not), this seems like it should be a valid case.
* Strange result with except:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
except
select i+1 from foo where i < 5) t)
select * from foo;
ERROR: table "foo" has 0 columns available but 1 columns specified
This query works if you replace "except" with "union". This should be
fixed for 8.4.
* Aggregates allowed:
with recursive foo(i) as
(values(1)
union all
select max(i)+1 from foo where i < 10)
select * from foo;
Aggregates should be blocked according to the standard.
Also, causes an infinite loop. This should be fixed for 8.4.
* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;
This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.
* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;
Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.
* ORDER BY, LIMIT, and OFFSET are rejected for recursive queries. The
standard does not seem to say that these should be rejected.
The following are my interpretations of relevant parts of the SQL
standard (200n), and the associated sections. These are only my
interpretation, so let me know if you interpret the standard
differently.
Non-linear recursion forbidden:
7.13: Syntax Rules: 2.g.ii
My interpretation of 2.g.ii.2 is that WQN[k] and WQN[l] may be the
same <query name>.
7.13: Syntax Rules: 2.g.iv
EXCEPT can't be used for recursive queries if a recursive reference
appears on the RHS:
7.13: Syntax Rules: 2.g.iii.1
INTERSECT ALL/EXCEPT ALL can't be used for recursive queries:
7.13: Syntax Rules: 2.g.iii.5
recursive references must appear in FROM clause:
7.13: Syntax Rules: 2.g.iii.3
My interpretation of this rule is that it does not allow a
recursive reference in a subquery in the targetlist or a subquery
in the where clause.
stratum defined:
7.13: Syntax Rules: 2.f
7.13: Syntax Rules: 2.g.i.1
recursive query must have anchor for every stratum:
7.13: Syntax Rules: 2.g.i.3
outer joins not allowed to join recursive references:
7.13: Syntax Rules: 2.g.iii.6
7.13: Syntax Rules: 2.g.iii.7
Aggregates/HAVING disallowed:
7.13: Syntax Rules: 2.g.iii.4.B
Mutual recursion defined:
7.13: Syntax Rules: 2.g.i.1
Evaluate each WITH entry once, even if it's referenced multiple times:
7.13: General Rules: 1
7.13: General Rules: 2.b
See also:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
Evaluation order with mutual recursion:
7.13: General Rules: 2.a
7.13: General Rules: 2.b
Evaluation semantics:
7.13: General Rules: 2.c
DISTINCT:
7.13: General Rules: 2.c.iv
7.13: General Rules: 2.c.ix.3.A
I will provide comments about the code and documentation soon. This is a
very useful feature.
Regards,
Jeff Davis
"Jeff" == Jeff Davis <pgsql@j-davis.com> writes:
Jeff> * Mutual Recursion:
This limitation isn't at all uncommon in other implementations; DB2
docs for example say:
"If more than one common table expression is defined in the same
statement, cyclic references between the common table expressions are
not permitted. A cyclic reference occurs when two common table
expressions dt1 and dt2 are created such that dt1 refers to dt2 and
dt2 refers to dt1."
MSSQL's documentation is less clear, but it also appears not to allow
mutual recursion (not allowing forward references to CTEs).
"A CTE can reference itself and previously defined CTEs in the same
WITH clause. Forward referencing is not allowed."
http://msdn.microsoft.com/en-us/library/ms175972.aspx
Jeff> * RHS only:
Jeff> with recursive
Jeff> foo(i) as (select i+1 from foo where i < 10 union all values(1))
Jeff> select * from foo;
Jeff> ERROR: Left hand side of UNION ALL must be a non-recursive term in a
Jeff> recursive query
Jeff> The standard does not require that the recursive term be on
Jeff> the RHS.
Again, the standard may not, but existing implementations do:
MSSQL:
"The recursive CTE definition must contain at least two CTE query
definitions, an anchor member and a recursive member. Multiple anchor
members and recursive members can be defined; however, all anchor
member query definitions must be put before the first recursive member
definition. All CTE query definitions are anchor members unless they
reference the CTE itself. "
DB2:
"The following restrictions apply to a recursive common-table-expression:
* A list of column-names must be specified following the
table-identifier.
* The UNION ALL set operator must be specified.
* The first fullselect of the first union (the initialization
fullselect) must not include a reference to the
common-table-expression itself in any FROM clause.
"
Jeff> * UNION ALL only:
Jeff> with recursive
Jeff> foo(i) as (values(1) union select i+1 from foo where i < 10)
Jeff> select * from foo;
Jeff> ERROR: non-recursive term and recursive term must be combined with
Jeff> UNION ALL
Jeff> The standard seems to allow UNION ALL, UNION, INTERSECT, and
Jeff> EXCEPT (when the recursive term is not on the RHS of the
Jeff> EXCEPT).
Again, existing implementations disagree. See above for DB2, and for
MSSQL:
"Anchor members must be combined by one of these set operators: UNION
ALL, UNION, INTERSECT, or EXCEPT. UNION ALL is the only set operator
allowed between the last anchor member and first recursive member, and
when combining multiple recursive members."
Jeff> * Binary recursion and subselect strangeness:
Jeff> with recursive foo(i) as
Jeff> (values (1)
Jeff> union all
Jeff> select * from
Jeff> (select i+1 from foo where i < 10
Jeff> union all
Jeff> select i+1 from foo where i < X) t)
Jeff> select * from foo;
Jeff> Produces 10 rows of output regardless of what "X" is. This
Jeff> should be fixed for 8.4. Also, this is non-linear recursion,
Jeff> which the standard seems to disallow.
That looks like it should be disallowed somehow.
Jeff> * Multiple recursive references:
[snip]
Jeff> If we're going to allow non-linear recursion (which the
Jeff> standard does not), this seems like it should be a valid
Jeff> case.
We probably shouldn't allow it (as above).
[snip * Strange result with except: which looks like a bug]
Jeff> * Aggregates allowed: which
Jeff> with recursive foo(i) as
Jeff> (values(1)
Jeff> union all
Jeff> select max(i)+1 from foo where i < 10)
Jeff> select * from foo;
Jeff> Aggregates should be blocked according to the standard.
Jeff> Also, causes an infinite loop. This should be fixed for 8.4.
Does the standard require anywhere that non-conforming statements must
be diagnosed? (seems impractical, since it would forbid extensions)
Jeff> * DISTINCT should supress duplicates:
Jeff> with recursive foo(i) as
Jeff> (select distinct * from (values(1),(2)) t
Jeff> union all
Jeff> select distinct i+1 from foo where i < 10)
Jeff> select * from foo;
Jeff> This outputs a lot of duplicates, but they should be
Jeff> supressed according to the standard. This query is essentially
Jeff> the same as supporting UNION for recursive queries, so we
Jeff> should either fix both for 8.4 or block both for consistency.
Yeah, though the standard's use of DISTINCT in this way is something
of a violation of the POLA.
Jeff> * outer joins on a recursive reference should be blocked:
Jeff> with recursive foo(i) as
Jeff> (values(1)
Jeff> union all
Jeff> select i+1 from foo left join (values(1)) t on (i=column1))
Jeff> select * from foo;
Jeff> Causes an infinite loop, but the standard says using an outer
Jeff> join in this situation should be prohibited. This should be
Jeff> fixed for 8.4.
No. This has already been discussed; it's neither possible nor desirable
to diagnose all cases which can result in infinite loops, and there are
important types of queries which would be unnecessarily forbidden.
Besides, you've misread the spec here: it prohibits the recursive
reference ONLY on the nullable side of the join. You cite:
Jeff> outer joins not allowed to join recursive references:
Jeff> 7.13: Syntax Rules: 2.g.iii.6
Jeff> 7.13: Syntax Rules: 2.g.iii.7
6) WQEi shall not contain a <qualified join> QJ in which:
A) QJ immediately contains a <join type> that specifies FULL and a
<table reference> or <table factor> that contains a <query name>
referencing WQNj.
[no recursive FULL JOIN at all]
B) QJ immediately contains a <join type> that specifies LEFT and a
<table factor> following the <join type> that contains a <query
name> referencing WQNj.
[note "following the <join type>", so WQNj LEFT JOIN foo is allowed,
but foo LEFT JOIN WQNj is not]
C) QJ immediately contains a <join type> that specifies RIGHT and a
<table reference> preceding the <join type> that contains a
<query name> referencing WQNj.
[note "preceding the <join type>", so foo RIGHT JOIN WQNj is allowed,
but WQNj RIGHT JOIN foo is not]
para (7) is identical but for natural rather than qualified joins.
Jeff> * ORDER BY, LIMIT, and OFFSET are rejected for recursive
Jeff> queries. The standard does not seem to say that these should be
Jeff> rejected.
Note that supporting those in subqueries (including CTEs) is a separate
optional feature of the standard.
--
Andrew (irc:RhodiumToad)
On Mon, 2008-09-08 at 18:08 +0100, Andrew Gierth wrote:
Jeff> * Mutual Recursion:
This limitation isn't at all uncommon in other implementations; DB2
docs for example say:
As with some other things in my list, this doesn't need to be supported
in 8.4. I just wanted to lay out my interpretation of the standard, and
places that we might (currently) fall short of it.
The fact that other DBMSs don't support mutual recursion is a good
indication that it's not important immediately.
Jeff> The standard does not require that the recursive term be on
Jeff> the RHS.Again, the standard may not, but existing implementations do:
Again, I don't think we need this for 8.4.
However, I think it's probably more important than mutual recursion.
Jeff> * UNION ALL only:
Jeff> with recursive
Jeff> foo(i) as (values(1) union select i+1 from foo where i < 10)
Jeff> select * from foo;
Jeff> ERROR: non-recursive term and recursive term must be combined with
Jeff> UNION ALLJeff> The standard seems to allow UNION ALL, UNION, INTERSECT, and
Jeff> EXCEPT (when the recursive term is not on the RHS of the
Jeff> EXCEPT).Again, existing implementations disagree. See above for DB2, and for
MSSQL:
And again, I agree that it's not important for 8.4.
At some point we need to determine what the goalposts are though. Are we
copying existing implementations, or are we implementing the standard?
Jeff> Produces 10 rows of output regardless of what "X" is. This
Jeff> should be fixed for 8.4. Also, this is non-linear recursion,
Jeff> which the standard seems to disallow.That looks like it should be disallowed somehow.
Agreed. I think it should just throw an error, probably.
[snip * Strange result with except: which looks like a bug]
Jeff> * Aggregates allowed: which
Jeff> with recursive foo(i) as
Jeff> (values(1)
Jeff> union all
Jeff> select max(i)+1 from foo where i < 10)
Jeff> select * from foo;Jeff> Aggregates should be blocked according to the standard.
Jeff> Also, causes an infinite loop. This should be fixed for 8.4.Does the standard require anywhere that non-conforming statements must
be diagnosed? (seems impractical, since it would forbid extensions)
2.g.iii.4.B explicitly says aggregates should be rejected, unless I have
misinterpreted.
Yeah, though the standard's use of DISTINCT in this way is something
of a violation of the POLA.
I agree that's kind of a funny requirement. But that's pretty typical of
the SQL standard. If DB2 or SQL Server follow the standard here, we
should, too. If not, it's open for discussion.
No. This has already been discussed; it's neither possible nor desirable
to diagnose all cases which can result in infinite loops, and there are
important types of queries which would be unnecessarily forbidden.
I didn't say we should forbid all infinite loops. But we should forbid
ones that the standard tells us to forbid.
Besides, you've misread the spec here: it prohibits the recursive
reference ONLY on the nullable side of the join. You cite:
Thank you for the correction. It does properly reject the outer joins
that the standard says should be rejected.
Jeff> * ORDER BY, LIMIT, and OFFSET are rejected for recursive
Jeff> queries. The standard does not seem to say that these should be
Jeff> rejected.Note that supporting those in subqueries (including CTEs) is a separate
optional feature of the standard.
I don't feel strongly about this either way, but I prefer that we are
consistent when possible. We do support these things in a subquery, so
shouldn't we support them in all subqueries?
Regards,
Jeff Davis
Jeff Davis <pgsql@j-davis.com> writes:
* Mutual Recursion:
with recursive
foo(i) as (values(1) union all select i+1 from bar where i < 10),
bar(i) as (values(1) union all select i+1 from foo where i < 10)
select * from foo;
ERROR: mutual recursive call is not supportedThe standard allows mutual recursion.
This seems to be a point of confusion. I originally read the standard and
concluded that mutual recursion was an optional feature. Itagaki-san showed me
a copy of the spec where it seemed there was a clear blanket prohibition on
mutually recursive queries and in fact anything but simple linearly expandable
queries. I wonder if there are different versions of the spec floating around
on this point.
Take a second look at your spec and read on to where it defines "linear" and
"expandable". If it doesn't define those terms then it's definitely different
from what I read. If it does, read on to see what it does with them. The main
reason to define them appeared to be to use them to say that supporting mutual
recursion is not required.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's PostGIS support!
On Mon, 2008-09-08 at 21:13 +0100, Gregory Stark wrote:
Jeff Davis <pgsql@j-davis.com> writes:
* Mutual Recursion:
with recursive
foo(i) as (values(1) union all select i+1 from bar where i < 10),
bar(i) as (values(1) union all select i+1 from foo where i < 10)
select * from foo;
ERROR: mutual recursive call is not supportedThe standard allows mutual recursion.
This seems to be a point of confusion. I originally read the standard and
concluded that mutual recursion was an optional feature. Itagaki-san showed me
a copy of the spec where it seemed there was a clear blanket prohibition on
mutually recursive queries and in fact anything but simple linearly expandable
queries. I wonder if there are different versions of the spec floating around
on this point.Take a second look at your spec and read on to where it defines "linear" and
"expandable". If it doesn't define those terms then it's definitely different
from what I read. If it does, read on to see what it does with them. The main
reason to define them appeared to be to use them to say that supporting mutual
recursion is not required.
I think we're reading the same version of the spec. I'm reading 200n.
My interpretation (Syntax Rule 2.h) is that expandable is only used to
determine whether it can contain a <search or cycle>.
That being said, I don't think it should be a requirement for 8.4. The
CTE patch is an important feature, and we shouldn't hold it up over
something comparatively obscure like mutual recursion. As Andrew Gierth
cited, other systems don't support it anyway. It should be kept in mind
for future work though.
Regards,
Jeff Davis
"Jeff" == Jeff Davis <jdavis@truviso.com> writes:
Jeff> Aggregates should be blocked according to the standard.
Jeff> Also, causes an infinite loop. This should be fixed for 8.4.
Does the standard require anywhere that non-conforming statements
must be diagnosed? (seems impractical, since it would forbid
extensions)
Jeff> 2.g.iii.4.B explicitly says aggregates should be rejected,
Jeff> unless I have misinterpreted.
Yes, you've misinterpreted. When the spec says that a query "shall
not" do such-and-such, it means that a conforming client isn't allowed
to do that, it does NOT mean that the server is required to produce an
error when it sees it.
Chapter and verse on this is given in the Framework doc, at 6.3.3.2:
In the Syntax Rules, the term "shall" defines conditions that are
required to be true of syntactically conforming SQL language. When such
conditions depend on the contents of one or more schemas, they are
required to be true just before the actions specified by the General
Rules are performed. The treatment of language that does not conform to
the SQL Formats and Syntax Rules is implementation-dependent. If any
condition required by Syntax Rules is not satisfied when the evaluation
of Access or General Rules is attempted and the implementation is
neither processing non-conforming SQL language nor processing
conforming SQL language in a non-conforming manner, then an exception
condition is raised: "syntax error or access rule violation".
Including an aggregate violates a "shall" in a syntax rule, therefore the
query is non-conforming, therefore the server can either process it in an
implementation-dependent manner or reject it with an exception.
Yeah, though the standard's use of DISTINCT in this way is something
of a violation of the POLA.
Jeff> I agree that's kind of a funny requirement. But that's pretty
Jeff> typical of the SQL standard. If DB2 or SQL Server follow the
Jeff> standard here, we should, too. If not, it's open for discussion.
MSSQL does not:
"The following items are not allowed in the CTE_query_definition of a
recursive member:
* SELECT DISTINCT
* GROUP BY
* HAVING
* Scalar aggregation
* TOP
* LEFT, RIGHT, OUTER JOIN (INNER JOIN is allowed)
* Subqueries
* A hint applied to a recursive reference to a CTE inside a
CTE_query_definition.
"
For DB2 the docs do not appear to specify either way; they don't seem to
forbid the use of SELECT DISTINCT inside a recursive CTE, but neither do
they seem to mention any unusual effect of including it.
Jeff> * ORDER BY, LIMIT, and OFFSET are rejected for recursive
Jeff> queries. The standard does not seem to say that these should be
Jeff> rejected.
Note that supporting those in subqueries (including CTEs) is a
separate optional feature of the standard.
Jeff> I don't feel strongly about this either way, but I prefer that we
Jeff> are consistent when possible. We do support these things in a
Jeff> subquery, so shouldn't we support them in all subqueries?
Ideally we should. DB2 appears to (other than OFFSET which it doesn't
seem to have at all). But it's not at all clear that it would be either
useful or easy to do so.
--
Andrew.
On Mon, 2008-09-08 at 22:53 +0100, Andrew Gierth wrote:
Yes, you've misinterpreted. When the spec says that a query "shall
not" do such-and-such, it means that a conforming client isn't allowed
to do that, it does NOT mean that the server is required to produce an
error when it sees it.
Interesting. Thanks for the clear reference.
So, we either need to reject it or define some implementation-dependent
behavior, right?
The patch currently rejects HAVING, which means that it's a little
difficult to use an aggregate effectively. I lean toward rejecting
aggregates if we reject HAVING, for consistency. If we allow it, we
should allow HAVING as well.
Jeff> I agree that's kind of a funny requirement. But that's pretty
Jeff> typical of the SQL standard. If DB2 or SQL Server follow the
Jeff> standard here, we should, too. If not, it's open for discussion.MSSQL does not:
Thanks again for a reference.
If MSSQL rejects SELECT DISTINCT for a recursive <query expression>,
then I think we should reject it. Right now the patch allows it but
provides a result that is inconsistent with the standard.
If we reject SELECT DISTINCT for recursive queries now, we can always
meet the standard later, or decide that the standard behavior is too
likely to cause confusion and just continue to block it.
Ideally we should. DB2 appears to (other than OFFSET which it doesn't
seem to have at all). But it's not at all clear that it would be either
useful or easy to do so.
Ok. If it's easy to support it should probably be done.
As an aside, you seem to be an expert with the standard, have you had a
chance to look at the question I asked earlier?:
http://archives.postgresql.org/pgsql-hackers/2008-09/msg00487.php
Regards,
Jeff Davis
Thanks for the review.
[I dropped y-asaba@sraoss.co.jp from the Cc list since he has left our
company and the email address is being deleted.]
I'm going to look into issues which are seem to be bug (of course if
you know what to fix, patches are always welcome:-).
These are my initial comments about the Common Table Expressions (CTE)
patch, also known as WITH [RECURSIVE]. These comments are based on the
patch here:http://archives.postgresql.org/pgsql-patches/2008-08/msg00021.php
This is a semantically complex feature, and the standard is fairly
complex as well. So I'm approaching this by making my own
interpretations from the standard first (I included my interpretations
and section references at the end of this email) and comparing to the
behavior of the patch.The following examples may be inconsistent with the standard. Some
have already been mentioned, and I don't think they all need to be
fixed for 8.4, but I mention them here for completeness.* Mutual Recursion:
with recursive
foo(i) as (values(1) union all select i+1 from bar where i < 10),
bar(i) as (values(1) union all select i+1 from foo where i < 10)
select * from foo;
ERROR: mutual recursive call is not supportedThe standard allows mutual recursion.
The discussion seems to agree that let it leave for post 8.4.
* Single Evaluation:
with
foo(i) as (select random() as i)
select * from foo union all select * from foo;
i
-------------------
0.233165248762816
0.62126633618027
(2 rows)The standard specifies that non-recursive WITH should be evaluated
once.
What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?
* RHS only:
with recursive
foo(i) as (select i+1 from foo where i < 10 union all values(1))
select * from foo;
ERROR: Left hand side of UNION ALL must be a non-recursive term in a
recursive queryThe standard does not require that the recursive term be on the RHS.
The discussion seems to agree that let it leave for post 8.4.
* UNION ALL only:
with recursive
foo(i) as (values(1) union select i+1 from foo where i < 10)
select * from foo;
ERROR: non-recursive term and recursive term must be combined with
UNION ALLThe standard seems to allow UNION ALL, UNION, INTERSECT, and EXCEPT
(when the recursive term is not on the RHS of the EXCEPT).
The discussion seems to agree that let it leave for post 8.4.
* Binary recursion and subselect strangeness:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
union all
select i+1 from foo where i < X) t)
select * from foo;Produces 10 rows of output regardless of what "X" is. This should be
fixed for 8.4.
Also, this is non-linear recursion, which the standard seems to
disallow.
I will try to fix this. However detecting the query being not a
non-linear one is not so easy.
* Multiple recursive references:
with recursive foo(i) as
(values (1)
union all
select i+1 from foo where i < 10
union all
select i+1 from foo where i < 20)
select * from foo;
ERROR: Left hand side of UNION ALL must be a non-recursive term in a
recursive queryIf we're going to allow non-linear recursion (which the standard
does not), this seems like it should be a valid case.
I will try to disallow this.
* Strange result with except:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
except
select i+1 from foo where i < 5) t)
select * from foo;
ERROR: table "foo" has 0 columns available but 1 columns specifiedThis query works if you replace "except" with "union". This should be
fixed for 8.4.
I will try to fix this.
* Aggregates allowed:
with recursive foo(i) as
(values(1)
union all
select max(i)+1 from foo where i < 10)
select * from foo;Aggregates should be blocked according to the standard.
Also, causes an infinite loop. This should be fixed for 8.4.
I will try to fix this.
* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.
I'm not sure if it's possible to fix this. Will look into.
* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.
Not an issue, I think.
* ORDER BY, LIMIT, and OFFSET are rejected for recursive queries. The
standard does not seem to say that these should be rejected.The following are my interpretations of relevant parts of the SQL
standard (200n), and the associated sections. These are only my
interpretation, so let me know if you interpret the standard
differently.Non-linear recursion forbidden:
7.13: Syntax Rules: 2.g.ii
My interpretation of 2.g.ii.2 is that WQN[k] and WQN[l] may be the
same <query name>.
7.13: Syntax Rules: 2.g.ivEXCEPT can't be used for recursive queries if a recursive reference
appears on the RHS:
7.13: Syntax Rules: 2.g.iii.1INTERSECT ALL/EXCEPT ALL can't be used for recursive queries:
7.13: Syntax Rules: 2.g.iii.5recursive references must appear in FROM clause:
7.13: Syntax Rules: 2.g.iii.3
My interpretation of this rule is that it does not allow a
recursive reference in a subquery in the targetlist or a subquery
in the where clause.stratum defined:
7.13: Syntax Rules: 2.f
7.13: Syntax Rules: 2.g.i.1recursive query must have anchor for every stratum:
7.13: Syntax Rules: 2.g.i.3outer joins not allowed to join recursive references:
7.13: Syntax Rules: 2.g.iii.6
7.13: Syntax Rules: 2.g.iii.7Aggregates/HAVING disallowed:
7.13: Syntax Rules: 2.g.iii.4.BMutual recursion defined:
7.13: Syntax Rules: 2.g.i.1Evaluate each WITH entry once, even if it's referenced multiple times:
7.13: General Rules: 1
7.13: General Rules: 2.b
See also:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.phpEvaluation order with mutual recursion:
7.13: General Rules: 2.a
7.13: General Rules: 2.bEvaluation semantics:
7.13: General Rules: 2.cDISTINCT:
7.13: General Rules: 2.c.iv
7.13: General Rules: 2.c.ix.3.AI will provide comments about the code and documentation soon. This is a
very useful feature.
Thanks. Enclosed is the latest patch to adopt CVS HEAD.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Attachments:
Thanks for the review.
[I dropped y-asaba@sraoss.co.jp from the Cc list since he has left our
company and the email address is being deleted.]
I'm going to look into issues which are seem to be bug (of course if
you know what to fix, patches are always welcome:-).
These are my initial comments about the Common Table Expressions (CTE)
patch, also known as WITH [RECURSIVE]. These comments are based on the
patch here:http://archives.postgresql.org/pgsql-patches/2008-08/msg00021.php
This is a semantically complex feature, and the standard is fairly
complex as well. So I'm approaching this by making my own
interpretations from the standard first (I included my interpretations
and section references at the end of this email) and comparing to the
behavior of the patch.The following examples may be inconsistent with the standard. Some
have already been mentioned, and I don't think they all need to be
fixed for 8.4, but I mention them here for completeness.* Mutual Recursion:
with recursive
foo(i) as (values(1) union all select i+1 from bar where i < 10),
bar(i) as (values(1) union all select i+1 from foo where i < 10)
select * from foo;
ERROR: mutual recursive call is not supportedThe standard allows mutual recursion.
The discussion seems to agree that let it leave for post 8.4.
* Single Evaluation:
with
foo(i) as (select random() as i)
select * from foo union all select * from foo;
i
-------------------
0.233165248762816
0.62126633618027
(2 rows)The standard specifies that non-recursive WITH should be evaluated
once.
What shall we do? I don't think there's an easy way to fix this as Tom
suggested. Maybe we should not allow WITH clause without RECURISVE for
8.4?
* RHS only:
with recursive
foo(i) as (select i+1 from foo where i < 10 union all values(1))
select * from foo;
ERROR: Left hand side of UNION ALL must be a non-recursive term in a
recursive queryThe standard does not require that the recursive term be on the RHS.
The discussion seems to agree that let it leave for post 8.4.
* UNION ALL only:
with recursive
foo(i) as (values(1) union select i+1 from foo where i < 10)
select * from foo;
ERROR: non-recursive term and recursive term must be combined with
UNION ALLThe standard seems to allow UNION ALL, UNION, INTERSECT, and EXCEPT
(when the recursive term is not on the RHS of the EXCEPT).
The discussion seems to agree that let it leave for post 8.4.
* Binary recursion and subselect strangeness:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
union all
select i+1 from foo where i < X) t)
select * from foo;Produces 10 rows of output regardless of what "X" is. This should be
fixed for 8.4.
Also, this is non-linear recursion, which the standard seems to
disallow.
I will try to fix this. However detecting the query being not a
non-linear one is not so easy.
* Multiple recursive references:
with recursive foo(i) as
(values (1)
union all
select i+1 from foo where i < 10
union all
select i+1 from foo where i < 20)
select * from foo;
ERROR: Left hand side of UNION ALL must be a non-recursive term in a
recursive queryIf we're going to allow non-linear recursion (which the standard
does not), this seems like it should be a valid case.
I will try to disallow this.
* Strange result with except:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
except
select i+1 from foo where i < 5) t)
select * from foo;
ERROR: table "foo" has 0 columns available but 1 columns specifiedThis query works if you replace "except" with "union". This should be
fixed for 8.4.
I will try to fix this.
* Aggregates allowed:
with recursive foo(i) as
(values(1)
union all
select max(i)+1 from foo where i < 10)
select * from foo;Aggregates should be blocked according to the standard.
Also, causes an infinite loop. This should be fixed for 8.4.
I will try to fix this.
* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.
I'm not sure if it's possible to fix this. Will look into.
* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.
Not an issue, I think.
* ORDER BY, LIMIT, and OFFSET are rejected for recursive queries. The
standard does not seem to say that these should be rejected.The following are my interpretations of relevant parts of the SQL
standard (200n), and the associated sections. These are only my
interpretation, so let me know if you interpret the standard
differently.Non-linear recursion forbidden:
7.13: Syntax Rules: 2.g.ii
My interpretation of 2.g.ii.2 is that WQN[k] and WQN[l] may be the
same <query name>.
7.13: Syntax Rules: 2.g.ivEXCEPT can't be used for recursive queries if a recursive reference
appears on the RHS:
7.13: Syntax Rules: 2.g.iii.1INTERSECT ALL/EXCEPT ALL can't be used for recursive queries:
7.13: Syntax Rules: 2.g.iii.5recursive references must appear in FROM clause:
7.13: Syntax Rules: 2.g.iii.3
My interpretation of this rule is that it does not allow a
recursive reference in a subquery in the targetlist or a subquery
in the where clause.stratum defined:
7.13: Syntax Rules: 2.f
7.13: Syntax Rules: 2.g.i.1recursive query must have anchor for every stratum:
7.13: Syntax Rules: 2.g.i.3outer joins not allowed to join recursive references:
7.13: Syntax Rules: 2.g.iii.6
7.13: Syntax Rules: 2.g.iii.7Aggregates/HAVING disallowed:
7.13: Syntax Rules: 2.g.iii.4.BMutual recursion defined:
7.13: Syntax Rules: 2.g.i.1Evaluate each WITH entry once, even if it's referenced multiple times:
7.13: General Rules: 1
7.13: General Rules: 2.b
See also:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.phpEvaluation order with mutual recursion:
7.13: General Rules: 2.a
7.13: General Rules: 2.bEvaluation semantics:
7.13: General Rules: 2.cDISTINCT:
7.13: General Rules: 2.c.iv
7.13: General Rules: 2.c.ix.3.AI will provide comments about the code and documentation soon. This is a
very useful feature.
Thanks. Enclosed is the latest patch to adopt CVS HEAD.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Attachments:
* Single Evaluation:
with
foo(i) as (select random() as i)
select * from foo union all select * from foo;
i
-------------------
0.233165248762816
0.62126633618027
(2 rows)The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?
ISTM that kind of misses the point. Even if it's WITH RECURSIVE
rather than simply WITH, one wouldn't expect multiple evaluations of
any non-recursive portion of the query.
...Robert
On Tue, 2008-09-09 at 13:45 +0900, Tatsuo Ishii wrote:
Thanks for the review.
The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?
My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.
The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
The important arguments in the thread seemed to be:
1. People will generally expect single evaluation, so might be
disappointed if they can't use this feature for that purpose.
2. It's a spec violation in the case of volatile functions.
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."
I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.
Tom Lane said that multiple evaluation is grounds for rejection:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01318.php
Is there hope of correcting this before November?
I will try to fix this. However detecting the query being not a
non-linear one is not so easy.
If we don't allow mutual recursion, the only kind of non-linear
recursion that might exist would be multiple references to the same
recursive query name in a recursive query, is that correct?
* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.I'm not sure if it's possible to fix this. Will look into.
Can't we just reject queries with top-level DISTINCT, similar to how
UNION is rejected?
* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.Not an issue, I think.
Agreed, Andrew Gierth corrected me here.
Regards,
Jeff Davis
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.
What makes you think it's going to be undocumented? Single versus
multiple evaluation is a keep aspect of this feature and certainly
needs to be documented one way or the other. I can't understand why
we would introduce a standard syntax with non-standard behavior, but
if we do, it certainly had better be mentioned in the documentation.
I think that the most likely result of a CTE implementation that
doesn't guarantee single evaluation is that people simply won't use
it. But anyone who does will expect that their queries will return
the same results in release N and release N+1, for all values of N.
The only way that an incompatible change of this type won't break
people's applications is if they're not using the feature in the first
place, in which case there is no point in committing it anyway.
I wonder if the whole approach to this patch is backward. Instead of
worrying about how to implement WITH RECURSIVE, maybe it would be
better to implement a really solid, spec-compliant version of WITH,
and add the RECURSIVE functionality in a later patch/release.
...Robert
On Tue, 2008-09-09 at 13:45 +0900, Tatsuo Ishii wrote:
Thanks for the review.
The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
The important arguments in the thread seemed to be:
1. People will generally expect single evaluation, so might be
disappointed if they can't use this feature for that purpose.2. It's a spec violation in the case of volatile functions.
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.Tom Lane said that multiple evaluation is grounds for rejection:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01318.phpIs there hope of correcting this before November?
According to Tom, to implement "single evaluation" we need to make big
infrastructure enhancement which is likely slip the schedule for 8.4
release which Tom does not want.
So as long as Tom and other people think that is a "must fix", there
seems no hope probably.
Anyway I will continue to work on existing patches...
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Show quoted text
I will try to fix this. However detecting the query being not a
non-linear one is not so easy.If we don't allow mutual recursion, the only kind of non-linear
recursion that might exist would be multiple references to the same
recursive query name in a recursive query, is that correct?* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.I'm not sure if it's possible to fix this. Will look into.
Can't we just reject queries with top-level DISTINCT, similar to how
UNION is rejected?* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.Not an issue, I think.
Agreed, Andrew Gierth corrected me here.
Regards,
Jeff Davis--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello
2008/9/9 Tatsuo Ishii <ishii@postgresql.org>:
On Tue, 2008-09-09 at 13:45 +0900, Tatsuo Ishii wrote:
Thanks for the review.
The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
The important arguments in the thread seemed to be:
1. People will generally expect single evaluation, so might be
disappointed if they can't use this feature for that purpose.2. It's a spec violation in the case of volatile functions.
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.Tom Lane said that multiple evaluation is grounds for rejection:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01318.phpIs there hope of correcting this before November?
According to Tom, to implement "single evaluation" we need to make big
infrastructure enhancement which is likely slip the schedule for 8.4
release which Tom does not want.
why? why don't use a materialisation?
So as long as Tom and other people think that is a "must fix", there
seems no hope probably.Anyway I will continue to work on existing patches...
--
I would to see your patch in core early. I am working on grouping sets
and I cannot finish my patch before your patch will be commited.
Regards
Pavel Stehule
Show quoted text
Tatsuo Ishii
SRA OSS, Inc. JapanI will try to fix this. However detecting the query being not a
non-linear one is not so easy.If we don't allow mutual recursion, the only kind of non-linear
recursion that might exist would be multiple references to the same
recursive query name in a recursive query, is that correct?* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.I'm not sure if it's possible to fix this. Will look into.
Can't we just reject queries with top-level DISTINCT, similar to how
UNION is rejected?* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.Not an issue, I think.
Agreed, Andrew Gierth corrected me here.
Regards,
Jeff Davis--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello
2008/9/9 Tatsuo Ishii <ishii@postgresql.org>:
On Tue, 2008-09-09 at 13:45 +0900, Tatsuo Ishii wrote:
Thanks for the review.
The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
The important arguments in the thread seemed to be:
1. People will generally expect single evaluation, so might be
disappointed if they can't use this feature for that purpose.2. It's a spec violation in the case of volatile functions.
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.Tom Lane said that multiple evaluation is grounds for rejection:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01318.phpIs there hope of correcting this before November?
According to Tom, to implement "single evaluation" we need to make big
infrastructure enhancement which is likely slip the schedule for 8.4
release which Tom does not want.why? why don't use a materialisation?
See:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
Show quoted text
So as long as Tom and other people think that is a "must fix", there
seems no hope probably.Anyway I will continue to work on existing patches...
--I would to see your patch in core early. I am working on grouping sets
and I cannot finish my patch before your patch will be commited.Regards
Pavel StehuleTatsuo Ishii
SRA OSS, Inc. JapanI will try to fix this. However detecting the query being not a
non-linear one is not so easy.If we don't allow mutual recursion, the only kind of non-linear
recursion that might exist would be multiple references to the same
recursive query name in a recursive query, is that correct?* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.I'm not sure if it's possible to fix this. Will look into.
Can't we just reject queries with top-level DISTINCT, similar to how
UNION is rejected?* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.Not an issue, I think.
Agreed, Andrew Gierth corrected me here.
Regards,
Jeff Davis--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello
2008/9/9 Tatsuo Ishii <ishii@postgresql.org>:
On Tue, 2008-09-09 at 13:45 +0900, Tatsuo Ishii wrote:
Thanks for the review.
The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
The important arguments in the thread seemed to be:
1. People will generally expect single evaluation, so might be
disappointed if they can't use this feature for that purpose.2. It's a spec violation in the case of volatile functions.
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.Tom Lane said that multiple evaluation is grounds for rejection:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01318.phpIs there hope of correcting this before November?
According to Tom, to implement "single evaluation" we need to make big
infrastructure enhancement which is likely slip the schedule for 8.4
release which Tom does not want.why? why don't use a materialisation?
See:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
Show quoted text
So as long as Tom and other people think that is a "must fix", there
seems no hope probably.Anyway I will continue to work on existing patches...
--I would to see your patch in core early. I am working on grouping sets
and I cannot finish my patch before your patch will be commited.Regards
Pavel StehuleTatsuo Ishii
SRA OSS, Inc. JapanI will try to fix this. However detecting the query being not a
non-linear one is not so easy.If we don't allow mutual recursion, the only kind of non-linear
recursion that might exist would be multiple references to the same
recursive query name in a recursive query, is that correct?* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.I'm not sure if it's possible to fix this. Will look into.
Can't we just reject queries with top-level DISTINCT, similar to how
UNION is rejected?* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.Not an issue, I think.
Agreed, Andrew Gierth corrected me here.
Regards,
Jeff Davis--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
* Aggregates allowed:
with recursive foo(i) as
(values(1)
union all
select max(i)+1 from foo where i < 10)
select * from foo;Aggregates should be blocked according to the standard.
Also, causes an infinite loop. This should be fixed for 8.4.I will try to fix this.
We already reject:
select max(i) from foo where i < 10)
But max(i)+1 seems to slip the check. I looked into this I found the
patch tried to detect the case before analyzing(see
parser/parse_cte.c) which is not a right thing I think.
I think we could detect the case by adding more checking in
parseCheckAggregates():
/*
* Check if there's aggregate function in a recursive term.
*/
foreach(l, qry->rtable)
{
RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
if (qry->hasAggs && rte->rtekind == RTE_RECURSIVE &&
rte->self_reference)
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("aggregate functions in a recursive term not allowed")));
}
}
What do you think?
--
Tatsuo Ishii
SRA OSS, Inc. Japan
On Tue, 2008-09-09 at 09:47 -0400, Robert Haas wrote:
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.What makes you think it's going to be undocumented? Single versus
multiple evaluation is a keep aspect of this feature and certainly
needs to be documented one way or the other. I can't understand why
we would introduce a standard syntax with non-standard behavior, but
if we do, it certainly had better be mentioned in the documentation.
I meant that -- hypothetically if we did accept the feature as-is -- the
number of evaluations would be documented to be undefined, not N. That
would avoid the backwards-compatibility problem.
This one point is probably not worth discussing now, because argument
#1 and #2 stand on their own.
Regards,
Jeff Davis
2008/9/9 Tatsuo Ishii <ishii@sraoss.co.jp>:
Hello
2008/9/9 Tatsuo Ishii <ishii@postgresql.org>:
On Tue, 2008-09-09 at 13:45 +0900, Tatsuo Ishii wrote:
Thanks for the review.
The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's a easy way to fix this. Maybe
we should not allow WITH clause without RECURISVE?My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
I am blind, I didn't find any reason, why materialisation isn't useable.
Regards
Pavel
Show quoted text
The important arguments in the thread seemed to be:
1. People will generally expect single evaluation, so might be
disappointed if they can't use this feature for that purpose.2. It's a spec violation in the case of volatile functions.
3. "I think this is a "must fix" because of the point about volatile
functions --- changing it later will result in user-visible semantics
changes, so we have to get it right the first time."I don't entirely agree with #3. It is user-visible, but only in the
sense that someone is depending on undocumented multiple-evaluation
behavior.Tom Lane said that multiple evaluation is grounds for rejection:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01318.phpIs there hope of correcting this before November?
According to Tom, to implement "single evaluation" we need to make big
infrastructure enhancement which is likely slip the schedule for 8.4
release which Tom does not want.why? why don't use a materialisation?
See:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.phpSo as long as Tom and other people think that is a "must fix", there
seems no hope probably.Anyway I will continue to work on existing patches...
--I would to see your patch in core early. I am working on grouping sets
and I cannot finish my patch before your patch will be commited.Regards
Pavel StehuleTatsuo Ishii
SRA OSS, Inc. JapanI will try to fix this. However detecting the query being not a
non-linear one is not so easy.If we don't allow mutual recursion, the only kind of non-linear
recursion that might exist would be multiple references to the same
recursive query name in a recursive query, is that correct?* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.I'm not sure if it's possible to fix this. Will look into.
Can't we just reject queries with top-level DISTINCT, similar to how
UNION is rejected?* outer joins on a recursive reference should be blocked:
with recursive foo(i) as
(values(1)
union all
select i+1 from foo left join (values(1)) t on (i=column1))
select * from foo;Causes an infinite loop, but the standard says using an outer join
in this situation should be prohibited. This should be fixed for 8.4.Not an issue, I think.
Agreed, Andrew Gierth corrected me here.
Regards,
Jeff Davis--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
I am blind, I didn't find any reason, why materialisation isn't useable.
I believe it's because of these two (closely related) problems:
# The basic
# implementation clearly ought to be to dump the result of the subquery
# into a tuplestore and then have the upper level read out from that.
# However, we don't have any infrastructure for having multiple
# upper-level RTEs reference the same tuplestore. (Perhaps the InitPlan
# infrastructure could be enhanced in that direction, but it's not ready
# for non-scalar outputs today.) Also, I think we'd have to teach
# tuplestore how to support multiple readout cursors. For example,
# consider
# WITH foo AS (SELECT ...) SELECT ... FROM foo a, foo b WHERE ...
# If the planner chooses to do the join as a nested loop then each
# Scan node needs to keep track of its own place in the tuplestore,
# concurrently with the other node having a different place.
...Robert
2008/9/9 Robert Haas <robertmhaas@gmail.com>:
My interpretation of 7.13: General Rules: 2.b is that it should be
single evaluation, even if RECURSIVE is present.The previous discussion was here:
http://archives.postgresql.org/pgsql-hackers/2008-07/msg01292.php
I am blind, I didn't find any reason, why materialisation isn't useable.
I believe it's because of these two (closely related) problems:
# The basic
# implementation clearly ought to be to dump the result of the subquery
# into a tuplestore and then have the upper level read out from that.
# However, we don't have any infrastructure for having multiple
# upper-level RTEs reference the same tuplestore. (Perhaps the InitPlan
# infrastructure could be enhanced in that direction, but it's not ready
# for non-scalar outputs today.) Also, I think we'd have to teach
# tuplestore how to support multiple readout cursors. For example,
# consider
# WITH foo AS (SELECT ...) SELECT ... FROM foo a, foo b WHERE ...
# If the planner chooses to do the join as a nested loop then each
# Scan node needs to keep track of its own place in the tuplestore,
# concurrently with the other node having a different place.
hmm. I solve similar problem in grouping sets :( etc
SELECT ... FROM ... GROUP BY GROUPING SETS (a,b)
is almost same as
With foo AS (SELECT ... FROM) SELECT ... FROM foo GROUP BY a UNION ALL
SELECT ... FROM foo GROUP BY b;
Regards
Pavel
Show quoted text
...Robert
On Tue, 2008-09-09 at 18:51 +0200, Pavel Stehule wrote:
hmm. I solve similar problem in grouping sets :( etc
How did you solve it?
Regards,
Jeff Davis
2008/9/9 Jeff Davis <pgsql@j-davis.com>:
On Tue, 2008-09-09 at 18:51 +0200, Pavel Stehule wrote:
hmm. I solve similar problem in grouping sets :( etc
I have special executor node - feeder, it hold one tuple and others
nodes read from this node. It's usable for hash aggregates.
Pavel
plan is like:
grouping sets
--> seq scan ...
--> hash aggg
--> feeder
--> hash agg
--> feeder
Show quoted text
How did you solve it?
Regards,
Jeff Davis
"Robert Haas" <robertmhaas@gmail.com> writes:
I am blind, I didn't find any reason, why materialisation isn't useable.
I believe it's because of these two (closely related) problems:
# The basic
# implementation clearly ought to be to dump the result of the subquery
# into a tuplestore and then have the upper level read out from that.
# However, we don't have any infrastructure for having multiple
# upper-level RTEs reference the same tuplestore. (Perhaps the InitPlan
# infrastructure could be enhanced in that direction, but it's not ready
# for non-scalar outputs today.) Also, I think we'd have to teach
# tuplestore how to support multiple readout cursors. For example,
# consider
# WITH foo AS (SELECT ...) SELECT ... FROM foo a, foo b WHERE ...
# If the planner chooses to do the join as a nested loop then each
# Scan node needs to keep track of its own place in the tuplestore,
# concurrently with the other node having a different place.
The amount of new code needed for that seems a pittance compared to the
size of the patch already, so I'm not seeing why Tatsuo-san considers
it infeasible.
regards, tom lane
I meant that -- hypothetically if we did accept the feature as-is -- the
number of evaluations would be documented to be undefined, not N. That
would avoid the backwards-compatibility problem.This one point is probably not worth discussing now, because argument
#1 and #2 stand on their own.
Agreed. Plus, both Tom and Pavel seem to think this is a relatively
solvable problem.
...Robert
* Single Evaluation:
with
foo(i) as (select random() as i)
select * from foo union all select * from foo;
i
-------------------
0.233165248762816
0.62126633618027
(2 rows)The standard specifies that non-recursive WITH should be evaluated
once.What shall we do? I don't think there's an easy way to fix this as Tom
suggested. Maybe we should not allow WITH clause without RECURISVE for
8.4?
This is a still remaing issue...
* Binary recursion and subselect strangeness:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
union all
select i+1 from foo where i < X) t)
select * from foo;Produces 10 rows of output regardless of what "X" is. This should be
fixed for 8.4.
Also, this is non-linear recursion, which the standard seems to
disallow.I will try to fix this. However detecting the query being not a
non-linear one is not so easy.
I have implemented rejection of non-linear recursion and now this type
of query will not be executed anyway.
* Multiple recursive references:
with recursive foo(i) as
(values (1)
union all
select i+1 from foo where i < 10
union all
select i+1 from foo where i < 20)
select * from foo;
ERROR: Left hand side of UNION ALL must be a non-recursive term in a
recursive queryIf we're going to allow non-linear recursion (which the standard
does not), this seems like it should be a valid case.I will try to disallow this.
Non-linear recursion is not allowed now.
* Strange result with except:
with recursive foo(i) as
(values (1)
union all
select * from
(select i+1 from foo where i < 10
except
select i+1 from foo where i < 5) t)
select * from foo;
ERROR: table "foo" has 0 columns available but 1 columns specifiedThis query works if you replace "except" with "union". This should be
fixed for 8.4.I will try to fix this.
This is a non-linear recursion too and will not be executed anyway.
* Aggregates allowed:
with recursive foo(i) as
(values(1)
union all
select max(i)+1 from foo where i < 10)
select * from foo;Aggregates should be blocked according to the standard.
Also, causes an infinite loop. This should be fixed for 8.4.I will try to fix this.
Fixed.
* DISTINCT should supress duplicates:
with recursive foo(i) as
(select distinct * from (values(1),(2)) t
union all
select distinct i+1 from foo where i < 10)
select * from foo;This outputs a lot of duplicates, but they should be supressed
according to the standard. This query is essentially the same as
supporting UNION for recursive queries, so we should either fix both for
8.4 or block both for consistency.I'm not sure if it's possible to fix this. Will look into.
Ok, now this type of DISTINCT is not allowed.
Included is the latest patches against CVS HEAD.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Attachments:
On Mon, Sep 15, 2008 at 06:46:16PM +0900, Tatsuo Ishii wrote:
* Single Evaluation:
with
foo(i) as (select random() as i)
select * from foo union all select * from foo;
i
-------------------
0.233165248762816
0.62126633618027
(2 rows)The standard specifies that non-recursive WITH should be
evaluated once.What shall we do? I don't think there's an easy way to fix this as
Tom suggested. Maybe we should not allow WITH clause without
RECURISVE for 8.4?This is a still remaing issue...
I don't think that the spec explicitly forbids this.
Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
On Mon, 2008-09-15 at 22:41 -0700, David Fetter wrote:
On Mon, Sep 15, 2008 at 06:46:16PM +0900, Tatsuo Ishii wrote:
* Single Evaluation:
with
foo(i) as (select random() as i)
select * from foo union all select * from foo;
i
-------------------
0.233165248762816
0.62126633618027
(2 rows)The standard specifies that non-recursive WITH should be
evaluated once.What shall we do? I don't think there's an easy way to fix this as
Tom suggested. Maybe we should not allow WITH clause without
RECURISVE for 8.4?This is a still remaing issue...
I don't think that the spec explicitly forbids this.
This has been discussed before.
Regardless of the nuances of the spec (and whether it says so explicitly
or implicitly), there are people in the community that see single
evaluation as important, and important enough to be a showstopper.
Tom Lane has suggested that this is a reasonable amount of work to
complete, and minor in comparison to the rest of the patch.
I think the right approach is to try to complete it so that everyone is
happy. I will work on this, but unfortunately I don't have a lot of time
right now, so I can't make any promises.
The rest of the patch looks good so far (there are still a few things I
want to look at), so I think this is the biggest open issue.
Regards,
Jeff Davis
Tatsuo Ishii <ishii@postgresql.org> writes:
Included is the latest patches against CVS HEAD.
I spent some time reading this patch. Here are a few comments in
no particular order:
RangeRecursive node lacks copyfuncs/equalfuncs support.
Query.recursive is missed in equalfuncs.c. But rather than fix that,
get rid of it entirely. AFAICS the only use is in qual_is_pushdown_safe,
and what is the value of that test? The callers know perfectly well
whether they are operating on a recursive RTE or not. You might as well
just delete all the useless qual-pushdown-attempt code from
set_recursion_pathlist, and not need to touch qual_is_pushdown_safe
at all.
Is physical_tlist optimization sensible for RecursiveScan? We seem
to use it for every other Scan node type.
I dislike putting state into ExecutorState; that makes it impossible
to have multiple recursion nodes in one plan tree. It would probably
be better for the Recursion and RecursiveScan nodes to talk to each
other directly (compare HashJoin/Hash); although since they are not
adjacent in the plan tree I admit I'm not sure how to do that.
es_disallow_tuplestore doesn't seem to need to be in ExecutorState
at all, it could as well be in RecursionState.
I don't really like the way that Append nodes are being abused here.
It would be better to allow nodeRecursion.c to duplicate a little code
from nodeAppend.c, and have the child plans be direct children of
the Recursion node. BTW, is it actually possible to have more than
two children? I didn't spend enough time analyzing the restrictions
in parse_cte to be sure. If there are always just two then you could
simplify the representation by treating it like a join node instead
of an append. (The RTE_RECURSIVE representation sure makes it look
like there can be only two...)
Mark/restore support seems useless ... note the comment on
ExecSupportsMarkRestore (which should be updated if this code
isn't removed).
RecursiveScan claims to support backwards fetch, but does not in fact
contain code to do so. (Given that it will always be underneath
Recursion, which can't do backwards fetch, I see little point in adding
such code; fix execAmi.c instead.)
ExecInitRecursion doesn't seem to be on the same page about whether
it supports backward scan as execAmi.c, either.
This comment in nodeRecursivescan.c seems bogus:
/*
* Do not initialize scan tuple type, result tuple type and
* projection info in ExecInitRecursivescan. These types are
* initialized after initializing Recursion node.
*/
because the code seems to be doing exactly what the comment says it
doesn't.
Numerous comments appear to have been copied-and-pasted and not modified
from the original. Somebody will have to go over all that text.
ruleutils.c fails completely for non-recursive WITH. It *must* regenerate
such a query with a WITH clause, not as a flattened subquery which is what
you seem to be doing. This isn't negotiable because the semantics are
different. This will mean at least some change in the parsetree
representation. Perhaps we could add a bool to subquery RTEs to mark them
as coming from a nonrecursive WITH? The tests added for RTE_RECURSIVE
seem a bit ugly too. If it thinks that can't happen it should Assert so,
not just fall through silently.
commentary for ParseState.p_ctenamespace is gratuitously unlike the
comment style for the other fields, and p_recursive_namespace isn't
documented at all.
ParseState.p_in_with_clause is unused, should be removed.
The WithClause struct definition is poorly commented. It should be
stated that it is used only pre-parse-analysis (assuming that continues
to be true after you get done fixing ruleutils.c...), and it doesn't
say what the elements of the subquery list are (specifically, what
node type). A lot of the other added structs and fields could use
better commenting too.
For that matter "subquery" is a poor name for WithClause's list of CTEs,
especially so since it's hard to search for. It should be a plural name
and I'd be inclined to use something like "ctes" not "subqueries".
The term "subquery" is too overloaded already, so any place you can
refer to a WITH-list member as a CTE you should do so.
WithClause node may need a location field, and almost certainly has to
be handled somehow in exprLocation().
The error reports in parse_cte.c *desperately* need error locations.
Why does transformWithClause do parse_sub_analyze twice?
I'm not sure that's even safe, and it's surely unnecessary.
Also, what happens if a subquery isn't a SelectStmt? Silently
doing nothing doesn't seem like a good plan there.
Why are we putting essentially the same information into both
p_recursive_namespace and p_ctenamespace? Is there really a need
for both lists? The code added to transformFromClauseItem
seems quite wrong since it searches both lists even if it found a
match in the first one. This whole area looks like it needs
refactoring.
Costing is all bogus, but we knew that...
Why does set_recursion_pathlist think that the subquery might have
useful pathkeys? We know it must always be a UNION ALL, no?
PlanState.has_recursivescan seems like a complete kluge. Can't it just be
removed? It looks to me like it is working around bugs that hopefully aren't
there anymore. There is certainly no reason why a recursive CTE should be
more in need of rescanning than any other kind of plan. If it is needed then
the current implementation is completely broken anyway, since it would only
detect a RecursiveScan node that is directly underneath an agg or hash node.
Please pay some attention to keeping things in logical, consistent orders.
For instance the withClause field was inserted into _copySelectStmt()
in a different place from where it was inserted in the actual struct
declaration, which is confusing.
parseTypeString() ought to check for null withClause.
expression_tree_walker/mutator support seems entirely broken for
RTE_RECURSIVE RTEs. Shouldn't it be recursing into the subquery?
Missed adding non_recursive_query to the "zap unneeded substructure" part
of set_plan_references (assuming it really is unneeded).
There seem to be quite a number of places where RTE_SUBQUERY RTEs
are handled but the patch fails to add RTE_RECURSIVE handling ...
It's a really bad idea to use RTE subquery field over again for
RTE_RECURSIVE, especially without any comment saying you did that.
I would suggest two pointers in the RTE_RECURSIVE field list instead.
Do we really have to make RECURSIVE a fully reserved keyword?
(Actually, the patch makes it worse than reserved, by failing to
add it to the reserved_keywords list.)
checkCteTargetList is completely broken: it will only notice illegal
sublinks that are at the very top level of a targetlist expression.
checkWhereClause is very far short of adequate as well. Need to recurse
here, or find some other way. Given that the subexpressions haven't been
analyzed yet, this seems a bit messy --- expression_tree_walker doesn't
know about pre-analysis node trees, so you can't use it. I'd suggest
replacing this whole set of routines with just one recursive routine that
doesn't make pre-assumptions about which node types can be found where.
Alternatively, is there any way of delaying the validity checks until
*after* parse analysis of the expressions, so that you could use
expression_tree_walker et al?
BTW, it seems like a lot of the logic there could be simplified by depending
on the enum ordering RECURSIVE_OTHER > RECURSIVE_SELF > NON_RECURSIVE.
There are a number of places that are taking the larger of two values
in baroque, hard-to-follow ways.
I wonder if checkCteSelectStmt is detecting nonlinearity correctly.
Since RECURSIVE_OTHER dominates RECURSIVE_SELF, couldn't it fail to
miss the problem in something like (self union (self union other)) ?
Maybe what you really need is a bitmask:
NON_RECURSIVE = 0,
RECURSIVE_SELF = 1,
RECURSIVE_OTHER = 2,
RECURSIVE_BOTH = 3 /* the OR of RECURSIVE_SELF and RECURSIVE_OTHER */
and then you can merge two values via OR instead of MAX.
regards, tom lane
Jeff Davis <pgsql@j-davis.com> writes:
I think the right approach is to try to complete it so that everyone is
happy. I will work on this, but unfortunately I don't have a lot of time
right now, so I can't make any promises.
I think there are two significant bits there:
* Fixing the parsetree representation so that the distinction between
a CTE and an RTE that references the CTE is preserved.
* Implementing some kind of "multiple readout tuplestore" to permit
multiple RTEs to scan a CTE plan without causing any row to be
evaluated more than once.
The first of these seems relatively straightforward: the WITH clause
has to be preserved explicitly in the Query representation, and RTEs
for CTEs should just carry indexes into the WITH list, not copies of
the subqueries. (Hm, we might need both an index and a levelsup
counter, to deal with nested queries...) This would solve ruleutils'
problem, too.
I haven't thought much about the multiple readout tuplestore though.
Anyone have a clear idea how to do that? In particular, can the
existing tuplestore code be enhanced to do it (without sacrificing
performance in the simple case), or do we need something new?
regards, tom lane
I had either on that a while back. I think the existing tuplestore can
be made to work without bad performance penaltiesbin the usual case.
The trick was to do it without making the code unreadable.
I can send the code I had but I doubt you want to use it as-is.
--
greg
Greg Stark <greg.stark@enterprisedb.com> writes:
I had either on that a while back. I think the existing tuplestore can
be made to work without bad performance penaltiesbin the usual case.
The trick was to do it without making the code unreadable.
I can send the code I had but I doubt you want to use it as-is.
Sure. Maybe someone else will see a way to make it more readable.
regards, tom lane
Do we really have to make RECURSIVE a fully reserved keyword?
According to the standard, RECURSIVE is a reserved keyword, I believe.
(Actually, the patch makes it worse than reserved, by failing to
add it to the reserved_keywords list.)
Yes, it's a bug. Will fix...
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Tatsuo Ishii <ishii@postgresql.org> writes:
Do we really have to make RECURSIVE a fully reserved keyword?
According to the standard, RECURSIVE is a reserved keyword, I believe.
Sure, but our general rule is to make keywords no more reserved than
is absolutely necessary to make the bison grammar unambiguous. I
haven't tested, but I'm thinking that if WITH is fully reserved then
RECURSIVE shouldn't have to be.
regards, tom lane
2008/9/17 Tom Lane <tgl@sss.pgh.pa.us>:
Tatsuo Ishii <ishii@postgresql.org> writes:
Do we really have to make RECURSIVE a fully reserved keyword?
According to the standard, RECURSIVE is a reserved keyword, I believe.
Sure, but our general rule is to make keywords no more reserved than
is absolutely necessary to make the bison grammar unambiguous. I
haven't tested, but I'm thinking that if WITH is fully reserved then
RECURSIVE shouldn't have to be.
I am not sure, if these rule is good. Somebody who develop on
postgresql should have a problems when they will be port to other
databases in future. Reserved words in standards should be respected.
regards
Pavel Stehule
Show quoted text
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
I am not sure, if these rule is good. Somebody who develop on
postgresql should have a problems when they will be port to other
databases in future. Reserved words in standards should be respected.
I disagree. I have never ported an app written for PostgreSQL to
another database system, and have no plans to start. The fact that
some other database system might barf on a particular bit of SQL is
insufficient reason for PostgreSQL to do the same thing.
If people want to write code that will work on multiple databases,
they should of course avoid using any SQL reserved words for anything
other than their reserved purposes. But there is no reason for the
database system to unilaterally shove that down everyone's throat. It
is very easy to overdo the idea of protecting users from themselves.
...Robert
"Robert Haas" <robertmhaas@gmail.com> writes:
I am not sure, if these rule is good. Somebody who develop on
postgresql should have a problems when they will be port to other
databases in future. Reserved words in standards should be respected.
I disagree. I have never ported an app written for PostgreSQL to
another database system, and have no plans to start. The fact that
some other database system might barf on a particular bit of SQL is
insufficient reason for PostgreSQL to do the same thing.
If people want to write code that will work on multiple databases,
they should of course avoid using any SQL reserved words for anything
other than their reserved purposes.
More than that, they have to actually test their SQL on each target DB.
Every DB (including us) is going to have some reserved words that are
not in the standard; so imagining that Postgres can all by itself
protect you from this type of problem is doomed to failure anyway.
regards, tom lane
Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Robert Haas" <robertmhaas@gmail.com> writes:
I am not sure, if these rule is good. Somebody who develop on
postgresql should have a problems when they will be port to other
databases in future. Reserved words in standards should be
respected.
If people want to write code that will work on multiple databases,
they should of course avoid using any SQL reserved words for
anything
other than their reserved purposes.
More than that, they have to actually test their SQL on each target
DB.
Every DB (including us) is going to have some reserved words that
are
not in the standard; so imagining that Postgres can all by itself
protect you from this type of problem is doomed to failure anyway.
If someone wants portable code, they can use a development tool which
wraps ALL identifiers in quotes, every time. That's what we do. The
important thing is that, to the extent practicable, standard SQL code
is accepted and behaves in compliance with the standard. I don't see
that it does anything to compromise that if you support additional,
non-standard syntax for extensions.
-Kevin
Is physical_tlist optimization sensible for RecursiveScan? We seem
to use it for every other Scan node type.
To enable physical_tlist optimization, it seems build_physical_tlist,
use_physical_tlist and disuse_physical_tlist need to be
changed. build_physical_tlist and use_physical_tlist have been already
patched and only disuse_physical_tlist needs to be patched. Any other
place I miss to enable the optimization?
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Tatsuo Ishii <ishii@postgresql.org> writes:
Is physical_tlist optimization sensible for RecursiveScan? We seem
to use it for every other Scan node type.
To enable physical_tlist optimization, it seems build_physical_tlist,
use_physical_tlist and disuse_physical_tlist need to be
changed. build_physical_tlist and use_physical_tlist have been already
patched and only disuse_physical_tlist needs to be patched. Any other
place I miss to enable the optimization?
IIRC, the comment for build_physical_tlist hadn't been patched, but
yeah that seems like about it.
regards, tom lane
To enable physical_tlist optimization, it seems build_physical_tlist,
use_physical_tlist and disuse_physical_tlist need to be
changed. build_physical_tlist and use_physical_tlist have been already
patched and only disuse_physical_tlist needs to be patched. Any other
place I miss to enable the optimization?IIRC, the comment for build_physical_tlist hadn't been patched, but
yeah that seems like about it.
Yeah, I need to fix sloppy comments in the existing patches all over
the places:-)
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Tom, thanks for the review.
Here is an in-progress report. Patches against CVS HEAD attached.
(uncommented items are work-in-progress).
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Tatsuo Ishii <ishii@postgresql.org> writes:
Included is the latest patches against CVS HEAD.
I spent some time reading this patch. Here are a few comments in
no particular order:RangeRecursive node lacks copyfuncs/equalfuncs support.
Functions added.
Query.recursive is missed in equalfuncs.c. But rather than fix that,
get rid of it entirely. AFAICS the only use is in qual_is_pushdown_safe,
and what is the value of that test? The callers know perfectly well
whether they are operating on a recursive RTE or not. You might as well
just delete all the useless qual-pushdown-attempt code from
set_recursion_pathlist, and not need to touch qual_is_pushdown_safe
at all.
Query.recursive removed and qual_is_pushdown_safe is untouched.
Is physical_tlist optimization sensible for RecursiveScan? We seem
to use it for every other Scan node type.
Fixed and physical_tlist optimization is enabled for RecursiveScan I
believe.
I dislike putting state into ExecutorState; that makes it impossible
to have multiple recursion nodes in one plan tree. It would probably
be better for the Recursion and RecursiveScan nodes to talk to each
other directly (compare HashJoin/Hash); although since they are not
adjacent in the plan tree I admit I'm not sure how to do that.es_disallow_tuplestore doesn't seem to need to be in ExecutorState
at all, it could as well be in RecursionState.
It was for a workaround to avoid an infinit recursion in some
cases. Discussion came to the conclusion that it's user's
responsibilty to avoid such that case (otherwise the semantics of our
recursive query becomes to be different from the one defined in the
standard) I believe.
es_disallow_tuplestore removed.
I don't really like the way that Append nodes are being abused here.
It would be better to allow nodeRecursion.c to duplicate a little code
from nodeAppend.c, and have the child plans be direct children of
the Recursion node. BTW, is it actually possible to have more than
two children? I didn't spend enough time analyzing the restrictions
in parse_cte to be sure. If there are always just two then you could
simplify the representation by treating it like a join node instead
of an append. (The RTE_RECURSIVE representation sure makes it look
like there can be only two...)Mark/restore support seems useless ... note the comment on
ExecSupportsMarkRestore (which should be updated if this code
isn't removed).RecursiveScan claims to support backwards fetch, but does not in fact
contain code to do so. (Given that it will always be underneath
Recursion, which can't do backwards fetch, I see little point in adding
such code; fix execAmi.c instead.)ExecInitRecursion doesn't seem to be on the same page about whether
it supports backward scan as execAmi.c, either.This comment in nodeRecursivescan.c seems bogus:
/*
* Do not initialize scan tuple type, result tuple type and
* projection info in ExecInitRecursivescan. These types are
* initialized after initializing Recursion node.
*/
because the code seems to be doing exactly what the comment says it
doesn't.Numerous comments appear to have been copied-and-pasted and not modified
from the original. Somebody will have to go over all that text.ruleutils.c fails completely for non-recursive WITH. It *must* regenerate
such a query with a WITH clause, not as a flattened subquery which is what
you seem to be doing. This isn't negotiable because the semantics are
different. This will mean at least some change in the parsetree
representation. Perhaps we could add a bool to subquery RTEs to mark them
as coming from a nonrecursive WITH? The tests added for RTE_RECURSIVE
seem a bit ugly too. If it thinks that can't happen it should Assert so,
not just fall through silently.commentary for ParseState.p_ctenamespace is gratuitously unlike the
comment style for the other fields, and p_recursive_namespace isn't
documented at all.ParseState.p_in_with_clause is unused, should be removed.
Done.
The WithClause struct definition is poorly commented. It should be
stated that it is used only pre-parse-analysis (assuming that continues
to be true after you get done fixing ruleutils.c...), and it doesn't
say what the elements of the subquery list are (specifically, what
node type). A lot of the other added structs and fields could use
better commenting too.For that matter "subquery" is a poor name for WithClause's list of CTEs,
especially so since it's hard to search for. It should be a plural name
and I'd be inclined to use something like "ctes" not "subqueries".
The term "subquery" is too overloaded already, so any place you can
refer to a WITH-list member as a CTE you should do so.WithClause node may need a location field, and almost certainly has to
be handled somehow in exprLocation().The error reports in parse_cte.c *desperately* need error locations.
Why does transformWithClause do parse_sub_analyze twice?
I'm not sure that's even safe, and it's surely unnecessary.
Also, what happens if a subquery isn't a SelectStmt? Silently
doing nothing doesn't seem like a good plan there.Why are we putting essentially the same information into both
p_recursive_namespace and p_ctenamespace? Is there really a need
for both lists? The code added to transformFromClauseItem
seems quite wrong since it searches both lists even if it found a
match in the first one. This whole area looks like it needs
refactoring.Costing is all bogus, but we knew that...
Why does set_recursion_pathlist think that the subquery might have
useful pathkeys? We know it must always be a UNION ALL, no?PlanState.has_recursivescan seems like a complete kluge. Can't it just be
removed? It looks to me like it is working around bugs that hopefully aren't
there anymore. There is certainly no reason why a recursive CTE should be
more in need of rescanning than any other kind of plan. If it is needed then
the current implementation is completely broken anyway, since it would only
detect a RecursiveScan node that is directly underneath an agg or hash node.Please pay some attention to keeping things in logical, consistent orders.
For instance the withClause field was inserted into _copySelectStmt()
in a different place from where it was inserted in the actual struct
declaration, which is confusing.parseTypeString() ought to check for null withClause.
Done.
expression_tree_walker/mutator support seems entirely broken for
RTE_RECURSIVE RTEs. Shouldn't it be recursing into the subquery?Missed adding non_recursive_query to the "zap unneeded substructure" part
of set_plan_references (assuming it really is unneeded).There seem to be quite a number of places where RTE_SUBQUERY RTEs
are handled but the patch fails to add RTE_RECURSIVE handling ...It's a really bad idea to use RTE subquery field over again for
RTE_RECURSIVE, especially without any comment saying you did that.
I would suggest two pointers in the RTE_RECURSIVE field list instead.Do we really have to make RECURSIVE a fully reserved keyword?
(Actually, the patch makes it worse than reserved, by failing to
add it to the reserved_keywords list.)
Changed to unreserved keyword.
Show quoted text
checkCteTargetList is completely broken: it will only notice illegal
sublinks that are at the very top level of a targetlist expression.
checkWhereClause is very far short of adequate as well. Need to recurse
here, or find some other way. Given that the subexpressions haven't been
analyzed yet, this seems a bit messy --- expression_tree_walker doesn't
know about pre-analysis node trees, so you can't use it. I'd suggest
replacing this whole set of routines with just one recursive routine that
doesn't make pre-assumptions about which node types can be found where.
Alternatively, is there any way of delaying the validity checks until
*after* parse analysis of the expressions, so that you could use
expression_tree_walker et al?BTW, it seems like a lot of the logic there could be simplified by depending
on the enum ordering RECURSIVE_OTHER > RECURSIVE_SELF > NON_RECURSIVE.
There are a number of places that are taking the larger of two values
in baroque, hard-to-follow ways.I wonder if checkCteSelectStmt is detecting nonlinearity correctly.
Since RECURSIVE_OTHER dominates RECURSIVE_SELF, couldn't it fail to
miss the problem in something like (self union (self union other)) ?
Maybe what you really need is a bitmask:
NON_RECURSIVE = 0,
RECURSIVE_SELF = 1,
RECURSIVE_OTHER = 2,
RECURSIVE_BOTH = 3 /* the OR of RECURSIVE_SELF and RECURSIVE_OTHER */
and then you can merge two values via OR instead of MAX.regards, tom lane
Attachments:
recursive_query.patch.gzapplication/octet-streamDownload
�m��H recursive_query.patch �<ks�8���_�xwg$��I=�H\�I���;k9����T�I�P����xg�~�u�E��v����s%�6���~����=���_��q<�g ������N�
�(m��N�u�n��u��;�zGn���Rs]�Y�^�?��x��u�C��#�}��
(��|&M�ivD���%�����G^ !v��qp{m/��������3�tu����������c�#�����B����?��4����]����.ir�b��<!��h4>��@bpv~���|"����w��?��_���R�D�~]$�� �V��A� ���!��q��2],�a�9�O��O�����M�&I<)��a��[�N�����:�C�j"T���2� ��aT��
��d���(]�2(e;a�a���"6�(��hX�[���$�1�Q������D���am9�U�I.N�?\��o��/q
��E^&��nc��8�I�w�a��x�Y��s�m������}e���-�������vfQ�S��y+�Q*7 4��Y ��f?m���A���{�'����5|��}d���H��&'SSA
[H0~���������4Ha<�j�'t�LXpK������,-���||����W��d =��D����N��zF����?�����#����1a:
&���������3?%#?"7��iB���{�:$A�,�`�4��(�<����;NiLg)���������!�����bX��H�TrP��@��'�A�1�� &$�iJ���B���"8�9���6��'�����L�;vH�* ����L� �>Qo�,��j��#h+xA�I�������TbJ�����Lr�z@����X�*( �.a�QJALi,���"��I*�Z����iH�.�@��U�a(1���U���������YW#�Ha�
�z^syU������Y}����=��{� �A��b����f0��<D��d�o���WOL�e������y^3�5���B�a[{x�����u�"z�]�"�������'�l�4������r��1�<e� ��pW#���E�JM@����_��>��e��L@�P���CT���5���#�,�����a<m�Gt��������O��0�����gWv3��SU���7=���%T�������Ou$�����.G�km��5��z]l�����(���jk�����PQ� �)c��qO0�oQ�)���=��1c|RNT��<�����Q���s?��4�6��t��>����|��#��8�`�2R�%�=����+��;�B�ai��["��A�� 1�#�)a0��4�G ��_y$�@��,�����^�fED�����Cz�f6l{��@F���!��C~�(�P�1���tr�1G�y��2�8�t ��C��BCF����A�����Gt��y�2GH@�(@��,���Fh��e(�p�[���u8������ ���b����7�����-���gWg6�K�#�����h]4�+�4��tUs����M2��p���� �� �m|�6�c���
i���h�p[��2�����h���W��t����h��>f��+$�A�����z�%n�����-���B���v��i���
��Szgg��$��.@��7�,�vE���h�I����{] ��o�:��^�5(��sqZ$�_�������9����t�.4��7?\R6� ON�!�j�@o��P:X�j�d�����O���9P��?�C�5=���fC�5{N/[���?�!2�18PL����2�h���[�u��$�T*�@���5��O<B��� q��7�g������&<�Rp�{I�"H����DX������e���������`xC��H��4�w�{�>P2<��#Z�;B6��%���@R�<�z��\]�
����5>���.��rL�|>
�\P?���&�En��v�!��^Mh/ogP���0=��
��(7���Cc�x�s�}����M��F.�^�m��m��� ��>��~��~�m����7A�+(V�:�)-a�������Q���4���t E@hlA�aU)U�b��@��rN��S��/�^7�=U#k`0��`���1H}�M��?��$���_���O��c�d��,o=��R �=���c����������J�\ P?Q@N�a�L/�5&��f�5f�o�����y�TPQ��)�����Q"u����i�q����@g���~��q����B'AH���C��X�{`�_�����;��U�:Ey�p������^�3�h x���h��g�"l�E^ �����z���J��?{n"��,
�x!!��1p]Q�N>����rx4�THq��?DV���*��<P��&�rQ�3V��3L6]c��2P4p>��Q�l4b�"��p�[N�w��}Y��F�L���t������y`n������Q���N%���^��:-cu��� �K�,���e&��5@�x�Ai;��*��z�������4�u ����]D���z��5�x�iG�M��� c��IS���V:���Ip�U�5����HO
y�,�w$�_(:���@��<kedD����x�#g�����r�����Hj$����J���(�2�5�=p�F���@C�\m���������6��B���j9�����y��v��\1�r�vZ���D �������?Aj��$��������M�u�N�[\��������UUB������i����h�����T�i���8l��E��!�}�P:�z���}����)N0?<X��C�^��s��������{������PXrSS8�!�LB�����M%|0X�c1���~��b/�e�b���jg�_�����T����������N��[Bd5��Q����vr�-KPV�{;������d������j�/���#�:�%*= �X��TN�j����!Z��p����/�P�8�b+�>��X�����\��dC�R�u�P���K���:�D�E�'N<��WjW�������i�1�ht�������3��Wx�`�)S0j�_&�p�{�|��Y�t�|�t�a��0J#v Q�t��.��2Zn��s9�����b[�w���5�w�]�������h��^C�|���G�|�
��B�C�.�����W��-��\A6��=�r���a]^������x��=<j6�:����E�^�n��H�T�j22/l�/������������������\#��[������J�1���\��S���ec:��(4�S�U�� c�k�|��@P{=�hU�'xU���b������x����x��6��m8^�s�v��e`N���'���8Y��i���<`%�!���bq+�WX��f2��F/s�_��Q�,YJ!~���8�a�:V���D�t&�Y�����Cp���Rl@[iWn�$��4M(�d4��G�p7��.��oB"P@��E���}<���-��e��r�Y�R�] T,�a]��zV���W@�E�T"P�������P(�UJA
��)�������c��zI&~�����6��G��](��p
Ip��&I����f9][K68��:A���M���b�w���aD��v!`����B�t����?�Q���+�$!s�2A�<�������II0�g�X=#>�E��"���I�' ���g�!ch{����g�?@�� .�C���6��G���Z������H*:�"~�� "~:�8k�g}�"������oD�;��r�Q��A��<\J�[.q��
���3 �����JjH���;�����4 ���
� !y|���G)eZB�i�S5k5;���,x�2�'�t O���1[^l4�����|��u�fS/Tp����V_�����a���w���wH =����|��h
ui��g<�r�e9�N\#v�����b��0h����O6� K�i#����d�-M���5����8\$�S*���4���f��4�%�<�w�`4[�4x�8�uS�v��q�#NJ�q�4�EX���
JH��c�P��5<y ��>��g��L������G3�vu '}C�v�teC�"���rEw��lY�dZ�e��FS~�|���C�IGx�g[������~q ��=j7�U���+� ��i��3�m�2D��<�nT%"y-��D7�5�!oC���]�-�c� ���+{K�/H����u�DM�����)�6����n�s����$��mg[e����r��������o1n����yG^��U\�)�ncG�s���J
��o�
������;'6����%�����b!�C���>�a y9�C#���=W=����;<��Q@�t���_���0��C��]��*���mB��C�S �wx?Dx��VA�+pz�sD��q&p�_�]\���_�^�//�������ie�/��\�L���o�Z�c)D iM���a�noVa>|�x����Hs�UeM�D����Z�;;��������,��f�FZ{dB�O��2�A��.��E`����s�Q�����>H�P����B��A2&nD3L#y�O��1��6��� B4G�Y@�xM�^����$�w���k��_��"�� ZH���6�n��R��p����}G����%�o{~�}�����/W(�b�[G���Q&��L!;�*�n��#v^����;d�2��A��7]A]������7�;�����t�P���&Ed�E\���<�����L�E?��%{A�{��,����W��PY]�</V&�oW�*�E��xb���v�������g�����sb�],������
u_)�.��x )U��0��r)�w?�����u���jG��`���bH��[�-��Je�����?�"Ir$5
3��0�
e>�p�e:�MDH[s2>"K�L���X�z�^J�hxp��8 N��=���� �1 wD}\%���R��vfX��n&T}K�:
�����
�s��w�V\��3�T�
�Gh�E��5�y
h�~��_6��?���
����Y�/�)�p������3�P�
H:�A��\�w���*"���Tl�U�$�P���`r��sCb��������pc�����]@v�}��3��#\{&s������m�O@��(��3* �k�HM����}���K>��"�xH�
L��)nX%��xb�!�x���K�Ub����}�\!���i+;/L)m�8�q�G��?��jj��Q�WJy��z^��ek��g�ao�}m�%z�N�y���d�W���s����w��_B���i�b}:�����
7A�K:��D�6����_k�l��}��7�(����
�@�Fg���� �?/�Y�;!v�G`���������/���^uZ�����z!R�1�������k^4�Al`��pN��c�� n��MP1����[�8d2�����"eh�l���Je�����������-��A�OC�2��,[8�SQe����e�I��p��_���}�Gey�{�7�`Ey������-,�g��J{W&������+��������a��D�*�m`x��_H������#�6�u� ����������$�0O}i����bp~y= ��x��7�2�kM��b�s��R�E��U��&�������N�m�X���
���
��7I<����SR����(���;3PbQ:_�����{�7��������3K��)��\!��(j��V�2�y�ho"5J9�Hsi��ql��*A�u4���D����h�1�KOd�XLsdZ���[u�:�a�,�������E��������n��yYg���$�����������.���9_:�*d:#��C����8K�Y'��V�b��tA������ZV@*�@3���h33�I=�d���gxj������� f���WiH��#��c�2�&f��6V�+W4cC+�������a
V��r����������,�H�*���A�
�3���j%!���;������)5ffPh�K�j��&
��oj�����6�����+:lv-��u����Q@Nx���$�>{t�4����$c����u��L�4�8y�'A�tO_�������$���e����Nt/�n��>�'�8����UKL&��mc��������c8�}EV����F9P2�"y�H�������@�Y!��5��$+S�\���t�����T�������Rd�}�����$��k��e]�1�U����F�����i��"=o#�����
���������2IP(�X�Wb>�T����J����KX
H������?�6���!�?�����Bi
�_+���~"+���f)��9v� �c8y��������5a�3����lh�yZ�����}���{t3YW�X�f��2�������q�z�b��C�Z$u�
-�6qb��zJff�Z��� d�S��M�6c�r�,���b���������k��N���2_R8
�|���uSm��*����Bet��G�������h�vR@���u���(U�}�>5��W��.30�i�n��)�����~�����e[�:u^���89��1��Lf�W���6��Q�:��`r� �N�TRx��+����\�S����I ��l��O��^�le����m������SB�����"S�=5���f��V�@;�>�3���K3Q�����7�nn������G��V���z%��>��� �gc
>�0e�k�imn ���1 xT{�j�������}8
�g:�������O.qd��H���!X��~�5Sq�]�(�i����H������bu�vj?d��� �:��������������>���5k����'���`�s���$���^4��$�[
IYWj��bsI-��6�\�+���*9����j�a��&��G�����}�^#�K�uq����.��K������#v�NYy�N���X1����R��+��f���DTyM&�#���:��8��b�~r3O��'�?v�O��������}}�+�R�X�����i�[�W��M@����VAs����5>�R���v�v�'�v���AwN*=/�Re���)����PT;Bb:ET��E�o�4���a��n���Rs���~0��l���3%f����]���]�Y0S����E���0D����,�j��+�=���IK��]�
)�=�@����^�q��MgH�[=nJ����a�A-N�v�`
�C�i0��d��;��pa��[ Q��\��C/OB��{p�J���EQW��C�EW��p~_u1���_����Z�d{�c����0 vD�^4$��C(d����u�Sp�*"&Y���mH�'H�hd�w���������R�$��g���3����p���0*5�M��3�r�B���&������B��K�>b�TYfy��)����W��y��^�m���+����~���� ��LC#���X�j v� �%x�hdn�!f�8����S?�PR�d�G=d�,���rgD/~G�� =�v�����0�|�
'�(��f:����V�=)hid�K�z��vn�
��<w�?� �l�bYz���@�����U�E��_�� �ojun����dD�44$[4"�x������8�Vm8�1Rr�����h1�z�5��`�/,c>�u���s��^�a�����}�� �O�U������X�
����{6��R����mTa\2��oU����U�{�e�r�iT����R:���P.cS'�)<��r&��1EJ������v����������Y{�y�����JR�w��H�w�X}��lT�f�Z�f�4�M�<M�s���8�j���`M�J����1����:a�c�>dK�zX�F���(�1R.�9����Y<_�4����ds~��12�Q�=o����u����/���QC����[��%�-6��@l������Or�S��R�|���~j��8R���� �j�+Keb���R��R�f�K�&<��y�9<�D�t
\>��H��%�j��� ���A�����\���z1�v�g;��|�|@,�;|�g>@2jJs~�dr����_�K�!�Tv������#+�sF���GdH��x~~��?l�*$��t���g �e2n�
���}��?���~�� r�*R�]���k����0�ES�S<�%�R"�T�b��@��h����R�|��e&��H�l���
_����j��J:H�o ��FP��!�~�3��N����&C����Y�i��^H�|��i�����L2aleN�o���m}����F�W�n3�$���yymX����'���3<A�#�:9*����H^#5��99�1���[EK�l��A������eT�19z��`���������������xF.�������eB���@��3�|��k�e��T���:%�����i���lRR���%s�+�%�T������o�hY#�(
c�����@WK�Q��9� }d��m,�,x���.��{��6t�����7m ��������H�K�����x��Js�������:�FE�<�����.KHS�gf�0������s��q+�pb�
YB�C����#S rJ�����@D4T����u�����-����n�qG�]��m�\2@)`$�</�����{rWl-
M���i�/*z�~o��,*��H>(/�D��5)Q��^(���k�2�
.��\3�k|i==aGt���
��{�5����x�� G���fx����di��4O�5
/��"�p���� v�L����%l��`J�^K�/y&n��5�M,5�Z����+��]FI���6��@����|H������k.�q�D[����TR�_��1y�� �B5�
$�h��d
hP���+_���
�~>�T,�H\,�N��Q2b����[� ��v�����d+���R.2���C�=������/`mo^��������\�bFe����VB|���w�C� ��YA��MT�������=���b+�9?,NF�@����B!��Q+�G�����x*��C�"����T:��r�<Wa������?��.�%�A�����~�`��a�9;�sY]����a�GI��F�`Uf���t���?)t����`���Z95��\��$�l##��u���r�^l fa(�>����Pt��b*���`��g>c( ���'G��c�l�+(��Q���-���K|x� Bj�����e�5�^E��_*)��~0����nk��V�[9���SHI�n�D�}�)��0Td���^��B���(����P�J�A���l< g����,f�`\BEz
��@$���n(m.�ZA���7 �]�RP����?) �}��5���}!�C�z��������A��ej���u�]��rs��oa�0�T�XQ��]��YO��J��*(�|B��D�h����:c��@���[C-V���7U�G��a(�Z��WKE��Q��hH�e����������M�Q�?�������Xo�t ����)��lu ��z�"�1�[~[��i����j0��b1dd s���s��*xG)�G����C�WSV��snY�5�{
MC$OP�.
�
�=��vpe�I����E���I����u^50�����k�q�Cw��j�.|�����r|"�+�RT��F/�!���Q���Z��+G 4���e��x��.�[���`����cGhD�DHM��Z����o�X��5F��:&����f�Otiw���7��� q0���l8�2��'tnZ�����R�~x�E�f��e�Du��^�
����(��l������*������Y)����\��@:,W������S��S�7I(�Y�� �,d�$Tx���X^����n/��Py<�l�&��c�Ys���_ {������V�����8�
���-9#[�P����5�
� d]�{g�A����m:s���YE'q����C����"xUW{��)���Y=Yf3`�n�M� ��qLI�T�.��>�W�9LF��"����9_F�0�3��.����{v'�Lk���-���
z ��l�� ��HK���G��;�<�����fn5�)V�L$��#�S�Km�.�a�����������$�'a7��p�_����HKN.�R�N*������
���
�
�tSW����G���g��t�FZ$���D����?Nabng�T:�h2EL��}uQ��>��R*O�����V����u���\=�h���w�a&o)^2��@�1�"��~ ��z�����pJ{ g��y:Px
D�i7������4���(��7�u�G�P)��c��h�l��@f�G�Rr5N�;�H/��AoF'{�!���+�*']��qH������p���2]1���pH��p��$[� !�mF�Lb���T(��t�E,T�����\�ek� �9����t4�M v��3����o{����������f9R��M�)���o�b���l��vdE���!d!��?����z?e��-��\j��<%C#Q �h��?`oE>������D�Z���+g�/`
<!��K�l;��@hw�fQX��6*9Icx^ �$S���W�\� -3l���<�\F�3�r.g�A
"�Y7��qE&� �0��-��pYu�����~�,���[��~I�|�Vz�����1�)�^�����J(�*�*�����>u0�!E".��_�K@uF���������/W��\m�{�
<�����)�ig�lA�}[��!GZ�B� &I1�����H��� �D�cZ: zz�e(@�eRB�*r0�"��T_���aa�P�����l`���BYb����@;�N�0��RL�"���R�:7V�@��j�VI��^�8�3$��8x�(/����G�q�!Ym1�
�}��G\1���:^�V�J�{�|�^���n���O��T�|W'u����H�h���1�[R���/�-1R���l��� �S_������/��������"J� z`�K@�Z8������t2{�72��a`I_�a��P����;��� ���Y�����l��=����/����n#@�yO���`A��v���+i ����;�����r�|W��%�J)2?�J���e����
��:�.�d�V��=%�q����n��?� ����.�w�L9<~@�W�����kQ<�-�%�-�!
��������T���J���TO���2��]�,�R�}dZCd�+�uG�b���f�����;)a�d�@)���I�F1(7lK�f%������,D��].����9�M�ir ��6Y4��$���)�mk��*���6�3�9���a����0�.���N��1�����G���� I��o(�%
��t�/e�7������nPQZR�ws���M�UM���(��yu�+ ��"���m�6��Y�^&�
�[
+Q��zE���3�y5,{�9��.�S[��+A����:�� �vX�K��w�����}h��Z���0�?m;�
:XV+�d4
MM<Rb&�Y_So5��bfw�������F1�;,��r�8Y�]/s�tVS�D:S�1"�yO�hTD��T�1\4Q��`HT�!{$�P�)j*;;��^(�UR��v���K1����k5�%�@!A:�C��%�������A���D
�s�z��zw���7�H5����2������X�xH����5 %k������,8���������������w5����3R�X��}<�����o�>DF[v�b�nw��{S\�2� ��������6�R{���n��[�eLl�HmW��sZK�$�5��x���j�p�>��� eH#���C��U�[7![�B�i_|{rp�����R ����.��sS:�G�L�et�ZU����p�������d��f��m*}�Z3k�����78Xt���������4�2)��z>��S��`e���,�F�����{�qd��;�z��0�u1>��n�l+Y��z��[�n�1L��z��aXZ}����h���t������v�8��P��j������1���F����v>�]x;����2�(#��X���w�`*�{���*KQ�T������M�&?2o��"y#��|�y@=&~�>�J�5�>�u�c�D������"� i���?H��`rA lVE�i]|�1 a�W������%-�*�JP���T�A�u�|`5I����������Bd��Xc����D�D?)�)�Q����7=� �l0��+=������_��������3��nx�,���T���L�[��;'�Y�
�p�F��\��5BD��Y���_[����V
�L��O�D���j�N�\<��)��F p�X���F�N��xF� �t�HTX�0�Cf���I�^�0�W!���R�}GC�������;�S������(61�F��H��j�������,�w�Q�A���v4 ���E�q�PR�����>��Oj�������ZP� �� F��]���m}��%.J��m>�#��o�Q��::����4�������:���9*3�~�g��7$�&�����F>���2�]qF�!�A"*��LQ��g0E��ob��pE0X���9���)�j�9��^M�e�c/�v�����y;W�#��7�O���#X��0G���C�gx#9�����q�rZ!e����s�^�*��!!�s���vJQ�6�=������P��T���d%T���Q�H{����,�8����oC����U����Xn����6�8���&d�Z#>~�N�F!��9G1����E�i$���D�k[`kS^8����/��9������J�W��d�;�'��E������������D�Y�t�)���bi�X�g�Vk�zU��h�'\��.�K���~2�u�|�����1"�y�&��W�Mp������.���4�� ����i �ZR[7��m��a��Hx`2�/|/�.�E��*�}gI�G�����W0�5����� �A���P��-��AI�{O�)�X���%��:"=�#�&G^�NI&,8�|��kR����-�B���l�3����v�R��!#�/���
%�~01o�w��*��X�CS�Ls
l�tG������X|&�F�u���0�����c�����:�U������Qa��
������l���B�9$�w����>��������x~P����0��X�kN����*���+�|[h#�wd�Vr��&r���^��W{$'�l�!�Z d��94<q�Lk����I<VQ�����^�06�a�uER)���D,!4�����-1ZdP�w�R��|��
��`�2s��W|@p.��@�RS��������z�������{%��,@��A�)�,���p8���_�����_��H\��[� ��X� |���/������7������\�{_��u�?��t1�?t�ts���N�0���L��O���m~#�[q�4)�&5�� �i���� �
>6��e�D}��w�
|�(VlE�-����x{z��h���������������!i*�����d�S���HQ���H�j2��n��V<�n���;R�WcL��������:y6�>��e2��B��������M�r
4m�����
D�
u�%�������X��:�n��^�Re�h�]T"�u��5��l�
�p��Sh�v��-e^��s���N��Mm^�o'��
�m/�\� �Ip�Gwp8�*i�^_����������������b�p��{�[���� ��h�#�N�������pr+u�7���rd��WI�������5h_������6%������
$�@$����:
����dz.��[�2|���M5��-(�9/!�M�C�d�)������(��V8�@X�L�}�@AeH����`��L����u3@����c�'�G��*��9��N���!���F�i�dE����F�E����E����%>�e���zSH�$0��a�[���EQkI�O����Xdzj�b�s�{$@��c�nuG�POjP�[��>e>�������`�T�oR�F#�4����]x�Y�����`��Z�G��-��9���8OM\��;�J|�v�nS&���p�Y��+�R�G��3:���C@=�@��#��e)��j�z����^��h�\
^M�����a���W��$�)�U����j%��J������'mfj)v��?G������c��m{�;�|�>k�������A��7K���S�
/�������M����������p�����{�:����}�G����7�v���;n���o�� �vrt�uGt�=�����d�[���'p��s��|`}q�n���'�0�s/~�C8o�(
��6�g�����Gc?o�c� ��y�����fNQ�1��6,�"?du@�<0���b0���������G�zy�h���M��Q8
��<6T��5�Y�6 ���e9�k�T��$�H�������/K��G����t�A��7)5P~�N�G���;n$2�����e5��@8J����=l*LO�1��f����M%�l���3�=�����J����1���_����0n��=��9���n����%���"�����[b����qJ'�eI������g��
Q��
�!����Blz���Z�j�MO9�<;�s�e�5�2��k6��r �j
h�����BP���Jv����u|~�������V���g�E������AX�_O�o�w��C�WPT�;_�}P���)�Z�\8! ���T����C�]�{��O�E{�
/�������y[0�%������3������V�{W��"ME|}�\�M�u/������d`�
A�������@y��H�p'�WAc"D���
��B�Jo�g��y-�f��'=������oeOz�&�/�-�����d������Ne7t�h�B��vm�����* ���N������:���
�WHw*4�8TA�3�lJ(\� ��jA����"��:S5k>�GFv+�r ,S��j�����%��g}'a��&�OQk�����>�SI��#����k�8������~���������}~
�#��-��^��������yr������$M��)�U�#���?6��u�]����]����}3������� �G)����Z��[*'4�2��R����yT��2!���_�=�\���v�8���>�xu|�p�������H����������i�������`������ ����k%8=���������y3}�4��cY0y�N0X*1�u�h���?�nw�8G���C2~$u�v*�M%��+D]BG��a���R�2��|�]��Yi��Hk���������e5}��R4���s���h��\�8`.�UA6�M��C���������d���7U��J>�J�T���>(����n�aw��n0�'GT�u�k����c�+�A=��t���1j������aN���68�����2qu>�������
��D�t���t��om�h�����\�0v+4J�5��YB���[��
zP��m=p���#���!���ie����n��3QR���a!cRP�����:���L
��ASIh�CE@�=�����&��m��&�6Vh�f'����7�eu�4�4N�*�P**��O}��H��I���o�������efq�u�d2
��X~��1A����V���v����b�?��F9�������$[����r5��U�� �<��2��e��@�X�*h-��
��[~���dj���;9!�m�M@����8�s$b+AT�I�9>v"\�k�d��u�X��^�uc��Nft�������ix��J�{sff����cM�X���:s�h��
w��*���vn����\7�^���E�����!�=�r�M����w�`;$���8+���w�Ed�fl����u��q�z�0?�b�!��/ �17Y$��[��_��h����&���K�JO���Rs�-j@���G���U��� �\�x�Q�V��z�ua-"��gQ���,�CzO!RP��a��o�H��5
��������-��u��'�54L������8*^�93{����Y�����k[=:@�q���8r�)����R�����G�^z���V}� �$'�(�sk$�K�f1�/����HO:�jh����to hJ��sD��htX3��y�q1�m
eneKM��Q �����E5�;@�m�M�O
�;�
O���=T{M�`��0i�D��CL��E}8���������$�^l�htBAG��&��1�L��1~.4sm��\������&z��mi��jn��I��sDlZZ�h�Ll��y��gR a.G`J��i�C�q������;���z|��9�HU����&+�U�`zO�/8��R�N+@���H���T e���Lv�h�$l�
�d��(�\2�t�E��b���,�����7@W��-K��;=/E������C��\d��@N��55/����G�?N��M��$0��F������ 8���h1@�d'�(��JE�^�z���j�T��6�V���n2VEdM��u�^\Tl�X[w
o���Q�@��iq{�U \��[�u?����tm~ps=]�eqm�G������pG�X_�~D+��P����4�l�����wQmu/�_� ���Ft��$0����3�aH7�0l�@p�����+����k�����0�ti���#�no�>fbB�m�`8 A40�dB��D������� �|���mlbG`��ud0xo�A,�;� �pG�+��{X��Z�s�
"��)'��f�tlZ�������p3������F6��U��+��"������m�}��(�F$�.|FI�� �j
0��[�R/9y�a������k�7��vD��
S�����b8�,e2�2]0q3J�mKw$�����S��1� �������r0�A9lM9l��ku1��|c�C����.��>�zp5 j���A,�����?~ �q�{�r�[���#Zht&�����]��u��r�C7�b�����}�� �o���7��6����^${�-hO�2�����+O��;�.`�^�T����m�?Y��v%�^9�j�@�'�!��Nv2mHE�����y5NY����~7�� Oe���G���Ql
��Vz���\��"u��c*���+F�\���H���H5����a��~��EsqV$��y��d@����&W���%����b�'g2��h4L���mp{lK��� �J�eU��l�!m��)Y�v�����X�+Q{dPS��,B���0TY�*��
g�n��%���6���.B����*����1�7@7sS���5��;��nQ�x���Sx*(v*�N�������zzc+UL�";`"�Ic�m8�~M��5���i<� T�'�������������#�f��d��=Fi� A�'�� _H��Rm�}������S���)tD���!���$����&pR� �m�4��&���BF��t����/.�gP%4���������)��/H��9��!<x ��?=P��LGA���,)����v��Ec��p��/�7�#������r!��A4/��M����;������rMA�M!�S�D��(�|� ����@���>�5h���4���� �Z�G5Z-���{���!�y.��x�[�m��%�Ow�0�����F�+�Ju����N:DA����f{U�����5�u��D�!��2.�6�����N1�/^��#JV�������6#���u���H|3�.A�?AT����*(T����}��v�;�m {aJ��>�'@���kF�m��/_�S�P5�/���4�Wi��Z����$yc������M�wo�����;���4�l|��P���J���/S-����%��FjT��%s��-C���e�����!�\�2dVP��l[��J2�L�� <%�+\�BXX �F�U�x�(?��)!�����Z����M��~?D�vGe'����:�nM$
�ZQ�����1�{
��]^'�\|�>���^*
9ll0f�.A�xcd�w�����!����^yYAg��e|����M,��������.t`�%�������i�yH�&�}���%�LYL���"G@�0�fq*8�Nd��p�iP�n�B���xt���L� ������C��/��#��L��\�+}r5�=�p�4��z<t���r����U
���O���� 2� ��:����C��I�{�jOO���F<�p���^�����t���GRZ%-2���]�L���iR9E������J���� U���R�b�����������K��"PH�L��d��]/�!�i���o�2�
��O.�����&�'\���'�w\����2'�[�5��O��1![��5��2sJ�^{a]������E$���_x{��=�� |�V0�bs�>�y5O����~X��/��,H���N
�o�����
5{�f������h����������]�4L@jsJ;k_ �E$��2��-�4�����S!�6](�Xl��r�lZ��HU>��E���F�� #�
0�,WUN��1�����n�-�FB�!�����}8�&WJ�����UR�C���Nt��5e��4����eX���8�4�jq�Eb<���h�_q;2fL)e+��2y�����jx�!��7�Hs���sA��<f�
�}I�Q+��M����;n���a�mSag�e�Ll�Dg���}{=�L��w�?���!�,d~X3q����!��;�� �O/�����-��V)���D~����b�B[�\8���l�����9�>u������L��<)��H6���D_I�gB~^_��[}%��3����%6Pq���f���
E/S/��/����;}�����%o$�*ra�����b���m�!�=���2of��@K+��_ {>