Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VU4n6-0000CV-L8 for pgsql-sql@arkaria.postgresql.org; Thu, 10 Oct 2013 01:11:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VU4n5-0002Wh-FM for pgsql-sql@arkaria.postgresql.org; Thu, 10 Oct 2013 01:11:47 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VU4n4-0002Wa-FA for pgsql-sql@postgresql.org; Thu, 10 Oct 2013 01:11:46 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VU4n1-0006W7-I1 for pgsql-sql@postgresql.org; Thu, 10 Oct 2013 01:11:45 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VU4n0-0007Lm-R5 for pgsql-sql@postgresql.org; Wed, 09 Oct 2013 18:11:42 -0700 Date: Wed, 9 Oct 2013 18:11:42 -0700 (PDT) From: David Johnston To: pgsql-sql@postgresql.org Message-ID: <1381367502833-5773942.post@n5.nabble.com> In-Reply-To: <1381357909835-5773925.post@n5.nabble.com> References: <1381357909835-5773925.post@n5.nabble.com> Subject: Re: Question about index/constraint definition in a table MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 4.5 (++++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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-tp5773924p5773942.html 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