You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prepared statement does not work for Symbol operators #10942
In what situations are prepared statements expected to work?
At the moment, they do not work at all for Model.findAll() and works buggy for Model.update().
Did not try other methods.
Can I opt out using prepared statements for single query? Or at least for all queries, something like new Sequelize({ usePrepared: false }) ?
This is the most sneaky. This will create a new plan for every distinct where condition. If a connection is reused for a long time, bad things will happen, see #10832
3. findAll
awaitPost.findAll({where: {year: 2018}})
I just discovered that it is "by design" for all SELECT related #3495 (comment)
4. increment
awaitPost.increment('year',{where: {year: 2018}})
Does not use PREPARE EXECUTE workflow, although this is a kind of update and must use it internally.
Also, by opting out of prepared statements, what would you expect to happen instead?
I expect that the query is executed in the default “text” mode, all substitutions are performed on the client side, as in case 3, 4.
+1 #3495 (comment) for opting out of prepared statements
It is very strange that maintainers merged this feature in the release. It works 50/50% (cases where it should- and should not- work are not mentioned in docs), have bugs (partially covered with tests?). And with this alpha implementation, you are forced to be an alpha tester, because there is no way to opt out.
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
The substituted parameter values inside prepared statements cause prepared statements to leak inside db. To release them, the db connection has to be closed.
The db connections are typically closed on connection options.pool.idle timeout. But when the workload is able to keep all options.pool.max connections busy for long enough time, eventually the (in case of mysql) sysvar_max_prepared_stmt_count limit is reached and all subsequent db requests are denied with Can't create more than max_prepared_stmt_count statements.
We are at 6.24.X as well. And maxed out the prepared statements on PROD.
Need to keep rebooting our engines to clear this out.
Is this also an issue with raw queries? Do we have known issues related to this?
We don't have much Op.x on our usage at all.
Our workaround is to limit the number prepared statements per connection. The prepared statements are seldom measurable in a bigger application. We did not measure any difference.
Activity
SnosMe commentedon May 12, 2019
And a few questions?
At the moment, they do not work at all for
Model.findAll()and works buggy forModel.update().Did not try other methods.
new Sequelize({ usePrepared: false })?papb commentedon Jul 25, 2019
Hello, I did not understand.
Can you clarify this with a MVCE?
Also, by opting out of prepared statements, what would you expect to happen instead?
SnosMe commentedon Jul 25, 2019
Test cases (Sequelize v5.10.2):
1.
update, using where "field: cond"2.
update, using advanced syntaxThis is the most sneaky. This will create a new plan for every distinct
wherecondition. If a connection is reused for a long time, bad things will happen, see #108323.
findAllI just discovered that it is "by design" for all SELECT related #3495 (comment)
4.
incrementDoes not use PREPARE EXECUTE workflow, although this is a kind of
updateand must use it internally.I expect that the query is executed in the default “text” mode, all substitutions are performed on the client side, as in case 3, 4.
+1 #3495 (comment) for opting out of prepared statements
It is very strange that maintainers merged this feature in the release. It works 50/50% (cases where it should- and should not- work are not mentioned in docs), have bugs (partially covered with tests?). And with this alpha implementation, you are forced to be an alpha tester, because there is no way to opt out.
ralexandr commentedon Aug 12, 2019
Is there any updates on this? Met same issue
github-actions commentedon Nov 10, 2021
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
katreniak commentedon May 2, 2022
The substituted parameter values inside prepared statements cause prepared statements to leak inside db. To release them, the db connection has to be closed.
The db connections are typically closed on connection options.pool.idle timeout. But when the workload is able to keep all options.pool.max connections busy for long enough time, eventually the (in case of mysql) sysvar_max_prepared_stmt_count limit is reached and all subsequent db requests are denied with
Can't create more than max_prepared_stmt_count statements.Is there a way to prevent this problem?
ephys commentedon May 2, 2022
That issue about prepared statements not being cleared is being tracked here: #10832, I'll post a status update over there
mahelbir commentedon Aug 13, 2023
Any updates?
ephys commentedon Aug 15, 2023
This was fixed in Sequelize 7 (pr), but it is very unlikely we'll be able to backport the fix
severinolorillajr commentedon Apr 7, 2025
@ephys quick confirmation.
We are at 6.24.X as well. And maxed out the prepared statements on PROD.
Need to keep rebooting our engines to clear this out.
Is this also an issue with raw queries? Do we have known issues related to this?
We don't have much Op.x on our usage at all.
katreniak commentedon Apr 7, 2025
Our workaround is to limit the number prepared statements per connection. The prepared statements are seldom measurable in a bigger application. We did not measure any difference.