X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 00DF63A1EC4 for ; Tue, 9 Nov 2004 16:54:10 +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 85931-08 for ; Tue, 9 Nov 2004 16:54:00 +0000 (GMT) Received: from lucifer.oficina (unknown [200.68.121.201]) by svr1.postgresql.org (Postfix) with ESMTP id 6C8EB3A3D1A for ; Tue, 9 Nov 2004 16:53:58 +0000 (GMT) Received: from localhost (localhost.akyasociados.com.ar [127.0.0.1]) by lucifer.oficina (8.13.1/8.12.10) with ESMTP id iA9GrsZf073878; Tue, 9 Nov 2004 13:53:54 -0300 (ART) (envelope-from franco@akyasociados.com.ar) Received: from lucifer.oficina ([127.0.0.1]) by localhost (lucifer.oficina [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 72682-05-4; Tue, 9 Nov 2004 13:53:54 -0300 (ART) Received: from [192.168.1.168] ([192.168.1.168]) (authenticated bits=0) by lucifer.oficina (8.13.1/8.12.10) with ESMTP id iA9Gr16E073840; Tue, 9 Nov 2004 13:53:03 -0300 (ART) (envelope-from franco@akyasociados.com.ar) Message-ID: <4190F5ED.1010808@akyasociados.com.ar> Date: Tue, 09 Nov 2004 13:53:01 -0300 From: Franco Bruno Borghesi User-Agent: Mozilla Thunderbird 0.9 (X11/20041108) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andras Kutrovics Cc: pgsql-sql@postgresql.org Subject: Re: Simple SQL Question References: <418BB051.6070808@freemail.hu> <1099678157.39887.15.camel@taz.oficina> <41908AE6.80202@freemail.hu> In-Reply-To: <41908AE6.80202@freemail.hu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at akyasociados.com.ar X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/86 X-Sequence-Number: 19405 Didn't know about the seqscan problem when using ORs. But you still can split the query in two, and then use Union to join the results: SELECT .... WHERE itemKey=:lastItemKey AND location>:lastLocation UNION SELECT ... WHERE itemKey>:lastItemKey You could solve the OFFSET/LIMIT modification problem if you could keep the transaction open, but I don't know if it's applicable in your case. Andras Kutrovics wrote: > Franco Bruno Borghesi wrote: > > > Hi! > > Sorry for being late with the answer, I was busy at one of our customer;) > >> wouldn't it be easier using offset & limit?: you always select from >> the table with an itemkey,location order by clause. You save the >> current offset between requests, and for every request you re-execute >> the query with a different offset. > > Sure, but sometimes I have to query by name, and dont want to create > another query component. > >> If you still want to go with what you already have, you should keep >> the lastItemKey and lastLocaltion values between requests, and your >> where clause should be something like: >> WHERE (itemKey=:lastItemKey AND location>:lastLocation) OR >> (itemKey>:lastItemKey) > > > It works perfectly, but I have to consider the performance issue, > because if i use 'or' statement, postgres doesn't use index scan, > and I also have tables with 3 or more keys and 500.000 records , where > the performance of this method is poor. > Maybe I will end up using limit and offset in case of incremental > fetching,but if the table is modified between requests, it can behave > weird. > Is there a perfect solution to this? > > Sorry for the english > > Thank you again, > > Andras Kutrovics > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >