From: | Mike Mascari <mascarm(at)mascari(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Partial Indices vs. mixing columns and functions |
Date: | 2001-07-11 14:31:19 |
Message-ID: | 3B4C6337.CC8163D4@mascari.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Tom Lane wrote:
>
> Mike Mascari <mascarm(at)mascari(dot)com> writes:
> > To enforce uniqueness because
> > deactive is NULL, I cannot just create an index like:
>
> > CREATE UNIQUE INDEX i_foo (value, deactive);
>
> It's not clear to me what you are really after here. You *can* create a
> unique index, even though 'deactive' is allowed to be NULL --- what will
> happen is that rows containing NULL will never conflict with other
> entries. Is that what you want, or are you trying to say that you don't
> want more than one row with 'deactive' NULL for any given 'value' value?
The latter.
>
> > Or will Martijn van Oosterhout's new Partial Indices work allow me to
> > create a unique index like:
>
> > CREATE UNIQUE INDEX i_foo ON foo(value)
> > WHERE deactive IS NULL;
>
> This would seem to imply that you want the latter.
Yes.
>
> As Martijn remarks elsewhere, the above would not be allowed by the
> existing code for partial indexes. But there is no good reason for
> that. The reason for the restriction is that the planner's code for
> determining whether a partial index can be used in a query is pretty
> limited (with good reason; we don't want to be letting loose a full-tilt
> automated theorem prover on every query...). But the above example
> demonstrates that an index can be useful even if it's never used in
> a query!
>
> I would say that this example shows that we should rip out the
> restrictions on the form of the predicate, and just ensure that the
> planner code will give up cleanly if the predicate is not of a form
> it can handle.
Fantastic! If left in its current state, I would have to use a fake
deactive value (some arbitrary date in the past), or add another column
to enforce uniqueness amongst 'active' records.
>
> regards, tom lane
Thanks,
Mike Mascari
mascarm(at)mascari(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | tamsin | 2001-07-11 14:51:24 | RE: How do system tables relate to other tables in postgresql |
Previous Message | Dave Cramer | 2001-07-11 14:20:29 | Re: [JDBC] JDBC and stored procedures |