Re: [PATCH] Allow multiple recursive self-references

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: Denis Hirn <denis(dot)hirn(at)uni-tuebingen(dot)de>
Cc: vignesh C <vignesh21(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pantelis Theodosiou <ypercube(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Zhihong Yu <zyu(at)yugabyte(dot)com>
Subject: Re: [PATCH] Allow multiple recursive self-references
Date: 2022-01-14 12:21:13
Message-ID: 98d7bb5a-0f01-5b3f-3e06-923492d9a15f@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11.01.22 12:33, Denis Hirn wrote:
>> I have been studying this a bit more. I don't understand your argument here.
>> Why would this query have different semantics than, say
>>
>> WITH RECURSIVE t(n) AS (
>> VALUES (1)
>> UNION ALL
>> VALUES (2)
>> UNION ALL
>> SELECT n+1 FROM t WHERE n < 100
>> ) SELECT * FROM t LIMIT 100;
>>
>> The order of UNION branches shouldn't be semantically relevant.
>
> WITH RECURSIVE (ab)uses the (typically associative and commutative) UNION [ALL] clause,
> and fundamentally changes the semantics – associativity and commutativity no longer apply.
> I think your confusion stems from this ambiguity.

The language in the SQL standard does not support this statement. There
is nothing in there that says that certain branches of the UNION in a
recursive query mean certain things. In fact, it doesn't even require
the query to contain a UNION at all. It just says to iterate on
evaluating the query until a fixed point is reached. I think this
supports my claim that the associativity and commutativity of a UNION in
a recursive query still apply.

This is all very complicated, so I don't claim this to be authoritative,
but I just don't see anything in the spec that supports what you are saying.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Marco Garavello 2022-01-14 12:24:09 Re: autovacuum: change priority of the vacuumed tables
Previous Message Julien Rouhaud 2022-01-14 12:16:53 Re: Partial aggregates pushdown