forked from nec-postgres/pgjdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: cache parsed statement across .prepareStatement calls
This allows to use server-side prepared statements when application uses the same SQL multiple times
- Loading branch information
Showing
14 changed files
with
832 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* Copyright (c) 2015, PostgreSQL Global Development Group | ||
* | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
package org.postgresql.core; | ||
|
||
import org.postgresql.util.CanEstimateSize; | ||
|
||
/** | ||
* Stores information on the parsed JDBC query. | ||
* It is used to cut parsing overhead when executing the same query through {@link java.sql.Connection#prepareStatement(String)}. | ||
*/ | ||
public class CachedQuery implements CanEstimateSize { | ||
/** | ||
* Cache key. {@link String} or {@link org.postgresql.jdbc2.CallableQueryKey} | ||
*/ | ||
public final Object key; | ||
public final Query query; | ||
public final boolean isFunction; | ||
public final boolean outParmBeforeFunc; | ||
|
||
private int executeCount; | ||
|
||
public CachedQuery(Object key, Query query, boolean isFunction, boolean outParmBeforeFunc) | ||
{ | ||
this.key = key; | ||
this.query = query; | ||
this.isFunction = isFunction; | ||
this.outParmBeforeFunc = outParmBeforeFunc; | ||
} | ||
|
||
public void increaseExecuteCount() { | ||
if (executeCount < Integer.MAX_VALUE) | ||
executeCount++; | ||
} | ||
|
||
public void increaseExecuteCount(int inc) { | ||
int newValue = executeCount + inc; | ||
if (newValue > 0) // if overflows, just ignore the update | ||
executeCount = newValue; | ||
} | ||
|
||
/** | ||
* Number of times this statement has been used | ||
* @return number of times this statement has been used | ||
*/ | ||
public int getExecuteCount() { | ||
return executeCount; | ||
} | ||
|
||
@Override | ||
public long getSize() | ||
{ | ||
int queryLength = String.valueOf(key).length() * 2 /* 2 bytes per char */; | ||
return queryLength * 2 /* original query and native sql */ + 100 /* entry in hash map, CachedQuery wrapper, etc */; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.