Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform query without parameter 'feature' causes excessive query plans in MSSQL #10810

Open
2 of 18 tasks
jostrander opened this issue Apr 2, 2024 · 0 comments
Open
2 of 18 tasks

Comments

@jostrander
Copy link

Issue description

stringified IDs for where-in clause causes a single query plan for each query

Expected Behavior

I would expect that value's injected in the query use query parameters and not use string interpolation. This appears to be the default behavior. However, an exception was added to appease sqlite's lower 1000 parameter limit in #190.

Actual Behavior

String interpolation of query values into the query instead of using query parameters if all IDs are numbers.

Steps to reproduce

Create two related entities, fill each with records and query using relations in query builder or find() and notice that the where includes parameterized and numerical inline arguments.

My Environment

Dependency Version
Operating System N/A
Node.js version v20.12.0
Typescript version 4.9.5
TypeORM version 0.3.10

Additional Context

const areAllNumbers = ids.every(
(id: any) => typeof id === "number",
)
if (areAllNumbers) {
// fixes #190. if all numbers then its safe to perform query without parameter
condition = `${mainAliasName}.${
metadata.primaryColumns[0].propertyPath
} IN (${ids.join(", ")})`

This is one of the locations where these IDs are injected. Manually setting areAllNumbers to false solves the problem for my use case, however that may not be desired behavior for some users.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

@jostrander jostrander changed the title Perform query without parameter 'feature' causes excessive query plans Perform query without parameter 'feature' causes excessive query plans in MSSQL Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant