pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Slow performance updating CLOB data
10+ messages / 6 participants
[nested] [flat]

* Slow performance updating CLOB data
@ 2016-07-17 09:39 Nicola Zanaga <NZanaga@efsw.it>
  2016-07-17 16:42 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 2 replies; 10+ messages in thread

From: Nicola Zanaga @ 2016-07-17 09:39 UTC (permalink / raw)
  To: pgsql-jdbc

Hi, using ResultSet.updateCharacterStream to update a CLOB is very slow.

Most of the time is spent in method PgResultSet.isUpdateable  because the table has a primary key but doesn't have a "oid" column.

So the code tries to get primary keys from the query, using getMetaData().getPrimaryKeys.
This is a very slow process.

There is any workaround ?

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
@ 2016-07-17 16:42 ` Thomas Kellerer <spam_eater@gmx.net>
  1 sibling, 0 replies; 10+ messages in thread

From: Thomas Kellerer @ 2016-07-17 16:42 UTC (permalink / raw)
  To: pgsql-jdbc

Nicola Zanaga schrieb am 17.07.2016 um 11:39:
> Hi, using ResultSet.updateCharacterStream to update a CLOB is very slow.
>
> Most of the time is spent in method PgResultSet.isUpdateable  because the table has a primary key but doesn't have a "oid" column.
>
> So the code tries to get primary keys from the query, using getMetaData().getPrimaryKeys.
> This is a very slow process.
>
> There is any workaround ?

Are you using setCharacterStream()? Why aren't you using setString()?

Please show us the Java code.





-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
@ 2016-07-18 08:43 ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:53   ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Thomas Kellerer @ 2016-07-18 08:43 UTC (permalink / raw)
  To: pgsql-jdbc

Nicola Zanaga schrieb am 18.07.2016 um 10:13:
> Here a snippet:
> 
>         st= connection.createStatement(ResultSet.*/TYPE_FORWARD_ONLY/*, ResultSet.*/CONCUR_UPDATABLE/*);
>         ResultSet resultSet= st.executeQuery("SELECT id, data FROM TestClob1 WHERE id = 1 ");
> 
>  
>         resultSet.next();
>         resultSet.updateCharacterStream(2, *new*StringReader("hello"), "hello".length());
>         resultSet.updateRow();
>         resultSet.close();

Did you try resultSet.updateString(2, "hello") instead? 

> Most of the time is spent in method PgResultSet.isUpdateable  because the table has a primary key but doesn't have a "oid" column.
> So the code tries to get primary keys from the query, using getMetaData().getPrimaryKeys.

But in order to run an UPDATE on the table, the driver will need to retrieve the PK, there is no way around that. 
I guess using updateString() won't change that

Thomas



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-18 08:53   ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 10:34     ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Vladimir Sitnikov @ 2016-07-18 08:53 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc


‎Is there a reason of using updateable resultset?
Simple update table set... should work just fine.

PS. Having table -> PK cache in pgjdbc would be good.

‎Vladimir



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:53   ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-18 10:34     ` Dave Cramer <pg@fastcrypt.com>
  2016-07-18 11:48       ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Dave Cramer @ 2016-07-18 10:34 UTC (permalink / raw)
  To: Nicola Zanaga <NZanaga@efsw.it>; +Cc: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>; Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

On 18 July 2016 at 06:27, Nicola Zanaga <NZanaga@efsw.it> wrote:

> Thanks for the quick replies.
>
> I'm using updateable resultset only to update CLOB data.
> My application uses many databases. This method can be used with many
> driver (I think this is the "standard"  mode to update CLOB data).
>
> I took a look at the code in PgResultSet, and I think the driver will be
> slow with any operation on updateable resultset, because it will always
> call " isUpdateable()" to do any operation.
> So, in my opinion, this makes updateable resultset quite useless
>

Well all drivers have to do something similar. Not all result sets are
updatable. What do other drivers do ?

Dave Cramer

davec@postgresintl.com
www.postgresintl.com

>
>

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:53   ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 10:34     ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
@ 2016-07-18 11:48       ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 12:38         ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
  2016-07-18 13:01         ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 2 replies; 10+ messages in thread

From: Vladimir Sitnikov @ 2016-07-18 11:48 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; Nicola Zanaga <NZanaga@efsw.it>; +Cc: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

