You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "ShenFeng312 (via GitHub)" <gi...@apache.org> on 2025/11/26 08:52:35 UTC

[I] PostgreSQLComExecuteExecutor may cause OOM when packet.getMaxRows() = 0 [shardingsphere]

ShenFeng312 opened a new issue, #37183:
URL: https://github.com/apache/shardingsphere/issues/37183

   PostgreSQLComExecuteExecutor has a potential Out-Of-Memory (OOM) problem.
   
   When packet.getMaxRows() is 0, and the returned result set is extremely large, the executor will attempt to write all result packets into memory. This behavior can easily lead to an OOM error under high-volume queries.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] PostgreSQLComExecuteExecutor may cause OOM when packet.getMaxRows() = 0 [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37183:
URL: https://github.com/apache/shardingsphere/issues/37183#issuecomment-3596656253

   I still believe we should align with PostgreSQL's default behavior, whether it seems rational or not. The gateway's role is to faithfully translate it. Therefore, we first need to clarify: what exactly is PostgreSQL's behavior?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] PostgreSQLComExecuteExecutor may cause OOM when packet.getMaxRows() = 0 [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37183:
URL: https://github.com/apache/shardingsphere/issues/37183#issuecomment-3592473622

   Thank you for raising this potential issue.
   To accurately determine whether the behavior in ShardingSphere-Proxy is correct, we need to further confirm the actual PostgreSQL behavior when Execute(maxRows = 0) is used.
   
   According to the PostgreSQL Extended Query Protocol, the maxRows field is controlled by the client, but the official documentation does not explicitly define the meaning of maxRows = 0. Therefore, we would like to ask for your help to confirm the following:
   
   Could you help confirm whether the following behaviors match the actual PostgreSQL server behavior?
   
   When the client sends Execute(portal, maxRows = 0),
   does PostgreSQL always return all result rows (i.e., unlimited fetch)?
   
   Under this condition, does PostgreSQL:
   
   stream rows to the client as they are read, or
   
   buffer the entire result set in memory before sending?
   
   ShardingSphere aims to keep its behavior consistent with PostgreSQL's native protocol.
   If PostgreSQL returns the full result set for maxRows = 0, then Proxy should follow the same semantics.
   If PostgreSQL handles this more efficiently, we are also open to adapting the same behavior.
   
   We would also appreciate your thoughts on the following:
   
   Would you recommend Proxy to introduce protective mechanisms for large result sets (e.g., streaming, batch sending, or a configurable maximum row limit)?
   
   Do you have any concrete test cases or tools we can use to compare PostgreSQL and Proxy memory behavior in this scenario?
   
   Thank you again for reporting this issue.
   Confirming the actual PostgreSQL protocol behavior will help us determine whether improvements or fixes are needed on the ShardingSphere-Proxy side.
   We appreciate any additional observations or suggestions you may have!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] PostgreSQLComExecuteExecutor may cause OOM when packet.getMaxRows() = 0 [shardingsphere]

Posted by "ShenFeng312 (via GitHub)" <gi...@apache.org>.
ShenFeng312 commented on issue #37183:
URL: https://github.com/apache/shardingsphere/issues/37183#issuecomment-3594632843

   I understand the issue you mentioned, but it seems difficult to verify. Based on the existing JDBC code, when autoCommit is not set to false (this is the prerequisite), JDBC will load all results into the ResultSet at once. The size of the result set is controlled by JDBC’s maxRows; if it is 0, it means “fetch all”.
   
   When autoCommit = false and setFetchSize = xx are configured, JDBC will fetch data in batches according to the fetch size. Here, fetchSize is essentially equivalent to our maxRows in the ExecutePacket. If it is 0, it will fetch everything.
   
   To solve the  problem, we might need to properly manage the transaction state. It’s very likely that before executing EXECUTE, we need to explicitly set autoCommit = false (if it was previously true), then perform streaming fetches using a reasonable fetch size. I’m not sure whether the proxy can handle this properly. After the fetch is completed, we should restore autoCommit = true (if it was originally true).
   
   Because indeed, blindly changing the fetch size will not take effect. The complexity here seems to exceed my expectations. Also note that the default behavior of JDBC is always to fetch all data, which is still dangerous for a gateway. @terrymanu 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] PostgreSQLComExecuteExecutor may cause OOM when packet.getMaxRows() = 0 [shardingsphere]

Posted by "ShenFeng312 (via GitHub)" <gi...@apache.org>.
ShenFeng312 commented on issue #37183:
URL: https://github.com/apache/shardingsphere/issues/37183#issuecomment-3619924076

   Perhaps I will consider fixing it in pgjdbc so that it can work the same way as MySQL, and then I will come back to fix this issue @terrymanu 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] PostgreSQLComExecuteExecutor may cause OOM when packet.getMaxRows() = 0 [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37183:
URL: https://github.com/apache/shardingsphere/issues/37183#issuecomment-3620475601

   Yes, it's helpful.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org