X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3E52F9DCD29 for ; Mon, 5 Dec 2005 19:04:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69874-05 for ; Mon, 5 Dec 2005 19:04:03 -0400 (AST) X-Greylist: delayed 00:52:08.840249 by SQLgrey- Received: from ylpvm15.prodigy.net (ylpvm15-ext.prodigy.net [207.115.57.46]) by postgresql.org (Postfix) with ESMTP id EAD419DCCDD for ; Mon, 5 Dec 2005 19:03:58 -0400 (AST) Received: from pimout5-ext.prodigy.net (pimout5-int.prodigy.net [207.115.4.21]) by ylpvm15.prodigy.net (8.12.10 outbound/8.12.10) with ESMTP id jB5N3oW6011185 for ; Mon, 5 Dec 2005 18:03:59 -0500 X-ORBL: [69.104.140.254] Received: from one (adsl-69-104-140-254.dsl.pltn13.pacbell.net [69.104.140.254]) by pimout5-ext.prodigy.net (8.13.4 outbound domainkey aix/8.13.4) with ESMTP id jB5N3eGi038436; Mon, 5 Dec 2005 18:03:40 -0500 Received: from [192.168.5.105] (unknown [192.168.5.105]) by one (Postfix) with ESMTP id 97FCDF1A40; Mon, 5 Dec 2005 15:03:39 -0800 (PST) Date: Mon, 5 Dec 2005 15:05:04 -0800 (PST) From: rm_pg@cheapcomplexdevices.com X-X-Sender: mayer@greenie.cheapcomplexdevices.com To: Tom Lane cc: rm_pg@cheapcomplexdevices.com, pgsql-performance@postgresql.org Subject: Re: Missed index opportunity for outer join? In-Reply-To: <3267.1133822299@sss.pgh.pa.us> Message-ID: References: <3267.1133822299@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.929 required=5 tests=[AWL=0.666, NO_REAL_NAME=0.55, RCVD_IN_NJABL_DUL=1.713] X-Spam-Score: 2.929 X-Spam-Level: ** X-Archive-Number: 200512/137 X-Sequence-Number: 15958 On Mon, 5 Dec 2005, Tom Lane wrote: > > Hm, I can't duplicate this in a simple test... > Can you try updating to 8.1 branch tip ... > Actually, a quick and dirty thing would be to try my would-be test case > below, and see if you get a seqscan on your copy. With your simple test-case I did not get the seqscan on 8.1.0. Output shown below that looks just like yours. I'll try upgrading a devel machine too - but will only be able to try on smalller test databases in the near term. > (Note to self: it is a bit odd that fac_id=261 is pushed down to become > an indexqual in one case but not the other ...) I speculate that the seq_scan wasn't really the slow part compared to not using using both parts of the index in the second part of the plan. The table point_features is tens of thousands of rows, while the table facets is tens of millions. Thanks, Ron =============================================================================== === Output of Tom's test case showing the same results he got. =============================================================================== greenie /home/pg2> createdb foo CREATE DATABASE greenie /home/pg2> psql foo [...] foo=# create table point_features(entity_id int, featureid int); CREATE TABLE foo=# create index point_features__featureid on point_features(featureid); CREATE INDEX foo=# create table facets(entity_id int, fac_id int); CREATE TABLE foo=# create index "fac_val(entity_id,fac_id)" on facets(entity_id,fac_id); CREATE INDEX foo=# set enable_hashjoin TO 0; SET foo=# set enable_mergejoin TO 0; SET foo=# explain select * from point_features upf join facets b on (b.entity_id = upf.entity_id and b.fac_id=261) where featureid in (120); QUERY PLAN -------------------------------------------------------------------------------------------------- Nested Loop (cost=1.03..49.15 rows=1 width=16) -> Bitmap Heap Scan on point_features upf (cost=1.03..10.27 rows=10 width=8) Recheck Cond: (featureid = 120) -> Bitmap Index Scan on point_features__featureid (cost=0.00..1.03 rows=10 width=0) Index Cond: (featureid = 120) -> Index Scan using "fac_val(entity_id,fac_id)" on facets b (cost=0.00..3.88 rows=1 width=8) Index Cond: ((b.entity_id = "outer".entity_id) AND (b.fac_id = 261)) (7 rows) foo=# explain select * from point_features upf left join facets b on (b.entity_id = upf.entity_id and b.fac_id=261) where featureid in (120); QUERY PLAN ------------------------------------------------------------------------------------------------- Nested Loop Left Join (cost=2.07..114.25 rows=10 width=16) -> Bitmap Heap Scan on point_features upf (cost=1.03..10.27 rows=10 width=8) Recheck Cond: (featureid = 120) -> Bitmap Index Scan on point_features__featureid (cost=0.00..1.03 rows=10 width=0) Index Cond: (featureid = 120) -> Bitmap Heap Scan on facets b (cost=1.03..10.27 rows=10 width=8) Recheck Cond: (b.entity_id = "outer".entity_id) Filter: (fac_id = 261) -> Bitmap Index Scan on "fac_val(entity_id,fac_id)" (cost=0.00..1.03 rows=10 width=0) Index Cond: (b.entity_id = "outer".entity_id) (10 rows) foo=#