small exclusion constraints patch

Lists: pgsql-hackers
From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: small exclusion constraints patch
Date: 2010-05-21 19:03:40
Message-ID: 1274468620.16366.3.camel@jdavis-laptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Currently, the check for exclusion constraints performs a sanity check
that's slightly too strict -- it assumes that a tuple will conflict with
itself. That is not always the case: the operator might be "<>", in
which case it's perfectly valid for the search for conflicts to not find
itself.

This patch simply removes that sanity check, and leaves a comment in
place.

Regards,
Jeff Davis

Attachment Content-Type Size
allow-exclude-ne.patch text/x-patch 1.0 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-21 19:24:35
Message-ID: 22686.1274469875@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jeff Davis <pgsql(at)j-davis(dot)com> writes:
> Currently, the check for exclusion constraints performs a sanity check
> that's slightly too strict -- it assumes that a tuple will conflict with
> itself. That is not always the case: the operator might be "<>", in
> which case it's perfectly valid for the search for conflicts to not find
> itself.

> This patch simply removes that sanity check, and leaves a comment in
> place.

I'm a bit uncomfortable with removing the sanity check; it seems like a
good thing to have, especially since this code hasn't even made it out
of beta yet. AFAIK the "<>" case is purely hypothetical, because we
have no index opclasses supporting such an operator, no? How about just
documenting that we'd need to remove the sanity check if we ever did add
support for such a case?

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-29 02:32:26
Message-ID: 201005290232.o4T2WQP10963@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Jeff Davis <pgsql(at)j-davis(dot)com> writes:
> > Currently, the check for exclusion constraints performs a sanity check
> > that's slightly too strict -- it assumes that a tuple will conflict with
> > itself. That is not always the case: the operator might be "<>", in
> > which case it's perfectly valid for the search for conflicts to not find
> > itself.
>
> > This patch simply removes that sanity check, and leaves a comment in
> > place.
>
> I'm a bit uncomfortable with removing the sanity check; it seems like a
> good thing to have, especially since this code hasn't even made it out
> of beta yet. AFAIK the "<>" case is purely hypothetical, because we
> have no index opclasses supporting such an operator, no? How about just
> documenting that we'd need to remove the sanity check if we ever did add
> support for such a case?

Done, with attached, applied patch.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

Attachment Content-Type Size
/rtmp/diff text/x-diff 908 bytes

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-29 21:16:59
Message-ID: AANLkTim3Ual2IPI03jkVTJsq14YTsMIVyLpcZNvGoyad@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, May 28, 2010 at 10:32 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Tom Lane wrote:
>> Jeff Davis <pgsql(at)j-davis(dot)com> writes:
>> > Currently, the check for exclusion constraints performs a sanity check
>> > that's slightly too strict -- it assumes that a tuple will conflict with
>> > itself. That is not always the case: the operator might be "<>", in
>> > which case it's perfectly valid for the search for conflicts to not find
>> > itself.
>>
>> > This patch simply removes that sanity check, and leaves a comment in
>> > place.
>>
>> I'm a bit uncomfortable with removing the sanity check; it seems like a
>> good thing to have, especially since this code hasn't even made it out
>> of beta yet.  AFAIK the "<>" case is purely hypothetical, because we
>> have no index opclasses supporting such an operator, no?  How about just
>> documenting that we'd need to remove the sanity check if we ever did add
>> support for such a case?
>
> Done, with attached, applied patch.

The only disadvantage I see of just documenting this is that someone
might write a user-defined index opclass that works like this, and
they won't be able to use this until at least 9.1 (or at least, not
without patching the source).

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-29 22:11:57
Message-ID: 25064.1275171117@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> The only disadvantage I see of just documenting this is that someone
> might write a user-defined index opclass that works like this, and
> they won't be able to use this until at least 9.1 (or at least, not
> without patching the source).

I don't actually think that anyone's very likely to write a <>-like index
operator. It's approximately useless to use an index for such a query.

Or, to put it differently: if nobody's done that in the past twenty
years, why is it likely to happen before 9.1?

regards, tom lane


From: David Fetter <david(at)fetter(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-29 23:32:48
Message-ID: 20100529233248.GA3615@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, May 29, 2010 at 06:11:57PM -0400, Tom Lane wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> > The only disadvantage I see of just documenting this is that
> > someone might write a user-defined index opclass that works like
> > this, and they won't be able to use this until at least 9.1 (or at
> > least, not without patching the source).
>
> I don't actually think that anyone's very likely to write a <>-like
> index operator. It's approximately useless to use an index for such
> a query.
>
> Or, to put it differently: if nobody's done that in the past twenty
> years, why is it likely to happen before 9.1?

Because there's a fundamentally new way to use them now, namely with
exclusion constraints :)

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-30 02:56:06
Message-ID: AANLkTinhuqAwH2xgNc78YrNYZxk1nxf80RGnjV0gy-Zb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, May 29, 2010 at 6:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> The only disadvantage I see of just documenting this is that someone
>> might write a user-defined index opclass that works like this, and
>> they won't be able to use this until at least 9.1 (or at least, not
>> without patching the source).
>
> I don't actually think that anyone's very likely to write a <>-like index
> operator.  It's approximately useless to use an index for such a query.
>
> Or, to put it differently: if nobody's done that in the past twenty
> years, why is it likely to happen before 9.1?

