Skip to content

Conversation

@tomaszmadeyski
Copy link

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
Copy link
Member

morozov commented Apr 17, 2017

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
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
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
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