Re: [HACKERS] What about LIMIT in SELECT ?

From: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
To: Jan Wieck <jwieck(at)debis(dot)com>
Cc: Eric Lee Green <eric(at)linux-hw(dot)com>, jeff(at)remapcorp(dot)com, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] What about LIMIT in SELECT ?
Date: 1998-10-14 13:59:56
Message-ID: 3624AE5C.752E4E7F@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-hackers

> I've done some tests and what I found out might be a bug in
> PostgreSQL's query optimizer.
> SELECT * FROM tab ORDER BY key;
> results in a sort->seqscan - I would have
> expected an indexscan!

Given that a table _could_ be completely unsorted on disk, it is
probably reasonable to suck the data in for a possible in-memory sort
rather than skipping around the disk to pick up individual tuples via
the index. Don't know if vacuum has a statistic on "orderness"...

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

- Tom

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Jan Wieck 1998-10-14 14:24:56 Re: [HACKERS] What about LIMIT in SELECT ?
Previous Message Oleg Bartunov 1998-10-14 12:53:53 Re: [HACKERS] What about LIMIT in SELECT ?

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 1998-10-14 14:24:56 Re: [HACKERS] What about LIMIT in SELECT ?
Previous Message Oleg Bartunov 1998-10-14 12:53:53 Re: [HACKERS] What about LIMIT in SELECT ?