Re: psql vs perl prepared inserts - Mailing list pgsql-general

From Neil Conway
Subject Re: psql vs perl prepared inserts
Date
Msg-id 425D0AD9.80401@samurai.com
Whole thread Raw
In response to Re: psql vs perl prepared inserts  (Dawid Kuroczko <qnex42@gmail.com>)
Responses Re: psql vs perl prepared inserts
Re: psql vs perl prepared inserts
Re: psql vs perl prepared inserts
List pgsql-general
Dawid Kuroczko wrote:
> For a test you might want to try also this approach (both from perl and
> from psql):
>
> $dbh->do('PREPARE sth_tim (int,inet,boolean,timestamptz) AS INSERT
> INTO timestamps VALUES ($1,$2,$3,$4)');
> $sth_tim  = $dbh->prepare("EXECUTE sth_tim(?,?,?,?)");
>
> ...and later execute it.  (and likewise with psql).  If you'll see gain in speed
> with perl it means your DBD::Pg wasn't using server side prepared
> statements.

The intent of prepared statements is to reduce the overhead of running
the parser, rewriter and planner multiple times for a statement that is
executed multiple times. For an INSERT query without any sub-selects
that is not rewritten by any rules, the cost to parse, rewrite and plan
the statement is trivial. So I wouldn't expect prepared statements to be
a big win -- you would gain a lot more from batching multiple inserts
into a single transaction, and more still from using COPY.

-Neil

pgsql-general by date:

Previous
From: Robert Treat
Date:
Subject: Re: What are the consequences of a bad database design (never seen that before !)
Next
From: Matt Van Mater
Date:
Subject: Re: psql vs perl prepared inserts