LIMIT and OFFSET

From: "Samuel J(dot) Sutjiono" <ssutjiono(at)wc-group(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>, <pgsql-general(at)postgresql(dot)org>
Subject: LIMIT and OFFSET
Date: 2002-03-01 16:24:49
Message-ID: 007201c1c13d$9c4b7040$110a010a@headquarters.wcgroup.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Hello all,

I am trying to understand how LIMIT and OFFSET work so I will use the best technique in my search stored procedures (function). Here are my codes:

Scenario:
There are 1,000,000 records in the catalog table and the result set is sorted by Price. All the search fields are indexed.

SELECT * from Catalog where ((VendorName ~* 'dvd|gladiator') or
(ProductModelName ~* 'dvd|gladiator') or
(ProductCategory ~* 'dvd|gladiator') or
(ProductDescr ~* 'dvd|gladiator')) and
(ProductMfr ILIKE 'sony')
ORDER BY Price
LIMIT 10 OFFSET 0

Questions:
1. If the search results in 50,000 rows, does the query dump all the rows to memory ?
2. Does the query do the search until it hits the 1,000,000th record and return the first 10 rows ?
3. If I set OFFSET to 10 (LIMIT 10 OFFSET 10), what is the query process ?
4. If I remove the sort, does the query do the same thing ?

I also need advice about the options that I have and if anybody can recommend the best technique in dealing with searches on large table. I really appreciate your help.

Best Regards,
Samuel

Browse pgsql-general by date

  From Date Subject
Next Message Miguel A. =?ISO-8859-1?Q?Ar=E9valo?= 2002-03-01 16:29:25 Clues about tables fileformat
Previous Message Mark Rae 2002-03-01 16:14:45 Aborting transaction on error

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2002-03-01 17:36:12 Re: About persistent connections...
Previous Message Gary Stainburn 2002-03-01 16:06:12 Re: About persistent connections...