Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 6F1021337B4F for ; Wed, 10 Nov 2010 05:42:50 -0400 (AST) 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 78578-01 for ; Wed, 10 Nov 2010 09:42:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.catalyst.net.nz (bertrand.catalyst.net.nz [202.78.240.40]) by mail.postgresql.org (Postfix) with ESMTP id 1376F1337B5B for ; Wed, 10 Nov 2010 05:42:42 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 2C68D31EDE for ; Wed, 10 Nov 2010 22:42:41 +1300 (NZDT) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1+bNqPR1o4hF for ; Wed, 10 Nov 2010 22:42:40 +1300 (NZDT) Received: from [192.168.1.11] (122-58-208-29.jetstream.xtra.co.nz [122.58.208.29]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id 7EF8031CE4 for ; Wed, 10 Nov 2010 22:42:40 +1300 (NZDT) Message-ID: <4CDA690F.1030408@catalyst.net.nz> Date: Wed, 10 Nov 2010 22:42:39 +1300 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Thunderbird/3.0.10 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Array interface References: <4CD06A81.1020800@vmsinfo.com> <4CDA618F.7050102@catalyst.net.nz> In-Reply-To: <4CDA618F.7050102@catalyst.net.nz> Content-Type: multipart/mixed; boundary="------------090402010904080701010204" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-10 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/132 X-Sequence-Number: 41156 This is a multi-part message in MIME format. --------------090402010904080701010204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 10/11/10 22:10, Mark Kirkwood wrote: > > What might also be interesting is doing each INSERT with an array-load > of bind variables appended to the VALUES clause - as this will only do > 1 insert call per "array" of values. This is probably more like what you were expecting: rows num values tuples(i.e array size) elapsed 1000000 1 106 1000000 10 14 1000000 100 13 1000000 1000 14 I didn't try to use PREPARE + EXECUTE here, just did "do" with the INSERT + array size number of VALUES tuples (execute could well be faster). The obvious difference here is we only do rows/(array size) number of insert calls. Cheers Mark --------------090402010904080701010204 Content-Type: application/x-perl; name="execinsert-values.pl" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="execinsert-values.pl" #!/usr/bin/perl # # execinsert-values.pl : test case for multi values insert # use strict; use warnings; use DBI; use Time::HiRes qw(time); my $driver = "Pg"; my $user = "postgres"; my $dbname = "bench"; my $host = "localhost"; my $port = 5439; my $dsn; my $dbh; my $sth; my $row; my $elapsed; my $i; my $maxi = shift; my $values; my $aid = 1; my $maxaid = 10000000; my $bid = 1; my $maxbid = 100; my $arraysiz = shift; if (!defined $maxi) { $maxi = 1000000 }; if (!defined $arraysiz) { $arraysiz = 1 }; $dsn = "dbi:$driver:host=$host;port=$port;dbname=$dbname"; $dbh = DBI->connect($dsn, $user, "", {AutoCommit => 0, RaiseError => 1} ) or die "Cannot connect to $dbname!\n"; $dbh->do("TRUNCATE pgbench_accounts"); $elapsed = time(); for ($i = 0; $i < $maxi + 1; $i++) { if ($i%$arraysiz eq 0) { if ($i > 0 ) { $dbh->do("INSERT INTO pgbench_accounts (aid, bid, abalance) VALUES $values"); } $values = "($aid, $bid, 0)"; } else { $values = $values . ",($aid, $bid, 0)"; } $aid++; if ($aid eq $maxaid) { $aid = 1; $bid++; } } $dbh->commit(); $elapsed = time() - $elapsed; print "$i inserts with array size $arraysiz in $elapsed s\n"; $dbh->disconnect(); --------------090402010904080701010204--