Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing performance issue related with querydsl spatial on hibernate. #3718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dcuestam
Copy link

@dcuestam dcuestam commented Apr 6, 2024

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

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.
@jwgmeligmeyling
Copy link
Member

jwgmeligmeyling commented Apr 6, 2024

The problem is that a function that returns a boolean cannot be used as predicate in JPQL. So the queries that this produces are semantically not correct JPQL. HQL is a bit more flexible, but this also varies between versions of Hibernate (the whole reason that this was introduced in d6a17a7). So there is a compatibility issue here (and we will have to do some testing against various versions of Hibernate).

Screenshot 2024-04-06 at 13 42 29

@dcuestam
Copy link
Author

dcuestam commented Apr 6, 2024

Hi @jwgmeligmeyling , but the current version of Hibernate in the project is 5.5.3.Final and from this version should be compatible, isn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants