refreshRow is slow - experimenting with modified version - Mailing list pgsql-jdbc

From John T. Dow
Subject refreshRow is slow - experimenting with modified version
Date
Msg-id 0L1300FAESM3PUR3@vms173003.mailsrvcs.net
Whole thread Raw
In response to Re: Unit test patches  (John Lister <john.lister-ps@kickstone.com>)
List pgsql-jdbc
Here are my results after experimenting on refreshRow with the standard JDBC and a modified (and much faster) version
whichuses the names returned by the resultset (called "labels") instead of going to the catalog to get the actual
columnname (a very slow process). 

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

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


pgsql-jdbc by date:

Previous
From: "John T. Dow"
Date:
Subject: refreshRow is slow - revisited
Next
From: Dave Crooke
Date:
Subject: Getting rid of a cursor from JDBC .... Re: [PERFORM] Re: HELP: How to tame the 8.3.x JDBC driver with a biq guery result set