Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8273F632D3B for ; Thu, 14 Jan 2010 17:59:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 81778-10 for ; Thu, 14 Jan 2010 21:59:08 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 01E90633CE6 for ; Thu, 14 Jan 2010 17:59:08 -0400 (AST) Received: from 121-98-80-66.bitstream.orcon.net.nz ([121.98.80.66] helo=[192.168.1.168]) by tremor.opencloud.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NVXiY-0006dD-28; Fri, 15 Jan 2010 10:59:02 +1300 Message-ID: <4B4F93A4.4060601@opencloud.com> Date: Fri, 15 Jan 2010 10:59:00 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: "John T. Dow" CC: "pgsql-jdbc@postgresql.org" Subject: Re: refreshRow is slow References: <201001141502.o0EF2Ix3083876@web2.nidhog.com> In-Reply-To: <201001141502.o0EF2Ix3083876@web2.nidhog.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/17 X-Sequence-Number: 20213 John T. Dow wrote: > I am having no luck getting responses to a question I posted earlier about optimistic locking with multiple rows. > > I'll ask a more targeted question. How do I efficiently refresh a single row in a resultset? > > Suppose I allow users to view multiple records with TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY. > > The user might select one row or 1,000 rows and scroll back and forth at will. > > The user might choose to change one of the rows. I do this with a separate FOR UPDATE query. > > The update query will fetch the current row, which might be different from the row in the original resultset. My programming compares the two rows and can report to the user the differences. After the row has been updated, I need to refresh that row in the result set so that if the user continues to scroll back and forth, it will see the updated information. > > I am using refreshRow. I do setFetchSize(1) first. This works, but sometimes it is very slow. It can take many seconds over a remote connection. Can I fix that? What's going on? What's your original query? What's the query that the driver ends up synthesizing when you call refreshRow()? Have you run that query separately under EXPLAIN ANALYZE etc? Do you have knowledge of the structure of the original query (i.e. are you building it yourself, or is it user-supplied?) If you do, have you considered running suitable update/refresh query yourself directly? (The driver has limited knowledge of your database structure and may not be able to produce 'good' queries for update/refresh via the resultset interface) > Note: I don't want to use TYPE_SCROLL_SENSITIVE because it would update the row in the result set silently and I wouldn't be able to tell the user that somebody had changed anything. (Besides, I understand that TYPE_SCROLL_SENSITIVE doesn't work reliably.) From memory the driver doesn't implement TYPE_SCROLL_SENSITIVE at all (that type of resultset is quite strange..) -O