Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

Which of the following two is more accurate?

select numbackends from pg_stat_database;

select count(*) from pg_stat_activity;

1 Answer

0 votes
by (40.7k points)

The equivalent version for the first query will be like this:

SELECT sum(numbackends) FROM pg_stat_database;

In the above case, you can expect the first version to be slightly faster than the second one, Because it has lesser rows to count. But you won't be able to measure the difference.

As both the queries are based on exactly the same data, so they will be equally accurate.

Related questions

Browse Categories