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
I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
In the current version, expressions like inArray(field, []) generate SQL responses such as false. However, there is no advanced optimization for such cases. This can lead to situations where more complex condition expressions, like and(..., inArray(..., [])), only produce (... and false). Ideally, (... and false) can be optimized to false, and (... or true) can be optimized to true.
In extreme cases, this means the entire SQL query could be reduced to select ... from ... where false ...; or select ... from ...; (where true directly optimizes to removing the where clause).
I believe this can be implemented. Based on my initial review of the Drizzle ORM code, I see two potential approaches:
Modify condition expressions to accept not only SQLWrapper | undefined but also boolean literals. This would allow for direct optimization. The downside is that it would require more widespread changes across the codebase.
Detect constant conditions during the final SQL generation phase. While this method is more complex, it may be a more localized change than the first option.
Additionally, more complex queries could also be optimized. For instance, in subqueries like:
select ... from ... where
cond1 or
(exists (select ... from ... where false)) or
(... in (select ... from ... where false))
This could be optimized to:
select ... from ... where cond1
Expected Outcome:
Better optimization of SQL queries by handling constant conditions (true/false) more efficiently, leading to potentially more performant queries in edge cases.
The text was updated successfully, but these errors were encountered:
Feature hasn't been suggested before.
Describe the enhancement you want to request
In the current version, expressions like
inArray(field, [])
generate SQL responses such asfalse
. However, there is no advanced optimization for such cases. This can lead to situations where more complex condition expressions, likeand(..., inArray(..., []))
, only produce(... and false)
. Ideally,(... and false)
can be optimized tofalse
, and(... or true)
can be optimized totrue
.In extreme cases, this means the entire SQL query could be reduced to
select ... from ... where false ...;
orselect ... from ...;
(where true
directly optimizes to removing thewhere
clause).I believe this can be implemented. Based on my initial review of the Drizzle ORM code, I see two potential approaches:
Modify condition expressions to accept not only
SQLWrapper | undefined
but alsoboolean
literals. This would allow for direct optimization. The downside is that it would require more widespread changes across the codebase.Detect constant conditions during the final SQL generation phase. While this method is more complex, it may be a more localized change than the first option.
Additionally, more complex queries could also be optimized. For instance, in subqueries like:
This could be optimized to:
Expected Outcome:
Better optimization of SQL queries by handling constant conditions (
true
/false
) more efficiently, leading to potentially more performant queries in edge cases.The text was updated successfully, but these errors were encountered: