Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A25F8476932 for ; Sun, 12 Jan 2003 11:48:58 -0500 (EST) Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id 01BA947692E for ; Sun, 12 Jan 2003 11:48:57 -0500 (EST) Received: (qmail 31370 invoked by uid 500); 12 Jan 2003 17:01:08 -0000 Date: Sun, 12 Jan 2003 11:01:08 -0600 From: Bruno Wolff III To: Gaetano Mendola Cc: pgsql-admin@postgresql.org Subject: Re: Query optimization path Message-ID: <20030112170108.GB31080@wolff.to> Mail-Followup-To: Gaetano Mendola , pgsql-admin@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/109 X-Sequence-Number: 6951 On Sun, Jan 12, 2003 at 17:31:34 +0100, Gaetano Mendola wrote: > Hi all, > > I have the following query: > > SELECT count(1) > FROM providers p JOIN class_default cd USING (id_provider) > JOIN user_data ud USING (id_class) > JOIN v_user_traffic ut USING (id_user) > WHERE id_user_status in (4,5) AND > p.company = 'XXXXX'; > > is not slow but I notice that if I do explain analyze with the table > reordered > inside the select in another way the cost change. Using "JOIN" fixes the order that tables are joined in. If you are just doing inner joins, then you probably don't want to use the "JOIN" keyword. The exception being when there are so many tables being joined that you want to manually specify at least some of the join ordering in order to help out the planner. Outer (and left and right) joins are generally not associative, so the "JOIN" keyword being required for those cases isn't generally going to be a problem.