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.
if result>1 than return true, else -> return false
Thanks for the issue. I added a PR that uses select 1 ... instead.
select 1 ...
Thank you very much for this.
I will backport this also to the 3.* branch.