Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 9E18F1337999 for ; Tue, 2 Nov 2010 16:46:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 87162-01 for ; Tue, 2 Nov 2010 19:46:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lpo-relay-04.vmsinfo.com (lpo-relay-04.vmsinfo.com [216.169.137.115]) by mail.postgresql.org (Postfix) with ESMTP id 1DDD2133798E for ; Tue, 2 Nov 2010 16:46:10 -0300 (ADT) X-IronPort-AV: E=Sophos;i="4.58,284,1286164800"; d="scan'208";a="26673299" Received: from unknown (HELO lpo-mailbox-02.vmsinfo.com) ([216.169.137.251]) by lpo-relay-04.vmsinfo.com with ESMTP; 02 Nov 2010 15:46:09 -0400 Received: from [10.101.43.35] (lpo-autonomy-p03.vmsinfo.com [216.169.135.234]) by lpo-mailbox-02.vmsinfo.com (Postfix) with ESMTP id D539256258 for ; Tue, 2 Nov 2010 15:46:09 -0400 (EDT) Message-ID: <4CD06A81.1020800@vmsinfo.com> Date: Tue, 02 Nov 2010 15:46:09 -0400 From: Mladen Gogala Organization: VMS User-Agent: Thunderbird 2.0.0.24 (X11/20101027) MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" Subject: Array interface Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/97 X-Sequence-Number: 41121 I wrote a little Perl script, intended to test the difference that array insert makes with PostgreSQL. Imagine my surprise when a single record insert into a local database was faster than batches of 100 records. Here are the two respective routines: sub do_ssql { my $exec_cnt = 0; while () { chomp; my @row = split /$sep/; $sth->execute(@row); $exec_cnt++; } $dbh->commit(); print "Insert executed $exec_cnt times.\n"; } sub do_msql { my $bsz = shift; die("Batch size must be >0!\n") unless $bsz > 0; my $exec_cnt = 0; my @tstat; my (@col1, @col2, @col3); while () { chomp; my @row = split /$sep/; push @col1, $row[0]; push @col2, $row[1]; push @col3, $row[2]; if ($. % $bsz == 0) { my $tuples = $sth->execute_array({ArrayTupleStatus => \@tstat}, \@col1, \@col2, \@col3); die("Multiple insert failed!\n") if (!$tuples); @col1 = (); @col2 = (); @col3 = (); $exec_cnt++; } } if ($#col1 >= 0) { my $tuples = $sth->execute_array({ArrayTupleStatus => \@tstat}, \@col1, \@col2, \@col3); die("Multiple insert failed!\n") if (!$tuples); $exec_cnt++; } $dbh->commit(); print "Insert executed $exec_cnt times.\n"; } The variable "$sth" is a prepared statement handle. -- Mladen Gogala Sr. Oracle DBA 1500 Broadway New York, NY 10036 (212) 329-5251 http://www.vmsinfo.com The Leader in Integrated Media Intelligence Solutions