From: Kris Jurka <books@ejurka.com>
To: Anish Kejariwal <anishkej@yahoo.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: avoid prepared statements on complex queries?
Date: Wed, 16 Nov 2011 16:20:10 -0500 (EST)
Message-ID: <alpine.BSO.2.00.1111161617200.14447@leary.csoft.net> (raw)
In-Reply-To: <1321406281.74175.YahooMailNeo@web33903.mail.mud.yahoo.com>
References: <1321406281.74175.YahooMailNeo@web33903.mail.mud.yahoo.com>
On Tue, 15 Nov 2011, Anish Kejariwal wrote:
> I'm running into an issue where a complex query is performing significantly
> slower if I use a prepared statement.
>
> Some notes about the query:
> -I'm calling a postgres function, via: select * from foo(?,?,?,?,?,?,?)
> -I'm getting back 4 million results
> -the underlying query is quite complex joining several tables, and the core
> table is partitioned over a couple hundred tables.
>
> Here's the java code:
>
> conn.setAutoCommit(false);
> pstmt = conn.prepareStatement("select * from foo(?,?,?,?,?,?,?)");
> pstmt.setFetchSize(1000);
>
> //and, then I do the usual thing to set parameters in the prepared statement
> stmt.setInt(1, SOME_NUMBER);
> pstmt.setArray(2, genepoolConn.createArrayOf("integer", ARRAY_OF_INTEGERS));
> //and so on
>
> So, obviously when using a prepared statement, postgres is coming up with
> the wrong execution plan when the the parameter list is unexpectedly large.
You haven't really shown that. Unless you issue the same query, manually
interpolating in the query parameters and get a much faster time, all
you've shown is that things get slower with a larger number of values.
What language is your function written in? Unless it's a sql function
which could be inlined, I wouldn't have expected any difference between
prepared vs inline query execution.
Kris Jurka
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, anishkej@yahoo.com
Subject: Re: avoid prepared statements on complex queries?
In-Reply-To: <alpine.BSO.2.00.1111161617200.14447@leary.csoft.net>
References: <1321406281.74175.YahooMailNeo@web33903.mail.mud.yahoo.com> <alpine.BSO.2.00.1111161617200.14447@leary.csoft.net>
* 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