From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | chester c young <chestercyoung(at)yahoo(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: best performance for simple dml |
Date: | 2011-06-27 07:05:32 |
Message-ID: | BANLkTik90qDGv-9CcHtV6i=abynywUkbNA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
2011/6/27 chester c young <chestercyoung(at)yahoo(dot)com>
>
> two questions:
> I thought copy was for multiple rows - is its setup cost effective for one row?
I expect it will be faster for one row too - it is not sql statement
if you want to understand to performance issues you have to understand to
a) network communication costs
b) SQL parsing and SQL planning costs
c) commits costs
d) other costs - triggers, referential integrity costs
>
> copy would also only be good for insert or select, not update - is this right?
sure,
If you need to call a lot of simple dml statement in cycle, then
a) try tu move it to stored function
b) if you can't to move it, then ensure, so statements will be
executed under outer transaction
slow code
for(i = 0; i < 1000; i++)
exec("insert into foo values($1), itoa(i));
10x faster code
exec('begin');
for(i = 0; i < 1000; i++)
exec("insert into foo values($1), itoa(i));
exec('commit');
Regards
Pavel Stehule
>
> --- On Mon, 6/27/11, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> Subject: Re: [SQL] best performance for simple dml
> To: "chester c young" <chestercyoung(at)yahoo(dot)com>
> Cc: pgsql-sql(at)postgresql(dot)org
> Date: Monday, June 27, 2011, 12:35 AM
>
> Hello
>
> try it and you will see. Depends on network speed, hw speed. But the most fast is using a COPY API
>
> http://www.postgresql.org/docs/9.0/interactive/libpq-copy.html
>
> Regards
>
> Pavel Stehule
>
>
> 2011/6/27 chester c young <chestercyoung(at)yahoo(dot)com>
>
> what is the best performance / best practices for frequently-used simple dml, for example, an insert
> 1. fast-interface
> 2. prepared statement calling "insert ..." with binary parameters
> 3. prepared statement calling "myfunc(..." with binary parameters; myfunc takes its arguments and performs an insert using them
>
From | Date | Subject | |
---|---|---|---|
Next Message | chester c young | 2011-06-27 07:49:49 | Re: best performance for simple dml |
Previous Message | chester c young | 2011-06-27 06:48:29 | Re: best performance for simple dml |