Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 7D467133655C for ; Tue, 28 Sep 2010 07:34:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 77932-09 for ; Tue, 28 Sep 2010 10:34:34 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id AB2421335ED4 for ; Tue, 28 Sep 2010 07:34:32 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id SBPT785F; Tue, 28 Sep 2010 11:34:31 +0100 Message-ID: <5F1C28C4D61848D6A012C5DD84B22226@marktestcr.marktest.pt> From: "Oliveiros d'Azevedo Cristina" To: "Tarlika Elisabeth Schmitz" , References: <20100923223940.5019475e@dick.coachhouse><8590CAE9E5504E23AB08C4EF31EA066F@marktestcr.marktest.pt><20100924171226.6000b310@dick.coachhouse><065CBEA1-1647-4233-BBB6-48E879FD91B0@gmail.com> <20100927175418.162ee906@dick.coachhouse> Subject: Re: identifying duplicates in table with redundancies Date: Tue, 28 Sep 2010 11:34:31 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.471 tagged_above=-5 required=5 tests=BAYES_00=-1.9, STOX_REPLY_TYPE=0.439, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/109 X-Sequence-Number: 34640 Hello again, Tarlika. In what concerns to indices, I 'm affraid I may not be the best person to advise you, my knowledge of them hardly goes beyond the most trivial cases. I'm sure there are plenty of other people on the list who are able to give you better advise than me. But, on this query in particular I would recomend an indice on trainer_name, as this field will be used on the join and on the group by. For the other query, the one you get by substituting trainer_name by trainer_id, place an index on trainer_id. Also, these indexes may help speed up the order by clause, if you use one. If you have a table with lots of data you can try them around and see how performance varies (and don't forget there's also EXPLAIN ANALYZE) Bear in mind, though, that this is just my 2 cents on a matter that I don't really master. Do not take this as an expert answer. There are many people on this list that can help you better Best, Oliveiros ----- Original Message ----- From: "Tarlika Elisabeth Schmitz" To: Sent: Monday, September 27, 2010 5:54 PM Subject: Re: [SQL] identifying duplicates in table with redundancies > On Fri, 24 Sep 2010 18:12:18 +0100 > Oliver d'Azevedo Christina wrote: > >>>> SELECT DISTINCT trainer_id,trainer_name >>>> FROM ( >>>> SELECT trainer_name -- The field you want to test for duplicates >>>> FROM ( >>>> SELECT DISTINCT "trainer_id","trainer_name" >>>> FROM student >>>> ) x >>>> GROUP BY "trainer_name" -- the field you want to test for >>>> duplicates >>>> HAVING (COUNT(*) > 1) >>>> ) z >>>> NATURAL JOIN student y > > > > What indices would you recommend for this operation? > > -- > > Best Regards, > Tarlika Elisabeth Schmitz > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql