Re: Partitionin with check functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: fatih ozturk <ozturkfa(at)yahoo(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Partitionin with check functions
Date: 2009-03-30 13:47:39
Message-ID: 2499.1238420859@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

fatih ozturk <ozturkfa(at)yahoo(dot)com> writes:
> My problem in partitioning is about using functions in table check constraints.

By and large, you can't. Per the fine manual:

Keep the partitioning constraints simple, else the planner may not be
able to prove that partitions don't need to be visited. Use simple
equality conditions for list partitioning, or simple range tests for
range partitioning, as illustrated in the preceding examples. A good
rule of thumb is that partitioning constraints should contain only
comparisons of the partitioning column(s) to constants using
B-tree-indexable operators.

In particular, a constraint like "sel=123" is *not* going to lead the
planner to draw any conclusions about the value of "mod(sel,6)".
Now, if you'd written "WHERE mod(sel,6)=3", I think it would draw
the right conclusions.

The underlying issue here is that "a=b" does not imply "f(a)=f(b)"
for all functions f, not even if "=" is known to be a btree equality
operator. Several of PG's standard datatypes have counterexamples,
so the planner *must* take this seriously.

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message toni hernández 2009-03-30 14:39:59 copy command and column attribute
Previous Message fatih ozturk 2009-03-30 08:34:52 Partitionin with check functions