Dave>Well all drivers have to do something similar. Not all result sets are
updatable. What do other drivers do ?

Technically speaking, pgjdbc could cache the names of primary keys for a
given table.
It would be useful at least in two places:
1) updateable resultset
2) return generated keys

However, as of now no such cache exists in pgjdbc.
The second issue is the backend does not send notifications on DDL changes.
Thus the cache can easily get out of sync when java thinks there's a column
named A, and in reality the column was dropped long ago.

Vladimir

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:53   ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 10:34     ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
  2016-07-18 11:48       ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-18 12:38         ` Dave Cramer <pg@fastcrypt.com>
  2016-07-18 12:55           ` Re: Slow performance updating CLOB data Christopher BROWN <brown@reflexe.fr>
  1 sibling, 1 reply; 10+ messages in thread

From: Dave Cramer @ 2016-07-18 12:38 UTC (permalink / raw)
  To: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>; +Cc: Nicola Zanaga <NZanaga@efsw.it>; Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

On 18 July 2016 at 07:48, Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
wrote:

> Dave>Well all drivers have to do something similar. Not all result sets
> are updatable. What do other drivers do ?
>
> Technically speaking, pgjdbc could cache the names of primary keys for a
> given table.
> It would be useful at least in two places:
> 1) updateable resultset
> 2) return generated keys
>
> However, as of now no such cache exists in pgjdbc.
> The second issue is the backend does not send notifications on DDL
> changes. Thus the cache can easily get out of sync when java thinks there's
> a column named A, and in reality the column was dropped long ago.
>
> This error would happen far fewer times than the cache would help the
problem. I think if we can figure out how to gracefully recover from the
error we would be far further ahead.

Dave Cramer

davec@postgresintl.com
www.postgresintl.com

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:53   ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 10:34     ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
  2016-07-18 11:48       ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 12:38         ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
@ 2016-07-18 12:55           ` Christopher BROWN <brown@reflexe.fr>
  2016-07-18 19:42             ` Re: Slow performance updating CLOB data Gavin Flower <GavinFlower@archidevsys.co.nz>
  0 siblings, 1 reply; 10+ messages in thread

From: Christopher BROWN @ 2016-07-18 12:55 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>; Nicola Zanaga <NZanaga@efsw.it>; Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

Hello,

What would the scope and capacity of the cache be?  For example, scoped to
the lifetime of a (pooled) Connection, to that of Statement, or something
else, and how could the cache capacity be controlled (avoiding excessive
garbage collection pressure, etc.) and instrumented (cache hits/misses,
cache filling and emptying rates, etc.)?  Would it be possible for the
application to issue a command to clear the cache immediately if the
application is aware of structural changes (this can happen a lot in
development might lead to unexpected behavior)?

--
Christopher


On 18 July 2016 at 14:38, Dave Cramer <pg@fastcrypt.com> wrote:

>
>
>
>
> On 18 July 2016 at 07:48, Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
> wrote:
>
>> Dave>Well all drivers have to do something similar. Not all result sets
>> are updatable. What do other drivers do ?
>>
>> Technically speaking, pgjdbc could cache the names of primary keys for a
>> given table.
>> It would be useful at least in two places:
>> 1) updateable resultset
>> 2) return generated keys
>>
>> However, as of now no such cache exists in pgjdbc.
>> The second issue is the backend does not send notifications on DDL
>> changes. Thus the cache can easily get out of sync when java thinks there's
>> a column named A, and in reality the column was dropped long ago.
>>
>> This error would happen far fewer times than the cache would help the
> problem. I think if we can figure out how to gracefully recover from the
> error we would be far further ahead.
>
> Dave Cramer
>
> davec@postgresintl.com
> www.postgresintl.com
>

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:53   ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 10:34     ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
  2016-07-18 11:48       ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 12:38         ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
  2016-07-18 12:55           ` Re: Slow performance updating CLOB data Christopher BROWN <brown@reflexe.fr>
@ 2016-07-18 19:42             ` Gavin Flower <GavinFlower@archidevsys.co.nz>
  0 siblings, 0 replies; 10+ messages in thread

