| From: | Mladen Gogala <mladen(dot)gogala(at)vmsinfo(dot)com> |
|---|---|
| To: | "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org> |
| Subject: | Array interface |
| Date: | 2010-11-02 19:46:09 |
| Message-ID: | 4CD06A81.1020800@vmsinfo.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-performance |
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 (<FL>)
{
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 (<FL>)
{
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 => \(at)tstat},
\(at)col1, \(at)col2, \(at)col3);
die("Multiple insert failed!\n") if (!$tuples);
@col1 = ();
@col2 = ();
@col3 = ();
$exec_cnt++;
}
}
if ($#col1 >= 0)
{
my $tuples = $sth->execute_array({ArrayTupleStatus => \(at)tstat},
\(at)col1, \(at)col2, \(at)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Cédric Villemain | 2010-11-02 20:32:02 | Re: Insert performance with composite index |
| Previous Message | Divakar Singh | 2010-11-02 12:51:07 | Re: Insert performance with composite index |