pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedPrepared statements (PREPARE and JDBC) are a lot slower than "normal" ones.
2+ messages / 2 participants
[nested] [flat]
* Prepared statements (PREPARE and JDBC) are a lot slower than "normal" ones.
@ 2018-02-13 09:25 Robert Zenz <robert.zenz@sibvisions.com>
2018-02-13 09:32 ` Re: Prepared statements (PREPARE and JDBC) are a lot slower than "normal" ones. Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 2+ messages in thread
From: Robert Zenz @ 2018-02-13 09:25 UTC (permalink / raw)
To: pgsql-general
We are seeing a quite heavy slow down when using prepared statements in 10.1.
I haven't done some thorough testing, to be honest, but what we are having is a
select from a view (complexity of it should not matter in my opinion), something
like this:
prepare TEST (text, int) select * from OUR_VIEW where COLUMNA = $1 and
COLUMNB = $2;
-- Actual test code follows.
-- Takes ~2 seconds.
select * from OUR_VIEW where COLUMNA = 'N' and COLUMNB = 35;
-- Takes ~10 seconds.
execute TEST ('N', 35);
Both return the same amount of rows, order of execution does not matter, these
times are reproducible. If the same select statement is executed through JDBC it
takes roughly 6 seconds (execution time only, no data fetched at that point).
I'm a little bit at a loss here. Is such a slow down "expected", did we simply
miss that prepared statements are slower? Or is there something else going on
that we are simply not aware of?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Prepared statements (PREPARE and JDBC) are a lot slower than "normal" ones.
2018-02-13 09:25 Prepared statements (PREPARE and JDBC) are a lot slower than "normal" ones. Robert Zenz <robert.zenz@sibvisions.com>
@ 2018-02-13 09:32 ` Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 2+ messages in thread
From: Laurenz Albe @ 2018-02-13 09:32 UTC (permalink / raw)
To: Robert Zenz <robert.zenz@sibvisions.com>; pgsql-general
Robert Zenz wrote:
> We are seeing a quite heavy slow down when using prepared statements in 10.1.
>
> I haven't done some thorough testing, to be honest, but what we are having is a
> select from a view (complexity of it should not matter in my opinion), something
> like this:
>
> prepare TEST (text, int) select * from OUR_VIEW where COLUMNA = $1 and
> COLUMNB = $2;
>
> -- Actual test code follows.
>
> -- Takes ~2 seconds.
> select * from OUR_VIEW where COLUMNA = 'N' and COLUMNB = 35;
>
> -- Takes ~10 seconds.
> execute TEST ('N', 35);
>
> Both return the same amount of rows, order of execution does not matter, these
> times are reproducible. If the same select statement is executed through JDBC it
> takes roughly 6 seconds (execution time only, no data fetched at that point).
> I'm a little bit at a loss here. Is such a slow down "expected", did we simply
> miss that prepared statements are slower? Or is there something else going on
> that we are simply not aware of?
Most likely, you are seeing the effects of a generic plan being used.
During the first five executions, the prepared statement will run a
"custom plan" generated with the actual parameters. If the cost estimate
of these plans is not cheaper than the cost estimate of the generic plan
(without substituting the actual parameters), the generic plan will be
used from the sixth execution on.
You can compare the execution plans generated with
EXPLAIN (ANALYZE, BUFFERS) EXECUTE test ('N', 35);
and
EXPLAIN (ANALYZE, BUFFERS) select * from OUR_VIEW where COLUMNA = 'N' and COLUMNB = 35;
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2018-02-13 09:32 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-02-13 09:25 Prepared statements (PREPARE and JDBC) are a lot slower than "normal" ones. Robert Zenz <robert.zenz@sibvisions.com>
2018-02-13 09:32 ` Laurenz Albe <laurenz.albe@cybertec.at>
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