From: Gavin Flower @ 2016-07-18 19:42 UTC (permalink / raw)
  To: Christopher BROWN <brown@reflexe.fr>; Dave Cramer <pg@fastcrypt.com>; +Cc: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>; Nicola Zanaga <NZanaga@efsw.it>; Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

Please see comment at the end of this post...

On 19/07/16 00:55, Christopher BROWN wrote:
> Hello,
>
> What would the scope and capacity of the cache be?  For example, 
> scoped to the lifetime of a (pooled) Connection, to that of Statement, 
> or something else, and how could the cache capacity be controlled 
> (avoiding excessive garbage collection pressure, etc.) and 
> instrumented (cache hits/misses, cache filling and emptying rates, 
> etc.)?  Would it be possible for the application to issue a command to 
> clear the cache immediately if the application is aware of structural 
> changes (this can happen a lot in development might lead to unexpected 
> behavior)?
>
> --
> Christopher
>
>
> On 18 July 2016 at 14:38, Dave Cramer <pg@fastcrypt.com 
> <mailto:pg@fastcrypt.com>> wrote:
>
>
>
>
>
>     On 18 July 2016 at 07:48, Vladimir Sitnikov
>     <sitnikov.vladimir@gmail.com <mailto:sitnikov.vladimir@gmail.com>>
>     wrote:
>
>         Dave>Well all drivers have to do something similar. Not all
>         result sets are updatable. What do other drivers do ?
>
>         Technically speaking, pgjdbc could cache the names of primary
>         keys for a given table.
>         It would be useful at least in two places:
>         1) updateable resultset
>         2) return generated keys
>
>         However, as of now no such cache exists in pgjdbc.
>         The second issue is the backend does not send notifications on
>         DDL changes. Thus the cache can easily get out of sync when
>         java thinks there's a column named A, and in reality the
>         column was dropped long ago.
>
>     This error would happen far fewer times than the cache would help
>     the problem. I think if we can figure out how to gracefully
>     recover from the error we would be far further ahead.
>
>     Dave Cramer
>
>     davec@postgresintl.com <mailto:davec@postgresintl.com>
>     www.postgresintl.com <http://www.postgresintl.com/;
>
In this list, the convention is to post replies at the end (with some 
rare exceptions), or interspersed when appropriate, and to omit parts no 
longer relevant.

The motivation of bottom posting like this: is that people get to see 
the context before the reply, AND emails don't end up getting longer & 
longer as people reply at the beginning forgetting to trim the now 
irrelevant stuff at the end.


Cheers,
Gavin


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Slow performance updating CLOB data
  2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
  2016-07-18 08:43 ` Re: Slow performance updating CLOB data Thomas Kellerer <spam_eater@gmx.net>
  2016-07-18 08:53   ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-18 10:34     ` Re: Slow performance updating CLOB data Dave Cramer <pg@fastcrypt.com>
  2016-07-18 11:48       ` Re: Slow performance updating CLOB data Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-18 13:01         ` Thomas Kellerer <spam_eater@gmx.net>
  1 sibling, 0 replies; 10+ messages in thread

From: Thomas Kellerer @ 2016-07-18 13:01 UTC (permalink / raw)
  To: pgsql-jdbc

Nicola Zanaga schrieb am 18.07.2016 um 14:28:
> 
> I can change strategy for postgres, but I don’t think is good to issue a query 
> like “UPDATE table SET clob = ‘value’ WHERE key = x” if value is more than 10Mb.
> 
You should use a PreparedStatement not string literals. 
But apart from that, that won't be any different to the SQL that the driver uses.

Why do you think that would be a problem? 
The client needs to send 10MB of data, regardless on _how_ it sends that. 

Thomas



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2016-07-18 19:42 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-17 09:39 Slow performance updating CLOB data Nicola Zanaga <NZanaga@efsw.it>
2016-07-17 16:42 ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-18 08:43 ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-18 08:53   ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-18 10:34     ` Dave Cramer <pg@fastcrypt.com>
2016-07-18 11:48       ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-18 12:38         ` Dave Cramer <pg@fastcrypt.com>
2016-07-18 12:55           ` Christopher BROWN <brown@reflexe.fr>
2016-07-18 19:42             ` Gavin Flower <GavinFlower@archidevsys.co.nz>
2016-07-18 13:01         ` Thomas Kellerer <spam_eater@gmx.net>

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