Message-ID: From: "Chris-SP365 (@Chris-SP365)" To: "pgjdbc/pgjdbc" Date: Mon, 27 Jan 2025 12:31:16 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3483: Support adaptive fetching without enforcing memory limits, and/or have a separate buffer size for it In-Reply-To: References: List-Id: X-GitHub-Author-Login: Chris-SP365 X-GitHub-Comment-Id: 2615636164 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3483 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3483#issuecomment-2615636164 Content-Type: text/plain; charset=utf-8 > We can't multiplex over the single connection, so we would have to consume and buffer the leftover in that case. This is the way multiple other database vendors JDBC implementations do it. SQL Server by default: https://learn.microsoft.com/en-us/sql/connect/jdbc/using-adaptive-buffering?view=sql-server-ver16 "Avoid executing more than one statement on the same connection simultaneously. Executing another statement before processing the results of the previous statement may cause the unprocessed results to be buffered into the application memory." MariaDB with setFetchSize(1) https://mariadb.com/kb/en/about-mariadb-connector-j/#streaming-result-sets If another query is run on same connection while the resultset has not been completly read, the connector will fetch all remaining rows before executing the query. This can lead to still needing lots of memory. Recommendation is then to use another connection for simultaneous operations. MySQL with setFetchSize(Integer.MIN_VALUE) throws an exception https://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html "There are some caveats with this approach. You must read all of the rows in the result set (or close it) before you can issue any other queries on the connection, or an exception will be thrown. " Result set streaming was our reason to switch to [PGJDBC-NG](https://impossibl.github.io/pgjdbc-ng/) which has the ability to stream the result set row by row. Our implementation does not issue a second command over one connection, it's just using a separate connection. So this is not a problem for us. @james-johnston-thumbtack would that behaviour help you?