Skip to content

feat: cache prepare statement for reuse#1496

Open
BobdenOs wants to merge 4 commits intomainfrom
feat/hana-prepare
Open

feat: cache prepare statement for reuse#1496
BobdenOs wants to merge 4 commits intomainfrom
feat/hana-prepare

Conversation

@BobdenOs
Copy link
Contributor

@BobdenOs BobdenOs commented Feb 5, 2026

Currently @cap-js/hana will always call prepare for queries that have placeholders ?. With this PR the SQL statement is used as a cache key preventing prepare from being called. Allowing already prepared statements to be run directly. Reducing the amount of round trips. It is not allowed to run SELECT statements in statement.runBatch. Therefor it is not possible to use the event loop as an arguments collection mechanism to further reduce network overhead. As the HANA connection is (currently) only capable of having a single packed in flight there is no possibility that performance will be worsened by having statement executions be queued on the cached prepared statement.

There is a special case for streaming queries (incl. blob streams for @sap/hana-client). It is not possible to determine when the prepared statement is no longer required. Therefor the prepared statements for streaming queries are detached from the cache once initiated.

@BobdenOs
Copy link
Contributor Author

BobdenOs commented Feb 6, 2026

Do not merge until all tests are passing:
reading a stream commits on end + hdb => Packet size limit exceeded

The root cause of the "random" packet size limit errors. Is caused by the tx.set happening right before the stmt.exec when re using already prepared statements of previous transactions.
potential fix: SAP/node-hdb#293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants