[libpostgresql-jdbc-java] 01/06: When a prepared statement uses different parameter types than what the statement was originally prepared for, the driver must replan the query for the new types. When doing this in batches the driver was not correctly freeing old plans.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_0_316
in repository libpostgresql-jdbc-java.
commit f948080af23ed83fd32412bd38137bc6a1a3a91f
Author: Kris Jurka <books at ejurka.com>
Date: Wed Apr 26 20:07:51 2006 +0000
When a prepared statement uses different parameter types than what
the statement was originally prepared for, the driver must replan
the query for the new types. When doing this in batches the
driver was not correctly freeing old plans.
To cleanup prepared statements the driver records a reference to a
query object in response to the ParseComplete message. The problem
in this case was that since the driver sends multiple Parse messages
before a Sync, when the driver receives the first ParseComplete
message the query object now contains a reference to the latest
parsed statement, not the first. So it was only cleaning up the
last parsed statement not all of them.
As reported by Peter Eisentraut.
---
org/postgresql/core/v3/QueryExecutorImpl.java | 20 ++++++++++++--------
org/postgresql/core/v3/SimpleQuery.java | 6 +++++-
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java
index 4731627..4b2b5c0 100644
--- a/org/postgresql/core/v3/QueryExecutorImpl.java
+++ b/org/postgresql/core/v3/QueryExecutorImpl.java
@@ -4,7 +4,7 @@
* Copyright (c) 2004, Open Cloud Limited.
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21 2005/02/01 07:27:54 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21.2.1 2005/11/05 09:27:56 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -650,6 +650,7 @@ public class QueryExecutorImpl implements QueryExecutor {
// Clean up any existing statement, as we can't use it.
query.unprepare();
+ processDeadParsedQueries();
String statementName = null;
if (!oneShot)
@@ -736,7 +737,7 @@ public class QueryExecutorImpl implements QueryExecutor {
for (int i = 1; i <= params.getParameterCount(); ++i)
pgStream.SendInteger4(params.getTypeOID(i));
- pendingParseQueue.add(query);
+ pendingParseQueue.add(new Object[]{query, query.getStatementName()});
}
private void sendBind(SimpleQuery query, SimpleParameterList params, Portal portal) throws IOException {
@@ -1054,8 +1055,7 @@ public class QueryExecutorImpl implements QueryExecutor {
private final HashMap parsedQueryMap = new HashMap();
private final ReferenceQueue parsedQueryCleanupQueue = new ReferenceQueue();
- private void registerParsedQuery(SimpleQuery query) {
- String statementName = query.getStatementName();
+ private void registerParsedQuery(SimpleQuery query, String statementName) {
if (statementName == null)
return ;
@@ -1140,11 +1140,14 @@ public class QueryExecutorImpl implements QueryExecutor {
case '1': // Parse Complete (response to Parse)
pgStream.ReceiveIntegerR(4); // len, discarded
- SimpleQuery parsedQuery = (SimpleQuery)pendingParseQueue.get(parseIndex++);
+ Object[] parsedQueryAndStatement = (Object[])pendingParseQueue.get(parseIndex++);
+ SimpleQuery parsedQuery = (SimpleQuery)parsedQueryAndStatement[0];
+ String parsedStatementName = (String)parsedQueryAndStatement[1];
+
if (Driver.logDebug)
- Driver.debug(" <=BE ParseComplete [" + parsedQuery.getStatementName() + "]");
+ Driver.debug(" <=BE ParseComplete [" + parsedStatementName + "]");
- registerParsedQuery(parsedQuery);
+ registerParsedQuery(parsedQuery, parsedStatementName);
break;
case 't': // ParameterDescription
@@ -1337,7 +1340,8 @@ public class QueryExecutorImpl implements QueryExecutor {
// Reset the statement name of Parses that failed.
while (parseIndex < pendingParseQueue.size())
{
- SimpleQuery failedQuery = (SimpleQuery)pendingParseQueue.get(parseIndex++);
+ Object[] failedQueryAndStatement = (Object[])pendingParseQueue.get(parseIndex++);
+ SimpleQuery failedQuery = (SimpleQuery)failedQueryAndStatement[0];
failedQuery.unprepare();
}
diff --git a/org/postgresql/core/v3/SimpleQuery.java b/org/postgresql/core/v3/SimpleQuery.java
index 9ebdc16..789a307 100644
--- a/org/postgresql/core/v3/SimpleQuery.java
+++ b/org/postgresql/core/v3/SimpleQuery.java
@@ -4,7 +4,7 @@
* Copyright (c) 2004, Open Cloud Limited.
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleQuery.java,v 1.7 2005/01/27 22:50:14 oliver Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleQuery.java,v 1.8 2005/02/01 07:27:54 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -100,6 +100,10 @@ class SimpleQuery implements V3Query {
}
void setCleanupRef(PhantomReference cleanupRef) {
+ if (this.cleanupRef != null) {
+ this.cleanupRef.clear();
+ this.cleanupRef.enqueue();
+ }
this.cleanupRef = cleanupRef;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list