Re: Validating CHECK constraints with SPI

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dan Robinson <dan(at)drob(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Validating CHECK constraints with SPI
Date: 2014-10-29 14:24:26
Message-ID: 18229.1414592666@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dan Robinson <dan(at)drob(dot)us> writes:
> Since the table is locked to updates while the constraint is validating,
> this means you have to jump through hoops if you want to add a CHECK
> constraint to a large table in a production setting. This validation could
> be considerably faster if we enabled it to use relevant indexes or other
> constraints. Is there a reason not to make an SPI call here, instead?

This seems like a lot of work for a gain that would only occur sometimes,
ie if the CHECK happened to correspond to a usable index condition.
I realize your point is that a clever DBA might intentionally create
such an index, but I don't think that people would bother in practice.
It's not any simpler, nor faster, than using the existing approach with
ALTER TABLE ADD CONSTRAINT NOT VALID followed by ALTER TABLE VALIDATE
CONSTRAINT.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2014-10-29 14:41:24 Re: Failback to old master
Previous Message Simon Riggs 2014-10-29 14:21:24 Re: group locking: incomplete patch, just for discussion