From: | "John T(dot) Dow" <john(at)johntdow(dot)com> |
---|---|
To: | "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | refreshRow is slow - experimenting with modified version |
Date: | 2010-04-19 03:05:32 |
Message-ID: | 0L1300FAESM3PUR3@vms173003.mailsrvcs.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Crooke | 2010-04-19 23:28:49 | 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 |
Previous Message | John T. Dow | 2010-04-18 02:47:21 | refreshRow is slow - revisited |