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 CAD2ADA4DC for ; Thu, 22 Sep 2005 05:24:11 -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 84829-04 for ; Thu, 22 Sep 2005 08:24:09 +0000 (GMT) Received: from smtp1.freeserve.com (smtp1.wanadoo.co.uk [193.252.22.158]) by svr1.postgresql.org (Postfix) with ESMTP id F296CDA4DB for ; Thu, 22 Sep 2005 05:24:08 -0300 (ADT) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf3014.me.freeserve.com (SMTP Server) with ESMTP id C1FE28800085; Thu, 22 Sep 2005 10:24:08 +0200 (CEST) Received: from 192.168.0.102 (modem-2050.leopard.dialup.pol.co.uk [217.135.152.2]) by mwinf3014.me.freeserve.com (SMTP Server) with ESMTP id 5F0A88800081; Thu, 22 Sep 2005 10:24:08 +0200 (CEST) X-ME-UUID: 20050922082408389.5F0A88800081@mwinf3014.me.freeserve.com Subject: Re: Nested Loop trouble : Execution time increases more From: Simon Riggs To: Antoine Bajolet Cc: pgsql-performance@postgresql.org In-Reply-To: <432C3A86.5010000@free.fr> References: <432C3A86.5010000@free.fr> Content-Type: text/plain Organization: 2nd Quadrant Date: Thu, 22 Sep 2005 09:24:10 +0100 Message-Id: <1127377450.4145.68.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-3) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.052 required=5 tests=[AWL=0.002, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200509/234 X-Sequence-Number: 14542 On Sat, 2005-09-17 at 17:47 +0200, Antoine Bajolet wrote: > There are more tables around, but the heart of the search engine is > made of three tables : > > fiches (f_id int4, f_title varchar) 52445 rows > engine (f_id int4, k_id int4, weight ) 11761700 rows > keywords(k_id, keyword) 1072600 rows > > A "fiche" is linked to any kind of document. > The engine table counts how many times a keyword appears in a document. > > A query to search on one or two keywords is quick to execute (the > front-end creates thoses queries): > > Is there a specific reason the planner chooses this way ? Yes, you have an additional join for each new keyword, so there is more work to do. Recode your SQL with an IN subselect that retrieves all possible keywords before it accesses the larger table. That way you should have only one join for each new keyword. > Can whe do something on the postgresql configuration to avoid this ? > Can whe force the planner to use a hash join as it does for the first > joins ? Not required, IMHO. Best Regards, Simon Riggs