Re: Request: set opclass for generated unique and primary

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Request: set opclass for generated unique and primary
Date: 2006-02-23 17:22:23
Message-ID: 20060223085324.X5797@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 23 Feb 2006, Pavel Stehule wrote:

> >
> >Right, but does the pattern_ops one have to be unique?
> Sorry, I don't uderstand

Are you trying to guarantee uniqueness on the pattern_ops rules. My
understanding is that pattern_ops is not just a special index that allows
like comparisons using the index while necessarily giving the same rules
throughout, it uses a different set of comparison rules from the default
index type.

I think this means that you could have a locale in which the insertion of
sequence a and then b would fail for a normal unique constraint and
succeed for one based on pattern_ops.

If the rule you are trying to guarantee is that the two values are unique
using the standard definition of unique, the latter index is insufficient
for doing so and having a unique index on (foo) and an non-unique index on
(foo whatever_pattern_ops) is not duplication.

If the rule you are trying to guarantee is that the two values are unique
using the rules as defined by pattern ops, then a unique index on (foo
whatever_pattern_ops) and an index on (foo) is not duplication, and it's
not really a unique constraint by a strict definition, and as such I'm not
convinced it should use the unique constraint syntax.

If the rule you are trying to guarantee that it's unique to both rules
(ie if either fails it's disallowed), you need both unique indexes in
order to guarantee that.

> I looked to source code and I propouse syntax:
>
> CREATE TABLE name ..
> colname type PRIMARY KEY | UNIQUE [USING INDEX [TABLESPACE ...] [OPERATOR
> CLASS opclass]
>
> CREATE CONSTRAINT name
> PRIMARY KEY | UNIQUE '(' colname opt_class, ....
>
> I don't think so this need big patch.
> What do you think?

I don't think it's that easy. In general I don't think there's a guarantee
that the rules the opclass uses are directly comparable to those of the
equality operator. As such, the constraint doesn't necessarily have the
same guarantees as a standard unique constraint as given by spec. That
means we need to be careful whenever we're making assumptions about a
unique constraint.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2006-02-23 17:26:08 Re: Zeroing damaged pages
Previous Message Markus Schaber 2006-02-23 17:20:18 Re: [PERFORM] Looking for a tool to "*" pg tables as ERDs