Hmm. Well suppose we bet a dollar on whether that will happen or not.
In fact, if you promise not to read
http://archives.postgresql.org/pgsql-hackers/2010-05/msg01175.php I'll
make it two dollars.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-30 03:40:46
Message-ID: 28529.1275190846@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Sat, May 29, 2010 at 6:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Or, to put it differently: if nobody's done that in the past twenty
>> years, why is it likely to happen before 9.1?

> Hmm. Well suppose we bet a dollar on whether that will happen or not.
> In fact, if you promise not to read
> http://archives.postgresql.org/pgsql-hackers/2010-05/msg01175.php I'll
> make it two dollars.

Yes, I've seen Jeff's example. It's a cute hack but somehow I doubt
that there is going to be a land rush to implement such things.
Can you point to any pre-existing example where anyone actually asked
for the ability to do that?

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-30 03:55:02
Message-ID: AANLkTim7B8Y4SuG3IngLCKw0ZvvUVavTESePwy_695pU@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, May 29, 2010 at 11:40 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Sat, May 29, 2010 at 6:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Or, to put it differently: if nobody's done that in the past twenty
>>> years, why is it likely to happen before 9.1?
>
>> Hmm.  Well suppose we bet a dollar on whether that will happen or not.
>>  In fact, if you promise not to read
>> http://archives.postgresql.org/pgsql-hackers/2010-05/msg01175.php I'll
>> make it two dollars.
>
> Yes, I've seen Jeff's example.  It's a cute hack but somehow I doubt
> that there is going to be a land rush to implement such things.
> Can you point to any pre-existing example where anyone actually asked
> for the ability to do that?

I've often wished for the ability to constrain a tale to hold just one
row, so I don't find that use case implausible at all. As to whether
Jeff's use case is a cute hack or something that people will really
want to do, I think the jury's still out on that one. But I don't
think we should make it not work unless we have a concrete reason, and
I haven't heard one yet.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


From: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-30 10:54:17
Message-ID: 4C0243D9.9070202@cs.helsinki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2010-05-30 06:55 +0300, Robert Haas wrote:
> On Sat, May 29, 2010 at 11:40 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Yes, I've seen Jeff's example. It's a cute hack but somehow I doubt
>> that there is going to be a land rush to implement such things.
>> Can you point to any pre-existing example where anyone actually asked
>> for the ability to do that?
>
> I've often wished for the ability to constrain a tale to hold just one
> row, so I don't find that use case implausible at all.

As I pointed out in
http://archives.postgresql.org/pgsql-hackers/2010-05/msg01177.php , you
can already do that.

Having said that, I also think that supporting <> in exclusion
constraints would be useful. I can't come up with a real-world use case
right now though.

Regards,
Marko Tiikkaja


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-30 14:01:46
Message-ID: 5141.1275228106@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi> writes:
> On 2010-05-30 06:55 +0300, Robert Haas wrote:
>> I've often wished for the ability to constrain a tale to hold just one
>> row, so I don't find that use case implausible at all.

> As I pointed out in
> http://archives.postgresql.org/pgsql-hackers/2010-05/msg01177.php , you
> can already do that.

Yes. This is NOT about constraining a table to hold only one row.
It's about requiring all its rows to hold the same value (in some
column(s)), without predetermining exactly which value that will be.
I think the use-case for that is really extremely narrow.

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>, Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-30 16:56:27
Message-ID: AANLkTikKlaxEGprL1KAn9ounpuIXvThYGwTblSEmEr9T@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, May 30, 2010 at 10:01 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi> writes:
>> On 2010-05-30 06:55 +0300, Robert Haas wrote:
>>> I've often wished for the ability to constrain a tale to hold just one
>>> row, so I don't find that use case implausible at all.
>
>> As I pointed out in
>> http://archives.postgresql.org/pgsql-hackers/2010-05/msg01177.php , you
>> can already do that.
>
> Yes.  This is NOT about constraining a table to hold only one row.
> It's about requiring all its rows to hold the same value (in some
> column(s)), without predetermining exactly which value that will be.
> I think the use-case for that is really extremely narrow.

It probably is pretty narrow. After all, exclusion constraints in
general are something that not everyone needs, and the ordinary use
case of preventing two intervals or regions from overlapping will
doubtless be far more common than this one. Still, I'm not sure how
that's relevant. The fact that not very many people will want to do
something is not a reason to prevent it.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>, Bruce Momjian <bruce(at)momjian(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-05-30 17:33:16
Message-ID: 29732.1275240796@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> ... The fact that not very many people will want to do
> something is not a reason to prevent it.

It's not about preventing it for no reason. The proposed patch removes a
significant sanity check from code that still hasn't gotten out of beta.
I might be willing to remove it in 9.1; I am *not* willing to remove it
from 9.0.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: small exclusion constraints patch
Date: 2010-07-16 00:46:22
Message-ID: 2047.1279241182@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jeff Davis <pgsql(at)j-davis(dot)com> writes:
> Currently, the check for exclusion constraints performs a sanity check
> that's slightly too strict -- it assumes that a tuple will conflict with
> itself. That is not always the case: the operator might be "<>", in
> which case it's perfectly valid for the search for conflicts to not find
> itself.

> This patch simply removes that sanity check, and leaves a comment in
> place.

Applied (for 9.1 only).

regards, tom lane