X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0B7163A47A5; Fri, 21 Jan 2005 09:21:24 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81936-01; Fri, 21 Jan 2005 09:21:10 +0000 (GMT) Received: from ar-sd.net (unknown [82.77.155.72]) by svr1.postgresql.org (Postfix) with ESMTP id 27C023A4788; Fri, 21 Jan 2005 09:21:11 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id 15FF32126D; Fri, 21 Jan 2005 11:16:44 +0200 (EET) Received: from ar-sd.net ([127.0.0.1]) by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 20649-06; Fri, 21 Jan 2005 11:16:42 +0200 (EET) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id 58C6F1E9D4; Fri, 21 Jan 2005 11:16:07 +0200 (EET) Message-ID: <00c001c4ff9a$809918e0$0b00a8c0@forge> From: "Andrei Bintintan" To: =?iso-8859-1?Q?Ragnar_Hafsta=F0?= , Cc: References: <019f01c4fee1$1b58d600$0b00a8c0@forge> <41EF9FD3.5020400@archonet.com> <020d01c4fef6$595bb9d0$0b00a8c0@forge> <87pt00c9zd.fsf@stark.xeocode.com> <1106248326.22416.22.camel@localhost.localdomain> <1106248992.22416.25.camel@localhost.localdomain> Subject: Re: [SQL] OFFSET impact on Performance??? Date: Fri, 21 Jan 2005 11:20:48 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at ar-sd.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.017 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/378 X-Sequence-Number: 10068 Now I read all the posts and I have some answers. Yes, I have a web aplication. I HAVE to know exactly how many pages I have and I have to allow the user to jump to a specific page(this is where I used limit and offset). We have this feature and I cannot take it out. >> > SELECT * FROM tab WHERE col > ? ORDER BY col LIMIT 50 Now this solution looks very fast, but I cannot implement it, because I cannot jump from page 1 to page xxxx only to page 2. Because I know with this type where did the page 1 ended. And we have some really complicated where's and about 10 tables are involved in the sql query. About the CURSOR I have to read more about them because this is my first time when I hear about. I don't know if temporary tables are a solution, really I don't think so, there are a lot of users that are working in the same time at the same page. So... still DIGGING for solutions. Andy. ----- Original Message ----- From: "Ragnar Hafstaš" To: Cc: "Andrei Bintintan" ; Sent: Thursday, January 20, 2005 9:23 PM Subject: Re: [PERFORM] [SQL] OFFSET impact on Performance??? > On Thu, 2005-01-20 at 19:12 +0000, Ragnar Hafstaš wrote: >> On Thu, 2005-01-20 at 11:59 -0500, Greg Stark wrote: >> >> > The best way to do pages for is not to use offset or cursors but to use >> > an >> > index. This only works if you can enumerate all the sort orders the >> > application might be using and can have an index on each of them. >> > >> > To do this the query would look something like: >> > >> > SELECT * FROM tab WHERE col > ? ORDER BY col LIMIT 50 >> > >> > Then you take note of the last value used on a given page and if the >> > user >> > selects "next" you pass that as the starting point for the next page. >> >> this will only work unchanged if the index is unique. imagine , for >> example if you have more than 50 rows with the same value of col. >> >> one way to fix this is to use ORDER BY col,oid > > and a slightly more complex WHERE clause as well, of course > > gnari > > >