Show 'Rows Removed by Filter' with two fractional digits in EXPLAIN
Thread notes
1 note#feature#minor#enhancement
hackorum-bot#feature#minor#enhancement
@global #feature #minor #enhancement
Hi,
Since ddb17e387aa, EXPLAIN reports per-loop actual rows with two decimal digits.
The neighbouring counters - Rows Removed by Filter, by Join Filter - are divided
by nloops too, but are still printed with zero digits. In a parameterised inner
side this makes the two numbers contradict each other, for example:
-> Index Scan using tenk1_unique1 on tenk1 b (actual rows=0.90 loops=10)
Index Cond: (unique1 = g.g)
Filter: (ten <> 0)
Rows Removed by Filter: 0
The scan returned 0.90 rows per loop out of 1.00 fetched, yet the filter claims
it removed nothing. See the attached patch for complete examples.
The patch is a single-line change in show_instrumentation_count() plus two
tests. It is a concept, not a finished patch: I have not regenerated the other
expected outputs, where many values will change from "N" to "N.00" - you can
find a sketch for that in 0002-* file. Before going through that churn, I would
like to hear whether people agree that these counters should follow the same
rule as actual rows. The options I see are:
1. Always print two digits, as actual rows do now.
2. Leave the math to users and print exact totals without dividing by nloops.
The second approach is a much bigger change, with obvious pros and cons.
The first one is simpler and more conservative, and it is what the attached
patch does. In [1]https://www.depesz.com/2025/02/28/waiting-for-postgresql-18-allow-explain-to-indicate-fractional-rows/, depesz describes how the switch to fractional actual rows
affected his explain parser, and it needed only a small fix. So I expect this
change to be similarly harmless for tools.
Thoughts?
[1]: https://www.depesz.com/2025/02/28/waiting-for-postgresql-18-allow-explain-to-indicate-fractional-rows/
https://www.depesz.com/2025/02/28/waiting-for-postgresql-18-allow-explain-to-indicate-fractional-rows/
--
regards, Andrei Lepikhov,
pgEdge
Attachments:
t254584_10001-Switch-JOIN-and-SCAN-filter-explain-output-to-floati.patchtext/plain; charset=UTF-8; name=0001-Switch-JOIN-and-SCAN-filter-explain-output-to-floati.patchDownload+47-2
0002-Adjust-regression-tests-to-fractional-Rows-Removed-b.patchtext/plain; charset=UTF-8; name=0002-Adjust-regression-tests-to-fractional-Rows-Removed-b.patchDownload+37-38
On 11/6/26 11:57, Andrei Lepikhov wrote:
Since ddb17e387aa, EXPLAIN reports per-loop actual rows with two decimal digits.
The neighbouring counters - Rows Removed by Filter, by Join Filter - are divided
by nloops too, but are still printed with zero digits. In a parameterised inner
side this makes the two numbers contradict each other, for example:-> Index Scan using tenk1_unique1 on tenk1 b (actual rows=0.90 loops=10)
Index Cond: (unique1 = g.g)
Filter: (ten <> 0)
Rows Removed by Filter: 0The scan returned 0.90 rows per loop out of 1.00 fetched, yet the filter claims
it removed nothing. See the attached patch for complete examples.
LGTM. Since these counters are also divided by nloops, it makes sense to
display them with two digits after the decimal point, just like actual rows.
The patch is a single-line change in show_instrumentation_count() plus two
tests. It is a concept, not a finished patch: I have not regenerated the other
expected outputs, where many values will change from "N" to "N.00" - you can
find a sketch for that in 0002-* file.
If we switch to fractional row counts, we should also remember to update
the relevant examples in the doc, including "Rows Removed by Filter",
"Rows Removed by Index Recheck", "Rows Removed by Conflict Filter",
"Rows Removed by Join Filter".
Regardless of whether we change this output format, it would be be
useful to document in the "Using EXPLAIN" section (perform.sgml), in the
paragraph describing "Rows Removed", that these counts are averages per
execution of the node. This is already the case, but the paragraph does
not mention it.
Before going through that churn, I would
like to hear whether people agree that these counters should follow the same
rule as actual rows. The options I see are:1. Always print two digits, as actual rows do now.
2. Leave the math to users and print exact totals without dividing by nloops.The second approach is a much bigger change, with obvious pros and cons.
The first one is simpler and more conservative, and it is what the attached
patch does. In [1], depesz describes how the switch to fractional actual rows
affected his explain parser, and it needed only a small fix. So I expect this
change to be similarly harmless for tools.Thoughts?
I also prefer the first option, as it is more conservative and keeps
these counters consistent with actual rows.
--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/
On 06/11/2026 14:17, Ilia Evdokimov wrote:
On 11/6/26 11:57, Andrei Lepikhov wrote:
The patch is a single-line change in show_instrumentation_count() plus two
tests. It is a concept, not a finished patch: I have not regenerated the other
expected outputs, where many values will change from "N" to "N.00" - you can
find a sketch for that in 0002-* file.If we switch to fractional row counts, we should also remember to update the
relevant examples in the doc, including "Rows Removed by Filter", "Rows Removed
by Index Recheck", "Rows Removed by Conflict Filter", "Rows Removed by Join
Filter".Regardless of whether we change this output format, it would be be useful to
document in the "Using EXPLAIN" section (perform.sgml), in the paragraph
describing "Rows Removed", that these counts are averages per execution of the
node. This is already the case, but the paragraph does not mention it.
Ok, my AI coding agent detects such places quite nicely. See the patch v0-0002-*
in attachment.
rule as actual rows. The options I see are:
1. Always print two digits, as actual rows do now.
2. Leave the math to users and print exact totals without dividing by nloops.The second approach is a much bigger change, with obvious pros and cons.
The first one is simpler and more conservative, and it is what the attached
patch does. In [1], depesz describes how the switch to fractional actual rows
affected his explain parser, and it needed only a small fix. So I expect this
change to be similarly harmless for tools.I also prefer the first option, as it is more conservative and keeps these
counters consistent with actual rows.
Hmm, I wouldn't say that I prefer the first approach. Reading explains quite
frequently that I'd prefer sums on all cycles for sure - sometimes huge work is
hidden in the third or even sixth digit after the point - because it is the
first non-zero digit. But I understand the reasoning and agree - it is a
contradictory question. So, No.1 is just a compromise.
--
regards, Andrei Lepikhov,
pgEdge
Attachments:
t254584_3v0-0001-Switch-JOIN-and-SCAN-filter-explain-output-to-flo.patchtext/plain; charset=UTF-8; name=v0-0001-Switch-JOIN-and-SCAN-filter-explain-output-to-flo.patchDownload+52-2
v0-0002-Adjust-regression-tests-and-docs-to-fractional-Ro.patchtext/plain; charset=UTF-8; name=v0-0002-Adjust-regression-tests-and-docs-to-fractional-Ro.patchDownload+55-53
On Fri, Nov 6, 2026 at 3:57 AM Andrei Lepikhov <lepihov@gmail.com> wrote:
1. Always print two digits, as actual rows do now.
2. Leave the math to users and print exact totals without dividing by nloops.
I think we should do #1. Dividing by nloops is never what I personally
want for any of these, but we got enough consensus on it to move
forward with it for the actual row counts, so I think doing the same
thing here makes sense to me. Maybe eventually we will get consensus
on other changes, but I think we probably don't have it now, and doing
what we can do is better than arguing a case we probably won't win.
--
Robert Haas
Databricks
On 09/11/2026 14:28, Robert Haas wrote:
On Fri, Nov 6, 2026 at 3:57 AM Andrei Lepikhov <lepihov@gmail.com> wrote:
1. Always print two digits, as actual rows do now.
2. Leave the math to users and print exact totals without dividing by nloops.I think we should do #1. Dividing by nloops is never what I personally
want for any of these, but we got enough consensus on it to move
forward with it for the actual row counts, so I think doing the same
thing here makes sense to me. Maybe eventually we will get consensus
on other changes, but I think we probably don't have it now, and doing
what we can do is better than arguing a case we probably won't win.
Ok, agreed.
Here's the next version of the patch. It passed 'make check-world' on the
current master (c074737f687).
--
regards, Andrei Lepikhov,
pgEdge
On 11/10/26 01:59, Andrei Lepikhov wrote:
Here's the next version of the patch. It passed 'make check-world' on the
current master (c074737f687).
One small nit: could we also use a precision of 2 in the else branch of
`nloops > 0`, so that it prints 0.00 rather than 0? Looking at the
changes in [0]https://gitlab.com/depesz/Pg--Explain/-/commit/5281e4ea1b23b1823e47f353055407307727adec#line_c77cc309f_137, its parser will accept both integer and fractional
values, so this suggestion is mainly for consistency.
The rest of the v1-patch looks good to me.
[0]: https://gitlab.com/depesz/Pg--Explain/-/commit/5281e4ea1b23b1823e47f353055407307727adec#line_c77cc309f_137
https://gitlab.com/depesz/Pg--Explain/-/commit/5281e4ea1b23b1823e47f353055407307727adec#line_c77cc309f_137
--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/
On 10/11/2026 08:12, Ilia Evdokimov wrote:
On 11/10/26 01:59, Andrei Lepikhov wrote:
Here's the next version of the patch. It passed 'make check-world' on the
current master (c074737f687).One small nit: could we also use a precision of 2 in the else branch of `nloops
0`, so that it prints 0.00 rather than 0? Looking at the changes in [0], its
parser will accept both integer and fractional values, so this suggestion is
mainly for consistency.
I doubt that. What you want is the never-executed, non-text format case. In this
case, I see the following:
"Actual Rows": 0,
To ensure, I checked it on the current master with the query:
explain (analyze, costs off, timing off, summary off, buffers off, format json)
select * from
generate_series(1,0) g, lateral
(select * from pg_class c
where c.relpages + g > 0
offset 0
) s;
So, as I understand it, adding floating-point to the 'else' section causes
inconsistency with the 'Actual Rows' format. Am I wrong?
--
regards, Andrei Lepikhov,
pgEdge
On 11/10/26 13:33, Andrei Lepikhov wrote:
On 10/11/2026 08:12, Ilia Evdokimov wrote:
On 11/10/26 01:59, Andrei Lepikhov wrote:
Here's the next version of the patch. It passed 'make check-world' on the
current master (c074737f687).One small nit: could we also use a precision of 2 in the else branch of `nloops
0`, so that it prints 0.00 rather than 0? Looking at the changes in [0], its
parser will accept both integer and fractional values, so this suggestion is
mainly for consistency.I doubt that. What you want is the never-executed, non-text format case. In this
case, I see the following:"Actual Rows": 0,
To ensure, I checked it on the current master with the query:
explain (analyze, costs off, timing off, summary off, buffers off, format json)
select * from
generate_series(1,0) g, lateral
(select * from pg_class c
where c.relpages + g > 0
offset 0
) s;So, as I understand it, adding floating-point to the 'else' section causes
inconsistency with the 'Actual Rows' format. Am I wrong?
You're right, I overlooked the never-executed case for Actual Rows.
Thanks for checking!
--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/
I reviewed v1 patch and it looks good to me
The patch is ready for committer, but needs a rebase to apply to the
current 19db7e5
--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/
On 23/11/2026 16:20, Ilia Evdokimov wrote:
I reviewed v1 patch and it looks good to me
The patch is ready for committer, but needs a rebase to apply to the current
19db7e5
Thanks! There is a conflict with edbb1d2, committed couple of weeks ago. In
attachment see a new version rebased onto current master.
--
regards, Andrei Lepikhov,
pgEdge