Skip to content

Conversation

@imnotjames
Copy link
Contributor

@imnotjames imnotjames commented Oct 11, 2020

we were supporting an empty IN clause for MySQL and Oracle
and this updates the handling to be for all other dialects as well
by making the "empty" clause be 0=1

This follows the lead of a number of other projects in a similar space:

I've also chosen to use 1=0 in the empty case because it's the most likely technique which allows the various query optimizers to do their magic. :)

Closes #4865
fixes #2195

we were supporting an empty `IN` clause for MySQL and Oracle
and this updates the handling to be for all other dialects as well
by making the "empty" clause be `0=1`

fixes typeorm#2195
@imnotjames
Copy link
Contributor Author

The test commit had CI ran against it to show the failures - the results can be found here

@imnotjames
Copy link
Contributor Author

imnotjames commented Oct 11, 2020

From a performance standpoint, all query optimizers that I've checked prevent the query from even doing any work (EG, this will turn the entire query into a no-op, so no table scan happens). The negation turns the expression itself into a no-op and it has no effect on the query.

I checked this against the following databases via an EXPLAIN or comparable tool:

  • MSSQL
  • PostgreSQL
  • MySQL
  • MariaDB
  • SQLite (I had trouble reading it but I think the HALT is above the actual table scan?)
  • CockroachDB

@imnotjames imnotjames merged commit 9635080 into typeorm:master Oct 15, 2020
@imnotjames imnotjames deleted the feat/where-in-empty branch October 15, 2020 17:29
@MultiWar
Copy link

Cool, thanks for working on this

@imnotjames imnotjames added the hacktoberfest-accepted label hacktoberfest label Oct 16, 2020
zaro pushed a commit to zaro/typeorm that referenced this pull request Jan 12, 2021
we were supporting an empty `IN` clause for MySQL and Oracle
and this updates the handling to be for all other dialects as well
by making the "empty" clause be `0=1`

Closes typeorm#4865
fixes typeorm#2195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted label hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL Syntax error when empty array is given into "In" method

2 participants