Skip to main content
1 of 4
isADon
  • 125
  • 4

Improving performance on count query where I only care if result > 0

I have following query

select count(*) rp.tag
from submission 
inner join post rp on submission.id = rp.submission_id 
where user_name = ?1
and lower(tag) like ('%verified%') and not lower(tag) like ('%unverified%')

If the result is greater than 0 I do something in my application for this user.

I run this query against a big list of users and it takes close to an hour to finish the whole process. I am looking in to ways to speed this up. The problem I see is that I am doing a count when I don't really need it. As I said all I need to know if is the result is greater than 0 or not.

Is there a way to finish the query early if any of the rp.tag match my condition?

isADon
  • 125
  • 4