From: Ron Mayer <rm_pg@cheapcomplexdevices.com>
To: pgsql-performance@postgresql.org
Subject: Multiple insert performance trick or performance misunderstanding?
Date: Sat, 24 Sep 2005 13:51:16 -0700
Message-ID: <dh4e88$25qe$1@news.hub.org> (raw)
When I need to insert a few hundred or thousand things in
a table from a 3-tier application, it seems I'm much better
off creating a big string of semicolon separated insert
statements rather than sending them one at a time - even
when I use the obvious things like wrapping the statements
in a transaction and using the library's prepared statements.
I tried both Ruby/DBI and C#/Npgsql; and in both cases
sets of inserts that took 3 seconds when run individually
took about 0.7 seconds when concatenated together.
Is it expected that I'd be better off sending big
concatenated strings like
"insert into tbl (c1,c2) values (v1,v2);insert into tbl (c1,c2) values (v3,v4);..."
instead of sending them one at a time?
db.ExecuteSQL("BEGIN");
sql = new System.Text.StringBulder(10000);
for ([a lot of data elements]) {
sql.Append(
"insert into user_point_features (col1,col2)"+
" values (" +obj.val1 +","+obj.val2+");"
);
}
db.ExecuteSQL(sql.ToString());
db.ExecuteSQL("COMMIT");
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: rm_pg@cheapcomplexdevices.com
Subject: Re: Multiple insert performance trick or performance misunderstanding?
In-Reply-To: <dh4e88$25qe$1@news.hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox