Fixing performance issue related with querydsl spatial on hibernate. #3718
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As the representation of the operations were doing an equal true (boolean check), the DB engine is not able to use the spatial index, and instead of performing the intersects with the entities using the spatial index and comparing only the ones indicated by this one, was applying the intersects operation to all the entities.
How was discovered?
While migrating my application from native spatial queries to querydsl-spatial I found a big downgrade on the performance. Analysing the differences between the native queries that I had and the ones generated by querydsl-spatial, I was able to indentify that queryDSL spatial was adding for most of the operations that I was interested on an = true clause. It is not needed and this comparison makes the db engine to not to use the spatial index on those queries.
it can be easily analysed by an EXPLAIN clause, that would show that using = true/false, the spatial index is not used, but without this clause, it is used, having exactly the same result in the queries.
In my case, the performance issue was of having queries executed in few milliseconds to more than 10 minutes in some cases