Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.
This repository was 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

@FireEmerald

Description

@FireEmerald

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions