Re: No-rewrite timestamp<->timestamptz conversions - Mailing list pgsql-hackers
From | Noah Misch |
---|---|
Subject | Re: No-rewrite timestamp<->timestamptz conversions |
Date | |
Msg-id | 20190226172909.GA1655734@rfd.leadboat.com Whole thread Raw |
In response to | Re: No-rewrite timestamp<->timestamptz conversions (Tom Lane <tgl@sss.pgh.pa.us>) |
Responses |
Re: No-rewrite timestamp<->timestamptz conversions
|
List | pgsql-hackers |
On Tue, Feb 26, 2019 at 10:46:29AM -0500, Tom Lane wrote: > Noah Misch <noah@leadboat.com> writes: > > Stepping back a bit, commit b8a18ad didn't provide a great UI. I doubt folks > > write queries this way spontaneously; to do so, they would have needed to > > learn that such syntax enables this optimization. If I'm going to do > > something more invasive, it should optimize the idiomatic "alter table t alter > > timestamptzcol type timestamp". One could do that with a facility like > > SupportRequestSimplify except permitted to consider STABLE facts. I suppose I > > could add a volatility field to SupportRequestSimplify. So far, I can't think > > of a second use case for such a facility, so instead I think > > ATColumnChangeRequiresRewrite() should have a hard-wired call for > > F_TIMESTAMPTZ_TIMESTAMP and F_TIMESTAMP_TIMESTAMPTZ. Patch attached. If we > > find more applications of this concept, it shouldn't be hard to migrate this > > logic into SupportRequestSimplify. Does anyone think that's better to do from > > the start? > > It'd be nice to get the SupportRequestSimplify API correct from the first > release, so if there's even a slightly plausible reason for it to support > this, I'd be inclined to err in the direction of doing so. On the other > hand, if we really can't think of another use-case then a hard-wired fix > might be the best way. Is it problematic to add a volatility field later? Older support functions will have needed to assume IMMUTABLE, and a simplification valid for IMMUTABLE is valid for all volatility levels. Still, yes, it would be nice to have from the start if we will indeed need it. > One thing that we'd have to nail down a bit harder, if we're to add > something to the SupportRequestSimplify API, is exactly what the semantics > of the weaker check should be. The notion of "stable" has always been a > bit squishy, in that it's not totally clear what span of time stability > of the function result is being promised over. In the case at hand, for > instance, is it really impossible for the timezone GUC to change during > the execution of the ALTER TABLE command? You could probably break that > if you tried hard enough, though it seems unlikely that anyone would do so > accidentally. No, one certainly can change a GUC during ALTER TABLE execution. The STABLE marking on current_setting is a fiction. I interpret that fiction as a signal that a query has undefined behavior if you change GUCs mid-query, which seems like a prudent level of effort toward such queries. Adding a volatility field to SupportRequestSimplify does invite C-language extension code to participate in deciding this undefined behavior, which would make it harder to verify that we like the undefined behavior of the moment (e.g. doesn't crash). Perhaps best not to overturn that rock?
pgsql-hackers by date: