Skip to main content
added [postgresql-performance] to 571 questions - Shog9 (Id=1924)
Link
added [query-performance] to 2412 questions - Shog9 (Id=1924)
Link
tags, sharpen title, trim nosie, clarify & fix orthogonal syntax error in query
Source Link
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

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

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(rp.tag) like ('%verified%')  
and not lower(rp.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 allAnd I only need to know if iswhether 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?

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?

Improving performance of count where only result > 0 matters

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(rp.tag) like ('%verified%') 
and not lower(rp.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. And I only need to know whether the result is greater than 0.

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

Source Link
isADon
  • 125
  • 4
Loading