Re: [HACKERS] What about LIMIT in SELECT ? - Mailing list pgsql-hackers

From jwieck@debis.com (Jan Wieck)
Subject Re: [HACKERS] What about LIMIT in SELECT ?
Date
Msg-id m0zTVAt-000EBRC@orion.SAPserv.Hamburg.dsh.de
Whole thread Raw
In response to Re: [HACKERS] What about LIMIT in SELECT ?  (Bruce Momjian <maillist@candle.pha.pa.us>)
List pgsql-hackers
> But, you are correct that certain cases where in index is already being
> used on a query, you could just skip the sort IF you used the index to
> get the rows from the base table.

    Especially in the case where

        SELECT ... WHERE key > 'val' ORDER BY key;

    creates  a Sort->IndexScan plan. The index scan already jumps
    around on the disc to collect the sorts input  and  the  sort
    finally returns exactly the same output (if the used index is
    only on key).

    And this is the case for  large  tables.  The  planner  first
    decides  to  use  an  index  scan due to the WHERE clause and
    later it notices the ORDER BY clause and creates a sort  over
    the scan.

    I'm  actually  hacking  around on it to see what happens if I
    suppress the sort node in some cases.


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) #

pgsql-hackers by date:

Previous
From: Terry Mackintosh
Date:
Subject: Re: [HACKERS] What about LIMIT in SELECT ?
Next
From: "Taral"
Date:
Subject: RE: [HACKERS] What about LIMIT in SELECT ?