pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tomas@nocrew.org
To: pgsql-odbc@postgresql.org
Subject: Bad performance with large objects
Date: 18 Jun 2004 13:00:43 +0200
Message-ID: <80r7sd6sh0.fsf@junk.nocrew.org> (raw)

Hi,

I'm using psqlodbc (latest from CVS) together with PostgreSQL 7.4.3 in
a project. In it, I have a table that uses large objects (type
"lo"). Functions for lo was imported from the contrib/lo-script.

The table looks like this:

 timestamp | bigint            | not null
 jobid     | bigint            | not null
 objectid  | bigint            | not null
 class     | integer           | not null
 field     | character varying | not null
 data      | lo                |

The idea is that each object consists of a number of fields with
corresponding lo-data. The program is responsible for putting together
the fields to full objects. There is also a timestamp, to be able to
have history of changes of objects.

To this, I have a statement that picks out the latest timestamp for
each field of each object:

SELECT objectid,class,field,data
FROM cjm_object t1
WHERE EXISTS (SELECT MAX(timestamp) FROM cjm_object
              WHERE objectid=t1.objectid AND class=t1.class
              AND field=t1.field
              GROUP BY objectid,class,field
              HAVING t1.timestamp=MAX(timestamp))
AND data IS NOT NULL
ORDER BY objectid,class,field;

So far so good, this works well. With about 2300 rows (about 2200
active, and 100 old changes), explain analyze in psql says that this
query takes about 300ms on my machine. I've also made a view that
picks out the lo-data as bytea (from pg_largeobject) instead, and this
takes about 700ms.

Now, when I run this query from my program through ODBC, using
SQLFetch (or SQLFetchScroll) to get the data, some 100 rows at a time,
it all takes about 6 seconds instead. I've tried to set different
rowset sizes, only use FETCH_NEXT, tried to optimize for sequential
fetching, but it won't get under at least 5 seconds for the whole
operation.

So, why does it take so much longer from ODBC, than from psql (even if
I pick out the bytea-data)? The program and postgresql both run on the
same machine, so there is no network delay. I've measured that it's
not my program that is slow, it's the ODBC calls.

I'm very thankful for any help to speed this up.


Greetings,

Tomas




view thread (2+ messages)  latest in thread

Message-ID: <80r7sd6sh0.fsf@junk.nocrew.org>
Permalink:  ../80r7sd6sh0.fsf@junk.nocrew.org/
Also on:    postgresql.org/message-id/80r7sd6sh0.fsf@junk.nocrew.org

 · 

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-odbc@postgresql.org
  Cc: tomas@nocrew.org
  Subject: Re: Bad performance with large objects
  In-Reply-To: <80r7sd6sh0.fsf@junk.nocrew.org>
  References: <80r7sd6sh0.fsf@junk.nocrew.org>

* 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