Skip to content

fix: hana preparations use map#1682

Closed
kasimos wants to merge 2 commits into
cap-js:mainfrom
kasimos:hanaPreparationMap
Closed

fix: hana preparations use map#1682
kasimos wants to merge 2 commits into
cap-js:mainfrom
kasimos:hanaPreparationMap

Conversation

@kasimos

@kasimos kasimos commented Jul 14, 2026

Copy link
Copy Markdown

Addresses #1681

Use a Map to store prepared statements and reuse them when possible.
Add a unique comment for procedure calls to prevent reuse for those, as some builtin procedures like acquiring application locks do not work with already prepared statements.

Please note that a similar fix would be possible for sqlite as well. For Postgres it depends on the used driver as some are already doing this preparation caching for you.

@BobdenOs

Copy link
Copy Markdown
Contributor

Duplicate from: #1496

@BobdenOs BobdenOs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is insufficient. We already have a PR which solves the problem #1496

currently there is a bug in the hdb driver that prevents a connection to re use a prepared statement after an session variable is updated. Once that is resolved it will be possible to merge the proper fix.

Comment thread hana/lib/HANAService.js
this.dbc.statements.push(stmt)
// we store the prepared statements for caching
// and to release them on commit/rollback all at once
let stmt = this.ensureDBC().statements.get(sql);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fundamentally flawed, because it is possible to run the same sql statement in "parallel" at this level which will start throwing errors when the same statement instance is called with exec / execute as the statement has state. Therefor it is required to create a queue for each statement until it is finished with an exec / execute.

Comment thread hana/lib/HANAService.js
const outParameters = isAsync ? [{ PARAMETER_NAME: 'ASYNC_CALL_ID' }] : await this._getProcedureMetadata(name, schema)
const ps = await this.prepare(query)
// make procedure preparations unique to avoid caching issues with internal procedures
const ps = await this.prepare(query+'--'+this.ensureDBC().statements.length)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By changing the SQL it does not just miss the local statement cache, but it will also miss the HANA execution plan cache. Which means that this can cause a dramatic overall response time impact as this force HANA to fully parse through the statement and all its dependencies which depends upon the complexity of the procedure definition.

@kasimos

kasimos commented Jul 14, 2026

Copy link
Copy Markdown
Author

Thanks, somehow I didn't find your PR when we encountered this. Sorry for that. closing the PR and moving discussion over to #1496

@kasimos kasimos closed this Jul 14, 2026
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