Skip to content

Commit

Permalink
Add MAX_QUERY_MEMORY_BYTES to PGProperty to use it in QueryExecutorIm…
Browse files Browse the repository at this point in the history
…pl as limitTupleBytes.
  • Loading branch information
vargabalazs93 committed Nov 14, 2024
1 parent b60a01c commit b5da9da
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
23 changes: 22 additions & 1 deletion pgjdbc/src/main/java/org/postgresql/PGProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,12 @@ public enum PGProperty {
"When connections that are not explicitly closed are garbage collected, log the stacktrace from the opening of the connection to trace the leak source"),

/**
* Specifies size of buffer during fetching result set. Can be specified as specified size or
* The allowed memory size in bytes, what a query can use (iData made attribute)
*/
MAX_QUERY_MEMORY_BYTES("maxQueryMemoryBytes", Long.toString(Long.MAX_VALUE), "The allowed memory size in bytes, what a query can use"),

/**
* Specifies size of buffer during fetching result th. Can be specified as specified size or
* percent of heap memory.
*/
MAX_RESULT_BUFFER(
Expand Down Expand Up @@ -1010,6 +1015,22 @@ public int getInt(Properties properties) throws PSQLException {
}
}

/**
* Return the long value for this connection parameter in the given {@code Properties}
*
* @param properties properties to take actual value from
* @return evaluated value for this connection parameter converted to long
* @throws PSQLException if it cannot be converted to long.
*/
public long getLong(Properties properties) throws PSQLException {
String value = get(properties);
try {
return Long.parseLong(value);

Check failure on line 1028 in pgjdbc/src/main/java/org/postgresql/PGProperty.java

View workflow job for this annotation

GitHub Actions / CheckerFramework

[Task :postgresql:compileJava] [argument] incompatible argument for parameter arg0 of Long.parseLong. return Long.parseLong(value); ^ found : @initialized @nullable String
} catch (NumberFormatException nfe) {
throw new PSQLException(GT.tr("{0} parameter value must be a long but was: {1}", getName(), value), PSQLState.INVALID_PARAMETER_VALUE, nfe);
}
}

/**
* Set the boolean value for this connection parameter in the given {@link Properties}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public QueryExecutorImpl(PGStream pgStream,

this.allowEncodingChanges = PGProperty.ALLOW_ENCODING_CHANGES.getBoolean(info);
this.cleanupSavePoints = PGProperty.CLEANUP_SAVEPOINTS.getBoolean(info);
this.limitTupleBytes = PGProperty.MAX_QUERY_MEMORY_BYTES.getLong(info);
// assignment, argument
this.replicationProtocol = new V3ReplicationProtocol(this, pgStream);
readStartupMessages();
Expand Down Expand Up @@ -3088,8 +3089,7 @@ public boolean getIntegerDateTimes() {
private long nextUniqueID = 1;
private final boolean allowEncodingChanges;
private final boolean cleanupSavePoints;

public static volatile long limitTupleBytes = Long.MAX_VALUE;
private final long limitTupleBytes;

/**
* <p>The estimated server response size since we last consumed the input stream from the server, in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,14 @@ public void setHideUnprivilegedObjects(boolean hideUnprivileged) {
PGProperty.HIDE_UNPRIVILEGED_OBJECTS.set(properties, hideUnprivileged);
}

public @Nullable String getMaxQueryMemoryBytes() {
return PGProperty.MAX_QUERY_MEMORY_BYTES.getOrDefault(properties);
}

public void setMaxQueryMemoryBytes(@Nullable String maxQueryMemoryBytes) {
PGProperty.MAX_QUERY_MEMORY_BYTES.set(properties, maxQueryMemoryBytes);
}

public @Nullable String getMaxResultBuffer() {
return PGProperty.MAX_RESULT_BUFFER.getOrDefault(properties);
}
Expand Down

0 comments on commit b5da9da

Please sign in to comment.