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 932C99DC81E for ; Wed, 14 Dec 2005 19:30:25 -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 22032-04 for ; Wed, 14 Dec 2005 19:30:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from linda-1.paradise.net.nz (bm-1a.paradise.net.nz [203.96.152.180]) by postgresql.org (Postfix) with ESMTP id DE7D89DCA36 for ; Wed, 14 Dec 2005 19:30:18 -0400 (AST) Received: from smtp-1.paradise.net.nz (tclsnelb1-src-1.paradise.net.nz [203.96.152.172]) by linda-1.paradise.net.nz (Paradise.net.nz) with ESMTP id <0IRI00MN2HAKLO@linda-1.paradise.net.nz> for pgsql-performance@postgresql.org; Thu, 15 Dec 2005 12:30:21 +1300 (NZDT) Received: from [192.168.1.11] (218-101-28-129.dsl.clear.net.nz [218.101.28.129]) by smtp-1.paradise.net.nz (Postfix) with ESMTP id 6437AFCF05A; Thu, 15 Dec 2005 12:30:20 +1300 (NZDT) Date: Thu, 15 Dec 2005 12:30:18 +1300 From: Mark Kirkwood Subject: Re: Simple Join In-reply-to: <200512141603.52583.blargity@gmail.com> To: Kevin Brown Cc: pgsql-performance@postgresql.org Message-id: <43A0AB0A.3000403@paradise.net.nz> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051106) References: <200512141603.52583.blargity@gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.444 required=5 tests=[AWL=0.444] X-Spam-Score: 0.444 X-Spam-Level: X-Archive-Number: 200512/340 X-Sequence-Number: 16161 Kevin Brown wrote: > I'll just start by warning that I'm new-ish to postgresql. > > I'm running 8.1 installed from source on a Debian Sarge server. I have a > simple query that I believe I've placed the indexes correctly for, and I > still end up with a seq scan. It makes sense, kinda, but it should be able > to use the index to gather the right values. I do have a production set of > data inserted into the tables, so this is running realistically: > > dli=# explain analyze SELECT ordered_products.product_id > dli-# FROM to_ship, ordered_products > dli-# WHERE to_ship.ordered_product_id = ordered_products.id AND > dli-# ordered_products.paid = TRUE AND > dli-# ordered_products.suspended_sub = FALSE; You scan 600000 rows from to_ship to get about 25000 - so some way to cut this down would help. Try out an explicit INNER JOIN which includes the filter info for paid and suspended_sub in the join condition (you may need indexes on each of id, paid and suspended_sub, so that the 8.1 optimizer can use a bitmap scan): SELECT ordered_products.product_id FROM to_ship INNER JOIN ordered_products ON (to_ship.ordered_product_id = ordered_products.id AND ordered_products.paid = TRUE AND ordered_products.suspended_sub = FALSE);