X-Original-To: pgsql-admin@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 1F9B847780C for ; Wed, 5 Mar 2003 04:54:56 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 85090-03 for ; Wed, 5 Mar 2003 04:54:54 -0500 (EST) Received: from c001.snv.cp.net (h021.c001.snv.cp.net [209.228.32.135]) by postgresql.org (Postfix) with SMTP id 14F3947722B for ; Tue, 4 Mar 2003 19:32:49 -0500 (EST) Received: (cpmta 11448 invoked from network); 4 Mar 2003 16:32:50 -0800 Received: from 209.228.32.123 (HELO mail.dilger.cc.criticalpath.net) by smtp.register-admin.com (209.228.32.135) with SMTP; 4 Mar 2003 16:32:50 -0800 X-Sent: 5 Mar 2003 00:32:50 GMT Received: from [216.68.146.219] by mail.dilger.cc with HTTP; Tue, 04 Mar 2003 16:32:38 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 7bit MIME-Version: 1.0 To: shreedhar@lucidindia.net Cc: pgsql-admin@postgresql.org From: "Nikolaus Dilger" Subject: Re: Can Any body discuss details of this Query Plan X-Sent-From: nikolaus@dilger.cc Date: Tue, 04 Mar 2003 16:32:38 -0800 (PST) X-Mailer: Web Mail 5.2.3-0_sol28 Message-Id: <20030304163250.4357.h009.c001.wm@mail.dilger.cc.criticalpath.net> X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/28 X-Sequence-Number: 7676 Sreedhar, You need to run VACUUM on a regular basis in order to have up-to-date database statistics for the PostgreSQL planner. The EXPLAIN command just has an estimation of how many rows will get processed and what the best way should be to execute the query. Without good table statistics this estimation can be completely wrong. You say that your tempaccountid table has only 10 rows. However, EXPLAIN shows the default of 1000 rows. You say that the table tblPermissions has about 70,000 rows. But before indexing PostgreSQL does not know that and again assumed the default. By indexing the tblPermissions table you updated its statistics and therefore the second EXPLAIN looks different. Regards, Nikolaus Dilger "shreedhar" wrote: > > pmdummy=# explain SELECT projectid FROM tblPermissions > pmdummy-# INNER JOIN tempaccountid ON > tempaccountid.accid = tblPermissions. > countid > pmdummy-# WHERE tblPermissions.topid = 3915; > > 1. tempaccountid (accid integer) no indexe or no > primary key > Number of Records 10 > 2. tblPermissions (accountid integer, raccountid > integer, topid integer) > primary key(accountid, raccountid) > Number of Records appoximately 70,0000 > > Before indexing on tblpermissions (topid) i got query > plan as > > > NOTICE: QUERY PLAN: > > Hash Join (cost=22.51..47.83 rows=25 width=12) > -> Seq Scan on tempaccountid (cost=0.00..20.00 > rows=1000 width=4) > -> Hash (cost=22.50..22.50 rows=5 width=8) > -> Seq Scan on tblpermissions > (cost=0.00..22.50 rows=5 width=8) > > EXPLAIN > > After indexing on tblpermissions (topid) i got query > plan as > > NOTICE: QUERY PLAN: > > Merge Join (cost=1345.76..1375.89 rows=2126 width=12) > -> Sort (cost=1275.93..1275.93 rows=425 width=8) > -> Index Scan using idx_tblpermissions_topid > on tblpermissions > (cost=0 > .00..1257.37 rows=425 width=8) > -> Sort (cost=69.83..69.83 rows=1000 width=4) > -> Seq Scan on tempaccountid > (cost=0.00..20.00 rows=1000 width=4) > > EXPLAIN > > But I could not under stand this statistics. Can any > body explain above. > > Thanks to all seniors and gurus, > > Sreedhar > > > "Faith, faith, faith in ourselves, faith, faith in God, > this is the secret > of greatness. > If you have faith in all the three hundred and thirty > millions of your > mythological gods, > and in all the gods which foreigners have now and again > introduced into your > midst, > and still have no faith in yourselves, there is no > salvation for you. " > (III. 190) > > > ---------------------------(end of > broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html