pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Jeremy Finzel <finzelj@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Primary key gist index?
Date: Wed, 14 Mar 2018 11:45:39 -0700
Message-ID: <abe5f8e1-1cea-5f01-b35e-b7f022097ed3@aklaver.com> (raw)
In-Reply-To: <CAMa1XUgaP-pjB+CydfnzJrRR18DoC+bSBEYOC8u37WGP7YYB2Q@mail.gmail.com>
References: <CAMa1XUiQDM2n5EHPir_ECoTjdA=kEDu1u_p=zMUxzdkkJpgmhw@mail.gmail.com>
	<bcb9d38a-861a-cb89-97c7-3c606b43b5a7@aklaver.com>
	<CAMa1XUgaP-pjB+CydfnzJrRR18DoC+bSBEYOC8u37WGP7YYB2Q@mail.gmail.com>

On 03/14/2018 11:10 AM, Jeremy Finzel wrote:
> 
> On Wed, Mar 14, 2018 at 8:33 AM, Adrian Klaver 
> <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     On 03/14/2018 06:19 AM, Jeremy Finzel wrote:
> 
>         Hello!  From all that I can tell, it is not possible using a
>         btree_gist index as a primary key.  If so, why not?  I have a
>         table with this gist
> 
> 
>     https://www.postgresql.org/docs/10/static/btree-gist.html
>     <https://www.postgresql.org/docs/10/static/btree-gist.html;
> 
>     "In general, these operator classes will not outperform the
>     equivalent standard B-tree index methods, and they lack one major
>     feature of the standard B-tree code: the ability to enforce uniqueness."
> 
> 
>         index which truly ought to be its primary key.  as_of_date is of
>         range date type:
> 
>         EXCLUDE USING gist (id WITH =, as_of_date WITH &&)
> 
>         Any direction here would be much appreciated.
> 
>         Right now, I am forced to create a redundant btree index UNIQUE,
>         btree (id, lower(as_of_date)) in order to have a primary key on
>         the table.
> 
>         Thanks!
>         Jeremy
> 
> 
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 
> 
> Thank you for the ref.  But I don't understand how an exclusion 
> constraint does not have "the ability to enforce uniqueness" unless they 
> just mean that is the case "under the covers of postgres".  That is 
> exactly what it does, right?  By the definition of the exclusion index I 
> have above, there cannot be more than one row with the same id and 
> as_of_date values.

https://www.postgresql.org/docs/10/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE

"The EXCLUDE clause defines an exclusion constraint, which guarantees 
that if any two rows are compared on the specified column(s) or 
expression(s) using the specified operator(s), not all of these 
comparisons will return TRUE. If all of the specified operators test for 
equality, this is equivalent to a UNIQUE constraint, although an 
ordinary unique constraint will be faster. ..."

I have always taken the above to mean that while is possible to create 
an EXCLUDE that enforces uniqueness that operation is internal to the 
EXCLUDE and is not knowable to Postgres when it is looking for a UNIQUE 
index. Probably because an EXCLUDE can be non-unique.


> 
> Thanks,
> Jeremy


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (9+ messages)  latest in thread

Message-ID: <abe5f8e1-1cea-5f01-b35e-b7f022097ed3@aklaver.com>
Permalink:  ../abe5f8e1-1cea-5f01-b35e-b7f022097ed3@aklaver.com/
Also on:    postgresql.org/message-id/abe5f8e1-1cea-5f01-b35e-b7f022097ed3@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, finzelj@gmail.com
  Subject: Re: Primary key gist index?
  In-Reply-To: <abe5f8e1-1cea-5f01-b35e-b7f022097ed3@aklaver.com>
  References: <CAMa1XUiQDM2n5EHPir_ECoTjdA=kEDu1u_p=zMUxzdkkJpgmhw@mail.gmail.com> <bcb9d38a-861a-cb89-97c7-3c606b43b5a7@aklaver.com> <CAMa1XUgaP-pjB+CydfnzJrRR18DoC+bSBEYOC8u37WGP7YYB2Q@mail.gmail.com> <abe5f8e1-1cea-5f01-b35e-b7f022097ed3@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox