X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C1DE4D79FD for ; Sun, 11 Sep 2005 14:13:02 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08614-05 for ; Sun, 11 Sep 2005 17:13:00 +0000 (GMT) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.203]) by svr1.postgresql.org (Postfix) with ESMTP id D7F7BD72E9 for ; Sun, 11 Sep 2005 14:12:59 -0300 (ADT) Received: by xproxy.gmail.com with SMTP id i31so2217353wxd for ; Sun, 11 Sep 2005 10:12:58 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=gvm9xMt0ystHE3Qo7Dymtb10GhSz3c6PIKQHqf8rb/0VCfWT+47cUjC3KRZQ5Gw9t6aSUXPGgWSZIUd8C2R7/Z3rmDQSnjj15EMKwWHdTN9PG7fRitmDiJE72p+dk+S7CD5HMg1prsWaJy0JM2IN7GbBF7XkkfrKr/uhPsZDcCs= Received: by 10.70.102.16 with SMTP id z16mr79803wxb; Sun, 11 Sep 2005 10:12:58 -0700 (PDT) Received: by 10.70.100.7 with HTTP; Sun, 11 Sep 2005 10:12:58 -0700 (PDT) Message-ID: <130df19305091110125a2d174f@mail.gmail.com> Date: Sun, 11 Sep 2005 20:12:58 +0300 From: Ksenia Marasanova Reply-To: ksenia.marasanova@gmail.com To: pgsql-performance@postgresql.org Subject: LEFT JOIN optimization Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 required=5 tests=[RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200509/130 X-Sequence-Number: 14438 Hi list, I don't have much experience with Postgres optimization, somehow I was happily avoiding anything more difficult than simple select statement, and it was working all right. Now LEFT JOIN must be used, and I am not happy with the performance: It takes about 5 seconds to run very simple LEFT JOIN query on a table "user_" with ~ 13.000 records left joined to table "church" with ~ 300 records on Powerbook PPC 1.67 GHz with 1.5 GB ram. Is it normal? Some details: test=3D# explain select * from user_ left join church on user_.church_id =3D church.id; QUERY PLAN =20 --------------------------------------------------------------------- Hash Left Join (cost=3D6.44..7626.69 rows=3D12763 width=3D325) Hash Cond: ("outer".church_id =3D "inner".id) -> Seq Scan on user_ (cost=3D0.00..7430.63 rows=3D12763 width=3D245) -> Hash (cost=3D5.75..5.75 rows=3D275 width=3D80) -> Seq Scan on church (cost=3D0.00..5.75 rows=3D275 width=3D80) (5 rows)