pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tyler Ward <tjw19@columbia.edu>
To: pgsql-admin@postgresql.org, Tyler Ward <tward@janestcapital.com>
Subject: Problem with inserts from subselects
Date: Fri, 23 Apr 2004 10:30:13 -0400
Message-ID: <40892875.70409@columbia.edu> (raw)




I'm using postgres 7.3.x (the default installed on Fedora Core 1) and 
I'm running into a serious
bug in the insert performance.

When I try a query like this...

<snip>

INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size)
(
   select tmp.session, tmp.sent, tmp.data_row, tmp.direction_id, i.id, 
tmp.price, tmp.size
   FROM table_b tmp
   INNER JOIN table_c i ON i.symbol_id = tmp.symbol_id AND i.route_id = 
tmp.route_id
   LIMIT 10
);

</snip>

the performance is really slow, that query takes about 10 seconds to 
run. If I raise the limit to 100, it takes
10 times longer, etc.... It is basically so slow that we can't use our 
database at all. However, if I just run the
inner select, like this....

<snip>
   select tmp.session, tmp.sent, tmp.data_row, tmp.direction_id, i.id, 
tmp.price, tmp.size
   FROM table_b tmp
   INNER JOIN table_c i ON i.symbol_id = tmp.symbol_id AND i.route_id = 
tmp.route_id
   LIMIT 10
</snip>

The result returns basically instantly, in less than half a second.

If I just insert the data by hand....

<snip>
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820183, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820184, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820185, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820186, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820187, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820188, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820189, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820190, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820191, 1, 852, 1.0, 10);
INSERT INTO table_a (session, sent, data_row, direction_id, instrument, 
price, size) VALUES (1, NOW(), 820192, 1, 852, 1.0, 10);
</snip>

then it's fast again. The above query finishes all ten inserts in less 
than half a second.

So it seems that the problem only occurs when inserting data from a 
select clause, what's going on? And more importantly, how can I
fix it?


-Tyler
tjw19@columbia.edu





view thread (4+ messages)  latest in thread

Message-ID: <40892875.70409@columbia.edu>
Permalink:  ../40892875.70409@columbia.edu/
Also on:    postgresql.org/message-id/40892875.70409@columbia.edu

 · 

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-admin@postgresql.org
  Cc: tjw19@columbia.edu, tward@janestcapital.com
  Subject: Re: Problem with inserts from subselects
  In-Reply-To: <40892875.70409@columbia.edu>
  References: <40892875.70409@columbia.edu>

* 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