From 96bed2e0e503bcd1d44baffa361dcb3381106222 Mon Sep 17 00:00:00 2001 From: Bhavik Shah <115029313+bhvkshah@users.noreply.github.com> Date: Thu, 13 Apr 2023 11:35:11 -0500 Subject: [PATCH] RingBuffer to respect setMaxRows on statement --- .../java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java b/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java index 60812b4..8240d08 100644 --- a/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java +++ b/src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java @@ -729,10 +729,13 @@ public ResultSet getResultSet() throws SQLException { * {@inheritDoc} */ public final void close() throws SQLException { - if(connection.getQueryExecutor().isRingBufferThreadRunning()) + if(connection.getQueryExecutor().isRingBufferThreadRunning() && + (!connection.getAutoCommit() || getMaxRows() == 0)) { // Wait for current ring buffer thread to finish, if any. // Shouldn't call from synchronized method, which can cause dead-lock. + // We don't want to wait for ring buffer to fetch all rows if setMaxRows() is set, + // or if autoCommit is set to true connection.getQueryExecutor().waitForRingBufferThreadToFinish(false, false, true, null, null); }