Re: Second RewriteQuery complains about first RewriteQuery in edge case - Mailing list pgsql-hackers

From Bernice Southey
Subject Re: Second RewriteQuery complains about first RewriteQuery in edge case
Date
Msg-id CAEDh4nw07=pbTbxe6XsBFzxnS1_DswiUC3znCF5PiTeVKo_a3g@mail.gmail.com
Whole thread Raw
In response to Re: Second RewriteQuery complains about first RewriteQuery in edge case  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: Second RewriteQuery complains about first RewriteQuery in edge case
List pgsql-hackers
Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> Yes, I think that would work, but I think a simpler solution would be
> to just have RewriteQuery() track which CTEs it had already rewritten,
> which can be done just by passing around a list of CTE names.
> Something like the attached.
I was playing around with an idea I had based on my first attempt to
fix this, when I got your email.

FWIW, I think I found a way to fix my bug that doesn't break your
rules example. I added a bool to RewriteQuery, and used this to stop
reprocessing updatable view CTEs. This leaves the rules recursion path
unchanged. Which means rule CTEs might still be processed repeatedly.
But as they probably can't be data-modifiable, I think
rewriteTargetListIU is effectively idempotent? The advantage of your
approach is it's consistent for all views, and it doesn't rely on
improbable data-modifiability for idempotency. Plus I'm still very
uncertain if there's more traps in rules I'm unaware of.

I also took another look at rewriteTargetListIU. From what I can make
out, stored generated columns rely on SetToDefault for idempotency.
But identity can't use this, so this is why a change to querytree
could be needed?

Thanks, Bernice

Attachment

pgsql-hackers by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: System views for versions reporting
Next
From: Fujii Masao
Date:
Subject: Re: CREATE/ALTER PUBLICATION improvements for syntax synopsis