Skip site navigation (1) Skip section navigation (2)

Re: WIP: generalized index constraints

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: WIP: generalized index constraints
Date: 2009-09-19 17:48:13
Message-ID: 1253382493.23353.48.camel@jdavis (view raw or flat)
Thread:
Lists: pgsql-hackers
I think we have a reasonable consensus around the name "operator
exclusion constraints", Robert Haas's suggestion. I am OK with that
name, and it got support from David Fetter and Tom Lane. As David Fetter
said, it's useful for the name to hint at the API.

Peter had some reasonable objections to that name, but the word "unique"
just doesn't cut it for this feature. My feature allows constraints
which are more restrictive than a unique constraint; but the final straw
was after a discussion with Tomás in which we determined that you can
also define constraints which are the opposite of unique: all values
must be the same (by using <> as the operator*).

I agree with Peter that we should support creating these constraints at
table creation time. This can be supported with the following syntax:

  CONSTRAINT foo_constr (a <op>, ...)
    { USING INDEX foo_idx | USING method }

and it's also a more declarative syntax for the ALTER TABLE case, and
prevents a series of other problems that Peter pointed out.

There's an important unresolved question with this patch that I need to
address, which just came to light: what about functional/expression
indexes?

Say you have a table foo(a text, b text) and an index on:
  ((a||b)::circle)

You could define an operator constraint like:
  ((a||b)::circle &&)

and that would be sane. But I suppose I should also allow any expression
with the same signature, like:
  ((b||a)::circle &&)

[ not a very realistic example, but it seems like it may be useful ]

Does that make sense? Does someone have a better idea? Am I missing
other issues here?

How do I test if two functions/expressions:
  a. are identical?
  b. have matching signatures?

Regards,
	Jeff Davis

*: Understandably, there is no strategy for <> for most data types.
However, if your constraint is that all values must be the same, it's
quite reasonable to add one and be able to use an index to quickly find
values that are different.


In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2009-09-19 17:48:56
Subject: Re: updated join removal patch
Previous:From: Marcos Luis Ortiz ValmasedaDate: 2009-09-19 17:27:00
Subject: Re: Crypto

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group