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

leofromgroza opened this Issue Mar 6, 2015 · 3 comments


None yet

2 participants


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

Thank you very much for this.

timowest commented Mar 7, 2015

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

@Shredder121 Shredder121 closed this in #1243 Mar 9, 2015
@timowest timowest removed the progress label Mar 13, 2015
@timowest timowest modified the milestone: 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