Skip to content

DBAL-858: Workaround for Oracle's limit in IN clause items - #2699

Closed
tomaszmadeyski wants to merge 1 commit into
doctrine:masterfrom
tomaszmadeyski:dbal-858
Closed

DBAL-858: Workaround for Oracle's limit in IN clause items#2699
tomaszmadeyski wants to merge 1 commit into
doctrine:masterfrom
tomaszmadeyski:dbal-858

Conversation

@tomaszmadeyski

Copy link
Copy Markdown

Oracle does not allow queries with more than 1000 elements in IN clause

Query:
SELECT ... WHERE foo IN (1,..., 1001)

will result in ORA-01795 maximum number of expressions in a list is 1000

This PR introduces method to convert such queries from
SELECT ... WHERE foo IN (1,..., 1001)
to
SELECT ... WHERE (foo IN (1,..., 1000) OR foo IN (1001))
and does this conversion before parsing query

It fixes #2095

@morozov

morozov commented Apr 17, 2017

Copy link
Copy Markdown
Member

In my understanding, Oracle enforces the limit on the number of parameters in order to prevent huge queries and too many bound variables. As long as these values are not taken from the input, the query above can be rewritten using subquery. Otherwise, a temporary table can be used.

I don't think the DBAL should workaround this limitation.

@Ocramius

Copy link
Copy Markdown
Member

I don't think the DBAL should workaround this limitation.

And especially not with hacks/workarounds. If there were a proper solution, then we could use it, but this really just needs to be escalated to the underlying driver's maintainer.

@tomaszmadeyski

Copy link
Copy Markdown
Author

Otherwise, a temporary table can be used.

That's exact issue I'm trying to solve. Using temporary table means writing a lot of boilerplate code and it's a hassle

I don't think the DBAL should workaround this limitation.

This is a port of solution for .NET's Entity Framework in their Oracle's driver, it is done in DBAL layer and I think it is very convenient http://blog.devart.com/entity-framework-sql-generation-enhancements-for-in-clause.html (see Oracle-specific SQL paragraph)

but this really just needs to be escalated to the underlying driver's maintainer

Do you mean oci8 driver's maintainer? If so this is not an issue of a driver, it is a feature/limitation of a DB engine itself and I don't think there's any chance Oracle will change this

@Ocramius

Copy link
Copy Markdown
Member

Do you mean oci8 driver's maintainer? If so this is not an issue of a driver, it is a feature/limitation of a DB engine itself and I don't think there's any chance Oracle will change this

Well aware of it, but this really shouldn't lead to this massive amount of complication for an edge case.

The fact that a tool has an imposed limitation doesn't mean that everyone else should work hard to provide a messy workaround for it: it should be fixed at the source of the problem or not at all, sorry :-\

If anyone knows Oracle devs that can influence the decisions there (I doubt it, since it's corporate world, which is basically Vogon poetry ^ 2), then please poke them and ask what the correct approach would be here. Adding complexity to the DBAL is something I'd not really want, as it already spawned massive amounts of headache for SQL Server (limit subquery mess).

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DBAL-858: oracle IN statement with more than 1000 values

3 participants