Last active
October 27, 2020 22:49
-
-
Save edvardm/75a4d05988d5f431cf0bb17f4bf035fc to your computer and use it in GitHub Desktop.
timescaledb, estimated row count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT h.schema_name, | |
h.table_name, | |
h.id AS table_id, | |
h.associated_table_prefix, | |
((round(row_estimate.row_estimate::numeric / 1000000, 3))::text || 'M') as estimated_rows | |
FROM _timescaledb_catalog.hypertable h | |
CROSS JOIN LATERAL ( SELECT sum(cl.reltuples) AS row_estimate | |
FROM _timescaledb_catalog.chunk c | |
JOIN pg_class cl ON cl.relname = c.table_name | |
WHERE c.hypertable_id = h.id | |
GROUP BY h.schema_name, h.table_name) row_estimate | |
ORDER BY schema_name, table_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment