X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 3BBFFD1B523 for ; Tue, 7 Oct 2003 16:24:05 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 48105-03 for ; Tue, 7 Oct 2003 13:23:15 -0300 (ADT) Received: from unimm.unisoftbg.com (mail.unisoftbg.com [194.12.229.207]) by svr1.postgresql.org (Postfix) with ESMTP id 63D76D1B54D for ; Tue, 7 Oct 2003 13:23:12 -0300 (ADT) Received: (qmail 30394 invoked by uid 507); 7 Oct 2003 16:27:32 -0000 Received: from unknown (HELO t1.unisoftbg.com) (pginfo%t1.unisoftbg.com@194.12.229.193) by 0 with SMTP; 7 Oct 2003 16:27:32 -0000 Message-ID: <3F82D873.D6AD4C56@t1.unisoftbg.com> Date: Tue, 07 Oct 2003 17:14:59 +0200 From: pginfo X-Mailer: Mozilla 4.03 [en] (Win95; I) MIME-Version: 1.0 To: Tomasz Myrta Cc: "pgsql-sql@postgresql.org" Subject: Re: Interest query plan References: <3F82D4FE.DD4E275B@t1.unisoftbg.com> <3F82E734.8060003@klaster.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/81 X-Sequence-Number: 15481 explain analyze select * from a_doc D left outer join A_SKLAD S ON(D.IDS=S.IDS_DOC) left join A_MED M ON(S.IDS_MED=M.IDS) where d.IDS='SOF_700060'; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------- Hash Join (cost=1.26..80.55 rows=6 width=2091) (actual time=1.09..1.11 rows=1 loops=1) Hash Cond: ("outer".ids_med = "inner".ids) -> Nested Loop (cost=0.00..79.18 rows=6 width=2056) (actual time=0.40..0.41 rows=1 loops=1) -> Index Scan using a_doc_pkey on a_doc d (cost=0.00..3.61 rows=1 width=1344) (actual time=0.14..0.14 rows=1 loops=1) Index Cond: (ids = 'SOF_700060'::name) -> Index Scan using i_sklad_ids_doc on a_sklad s (cost=0.00..75.31 rows=22 width=712) (actual time=0.12..0.13 rows=1 loops=1) Index Cond: ("outer".ids = s.ids_doc) -> Hash (cost=1.21..1.21 rows=21 width=35) (actual time=0.19..0.19 rows=0 loops=1) -> Seq Scan on a_med m (cost=0.00..1.21 rows=21 width=35) (actual time=0.07..0.15 rows=21 loops=1) Total runtime: 1.82 msec (10 rows) I thinked that a_sklad join a_med ... will help, but.... Tomasz Myrta wrote: > > Hi all, > > I am running pg 7.3.1. > > My query is very simple but pg generates not the best possible plan for > > me: > > analyze select * from a_doc D left outer join (A_SKLAD S join A_MED M > > ON(S.IDS_MED=M.IDS) )on( d.IDS=s.IDS_DOC) where d.IDS='SOF_700060'; > What about: > > select * from a_doc D > left join A_SKLAD S on(d.IDS=s.IDS_DOC) > left join A_MED M ON(S.IDS_MED=M.IDS) > where d.IDS='SOF_700060' > > ? > > Regards, > Tomasz Myrta