0 votes
1 view
in SQL by (22.4k 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.3k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...