Skip to content

Commit

Permalink
Rename {enable|disable}_column_stats API
Browse files Browse the repository at this point in the history
For better understanding we've decided to rename the public API from
`{enable|disable}_column_stats` to `{enable|disable}_chunk_skipping`.
  • Loading branch information
fabriziomello committed Jul 26, 2024
1 parent 554957c commit a4a023e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 94 deletions.
4 changes: 2 additions & 2 deletions sql/ddl_api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ AS '@MODULE_PATHNAME@', 'ts_dimension_add_general' LANGUAGE C VOLATILE;
-- if_not_exists - If set, and the entry already exists, generate a notice instead of an error
-- Returns the "id" of the entry created. The "enabled" field
-- is set to true if entry is created or exists already.
CREATE OR REPLACE FUNCTION @extschema@.enable_column_stats(
CREATE OR REPLACE FUNCTION @extschema@.enable_chunk_skipping(
hypertable REGCLASS,
column_name NAME,
if_not_exists BOOLEAN = FALSE
Expand All @@ -170,7 +170,7 @@ AS '@MODULE_PATHNAME@', 'ts_chunk_column_stats_enable' LANGUAGE C VOLATILE;
-- if_not_exists - If set, and the entry does not exist,
-- generate a notice instead of an error. The "disabled" field
-- is set to true if entry is deleted successfully.
CREATE OR REPLACE FUNCTION @extschema@.disable_column_stats(
CREATE OR REPLACE FUNCTION @extschema@.disable_chunk_skipping(
hypertable REGCLASS,
column_name NAME,
if_not_exists BOOLEAN = FALSE
Expand Down
4 changes: 2 additions & 2 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- hypertable - OID of the table to which the column belongs to
-- column_name - The column to track statistics for
-- if_not_exists - If set, and the entry already exists, generate a notice instead of an error
CREATE FUNCTION @extschema@.enable_column_stats(
CREATE FUNCTION @extschema@.enable_chunk_skipping(
hypertable REGCLASS,
column_name NAME,
if_not_exists BOOLEAN = FALSE
Expand All @@ -16,7 +16,7 @@ AS 'SELECT NULL,NULL' LANGUAGE SQL VOLATILE SET search_path = pg_catalog, pg_tem
-- column_name - NAME of the column on which the stats are tracked
-- if_not_exists - If set, and the entry does not exist,
-- generate a notice instead of an error
CREATE FUNCTION @extschema@.disable_column_stats(
CREATE FUNCTION @extschema@.disable_chunk_skipping(
hypertable REGCLASS,
column_name NAME,
if_not_exists BOOLEAN = FALSE
Expand Down
4 changes: 2 additions & 2 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_get_bucket_function_info(INTEGER);
-- remove chunk column statistics related objects
DROP FUNCTION IF EXISTS @extschema@.enable_column_stats(REGCLASS, NAME, BOOLEAN);
DROP FUNCTION IF EXISTS @extschema@.disable_column_stats(REGCLASS, NAME, BOOLEAN);
DROP FUNCTION IF EXISTS @extschema@.enable_chunk_skipping(REGCLASS, NAME, BOOLEAN);
DROP FUNCTION IF EXISTS @extschema@.disable_chunk_skipping(REGCLASS, NAME, BOOLEAN);
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.chunk_column_stats;
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.chunk_column_stats_id_seq;
DROP TABLE IF EXISTS _timescaledb_catalog.chunk_column_stats;
Expand Down
44 changes: 22 additions & 22 deletions tsl/test/expected/chunk_column_stats-14.out
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ INSERT INTO sample_table VALUES (:'start_date'::timestamptz, 16, 14.6554, 47, 'n
-- Non-int, date, timestamp cannot be specified as a min/max ranges for now
-- We could expand to FLOATs, NUMERICs later
\set ON_ERROR_STOP 0
SELECT * FROM enable_column_stats('sample_table', 'name');
SELECT * FROM enable_chunk_skipping('sample_table', 'name');
ERROR: data type "character varying" unsupported for range calculation
SELECT * FROM enable_column_stats('sample_table', NULL);
SELECT * FROM enable_chunk_skipping('sample_table', NULL);
ERROR: column name cannot be NULL
SELECT * FROM enable_column_stats(NULL, 'name');
SELECT * FROM enable_chunk_skipping(NULL, 'name');
ERROR: hypertable cannot be NULL
SELECT * FROM enable_column_stats('sample_table1', 'name');
ERROR: relation "sample_table1" does not exist at character 35
SELECT * FROM enable_chunk_skipping('sample_table1', 'name');
ERROR: relation "sample_table1" does not exist at character 37
CREATE TABLE plain_table(like sample_table);
SELECT * FROM enable_column_stats('plain_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('plain_table', 'sensor_id');
ERROR: table "plain_table" is not a hypertable
DROP TABLE plain_table;
\set ON_ERROR_STOP 1
-- Specify tracking of min/max ranges for a column
SELECT * FROM enable_column_stats('sample_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id');
column_stats_id | enabled
-----------------+---------
1 | t
Expand All @@ -82,7 +82,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
(3 rows)

-- Skipping should work
SELECT * FROM enable_column_stats('sample_table', 'sensor_id', true);
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id', true);
NOTICE: already enabled for column "sensor_id", skipping
column_stats_id | enabled
-----------------+---------
Expand Down Expand Up @@ -334,8 +334,8 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;

-- Check that a RENAME COLUMN works ok
ALTER TABLE sample_table RENAME COLUMN sensor_id TO sense_id;
-- use the disable_column_stats API to remove the min/max range entries
SELECT * from disable_column_stats('sample_table', 'sense_id');
-- use the disable_chunk_skipping API to remove the min/max range entries
SELECT * from disable_chunk_skipping('sample_table', 'sense_id');
hypertable_id | column_name | disabled
---------------+-------------+----------
1 | sense_id | t
Expand All @@ -346,7 +346,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
----+---------------+----------+-------------+-------------+-----------+-------
(0 rows)

SELECT * from disable_column_stats('sample_table', 'sense_id', true);
SELECT * from disable_chunk_skipping('sample_table', 'sense_id', true);
NOTICE: statistics not enabled for column "sense_id", skipping
hypertable_id | column_name | disabled
---------------+-------------+----------
Expand All @@ -355,21 +355,21 @@ NOTICE: statistics not enabled for column "sense_id", skipping

ALTER TABLE sample_table RENAME COLUMN sense_id TO sensor_id;
\set ON_ERROR_STOP 0
SELECT * from disable_column_stats('sample_table', 'sensor_id');
SELECT * from disable_chunk_skipping('sample_table', 'sensor_id');
ERROR: statistics not enabled for column "sensor_id"
SELECT * from disable_column_stats('sample_table', NULL);
SELECT * from disable_chunk_skipping('sample_table', NULL);
ERROR: column name cannot be NULL
SELECT * from disable_column_stats(NULL, 'sensor_id');
SELECT * from disable_chunk_skipping(NULL, 'sensor_id');
ERROR: hypertable cannot be NULL
SELECT * from disable_column_stats('sample_table1', 'sensor_id');
ERROR: relation "sample_table1" does not exist at character 36
SELECT * from disable_chunk_skipping('sample_table1', 'sensor_id');
ERROR: relation "sample_table1" does not exist at character 38
-- should only work on columns that have been enabled for tracking
SELECT * from disable_column_stats('sample_table', 'time');
SELECT * from disable_chunk_skipping('sample_table', 'time');
ERROR: statistics not enabled for column "time"
SELECT * from disable_column_stats('sample_table', 'cpu');
SELECT * from disable_chunk_skipping('sample_table', 'cpu');
ERROR: statistics not enabled for column "cpu"
\set ON_ERROR_STOP 1
SELECT * FROM enable_column_stats('sample_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id');
column_stats_id | enabled
-----------------+---------
5 | t
Expand Down Expand Up @@ -485,7 +485,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
----+---------------+----------+-------------+-------------+-----------+-------
(0 rows)

-- Check that empty hypertables can have enable_column_stats and
-- Check that empty hypertables can have enable_chunk_skipping and
-- that new chunks get entries in the catalog as they get added
CREATE TABLE sample_table1 (
time TIMESTAMP WITH TIME ZONE NOT NULL,
Expand All @@ -503,7 +503,7 @@ WARNING: column type "character varying" used for "name" does not follow best p
3 | public | sample_table1 | t
(1 row)

SELECT * FROM enable_column_stats('sample_table1', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table1', 'sensor_id');
column_stats_id | enabled
-----------------+---------
9 | t
Expand Down Expand Up @@ -534,7 +534,7 @@ ERROR: column "sensor_id" cannot be cast automatically to type timestamp with t
ALTER TABLE sample_table1 ALTER COLUMN sensor_id TYPE TEXT;
ERROR: data type "text" unsupported for statistics calculation
\set ON_ERROR_STOP 1
SELECT * FROM disable_column_stats('sample_table1', 'sensor_id');
SELECT * FROM disable_chunk_skipping('sample_table1', 'sensor_id');
hypertable_id | column_name | disabled
---------------+-------------+----------
3 | sensor_id | t
Expand Down
44 changes: 22 additions & 22 deletions tsl/test/expected/chunk_column_stats-15.out
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ INSERT INTO sample_table VALUES (:'start_date'::timestamptz, 16, 14.6554, 47, 'n
-- Non-int, date, timestamp cannot be specified as a min/max ranges for now
-- We could expand to FLOATs, NUMERICs later
\set ON_ERROR_STOP 0
SELECT * FROM enable_column_stats('sample_table', 'name');
SELECT * FROM enable_chunk_skipping('sample_table', 'name');
ERROR: data type "character varying" unsupported for range calculation
SELECT * FROM enable_column_stats('sample_table', NULL);
SELECT * FROM enable_chunk_skipping('sample_table', NULL);
ERROR: column name cannot be NULL
SELECT * FROM enable_column_stats(NULL, 'name');
SELECT * FROM enable_chunk_skipping(NULL, 'name');
ERROR: hypertable cannot be NULL
SELECT * FROM enable_column_stats('sample_table1', 'name');
ERROR: relation "sample_table1" does not exist at character 35
SELECT * FROM enable_chunk_skipping('sample_table1', 'name');
ERROR: relation "sample_table1" does not exist at character 37
CREATE TABLE plain_table(like sample_table);
SELECT * FROM enable_column_stats('plain_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('plain_table', 'sensor_id');
ERROR: table "plain_table" is not a hypertable
DROP TABLE plain_table;
\set ON_ERROR_STOP 1
-- Specify tracking of min/max ranges for a column
SELECT * FROM enable_column_stats('sample_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id');
column_stats_id | enabled
-----------------+---------
1 | t
Expand All @@ -82,7 +82,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
(3 rows)

-- Skipping should work
SELECT * FROM enable_column_stats('sample_table', 'sensor_id', true);
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id', true);
NOTICE: already enabled for column "sensor_id", skipping
column_stats_id | enabled
-----------------+---------
Expand Down Expand Up @@ -335,8 +335,8 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;

-- Check that a RENAME COLUMN works ok
ALTER TABLE sample_table RENAME COLUMN sensor_id TO sense_id;
-- use the disable_column_stats API to remove the min/max range entries
SELECT * from disable_column_stats('sample_table', 'sense_id');
-- use the disable_chunk_skipping API to remove the min/max range entries
SELECT * from disable_chunk_skipping('sample_table', 'sense_id');
hypertable_id | column_name | disabled
---------------+-------------+----------
1 | sense_id | t
Expand All @@ -347,7 +347,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
----+---------------+----------+-------------+-------------+-----------+-------
(0 rows)

SELECT * from disable_column_stats('sample_table', 'sense_id', true);
SELECT * from disable_chunk_skipping('sample_table', 'sense_id', true);
NOTICE: statistics not enabled for column "sense_id", skipping
hypertable_id | column_name | disabled
---------------+-------------+----------
Expand All @@ -356,21 +356,21 @@ NOTICE: statistics not enabled for column "sense_id", skipping

ALTER TABLE sample_table RENAME COLUMN sense_id TO sensor_id;
\set ON_ERROR_STOP 0
SELECT * from disable_column_stats('sample_table', 'sensor_id');
SELECT * from disable_chunk_skipping('sample_table', 'sensor_id');
ERROR: statistics not enabled for column "sensor_id"
SELECT * from disable_column_stats('sample_table', NULL);
SELECT * from disable_chunk_skipping('sample_table', NULL);
ERROR: column name cannot be NULL
SELECT * from disable_column_stats(NULL, 'sensor_id');
SELECT * from disable_chunk_skipping(NULL, 'sensor_id');
ERROR: hypertable cannot be NULL
SELECT * from disable_column_stats('sample_table1', 'sensor_id');
ERROR: relation "sample_table1" does not exist at character 36
SELECT * from disable_chunk_skipping('sample_table1', 'sensor_id');
ERROR: relation "sample_table1" does not exist at character 38
-- should only work on columns that have been enabled for tracking
SELECT * from disable_column_stats('sample_table', 'time');
SELECT * from disable_chunk_skipping('sample_table', 'time');
ERROR: statistics not enabled for column "time"
SELECT * from disable_column_stats('sample_table', 'cpu');
SELECT * from disable_chunk_skipping('sample_table', 'cpu');
ERROR: statistics not enabled for column "cpu"
\set ON_ERROR_STOP 1
SELECT * FROM enable_column_stats('sample_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id');
column_stats_id | enabled
-----------------+---------
5 | t
Expand Down Expand Up @@ -486,7 +486,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
----+---------------+----------+-------------+-------------+-----------+-------
(0 rows)

-- Check that empty hypertables can have enable_column_stats and
-- Check that empty hypertables can have enable_chunk_skipping and
-- that new chunks get entries in the catalog as they get added
CREATE TABLE sample_table1 (
time TIMESTAMP WITH TIME ZONE NOT NULL,
Expand All @@ -504,7 +504,7 @@ WARNING: column type "character varying" used for "name" does not follow best p
3 | public | sample_table1 | t
(1 row)

SELECT * FROM enable_column_stats('sample_table1', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table1', 'sensor_id');
column_stats_id | enabled
-----------------+---------
9 | t
Expand Down Expand Up @@ -535,7 +535,7 @@ ERROR: column "sensor_id" cannot be cast automatically to type timestamp with t
ALTER TABLE sample_table1 ALTER COLUMN sensor_id TYPE TEXT;
ERROR: data type "text" unsupported for statistics calculation
\set ON_ERROR_STOP 1
SELECT * FROM disable_column_stats('sample_table1', 'sensor_id');
SELECT * FROM disable_chunk_skipping('sample_table1', 'sensor_id');
hypertable_id | column_name | disabled
---------------+-------------+----------
3 | sensor_id | t
Expand Down
44 changes: 22 additions & 22 deletions tsl/test/expected/chunk_column_stats-16.out
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ INSERT INTO sample_table VALUES (:'start_date'::timestamptz, 16, 14.6554, 47, 'n
-- Non-int, date, timestamp cannot be specified as a min/max ranges for now
-- We could expand to FLOATs, NUMERICs later
\set ON_ERROR_STOP 0
SELECT * FROM enable_column_stats('sample_table', 'name');
SELECT * FROM enable_chunk_skipping('sample_table', 'name');
ERROR: data type "character varying" unsupported for range calculation
SELECT * FROM enable_column_stats('sample_table', NULL);
SELECT * FROM enable_chunk_skipping('sample_table', NULL);
ERROR: column name cannot be NULL
SELECT * FROM enable_column_stats(NULL, 'name');
SELECT * FROM enable_chunk_skipping(NULL, 'name');
ERROR: hypertable cannot be NULL
SELECT * FROM enable_column_stats('sample_table1', 'name');
ERROR: relation "sample_table1" does not exist at character 35
SELECT * FROM enable_chunk_skipping('sample_table1', 'name');
ERROR: relation "sample_table1" does not exist at character 37
CREATE TABLE plain_table(like sample_table);
SELECT * FROM enable_column_stats('plain_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('plain_table', 'sensor_id');
ERROR: table "plain_table" is not a hypertable
DROP TABLE plain_table;
\set ON_ERROR_STOP 1
-- Specify tracking of min/max ranges for a column
SELECT * FROM enable_column_stats('sample_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id');
column_stats_id | enabled
-----------------+---------
1 | t
Expand All @@ -82,7 +82,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
(3 rows)

-- Skipping should work
SELECT * FROM enable_column_stats('sample_table', 'sensor_id', true);
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id', true);
NOTICE: already enabled for column "sensor_id", skipping
column_stats_id | enabled
-----------------+---------
Expand Down Expand Up @@ -335,8 +335,8 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;

-- Check that a RENAME COLUMN works ok
ALTER TABLE sample_table RENAME COLUMN sensor_id TO sense_id;
-- use the disable_column_stats API to remove the min/max range entries
SELECT * from disable_column_stats('sample_table', 'sense_id');
-- use the disable_chunk_skipping API to remove the min/max range entries
SELECT * from disable_chunk_skipping('sample_table', 'sense_id');
hypertable_id | column_name | disabled
---------------+-------------+----------
1 | sense_id | t
Expand All @@ -347,7 +347,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
----+---------------+----------+-------------+-------------+-----------+-------
(0 rows)

SELECT * from disable_column_stats('sample_table', 'sense_id', true);
SELECT * from disable_chunk_skipping('sample_table', 'sense_id', true);
NOTICE: statistics not enabled for column "sense_id", skipping
hypertable_id | column_name | disabled
---------------+-------------+----------
Expand All @@ -356,21 +356,21 @@ NOTICE: statistics not enabled for column "sense_id", skipping

ALTER TABLE sample_table RENAME COLUMN sense_id TO sensor_id;
\set ON_ERROR_STOP 0
SELECT * from disable_column_stats('sample_table', 'sensor_id');
SELECT * from disable_chunk_skipping('sample_table', 'sensor_id');
ERROR: statistics not enabled for column "sensor_id"
SELECT * from disable_column_stats('sample_table', NULL);
SELECT * from disable_chunk_skipping('sample_table', NULL);
ERROR: column name cannot be NULL
SELECT * from disable_column_stats(NULL, 'sensor_id');
SELECT * from disable_chunk_skipping(NULL, 'sensor_id');
ERROR: hypertable cannot be NULL
SELECT * from disable_column_stats('sample_table1', 'sensor_id');
ERROR: relation "sample_table1" does not exist at character 36
SELECT * from disable_chunk_skipping('sample_table1', 'sensor_id');
ERROR: relation "sample_table1" does not exist at character 38
-- should only work on columns that have been enabled for tracking
SELECT * from disable_column_stats('sample_table', 'time');
SELECT * from disable_chunk_skipping('sample_table', 'time');
ERROR: statistics not enabled for column "time"
SELECT * from disable_column_stats('sample_table', 'cpu');
SELECT * from disable_chunk_skipping('sample_table', 'cpu');
ERROR: statistics not enabled for column "cpu"
\set ON_ERROR_STOP 1
SELECT * FROM enable_column_stats('sample_table', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table', 'sensor_id');
column_stats_id | enabled
-----------------+---------
5 | t
Expand Down Expand Up @@ -486,7 +486,7 @@ SELECT * from _timescaledb_catalog.chunk_column_stats;
----+---------------+----------+-------------+-------------+-----------+-------
(0 rows)

-- Check that empty hypertables can have enable_column_stats and
-- Check that empty hypertables can have enable_chunk_skipping and
-- that new chunks get entries in the catalog as they get added
CREATE TABLE sample_table1 (
time TIMESTAMP WITH TIME ZONE NOT NULL,
Expand All @@ -504,7 +504,7 @@ WARNING: column type "character varying" used for "name" does not follow best p
3 | public | sample_table1 | t
(1 row)

SELECT * FROM enable_column_stats('sample_table1', 'sensor_id');
SELECT * FROM enable_chunk_skipping('sample_table1', 'sensor_id');
column_stats_id | enabled
-----------------+---------
9 | t
Expand Down Expand Up @@ -535,7 +535,7 @@ ERROR: column "sensor_id" cannot be cast automatically to type timestamp with t
ALTER TABLE sample_table1 ALTER COLUMN sensor_id TYPE TEXT;
ERROR: data type "text" unsupported for statistics calculation
\set ON_ERROR_STOP 1
SELECT * FROM disable_column_stats('sample_table1', 'sensor_id');
SELECT * FROM disable_chunk_skipping('sample_table1', 'sensor_id');
hypertable_id | column_name | disabled
---------------+-------------+----------
3 | sensor_id | t
Expand Down
Loading

0 comments on commit a4a023e

Please sign in to comment.