Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Function get_table_bloat_approx_sql fails with division by zero #464

Closed
FireEmerald opened this issue Mar 10, 2022 · 1 comment
Closed
Assignees

Comments

@FireEmerald
Copy link
Contributor

FireEmerald commented Mar 10, 2022

Problem:

The divisions in these case statements fail when the tblpages from the subquery is 0 for some rows of a section of a partitioned table.

CASE
WHEN tblpages - est_tblpages > 0
THEN 100 * (tblpages - est_tblpages) / tblpages::float
ELSE 0
END AS extra_ratio,
fillfactor,
CASE
WHEN tblpages - est_tblpages_ff > 0
THEN (tblpages - est_tblpages_ff) * bs
ELSE 0
END AS bloat_size,
CASE
WHEN tblpages - est_tblpages_ff > 0
THEN 100 * (tblpages - est_tblpages_ff) / tblpages::float
ELSE 0
END AS bloat_ratio,

Sample row of subquery:

est_tblpages | est_tblpages_ff | tblpages | fillfactor | bs   | tblid    | schemaname | tblname               | heappages | toastpages | is_na
-3             -3                0          100          8192   17624404   public       partitioned_table_001   0           0            t

Table partitioned_table_001 is a partition of partitioned_table.

Possible fix?

--   v-----new------v
WHEN tblpages > 0 AND tblpages - est_tblpages > 0
    THEN 100 * (tblpages - est_tblpages) / tblpages::float
ELSE 0
END                        AS extra_ratio,

Should be added to all three CASES.

@pashagolub
Copy link
Collaborator

Thanks for your support. We will fix this ASAP.

@pashagolub pashagolub self-assigned this Apr 20, 2022
@pashagolub pashagolub moved this to Todo in pgwatch2 Apr 20, 2022
kmoppel-cognite added a commit that referenced this issue Apr 25, 2022
…oat_approx_sql

[-] fix `get_table_bloat_approx_sql()` when `tblpages = 0`, closes #464
Repository owner moved this from Todo to Done in pgwatch2 Apr 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants