ALTER TABLE ... ALTER CONSTRAINT

Поиск
Список
Период
Сортировка
Искать

ALTER TABLE ... ALTER CONSTRAINT

От:
Simon Riggs <simon@2ndQuadrant.com>
Дата:
Вложения:
While fiddling with FK tuning, it was useful to be able to enable and
disable the DEFERRED mode of constraints.

That is not currently possible in SQL, so I wrote this patch. Without
this you have to drop and then re-add a constraint, which is
impractical for large tables.

e.g.
CREATE TABLE fktable (id integer, fk integer REFERENCES pktable (id));

ALTER TABLE foo
   ALTER CONSTRAINT fktable_fk_fkey DEFERRED INITIALLY IMMEDIATE;

Includes docs and tests.

Currently works for FKs only. Potentially other constraints can be
supported in future.

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Andres Freund <andres@2ndquadrant.com>
Дата:
On 2013-06-08 21:45:24 +0100, Simon Riggs wrote:
> While fiddling with FK tuning, it was useful to be able to enable and
> disable the DEFERRED mode of constraints.
> 
> That is not currently possible in SQL, so I wrote this patch. Without
> this you have to drop and then re-add a constraint, which is
> impractical for large tables.
> 
> e.g.
> CREATE TABLE fktable (id integer, fk integer REFERENCES pktable (id));
> 
> ALTER TABLE foo
>    ALTER CONSTRAINT fktable_fk_fkey DEFERRED INITIALLY IMMEDIATE;
> 
> Includes docs and tests.
> 
> Currently works for FKs only. Potentially other constraints can be
> supported in future.

I haven't looked at the patch in detail, but I am very, very much in
favor of the feature in general… I have wished for this more than once,
and it certainly cost me more time working around it than it would have
cost to implement it.

Thanks,

Andres Freund

-- Andres Freund	                   http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services


Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Kevin Grittner <kgrittn@ymail.com>
Дата:
Andres Freund  wrote:
> On 2013-06-08 21:45:24 +0100, Simon Riggs wrote:

>> ALTER TABLE foo
>>     ALTER CONSTRAINT fktable_fk_fkey DEFERRED INITIALLY IMMEDIATE;

> I haven't looked at the patch in detail, but I am very, very much in
> favor of the feature in general… I have wished for this more than once

+1

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Dimitri Fontaine <dimitri@2ndQuadrant.fr>
Дата:
Andres Freund  writes:
> I haven't looked at the patch in detail, but I am very, very much in
> favor of the feature in general… I have wished for this more than once,

+1

-- 
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support


Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Michael Paquier <michael.paquier@gmail.com>
Дата:



On Mon, Jun 10, 2013 at 11:06 PM, Dimitri Fontaine <dimitri@2ndquadrant.fr> wrote:
Andres Freund <andres@2ndquadrant.com> writes:
> I haven't looked at the patch in detail, but I am very, very much in
> favor of the feature in general… I have wished for this more than once,

+1
+1. It will be useful.
--
Michael

Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Abhijit Menon-Sen <ams@2ndQuadrant.com>
Дата:
At 2013-06-08 21:45:24 +0100, simon@2ndQuadrant.com wrote:
>
> ALTER TABLE foo
>    ALTER CONSTRAINT fktable_fk_fkey DEFERRED INITIALLY IMMEDIATE;

I read the patch (looks good), applied it on HEAD (fine), ran make check
(fine), and played with it in a test database. It looks great, and from
previous responses it's something a lot of people have wished for.

I'm marking this ready for committer.

-- Abhijit


Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Jeff Janes <jeff.janes@gmail.com>
Дата:
On Sun, Jun 23, 2013 at 8:58 PM, Abhijit Menon-Sen <ams@2ndquadrant.com> wrote:
At 2013-06-08 21:45:24 +0100, simon@2ndQuadrant.com wrote:
>
> ALTER TABLE foo
>    ALTER CONSTRAINT fktable_fk_fkey DEFERRED INITIALLY IMMEDIATE;

I read the patch (looks good), applied it on HEAD (fine), ran make check
(fine), and played with it in a test database. It looks great, and from
previous responses it's something a lot of people have wished for.

I'm marking this ready for committer.

After the commit, I'm now getting the compiler warning:

tablecmds.c: In function 'ATPrepCmd':
tablecmds.c:2953: warning: 'pass' may be used uninitialized in this function


case AT_AlterConstraint (line 3130) is the only case branch that does not set pass.

Cheers,

Jeff

Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Simon Riggs <simon@2ndQuadrant.com>
Дата:
On 24 June 2013 21:42, Jeff Janes <jeff.janes@gmail.com> wrote:
On Sun, Jun 23, 2013 at 8:58 PM, Abhijit Menon-Sen <ams@2ndquadrant.com> wrote:
At 2013-06-08 21:45:24 +0100, simon@2ndQuadrant.com wrote:
>
> ALTER TABLE foo
>    ALTER CONSTRAINT fktable_fk_fkey DEFERRED INITIALLY IMMEDIATE;

I read the patch (looks good), applied it on HEAD (fine), ran make check
(fine), and played with it in a test database. It looks great, and from
previous responses it's something a lot of people have wished for.

I'm marking this ready for committer.

After the commit, I'm now getting the compiler warning:

tablecmds.c: In function 'ATPrepCmd':
tablecmds.c:2953: warning: 'pass' may be used uninitialized in this function


case AT_AlterConstraint (line 3130) is the only case branch that does not set pass.

The investigation is into why my current compiler didn't report that. Thanks though.

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Simon Riggs <simon@2ndQuadrant.com>
Дата:
On 24 June 2013 22:17, Simon Riggs <simon@2ndquadrant.com> wrote:
On 24 June 2013 21:42, Jeff Janes <jeff.janes@gmail.com> wrote:
On Sun, Jun 23, 2013 at 8:58 PM, Abhijit Menon-Sen <ams@2ndquadrant.com> wrote:
At 2013-06-08 21:45:24 +0100, simon@2ndQuadrant.com wrote:
>
> ALTER TABLE foo
>    ALTER CONSTRAINT fktable_fk_fkey DEFERRED INITIALLY IMMEDIATE;

I read the patch (looks good), applied it on HEAD (fine), ran make check
(fine), and played with it in a test database. It looks great, and from
previous responses it's something a lot of people have wished for.

I'm marking this ready for committer.

After the commit, I'm now getting the compiler warning:

tablecmds.c: In function 'ATPrepCmd':
tablecmds.c:2953: warning: 'pass' may be used uninitialized in this function


case AT_AlterConstraint (line 3130) is the only case branch that does not set pass.

The investigation is into why my current compiler didn't report that. Thanks though.

Looks like that really is a deficiency in my tool chain on OSX, rather than some bug/user error. Even at the very latest, very shiny version.

Latest versions of gcc trap the error, so I'll have to investigate an alternative.

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Re: ALTER TABLE ... ALTER CONSTRAINT

От:
Alvaro Herrera <alvherre@2ndquadrant.com>
Дата:
Simon Riggs escribió:

> Looks like that really is a deficiency in my tool chain on OSX, rather than
> some bug/user error. Even at the very latest, very shiny version.
> 
> Latest versions of gcc trap the error, so I'll have to investigate an
> alternative.

Funnily enough, on Debian Wheezy with gcc 4.7.2 I don't get the warning,
and Andres with gcc 4.7.3 (from Debian unstable) does see it.  (Of
course, the 4.8 version shipped with unstable also shows it.)

Clang similarly requires pretty new versions to show the warning.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


FAQ