X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id DE9079FB1FC for ; Tue, 29 Aug 2006 04:38:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 37364-06 for ; Tue, 29 Aug 2006 04:38:13 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.177]) by postgresql.org (Postfix) with ESMTP id 75D149FB1F9 for ; Tue, 29 Aug 2006 04:38:13 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu3) with ESMTP (Nemesis), id 0MKxQS-1GHyAm0DVZ-0005ke; Tue, 29 Aug 2006 09:38:12 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1GHyAl-0007v9-00 for pgsql-performance@postgresql.org; Tue, 29 Aug 2006 09:38:11 +0200 Date: Tue, 29 Aug 2006 09:38:11 +0200 From: "A. Kretschmer" To: pgsql-performance@postgresql.org Subject: Re: Internal Operations on LIMIT & OFFSET clause Message-ID: <20060829073811.GA28883@localhost.localdomain> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.749 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS X-Spam-Level: X-Archive-Number: 200608/452 X-Sequence-Number: 20637 am Tue, dem 29.08.2006, um 12:51:27 +0530 mailte Vanitha Jaya folgendes: > Hi Friends, > > I have one doubt in LIMIT & OFFSET clause operation. > I have a table "test_limit", and it contain, First of all, you can use EXPLAIN ANALYSE for such tasks! test=*# explain analyse select * from mira limit 13; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..0.20 rows=13 width=12) (actual time=0.073..0.146 rows=13 loops=1) -> Seq Scan on mira (cost=0.00..2311.00 rows=150000 width=12) (actual time=0.068..0.097 rows=13 loops=1) Total runtime: 0.223 ms (3 rows) This is a Seq-Scan for the first 13 records. The table contains 15.000 records. > > I also tried ORDER BY clause as bellow. > SELECT * from test_limit ORDER BY s_no LIMIT 5; test=*# explain analyse select * from mira order by 1 limit 13; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------- Limit (cost=17263.70..17263.73 rows=13 width=12) (actual time=1149.554..1149.624 rows=13 loops=1) -> Sort (cost=17263.70..17638.70 rows=150000 width=12) (actual time=1149.548..1149.574 rows=13 loops=1) Sort Key: x -> Seq Scan on mira (cost=0.00..2311.00 rows=150000 width=12) (actual time=0.013..362.187 rows=150000 loops=1) Total runtime: 1153.545 ms (5 rows) This is a komplete seq-scan, than the sort, then the limit. > But, without ORDER BY clause I don't know how many record processing when > applying LIMIT clause. Here, with 8.1, it processed only LIMIT records, see my example and notice the runtime (0.223 ms versus 1153.545 ms). HTH, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net