X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E57963A292C for ; Fri, 7 Jan 2005 20:04:59 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03469-05 for ; Fri, 7 Jan 2005 20:04:24 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.200]) by svr1.postgresql.org (Postfix) with ESMTP id 6E9123A4F75 for ; Fri, 7 Jan 2005 20:04:28 +0000 (GMT) Received: by wproxy.gmail.com with SMTP id 70so453579wra for ; Fri, 07 Jan 2005 12:04:28 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=WsSa51ERg+jwq9If+q9Wy2mj4RobcmOeTRPcpBMsYDXXlWzt4c403LDl+h7C9c9K6thAHGThff0LtW67QB2eHwEYvGkx/f2EuQlQEgrD+o9T40cbMyk1RZTifFJ9tnl57VSN//zcLWgGWToHcJvqu6fco7X/w+Q8p6KZwjIGLQE= Received: by 10.54.5.9 with SMTP id 9mr551029wre; Fri, 07 Jan 2005 12:04:28 -0800 (PST) Received: by 10.54.13.17 with HTTP; Fri, 7 Jan 2005 12:04:28 -0800 (PST) Message-ID: Date: Fri, 7 Jan 2005 15:04:28 -0500 From: David Jaquay Reply-To: David Jaquay To: josh@agliodbs.com Subject: Re: Query across a date range Cc: pgsql-performance@postgresql.org In-Reply-To: <200501071135.11229.josh@agliodbs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <20050107182106.6CBEC5AF685@svr4.postgresql.org> <200501071135.11229.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200501/81 X-Sequence-Number: 9771 'explain analyze' output is below. I have done analyze recently, and am using pg 7.4.2 on SuSE 9.1. I'd be curious to know how to "a nestloop indexscan" to try it out. Thanks, Dave mydb=> explain analyze select * from line_items t, sales_tickets s where writtenDate >= '12/01/2002' and writtenDate <= '12/31/2002' and t.ticketid = s.ticketId and s.storeId = 1; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- Hash Join (cost=93865.46..114054.74 rows=19898 width=28) (actual time=25419.088..32140.217 rows=23914 loops=1) Hash Cond: ("outer".ticketid = "inner".ticketid) -> Index Scan using line_items_written on line_items t (cost=0.00..3823.11 rows=158757 width=16) (actual time=100.621..3354.818 rows=169770 loops=1) Index Cond: ((writtendate >= '2002-12-01'::date) AND (writtendate <= '2002-12-31'::date)) -> Hash (cost=89543.50..89543.50 rows=626783 width=12) (actual time=22844.146..22844.146 rows=0 loops=1) -> Seq Scan on sales_tickets s (cost=0.00..89543.50 rows=626783 width=12) (actual time=38.017..19387.447 rows=713846 loops=1) Filter: (storeid = 1) Total runtime: 32164.948 ms (8 rows) On Fri, 7 Jan 2005 11:35:11 -0800, Josh Berkus wrote: > Can you run EXPLAIN ANALYZE instead of just EXPLAIN? That will show you the > discrepancy between estimated and actual costs, and probably show you what > needs fixing. Also, Tom Lane wrote: > Could we see EXPLAIN ANALYZE, not just EXPLAIN, results? > > Also, have you ANALYZEd lately? If the estimated row counts are at all > accurate, I doubt that forcing a nestloop indexscan would improve the > situation. > > Also, what PG version is this?