mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-28 09:46:44 +08:00
Since the parent table of a hypertable cannot contain any rows including it in the plan is not necessary. PostgreSQL might also not have good statistics for the main table as autoanalyze is triggered by inserts which never happen to the main table, leading to worse plans. This patch adds a new guc enable_constraint_exclusion to disable planner constraint exclusion. Constraint exclusion will not work with cursors and WHERE CURRENT OF so the new guc will allow you to disable that feature. This patch also fixes constraint exclusion for JOINs and sort optimization for queries with chunks_in.
50 lines
1.9 KiB
SQL
50 lines
1.9 KiB
SQL
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
|
|
SELECT * FROM timescaledb_information.hypertable;
|
|
|
|
-- create simple hypertable with 1 chunk
|
|
CREATE TABLE ht1(time TIMESTAMPTZ NOT NULL);
|
|
SELECT create_hypertable('ht1','time');
|
|
INSERT INTO ht1 SELECT '2000-01-01'::TIMESTAMPTZ;
|
|
|
|
-- create simple hypertable with 1 chunk and toasted data
|
|
CREATE TABLE ht2(time TIMESTAMPTZ NOT NULL, data TEXT);
|
|
SELECT create_hypertable('ht2','time');
|
|
INSERT INTO ht2 SELECT '2000-01-01'::TIMESTAMPTZ, repeat('8k',4096);
|
|
|
|
SELECT * FROM timescaledb_information.hypertable;
|
|
|
|
\c :TEST_DBNAME :ROLE_SUPERUSER
|
|
|
|
-- create schema open and hypertable with 3 chunks
|
|
CREATE SCHEMA open;
|
|
GRANT USAGE ON SCHEMA open TO :ROLE_DEFAULT_PERM_USER;
|
|
CREATE TABLE open.open_ht(time TIMESTAMPTZ NOT NULL);
|
|
SELECT create_hypertable('open.open_ht','time');
|
|
INSERT INTO open.open_ht SELECT '2000-01-01'::TIMESTAMPTZ;
|
|
INSERT INTO open.open_ht SELECT '2001-01-01'::TIMESTAMPTZ;
|
|
INSERT INTO open.open_ht SELECT '2002-01-01'::TIMESTAMPTZ;
|
|
|
|
-- create schema closed and hypertable
|
|
CREATE SCHEMA closed;
|
|
CREATE TABLE closed.closed_ht(time TIMESTAMPTZ NOT NULL);
|
|
SELECT create_hypertable('closed.closed_ht','time');
|
|
INSERT INTO closed.closed_ht SELECT '2000-01-01'::TIMESTAMPTZ;
|
|
|
|
SELECT * FROM timescaledb_information.hypertable ORDER BY table_schema, table_name;
|
|
|
|
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
|
|
SELECT * FROM timescaledb_information.hypertable ORDER BY table_schema,table_name;
|
|
|
|
-- filter by schema
|
|
SELECT * FROM timescaledb_information.hypertable WHERE table_schema = 'closed' ORDER BY table_schema, table_name;
|
|
|
|
-- filter by table name
|
|
SELECT * FROM timescaledb_information.hypertable WHERE table_name = 'ht1' ORDER BY table_schema, table_name;
|
|
|
|
-- filter by owner
|
|
SELECT * FROM timescaledb_information.hypertable WHERE table_owner = 'super_user' ORDER BY table_schema,table_name;
|
|
|