pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John T. Dow <john@johntdow.com>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: refreshRow is slow - experimenting with modified version
Date: Sun, 18 Apr 2010 23:05:32 -0400
Message-ID: <0L1300FAESM3PUR3@vms173003.mailsrvcs.net> (raw)
In-Reply-To: <49FDDA33.5070009@kickstone.com>

Here are my results after experimenting on refreshRow with the standard JDBC and a modified (and much faster) version which uses the names returned by the resultset (called "labels") instead of going to the catalog to get the actual column name (a very slow process).

I tested three resultsets: straight column names, an alias that merely renames a column, and an alias that names an expression result.

Both versions handle straight column names but the modified version fails when a column is renamed. 

This is interesting: Both fail if there's an expression.

Create table

    create table testdb (
      recno         serial primary key,
      name          varchar,
      sum           decimal,
      count         decimal);

Load/reload table
    delete from testdb;
    insert into testdb(name,sum,count) values ('Able',100,5);
    insert into testdb(name,sum,count) values ('Baker',200,3);
    insert into testdb(name,sum,count) values ('Caty',50,2);

The experiment

    Create a resultset using each of these three queries

        1   select name, sum, recno from testdb

        2   select name, sum as sumalias, recno from testdb

        3   select name, sum / count as avg, recno from testdb

    For each, position at the second row (Baker) and update the name,
    then try to refresh the row and see what happens.

    Standard JDBC's refreshRow does this for each column

            selectSQL.append( fields[i].getColumnName(connection) );

    and the modified JDBC does this

            selectSQL.append( fields[i].getColumnLabel() );

Experimental results for the three resultsets.

    1   Both versions of JDBC did the same thing with straight column names.

    2   The modified version failed because sumalias is not a column name.

    3   Both failed because of the expression.

Discussion
    Using the modified version is essentially as good as the standard version
    if one doesn't use aliases just to rename columns (without expressions).
    Eg if you do    select * from table   you're ok.

    Both fail with expressions, so the standard JDBC is no better than the
    modified JDBC.

Question

    Isn't the best solution to reuse the original query instead of either the
    column name or label? That would deliver the average as was intended by
    the original select.

John




Message-ID: <0L1300FAESM3PUR3@vms173003.mailsrvcs.net>
Permalink:  ../0L1300FAESM3PUR3@vms173003.mailsrvcs.net/
Also on:    postgresql.org/message-id/0L1300FAESM3PUR3@vms173003.mailsrvcs.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: john@johntdow.com
  Subject: Re: refreshRow is slow - experimenting with modified version
  In-Reply-To: <0L1300FAESM3PUR3@vms173003.mailsrvcs.net>
  References: <49FDDA33.5070009@kickstone.com> <0L1300FAESM3PUR3@vms173003.mailsrvcs.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox