Setting a pre-existing index as a primary key

Lists: pgsql-hackers
From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Setting a pre-existing index as a primary key
Date: 2008-04-09 00:00:27
Message-ID: 36e682920804081700n3ef85bafx54a1c9f431532a10@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hey all,

I've run into a couple cases now where it would be helpful to easily
assign an already-existing unique index as a primary key. Unless I
completely missed something, there's no way to do this now without a
bit of catalog hackery.

My implementation idea is as follows:

Proposed Syntax (based on Oracle's syntax)

ALTER TABLE foo ADD CONSTRAINT bar PRIMARY KEY USING INDEX schema.tablename;

Proposed Implementation

1. Verify that the index named is a unique index
2. Check index columns for NOT NULL constraints
3. If indexed columns are not already NOT NULL, apply NOT NULL
4. If NOT NULL succeeds, complete the operation (catalogs,
dependencies, ...), else bail out.

Any comments, ideas, suggestions?

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-04-09 01:04:11
Message-ID: 10889.1207703051@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:
> I've run into a couple cases now where it would be helpful to easily
> assign an already-existing unique index as a primary key.

You need to present a more convincing use-case than this unsupported
assertion. There's hardly any effective difference between a unique
index + NOT NULL constraints and a declared primary key ... so what
did you really need it for?

> 1. Verify that the index named is a unique index

... and not partial, and not on expressions, and not invalid, and not
using non-default opclasses (which might have a surprising definition of
"equal"), and not already owned by a constraint ... not to mention that
it'd better be an index on the named table, which among other things
removes the need for a schema specification on the index name.

regards, tom lane


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-04-09 03:03:38
Message-ID: 36e682920804082003m5d3fba19y3d500944cd1cbeda@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Apr 8, 2008 at 9:04 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:
> > I've run into a couple cases now where it would be helpful to easily
> > assign an already-existing unique index as a primary key.
>
> You need to present a more convincing use-case than this unsupported
> assertion. There's hardly any effective difference between a unique
> index + NOT NULL constraints and a declared primary key ... so what
> did you really need it for?

Agreed, functionally there's not much of a difference. It's more of a
matter of proper design identifying a primary key.

> > 1. Verify that the index named is a unique index
>
> ... and not partial, and not on expressions, and not invalid, and not
> using non-default opclasses (which might have a surprising definition of
> "equal"), and not already owned by a constraint ... not to mention that
> it'd better be an index on the named table, which among other things
> removes the need for a schema specification on the index name.

Of course.

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-04-10 05:58:05
Message-ID: c2d9e70e0804092258s860bfeetbaab8fc78d0c0223@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Apr 8, 2008 at 10:03 PM, Jonah H. Harris <jonah(dot)harris(at)gmail(dot)com> wrote:
> On Tue, Apr 8, 2008 at 9:04 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > "Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:
> > > I've run into a couple cases now where it would be helpful to easily
> > > assign an already-existing unique index as a primary key.
> >
> > You need to present a more convincing use-case than this unsupported
> > assertion. There's hardly any effective difference between a unique
> > index + NOT NULL constraints and a declared primary key ... so what
> > did you really need it for?
>
> Agreed, functionally there's not much of a difference. It's more of a
> matter of proper design identifying a primary key.
>

set right constraints it's good for documenting the system itself, i
like the idea...

--
regards,
Jaime Casanova


From: Mario Weilguni <mweilguni(at)sime(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-04-10 09:46:55
Message-ID: 47FDE20F.7040006@sime.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane schrieb:
> "Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:
>
>> I've run into a couple cases now where it would be helpful to easily
>> assign an already-existing unique index as a primary key.
>>
>
> You need to present a more convincing use-case than this unsupported
> assertion. There's hardly any effective difference between a unique
> index + NOT NULL constraints and a declared primary key ... so what
> did you really need it for?
>
>
In fact it seems to be necessary when connecting with ODBC, I had the
problem a month ago, MsSQL will not work correctly with connected tables
in a postgres database when there is no PK. NOT NULL and unique index
is not enough.

But I think it's overkill to add ALTER commands for this rare corner
case, maybe it's enough to set "indisprimary" on the index?


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 01:50:23
Message-ID: 200805100150.m4A1oNT28688@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Added to TODO:

o Allow an existing index to be marked as a table's primary key

---------------------------------------------------------------------------

Jonah H. Harris wrote:
> Hey all,
>
> I've run into a couple cases now where it would be helpful to easily
> assign an already-existing unique index as a primary key. Unless I
> completely missed something, there's no way to do this now without a
> bit of catalog hackery.
>
> My implementation idea is as follows:
>
> Proposed Syntax (based on Oracle's syntax)
>
> ALTER TABLE foo ADD CONSTRAINT bar PRIMARY KEY USING INDEX schema.tablename;
>
> Proposed Implementation
>
> 1. Verify that the index named is a unique index
> 2. Check index columns for NOT NULL constraints
> 3. If indexed columns are not already NOT NULL, apply NOT NULL
> 4. If NOT NULL succeeds, complete the operation (catalogs,
> dependencies, ...), else bail out.
>
> Any comments, ideas, suggestions?
>
> --
> Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
> EnterpriseDB Corporation | fax: 732.331.1301
> 499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
> Edison, NJ 08837 | http://www.enterprisedb.com/
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 02:48:15
Message-ID: 48250CEF.4090802@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Added to TODO:
>
>> Proposed Implementation
>>
>> 1. Verify that the index named is a unique index
>> 2. Check index columns for NOT NULL constraints
>> 3. If indexed columns are not already NOT NULL, apply NOT NULL
>> 4. If NOT NULL succeeds, complete the operation (catalogs,
>> dependencies, ...), else bail out.
>>
>> Any comments, ideas, suggestions?

I would add:

5. Modify index name to use appropriate naming style.

Joshua D. Drake


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 03:41:00
Message-ID: 24480.1210390860@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Joshua D. Drake" <jd(at)commandprompt(dot)com> writes:
> Bruce Momjian wrote:
>> Any comments, ideas, suggestions?

> I would add:

> 5. Modify index name to use appropriate naming style.

Why, and exactly what would you define as "appropriate naming style"?
The user has always been free to pick whatever constraint name he
wants.

regards, tom lane


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 05:14:35
Message-ID: 48252F3B.6020406@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> "Joshua D. Drake" <jd(at)commandprompt(dot)com> writes:
>> Bruce Momjian wrote:
>>> Any comments, ideas, suggestions?
>
>> I would add:
>
>> 5. Modify index name to use appropriate naming style.
>
> Why, and exactly what would you define as "appropriate naming style"?
> The user has always been free to pick whatever constraint name he
> wants.

Well it should be optional but it would be nice if we had the option to
have it renamed per the default... meaning the same output if I were to
do this:

create table foo (id serial primary key);

I end up with "foo_pkey" PRIMARY KEY, btree (id)

Which is nice for consistency.

Sincerely,

Joshua D. Drake

>
> regards, tom lane
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 15:10:37
Message-ID: 2126.1210432237@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Joshua D. Drake" <jd(at)commandprompt(dot)com> writes:
> Tom Lane wrote:
>> Why, and exactly what would you define as "appropriate naming style"?
>> The user has always been free to pick whatever constraint name he
>> wants.

> Well it should be optional but it would be nice if we had the option to
> have it renamed per the default... meaning the same output if I were to
> do this:

If you want that, you can rename the index (either before or afterwards).
I don't see any reason to clutter the make-constraint-from-index command
with questions of renaming.

regards, tom lane


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 15:32:34
Message-ID: 4825C012.4000803@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>> Well it should be optional but it would be nice if we had the option to
>> have it renamed per the default... meaning the same output if I were to
>> do this:
>
> If you want that, you can rename the index (either before or afterwards).
> I don't see any reason to clutter the make-constraint-from-index command
> with questions of renaming.

As a counter point, I don't see any reason to make the DBA's life
harder. Sure it is just one step but it is a human step, prone to error
and taking more time than it should. Why not just make it easy?
Especially when the easy isn't sacrificing data integrity or quality of
product?

Sincerely,

Joshua D. Drake

>
> regards, tom lane
>


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 15:55:17
Message-ID: 4825C565.5070802@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Joshua D. Drake wrote:
> Tom Lane wrote:
>
>>> Well it should be optional but it would be nice if we had the option
>>> to have it renamed per the default... meaning the same output if I
>>> were to do this:
>>
>> If you want that, you can rename the index (either before or
>> afterwards).
>> I don't see any reason to clutter the make-constraint-from-index command
>> with questions of renaming.
>
> As a counter point, I don't see any reason to make the DBA's life
> harder. Sure it is just one step but it is a human step, prone to
> error and taking more time than it should. Why not just make it easy?
> Especially when the easy isn't sacrificing data integrity or quality
> of product?
>
>
>

Because that's not the basis on which we decide to add features. You
need to asses the code complexity, the potential benefit and number of
likely users. In this case, the amount of code required for what would
be nothing more than syntactic sugar for what is in any case a very
simple statement makes me agree with Tom.

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 15:55:29
Message-ID: 2714.1210434929@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Joshua D. Drake" <jd(at)commandprompt(dot)com> writes:
> As a counter point, I don't see any reason to make the DBA's life
> harder. Sure it is just one step but it is a human step, prone to error
> and taking more time than it should. Why not just make it easy?

I don't see that decorating infrequently-used statements with bizarre
options that duplicate the functionality of other commands is "making it
easy". Apparently your definition of "easy" depends entirely on
keystrokes and not at all on memory/cognitive burden.

IMHO a utility command should do one easily-explained thing. The fewer
options the better.

regards, tom lane


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 17:08:58
Message-ID: 4825D6AA.3050204@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

> Apparently your definition of "easy" depends entirely on
> keystrokes and not at all on memory/cognitive burden.

I was trying to remove one opportunity for human error, which is tied to
memory and cognitive burden. It is very easy to fat finger something. Is
it a critical error? No. Is it obnoxious to have to go back and fix it,
yes. When you are going back to fix, are you going to be grousing about
how PostgreSQL doesn't make this easier, maybe.

>
> IMHO a utility command should do one easily-explained thing. The fewer
> options the better.

I would agree with this except that by my definition your argument
fails. You are adding options by not allowing a sane default that
applies consistency to the database. I believe this will cause more
trouble than having the limitation in the first place.

Anyway, I have made my arguments. I believe we are still in the middle
of a commit fest.

Sincerely,

Joshua D. Drake


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bruce Momjian" <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 21:15:10
Message-ID: 36e682920805101415u669726c7o148d733a8d5d16e9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

So, would anyone be averse to something like the following:

ALTER TABLE blah ADD ... PRIMARY KEY (...) USING PREBUILT INDEX index_hame

If the user doesn't specify CONSTRAINT constraint_name, it will
default to current implicit behavior of col_pkey.

-Jonah

On Sat, May 10, 2008 at 1:08 PM, Joshua D. Drake <jd(at)commandprompt(dot)com> wrote:
> Tom Lane wrote:
>
>> Apparently your definition of "easy" depends entirely on
>> keystrokes and not at all on memory/cognitive burden.
>
> I was trying to remove one opportunity for human error, which is tied to
> memory and cognitive burden. It is very easy to fat finger something. Is it
> a critical error? No. Is it obnoxious to have to go back and fix it, yes.
> When you are going back to fix, are you going to be grousing about how
> PostgreSQL doesn't make this easier, maybe.
>
>>
>> IMHO a utility command should do one easily-explained thing. The fewer
>> options the better.
>
> I would agree with this except that by my definition your argument fails.
> You are adding options by not allowing a sane default that applies
> consistency to the database. I believe this will cause more trouble than
> having the limitation in the first place.
>
> Anyway, I have made my arguments. I believe we are still in the middle of a
> commit fest.
>
> Sincerely,
>
> Joshua D. Drake
>
>

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
Cc: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 21:35:59
Message-ID: 87wsm16dvk.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:

> So, would anyone be averse to something like the following:
>
> ALTER TABLE blah ADD ... PRIMARY KEY (...) USING PREBUILT INDEX index_hame
>
> If the user doesn't specify CONSTRAINT constraint_name, it will
> default to current implicit behavior of col_pkey.

This is all so that the primary key shows up with a nice "PRIMARY KEY" instead
of just the unique index?

The "PREBUILT" seems unnecessary in that syntax.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's Slony Replication support!


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Gregory Stark" <stark(at)enterprisedb(dot)com>
Cc: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bruce Momjian" <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 21:44:34
Message-ID: 36e682920805101444l632ee2a2g5c6cc85ed4b8292a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Yes, I just think PREBUILT conveys the meaning of the command more
appropriately. I could care less though.

On Sat, May 10, 2008 at 5:35 PM, Gregory Stark <stark(at)enterprisedb(dot)com> wrote:
> "Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:
>
>> So, would anyone be averse to something like the following:
>>
>> ALTER TABLE blah ADD ... PRIMARY KEY (...) USING PREBUILT INDEX index_hame
>>
>> If the user doesn't specify CONSTRAINT constraint_name, it will
>> default to current implicit behavior of col_pkey.
>
> This is all so that the primary key shows up with a nice "PRIMARY KEY" instead
> of just the unique index?
>
> The "PREBUILT" seems unnecessary in that syntax.
>
> --
> Gregory Stark
> EnterpriseDB http://www.enterprisedb.com
> Ask me about EnterpriseDB's Slony Replication support!
>

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
Cc: Gregory Stark <stark(at)enterprisedb(dot)com>, "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-10 22:48:23
Message-ID: 48262637.7070100@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jonah H. Harris wrote:
> Yes, I just think PREBUILT conveys the meaning of the command more
> appropriately. I could care less though.
>

(Please don't top-answer)

I don't think we should add new keywords unnecessarily.

cheers

andrew
> On Sat, May 10, 2008 at 5:35 PM, Gregory Stark <stark(at)enterprisedb(dot)com> wrote:
>
>> "Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:
>>
>>
>>> So, would anyone be averse to something like the following:
>>>
>>> ALTER TABLE blah ADD ... PRIMARY KEY (...) USING PREBUILT INDEX index_hame
>>>
>>> If the user doesn't specify CONSTRAINT constraint_name, it will
>>> default to current implicit behavior of col_pkey.
>>>
>> This is all so that the primary key shows up with a nice "PRIMARY KEY" instead
>> of just the unique index?
>>
>> The "PREBUILT" seems unnecessary in that syntax.
>>
>> --
>> Gregory Stark
>> EnterpriseDB http://www.enterprisedb.com
>> Ask me about EnterpriseDB's Slony Replication support!
>>
>>
>
>
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
Cc: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-11 00:33:24
Message-ID: 9090.1210466004@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Jonah H. Harris" <jonah(dot)harris(at)gmail(dot)com> writes:
> ALTER TABLE blah ADD ... PRIMARY KEY (...) USING PREBUILT INDEX index_hame

> If the user doesn't specify CONSTRAINT constraint_name, it will
> default to current implicit behavior of col_pkey.

IOW, the default behavior is to rename the index? Doesn't seem to me
to satisfy the principle of least surprise.

I agree with Andrew that creating new keywords just for noise purposes
is not gonna happen.

regards, tom lane


From: Andrew Sullivan <ajs(at)commandprompt(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-11 02:41:56
Message-ID: 20080511024156.GA52350@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, May 10, 2008 at 11:55:29AM -0400, Tom Lane wrote:

> IMHO a utility command should do one easily-explained thing. The fewer
> options the better.

Sticking to that principle makes for a better-maintained system. I
agree. If we want to point out, "You might rename your index
afterwards to make it look like other default primary keys," I have no
objection.

A

--
Andrew Sullivan
ajs(at)commandprompt(dot)com
+1 503 667 4564 x104
http://www.commandprompt.com/


From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-11 09:13:05
Message-ID: 4826B8A1.9070504@wildenhain.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Joshua D. Drake wrote:
> Tom Lane wrote:
>
>>> Well it should be optional but it would be nice if we had the option
>>> to have it renamed per the default... meaning the same output if I
>>> were to do this:
>>
>> If you want that, you can rename the index (either before or afterwards).
>> I don't see any reason to clutter the make-constraint-from-index command
>> with questions of renaming.
>
> As a counter point, I don't see any reason to make the DBA's life
> harder. Sure it is just one step but it is a human step, prone to error
> and taking more time than it should. Why not just make it easy?
> Especially when the easy isn't sacrificing data integrity or quality of
> product?

well the name is by no means a functional problem. Its merely cosmetics,
so if you want propose that a warning is issued to suggest a saner name.

This should be sufficient I think.

T.


From: David Fetter <david(at)fetter(dot)org>
To: Andrew Sullivan <ajs(at)commandprompt(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-11 16:32:01
Message-ID: 20080511163201.GE18958@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, May 10, 2008 at 10:41:56PM -0400, Andrew Sullivan wrote:
> On Sat, May 10, 2008 at 11:55:29AM -0400, Tom Lane wrote:
> > IMHO a utility command should do one easily-explained thing. The
> > fewer options the better.
>
> Sticking to that principle makes for a better-maintained system. I
> agree. If we want to point out, "You might rename your index
> afterwards to make it look like other default primary keys," I have
> no objection.

For convenience, it might be nice to include the generated name in the
notice.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-12 16:17:34
Message-ID: 200805121617.m4CGHYr06026@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Joshua D. Drake wrote:
> Tom Lane wrote:
>
> >> Well it should be optional but it would be nice if we had the option to
> >> have it renamed per the default... meaning the same output if I were to
> >> do this:
> >
> > If you want that, you can rename the index (either before or afterwards).
> > I don't see any reason to clutter the make-constraint-from-index command
> > with questions of renaming.
>
> As a counter point, I don't see any reason to make the DBA's life
> harder. Sure it is just one step but it is a human step, prone to error
> and taking more time than it should. Why not just make it easy?
> Especially when the easy isn't sacrificing data integrity or quality of
> product?

I realize most feel we don't need to add a rename to this, but there are
two more reasons _not_ to do this. First, there is the possibility of
name collision with the new name so you would then require the user to
use the option not to rename. Plus, if you renamed, the old index name
would go away, and some people might think the index was removed and not
realize it was renamed, or find it confusing it was renamed.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-12 17:04:59
Message-ID: 22201.1210611899@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> I realize most feel we don't need to add a rename to this, but there are
> two more reasons _not_ to do this.

One other thought I had about this is that the proposed syntax

ALTER TABLE tab ADD PRIMARY KEY (col [, ...]) USING INDEX foo

is not well chosen anyway. It forces the user to provide a column name
list matching the index, which is just extra typing and extra cognitive
burden, and it forces the system to have code checking that this list
matches the specified index. So I'm thinking it should look like

ALTER TABLE tab ADD PRIMARY KEY USING INDEX foo
or maybe just
ALTER TABLE tab ADD PRIMARY KEY USING foo

This would be a separate grammar production having nothing to do with
the ADD CONSTRAINT syntax. It's not ambiguous since the column name
list is required in ADD CONSTRAINT.

BTW, aside from selecting the index the command would have to verify
that the indexed columns are all NOT NULL. We could either have it
just throw an error if they aren't, or have it silently try to do
an ALTER SET NOT NULL, which would require a table scan.

I'm going to argue for the "just throw an error" choice. I don't like
the idea of a utility command that takes exclusive lock and then is
either near-instantaneous or slow depending on factors not immediately
obvious.

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Setting a pre-existing index as a primary key
Date: 2008-05-12 17:25:26
Message-ID: 48287D86.8030908@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> BTW, aside from selecting the index the command would have to verify
> that the indexed columns are all NOT NULL. We could either have it
> just throw an error if they aren't, or have it silently try to do
> an ALTER SET NOT NULL, which would require a table scan.
>
> I'm going to argue for the "just throw an error" choice. I don't like
> the idea of a utility command that takes exclusive lock and then is
> either near-instantaneous or slow depending on factors not immediately
> obvious.
>
>
>

+1

cheers

andrew