Re: Partitionin with check functions - Mailing list pgsql-admin

From Tom Lane
Subject Re: Partitionin with check functions
Date
Msg-id 2499.1238420859@sss.pgh.pa.us
Whole thread Raw
In response to Partitionin with check functions  (fatih ozturk <ozturkfa@yahoo.com>)
List pgsql-admin
fatih ozturk <ozturkfa@yahoo.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

pgsql-admin by date:

Previous
From: fatih ozturk
Date:
Subject: Partitionin with check functions
Next
From: Harald Fuchs
Date:
Subject: Re: Partitionin with check functions