You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix pg_statio_all_tables view for multiple TOAST indexes.
A TOAST table can normally have only one index, but there are corner
cases where it has more; for example, transiently during REINDEX
CONCURRENTLY. In such a case, the pg_statio_all_tables view produced
multiple rows for the owning table, one per TOAST index. Refactor the
view to avoid that, instead summing the stats across all the indexes,
as we do for regular table indexes.
While this has been wrong for a long time, back-patching seems unwise
due to the difficulty of putting a system view change into back
branches.
Andrei Zubkov, tweaked a bit by me
Discussion: https://postgr.es/m/acefef4189706971fc475f912c1afdab1c48d627.camel@moonset.ru
Copy file name to clipboardExpand all lines: src/test/regress/expected/rules.out
+13-8
Original file line number
Diff line number
Diff line change
@@ -2269,19 +2269,24 @@ pg_statio_all_tables| SELECT c.oid AS relid,
2269
2269
c.relname,
2270
2270
(pg_stat_get_blocks_fetched(c.oid) - pg_stat_get_blocks_hit(c.oid)) AS heap_blks_read,
2271
2271
pg_stat_get_blocks_hit(c.oid) AS heap_blks_hit,
2272
-
(sum((pg_stat_get_blocks_fetched(i.indexrelid) - pg_stat_get_blocks_hit(i.indexrelid))))::bigint AS idx_blks_read,
2273
-
(sum(pg_stat_get_blocks_hit(i.indexrelid)))::bigint AS idx_blks_hit,
2272
+
i.idx_blks_read,
2273
+
i.idx_blks_hit,
2274
2274
(pg_stat_get_blocks_fetched(t.oid) - pg_stat_get_blocks_hit(t.oid)) AS toast_blks_read,
2275
2275
pg_stat_get_blocks_hit(t.oid) AS toast_blks_hit,
2276
-
(pg_stat_get_blocks_fetched(x.indexrelid) - pg_stat_get_blocks_hit(x.indexrelid)) AS tidx_blks_read,
2277
-
pg_stat_get_blocks_hit(x.indexrelid) AS tidx_blks_hit
2276
+
x.idx_blks_read AS tidx_blks_read,
2277
+
x.idx_blks_hit AS tidx_blks_hit
2278
2278
FROM ((((pg_class c
2279
-
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
2280
2279
LEFT JOIN pg_class t ON ((c.reltoastrelid = t.oid)))
2281
-
LEFT JOIN pg_index x ON ((t.oid = x.indrelid)))
2282
2280
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
2283
-
WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]))
2284
-
GROUP BY c.oid, n.nspname, c.relname, t.oid, x.indexrelid;
2281
+
LEFT JOIN LATERAL ( SELECT (sum((pg_stat_get_blocks_fetched(pg_index.indexrelid) - pg_stat_get_blocks_hit(pg_index.indexrelid))))::bigint AS idx_blks_read,
2282
+
(sum(pg_stat_get_blocks_hit(pg_index.indexrelid)))::bigint AS idx_blks_hit
2283
+
FROM pg_index
2284
+
WHERE (pg_index.indrelid = c.oid)) i ON (true))
2285
+
LEFT JOIN LATERAL ( SELECT (sum((pg_stat_get_blocks_fetched(pg_index.indexrelid) - pg_stat_get_blocks_hit(pg_index.indexrelid))))::bigint AS idx_blks_read,
2286
+
(sum(pg_stat_get_blocks_hit(pg_index.indexrelid)))::bigint AS idx_blks_hit
2287
+
FROM pg_index
2288
+
WHERE (pg_index.indrelid = t.oid)) x ON (true))
2289
+
WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]));
0 commit comments