How to get the size of a Service Broker Queue quickly when the table is >500K rows, and filter it by MessageType

StackOverflow https://stackoverflow.com/questions/18620300

  •  27-06-2022
  •  | 
  •  

Question

A couple of years ago, a question was asked on StackOverflow about getting the count of messages in a large queue.

How do I get the size of a Service Broker Queue quickly when the table is >500k rows?

An answer was given to query the underlying b-tree.

http://rusanu.com/2006/11/09/fast-way-to-check-message-count/

If there are multiple MessageTypes in the queue, is there a way to do this same query of the underlying b-tree with the counts filtered by MessageType?

We can do it this way, but we fear this could cause performance problems on large queues.

SELECT COUNT(*) FROM My_Queue WHERE message_type_name = 'MyMessageType'
Was it helpful?

Solution

No - the query on the b-tree is looking at the real data structure (the concept of a table that we think all relational databases are composed if is, itself, not really what's there underneath).

The only way to filter on a value in a column is to run the query against the table - unfortunately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top