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

Inefficient implementation (in my case) of method com.querydsl.jpa.JPAQueryBase.exists() #1241

Closed
leofromgroza opened this issue Mar 6, 2015 · 3 comments
Milestone

Comments

@leofromgroza
Copy link

@leofromgroza leofromgroza commented Mar 6, 2015

boolean com.querydsl.jpa.JPAQueryBase.exists()
In my case I'm trying to check if active User presents in DB. For this purposes I use exists method. I expected that QueryDSL will generate one simple SQL request. But it generates not only one SQL request for extracting User, but also a few requests for extracting whole bunch of EAGER fields of my User model (believe me, I need them))). After that I saw this piece of code and I undertand that in fact there are two subvariants of exists method. But both of them first of all extracts full User model with LIMIT 1.
But it looks like that it would be better to use simple SELECT with COUNT(*) and check if result:
if result>1 than return true, else -> return false.
I understand that for giant tables and very simple models COUNT will be working slower than SELECT with LIMIT 1, but in my case (User table has ~1500 rows) COUNT is working much more faster than current implementation of exists() method.

@timowest
Copy link
Member

@timowest timowest commented Mar 6, 2015

Thanks for the issue. I added a PR that uses select 1 ... instead.

@timowest timowest added this to the 4.0.0 milestone Mar 6, 2015
@leofromgroza
Copy link
Author

@leofromgroza leofromgroza commented Mar 7, 2015

Thank you very much for this.

@timowest
Copy link
Member

@timowest timowest commented Mar 7, 2015

I will backport this also to the 3.* branch.

@timowest timowest removed the progress label Mar 13, 2015
@timowest timowest modified the milestones: 3.6.3, 4.0.0 Mar 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.