X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 4EF43D1C9E8 for ; Fri, 23 Apr 2004 11:48:47 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 43879-06 for ; Fri, 23 Apr 2004 11:48:45 -0300 (ADT) Received: from mocha2.baileylink.net (mocha2.baileylink.net [12.152.112.28]) by svr1.postgresql.org (Postfix) with SMTP id 7E37FD1C9B4 for ; Fri, 23 Apr 2004 11:48:38 -0300 (ADT) Received: (qmail 24924 invoked from network); 23 Apr 2004 14:48:42 -0000 Received: from nuernburg.baileylink.net (HELO baileylink.net) (12.152.112.18) by mocha2.baileylink.net with SMTP; 23 Apr 2004 14:48:42 -0000 Message-ID: <40892E2D.5070804@baileylink.net> Date: Fri, 23 Apr 2004 09:54:37 -0500 From: banghe User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tyler Ward Cc: pgsql-admin@postgresql.org, Tyler Ward Subject: Re: Problem with inserts from subselects References: <40892875.70409@columbia.edu> In-Reply-To: <40892875.70409@columbia.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.1 tagged_above=0.0 required=5.0 tests=MAILTO_TO_SPAM_ADDR X-Spam-Level: * X-Archive-Number: 200404/302 X-Sequence-Number: 13275 Can you try in this way: 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 ; This is without ( ). Banghe Tyler Ward wrote: > > > > 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... > > > > 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 > ); > > > > 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.... > > > 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 > > > The result returns basically instantly, in less than half a second. > > If I just insert the data by hand.... > > > 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); > > > 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 > > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster >