X-Original-To: pgsql-general@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 995A4475D0D for ; Thu, 13 Feb 2003 20:04:37 -0500 (EST) Received: from sabre.velocet.net (sabre.velocet.net [216.138.209.205]) by postgresql.org (Postfix) with ESMTP id A159A475A6D for ; Thu, 13 Feb 2003 20:04:18 -0500 (EST) Received: from stark.dyndns.tv (H162.C233.tor.velocet.net [216.138.233.162]) by sabre.velocet.net (Postfix) with ESMTP id 302EE1381D2; Thu, 13 Feb 2003 20:04:16 -0500 (EST) Received: from localhost ([127.0.0.1] helo=stark.dyndns.tv ident=foobar) by stark.dyndns.tv with smtp (Exim 3.36 #1 (Debian)) id 18jUGx-0001lb-00; Thu, 13 Feb 2003 20:04:11 -0500 To: Tom Lane Cc: Greg Stark , Stephan Szabo , pgsql-general@postgresql.org Subject: Re: index scan with index cond on first column doesn't recognize sort order of second column References: <20030213113156.T47380-100000@megazone23.bigpanda.com> <87u1f7kf1y.fsf@stark.dyndns.tv> <1915.1045178941@sss.pgh.pa.us> In-Reply-To: <1915.1045178941@sss.pgh.pa.us> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 13 Feb 2003 20:04:07 -0500 Message-ID: <87isvnk708.fsf@stark.dyndns.tv> Lines: 35 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/751 X-Sequence-Number: 37505 Tom Lane writes: > Greg Stark writes: > > I'm not clear on what truncate_useless_pathkeys is doing. > > It's throwing away pathkey info that isn't relevant for the current > query (and would cause the planner to consider a multi-column-index > scan as better-ordered than a scan of an index with fewer columns, > when no such thing is true if the extra columns aren't relevant). But it might be better ordered. I think you may have missed the original context. In a query like: SELECT * FROM table_a join table_b using (col2) WHERE a.col1 = $0 Where there's an index on table_a(col1,col2) could use a merge join without a sort. Having truncate_useless_pathkeys removing the prefix means removing col2 from the pathkeys leaving col1. In fact once the restriction is taken into account the ordering of the path is in fact simply col2, which is just what's needed for the mergejoin. > > If it were changed to just keep the suffix would that break other things? > > Yes, that would be completely backwards. I'm not clear on how removing the suffix is ever useful. Even in a query like: SELECT * FROM table_a join table_b using (col1,col2) WHERE a.col1 between $0 and $1 The suffix is still relevant, the merge join is still possible. -- greg