SELECT reltuples FROM pg_class WHERE relname = "table"
SELECT reltuples FROM pg_class WHERE relname = "table"
SELECT h.schema_name, h.table_name, h.id AS table_id, h.associated_table_prefix, row_estimate.row_estimate 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;
CREATE FUNCTION row_estimator(query text) RETURNS bigint LANGUAGE plpgsql AS $$DECLARE plan jsonb; BEGIN EXECUTE 'EXPLAIN (FORMAT JSON) ' || query INTO plan; RETURN (plan->0->'Plan'->>'Plan Rows')::bigint; END;$$;