X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E385ED1B175 for ; Fri, 18 Jun 2004 08:00:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17866-08 for ; Fri, 18 Jun 2004 11:00:49 +0000 (GMT) Received: from junk.nocrew.org (junk.nocrew.org [213.242.147.30]) by svr1.postgresql.org (Postfix) with ESMTP id D232BD1B169 for ; Fri, 18 Jun 2004 08:00:45 -0300 (ADT) Received: from tomas by junk.nocrew.org with local (Exim 3.35 #1 (Debian)) for pgsql-odbc@postgresql.org id 1BbH6x-0002ww-00; Fri, 18 Jun 2004 13:00:43 +0200 To: pgsql-odbc@postgresql.org Subject: Bad performance with large objects From: tomas@nocrew.org (Tomas =?iso-8859-1?q?Sk=E4re?=) Date: 18 Jun 2004 13:00:43 +0200 Message-ID: <80r7sd6sh0.fsf@junk.nocrew.org> Lines: 58 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/38 X-Sequence-Number: 4108 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