Re: Partitions not Working as Expected

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sthomas(at)optionshouse(dot)com
Cc: Dave Johansen <davejohansen(at)gmail(dot)com>, bricklen <bricklen(at)gmail(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Partitions not Working as Expected
Date: 2013-06-27 21:44:09
Message-ID: 1303.1372369449@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Shaun Thomas <sthomas(at)optionshouse(dot)com> writes:
> On 06/27/2013 01:42 PM, Tom Lane wrote:
>> That will break things: CURRENT_DATE will then be equivalent to just
>> writing today's date as a literal.

> Interesting. I tested it by creating a view and a table with a default,
> and it always seems to get translated to:
> ('now'::text)::date

Yeah, that is what the parser does with it. The way to read that is
"a constant of type text, containing the string 'now', to which is
applied a run-time coercion to type date". The run-time coercion is
equivalent to (and implemented by) calling text_out then date_in.
If date_in is marked immutable, then the planner will correctly conclude
that it can fold the whole thing to a date constant on sight. Now you
have a plan with a hard-wired value for the current date, which will
begin to give wrong answers after midnight passes. If your usage
pattern is such that no query plan survives across a day boundary,
you might not notice ... but it's still wrong.

> ... What's interesting is that EnterpriseDB has
> their own pg_catalog.current_date function that gets called by the
> CURRENT_DATE keyword.

Yeah, we really ought to do likewise in the community code. But that
doesn't affect the fundamental semantic issue here, which is that you
can't mark the expression immutable without creating incorrect cached
plans.

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Rafael Domiciano 2013-07-01 18:06:34 Re: 9.2.2 - semop hanging
Previous Message Tom Lane 2013-06-27 21:17:55 Re: Partitions not Working as Expected