X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 31AEACDB52 for ; Fri, 11 Jul 2003 21:10:50 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 17249-07 for ; Fri, 11 Jul 2003 21:11:05 +0000 (GMT) Received: from mail-2.zoominternet.net (unknown [63.67.120.12]) by svr1.postgresql.org (Postfix) with SMTP id 28F62CC63D for ; Fri, 11 Jul 2003 10:17:23 -0300 (ADT) Received: (qmail 6943 invoked from network); 11 Jul 2003 13:17:37 -0000 Received: from acs-24-154-209-142.zoominternet.net (HELO gmod.lajolla) ([24.154.209.142]) (envelope-sender ) by mail-2.zoominternet.net (qmail-ldap-1.03) with SMTP for ; 11 Jul 2003 13:17:37 -0000 Subject: Re: force the use of a particular index From: Scott Cain To: Rod Taylor Cc: Postgresql Performance In-Reply-To: <1057920672.46100.149.camel@jester> References: <1057850280.1451.22.camel@localhost.localdomain> <1057920672.46100.149.camel@jester> Content-Type: text/plain Organization: Cold Spring Harbor Lab Message-Id: <1057929459.5766.7.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 11 Jul 2003 09:17:40 -0400 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/183 X-Sequence-Number: 2476 The problem (at least as it appears to me) is not that it is performing a table scan instead of an index scan, it is that it is using the wrong index. Here is the output from EXPLAIN ANALYZE: QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ Unique (cost=494008.47..494037.59 rows=166 width=54) (actual time=114660.37..114660.38 rows=1 loops=1) -> Sort (cost=494008.47..494012.63 rows=1664 width=54) (actual time=114660.37..114660.37 rows=1 loops=1) Sort Key: f.name, fl.fmin, fl.fmax, fl.strand, f.type_id, f.feature_id -> Nested Loop (cost=0.00..493919.44 rows=1664 width=54) (actual time=2596.13..114632.90 rows=1 loops=1) -> Index Scan using feature_pkey on feature f (cost=0.00..134601.43 rows=52231 width=40) (actual time=105.74..56048.87 rows=13825 loops=1) Filter: (type_id = 219) -> Index Scan using featureloc_idx1 on featureloc fl (cost=0.00..6.87 rows=1 width=14) (actual time=4.23..4.23 rows=0 loops=13825) Index Cond: ("outer".feature_id = fl.feature_id) Filter: ((srcfeature_id = 6) AND (fmin <= 2585581) AND (fmax >= 2565581)) Total runtime: 114660.91 msec This is the same regardless of enable_seqscan's setting. The index that it is using on featureloc (featureloc_idx1) is on the foreign key feature_id. It should instead be using another index, featureloc_idx3, which is built on (srcfeature_id, fmin, fmax). I should also mention that I've done a VACUUM FULL ANALYZE on this database, and I've been using it for a while, and this is the primary type of query I perform on the database. Thanks, Scott On Fri, 2003-07-11 at 06:51, Rod Taylor wrote: > On Thu, 2003-07-10 at 15:18, Scott Cain wrote: > > Hello, > > > > I am wondering if there is a way to force the use of a particular index > > when doing a query. I have two tables that are pretty big (each >3 > > million rows), and when I do a join between them the performance is > > generally quite poor as it does not use the indexes that I think it > > should use. Here is an example query: > > Please send the EXPLAIN ANALYZE results for that query with and without > sequential scans enabled. > > set enable_seqscan = true; > EXPLAIN ANALYZE ; > > set enable_seqscan = false; > EXPLAIN ANALYZE ; -- ------------------------------------------------------------------------ Scott Cain, Ph. D. cain@cshl.org GMOD Coordinator (http://www.gmod.org/) 216-392-3087 Cold Spring Harbor Laboratory