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 92677D1BAAD for ; Fri, 23 Apr 2004 10:29:53 -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 16939-01 for ; Fri, 23 Apr 2004 10:29:54 -0300 (ADT) Received: from via-smtp3.imconline.net (via-smtp3.imconline.net [66.155.127.63]) by svr1.postgresql.org (Postfix) with ESMTP id CA5F3D1B97B for ; Fri, 23 Apr 2004 10:29:48 -0300 (ADT) Received: from janestcapital.com ([66.155.124.107]) by via-smtp3.imconline.net with Microsoft SMTPSVC(5.0.2195.5329); Fri, 23 Apr 2004 09:27:48 -0400 Received: from columbia.edu [141.155.88.179] by janestcapital.com with ESMTP (SMTPD32-8.02) id AA4FA5D0022; Fri, 23 Apr 2004 09:29:51 -0400 Message-ID: <40892875.70409@columbia.edu> Date: Fri, 23 Apr 2004 10:30:13 -0400 From: Tyler Ward User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-admin@postgresql.org, Tyler Ward Subject: Problem with inserts from subselects Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 23 Apr 2004 13:27:48.0569 (UTC) FILETIME=[C5247490:01C42936] X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.9 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS, MAILTO_TO_SPAM_ADDR X-Spam-Level: * X-Archive-Number: 200404/301 X-Sequence-Number: 13274 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