powa-team / pg_qualstats

A PostgreSQL extension for collecting statistics about predicates, helping find what indices are missing
Other
272 stars 26 forks source link

execution_count column does not show proper row count #62

Closed nikhil-postgres closed 3 weeks ago

nikhil-postgres commented 3 weeks ago

Hi Team,

I was working on pg_qualstats extension for the first time. In the document, it says 'execution_count' column of pg_qualstats show the 'no of records processes'.

I tested with below scenario. The original value for this column is 14. I ran an UPDATE which updates a single record. After this UPDATE, the value for execution_count changed to 18 but it updated only one record. Why is this difference ?

postgres=# select * from pg_qualstats_pretty;
 left_schema |    left_table    | left_column |   operator   | right_schema | right_table | right_column | occurences | execution_count | nbfiltered 
-------------+------------------+-------------+--------------+--------------+-------------+--------------+------------+-----------------+------------
 public      | pgbench_branches | bid         | pg_catalog.= |              |             |              |          2 |              14 |          0
(1 row)

postgres=# UPDATE pgbench_branches SET bbalance = bbalance + 20 where bid=3;
UPDATE 1
postgres=# select * from pg_qualstats_pretty;
 left_schema |    left_table    | left_column |   operator   | right_schema | right_table | right_column | occurences | execution_count | nbfiltered 
-------------+------------------+-------------+--------------+--------------+-------------+--------------+------------+-----------------+------------
 public      | pgbench_branches | bid         | pg_catalog.= |              |             |              |          3 |              18 |          0
(1 row)
rjuju commented 3 weeks ago

Hi,

The execution_count column is the number of time the operator was executed, not the number of time it matched your condition.

The most likely explanation here is that you initialized your pgbench database with scale = 4, which mean that you have 4 records in the pgbench_branches table, so the UPDATE visited 4 rows and checked each of them to see if it's the specified bid or not, and modified only 1 row.