Received: from dsh.de (neptun.sns-felb.debis.de [53.122.101.2]) by hub.org (8.8.8/8.8.8) with ESMTP id KAA23717 for ; Wed, 14 Oct 1998 10:26:13 -0400 (EDT) (envelope-from wieck@sapserv.debis.de) Received: by dsh.de; id QAA25644; Wed, 14 Oct 1998 16:28:01 +0200 (MET DST) Received: from dshmail.dsh.de(53.47.15.3) by neptun.dsh.de via smap (3.2) id xma025301; Wed, 14 Oct 98 16:27:43 +0200 Received: from mail1.hh1.dsh.de (mail1.hh1.dsh.de [53.47.9.5]) by dshmail.dsh.de (8.8.7/8.8.7) with ESMTP id QAA05943; Wed, 14 Oct 1998 16:24:42 +0200 (MET DST) Received: from mars.SAPserv.Hamburg.dsh.de (root@mail5.hh1.dsh.de [53.2.168.17]) by mail1.hh1.dsh.de (8.8.7/8.8.7) with SMTP id QAA22339; Wed, 14 Oct 1998 16:26:57 +0200 Received: from orion.SAPserv.Hamburg.dsh.de by mars.SAPserv.Hamburg.dsh.de with smtp for <> id m0zTPT8-000B5AC; Wed, 14 Oct 98 13:51 MET DST Received: by orion.SAPserv.Hamburg.dsh.de for lockhart@alumni.caltech.edu id m0zTS0m-000EBRC; Wed, 14 Oct 98 16:34 MET DST Message-Id: From: jwieck@debis.com (Jan Wieck) Subject: Re: [HACKERS] What about LIMIT in SELECT ? To: lockhart@alumni.caltech.edu (Thomas G. Lockhart) Date: Wed, 14 Oct 1998 16:34:47 +0200 (MET DST) Cc: jwieck@debis.com, eric@linux-hw.com, jeff@remapcorp.com, hackers@postgreSQL.org Reply-To: jwieck@debis.com (Jan Wieck) In-Reply-To: <3624AE5C.752E4E7F@alumni.caltech.edu> from "Thomas G. Lockhart" at Oct 14, 98 01:59:56 pm X-Mailer: ELM [version 2.4 PL25] Content-Type: text > > > SELECT * FROM tab WHERE key > 'G' ORDER BY key; > > results in a sort->indexscan - hmmm. > > The last one is the query we would need in the web > > environment used over a cursor as in the example above. But > > due to the sort, the backend selects until the end of the > > table, sorts them and then returns only the first 20 rows > > (out of sorts result). > > So you are saying that for this last case the sort was unnecessary? Does > the backend traverse the index in the correct order to guarantee that > the tuples are coming out already sorted? Does a hash index give the > same plan (I would expect a sort->seqscan for a hash index)? Good point! As far as I can see, the planner chooses index usage only depending on the WHERE clause. A hash index is only usable when the given qualification uses = on the indexed attribute(s). If the sortClause exactly matches the indexed attributes of the ONE used btree index and all operators request ascending order I think the index scan already returns the correct order. Who know's definitely? Addition to my last posting: ... and if the index scan is using a btree index ... Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #======================================== jwieck@debis.com (Jan Wieck) #