Thread: is a good practice to create an index on the oid?
I am using the oid of the table as the main key and I've found that is not indexed (maybe because I have declared another primary key in the table) it is a good practice to create an index like this on the oid of a table? CREATE INDEX idoid annuncio400 USING btree (oid); does it work as a normal index? Thank you Edoardo
Yes, you can create an index on the oid, but unless you are selecting on it, it is of little use. you would have to do select * from foo where oid=? to get any value out of the index. Dave On Mon, 2004-04-26 at 12:38, Edoardo Ceccarelli wrote: > I am using the oid of the table as the main key and I've found that is > not indexed (maybe because I have declared another primary key in the table) > > it is a good practice to create an index like this on the oid of a table? > CREATE INDEX idoid annuncio400 USING btree (oid); > > > does it work as a normal index? > > Thank you > Edoardo > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > > > > !DSPAM:408d7c38183971270217895! > > -- Dave Cramer 519 939 0336 ICQ # 14675561
> I am using the oid of the table as the main key and I've found that is > not indexed (maybe because I have declared another primary key in the > table) > > it is a good practice to create an index like this on the oid of a table? > CREATE INDEX idoid annuncio400 USING btree (oid); Yes it is - in fact you really should add a unique index, not just a normal index, as you want to enforce uniqueness of the oid column. It is theoretically possible to end up with duplicate oids in wraparound situations. Even better though is to not use oids at all, of course... Chris
AFAIK, oids aren't used for anything internally, so duplicates don't really matter. Besides, what would you do about duplicate oid's ? The best suggestion is of course his last, don't use them. On Mon, 2004-04-26 at 22:48, Christopher Kings-Lynne wrote: > > I am using the oid of the table as the main key and I've found that is > > not indexed (maybe because I have declared another primary key in the > > table) > > > > it is a good practice to create an index like this on the oid of a table? > > CREATE INDEX idoid annuncio400 USING btree (oid); > > Yes it is - in fact you really should add a unique index, not just a > normal index, as you want to enforce uniqueness of the oid column. It > is theoretically possible to end up with duplicate oids in wraparound > situations. > > Even better though is to not use oids at all, of course... > > Chris > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html > > > > !DSPAM:408dcc51235334924183622! > > -- Dave Cramer 519 939 0336 ICQ # 14675561
Re: [JDBC] [PERFORM] is a good practice to create an index on the
From
Christopher Kings-Lynne
Date:
> AFAIK, oids aren't used for anything internally, so duplicates don't > really matter. Besides, what would you do about duplicate oid's ? If he's using them _externally_, then he does have to worry about duplicates. Chris
Edoardo, Are you using them for referential integrity? If so you would be wise to use sequences instead. Christopher: yes you are correct, I wasn't sure if that is what he was doing. Dave On Tue, 2004-04-27 at 11:01, Christopher Kings-Lynne wrote: > > AFAIK, oids aren't used for anything internally, so duplicates don't > > really matter. Besides, what would you do about duplicate oid's ? > > If he's using them _externally_, then he does have to worry about > duplicates. > > Chris > > > > !DSPAM:408e75e0137721921318500! > > -- Dave Cramer 519 939 0336 ICQ # 14675561
I am going to use them as primary key of the table, so I'll surely need them unique :) thank you for you help Edoardo Dave Cramer ha scritto: >Edoardo, > >Are you using them for referential integrity? If so you would be wise to >use sequences instead. > >Christopher: yes you are correct, I wasn't sure if that is what he was >doing. > >Dave >On Tue, 2004-04-27 at 11:01, Christopher Kings-Lynne wrote: > > >>>AFAIK, oids aren't used for anything internally, so duplicates don't >>>really matter. Besides, what would you do about duplicate oid's ? >>> >>> >>If he's using them _externally_, then he does have to worry about >>duplicates. >> >>Chris >> >> >> >>!DSPAM:408e75e0137721921318500! >> >> >> >>
Re: [JDBC] [PERFORM] is a good practice to create an index on the
From
Christopher Kings-Lynne
Date:
> I am going to use them as primary key of the table, so I'll surely need > them unique :) Eduoardo, I REALLY suggest you don't use them at all. You should make a primary key like this: CREATE TABLE blah ( id SERIAL PRIMARY KEY, ... ); Also note that by default, OIDs are NOT dumped by pg_dump. You will need to add extra switches to your pg_dump backup to ensure that they are. Chris
do you mean that, declaring an index serial, I'd never have to deal with incrementing its primary key? good to know! anyway in this particular situation I don't need such accurate behaviour: this table is filled up with a lot of data twice per week and it's used only to answer queries. I could drop it whenever I want :) Thanks again, eddy Christopher Kings-Lynne ha scritto: >> I am going to use them as primary key of the table, so I'll surely >> need them unique :) > > > Eduoardo, I REALLY suggest you don't use them at all. You should make > a primary key like this: > > CREATE TABLE blah ( > id SERIAL PRIMARY KEY, > ... > ); > > Also note that by default, OIDs are NOT dumped by pg_dump. You will > need to add extra switches to your pg_dump backup to ensure that they > are. > > Chris > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster > > >
Re: [JDBC] [PERFORM] is a good practice to create an index on the
From
Christopher Kings-Lynne
Date:
> do you mean that, declaring an index serial, I'd never have to deal with > incrementing its primary key? good to know! Yep. You can use 'DEFAULT' as the value, eg: INSERT INTO blah (DEFAULT, ...); > anyway in this particular situation I don't need such accurate > behaviour: this table is filled up with a lot of data twice per week and > it's used only to answer queries. > I could drop it whenever I want :) Sure. Chris
On Wed, Apr 28, 2004 at 10:13:14 +0200, Edoardo Ceccarelli <eddy@axa.it> wrote: > do you mean that, declaring an index serial, I'd never have to deal with > incrementing its primary key? good to know! That isn't what is happening. Serial is a special type. It is int plus a default rule linked to a sequence. No index is created by default for the serial type. Declaring a column as a primary key will however create a unique index on that column. Also note that you should only assume that the serial values are unique. (This assumes that you don't use setval and that you don't roll a sequence over.) Within a single session you can assume the sequence values will be monotonicly increasing. The values that end up in your table can have gaps. Typically this happens when a transaction rolls back after obtaining a new value from a sequence. It can also happen if you grab sequence values in larger blocks (which might be more efficient if a session normally acquires mulitple values from a particular sequence) than the default 1. > anyway in this particular situation I don't need such accurate > behaviour: this table is filled up with a lot of data twice per week and > it's used only to answer queries. > I could drop it whenever I want :) You really don't want to use oids.