mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 11:03:36 +08:00
Function approximate_row_count returns 0 for caggs (#6053)
The approximate_row_count function is executed directly on the user view instead of corresponding materialized hypertable which returns 0 for caggs. The function is updated to fetch the details for materialized hypertable information corresponding to cagg and then get the approximate_row_count for the materialized hypertable. Fixes #6051
This commit is contained in:
parent
ef783c4b55
commit
93519d0af8
1
.unreleased/bugfix_6053
Normal file
1
.unreleased/bugfix_6053
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fixes: #6053 Function approximate_row_count returns 0 for caggs
|
@ -415,6 +415,7 @@ RETURNS BIGINT
|
|||||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||||
$BODY$
|
$BODY$
|
||||||
DECLARE
|
DECLARE
|
||||||
|
mat_ht REGCLASS = NULL;
|
||||||
local_table_name NAME = NULL;
|
local_table_name NAME = NULL;
|
||||||
local_schema_name NAME = NULL;
|
local_schema_name NAME = NULL;
|
||||||
is_distributed BOOL = FALSE;
|
is_distributed BOOL = FALSE;
|
||||||
@ -428,6 +429,20 @@ DECLARE
|
|||||||
max_compressed_row_count BIGINT = 1000;
|
max_compressed_row_count BIGINT = 1000;
|
||||||
is_compressed_chunk INTEGER;
|
is_compressed_chunk INTEGER;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
-- Check if input relation is continuous aggregate view then
|
||||||
|
-- get the corresponding materialized hypertable and schema name
|
||||||
|
SELECT format('%I.%I', ht.schema_name, ht.table_name)::regclass
|
||||||
|
INTO mat_ht
|
||||||
|
FROM pg_class c
|
||||||
|
JOIN pg_namespace n ON (n.OID = c.relnamespace)
|
||||||
|
JOIN _timescaledb_catalog.continuous_agg a ON (a.user_view_schema = n.nspname AND a.user_view_name = c.relname)
|
||||||
|
JOIN _timescaledb_catalog.hypertable ht ON (a.mat_hypertable_id = ht.id)
|
||||||
|
WHERE c.OID = relation;
|
||||||
|
|
||||||
|
IF mat_ht IS NOT NULL THEN
|
||||||
|
relation = mat_ht;
|
||||||
|
END IF;
|
||||||
|
|
||||||
SELECT relname, nspname FROM pg_class c
|
SELECT relname, nspname FROM pg_class c
|
||||||
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
|
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
|
||||||
INTO local_table_name, local_schema_name
|
INTO local_table_name, local_schema_name
|
||||||
|
@ -52,6 +52,12 @@ SELECT * FROM chunks_detailed_size('hypersize_cagg') ORDER BY node_name;
|
|||||||
--------------+------------+-------------+-------------+-------------+-------------+-----------
|
--------------+------------+-------------+-------------+-------------+-------------+-----------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
|
SELECT * FROM approximate_row_count('hypersize_cagg');
|
||||||
|
approximate_row_count
|
||||||
|
-----------------------
|
||||||
|
0
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- Test size functions on non-empty countinuous aggregate
|
-- Test size functions on non-empty countinuous aggregate
|
||||||
CALL refresh_continuous_aggregate('hypersize_cagg', NULL, NULL);
|
CALL refresh_continuous_aggregate('hypersize_cagg', NULL, NULL);
|
||||||
SELECT * FROM hypertable_size('hypersize_cagg');
|
SELECT * FROM hypertable_size('hypersize_cagg');
|
||||||
@ -90,3 +96,10 @@ SELECT * FROM chunks_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
|
|||||||
_timescaledb_internal | _hyper_2_2_chunk | 8192 | 16384 | 8192 | 32768 |
|
_timescaledb_internal | _hyper_2_2_chunk | 8192 | 16384 | 8192 | 32768 |
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
ANALYZE :MAT_HYPERTABLE_NAME;
|
||||||
|
SELECT * FROM approximate_row_count('hypersize_cagg');
|
||||||
|
approximate_row_count
|
||||||
|
-----------------------
|
||||||
|
1
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ SELECT * FROM chunks_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
|
|||||||
SELECT * FROM hypertable_size('hypersize_cagg');
|
SELECT * FROM hypertable_size('hypersize_cagg');
|
||||||
SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name;
|
SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name;
|
||||||
SELECT * FROM chunks_detailed_size('hypersize_cagg') ORDER BY node_name;
|
SELECT * FROM chunks_detailed_size('hypersize_cagg') ORDER BY node_name;
|
||||||
|
SELECT * FROM approximate_row_count('hypersize_cagg');
|
||||||
|
|
||||||
-- Test size functions on non-empty countinuous aggregate
|
-- Test size functions on non-empty countinuous aggregate
|
||||||
CALL refresh_continuous_aggregate('hypersize_cagg', NULL, NULL);
|
CALL refresh_continuous_aggregate('hypersize_cagg', NULL, NULL);
|
||||||
@ -30,3 +31,5 @@ SELECT * FROM chunks_detailed_size('hypersize_cagg') ORDER BY node_name;
|
|||||||
SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME');
|
SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME');
|
||||||
SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
|
SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
|
||||||
SELECT * FROM chunks_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
|
SELECT * FROM chunks_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
|
||||||
|
ANALYZE :MAT_HYPERTABLE_NAME;
|
||||||
|
SELECT * FROM approximate_row_count('hypersize_cagg');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user