Re: BUG #18399: Query plan optimization results in runtime error when hoisting cast from inside subquery - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #18399: Query plan optimization results in runtime error when hoisting cast from inside subquery
Date
Msg-id 4085750.1710895021@sss.pgh.pa.us
Whole thread Raw
In response to BUG #18399: Query plan optimization results in runtime error when hoisting cast from inside subquery  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18399: Query plan optimization results in runtime error when hoisting cast from inside subquery
List pgsql-bugs
Sawyer Knoblich <scknoblich@gmail.com> writes:
> To make sure I'm understanding correctly, are you suggesting that this is
> not a bug? The mention of "the cast to integer is presumed to be
> side-effect-free, which isn't true if you're working with data where it
> could throw errors" to me heavily implies that this is a faulty assumption
> on behalf of the optimizer about what behaviors certain parts of the query
> may have, but I didn't get the impression that this is being considered an
> optimizer bug and is instead something that just needs to be worked around
> or avoided (although if I'm not interpreting it right then definitely
> please correct me).

It is not an optimizer bug: the optimizer is doing what the function
marking entitles it to.  You could argue that it's a marking bug and
no function/operator that can throw an error should be marked stable
or immutable, because throwing an error is a kind of side-effect.
But that would be a pretty useless answer, as it would nearly destroy
our ability to optimize queries at all, since there's not all that
many functions that can be guaranteed not to throw errors.

In short, this state of affairs is an engineering compromise.
It's not perfect, but it's not easy to see how to do better either.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Carl Smith
Date:
Subject: Re: BUG #18392: Can't restore database (using pg_restore) after latest Feb 8 update
Next
From: Thomas Munro
Date:
Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded