agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
Question about index/constraint definition in a table
3+ messages / 2 participants
[nested] [flat]

* Question about index/constraint definition in a table
@ 2013-10-09 22:23 JORGE MALDONADO <jorgemal1960@gmail.com>
  2013-10-09 22:31 ` Re: Question about index/constraint definition in a table David Johnston <polobo@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: JORGE MALDONADO @ 2013-10-09 22:23 UTC (permalink / raw)
  To: pgsql-sql

I have a table as follows:
------------------------------------------------
Table Artist Colaborations
------------------------------------------------
* car_id (integer field, primary key)
* car_song (integer field, foreign key, foreign table is a catalog of songs)
* car_artist (integer field, foreign key, foreign table is a catalog of
artists)

So, I added 2 indexes to improve JOIN in queries:
1. An index for car_song which accepts duplicates.
2. An index for car_artist which accepts duplicates.

Now, the combination of "car_song + car_artist" cannot be duplicated so I
think that adding a constraint on these 2 fields is the solution.

My question: Is this the correct way to go?

Respectfully,
Jorge Maldonado

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Question about index/constraint definition in a table
  2013-10-09 22:23 Question about index/constraint definition in a table JORGE MALDONADO <jorgemal1960@gmail.com>
@ 2013-10-09 22:31 ` David Johnston <polobo@yahoo.com>
  2013-10-10 01:11   ` Re: Question about index/constraint definition in a table David Johnston <polobo@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: David Johnston @ 2013-10-09 22:31 UTC (permalink / raw)
  To: pgsql-sql

JORGE MALDONADO wrote
> I have a table as follows:
> ------------------------------------------------
> Table Artist Colaborations
> ------------------------------------------------
> * car_id (integer field, primary key)
> * car_song (integer field, foreign key, foreign table is a catalog of
> songs)
> * car_artist (integer field, foreign key, foreign table is a catalog of
> artists)
> 
> So, I added 2 indexes to improve JOIN in queries:
> 1. An index for car_song which accepts duplicates.
> 2. An index for car_artist which accepts duplicates.
> 
> Now, the combination of "car_song + car_artist" cannot be duplicated so I
> think that adding a constraint on these 2 fields is the solution.
> 
> My question: Is this the correct way to go?
> 
> Respectfully,
> Jorge Maldonado

Yes.  Why is it this is a question for you?

Also, the car_id field becomes pointless since your new constraint is the
true and natural PK.

David J.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/Question-about-index-constraint-definition-in-a-table-tp5773...
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Question about index/constraint definition in a table
  2013-10-09 22:23 Question about index/constraint definition in a table JORGE MALDONADO <jorgemal1960@gmail.com>
  2013-10-09 22:31 ` Re: Question about index/constraint definition in a table David Johnston <polobo@yahoo.com>
@ 2013-10-10 01:11   ` David Johnston <polobo@yahoo.com>
  0 siblings, 0 replies; 3+ messages in thread

From: David Johnston @ 2013-10-10 01:11 UTC (permalink / raw)
  To: pgsql-sql

David Johnston wrote
> 
> JORGE MALDONADO wrote
>> I have a table as follows:
>> ------------------------------------------------
>> Table Artist Colaborations
>> ------------------------------------------------
>> * car_id (integer field, primary key)
>> * car_song (integer field, foreign key, foreign table is a catalog of
>> songs)
>> * car_artist (integer field, foreign key, foreign table is a catalog of
>> artists)
>> 
>> So, I added 2 indexes to improve JOIN in queries:
>> 1. An index for car_song which accepts duplicates.
>> 2. An index for car_artist which accepts duplicates.
>> 
>> Now, the combination of "car_song + car_artist" cannot be duplicated so I
>> think that adding a constraint on these 2 fields is the solution.
>> 
>> My question: Is this the correct way to go?
>> 
>> Respectfully,
>> Jorge Maldonado
> Yes.  Why is it this is a question for you?
> 
> Also, the car_id field becomes pointless since your new constraint is the
> true and natural PK.
> 
> David J.

with index only scans it seems that defining a pair of unique indexes (and
no single column indexes) would have value.  How much value I do not know. 
Would still want to drop the artificial id field.

David J.







--
View this message in context: http://postgresql.1045698.n5.nabble.com/Question-about-index-constraint-definition-in-a-table-tp5773...
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2013-10-10 01:11 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-10-09 22:23 Question about index/constraint definition in a table JORGE MALDONADO <jorgemal1960@gmail.com>
2013-10-09 22:31 ` David Johnston <polobo@yahoo.com>
2013-10-10 01:11   ` David Johnston <polobo@yahoo.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox