X-Original-To: pgsql-general@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 2A95E475B99 for ; Thu, 13 Feb 2003 20:47:53 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 3113E475CC7 for ; Thu, 13 Feb 2003 20:47:33 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h1E1lW5u003082; Thu, 13 Feb 2003 20:47:32 -0500 (EST) To: Greg Stark Cc: Stephan Szabo , pgsql-general@postgresql.org Subject: Re: index scan with index cond on first column doesn't recognize sort order of second column In-reply-to: <87isvnk708.fsf@stark.dyndns.tv> References: <20030213113156.T47380-100000@megazone23.bigpanda.com> <87u1f7kf1y.fsf@stark.dyndns.tv> <1915.1045178941@sss.pgh.pa.us> <87isvnk708.fsf@stark.dyndns.tv> Comments: In-reply-to Greg Stark message dated "13 Feb 2003 20:04:07 -0500" Date: Thu, 13 Feb 2003 20:47:32 -0500 Message-ID: <3081.1045187252@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/752 X-Sequence-Number: 37506 Greg Stark writes: > 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. Yes. The appropriate way to recognize that (without breaking things) is to consider that the indexscan generates pathkeys (col2) because col1 can be assumed constant. This is not truncate_useless_pathkeys's business, however. It would have to be done in the code that creates the indexscan path to begin with. (Ideally, we'd mark the path to show that it could be considered to have either sort ordering (col1, col2) or sort ordering (col2), so that it could match to either requirement. I'm not sure if that's feasible with the current datastructures though. Might have to make two copies of the path :-() > I'm not clear on how removing the suffix is ever useful. It reduces the number of alternatives that add_path will keep track of, thus making for a combinatorial reduction in the cost of planning. Actually you are barking up the wrong tree entirely; I'm pretty certain that truncate_useless_pathkeys *doesn't* remove this pathkey, because it should notice that it is relevant to the mergejoin condition. regards, tom lane