Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id EE6036328B7 for ; Sat, 28 Aug 2010 12:21:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 47643-09 for ; Sat, 28 Aug 2010 15:21:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from newserver.jfcomputer.com (unknown [76.14.161.106]) by mail.postgresql.org (Postfix) with ESMTP id B3203634C59 for ; Sat, 28 Aug 2010 12:21:44 -0300 (ADT) Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id 9B8F912208 for ; Sat, 28 Aug 2010 15:21:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UHeIRSMs80kp for ; Sat, 28 Aug 2010 08:21:35 -0700 (PDT) Received: from linux-desktop.localnet (unknown [76.14.161.106]) by newserver.jfcomputer.com (Postfix) with ESMTP id B17ED12207 for ; Sat, 28 Aug 2010 08:21:35 -0700 (PDT) From: John Fabiani Organization: J.F. Computer Solutions To: postgres list Subject: a general ? on select performance Date: Sat, 28 Aug 2010 08:21:40 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.34-12-desktop; KDE/4.4.4; i686; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201008280821.40740.johnf@jfcomputer.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.107 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201008/81 X-Sequence-Number: 34521 Hi, In general what are the causes of SQL select statement slow downs - other than the size of the data? I realize this is a broad question but read on please. Here's where I'm coming from: I have program that loops though several thousands of records. The loop contains a select statement that confirms that I don't have a dup and then inserts a record into a different table. IOW's the statement is checking against a static table. The size of the table I'm checking does not change during the loop. I'm sure many have done something similar. The loop performs very well for the first 500 - 800 items. Then starts slowing down. And somewhere around 1200 really slows to a crawl. To the point it does not complete in a 12 hour period. But when I take several of the statements and execute them using pgAdmin - they take almost no time (0.001 if memory serves) for rec in check_set_data: select pkid from check_table where check_field = rec.field_name if found skip else insert into new table. I'm using 8.4 on openSUSE 11.3 multi-processor, 8 GB of ram. Johnf