PostgreSQL – How do I know the actual count in a big table of high insertion rates

Suppose I have a table with exactly 10M rows. I need to know the exact number of rows. It takes 5 seconds for COUNT requests. Suppose 100 rows are added to the table every second.

If I now request that the database count exactly 10,000,000 rows, and this request takes 5 seconds to complete, the result is 10000000, 10000500 or some value between these two values?

If you are not running the statement in an explicit transaction, then it gives The count out will be correct, so 10000000 is not 10000500.

If you run it in a transaction, the exact behavior depends on the isolation level you use, and what happened before in that transaction Things.

Suppose I have a table with exactly 10M rows. I need to know the exact number of rows. It takes 5 seconds for COUNT requests. Suppose I add to the table every second 100 rows.

If I now request that the database count exactly 10,000,000 rows, and the request takes 5 seconds to complete, the result is 10000000, 10000500 or some value between these two values?

If you are not running the statement in an explicit transaction, then the count it gives when the statement starts to execute will be correct, so 10000000 is not 10000500 .

If you run it in a transaction, the exact behavior depends on the isolation level you use and what happened before in that transaction.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 714 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.