X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 3652B9FB274 for ; Tue, 15 Aug 2006 11:45:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 91386-01 for ; Tue, 15 Aug 2006 14:44:57 +0000 (UTC) X-Greylist: delayed 00:06:40.617611 by SQLgrey- Received: from web36109.mail.mud.yahoo.com (web36109.mail.mud.yahoo.com [66.163.179.223]) by postgresql.org (Postfix) with SMTP id D83459FB269 for ; Tue, 15 Aug 2006 11:44:55 -0300 (ADT) Received: (qmail 69496 invoked by uid 60001); 15 Aug 2006 14:38:12 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.ar; h=Message-ID:Received:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=NODwgyH/fecdOv9unjRIxt+L2B/NWHRkCUDO3ydLhIni8SVcCJq28O5ed/DoceHBod4qt1Gfa4uQwK8zga99MxUiKBd4UMhv/TE3nyaUYgFy90118LmFPPAzblpbEiuem+71Et12uh6Jow31Jaoe/fF2jfng2sG2nDHunF1Gz88= ; Message-ID: <20060815143812.69494.qmail@web36109.mail.mud.yahoo.com> Received: from [200.49.144.50] by web36109.mail.mud.yahoo.com via HTTP; Tue, 15 Aug 2006 14:38:12 GMT Date: Tue, 15 Aug 2006 14:38:12 +0000 (GMT) From: =?iso-8859-1?q?Sebasti=E1n=20Baioni?= Reply-To: sebaioni-postgresql@yahoo.com.ar Subject: Inner Join of the same table To: Performance PostgreSQL MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-455872028-1155652692=:68034" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200608/221 X-Sequence-Number: 20406 --0-455872028-1155652692=:68034 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hello, I'm migrating from MS SQL Server to PostgreSQL 8.1 and I have a serious problem: Table: APORTES - Rows: 9,000,000 (9 million) *cuiT (char 11) *cuiL (char 11) *PERI (char 6) FAMI (numeric 6) I need all the cuiLs whose max(PERI) are from a cuiT, and the Max(FAMI) of those cuiLs, so the sentence is: SELECT DISTINCT T.cuiT, T.cuiL. U.MAXPERI, U.MAXFAMI FROM APORTES T INNER JOIN (SELECT cuiL, MAX(PERI) AS MAXPERI, MAX(FAMI) AS MAXFAMI FROM APORTES GROUP BY cuiL) AS U ON T.cuiL = U.cuiL AND T.PERI=U.MAXPERI WHERE T.cuiT='12345678901' In MS SQL Server it lasts 1minute, in PostgreSQL for Windows it lasts 40minutes and in PostgreSQL for Linux (FreeBSD) it lasts 20minuts. Do you know if there is any way to tune the server or optimize this sentence? Thanks Sebastián Baioni Sebastián Baioni --------------------------------- Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). Probalo ya! --0-455872028-1155652692=:68034 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hello, I'm migrating from MS SQL Server to PostgreSQL 8.1 and I have a serious problem:
Table: APORTES - Rows: 9,000,000 (9 million)
*cuiT (char 11)
*cuiL (char 11)
*PERI (char 6)
FAMI (numeric 6)

I need all the cuiLs whose max(PERI) are from a cuiT, and the Max(FAMI) of those cuiLs, so the sentence is:

SELECT DISTINCT T.cuiT, T.cuiL. U.MAXPERI, U.MAXFAMI
       FROM APORTES T
       INNER JOIN
       (SELECT cuiL, MAX(PERI) AS MAXPERI,
               MAX(FAMI) AS MAXFAMI

        FROM APORTES
        GROUP BY cuiL) AS U
       ON T.cuiL = U.cuiL AND T.PERI=U.MAXPERI
WHERE T.cuiT='12345678901'

In MS SQL Server it lasts 1minute, in PostgreSQL for Windows it lasts 40minutes and in PostgreSQL for Linux (FreeBSD) it lasts 20minuts.

Do you know if there is any way to tune the server or optimize this sentence?

Thanks
     Sebastián Baioni

Instrumentos musicalesSebastián Baioni Ofertas náuticas


Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
Probalo ya! --0-455872028-1155652692=:68034--