From 72c7a6aebc05e4c0228409db807c54396d90cccb Mon Sep 17 00:00:00 2001 From: lhy Date: Thu, 28 Nov 2024 21:47:02 -0500 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/timescaledb/Makefile | 101 + contrib/timescaledb/data/empty | 0 .../AddPartitionFailOnEmptyChunkedTable.out | 34 + .../regress/expected/BigIntBoundaryTest.out | 95 + .../regress/expected/ChunkParallelism.out | 46 + .../regress/expected/ChunkRename.out | 58 + .../expected/ChunkSchemaRenameSuccess.out | 52 + .../regress/expected/ChunkSchemaSetup.out | 44 + .../expected/ChunkTablespaceUpdate.out | 50 + .../regress/expected/ColumnCleanup.out | 137 + .../regress/expected/ColumnRenameError.out | 34 + .../regress/expected/ColumnSyncFix.out | 63 + .../CreateHypertableDuplicateError.out | 44 + .../expected/CustomPartitionFunctionTest.out | 99 + .../expected/CustomTypeTableToHypertable.out | 25 + .../expected/DefaultTablespaceValidation.out | 126 + .../expected/EmptyTableMigrateSuccess.out | 16 + .../expected/HypertableChunksDataCorrect.out | 57 + .../expected/HypertableCreateNoPerm.out | 13 + .../HypertableCreationInfoSuccess.out | 24 + .../expected/HypertableCustomTypeRelation.out | 38 + .../expected/HypertableSchemaRename.out | 24 + .../HypertableTablespaceNoAccumulation.out | 90 + .../expected/HypertableTriggerExists.out | 35 + .../IndexTablespaceUpdateValidation.out | 74 + .../InvalidFunctionAddPartitionFail.out | 59 + .../InvalidFunctionHypertableCreationFail.out | 38 + .../InvalidPartitionFunctionFailure.out | 77 + .../MultipleHypertablesRenameSuccess.out | 48 + .../expected/PartitionCountChangeError.out | 44 + .../expected/PartitionCountChangeSuccess.out | 52 + .../expected/PartitionDimensionAddSuccess.out | 31 + .../PluginSchemaRenameErrorHandling.out | 15 + .../expected/RoleInheritanceInsertTest.out | 28 + .../expected/RoleSchemaHypertableFail.out | 15 + .../RoleSchemaPermHypertableSuccess.out | 19 + .../SchemaDeletionCascadeHypertables.out | 44 + .../expected/SchemaPermRoleHypertableFail.out | 17 + .../expected/SetIntegerNowFuncTest.out | 94 + .../regress/expected/ShowBlocksInSchema.out | 26 + .../expected/TableDataMigrateSuccess.out | 27 + .../expected/TableDataNoMigrateError.out | 27 + .../expected/TablespaceFunctionHandling.out | 118 + .../expected/TablespaceToHypertable.out | 63 + .../expected/TestAddMultipleDimensions.out | 37 + .../expected/TestTimeDimensionPartition.out | 33 + .../ValidFunctionAddPartitionSuccess.out | 34 + ...ValidFunctionHypertableCreationSuccess.out | 27 + .../expected/ValidateAddBigIntDimension.out | 39 + .../ValidateAddDimensionExplicitType.out | 21 + .../ValidateAddDimensionIfNotExists.out | 29 + .../ValidateAddDimensionWithInterval.out | 25 + ...alidateConflictingPartitionParamsError.out | 20 + .../expected/ValidateCreateCommand.out | 45 + .../ValidateDataExistsDimensionError.out | 46 + .../ValidateDuplicateDimensionError.out | 26 + .../expected/ValidateMissingFieldError.out | 20 + .../ValidatePartitionDimensionAddFail.out | 15 + .../ValidateRegularTableHypertableError.out | 28 + contrib/timescaledb/regress/expected/lhy1.out | 2 + contrib/timescaledb/regress/smartmatch.pl | 583 ++++ .../AddPartitionFailOnEmptyChunkedTable.sql | 17 + .../regress/sql/BigIntBoundaryTest.sql | 91 + .../regress/sql/ChunkParallelism.sql | 19 + .../timescaledb/regress/sql/ChunkRename.sql | 24 + .../regress/sql/ChunkSchemaRenameSuccess.sql | 29 + .../regress/sql/ChunkSchemaSetup.sql | 19 + .../regress/sql/ChunkTablespaceUpdate.sql | 27 + .../timescaledb/regress/sql/ColumnCleanup.sql | 64 + .../regress/sql/ColumnRenameError.sql | 16 + .../timescaledb/regress/sql/ColumnSyncFix.sql | 30 + .../sql/CreateHypertableDuplicateError.sql | 19 + .../sql/CustomPartitionFunctionTest.sql | 56 + .../sql/CustomTypeTableToHypertable.sql | 16 + .../sql/DefaultTablespaceValidation.sql | 76 + .../regress/sql/EmptyTableMigrateSuccess.sql | 10 + .../sql/HypertableChunksDataCorrect.sql | 26 + .../regress/sql/HypertableCreateNoPerm.sql | 12 + .../sql/HypertableCreationInfoSuccess.sql | 23 + .../sql/HypertableCustomTypeRelation.sql | 26 + .../regress/sql/HypertableSchemaRename.sql | 21 + .../HypertableTablespaceNoAccumulation.sql | 48 + .../regress/sql/HypertableTriggerExists.sql | 29 + .../sql/IndexTablespaceUpdateValidation.sql | 52 + .../sql/InvalidFunctionAddPartitionFail.sql | 34 + .../InvalidFunctionHypertableCreationFail.sql | 23 + .../sql/InvalidPartitionFunctionFailure.sql | 47 + .../sql/MultipleHypertablesRenameSuccess.sql | 35 + .../regress/sql/PartitionCountChangeError.sql | 24 + .../sql/PartitionCountChangeSuccess.sql | 29 + .../sql/PartitionDimensionAddSuccess.sql | 20 + .../sql/PluginSchemaRenameErrorHandling.sql | 11 + .../regress/sql/RoleInheritanceInsertTest.sql | 25 + .../regress/sql/RoleSchemaHypertableFail.sql | 15 + .../sql/RoleSchemaPermHypertableSuccess.sql | 19 + .../sql/SchemaDeletionCascadeHypertables.sql | 29 + .../sql/SchemaPermRoleHypertableFail.sql | 16 + .../regress/sql/SetIntegerNowFuncTest.sql | 42 + .../regress/sql/ShowBlocksInSchema.sql | 15 + .../regress/sql/TableDataMigrateSuccess.sql | 14 + .../regress/sql/TableDataNoMigrateError.sql | 14 + .../sql/TablespaceFunctionHandling.sql | 57 + .../regress/sql/TablespaceToHypertable.sql | 32 + .../regress/sql/TestAddMultipleDimensions.sql | 18 + .../sql/TestTimeDimensionPartition.sql | 16 + .../sql/ValidFunctionAddPartitionSuccess.sql | 21 + ...ValidFunctionHypertableCreationSuccess.sql | 19 + .../sql/ValidateAddBigIntDimension.sql | 17 + .../sql/ValidateAddDimensionExplicitType.sql | 11 + .../sql/ValidateAddDimensionIfNotExists.sql | 14 + .../sql/ValidateAddDimensionWithInterval.sql | 12 + ...alidateConflictingPartitionParamsError.sql | 12 + .../regress/sql/ValidateCreateCommand.sql | 29 + .../sql/ValidateDataExistsDimensionError.sql | 20 + .../sql/ValidateDuplicateDimensionError.sql | 13 + .../regress/sql/ValidateMissingFieldError.sql | 12 + .../sql/ValidatePartitionDimensionAddFail.sql | 10 + .../ValidateRegularTableHypertableError.sql | 23 + contrib/timescaledb/regress/sql/lhy1.sql | 2 + contrib/timescaledb/temp-config.conf | 1 + contrib/timescaledb/timescaledb--1.7.4.sql | 2493 +++++++++++++++++ contrib/timescaledb/timescaledb.so | Bin 0 -> 7200 bytes 122 files changed, 7245 insertions(+) create mode 100644 contrib/timescaledb/Makefile create mode 100644 contrib/timescaledb/data/empty create mode 100644 contrib/timescaledb/regress/expected/AddPartitionFailOnEmptyChunkedTable.out create mode 100644 contrib/timescaledb/regress/expected/BigIntBoundaryTest.out create mode 100644 contrib/timescaledb/regress/expected/ChunkParallelism.out create mode 100644 contrib/timescaledb/regress/expected/ChunkRename.out create mode 100644 contrib/timescaledb/regress/expected/ChunkSchemaRenameSuccess.out create mode 100644 contrib/timescaledb/regress/expected/ChunkSchemaSetup.out create mode 100644 contrib/timescaledb/regress/expected/ChunkTablespaceUpdate.out create mode 100644 contrib/timescaledb/regress/expected/ColumnCleanup.out create mode 100644 contrib/timescaledb/regress/expected/ColumnRenameError.out create mode 100644 contrib/timescaledb/regress/expected/ColumnSyncFix.out create mode 100644 contrib/timescaledb/regress/expected/CreateHypertableDuplicateError.out create mode 100644 contrib/timescaledb/regress/expected/CustomPartitionFunctionTest.out create mode 100644 contrib/timescaledb/regress/expected/CustomTypeTableToHypertable.out create mode 100644 contrib/timescaledb/regress/expected/DefaultTablespaceValidation.out create mode 100644 contrib/timescaledb/regress/expected/EmptyTableMigrateSuccess.out create mode 100644 contrib/timescaledb/regress/expected/HypertableChunksDataCorrect.out create mode 100644 contrib/timescaledb/regress/expected/HypertableCreateNoPerm.out create mode 100644 contrib/timescaledb/regress/expected/HypertableCreationInfoSuccess.out create mode 100644 contrib/timescaledb/regress/expected/HypertableCustomTypeRelation.out create mode 100644 contrib/timescaledb/regress/expected/HypertableSchemaRename.out create mode 100644 contrib/timescaledb/regress/expected/HypertableTablespaceNoAccumulation.out create mode 100644 contrib/timescaledb/regress/expected/HypertableTriggerExists.out create mode 100644 contrib/timescaledb/regress/expected/IndexTablespaceUpdateValidation.out create mode 100644 contrib/timescaledb/regress/expected/InvalidFunctionAddPartitionFail.out create mode 100644 contrib/timescaledb/regress/expected/InvalidFunctionHypertableCreationFail.out create mode 100644 contrib/timescaledb/regress/expected/InvalidPartitionFunctionFailure.out create mode 100644 contrib/timescaledb/regress/expected/MultipleHypertablesRenameSuccess.out create mode 100644 contrib/timescaledb/regress/expected/PartitionCountChangeError.out create mode 100644 contrib/timescaledb/regress/expected/PartitionCountChangeSuccess.out create mode 100644 contrib/timescaledb/regress/expected/PartitionDimensionAddSuccess.out create mode 100644 contrib/timescaledb/regress/expected/PluginSchemaRenameErrorHandling.out create mode 100644 contrib/timescaledb/regress/expected/RoleInheritanceInsertTest.out create mode 100644 contrib/timescaledb/regress/expected/RoleSchemaHypertableFail.out create mode 100644 contrib/timescaledb/regress/expected/RoleSchemaPermHypertableSuccess.out create mode 100644 contrib/timescaledb/regress/expected/SchemaDeletionCascadeHypertables.out create mode 100644 contrib/timescaledb/regress/expected/SchemaPermRoleHypertableFail.out create mode 100644 contrib/timescaledb/regress/expected/SetIntegerNowFuncTest.out create mode 100644 contrib/timescaledb/regress/expected/ShowBlocksInSchema.out create mode 100644 contrib/timescaledb/regress/expected/TableDataMigrateSuccess.out create mode 100644 contrib/timescaledb/regress/expected/TableDataNoMigrateError.out create mode 100644 contrib/timescaledb/regress/expected/TablespaceFunctionHandling.out create mode 100644 contrib/timescaledb/regress/expected/TablespaceToHypertable.out create mode 100644 contrib/timescaledb/regress/expected/TestAddMultipleDimensions.out create mode 100644 contrib/timescaledb/regress/expected/TestTimeDimensionPartition.out create mode 100755 contrib/timescaledb/regress/expected/ValidFunctionAddPartitionSuccess.out create mode 100755 contrib/timescaledb/regress/expected/ValidFunctionHypertableCreationSuccess.out create mode 100644 contrib/timescaledb/regress/expected/ValidateAddBigIntDimension.out create mode 100644 contrib/timescaledb/regress/expected/ValidateAddDimensionExplicitType.out create mode 100644 contrib/timescaledb/regress/expected/ValidateAddDimensionIfNotExists.out create mode 100644 contrib/timescaledb/regress/expected/ValidateAddDimensionWithInterval.out create mode 100644 contrib/timescaledb/regress/expected/ValidateConflictingPartitionParamsError.out create mode 100644 contrib/timescaledb/regress/expected/ValidateCreateCommand.out create mode 100644 contrib/timescaledb/regress/expected/ValidateDataExistsDimensionError.out create mode 100644 contrib/timescaledb/regress/expected/ValidateDuplicateDimensionError.out create mode 100644 contrib/timescaledb/regress/expected/ValidateMissingFieldError.out create mode 100644 contrib/timescaledb/regress/expected/ValidatePartitionDimensionAddFail.out create mode 100644 contrib/timescaledb/regress/expected/ValidateRegularTableHypertableError.out create mode 100755 contrib/timescaledb/regress/expected/lhy1.out create mode 100755 contrib/timescaledb/regress/smartmatch.pl create mode 100644 contrib/timescaledb/regress/sql/AddPartitionFailOnEmptyChunkedTable.sql create mode 100644 contrib/timescaledb/regress/sql/BigIntBoundaryTest.sql create mode 100644 contrib/timescaledb/regress/sql/ChunkParallelism.sql create mode 100644 contrib/timescaledb/regress/sql/ChunkRename.sql create mode 100644 contrib/timescaledb/regress/sql/ChunkSchemaRenameSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/ChunkSchemaSetup.sql create mode 100644 contrib/timescaledb/regress/sql/ChunkTablespaceUpdate.sql create mode 100644 contrib/timescaledb/regress/sql/ColumnCleanup.sql create mode 100644 contrib/timescaledb/regress/sql/ColumnRenameError.sql create mode 100644 contrib/timescaledb/regress/sql/ColumnSyncFix.sql create mode 100644 contrib/timescaledb/regress/sql/CreateHypertableDuplicateError.sql create mode 100644 contrib/timescaledb/regress/sql/CustomPartitionFunctionTest.sql create mode 100644 contrib/timescaledb/regress/sql/CustomTypeTableToHypertable.sql create mode 100644 contrib/timescaledb/regress/sql/DefaultTablespaceValidation.sql create mode 100644 contrib/timescaledb/regress/sql/EmptyTableMigrateSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/HypertableChunksDataCorrect.sql create mode 100644 contrib/timescaledb/regress/sql/HypertableCreateNoPerm.sql create mode 100644 contrib/timescaledb/regress/sql/HypertableCreationInfoSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/HypertableCustomTypeRelation.sql create mode 100644 contrib/timescaledb/regress/sql/HypertableSchemaRename.sql create mode 100644 contrib/timescaledb/regress/sql/HypertableTablespaceNoAccumulation.sql create mode 100644 contrib/timescaledb/regress/sql/HypertableTriggerExists.sql create mode 100644 contrib/timescaledb/regress/sql/IndexTablespaceUpdateValidation.sql create mode 100644 contrib/timescaledb/regress/sql/InvalidFunctionAddPartitionFail.sql create mode 100644 contrib/timescaledb/regress/sql/InvalidFunctionHypertableCreationFail.sql create mode 100644 contrib/timescaledb/regress/sql/InvalidPartitionFunctionFailure.sql create mode 100644 contrib/timescaledb/regress/sql/MultipleHypertablesRenameSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/PartitionCountChangeError.sql create mode 100644 contrib/timescaledb/regress/sql/PartitionCountChangeSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/PartitionDimensionAddSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/PluginSchemaRenameErrorHandling.sql create mode 100644 contrib/timescaledb/regress/sql/RoleInheritanceInsertTest.sql create mode 100644 contrib/timescaledb/regress/sql/RoleSchemaHypertableFail.sql create mode 100644 contrib/timescaledb/regress/sql/RoleSchemaPermHypertableSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/SchemaDeletionCascadeHypertables.sql create mode 100644 contrib/timescaledb/regress/sql/SchemaPermRoleHypertableFail.sql create mode 100644 contrib/timescaledb/regress/sql/SetIntegerNowFuncTest.sql create mode 100644 contrib/timescaledb/regress/sql/ShowBlocksInSchema.sql create mode 100644 contrib/timescaledb/regress/sql/TableDataMigrateSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/TableDataNoMigrateError.sql create mode 100644 contrib/timescaledb/regress/sql/TablespaceFunctionHandling.sql create mode 100644 contrib/timescaledb/regress/sql/TablespaceToHypertable.sql create mode 100644 contrib/timescaledb/regress/sql/TestAddMultipleDimensions.sql create mode 100644 contrib/timescaledb/regress/sql/TestTimeDimensionPartition.sql create mode 100755 contrib/timescaledb/regress/sql/ValidFunctionAddPartitionSuccess.sql create mode 100755 contrib/timescaledb/regress/sql/ValidFunctionHypertableCreationSuccess.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateAddBigIntDimension.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateAddDimensionExplicitType.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateAddDimensionIfNotExists.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateAddDimensionWithInterval.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateConflictingPartitionParamsError.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateCreateCommand.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateDataExistsDimensionError.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateDuplicateDimensionError.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateMissingFieldError.sql create mode 100644 contrib/timescaledb/regress/sql/ValidatePartitionDimensionAddFail.sql create mode 100644 contrib/timescaledb/regress/sql/ValidateRegularTableHypertableError.sql create mode 100755 contrib/timescaledb/regress/sql/lhy1.sql create mode 100644 contrib/timescaledb/temp-config.conf create mode 100755 contrib/timescaledb/timescaledb--1.7.4.sql create mode 100755 contrib/timescaledb/timescaledb.so diff --git a/contrib/timescaledb/Makefile b/contrib/timescaledb/Makefile new file mode 100644 index 000000000..bed98dd3e --- /dev/null +++ b/contrib/timescaledb/Makefile @@ -0,0 +1,101 @@ +MODULE_big = timescaledb + +EXTENSION = timescaledb + +DATA = timescaledb--1.7.4.sql + +override CPPFLAGS :=$(filter-out -fPIE, $(CPPFLAGS)) -fPIC + +override LIBDIR := /home/lhy/self_detection/lib/ + +#compile in og source +top_builddir = ../.. + +# sorted in dependency order expr +REGRESS = lhy1 \ + ValidFunctionAddPartitionSuccess \ + ValidFunctionHypertableCreationSuccess \ + AddPartitionFailOnEmptyChunkedTable \ + BigIntBoundaryTest \ + ChunkParallelism \ + ChunkRename \ + ChunkSchemaRenameSuccess \ + ChunkSchemaSetup \ + ChunkTablespaceUpdate \ + ColumnCleanup \ + ColumnRenameError \ + ColumnSyncFix \ + CreateHypertableDuplicateError \ + CustomPartitionFunctionTest \ + CustomTypeTableToHypertable \ + DefaultTablespaceValidation \ + EmptyTableMigrateSuccess \ + HypertableChunksDataCorrect \ + HypertableCreateNoPerm \ + HypertableCreationInfoSuccess \ + HypertableCustomTypeRelation \ + HypertableSchemaRename \ + HypertableTablespaceNoAccumulation \ + HypertableTriggerExists \ + IndexTablespaceUpdateValidation \ + InvalidFunctionAddPartitionFail \ + InvalidFunctionHypertableCreationFail \ + InvalidPartitionFunctionFailure \ + MultipleHypertablesRenameSuccess \ + PartitionCountChangeError \ + PartitionCountChangeSuccess \ + PartitionDimensionAddSuccess \ + PluginSchemaRenameErrorHandling \ + RoleInheritanceInsertTest \ + RoleSchemaHypertableFail \ + RoleSchemaPermHypertableSuccess \ + SchemaDeletionCascadeHypertables \ + SchemaPermRoleHypertableFail \ + SetIntegerNowFuncTest \ + ShowBlocksInSchema \ + TableDataMigrateSuccess \ + TableDataNoMigrateError \ + TablespaceFunctionHandling \ + TablespaceToHypertable \ + TestAddMultipleDimensions \ + TestTimeDimensionPartition \ + ValidateAddBigIntDimension \ + ValidateAddDimensionExplicitType \ + ValidateAddDimensionIfNotExists \ + ValidateAddDimensionWithInterval \ + ValidateConflictingPartitionParamsError \ + ValidateCreateCommand \ + ValidateDataExistsDimensionError \ + ValidateDuplicateDimensionError \ + ValidateMissingFieldError \ + ValidatePartitionDimensionAddFail \ + ValidateRegularTableHypertableError \ + + +srcdir=`pwd` + +ag_regress_dir = $(srcdir)/regress + +top_builddir = ../.. +REGRESS_OPTS = --dbname=test1 --extra-install='contrib/timescaledb' --top-builddir="../.." --inputdir=$(ag_regress_dir) --outputdir=$(ag_regress_dir) --encoding=UTF-8 --temp-install=$(ag_regress_dir)/instance --encoding=UTF-8 --dlpath=$(top_builddir)/src/test/regress --port=5432 -c 0 -d 1 --single_node + +ag_regress_out = instance/ log/ results/ regression.* + +EXTRA_CLEAN = regress/regression.diffs regress/regression.out regress/instance/ regress/log/ regress/results/ regress/.sql/ + +ifdef USE_PGXS +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +LIBS := $(shell $(PG_CONFIG) --libdir) +include $(PGXS) +include $(LIBS) +else +subdir = contrib/timescaledb +include $(top_builddir)/src/Makefile.global +include $(top_builddir)/contrib/contrib-global.mk +endif + +installcheck: use_smartmatch + +use_smartmatch: + cp $(top_builddir)/src/test/regress/smartmatch.pl $(srcdir)/regress/smartmatch.pl \ No newline at end of file diff --git a/contrib/timescaledb/data/empty b/contrib/timescaledb/data/empty new file mode 100644 index 000000000..e69de29bb diff --git a/contrib/timescaledb/regress/expected/AddPartitionFailOnEmptyChunkedTable.out b/contrib/timescaledb/regress/expected/AddPartitionFailOnEmptyChunkedTable.out new file mode 100644 index 000000000..ce5f6e8ef --- /dev/null +++ b/contrib/timescaledb/regress/expected/AddPartitionFailOnEmptyChunkedTable.out @@ -0,0 +1,34 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.插入数据 +insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_table values (123456789, 23.8, ... + ^ +-- 3.删除数据 +delete from test_schema.test_table where time is not null; +ERROR: schema "test_schema" does not exist +LINE 1: delete from test_schema.test_table where time is not null; + ^ +select count(*) from test_schema.test_table; +ERROR: schema "test_schema" does not exist +LINE 1: select count(*) from test_schema.test_table; + ^ +-- 4.新增分区维度 +select add_dimension('test_schema.test_table', 'device_type', 2); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'device_type'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/BigIntBoundaryTest.out b/contrib/timescaledb/regress/expected/BigIntBoundaryTest.out new file mode 100644 index 000000000..cabbde8d5 --- /dev/null +++ b/contrib/timescaledb/regress/expected/BigIntBoundaryTest.out @@ -0,0 +1,95 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.在role1下创建自定义函数 +set role lhy password 'Test@123'; +ERROR: Invalid username/password,set role denied. +CREATE OR REPLACE FUNCTION assert_true( + val boolean +) + RETURNS VOID LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + IF !val THEN + RAISE 'Assert failed'; + END IF; +END +$BODY$; +CREATE OR REPLACE FUNCTION assert_equal( + val1 anyelement, + val2 anyelement +) + RETURNS VOID LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + IF val1 != val2 THEN + RAISE 'Assert failed'; + END IF; +END +$BODY$; +-- 2.在初始用户下创建自定义函数 +\c test1 lhy +CREATE OR REPLACE FUNCTION allow_downgrade_to_apache() +RETURNS VOID +AS '$libdir/timescaledb-1.7.4', 'ts_allow_downgrade_to_apache' +LANGUAGE C; +CREATE OR REPLACE FUNCTION _timescaledb_internal.dimension_calculate_default_range_open( + dimension_value BIGINT, + interval_length BIGINT, + OUT range_start BIGINT, + OUT range_end BIGINT) + AS '$libdir/timescaledb-1.7.4', 'ts_dimension_calculate_open_range_default' LANGUAGE C STABLE; +WARNING: schema not defined, it may cause duplicate data. +DETAIL: schema not exists. +ERROR: schema "_timescaledb_internal" does not exist +CREATE OR REPLACE FUNCTION _timescaledb_internal.dimension_calculate_default_range_closed( + dimension_value BIGINT, + num_slices SMALLINT, + OUT range_start BIGINT, + OUT range_end BIGINT) + AS '$libdir/timescaledb-1.7.4', 'ts_dimension_calculate_closed_range_default' LANGUAGE C STABLE; +WARNING: schema not defined, it may cause duplicate data. +DETAIL: schema not exists. +ERROR: schema "_timescaledb_internal" does not exist +-- 3.bigint边界值测试 +SELECT assert_equal(0::bigint, actual_range_start), assert_equal(10::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(0,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(0::bigint, actual_range_start), assert_equal(10::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(9,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(10::bigint, actual_range_start), assert_equal(20::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(10,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(-10::bigint, actual_range_start), assert_equal(0::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-1,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(-10::bigint, actual_range_start), assert_equal(0::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-10,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(-20::bigint, actual_range_start), assert_equal(-10::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-11,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(-9223372036854775808, actual_range_start), assert_equal(-9223372036854775800::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-9223372036854775808,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(-9223372036854775808, actual_range_start), assert_equal(-9223372036854775800::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-9223372036854775807,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(9223372036854775800::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(9223372036854775807,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(9223372036854775800::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(9223372036854775806,10) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal((-9223372036854775808)::bigint, actual_range_start), assert_equal(1073741823::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_closed(0,2::smallint) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal(1073741823::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_closed(1073741824,2::smallint) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +SELECT assert_equal((-9223372036854775808)::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_closed(1073741824,1::smallint) AS res(actual_range_start, actual_range_end); +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ChunkParallelism.out b/contrib/timescaledb/regress/expected/ChunkParallelism.out new file mode 100644 index 000000000..1c13bda3a --- /dev/null +++ b/contrib/timescaledb/regress/expected/ChunkParallelism.out @@ -0,0 +1,46 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +\echo 1.创建超表 +1.创建超表 +\c test1 lhy; +drop table if exists test1 cascade; +NOTICE: table "test1" does not exist, skipping +CREATE TABLE test1(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +NOTICE: CREATE TABLE will create implicit sequence "test1_id_seq" for serial column "test1.id" +SELECT create_hypertable('test1', 'time', chunk_time_interval => 2628000000000); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := bigint) does not exist +LINE 1: SELECT create_hypertable('test1', 'time', chunk_time_interva... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +INSERT INTO test1 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test1 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test1 + Table "public.test1" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+----------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('test1_id_seq'::regclass) | plain | | + time | timestamp without time zone | | plain | | + temp | double precision | | plain | | + colorid | integer | | plain | | + notes | text | | extended | | + notes_2 | text | | extended | | +Has OIDs: no +Options: orientation=row, compression=no + +\echo 2.设置子表并行度 +2.设置子表并行度 +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk SET (parallel_workers=2); +ERROR: schema "_timescaledb_internal" does not exist +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk SET (parallel_workers=4); +ERROR: schema "_timescaledb_internal" does not exist +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk RESET (parallel_workers); +ERROR: schema "_timescaledb_internal" does not exist +SELECT relname, reloptions FROM pg_class WHERE relname IN ('_hyper_1_1_chunk','_hyper_1_2_chunk'); + relname | reloptions +---------+------------ +(0 rows) + +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ChunkRename.out b/contrib/timescaledb/regress/expected/ChunkRename.out new file mode 100644 index 000000000..9a5f00494 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ChunkRename.out @@ -0,0 +1,58 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +\echo 1.创建超表 +1.创建超表 +\c test1 lhy1; +drop table if exists test2 cascade; +NOTICE: table "test2" does not exist, skipping +CREATE TABLE test2(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +NOTICE: CREATE TABLE will create implicit sequence "test2_id_seq" for serial column "test2.id" +SELECT create_hypertable('test2', 'time', chunk_time_interval => 2628000000000); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := bigint) does not exist +LINE 1: SELECT create_hypertable('test2', 'time', chunk_time_interva... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +INSERT INTO test2 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test2 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test2 + Table "lhy1.test2" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+----------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('test2_id_seq'::regclass) | plain | | + time | timestamp without time zone | | plain | | + temp | double precision | | plain | | + colorid | integer | | plain | | + notes | text | | extended | | + notes_2 | text | | extended | | +Has OIDs: no +Options: orientation=row, compression=no + +\echo 2.非初始用户重命名chunk的表名称合理报错 +2.非初始用户重命名chunk的表名称合理报错 +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; + ^ +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk RENAME TO new_chunk_name; +ERROR: schema "_timescaledb_internal" does not exist +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; + ^ +\echo 3.初始用户重命名chunk的表名称成功 +3.初始用户重命名chunk的表名称成功 +\c test1 lhy +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 2; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.chunk WHERE id = 2; + ^ +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk RENAME TO new_chunk_name; +ERROR: schema "_timescaledb_internal" does not exist +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 2; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.chunk WHERE id = 2; + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ChunkSchemaRenameSuccess.out b/contrib/timescaledb/regress/expected/ChunkSchemaRenameSuccess.out new file mode 100644 index 000000000..9cd258114 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ChunkSchemaRenameSuccess.out @@ -0,0 +1,52 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.指定chunk的模式名为my_associated_schema创建超表 +CREATE TABLE my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('my_table','date', associated_schema_name => 'my_associated_schema'); +ERROR: function create_hypertable(unknown, unknown, associated_schema_name := unknown) does not exist +LINE 1: SELECT create_hypertable('my_table','date', associated_schem... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据 +INSERT INTO my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +-- 3.更改关联的chunk的模式名 +ALTER SCHEMA my_associated_schema RENAME TO new_associated_schema; +ERROR: schema "my_associated_schema" does not exist +\d+ my_table + Table "public.my_table" + Column | Type | Modifiers | Storage | Stats target | Description +----------+--------------------------+-----------+---------+--------------+------------- + date | timestamp with time zone | not null | plain | | + quantity | double precision | | plain | | +Has OIDs: no +Options: orientation=row, compression=no + +-- 4.再次插入数据 +INSERT INTO my_table (date, quantity) VALUES ('2018-08-10T23:00:00+00:00', 20); +\d+ my_table + Table "public.my_table" + Column | Type | Modifiers | Storage | Stats target | Description +----------+--------------------------+-----------+---------+--------------+------------- + date | timestamp with time zone | not null | plain | | + quantity | double precision | | plain | | +Has OIDs: no +Options: orientation=row, compression=no + +-- 5.在系统表下查看chunk模式名均更改成功 +SELECT * from _timescaledb_catalog.hypertable where table_name='my_table'; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * from _timescaledb_catalog.hypertable where table_na... + ^ +SELECT * from _timescaledb_catalog.chunk; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * from _timescaledb_catalog.chunk; + ^ +-- 6.清理环境 +DROP TABLE my_table; +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ChunkSchemaSetup.out b/contrib/timescaledb/regress/expected/ChunkSchemaSetup.out new file mode 100644 index 000000000..e500459f7 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ChunkSchemaSetup.out @@ -0,0 +1,44 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +\echo 1.创建超表 +1.创建超表 +\c test1 lhy1; +drop table if exists test3 cascade; +NOTICE: table "test3" does not exist, skipping +CREATE TABLE test3(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +NOTICE: CREATE TABLE will create implicit sequence "test3_id_seq" for serial column "test3.id" +SELECT create_hypertable('test3', 'time', chunk_time_interval => 2628000000000); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := bigint) does not exist +LINE 1: SELECT create_hypertable('test3', 'time', chunk_time_interva... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test3 + Table "lhy1.test3" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+----------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('test3_id_seq'::regclass) | plain | | + time | timestamp without time zone | | plain | | + temp | double precision | | plain | | + colorid | integer | | plain | | + notes | text | | extended | | + notes_2 | text | | extended | | +Has OIDs: no +Options: orientation=row, compression=no + +\echo 2.初始用户设置chunk的schema为public成功 +2.初始用户设置chunk的schema为public成功 +\c test1 lhy +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk RENAME TO new_chunk_name; +ERROR: schema "_timescaledb_internal" does not exist +ALTER TABLE _timescaledb_internal.new_chunk_name SET SCHEMA public; +ERROR: schema "_timescaledb_internal" does not exist +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ChunkTablespaceUpdate.out b/contrib/timescaledb/regress/expected/ChunkTablespaceUpdate.out new file mode 100644 index 000000000..8c7443f70 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ChunkTablespaceUpdate.out @@ -0,0 +1,50 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 lhy1; +drop table if exists test3 cascade; +CREATE TABLE test3(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +NOTICE: CREATE TABLE will create implicit sequence "test3_id_seq" for serial column "test3.id" +SELECT create_hypertable('test3', 'time', chunk_time_interval => 2628000000000); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := bigint) does not exist +LINE 1: SELECT create_hypertable('test3', 'time', chunk_time_interva... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test3 + Table "lhy1.test3" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+----------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('test3_id_seq'::regclass) | plain | | + time | timestamp without time zone | | plain | | + temp | double precision | | plain | | + colorid | integer | | plain | | + notes | text | | extended | | + notes_2 | text | | extended | | +Has OIDs: no +Options: orientation=row, compression=no + +-- 2.切换至初始用户创建表空间 +\c test1 lhy; +SET client_min_messages = ERROR; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2/PG_9.2_201611171_datanode1" already in use as a tablespace +-- 3.切换至角色role1,更改chunk的表空间 +\c test1 lhy1; +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk SET TABLESPACE tablespace1; +ERROR: schema "_timescaledb_internal" does not exist +SELECT tablespace FROM pg_tables WHERE tablename = '_hyper_1_1_chunk'; + tablespace +------------ +(0 rows) + +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ColumnCleanup.out b/contrib/timescaledb/regress/expected/ColumnCleanup.out new file mode 100644 index 000000000..03fc63ee2 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ColumnCleanup.out @@ -0,0 +1,137 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +\echo 1.创建超表 +1.创建超表 +set role lhy; +ERROR: Invalid username/password,set role denied. +CREATE TABLE alter_after(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +NOTICE: CREATE TABLE will create implicit sequence "alter_after_id_seq" for serial column "alter_after.id" +SELECT create_hypertable('alter_after', 'time', chunk_time_interval => 2628000000000); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := bigint) does not exist +LINE 1: SELECT create_hypertable('alter_after', 'time', chunk_time_i... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\echo 2.插入1条数据生成第一个chunk(子表) +2.插入1条数据生成第一个chunk(子表) +INSERT INTO alter_after (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +\d+ alter_after + Table "public.alter_after" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+----------------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('alter_after_id_seq'::regclass) | plain | | + time | timestamp without time zone | | plain | | + temp | double precision | | plain | | + colorid | integer | | plain | | + notes | text | | extended | | + notes_2 | text | | extended | | +Has OIDs: no +Options: orientation=row, compression=no + +\echo 3.删除并更改列字段属性 +3.删除并更改列字段属性 +ALTER TABLE alter_after DROP COLUMN id; +ALTER TABLE alter_after ALTER COLUMN temp SET (n_distinct = 10); +ALTER TABLE alter_after ALTER COLUMN colorid SET (n_distinct = 11); +ALTER TABLE alter_after ALTER COLUMN colorid RESET (n_distinct); +ALTER TABLE alter_after ALTER COLUMN colorid SET STATISTICS 101; +ALTER TABLE alter_after ALTER COLUMN notes_2 SET STORAGE EXTERNAL; +\echo 4.删除列后插入数据成功(生成新的chunk) +4.删除列后插入数据成功(生成新的chunk) +INSERT INTO alter_after VALUES ('2017-03-22T09:18:23', 21.5, 1), + ('2017-05-22T09:18:22', 36.2, 2), + ('2017-05-22T09:18:23', 15.2, 2); +\d+ alter_after + Table "public.alter_after" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+-----------+----------+--------------+------------- + time | timestamp without time zone | | plain | | + temp | double precision | | plain | | + colorid | integer | | plain | 101 | + notes | text | | extended | | + notes_2 | text | | external | | +Has OIDs: no +Options: orientation=row, compression=no + +\echo 5.确保copy数据功能正常 +5.确保copy数据功能正常 +\COPY alter_after FROM '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/sql/data/alter.tsv' NULL AS ''; +/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/sql/data/alter.tsv: No such file or directory +\echo 6.查看表的数据显示正常 +6.查看表的数据显示正常 +SELECT * FROM alter_after; + time | temp | colorid | notes | notes_2 +--------------------------+------+---------+-------+--------- + Wed Mar 22 09:18:22 2017 | 23.5 | 1 | | + Wed Mar 22 09:18:23 2017 | 21.5 | 1 | | + Mon May 22 09:18:22 2017 | 36.2 | 2 | | + Mon May 22 09:18:23 2017 | 15.2 | 2 | | +(4 rows) + +\echo 7.在drop列之后创建的chunk的attnum不同 +7.在drop列之后创建的chunk的attnum不同 +SELECT c.relname, a.attname, a.attnum FROM pg_attribute a, pg_class c +WHERE a.attrelid = c.oid +AND (c.relname LIKE '_hyper_54%_chunk' OR c.relname = 'alter_after') +AND a.attnum > 0 +ORDER BY c.relname, a.attnum; + relname | attname | attnum +-------------+------------------------------+-------- + alter_after | ........pg.dropped.1........ | 1 + alter_after | time | 2 + alter_after | temp | 3 + alter_after | colorid | 4 + alter_after | notes | 5 + alter_after | notes_2 | 6 +(6 rows) + +\echo 8.再次添加id列后插入数据 +8.再次添加id列后插入数据 +-- 这个会出现异常,因为普通表也不支持 +ALTER TABLE alter_after ADD COLUMN id serial; +ERROR: It's not supported to alter table add serial column +INSERT INTO alter_after (time, temp, colorid) VALUES ('2017-08-22T09:19:14', 12.5, 3); +\echo 9.验证在chunk上修改列属性成功(块的名称要跟实际块的名称对应,下面chunk的名称_hyper_58_45_chunk等不是固定不变的) +9.验证在chunk上修改列属性成功(块的名称要跟实际块的名称对应,下面chunk的名称_hyper_58_45_chunk等不是固定不变的) +-- 这个需要输出一下上面的_hyper_29%_chunk来看看底下的叫什么名字,到时候需要将epected替换一下 +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk ALTER COLUMN temp RESET (n_distinct); +ERROR: schema "_timescaledb_internal" does not exist +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk ALTER COLUMN temp SET (n_distinct = 20); +ERROR: schema "_timescaledb_internal" does not exist +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk ALTER COLUMN temp SET STATISTICS 201; +ERROR: schema "_timescaledb_internal" does not exist +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk ALTER COLUMN notes SET STORAGE EXTERNAL; +ERROR: schema "_timescaledb_internal" does not exist +\echo 10.增加列后查看表的attnum与n_distinct属性 +10.增加列后查看表的attnum与n_distinct属性 +SELECT c.relname, a.attname, a.attnum, a.attoptions, a.attstattarget, a.attstorage FROM pg_attribute a, pg_class c +WHERE a.attrelid = c.oid +AND (c.relname LIKE '_hyper_1%_chunk' OR c.relname = 'alter_after') +AND a.attnum > 0 +ORDER BY c.relname, a.attnum; + relname | attname | attnum | attoptions | attstattarget | attstorage +-------------+------------------------------+--------+-----------------+---------------+------------ + alter_after | ........pg.dropped.1........ | 1 | | 0 | p + alter_after | time | 2 | | -1 | p + alter_after | temp | 3 | {n_distinct=10} | -1 | p + alter_after | colorid | 4 | | 101 | p + alter_after | notes | 5 | | -1 | x + alter_after | notes_2 | 6 | | -1 | e +(6 rows) + +\echo 11.查看超表的数据 +11.查看超表的数据 +SELECT * FROM alter_after; + time | temp | colorid | notes | notes_2 +--------------------------+------+---------+-------+--------- + Wed Mar 22 09:18:22 2017 | 23.5 | 1 | | + Wed Mar 22 09:18:23 2017 | 21.5 | 1 | | + Mon May 22 09:18:22 2017 | 36.2 | 2 | | + Mon May 22 09:18:23 2017 | 15.2 | 2 | | + Tue Aug 22 09:19:14 2017 | 12.5 | 3 | | +(5 rows) + +\o +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ColumnRenameError.out b/contrib/timescaledb/regress/expected/ColumnRenameError.out new file mode 100644 index 000000000..ef4c44eda --- /dev/null +++ b/contrib/timescaledb/regress/expected/ColumnRenameError.out @@ -0,0 +1,34 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 lhy1; +drop table if exists test3 cascade; +CREATE TABLE test3(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +NOTICE: CREATE TABLE will create implicit sequence "test3_id_seq" for serial column "test3.id" +SELECT create_hypertable('test3', 'time', chunk_time_interval => 2628000000000); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := bigint) does not exist +LINE 1: SELECT create_hypertable('test3', 'time', chunk_time_interva... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test3 + Table "lhy1.test3" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+----------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('test3_id_seq'::regclass) | plain | | + time | timestamp without time zone | | plain | | + temp | double precision | | plain | | + colorid | integer | | plain | | + notes | text | | extended | | + notes_2 | text | | extended | | +Has OIDs: no +Options: orientation=row, compression=no + +-- 2.重命名子表的列名称合理报错 +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk RENAME COLUMN time TO newtime; +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ColumnSyncFix.out b/contrib/timescaledb/regress/expected/ColumnSyncFix.out new file mode 100644 index 000000000..7b2f56daa --- /dev/null +++ b/contrib/timescaledb/regress/expected/ColumnSyncFix.out @@ -0,0 +1,63 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +\echo 1.创建普通表 +1.创建普通表 +CREATE TABLE alter_before(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +NOTICE: CREATE TABLE will create implicit sequence "alter_before_id_seq" for serial column "alter_before.id" +\echo 2.修改列字段属性 +2.修改列字段属性 +ALTER TABLE alter_before DROP COLUMN id; +ALTER TABLE alter_before ALTER COLUMN temp SET (n_distinct = 10); +ALTER TABLE alter_before ALTER COLUMN colorid SET (n_distinct = 11); +ALTER TABLE alter_before ALTER COLUMN colorid RESET (n_distinct); +ALTER TABLE alter_before ALTER COLUMN temp SET STATISTICS 100; +ALTER TABLE alter_before ALTER COLUMN notes SET STORAGE EXTERNAL; +\echo 3.创建超表 +3.创建超表 +SELECT create_hypertable('alter_before', 'time', chunk_time_interval => 2628000000000); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := bigint) does not exist +LINE 1: SELECT create_hypertable('alter_before', 'time', chunk_time_... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\echo 4.超表插入数据 +4.超表插入数据 +INSERT INTO alter_before VALUES ('2017-03-22T09:18:22', 23.5, 1); +SELECT * FROM alter_before; + time | temp | colorid | notes | notes_2 +--------------------------+------+---------+-------+--------- + Wed Mar 22 09:18:22 2017 | 23.5 | 1 | | +(1 row) + +\d+ alter_before + Table "public.alter_before" + Column | Type | Modifiers | Storage | Stats target | Description +---------+-----------------------------+-----------+----------+--------------+------------- + time | timestamp without time zone | | plain | | + temp | double precision | | plain | 100 | + colorid | integer | | plain | | + notes | text | | external | | + notes_2 | text | | extended | | +Has OIDs: no +Options: orientation=row, compression=no + +\echo 5.显示已删除的列被标记为已删除且父表与子表(chunk)的attnum不同(_hyper_57%_chunk对应超表的块) +5.显示已删除的列被标记为已删除且父表与子表(chunk)的attnum不同(_hyper_57%_chunk对应超表的块) +SELECT c.relname, a.attname, a.attnum, a.attoptions, a.attstattarget, a.attstorage FROM pg_attribute a, pg_class c +WHERE a.attrelid = c.oid +AND (c.relname LIKE '_hyper_1%_chunk' OR c.relname = 'alter_before') +AND a.attnum > 0 +ORDER BY c.relname, a.attnum; + relname | attname | attnum | attoptions | attstattarget | attstorage +--------------+------------------------------+--------+-----------------+---------------+------------ + alter_before | ........pg.dropped.1........ | 1 | | 0 | p + alter_before | time | 2 | | -1 | p + alter_before | temp | 3 | {n_distinct=10} | 100 | p + alter_before | colorid | 4 | | -1 | p + alter_before | notes | 5 | | -1 | e + alter_before | notes_2 | 6 | | -1 | x +(6 rows) + +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/CreateHypertableDuplicateError.out b/contrib/timescaledb/regress/expected/CreateHypertableDuplicateError.out new file mode 100644 index 000000000..66cfae87b --- /dev/null +++ b/contrib/timescaledb/regress/expected/CreateHypertableDuplicateError.out @@ -0,0 +1,44 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_1dim; +ERROR: schema "test_schema" does not exist +create table test_schema.test_1dim(time timestamp, temp float); +ERROR: schema "test_schema" does not exist +select create_hypertable('test_schema.test_1dim', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_1dim', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.不指定if_not_exists参数再次创建超表 +select create_hypertable('test_schema.test_1dim', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_1dim', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 3.插入数据 +insert into test_schema.test_1dim VALUES ('2004-10-19 10:23:54+02', 1.0); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_1dim VALUES ('2004-10-19 10:23:... + ^ +-- 4.指定if_not_exists参数为true再次创建超表 +select create_hypertable('test_schema.test_1dim', 'time', if_not_exists => true); +ERROR: function create_hypertable(unknown, unknown, if_not_exists := boolean) does not exist +LINE 1: select create_hypertable('test_schema.test_1dim', 'time', if... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 5.不指定if_not_exists参数再次创建超表合理报错 +select create_hypertable('test_schema.test_1dim', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_1dim', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/CustomPartitionFunctionTest.out b/contrib/timescaledb/regress/expected/CustomPartitionFunctionTest.out new file mode 100644 index 000000000..8ba37d04b --- /dev/null +++ b/contrib/timescaledb/regress/expected/CustomPartitionFunctionTest.out @@ -0,0 +1,99 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.使用og初始用户role登入数据库 +\c test1 lhy; +-- 2.从role2角色中收回role1角色的权限 +revoke lhy1 from lhy2; +WARNING: role "lhy2" is not a member of role "lhy1" +-- 3.创建自定义分区函数 +CREATE OR REPLACE FUNCTION partfunc_not_immutable(source anyelement) + RETURNS INTEGER LANGUAGE PLPGSQL AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_not_immutable" near line 3 +CREATE OR REPLACE FUNCTION partfunc_bad_return_type(source anyelement) + RETURNS BIGINT LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_bad_return_type" near line 3 +CREATE OR REPLACE FUNCTION partfunc_bad_arg_type(source text) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_bad_arg_type" near line 3 +CREATE OR REPLACE FUNCTION partfunc_bad_multi_arg(source anyelement, extra_arg integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_bad_multi_arg" near line 3 +CREATE OR REPLACE FUNCTION partfunc_valid(source anyelement) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_valid" near line 3 +-- 4.创建超表 +drop table if exists test_schema.test_partfunc; +ERROR: schema "test_schema" does not exist +create table test_schema.test_partfunc(time timestamptz, temp float, device int); +ERROR: schema "test_schema" does not exist +select create_hypertable('test_schema.test_partfunc', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_partfunc', 'time'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 5.自定义分区函数无效导致增加分区维度失败 +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_not_immutable'); +ERROR: function add_dimension(unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select add_dimension('test_schema.test_partfunc', 'device', ... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_bad_return_type'); +ERROR: function add_dimension(unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select add_dimension('test_schema.test_partfunc', 'device', ... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_bad_arg_type'); +ERROR: function add_dimension(unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select add_dimension('test_schema.test_partfunc', 'device', ... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_bad_multi_arg'); +ERROR: function add_dimension(unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select add_dimension('test_schema.test_partfunc', 'device', ... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 6.使用有效的分区函数添加分区维度成功 +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_valid'); +ERROR: function add_dimension(unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select add_dimension('test_schema.test_partfunc', 'device', ... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/CustomTypeTableToHypertable.out b/contrib/timescaledb/regress/expected/CustomTypeTableToHypertable.out new file mode 100644 index 000000000..dc7a667d6 --- /dev/null +++ b/contrib/timescaledb/regress/expected/CustomTypeTableToHypertable.out @@ -0,0 +1,25 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建自定义数据类型并转换为超表 +\c test1 +CREATE TYPE test_type AS (time timestamp, temp float); +CREATE TABLE test_table_of_type OF test_type; +SELECT create_hypertable('test_table_of_type', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('test_table_of_type', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.超表插入数据 +INSERT INTO test_table_of_type VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +-- 3.删除自定义数据类型 +DROP TYPE test_type; +ERROR: cannot drop type test_type because other objects depend on it +DETAIL: table test_table_of_type depends on type test_type +HINT: Use DROP ... CASCADE to drop the dependent objects too. +-- 4.加CASCADE删除自定义数据类型 +DROP TYPE test_type CASCADE; +NOTICE: drop cascades to table test_table_of_type +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/DefaultTablespaceValidation.out b/contrib/timescaledb/regress/expected/DefaultTablespaceValidation.out new file mode 100644 index 000000000..596b38e0b --- /dev/null +++ b/contrib/timescaledb/regress/expected/DefaultTablespaceValidation.out @@ -0,0 +1,126 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.清理test1库下所有表 +drop table if EXISTS test1 cascade; +drop table if EXISTS test2 cascade; +NOTICE: table "test2" does not exist, skipping +-- 2.切换至初始用户创建表空间 +\c test1 lhy; +SET client_min_messages = ERROR; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2/PG_9.2_201611171_datanode1" already in use as a tablespace +-- 3.创建超表 +CREATE TABLE hyper_in_space(time bigint, temp float, device int); +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, chunk_time_interval := integer) does not exist +LINE 1: SELECT create_hypertable('hyper_in_space', 'time', 'device',... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 4.插入数据,查看表空间下的表信息 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + tablename +----------- +(0 rows) + +-- 5.设置默认表空间为tablespace1后插入数据 +SET default_tablespace = tablespace1; +ERROR: invalid value for parameter "default_tablespace": "tablespace1" +DETAIL: Tablespace "tablespace1" does not exist. +INSERT INTO hyper_in_space(time, temp, device) VALUES (11, 24, 3); +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename LIKE '_hyper%' ORDER BY tablename; + tablename | tablespace +----------------+------------ + hyper_in_space | +(1 row) + +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + tablename +----------- +(0 rows) + +-- 6.更改父表的表空间为tablespace1,查看tablespace1下的表信息 +SET default_tablespace TO DEFAULT; +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; +ERROR: tablespace "tablespace1" does not exist +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + tablename +----------- +(0 rows) + +\d+ hyper_in_space + Table "public.hyper_in_space" + Column | Type | Modifiers | Storage | Stats target | Description +--------+------------------+-----------+---------+--------------+------------- + time | bigint | | plain | | + temp | double precision | | plain | | + device | integer | | plain | | +Has OIDs: no +Options: orientation=row, compression=no + +-- 7.插入如下数据,数据插入表空间已有的chunk中,不产生新的chunk +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 27, 1); +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + tablename +----------- +(0 rows) + +select * from _timescaledb_internal._hyper_1_1_chunk; +ERROR: schema "_timescaledb_internal" does not exist +LINE 1: select * from _timescaledb_internal._hyper_1_1_chunk; + ^ +-- 8.插入如下数据,产生新的chunk +INSERT INTO hyper_in_space(time, temp, device) VALUES (8, 24, 2); +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename LIKE '_hyper%' ORDER BY tablename; + tablename | tablespace +----------------+------------ + hyper_in_space | +(1 row) + +-- 9.超表已附加到表空间,超表存在删除表空间合理报错 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; +ERROR: tablespace "tablespace1" does not exist +DROP TABLESPACE tablespace1; +ERROR: Tablespace "tablespace1" does not exist. +-- 10.show_chunks与drop_chunks一致 +-- 设置变量 +\set QUERY1 'SELECT show_chunks(\'hyper_in_space\', 22)::NAME' +\set QUERY2 'SELECT drop_chunks(22, \'hyper_in_space\')::NAME' +-- 创建临时结果(cte)用于查询 +with query1 AS ( + SELECT row_number() OVER(ORDER BY q.*) row_number, * FROM (:QUERY1) as q +), +query2 AS ( + SELECT row_number() OVER (ORDER BY v.*) row_number, * FROM (:QUERY2) as v +) +SELECT count(*) FILTER (WHERE query1.row_number IS DISTINCT FROM query2.row_number OR query1.show_chunks IS DISTINCT FROM query2.drop_chunks) AS "Different Rows", +coalesce(max(query1.row_number), 0) AS "Total Rows from Query 1", coalesce(max(query2.row_number), 0) AS "Total Rows from Query 2" +FROM query1 FULL OUTER JOIN query2 ON (query1.row_number = query2.row_number); +ERROR: function show_chunks(unknown, integer) does not exist +LINE 2: ...r() OVER(ORDER BY q.*) row_number, * FROM (SELECT show_chunk... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: show_chunks +-- 11.再次查看表空间tablespace1下的表信息,不存在chunk(子表) +SELECT tablename, tablespace FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + tablename | tablespace +-----------+------------ +(0 rows) + +-- 12.超表与表空间存在依赖关系,删除表空间合理报错。删除超表成功 +DROP TABLESPACE tablespace1; +ERROR: Tablespace "tablespace1" does not exist. +DROP TABLE hyper_in_space; +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/EmptyTableMigrateSuccess.out b/contrib/timescaledb/regress/expected/EmptyTableMigrateSuccess.out new file mode 100644 index 000000000..768b2e1f3 --- /dev/null +++ b/contrib/timescaledb/regress/expected/EmptyTableMigrateSuccess.out @@ -0,0 +1,16 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建普通表 +\c test1 +create table test_schema.test_migrate_empty(time timestamp, temp float); +ERROR: schema "test_schema" does not exist +-- 2.转换为超表 +select create_hypertable('test_schema.test_migrate_empty', 'time', migrate_data => true); +ERROR: function create_hypertable(unknown, unknown, migrate_data := boolean) does not exist +LINE 1: select create_hypertable('test_schema.test_migrate_empty', '... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/HypertableChunksDataCorrect.out b/contrib/timescaledb/regress/expected/HypertableChunksDataCorrect.out new file mode 100644 index 000000000..9f5f60bd7 --- /dev/null +++ b/contrib/timescaledb/regress/expected/HypertableChunksDataCorrect.out @@ -0,0 +1,57 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- -- 1.创建表并插入数据 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +create table test_schema.test_migrate(time timestamp, temp float); +ERROR: schema "test_schema" does not exist +insert into test_schema.test_migrate VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_migrate VALUES ('2004-10-19 10:... + ^ +select * from only test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +LINE 1: select * from only test_schema.test_migrate; + ^ +-- 2.转换为超表(此刻父表的数据被移至子表) +select create_hypertable('test_schema.test_migrate', 'time', migrate_data => true); +ERROR: function create_hypertable(unknown, unknown, migrate_data := boolean) does not exist +LINE 1: select create_hypertable('test_schema.test_migrate', 'time',... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 3.查看超表的表信息,获取超表id +select * from _timescaledb_catalog.hypertable where table_name = 'test_migrate'; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.hypertable where table_na... + ^ +-- 4.查看该超表id下的chunk信息有2个 +select * from _timescaledb_catalog.chunk; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.chunk; + ^ +-- 5.只查看父表数据 +select * from only test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +LINE 1: select * from only test_schema.test_migrate; + ^ +-- 6.广义查看超表数据 +select * from test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +LINE 1: select * from test_schema.test_migrate; + ^ +\d+ test_schema.test_migrate +-- 7.在每个子表中查看数据 +select * from only _timescaledb_internal._hyper_51_67_chunk; +ERROR: schema "_timescaledb_internal" does not exist +LINE 1: select * from only _timescaledb_internal._hyper_51_67_chunk; + ^ +select * from only _timescaledb_internal._hyper_58_70_chunk; +ERROR: schema "_timescaledb_internal" does not exist +LINE 1: select * from only _timescaledb_internal._hyper_58_70_chunk; + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/HypertableCreateNoPerm.out b/contrib/timescaledb/regress/expected/HypertableCreateNoPerm.out new file mode 100644 index 000000000..4781b6bb9 --- /dev/null +++ b/contrib/timescaledb/regress/expected/HypertableCreateNoPerm.out @@ -0,0 +1,13 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.在role1下创建普通表 +\c test1 +create table test_schema.test_table_no_not_null(time BIGINT, device_id text); +ERROR: schema "test_schema" does not exist +-- 2.切换角色至role2,在role2下创建超表 +set role lhy2 password 'Test@123'; +select * from create_hypertable('test_schema.test_table_no_not_null', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month')); +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/HypertableCreationInfoSuccess.out b/contrib/timescaledb/regress/expected/HypertableCreationInfoSuccess.out new file mode 100644 index 000000000..c1bd2e5fb --- /dev/null +++ b/contrib/timescaledb/regress/expected/HypertableCreationInfoSuccess.out @@ -0,0 +1,24 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +-- 2.将会话恢复为原有权限 +RESET ROLE; +-- 3.赋值role2的chunk_schema权限给role1 +GRANT CREATE ON SCHEMA chunk_schema TO lhy1; +ERROR: schema "chunk_schema" does not exist +-- 4.切换至role1创建超表 +set role lhy1 password 'Test@123'; +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 5.查看创建超表的命令 +SELECT * FROM _timescaledb_internal.get_create_command('test_table'); +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/HypertableCustomTypeRelation.out b/contrib/timescaledb/regress/expected/HypertableCustomTypeRelation.out new file mode 100644 index 000000000..390684b4f --- /dev/null +++ b/contrib/timescaledb/regress/expected/HypertableCustomTypeRelation.out @@ -0,0 +1,38 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.转换为超表 +\c test1 +CREATE TABLE test_table_of_type (time timestamp, temp float); +SELECT create_hypertable('test_table_of_type', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('test_table_of_type', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据 +INSERT INTO test_table_of_type VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +-- 3.创建自定义数据类型 +CREATE TYPE test_type AS (time timestamp, temp float); +-- 4.超表链接到组合类型test_type +ALTER TABLE test_table_of_type OF test_type; +-- 5.删除自定义数据类型 +DROP TYPE test_type; +ERROR: cannot drop type test_type because other objects depend on it +DETAIL: table test_table_of_type depends on type test_type +HINT: Use DROP ... CASCADE to drop the dependent objects too. +-- 6.加cascade删除数据类型后rollback +BEGIN; +DROP TYPE test_type CASCADE; +NOTICE: drop cascades to table test_table_of_type +ROLLBACK; +-- 7.不加CASCADE再次删除自定义数据类型 +DROP TYPE test_type; +ERROR: cannot drop type test_type because other objects depend on it +DETAIL: table test_table_of_type depends on type test_type +HINT: Use DROP ... CASCADE to drop the dependent objects too. +-- 8.超表解除自定义数据类型后删除自定义数据类型 +ALTER TABLE test_table_of_type NOT OF; +DROP TYPE test_type; +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/HypertableSchemaRename.out b/contrib/timescaledb/regress/expected/HypertableSchemaRename.out new file mode 100644 index 000000000..85cb9ed12 --- /dev/null +++ b/contrib/timescaledb/regress/expected/HypertableSchemaRename.out @@ -0,0 +1,24 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.自定义模式名创建超表 +\c test1 lhy; +CREATE SCHEMA IF NOT EXISTS original_name; +CREATE TABLE original_name.my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('original_name.my_table','date'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('original_name.my_table','date'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据并更改超表模式名 +INSERT INTO original_name.my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +ALTER SCHEMA original_name RENAME TO new_name; +-- 3.清理环境 +DROP TABLE new_name.my_table; +DROP SCHEMA new_name; +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/HypertableTablespaceNoAccumulation.out b/contrib/timescaledb/regress/expected/HypertableTablespaceNoAccumulation.out new file mode 100644 index 000000000..50ffcc455 --- /dev/null +++ b/contrib/timescaledb/regress/expected/HypertableTablespaceNoAccumulation.out @@ -0,0 +1,90 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建普通表并转换为超表 +\c test1 lhy; +SET client_min_messages = ERROR; +drop table if exists hyper_in_space; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLE hyper_in_space(time bigint, temp float, device int) TABLESPACE tablespace1; +ERROR: tablespace "tablespace1" does not exist +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, chunk_time_interval := integer) does not exist +LINE 1: SELECT create_hypertable('hyper_in_space', 'time', 'device',... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23... + ^ +-- 3.查看超表id下有唯一的表空间tablespace1 +SELECT * FROM _timescaledb_catalog.tablespace; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.tablespace; + ^ +-- 4.通过alter table设置超表的表空间为tablespace2 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace2; +ERROR: relation "hyper_in_space" does not exist +SELECT * FROM _timescaledb_catalog.tablespace; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.tablespace; + ^ +-- 5.通过alter table重新设置超表的表空间为tablespace1 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; +ERROR: relation "hyper_in_space" does not exist +SELECT * FROM _timescaledb_catalog.tablespace; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.tablespace; + ^ +-- 6.查看chunk与超表附加的表空间信息 +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + tablename | tablespace +-----------+------------ +(0 rows) + +-- 7.超表hyper_in_space分离表空间tablespace1 +SELECT detach_tablespace('tablespace1', 'hyper_in_space'); +ERROR: function detach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT detach_tablespace('tablespace1', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: detach_tablespace +-- 8.超表插入数据后查看表空间信息 +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (7, 23, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (7, 23... + ^ +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + tablename | tablespace +-----------+------------ +(0 rows) + +-- 9.系统表_timescaledb_catalog.tablespace查看附加的表空间信息 +SELECT * FROM _timescaledb_catalog.tablespace; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.tablespace; + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/HypertableTriggerExists.out b/contrib/timescaledb/regress/expected/HypertableTriggerExists.out new file mode 100644 index 000000000..c6f68cebb --- /dev/null +++ b/contrib/timescaledb/regress/expected/HypertableTriggerExists.out @@ -0,0 +1,35 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建触发器测试函数 +\c test1 +CREATE SCHEMA IF NOT EXISTS test; +GRANT USAGE ON SCHEMA test TO PUBLIC; +CREATE OR REPLACE FUNCTION test.show_triggers(rel regclass, show_internal boolean = false) +RETURNS TABLE("Trigger" name, + "Type" smallint, + "Function" regproc) LANGUAGE SQL STABLE AS +$BODY$ + SELECT t.tgname, + t.tgtype, + t.tgfoid::regproc + FROM pg_trigger t + WHERE t.tgrelid = rel + AND t.tgisinternal = show_internal + ORDER BY t.tgname; +$BODY$; +-- 2.创建超表 +create table test_schema.test_table2(time date); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table2', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: select * from create_hypertable('test_schema.test_table2', '... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +-- 3.查看超表的触发器 +SELECT * FROM test.show_triggers('test_schema.test_table2'); +ERROR: schema "test_schema" does not exist +LINE 1: SELECT * FROM test.show_triggers('test_schema.test_table2'); + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/IndexTablespaceUpdateValidation.out b/contrib/timescaledb/regress/expected/IndexTablespaceUpdateValidation.out new file mode 100644 index 000000000..a3f39bf07 --- /dev/null +++ b/contrib/timescaledb/regress/expected/IndexTablespaceUpdateValidation.out @@ -0,0 +1,74 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建表空间 +DROP TABLESPACE IF EXISTS tablespace1; +NOTICE: Tablespace "tablespace1" does not exist, skipping. +DROP TABLESPACE IF EXISTS tablespace2; +NOTICE: Tablespace "tablespace2" does not exist, skipping. +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2/PG_9.2_201611171_datanode1" already in use as a tablespace +-- 2.在表空间tablespace1上创建具有主键索引的表(复合主键) +CREATE TABLE series( + time timestamptz not null, + device int, + value float, + CONSTRAINT series_pk PRIMARY KEY (time, device) USING INDEX TABLESPACE tablespace1); +ERROR: tablespace "tablespace1" does not exist +SELECT create_hypertable('series', 'time', create_default_indexes => FALSE); +ERROR: function create_hypertable(unknown, unknown, create_default_indexes := boolean) does not exist +LINE 1: SELECT create_hypertable('series', 'time', create_default_in... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 3.插入数据以创建初始块 +INSERT INTO series VALUES ('2019-04-21 10:12', 1, 1.01); +ERROR: relation "series" does not exist on datanode1 +LINE 1: INSERT INTO series VALUES ('2019-04-21 10:12', 1, 1.01); + ^ +-- 4.创建索引series_value并指定表空间为tablespace2 +CREATE INDEX series_value ON series (value, time) TABLESPACE tablespace2; +ERROR: relation "series" does not exist +-- 5.查看系统表pg_indexes的索引信息 +SELECT schemaname, tablename, indexname, tablespace +FROM pg_indexes +WHERE indexname LIKE '%series%' +ORDER BY indexname; + schemaname | tablename | indexname | tablespace +------------+-----------+-----------+------------ +(0 rows) + +-- 6.使用alter index改变复合主键约束的索引表空间为tablespace2 +ALTER INDEX series_pk SET TABLESPACE tablespace2; +ERROR: relation "series_pk" does not exist +-- 7.time字段创建索引,设置series_value索引的表空间为默认表空间 +CREATE INDEX ON series (time) TABLESPACE tablespace1; +ERROR: relation "series" does not exist +ALTER INDEX series_value SET TABLESPACE pg_default; +ERROR: relation "series_value" does not exist +-- 8.插入新数据以创建新的chunk +INSERT INTO series VALUES ('2019-04-29 10:12', 2, 1.31); +ERROR: relation "series" does not exist on datanode1 +LINE 1: INSERT INTO series VALUES ('2019-04-29 10:12', 2, 1.31); + ^ +-- 9.更新索引的表空间后,在当前的表空间tablespace2中创建新的chunk +SELECT schemaname, tablename, indexname, tablespace +FROM pg_indexes +WHERE indexname LIKE '%series%' +ORDER BY indexname; + schemaname | tablename | indexname | tablespace +------------+-----------+-----------+------------ +(0 rows) + +-- 10.清理环境 +DROP TABLE series; +ERROR: table "series" does not exist +DROP TABLESPACE tablespace1; +ERROR: Tablespace "tablespace1" does not exist. +DROP TABLESPACE tablespace2; +ERROR: Tablespace "tablespace2" does not exist. +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/InvalidFunctionAddPartitionFail.out b/contrib/timescaledb/regress/expected/InvalidFunctionAddPartitionFail.out new file mode 100644 index 000000000..6735d3240 --- /dev/null +++ b/contrib/timescaledb/regress/expected/InvalidFunctionAddPartitionFail.out @@ -0,0 +1,59 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +ERROR: Invalid username/password,set role denied. +CREATE OR REPLACE FUNCTION invalid_partfunc(source integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN NULL; +END +$BODY$; +CREATE OR REPLACE FUNCTION time_partfunc(source text) + RETURNS TIMESTAMPTZ LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN timezone('UTC', to_timestamp(source)); +END +$BODY$; +-- 2.创建超表 +drop table if exists test_schema.test_invalid_func; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.test_invalid_func(time timestamptz, temp float8, device text); +ERROR: schema "test_schema" does not exist +SELECT create_hypertable('test_schema.test_invalid_func', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('test_schema.test_invalid_func', 't... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 3.增加分区维度使用无效的自定义函数 +SELECT add_dimension('test_schema.test_invalid_func', 'device', 2, partitioning_func => 'invalid_partfunc'); +ERROR: function add_dimension(unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: SELECT add_dimension('test_schema.test_invalid_func', 'devic... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 4.创建超表 +drop table if exists test_schema.open_dim_part_func; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +ERROR: schema "test_schema" does not exist +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'time_partfunc'); +ERROR: function create_hypertable(unknown, unknown, time_partitioning_func := unknown) does not exist +LINE 1: SELECT create_hypertable('test_schema.open_dim_part_func', '... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 5.使用无效的自定义函数增加分区维度 +SELECT add_dimension('test_schema.open_dim_part_func', 'event_time', chunk_time_interval => interval '1 day', partitioning_func => 'invalid_partfunc'); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := interval, partitioning_func := unknown) does not exist +LINE 1: SELECT add_dimension('test_schema.open_dim_part_func', 'even... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/InvalidFunctionHypertableCreationFail.out b/contrib/timescaledb/regress/expected/InvalidFunctionHypertableCreationFail.out new file mode 100644 index 000000000..98055000c --- /dev/null +++ b/contrib/timescaledb/regress/expected/InvalidFunctionHypertableCreationFail.out @@ -0,0 +1,38 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +ERROR: Invalid username/password,set role denied. +CREATE OR REPLACE FUNCTION invalid_partfunc(source integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN NULL; +END +$BODY$; +-- 2.分区为时间、文本类型使用无效的自定义函数 +drop table if exists test_schema.test_invalid_func; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.test_invalid_func(time timestamptz, temp float8, device text); +ERROR: schema "test_schema" does not exist +SELECT create_hypertable('test_schema.test_invalid_func', 'time', 'device', 2, partitioning_func => 'invalid_partfunc'); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: SELECT create_hypertable('test_schema.test_invalid_func', 't... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 3.分区为文本类型使用自定义函数 +drop table if exists test_schema.open_dim_part_func; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +ERROR: schema "test_schema" does not exist +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'invalid_partfunc'); +ERROR: function create_hypertable(unknown, unknown, time_partitioning_func := unknown) does not exist +LINE 1: SELECT create_hypertable('test_schema.open_dim_part_func', '... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/InvalidPartitionFunctionFailure.out b/contrib/timescaledb/regress/expected/InvalidPartitionFunctionFailure.out new file mode 100644 index 000000000..45094add6 --- /dev/null +++ b/contrib/timescaledb/regress/expected/InvalidPartitionFunctionFailure.out @@ -0,0 +1,77 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.使用role1登入数据库 +\c test1 +alter role lhy1 login; +-- \c test_speed7 role1; +-- 2.从role2角色中收回role1角色的权限 +revoke lhy1 from lhy2; +WARNING: role "lhy2" is not a member of role "lhy1" +-- 3.创建自定义分区函数 +CREATE OR REPLACE FUNCTION partfunc_not_immutable(source anyelement) + RETURNS INTEGER LANGUAGE PLPGSQL AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_not_immutable" near line 3 +CREATE OR REPLACE FUNCTION partfunc_bad_return_type(source anyelement) + RETURNS BIGINT LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_bad_return_type" near line 3 +CREATE OR REPLACE FUNCTION partfunc_bad_arg_type(source text) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_bad_arg_type" near line 3 +CREATE OR REPLACE FUNCTION partfunc_bad_multi_arg(source anyelement, extra_arg integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: compilation of PL/pgSQL function "partfunc_bad_multi_arg" near line 3 +-- 4.创建普通表 +create table test_schema.test_partfunc(time timestamptz, temp float, device int); +ERROR: schema "test_schema" does not exist +-- 5.自定义分区功能函数无效导致创建超表失败 +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_not_immutable'); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_partfunc', 'time'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_bad_return_type'); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_partfunc', 'time'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_bad_arg_type'); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_partfunc', 'time'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_bad_multi_arg'); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, partitioning_func := unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_partfunc', 'time'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/MultipleHypertablesRenameSuccess.out b/contrib/timescaledb/regress/expected/MultipleHypertablesRenameSuccess.out new file mode 100644 index 000000000..7d36dc715 --- /dev/null +++ b/contrib/timescaledb/regress/expected/MultipleHypertablesRenameSuccess.out @@ -0,0 +1,48 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.自定义模式名创建超表 +\c test1 lhy; +CREATE SCHEMA IF NOT EXISTS original_name; +CREATE TABLE original_name.my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +CREATE TABLE original_name.my_table2 ( + date timestamp with time zone NOT NULL, + quantity double precision +); +CREATE TABLE regular_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('original_name.my_table','date'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('original_name.my_table','date'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +SELECT create_hypertable('original_name.my_table2','date'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('original_name.my_table2','date'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +SELECT create_hypertable('regular_table','date'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('regular_table','date'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据并更改超表的模式名 +INSERT INTO original_name.my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +INSERT INTO original_name.my_table2 (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +INSERT INTO regular_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +ALTER SCHEMA original_name RENAME TO new_name; +-- 3.清理环境 +DROP TABLE new_name.my_table; +DROP TABLE new_name.my_table2; +DROP TABLE regular_table; +DROP SCHEMA new_name; +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/PartitionCountChangeError.out b/contrib/timescaledb/regress/expected/PartitionCountChangeError.out new file mode 100644 index 000000000..9925f2c8e --- /dev/null +++ b/contrib/timescaledb/regress/expected/PartitionCountChangeError.out @@ -0,0 +1,44 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 4... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 3.未指明要更改的分区数量,合理报错 +SELECT set_number_partitions('test_schema.test_table', 1); +ERROR: function set_number_partitions(unknown, integer) does not exist +LINE 1: SELECT set_number_partitions('test_schema.test_table', 1); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_number_partitions +-- 4.分区数量边界值测试,合理报错 +SELECT set_number_partitions('test_schema.test_table', 0, 'location'); +ERROR: function set_number_partitions(unknown, integer, unknown) does not exist +LINE 1: SELECT set_number_partitions('test_schema.test_table', 0, 'l... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_number_partitions +SELECT set_number_partitions('test_schema.test_table', 32768, 'location'); +ERROR: function set_number_partitions(unknown, integer, unknown) does not exist +LINE 1: SELECT set_number_partitions('test_schema.test_table', 32768... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_number_partitions +-- 5.get_create_command仅支持最多2个分区维度超级表,多维合理报错 + SELECT * FROM _timescaledb_internal.get_create_command('test_table'); +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/PartitionCountChangeSuccess.out b/contrib/timescaledb/regress/expected/PartitionCountChangeSuccess.out new file mode 100644 index 000000000..58be35403 --- /dev/null +++ b/contrib/timescaledb/regress/expected/PartitionCountChangeSuccess.out @@ -0,0 +1,52 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.更改超表的分区数量为1,合理报错 +SELECT set_number_partitions('test_schema.test_table', 1, 'location'); +ERROR: function set_number_partitions(unknown, integer, unknown) does not exist +LINE 1: SELECT set_number_partitions('test_schema.test_table', 1, 'l... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_number_partitions +-- 3.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 4... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 4.更改超表的分区数量为1 +SELECT set_number_partitions('test_schema.test_table', 1, 'location'); +ERROR: function set_number_partitions(unknown, integer, unknown) does not exist +LINE 1: SELECT set_number_partitions('test_schema.test_table', 1, 'l... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_number_partitions +-- 5.查看超表的分区信息 +select * from _timescaledb_catalog.dimension WHERE column_name = 'location'; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.dimension WHERE column_na... + ^ +-- 6.更改超表的分区数量为2 +SELECT set_number_partitions('test_schema.test_table', 2, 'location'); +ERROR: function set_number_partitions(unknown, integer, unknown) does not exist +LINE 1: SELECT set_number_partitions('test_schema.test_table', 2, 'l... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_number_partitions +-- 7.查看超表的分区信息 +select * from _timescaledb_catalog.dimension WHERE column_name = 'location'; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.dimension WHERE column_na... + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/PartitionDimensionAddSuccess.out b/contrib/timescaledb/regress/expected/PartitionDimensionAddSuccess.out new file mode 100644 index 000000000..e5734325c --- /dev/null +++ b/contrib/timescaledb/regress/expected/PartitionDimensionAddSuccess.out @@ -0,0 +1,31 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 4... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 3.查看超表信息 +select * from _timescaledb_catalog.hypertable where table_name = 'test_table'; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.hypertable where table_na... + ^ +-- 4.查看超表的分区维度信息 +select * from _timescaledb_catalog.dimension; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.dimension; + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/PluginSchemaRenameErrorHandling.out b/contrib/timescaledb/regress/expected/PluginSchemaRenameErrorHandling.out new file mode 100644 index 000000000..40c49f578 --- /dev/null +++ b/contrib/timescaledb/regress/expected/PluginSchemaRenameErrorHandling.out @@ -0,0 +1,15 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.重命名插件引入schema +\c test1 lhy; +ALTER SCHEMA _timescaledb_internal RENAME TO my_new_schema_name; +ERROR: schema "_timescaledb_internal" does not exist +ALTER SCHEMA _timescaledb_catalog RENAME TO my_new_schema_name; +ERROR: schema "_timescaledb_catalog" does not exist +ALTER SCHEMA _timescaledb_cache RENAME TO my_new_schema_name; +ERROR: schema "_timescaledb_cache" does not exist +ALTER SCHEMA _timescaledb_config RENAME TO my_new_schema_name; +ERROR: schema "_timescaledb_config" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/RoleInheritanceInsertTest.out b/contrib/timescaledb/regress/expected/RoleInheritanceInsertTest.out new file mode 100644 index 000000000..ce49b5600 --- /dev/null +++ b/contrib/timescaledb/regress/expected/RoleInheritanceInsertTest.out @@ -0,0 +1,28 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_table_no_not_null(time BIGINT, device_id text); +ERROR: schema "test_schema" does not exist +-- 2.将会话恢复为原有权限 +RESET ROLE; +-- 3.role2继承role1权限并切换至role2角色 +grant lhy1 to lhy2; +set role lhy2 password 'Test@123'; +-- 4.在role2创建超表 + select * from create_hypertable('test_schema.test_table_no_not_null', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month')); +ERROR: schema "_timescaledb_internal" does not exist +-- 5.验证时间列time为空插入数据合理报错 +insert into test_schema.test_table_no_not_null (device_id) VALUES('foo'); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_table_no_not_null (device_id) V... + ^ +-- 6.验证时间列time不为空插入数据成功 +insert into test_schema.test_table_no_not_null (time, device_id) VALUES(1, 'foo'); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_table_no_not_null (time, device... + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/RoleSchemaHypertableFail.out b/contrib/timescaledb/regress/expected/RoleSchemaHypertableFail.out new file mode 100644 index 000000000..d9e002ce2 --- /dev/null +++ b/contrib/timescaledb/regress/expected/RoleSchemaHypertableFail.out @@ -0,0 +1,15 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.将会话恢复为原有权限 +\c test1 +RESET ROLE; +-- 2.在role1下创建普通表 +set role lhy1 password 'Test@123'; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +-- 3.创建超表 +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/RoleSchemaPermHypertableSuccess.out b/contrib/timescaledb/regress/expected/RoleSchemaPermHypertableSuccess.out new file mode 100644 index 000000000..1635ac6e1 --- /dev/null +++ b/contrib/timescaledb/regress/expected/RoleSchemaPermHypertableSuccess.out @@ -0,0 +1,19 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +-- 2.将会话恢复为原有权限 +RESET ROLE; +-- 3.赋值role2的chunk_schema权限给role1 +GRANT CREATE ON SCHEMA chunk_schema TO lhy1; +ERROR: schema "chunk_schema" does not exist +-- 4.切换至role1创建超表 +set role lhy1 password 'Test@123'; +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/SchemaDeletionCascadeHypertables.out b/contrib/timescaledb/regress/expected/SchemaDeletionCascadeHypertables.out new file mode 100644 index 000000000..69eeb2079 --- /dev/null +++ b/contrib/timescaledb/regress/expected/SchemaDeletionCascadeHypertables.out @@ -0,0 +1,44 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 lhy; +CREATE SCHEMA IF NOT EXISTS original_name; +CREATE TABLE original_name.my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +CREATE TABLE original_name.my_table2 ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('original_name.my_table','date'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('original_name.my_table','date'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +SELECT create_hypertable('original_name.my_table2','date'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('original_name.my_table2','date'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据 +INSERT INTO original_name.my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +INSERT INTO original_name.my_table2 (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +-- 3.更改模式名后删除修改后的模式名 +ALTER SCHEMA original_name RENAME TO new_name; +DROP SCHEMA new_name CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table new_name.my_table +drop cascades to table new_name.my_table2 +-- 4.查看超表是否存在 +\dt new_name.*; + List of relations + Schema | Name | Type | Owner | Storage +--------+------+------+-------+--------- +(0 rows) + +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/SchemaPermRoleHypertableFail.out b/contrib/timescaledb/regress/expected/SchemaPermRoleHypertableFail.out new file mode 100644 index 000000000..d4105a75b --- /dev/null +++ b/contrib/timescaledb/regress/expected/SchemaPermRoleHypertableFail.out @@ -0,0 +1,17 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_table_no_not_null(time BIGINT, device_id text); +ERROR: schema "test_schema" does not exist +-- 2.在role1角色下给role2赋test_schmea的所有权限 +GRANT ALL ON SCHEMA test_schema TO lhy2; +ERROR: schema "test_schema" does not exist +-- 3.切换角色到role2创建超表 +set role lhy2 password 'Test@123'; + select * from create_hypertable('test_schema.test_table_no_not_null', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month')); +ERROR: schema "_timescaledb_internal" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/SetIntegerNowFuncTest.out b/contrib/timescaledb/regress/expected/SetIntegerNowFuncTest.out new file mode 100644 index 000000000..942a8406e --- /dev/null +++ b/contrib/timescaledb/regress/expected/SetIntegerNowFuncTest.out @@ -0,0 +1,94 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.role1角色登入pg兼容库test1 +alter role lhy1 login; +\c test1 lhy1 +-- 2.创建超表并返回超表ID +drop table if exists test_table_int; +NOTICE: table "test_table_int" does not exist, skipping +CREATE TABLE test_table_int(time bigint, junk int); +SELECT hypertable_id AS "TEST_TABLE_INT_HYPERTABLE_ID" FROM create_hypertable('test_table_int', 'time', chunk_time_interval => 1); +ERROR: function create_hypertable(unknown, unknown, chunk_time_interval := integer) does not exist +LINE 1: ...ertable_id AS "TEST_TABLE_INT_HYPERTABLE_ID" FROM create_hyp... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +-- 3.og初始用户role登入该兼容库test1 +\c test1 lhy1 +-- 4.创建函数及模式名并进行赋权 +CREATE SCHEMA IF NOT EXISTS my_schema; +ERROR: permission denied for database test1 +DETAIL: N/A +create or replace function my_schema.dummy_now2() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +WARNING: schema not defined, it may cause duplicate data. +DETAIL: schema not exists. +ERROR: schema "my_schema" does not exist +grant execute on ALL FUNCTIONS IN SCHEMA my_schema to public; +ERROR: schema "my_schema" does not exist +create or replace function dummy_now3() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +grant execute on ALL FUNCTIONS IN SCHEMA my_schema to public; +ERROR: schema "my_schema" does not exist +REVOKE execute ON function dummy_now3() FROM PUBLIC; +CREATE SCHEMA IF NOT EXISTS my_user_schema; +ERROR: permission denied for database test1 +DETAIL: N/A +GRANT ALL ON SCHEMA my_user_schema to PUBLIC; +ERROR: schema "my_user_schema" does not exist +-- 5.role1角色登入pg兼容库test1,创建函数 +\c test1 lhy1 +create or replace function dummy_now() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +create or replace function my_user_schema.dummy_now4() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +WARNING: schema not defined, it may cause duplicate data. +DETAIL: schema not exists. +ERROR: schema "my_user_schema" does not exist +-- 6.设置整数类超表当前时间函数,查看超表分区信息 +select set_integer_now_func('test_table_int', 'dummy_now'); +ERROR: function set_integer_now_func(unknown, unknown) does not exist +LINE 1: select set_integer_now_func('test_table_int', 'dummy_now'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_integer_now_func +select * from _timescaledb_catalog.dimension WHERE hypertable_id = 88; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.dimension WHERE hypertabl... + ^ +-- 7.重复设置整数类超表当前时间函数 +select set_integer_now_func('test_table_int', 'dummy_now'); +ERROR: function set_integer_now_func(unknown, unknown) does not exist +LINE 1: select set_integer_now_func('test_table_int', 'dummy_now'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_integer_now_func +-- 8.当前用户无权限,设置整数类超表当前时间函数 +select set_integer_now_func('test_table_int', 'my_schema.dummy_now2', replace_if_exists => TRUE); +ERROR: function set_integer_now_func(unknown, unknown, replace_if_exists := boolean) does not exist +LINE 1: select set_integer_now_func('test_table_int', 'my_schema.dum... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_integer_now_func +select set_integer_now_func('test_table_int', 'dummy_now3', replace_if_exists => TRUE); +ERROR: function set_integer_now_func(unknown, unknown, replace_if_exists := boolean) does not exist +LINE 1: select set_integer_now_func('test_table_int', 'dummy_now3', ... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_integer_now_func +-- 9.设置整数类超表指定replace_if_exists参数为true +select set_integer_now_func('test_table_int', 'my_user_schema.dummy_now4', replace_if_exists => TRUE); +ERROR: function set_integer_now_func(unknown, unknown, replace_if_exists := boolean) does not exist +LINE 1: select set_integer_now_func('test_table_int', 'my_user_schem... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: set_integer_now_func +10.再次通过og初始用户role登入pg兼容库 +\c test1 lhy +-- 11.查看超表分区信息 +ALTER SCHEMA my_user_schema RENAME TO my_new_schema; +ERROR: syntax error at or near "10." +LINE 1: 10.再次通过og初始用户role登入pg兼容库 + ^ +select * from _timescaledb_catalog.dimension WHERE hypertable_id = 88; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.dimension WHERE hypertabl... + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ShowBlocksInSchema.out b/contrib/timescaledb/regress/expected/ShowBlocksInSchema.out new file mode 100644 index 000000000..336cb3da8 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ShowBlocksInSchema.out @@ -0,0 +1,26 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.插入数据 +insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_table values (123456789, 23.8, ... + ^ +-- 3.查看关联模式的chunk + \dt "chunk_schema".* + List of relations + Schema | Name | Type | Owner | Storage +--------+------+------+-------+--------- +(0 rows) + +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/TableDataMigrateSuccess.out b/contrib/timescaledb/regress/expected/TableDataMigrateSuccess.out new file mode 100644 index 000000000..ff172ed01 --- /dev/null +++ b/contrib/timescaledb/regress/expected/TableDataMigrateSuccess.out @@ -0,0 +1,27 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建表并插入数据 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +create table test_schema.test_migrate(time timestamp, temp float); +ERROR: schema "test_schema" does not exist +insert into test_schema.test_migrate VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_migrate VALUES ('2004-10-19 10:... + ^ +select * from only test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +LINE 1: select * from only test_schema.test_migrate; + ^ +-- 2.转换为超表 +select create_hypertable('test_schema.test_migrate', 'time', migrate_data => true); +ERROR: function create_hypertable(unknown, unknown, migrate_data := boolean) does not exist +LINE 1: select create_hypertable('test_schema.test_migrate', 'time',... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/TableDataNoMigrateError.out b/contrib/timescaledb/regress/expected/TableDataNoMigrateError.out new file mode 100644 index 000000000..8b2571dc7 --- /dev/null +++ b/contrib/timescaledb/regress/expected/TableDataNoMigrateError.out @@ -0,0 +1,27 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建表并插入数据 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +create table test_schema.test_migrate(time timestamp, temp float); +ERROR: schema "test_schema" does not exist +insert into test_schema.test_migrate VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_migrate VALUES ('2004-10-19 10:... + ^ +select * from only test_schema.test_migrate; +ERROR: schema "test_schema" does not exist +LINE 1: select * from only test_schema.test_migrate; + ^ +-- 2.转换为超表 +select create_hypertable('test_schema.test_migrate', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_migrate', 'time')... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/TablespaceFunctionHandling.out b/contrib/timescaledb/regress/expected/TablespaceFunctionHandling.out new file mode 100644 index 000000000..1feaf85eb --- /dev/null +++ b/contrib/timescaledb/regress/expected/TablespaceFunctionHandling.out @@ -0,0 +1,118 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建普通表并转换为超表 +\c test1 lhy; +SET client_min_messages = ERROR; +drop table if exists hyper_in_space cascade; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLE hyper_in_space(time bigint, temp float, device int) TABLESPACE tablespace1; +ERROR: tablespace "tablespace1" does not exist +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, chunk_time_interval := integer) does not exist +LINE 1: SELECT create_hypertable('hyper_in_space', 'time', 'device',... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23... + ^ +-- 3.detach_tablespace分离超表的表空间tablespace1 +SELECT detach_tablespace('tablespace1', 'hyper_in_space'); +ERROR: function detach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT detach_tablespace('tablespace1', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: detach_tablespace +-- 4.再次插入数据 +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (7, 23, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (7, 23... + ^ +-- 5.attach_tablespace在超表添加默认表空间与tablespace2 +SELECT attach_tablespace('pg_default', 'hyper_in_space'); +ERROR: function attach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT attach_tablespace('pg_default', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: attach_tablespace +SELECT attach_tablespace('tablespace2', 'hyper_in_space'); +ERROR: function attach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT attach_tablespace('tablespace2', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: attach_tablespace +-- 6.查看超表hyper_in_space、超表的chunk的表空间 +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + tablename | tablespace +-----------+------------ +(0 rows) + +-- 7.系统表_timescaledb_catalog.tablespace查看超表的表空间 +SELECT * FROM _timescaledb_catalog.tablespace; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.tablespace; + ^ +-- 8.再次插入数据后查看超表hyper_in_space、chunk的表空间 +INSERT INTO hyper_in_space(time, temp, device) VALUES (12, 22, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (12, 2... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (13, 23, 2); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (13, 2... + ^ +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + tablename | tablespace +-----------+------------ +(0 rows) + +-- 9.分离超表的默认表空间 +SELECT detach_tablespace('pg_default', 'hyper_in_space'); +ERROR: function detach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT detach_tablespace('pg_default', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: detach_tablespace +-- 10.通过alter table设置超表的表空间为默认表空间并通过pg_tables表查看超表及子表的表空间 +ALTER TABLE hyper_in_space SET TABLESPACE pg_default; +ERROR: relation "hyper_in_space" does not exist +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + tablename | tablespace +-----------+------------ +(0 rows) + +-- 11.分离超表hyper_in_space的默认表空间并删除超表 +SELECT detach_tablespace('pg_default', 'hyper_in_space'); +ERROR: function detach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT detach_tablespace('pg_default', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: detach_tablespace +DROP TABLE hyper_in_space; +ERROR: table "hyper_in_space" does not exist +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/TablespaceToHypertable.out b/contrib/timescaledb/regress/expected/TablespaceToHypertable.out new file mode 100644 index 000000000..64ac5e34e --- /dev/null +++ b/contrib/timescaledb/regress/expected/TablespaceToHypertable.out @@ -0,0 +1,63 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建普通表并转换为超表 +\c test1 lhy; +SET client_min_messages = ERROR; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +ERROR: directory "/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2/PG_9.2_201611171_datanode1" already in use as a tablespace +CREATE TABLE hyper_in_space(time bigint, temp float, device int) TABLESPACE tablespace1; +ERROR: tablespace "tablespace1" does not exist +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); +ERROR: function create_hypertable(unknown, unknown, unknown, integer, chunk_time_interval := integer) does not exist +LINE 1: SELECT create_hypertable('hyper_in_space', 'time', 'device',... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.插入数据后查看表空间下的表信息 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21... + ^ +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +ERROR: relation "hyper_in_space" does not exist on datanode1 +LINE 1: INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23... + ^ +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + tablename | tablespace +-----------+------------ +(0 rows) + +-- 3.超表hyper_in_space附加到tablespace2表空间 +SELECT attach_tablespace('tablespace2', 'hyper_in_space'); +ERROR: function attach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT attach_tablespace('tablespace2', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: attach_tablespace +-- 4.超表附加的表空间大于1个时,设置超表的表空间 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; +ERROR: relation "hyper_in_space" does not exist +-- 5.分离超表的表空间 +SELECT detach_tablespace('tablespace2', 'hyper_in_space'); +ERROR: function detach_tablespace(unknown, unknown) does not exist +LINE 1: SELECT detach_tablespace('tablespace2', 'hyper_in_space'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: detach_tablespace +SELECT * FROM _timescaledb_catalog.tablespace; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: SELECT * FROM _timescaledb_catalog.tablespace; + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/TestAddMultipleDimensions.out b/contrib/timescaledb/regress/expected/TestAddMultipleDimensions.out new file mode 100644 index 000000000..cbe6e4f6a --- /dev/null +++ b/contrib/timescaledb/regress/expected/TestAddMultipleDimensions.out @@ -0,0 +1,37 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 4... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 3.再次添加分区维度 +select add_dimension('test_schema.test_table', 'id', chunk_time_interval => 1000); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'id', chunk_t... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 4.查看超表信息及分区维度信息 +select * from _timescaledb_catalog.hypertable where table_name = 'test_table'; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.hypertable where table_na... + ^ +select * from _timescaledb_catalog.dimension; +ERROR: schema "_timescaledb_catalog" does not exist +LINE 1: select * from _timescaledb_catalog.dimension; + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/TestTimeDimensionPartition.out b/contrib/timescaledb/regress/expected/TestTimeDimensionPartition.out new file mode 100644 index 000000000..b7e0092e6 --- /dev/null +++ b/contrib/timescaledb/regress/expected/TestTimeDimensionPartition.out @@ -0,0 +1,33 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_1dim(time timestamp, temp float); +ERROR: schema "test_schema" does not exist +select create_hypertable('test_schema.test_1dim', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: select create_hypertable('test_schema.test_1dim', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.查看超表创建信息 +SELECT * FROM _timescaledb_internal.get_create_command('test_1dim'); +ERROR: schema "_timescaledb_internal" does not exist +-- 3.查看test_schema模式下的表 +\dt "test_schema".* + List of relations + Schema | Name | Type | Owner | Storage +--------+------+------+-------+--------- +(0 rows) + +-- 4.指定if_not_exists为true再次创建超表 +select create_hypertable('test_schema.test_1dim', 'time', if_not_exists => true); +ERROR: function create_hypertable(unknown, unknown, if_not_exists := boolean) does not exist +LINE 1: select create_hypertable('test_schema.test_1dim', 'time', if... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidFunctionAddPartitionSuccess.out b/contrib/timescaledb/regress/expected/ValidFunctionAddPartitionSuccess.out new file mode 100755 index 000000000..289932be8 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidFunctionAddPartitionSuccess.out @@ -0,0 +1,34 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +ERROR: Invalid username/password,set role denied. +CREATE OR REPLACE FUNCTION time_partfunc(source text) + RETURNS TIMESTAMPTZ LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN timezone('UTC', to_timestamp(source)); +END +$BODY$; +-- 2.使用自定义函数创建超表 +drop table if exists test_schema.open_dim_part_func; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +ERROR: schema "test_schema" does not exist +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'time_partfunc'); +ERROR: function create_hypertable(unknown, unknown, time_partitioning_func := unknown) does not exist +LINE 1: SELECT create_hypertable('test_schema.open_dim_part_func', '... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 3.新增超表的分区维度 +SELECT add_dimension('test_schema.open_dim_part_func', 'event_time', chunk_time_interval => interval '1 day', partitioning_func => 'time_partfunc'); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := interval, partitioning_func := unknown) does not exist +LINE 1: SELECT add_dimension('test_schema.open_dim_part_func', 'even... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidFunctionHypertableCreationSuccess.out b/contrib/timescaledb/regress/expected/ValidFunctionHypertableCreationSuccess.out new file mode 100755 index 000000000..b2d9242fd --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidFunctionHypertableCreationSuccess.out @@ -0,0 +1,27 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +ERROR: Invalid username/password,set role denied. +CREATE OR REPLACE FUNCTION time_partfunc(source text) + RETURNS TIMESTAMPTZ LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN timezone('UTC', to_timestamp(source)); +END +$BODY$; +-- 2.使用自定义函数创建超表 +drop table if exists test_schema.open_dim_part_func; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +ERROR: schema "test_schema" does not exist +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'time_partfunc'); +ERROR: function create_hypertable(unknown, unknown, time_partitioning_func := unknown) does not exist +LINE 1: SELECT create_hypertable('test_schema.open_dim_part_func', '... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateAddBigIntDimension.out b/contrib/timescaledb/regress/expected/ValidateAddBigIntDimension.out new file mode 100644 index 000000000..64418414a --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateAddBigIntDimension.out @@ -0,0 +1,39 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy password 'Test@123'; +ERROR: Invalid username/password,set role denied. +drop table if exists dim_test_time; +NOTICE: table "dim_test_time" does not exist, skipping +CREATE TABLE dim_test_time(time TIMESTAMPTZ, time2 TIMESTAMPTZ, time3 BIGINT, temp float8, device int, location int); +SELECT create_hypertable('dim_test_time', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('dim_test_time', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.使用时间间隔方式,新增bigint作为分区维度,合理报错 +SELECT add_dimension('dim_test_time', 'time3', chunk_time_interval => INTERVAL '1 day'); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := interval) does not exist +LINE 1: SELECT add_dimension('dim_test_time', 'time3', chunk_time_in... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 3.使用字符串,新增bigint作为分区维度,合理报错 +SELECT add_dimension('dim_test_time', 'time3', chunk_time_interval => 'foo'::TEXT); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := text) does not exist +LINE 1: SELECT add_dimension('dim_test_time', 'time3', chunk_time_in... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 4.使用显式新增分区维度成功 +SELECT add_dimension('dim_test_time', 'time3', chunk_time_interval => 500); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := integer) does not exist +LINE 1: SELECT add_dimension('dim_test_time', 'time3', chunk_time_in... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateAddDimensionExplicitType.out b/contrib/timescaledb/regress/expected/ValidateAddDimensionExplicitType.out new file mode 100644 index 000000000..c018fd063 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateAddDimensionExplicitType.out @@ -0,0 +1,21 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +CREATE TABLE dim_test_time2(time TIMESTAMPTZ, time2 TIMESTAMPTZ, temp float8, device int, location int); +SELECT create_hypertable('dim_test_time2', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('dim_test_time2', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.add_dimension为TIMESTAMPTZ列使用显式类型 +SELECT add_dimension('dim_test_time2', 'time2', chunk_time_interval => 500); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := integer) does not exist +LINE 1: SELECT add_dimension('dim_test_time2', 'time2', chunk_time_i... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateAddDimensionIfNotExists.out b/contrib/timescaledb/regress/expected/ValidateAddDimensionIfNotExists.out new file mode 100644 index 000000000..8f8fc589f --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateAddDimensionIfNotExists.out @@ -0,0 +1,29 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +drop table if exists dim_test_time2; +CREATE TABLE dim_test_time2(time TIMESTAMPTZ, time2 TIMESTAMPTZ, temp float8, device int, location int); +SELECT create_hypertable('dim_test_time2', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('dim_test_time2', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.add_dimension为TIMESTAMPTZ列使用显式类型 +SELECT add_dimension('dim_test_time2', 'time2', chunk_time_interval => 500); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := integer) does not exist +LINE 1: SELECT add_dimension('dim_test_time2', 'time2', chunk_time_i... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 3.指定if_not_exists为true重复添加分区维度给出提示信息 +SELECT add_dimension('dim_test_time2', 'time2', chunk_time_interval => 500, if_not_exists => true); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := integer, if_not_exists := boolean) does not exist +LINE 1: SELECT add_dimension('dim_test_time2', 'time2', chunk_time_i... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateAddDimensionWithInterval.out b/contrib/timescaledb/regress/expected/ValidateAddDimensionWithInterval.out new file mode 100644 index 000000000..e02a35467 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateAddDimensionWithInterval.out @@ -0,0 +1,25 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +set role lhy password 'Test@123'; +ERROR: Invalid username/password,set role denied. +CREATE TABLE dim_test_time(time TIMESTAMPTZ, time2 TIMESTAMPTZ, time3 BIGINT, temp float8, device int, location int); +ERROR: relation "dim_test_time" already exists in schema "public" +DETAIL: creating new table with existing name in the same schema +SELECT create_hypertable('dim_test_time', 'time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('dim_test_time', 'time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 2.使用时间间隔创建分区维度 +SELECT add_dimension('dim_test_time', 'time2', chunk_time_interval => INTERVAL '1 day'); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := interval) does not exist +LINE 1: SELECT add_dimension('dim_test_time', 'time2', chunk_time_in... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateConflictingPartitionParamsError.out b/contrib/timescaledb/regress/expected/ValidateConflictingPartitionParamsError.out new file mode 100644 index 000000000..57fea14ac --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateConflictingPartitionParamsError.out @@ -0,0 +1,20 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.同时指定number_partitions、chunk_time_interval参数添加分区维度 +select add_dimension('test_schema.test_table', 'id2', number_partitions => 2, chunk_time_interval => 1000); +ERROR: function add_dimension(unknown, unknown, number_partitions := integer, chunk_time_interval := integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'id2', number... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateCreateCommand.out b/contrib/timescaledb/regress/expected/ValidateCreateCommand.out new file mode 100644 index 000000000..26f5bcf37 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateCreateCommand.out @@ -0,0 +1,45 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建test.execute_sql测试函数 +\c test1 lhy +CREATE SCHEMA IF NOT EXISTS test; +NOTICE: schema "test" already exists,skipping +GRANT USAGE ON SCHEMA test TO PUBLIC; +CREATE OR REPLACE FUNCTION test.execute_sql(cmd TEXT) +RETURNS TEXT LANGUAGE PLPGSQL AS $BODY$ +BEGIN + EXECUTE cmd; + RETURN cmd; +END +$BODY$; +-- 2.创建超表 +set role lhy1 password 'Test@123'; +DROP TABLE if exists test_schema.test_sql_cmd CASCADE; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.test_sql_cmd(time TIMESTAMPTZ, temp FLOAT8, device_id TEXT, device_type TEXT, location TEXT, id INT, id2 INT); +ERROR: schema "test_schema" does not exist +SELECT create_hypertable('test_schema.test_sql_cmd','time'); +ERROR: function create_hypertable(unknown, unknown) does not exist +LINE 1: SELECT create_hypertable('test_schema.test_sql_cmd','time'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: create_hypertable +-- 3.验证get_create_command命令 +SELECT * FROM _timescaledb_internal.get_create_command('test_sql_cmd'); +ERROR: schema "_timescaledb_internal" does not exist +SELECT _timescaledb_internal.get_create_command('test_sql_cmd') AS create_cmd; +ERROR: schema "_timescaledb_internal" does not exist +CONTEXT: referenced column: create_cmd +-- 4.删除超表,创建普通表 +DROP TABLE test_schema.test_sql_cmd CASCADE; +ERROR: schema "test_schema" does not exist +CREATE TABLE test_schema.test_sql_cmd(time TIMESTAMPTZ, temp FLOAT8, device_id TEXT, device_type TEXT, location TEXT, id INT, id2 INT); +ERROR: schema "test_schema" does not exist +-- 5.test.execute_sql测试函数验证 +SELECT test.execute_sql(:'create_cmd'); +ERROR: syntax error at or near ":" +LINE 1: SELECT test.execute_sql(:'create_cmd'); + ^ +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateDataExistsDimensionError.out b/contrib/timescaledb/regress/expected/ValidateDataExistsDimensionError.out new file mode 100644 index 000000000..7f98a08a9 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateDataExistsDimensionError.out @@ -0,0 +1,46 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.新增分区维度 +select add_dimension('test_schema.test_table', 'location', 2); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 2... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 3.插入数据 +insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1); +ERROR: schema "test_schema" does not exist +LINE 1: insert into test_schema.test_table values (123456789, 23.8, ... + ^ +-- 4.添加分区维度 +select add_dimension('test_schema.test_table', 'device_type', 2); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'device_type'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 5.if_not_exists参数设置为true添加分区维度 +select add_dimension('test_schema.test_table', 'device_type', 2, if_not_exists => true); +ERROR: function add_dimension(unknown, unknown, integer, if_not_exists := boolean) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'device_type'... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +-- 6.if_not_exists参数设置为true,添加已有分区维度 +select add_dimension('test_schema.test_table', 'location', 2, if_not_exists => true); +ERROR: function add_dimension(unknown, unknown, integer, if_not_exists := boolean) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 2... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateDuplicateDimensionError.out b/contrib/timescaledb/regress/expected/ValidateDuplicateDimensionError.out new file mode 100644 index 000000000..547a900a7 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateDuplicateDimensionError.out @@ -0,0 +1,26 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.重复增加分区维度 +select add_dimension('test_schema.test_table', 'location', 2); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 2... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +select add_dimension('test_schema.test_table', 'location', 2); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: select add_dimension('test_schema.test_table', 'location', 2... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateMissingFieldError.out b/contrib/timescaledb/regress/expected/ValidateMissingFieldError.out new file mode 100644 index 000000000..92ea4dfd7 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateMissingFieldError.out @@ -0,0 +1,20 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +ERROR: schema "test_schema" does not exist +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +ERROR: schema "test_schema" does not exist +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +ERROR: schema "_timescaledb_internal" does not exist +-- 2.超表的列字段不存在,添加分区维度合理报错 +SELECT add_dimension('test_schema.test_table', 'nope', 2); +ERROR: function add_dimension(unknown, unknown, integer) does not exist +LINE 1: SELECT add_dimension('test_schema.test_table', 'nope', 2); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidatePartitionDimensionAddFail.out b/contrib/timescaledb/regress/expected/ValidatePartitionDimensionAddFail.out new file mode 100644 index 000000000..2b1a187af --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidatePartitionDimensionAddFail.out @@ -0,0 +1,15 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.建表 +\c test1 +CREATE TABLE not_hypertable(time TIMESTAMPTZ, temp float8, device int, location int); +-- 2.添加分区维度 +SELECT add_dimension('not_hypertable', 'time', chunk_time_interval => 500); +ERROR: function add_dimension(unknown, unknown, chunk_time_interval := integer) does not exist +LINE 1: SELECT add_dimension('not_hypertable', 'time', chunk_time_in... + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: add_dimension +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/ValidateRegularTableHypertableError.out b/contrib/timescaledb/regress/expected/ValidateRegularTableHypertableError.out new file mode 100644 index 000000000..1899e8da7 --- /dev/null +++ b/contrib/timescaledb/regress/expected/ValidateRegularTableHypertableError.out @@ -0,0 +1,28 @@ +create extension timescaledb; +ERROR: Copy file "$libdir/proc_srclib/ /home/lhy/self_detection/lib/timescaledb-1.7.4" failed: No such file or directory +-- 1.创建role及schema +\c test1 +CREATE ROLE lhy1 IDENTIFIED BY 'Test@123'; +ERROR: role "lhy1" already exists +CREATE ROLE lhy2 IDENTIFIED BY 'Test@123'; +ERROR: role "lhy2" already exists +CREATE SCHEMA test_schema AUTHORIZATION lhy1; +CREATE SCHEMA chunk_schema AUTHORIZATION lhy2; +-- 2.切换至role1 +set role lhy1 password 'Test@123'; +-- 3.创建普通表 +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +-- 4.get_create_command查看非超表合理报错 +SELECT * FROM _timescaledb_internal.get_create_command('test_table'); +ERROR: schema "_timescaledb_internal" does not exist +-- 5.查看模式名test_schema下的表 + \dt "test_schema".* + List of relations + Schema | Name | Type | Owner | Storage +-------------+------------+-------+-------+---------------------------------- + test_schema | test_table | table | lhy1 | {orientation=row,compression=no} +(1 row) + +\c test1 lhy; +drop extension timescaledb cascade; +ERROR: extension "timescaledb" does not exist diff --git a/contrib/timescaledb/regress/expected/lhy1.out b/contrib/timescaledb/regress/expected/lhy1.out new file mode 100755 index 000000000..387c4535d --- /dev/null +++ b/contrib/timescaledb/regress/expected/lhy1.out @@ -0,0 +1,2 @@ +create user lhy1 with password 'Test@123'; +create user lhy2 with password 'Test@123'; diff --git a/contrib/timescaledb/regress/smartmatch.pl b/contrib/timescaledb/regress/smartmatch.pl new file mode 100755 index 000000000..e99dc8113 --- /dev/null +++ b/contrib/timescaledb/regress/smartmatch.pl @@ -0,0 +1,583 @@ +#!/usr/bin/perl + + +# smartmatch: +# +# This script is extracted from Gurjeet Singh ( singh.gurjeet@gmail.com ) NEUROdiff patch. +# +# 04 Apr 2013 : First implementation + +use strict; +use warnings; + +sub usage +{ + print "Usage: smartmatch.pl \n"; + return; +} + +# file handles for expected and results files +my $EXPECTED; +my $RESULT; +my $NEW_EXPECTED; + +my $expected; # line iterator for EXPECTED file +my $result; # line iterator for RESULT file + +my $re; # the Regular Expression part of a line which starts with ? + +my $insideuo; # boolean, representing if we are INSIDE an UnOrdered set of lines + +my $bFirstLine; # Indicates whether the line going to be printed is the first or not + +my $iuo; # counter I for counting lines within an UnOrdered set +my $seenspecialinuo; # Seen special marker inside unordered group +my $smartmatch; # seen any special match syntax + +my $rc = 0; # Return Code + +my @earr = ( [], [] ); # 2-dimensional ARRay to keep Expected file's unmatched lines from an unordered set +my @rarr = ( [], [] ); # 2-dimensional ARRay to keep Result file's unmatched lines from unordered set + +my @searr = ( [], [] ); # 2-dimensional ARRay to keep Expected file's sorted lines from an unordered set +my @srarr = ( [], [] ); # 2-dimensional ARRay to keep Result file's sorted lines from unordered set + +# we require exactly 3 arguments +if( @ARGV != 3 ) +{ + usage(); + exit(2); +} + +# initialize (almost) everything +open $EXPECTED , "<", $ARGV[0] or die $!; +open $RESULT , "<", $ARGV[1] or die $!; +open $NEW_EXPECTED , ">", $ARGV[2] or die $!; + +$insideuo = 0; +$iuo = 0; +$smartmatch = 0; + +$bFirstLine = 1; + +# process all lines from both the files +while( 1 ) +{ + undef $!; + + my $matched = 1; + + $expected = <$EXPECTED>; + + undef $!; + + $result = <$RESULT>; + + + # one file finished but not the other + if( ( !defined( $expected ) || !defined( $result ) ) + && ( defined( $expected ) || defined( $result ) ) ) + { + $rc = 2; + + if( defined( $expected ) ) + { + if( $bFirstLine ) + { + print $NEW_EXPECTED "$expected"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\n$expected"; + } + } + + last; # while( 1 ) + } + + # both files finished + if( !defined( $expected ) && !defined( $result ) ) + { + last; # while( 1 ) + } + + # chomp away... + # Apart from getting rid of extra newlines in messages, this will also help + # us be agnostic about platform specific newline sequences. + # + # Correction: Apparently the above assumption is not true (found the hard + # way :( ). + # If the file was generated on Windows (CRLF), the Linux version of chomp + # will trim only \n and leave \r. Had to use dos2unix on the out files to + # make this script work. + chomp( $expected ); + chomp( $result ); + + # if the line from expected file starts with a ?, treat it specially + if( $expected =~ /^--\?.*/ ) + { + $smartmatch=1; + + # extract the Regular Expression + $re = substr $expected, 3; + + # If this is the beginning of an UnOrdered set of lines + if( $re eq 'unordered: start' ) + { + if( $insideuo ) + { + + if( $bFirstLine ) + { + print $NEW_EXPECTED "Nesting of 'unordered: start' blocks is not allowed"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\nNesting of 'unordered: start' blocks is not allowed"; + } + + exit( 2 ); + } + + # reset the variables for the UO set. + $iuo = 0; + $insideuo = 1; + $seenspecialinuo = 0; + + if( $bFirstLine ) + { + print $NEW_EXPECTED "$expected"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\n$expected"; + } + + next; + } + + # end of an UnOrderd set of lines + if( $re eq 'unordered: end' ) + { + if( !$insideuo ) + { + print $NEW_EXPECTED "'unordered: end' line found without a matching 'unordered: start' line\n"; + exit( 2 ); + } + + $insideuo = 0; + + # If there were some lines containing RE, do comparison the hard way + if( $seenspecialinuo ) + { + # begin the (m*n) processing of the two arrays. These arrays + # contain the set of unmatched lines from respective files + foreach my $eelemref ( @earr ) + { + my $i = 0; + + my $eelem = $eelemref->[0]; + + foreach my $relemref ( @rarr ) + { + my $relem = $relemref->[0]; + + $matched = 1; + + # treat these lines the same as we threat the others; + # that is, if an 'expected' line starts with a '?', we + # perform Regular Expression match, else we perform + # normal comparison. + + if( $eelem =~ /^--\?.*/ ) + { + my $tmpre = substr $eelem, 3; + + if( $relem !~ /^$tmpre$/ ) + { + $matched = 0; + } + else + { + if( $bFirstLine ) + { + print $NEW_EXPECTED "$relem"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\n$relem"; + } + + last; + } + } + elsif( $eelem ne $relem ) + { + $matched = 0; + } + else + { + if( $bFirstLine ) + { + print $NEW_EXPECTED "$relem"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\n$relem"; + } + + last; + } + + ++$i; + } # foreach @rarr + + if( !$matched ) + { + $rc = 2; + if( $bFirstLine ) + { + print $NEW_EXPECTED "$eelem"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\n$eelem"; + } + + } + else + { + splice @rarr, $i, 0; + } + } # foreach @earr + } + else # if there's no line containing an RE in this UO group, + # do it efficiently + { + # sort both arrays based on the text. + @searr = sort { $a->[0] cmp $b->[0] } @earr; + @srarr = sort { $a->[0] cmp $b->[0] } @rarr; + + my $min_len = (scalar(@searr) <= scalar(@srarr) ? scalar(@searr) : scalar(@srarr) ); + my $i; + $matched = 1; + + for( $i = 0; $i < $min_len; ++$i ) + { + my $eelem = $searr[$i][0]; + my $relem = $srarr[$i][0]; + + # treat these lines the same as we threat the others; that is, if an + # 'expected' line starts with a '?', we perform Regular Expression + # match, else we perform normal comparison. + + if( $eelem =~ /^--\?.*/ ) + { + my $tmpre = substr $eelem, 3; + + if( $relem !~ /^$tmpre$/ ) + { + $matched = 0; + } + } + elsif( $eelem ne $relem ) + { + $matched = 0; + } + } + + if ((scalar(@searr) > $i) || (scalar(@srarr) > $i)) + { + $matched = 0; + } + + if ( !$matched ) + { + $rc = 2; + for( my $i = 0; $i < scalar(@earr); ++$i ) + { + if( $bFirstLine ) + { + print $NEW_EXPECTED "$earr[$i][0]"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\n$earr[$i][0]"; + } + } + } + else + { + for( my $i = 0; $i < scalar(@rarr); ++$i ) + { + if( $bFirstLine ) + { + print $NEW_EXPECTED "$rarr[$i][0]"; + $bFirstLine = 0; + } + else + { + print $NEW_EXPECTED "\n$rarr[$i][0]"; + } + } + } + + $matched = 0; + } # else part of if( $seenspecialinuo ) + + if( $bFirstLine ) + { + $bFirstLine = 0; + print $NEW_EXPECTED "$expected"; + } + else + { + print $NEW_EXPECTED "\n$expected"; + } + + # reset the array variables to reclaim memory + @searr = @srarr = (); + @earr = @rarr = (); + + next; # while( 1 ) + + } # if re == 'unordered: end' + + # it is not an 'unordered' marker, so do regular Regular Expression match + else + { + my $re_1; + + if ($result !~ /^$re/) + { + if ($re =~ /(.*)datanode.*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*)\(cost=.*/ ) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*)\(actual time=.*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*)\(CPU:.*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*)\(RoughCheck CU:.*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*)Buffers:.*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /[.*]/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /(.*).*/) + { + $re_1 = quotemeta($1); + if ($result !~ /$re_1.*/) + { + $matched = 0; + } + } + elsif ($re =~ /^\s*Sort\s+Method.*/) + { + if ($result !~ /^\s*Sort\s+Method.*/) + { + $matched = 0; + } + } + + + elsif ($re =~ /Total runtime:.*/) + { + if ($result !~ /^\s*Total runtime:.*/) + { + $matched = 0; + } + } + elsif ($re =~ /^\s*QUERY PLAN\s*$/) + { + if ($result !~ /^\s*QUERY PLAN\s*$/) + { + $matched = 0; + } + } + elsif ($re =~ /^\-+$/) + { + if ($result !~ /^\-+$/) + { + $matched = 0; + } + } + else + { + $matched = 0; + } + } + } + + } # if $expected like ?.* + + # $expected doesn't begin with the special marker, so do normal comparison + elsif( $expected ne $result ) + { + $matched = 0; + } + + if( !$matched || $insideuo ) + { + # if the lines did not match, and if we are comparing an unordered set of lines, + # then save the lines for processing later. + if( $insideuo ) + { + $earr[$iuo][0] = $expected; + $rarr[$iuo][0] = $result; + + + if( !$seenspecialinuo && $expected =~ /^--\?.*/ ) + { + $seenspecialinuo = 1; + } + + ++$iuo; + } + else # print out the difference + { + $rc = 2; + if( $bFirstLine ) + { + $bFirstLine = 0; + print $NEW_EXPECTED "$expected"; + } + else + { + print $NEW_EXPECTED "\n$expected"; + } + } + } + else + { + if( $bFirstLine ) + { + $bFirstLine = 0; + print $NEW_EXPECTED "$result"; + } + else + { + print $NEW_EXPECTED "\n$result"; + } + + } +} + +close $EXPECTED; +close $RESULT; +close $NEW_EXPECTED; + +exit( $rc + $smartmatch ); diff --git a/contrib/timescaledb/regress/sql/AddPartitionFailOnEmptyChunkedTable.sql b/contrib/timescaledb/regress/sql/AddPartitionFailOnEmptyChunkedTable.sql new file mode 100644 index 000000000..10b24d473 --- /dev/null +++ b/contrib/timescaledb/regress/sql/AddPartitionFailOnEmptyChunkedTable.sql @@ -0,0 +1,17 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +-- 2.插入数据 +insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1); +-- 3.删除数据 +delete from test_schema.test_table where time is not null; +select count(*) from test_schema.test_table; +-- 4.新增分区维度 +select add_dimension('test_schema.test_table', 'device_type', 2); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/BigIntBoundaryTest.sql b/contrib/timescaledb/regress/sql/BigIntBoundaryTest.sql new file mode 100644 index 000000000..d025119ce --- /dev/null +++ b/contrib/timescaledb/regress/sql/BigIntBoundaryTest.sql @@ -0,0 +1,91 @@ +create extension timescaledb; + +-- 1.在role1下创建自定义函数 +set role lhy password 'Test@123'; +CREATE OR REPLACE FUNCTION assert_true( + val boolean +) + RETURNS VOID LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + IF !val THEN + RAISE 'Assert failed'; + END IF; +END +$BODY$; + + +CREATE OR REPLACE FUNCTION assert_equal( + val1 anyelement, + val2 anyelement +) + RETURNS VOID LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + IF val1 != val2 THEN + RAISE 'Assert failed'; + END IF; +END +$BODY$; + +-- 2.在初始用户下创建自定义函数 +\c test1 lhy +CREATE OR REPLACE FUNCTION allow_downgrade_to_apache() +RETURNS VOID +AS '$libdir/timescaledb-1.7.4', 'ts_allow_downgrade_to_apache' +LANGUAGE C; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.dimension_calculate_default_range_open( + dimension_value BIGINT, + interval_length BIGINT, + OUT range_start BIGINT, + OUT range_end BIGINT) + AS '$libdir/timescaledb-1.7.4', 'ts_dimension_calculate_open_range_default' LANGUAGE C STABLE; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.dimension_calculate_default_range_closed( + dimension_value BIGINT, + num_slices SMALLINT, + OUT range_start BIGINT, + OUT range_end BIGINT) + AS '$libdir/timescaledb-1.7.4', 'ts_dimension_calculate_closed_range_default' LANGUAGE C STABLE; + +-- 3.bigint边界值测试 +SELECT assert_equal(0::bigint, actual_range_start), assert_equal(10::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(0,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(0::bigint, actual_range_start), assert_equal(10::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(9,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(10::bigint, actual_range_start), assert_equal(20::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(10,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(-10::bigint, actual_range_start), assert_equal(0::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-1,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(-10::bigint, actual_range_start), assert_equal(0::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-10,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(-20::bigint, actual_range_start), assert_equal(-10::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-11,10) AS res(actual_range_start, actual_range_end); +SELECT assert_equal(-9223372036854775808, actual_range_start), assert_equal(-9223372036854775800::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-9223372036854775808,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(-9223372036854775808, actual_range_start), assert_equal(-9223372036854775800::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(-9223372036854775807,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(9223372036854775800::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(9223372036854775807,10) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(9223372036854775800::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_open(9223372036854775806,10) AS res(actual_range_start, actual_range_end); +SELECT assert_equal((-9223372036854775808)::bigint, actual_range_start), assert_equal(1073741823::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_closed(0,2::smallint) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal(1073741823::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_closed(1073741824,2::smallint) AS res(actual_range_start, actual_range_end); + +SELECT assert_equal((-9223372036854775808)::bigint, actual_range_start), assert_equal(9223372036854775807::bigint, actual_range_end) +FROM _timescaledb_internal.dimension_calculate_default_range_closed(1073741824,1::smallint) AS res(actual_range_start, actual_range_end); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ChunkParallelism.sql b/contrib/timescaledb/regress/sql/ChunkParallelism.sql new file mode 100644 index 000000000..b8e301b19 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ChunkParallelism.sql @@ -0,0 +1,19 @@ +create extension timescaledb; + +\echo 1.创建超表 +\c test1 lhy; +drop table if exists test1 cascade; +CREATE TABLE test1(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +SELECT create_hypertable('test1', 'time', chunk_time_interval => 2628000000000); +INSERT INTO test1 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test1 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test1 + +\echo 2.设置子表并行度 +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk SET (parallel_workers=2); +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk SET (parallel_workers=4); +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk RESET (parallel_workers); +SELECT relname, reloptions FROM pg_class WHERE relname IN ('_hyper_1_1_chunk','_hyper_1_2_chunk'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ChunkRename.sql b/contrib/timescaledb/regress/sql/ChunkRename.sql new file mode 100644 index 000000000..0b312ed40 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ChunkRename.sql @@ -0,0 +1,24 @@ +create extension timescaledb; + +\echo 1.创建超表 +\c test1 lhy1; +drop table if exists test2 cascade; +CREATE TABLE test2(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +SELECT create_hypertable('test2', 'time', chunk_time_interval => 2628000000000); +INSERT INTO test2 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test2 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test2 + +\echo 2.非初始用户重命名chunk的表名称合理报错 +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk RENAME TO new_chunk_name; +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; + +\echo 3.初始用户重命名chunk的表名称成功 +\c test1 lhy +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 2; +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk RENAME TO new_chunk_name; +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 2; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ChunkSchemaRenameSuccess.sql b/contrib/timescaledb/regress/sql/ChunkSchemaRenameSuccess.sql new file mode 100644 index 000000000..b7b7aaabe --- /dev/null +++ b/contrib/timescaledb/regress/sql/ChunkSchemaRenameSuccess.sql @@ -0,0 +1,29 @@ +create extension timescaledb; + +-- 1.指定chunk的模式名为my_associated_schema创建超表 +CREATE TABLE my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('my_table','date', associated_schema_name => 'my_associated_schema'); + +-- 2.插入数据 +INSERT INTO my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); + +-- 3.更改关联的chunk的模式名 +ALTER SCHEMA my_associated_schema RENAME TO new_associated_schema; +\d+ my_table + +-- 4.再次插入数据 +INSERT INTO my_table (date, quantity) VALUES ('2018-08-10T23:00:00+00:00', 20); +\d+ my_table + +-- 5.在系统表下查看chunk模式名均更改成功 +SELECT * from _timescaledb_catalog.hypertable where table_name='my_table'; +SELECT * from _timescaledb_catalog.chunk; + +-- 6.清理环境 +DROP TABLE my_table; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ChunkSchemaSetup.sql b/contrib/timescaledb/regress/sql/ChunkSchemaSetup.sql new file mode 100644 index 000000000..79d9a15ce --- /dev/null +++ b/contrib/timescaledb/regress/sql/ChunkSchemaSetup.sql @@ -0,0 +1,19 @@ +create extension timescaledb; + +\echo 1.创建超表 +\c test1 lhy1; +drop table if exists test3 cascade; +CREATE TABLE test3(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +SELECT create_hypertable('test3', 'time', chunk_time_interval => 2628000000000); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test3 + +\echo 2.初始用户设置chunk的schema为public成功 +\c test1 lhy +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk RENAME TO new_chunk_name; +ALTER TABLE _timescaledb_internal.new_chunk_name SET SCHEMA public; +SELECT * FROM _timescaledb_catalog.chunk WHERE id = 1; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ChunkTablespaceUpdate.sql b/contrib/timescaledb/regress/sql/ChunkTablespaceUpdate.sql new file mode 100644 index 000000000..02d0d0e3c --- /dev/null +++ b/contrib/timescaledb/regress/sql/ChunkTablespaceUpdate.sql @@ -0,0 +1,27 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 lhy1; +drop table if exists test3 cascade; +CREATE TABLE test3(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +SELECT create_hypertable('test3', 'time', chunk_time_interval => 2628000000000); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test3 + +-- 2.切换至初始用户创建表空间 +\c test1 lhy; +SET client_min_messages = ERROR; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; + +-- 3.切换至角色role1,更改chunk的表空间 +\c test1 lhy1; +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk SET TABLESPACE tablespace1; +SELECT tablespace FROM pg_tables WHERE tablename = '_hyper_1_1_chunk'; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ColumnCleanup.sql b/contrib/timescaledb/regress/sql/ColumnCleanup.sql new file mode 100644 index 000000000..cc162433b --- /dev/null +++ b/contrib/timescaledb/regress/sql/ColumnCleanup.sql @@ -0,0 +1,64 @@ +create extension timescaledb; + +\echo 1.创建超表 +set role lhy; +CREATE TABLE alter_after(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +SELECT create_hypertable('alter_after', 'time', chunk_time_interval => 2628000000000); + +\echo 2.插入1条数据生成第一个chunk(子表) +INSERT INTO alter_after (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +\d+ alter_after + +\echo 3.删除并更改列字段属性 +ALTER TABLE alter_after DROP COLUMN id; +ALTER TABLE alter_after ALTER COLUMN temp SET (n_distinct = 10); +ALTER TABLE alter_after ALTER COLUMN colorid SET (n_distinct = 11); +ALTER TABLE alter_after ALTER COLUMN colorid RESET (n_distinct); +ALTER TABLE alter_after ALTER COLUMN colorid SET STATISTICS 101; +ALTER TABLE alter_after ALTER COLUMN notes_2 SET STORAGE EXTERNAL; + +\echo 4.删除列后插入数据成功(生成新的chunk) +INSERT INTO alter_after VALUES ('2017-03-22T09:18:23', 21.5, 1), + ('2017-05-22T09:18:22', 36.2, 2), + ('2017-05-22T09:18:23', 15.2, 2); +\d+ alter_after + +\echo 5.确保copy数据功能正常 +\COPY alter_after FROM '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/sql/data/alter.tsv' NULL AS ''; + +\echo 6.查看表的数据显示正常 +SELECT * FROM alter_after; + +\echo 7.在drop列之后创建的chunk的attnum不同 +SELECT c.relname, a.attname, a.attnum FROM pg_attribute a, pg_class c +WHERE a.attrelid = c.oid +AND (c.relname LIKE '_hyper_54%_chunk' OR c.relname = 'alter_after') +AND a.attnum > 0 +ORDER BY c.relname, a.attnum; + +\echo 8.再次添加id列后插入数据 +-- 这个会出现异常,因为普通表也不支持 +ALTER TABLE alter_after ADD COLUMN id serial; +INSERT INTO alter_after (time, temp, colorid) VALUES ('2017-08-22T09:19:14', 12.5, 3); + +\echo 9.验证在chunk上修改列属性成功(块的名称要跟实际块的名称对应,下面chunk的名称_hyper_58_45_chunk等不是固定不变的) +-- 这个需要输出一下上面的_hyper_29%_chunk来看看底下的叫什么名字,到时候需要将epected替换一下 +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk ALTER COLUMN temp RESET (n_distinct); +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk ALTER COLUMN temp SET (n_distinct = 20); +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk ALTER COLUMN temp SET STATISTICS 201; +ALTER TABLE _timescaledb_internal._hyper_1_2_chunk ALTER COLUMN notes SET STORAGE EXTERNAL; + +\echo 10.增加列后查看表的attnum与n_distinct属性 +SELECT c.relname, a.attname, a.attnum, a.attoptions, a.attstattarget, a.attstorage FROM pg_attribute a, pg_class c +WHERE a.attrelid = c.oid +AND (c.relname LIKE '_hyper_1%_chunk' OR c.relname = 'alter_after') +AND a.attnum > 0 +ORDER BY c.relname, a.attnum; + +\echo 11.查看超表的数据 +SELECT * FROM alter_after; + +\o + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ColumnRenameError.sql b/contrib/timescaledb/regress/sql/ColumnRenameError.sql new file mode 100644 index 000000000..784d54ae8 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ColumnRenameError.sql @@ -0,0 +1,16 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 lhy1; +drop table if exists test3 cascade; +CREATE TABLE test3(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); +SELECT create_hypertable('test3', 'time', chunk_time_interval => 2628000000000); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-03-22T09:18:22', 23.5, 1); +INSERT INTO test3 (time, temp, colorid) VALUES ('2017-06-22T09:18:22', 23.5, 1); +\d+ test3 + +-- 2.重命名子表的列名称合理报错 +ALTER TABLE _timescaledb_internal._hyper_1_1_chunk RENAME COLUMN time TO newtime; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ColumnSyncFix.sql b/contrib/timescaledb/regress/sql/ColumnSyncFix.sql new file mode 100644 index 000000000..05e2e7abe --- /dev/null +++ b/contrib/timescaledb/regress/sql/ColumnSyncFix.sql @@ -0,0 +1,30 @@ +create extension timescaledb; + +\echo 1.创建普通表 +CREATE TABLE alter_before(id serial, time timestamp, temp float, colorid integer, notes text, notes_2 text); + +\echo 2.修改列字段属性 +ALTER TABLE alter_before DROP COLUMN id; +ALTER TABLE alter_before ALTER COLUMN temp SET (n_distinct = 10); +ALTER TABLE alter_before ALTER COLUMN colorid SET (n_distinct = 11); +ALTER TABLE alter_before ALTER COLUMN colorid RESET (n_distinct); +ALTER TABLE alter_before ALTER COLUMN temp SET STATISTICS 100; +ALTER TABLE alter_before ALTER COLUMN notes SET STORAGE EXTERNAL; + +\echo 3.创建超表 +SELECT create_hypertable('alter_before', 'time', chunk_time_interval => 2628000000000); + +\echo 4.超表插入数据 +INSERT INTO alter_before VALUES ('2017-03-22T09:18:22', 23.5, 1); +SELECT * FROM alter_before; +\d+ alter_before + +\echo 5.显示已删除的列被标记为已删除且父表与子表(chunk)的attnum不同(_hyper_57%_chunk对应超表的块) +SELECT c.relname, a.attname, a.attnum, a.attoptions, a.attstattarget, a.attstorage FROM pg_attribute a, pg_class c +WHERE a.attrelid = c.oid +AND (c.relname LIKE '_hyper_1%_chunk' OR c.relname = 'alter_before') +AND a.attnum > 0 +ORDER BY c.relname, a.attnum; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/CreateHypertableDuplicateError.sql b/contrib/timescaledb/regress/sql/CreateHypertableDuplicateError.sql new file mode 100644 index 000000000..0e74a2e7b --- /dev/null +++ b/contrib/timescaledb/regress/sql/CreateHypertableDuplicateError.sql @@ -0,0 +1,19 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_1dim; +create table test_schema.test_1dim(time timestamp, temp float); +select create_hypertable('test_schema.test_1dim', 'time'); +-- 2.不指定if_not_exists参数再次创建超表 +select create_hypertable('test_schema.test_1dim', 'time'); +-- 3.插入数据 +insert into test_schema.test_1dim VALUES ('2004-10-19 10:23:54+02', 1.0); +-- 4.指定if_not_exists参数为true再次创建超表 +select create_hypertable('test_schema.test_1dim', 'time', if_not_exists => true); +-- 5.不指定if_not_exists参数再次创建超表合理报错 +select create_hypertable('test_schema.test_1dim', 'time'); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/CustomPartitionFunctionTest.sql b/contrib/timescaledb/regress/sql/CustomPartitionFunctionTest.sql new file mode 100644 index 000000000..dc14b673e --- /dev/null +++ b/contrib/timescaledb/regress/sql/CustomPartitionFunctionTest.sql @@ -0,0 +1,56 @@ +create extension timescaledb; + +-- 1.使用og初始用户role登入数据库 +\c test1 lhy; +-- 2.从role2角色中收回role1角色的权限 +revoke lhy1 from lhy2; +-- 3.创建自定义分区函数 +CREATE OR REPLACE FUNCTION partfunc_not_immutable(source anyelement) + RETURNS INTEGER LANGUAGE PLPGSQL AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +CREATE OR REPLACE FUNCTION partfunc_bad_return_type(source anyelement) + RETURNS BIGINT LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +CREATE OR REPLACE FUNCTION partfunc_bad_arg_type(source text) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +CREATE OR REPLACE FUNCTION partfunc_bad_multi_arg(source anyelement, extra_arg integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +CREATE OR REPLACE FUNCTION partfunc_valid(source anyelement) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +-- 4.创建超表 +drop table if exists test_schema.test_partfunc; +create table test_schema.test_partfunc(time timestamptz, temp float, device int); +select create_hypertable('test_schema.test_partfunc', 'time'); +-- 5.自定义分区函数无效导致增加分区维度失败 +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_not_immutable'); +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_bad_return_type'); +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_bad_arg_type'); +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_bad_multi_arg'); +-- 6.使用有效的分区函数添加分区维度成功 +select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_valid'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/CustomTypeTableToHypertable.sql b/contrib/timescaledb/regress/sql/CustomTypeTableToHypertable.sql new file mode 100644 index 000000000..355648310 --- /dev/null +++ b/contrib/timescaledb/regress/sql/CustomTypeTableToHypertable.sql @@ -0,0 +1,16 @@ +create extension timescaledb; + +-- 1.创建自定义数据类型并转换为超表 +\c test1 +CREATE TYPE test_type AS (time timestamp, temp float); +CREATE TABLE test_table_of_type OF test_type; +SELECT create_hypertable('test_table_of_type', 'time'); +-- 2.超表插入数据 +INSERT INTO test_table_of_type VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +-- 3.删除自定义数据类型 +DROP TYPE test_type; +-- 4.加CASCADE删除自定义数据类型 +DROP TYPE test_type CASCADE; + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/DefaultTablespaceValidation.sql b/contrib/timescaledb/regress/sql/DefaultTablespaceValidation.sql new file mode 100644 index 000000000..e1b5baf13 --- /dev/null +++ b/contrib/timescaledb/regress/sql/DefaultTablespaceValidation.sql @@ -0,0 +1,76 @@ +create extension timescaledb; + +-- 1.清理test1库下所有表 +drop table if EXISTS test1 cascade; +drop table if EXISTS test2 cascade; + +-- 2.切换至初始用户创建表空间 +\c test1 lhy; +SET client_min_messages = ERROR; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; + +-- 3.创建超表 +CREATE TABLE hyper_in_space(time bigint, temp float, device int); +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); + +-- 4.插入数据,查看表空间下的表信息 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + +-- 5.设置默认表空间为tablespace1后插入数据 +SET default_tablespace = tablespace1; +INSERT INTO hyper_in_space(time, temp, device) VALUES (11, 24, 3); +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename LIKE '_hyper%' ORDER BY tablename; +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + +-- 6.更改父表的表空间为tablespace1,查看tablespace1下的表信息 +SET default_tablespace TO DEFAULT; +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; +\d+ hyper_in_space + +-- 7.插入如下数据,数据插入表空间已有的chunk中,不产生新的chunk +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 27, 1); +SELECT tablename FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; +select * from _timescaledb_internal._hyper_1_1_chunk; + +-- 8.插入如下数据,产生新的chunk +INSERT INTO hyper_in_space(time, temp, device) VALUES (8, 24, 2); +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename LIKE '_hyper%' ORDER BY tablename; + +-- 9.超表已附加到表空间,超表存在删除表空间合理报错 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; +DROP TABLESPACE tablespace1; + +-- 10.show_chunks与drop_chunks一致 +-- 设置变量 +\set QUERY1 'SELECT show_chunks(\'hyper_in_space\', 22)::NAME' +\set QUERY2 'SELECT drop_chunks(22, \'hyper_in_space\')::NAME' +-- 创建临时结果(cte)用于查询 +with query1 AS ( + SELECT row_number() OVER(ORDER BY q.*) row_number, * FROM (:QUERY1) as q +), +query2 AS ( + SELECT row_number() OVER (ORDER BY v.*) row_number, * FROM (:QUERY2) as v +) +SELECT count(*) FILTER (WHERE query1.row_number IS DISTINCT FROM query2.row_number OR query1.show_chunks IS DISTINCT FROM query2.drop_chunks) AS "Different Rows", +coalesce(max(query1.row_number), 0) AS "Total Rows from Query 1", coalesce(max(query2.row_number), 0) AS "Total Rows from Query 2" +FROM query1 FULL OUTER JOIN query2 ON (query1.row_number = query2.row_number); + +-- 11.再次查看表空间tablespace1下的表信息,不存在chunk(子表) +SELECT tablename, tablespace FROM pg_tables WHERE tablespace = 'tablespace1' ORDER BY tablename; + +-- 12.超表与表空间存在依赖关系,删除表空间合理报错。删除超表成功 +DROP TABLESPACE tablespace1; +DROP TABLE hyper_in_space; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/EmptyTableMigrateSuccess.sql b/contrib/timescaledb/regress/sql/EmptyTableMigrateSuccess.sql new file mode 100644 index 000000000..5f93251a0 --- /dev/null +++ b/contrib/timescaledb/regress/sql/EmptyTableMigrateSuccess.sql @@ -0,0 +1,10 @@ +create extension timescaledb; + +-- 1.创建普通表 +\c test1 +create table test_schema.test_migrate_empty(time timestamp, temp float); +-- 2.转换为超表 +select create_hypertable('test_schema.test_migrate_empty', 'time', migrate_data => true); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/HypertableChunksDataCorrect.sql b/contrib/timescaledb/regress/sql/HypertableChunksDataCorrect.sql new file mode 100644 index 000000000..81db4e5fb --- /dev/null +++ b/contrib/timescaledb/regress/sql/HypertableChunksDataCorrect.sql @@ -0,0 +1,26 @@ +create extension timescaledb; + +-- -- 1.创建表并插入数据 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_migrate; +create table test_schema.test_migrate(time timestamp, temp float); +insert into test_schema.test_migrate VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +select * from only test_schema.test_migrate; +-- 2.转换为超表(此刻父表的数据被移至子表) +select create_hypertable('test_schema.test_migrate', 'time', migrate_data => true); +-- 3.查看超表的表信息,获取超表id +select * from _timescaledb_catalog.hypertable where table_name = 'test_migrate'; +-- 4.查看该超表id下的chunk信息有2个 +select * from _timescaledb_catalog.chunk; +-- 5.只查看父表数据 +select * from only test_schema.test_migrate; +-- 6.广义查看超表数据 +select * from test_schema.test_migrate; +\d+ test_schema.test_migrate +-- 7.在每个子表中查看数据 +select * from only _timescaledb_internal._hyper_51_67_chunk; +select * from only _timescaledb_internal._hyper_58_70_chunk; + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/HypertableCreateNoPerm.sql b/contrib/timescaledb/regress/sql/HypertableCreateNoPerm.sql new file mode 100644 index 000000000..677dc47a3 --- /dev/null +++ b/contrib/timescaledb/regress/sql/HypertableCreateNoPerm.sql @@ -0,0 +1,12 @@ +create extension timescaledb; + +-- 1.在role1下创建普通表 +\c test1 +create table test_schema.test_table_no_not_null(time BIGINT, device_id text); + +-- 2.切换角色至role2,在role2下创建超表 +set role lhy2 password 'Test@123'; +select * from create_hypertable('test_schema.test_table_no_not_null', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month')); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/HypertableCreationInfoSuccess.sql b/contrib/timescaledb/regress/sql/HypertableCreationInfoSuccess.sql new file mode 100644 index 000000000..0b7e1c6d1 --- /dev/null +++ b/contrib/timescaledb/regress/sql/HypertableCreationInfoSuccess.sql @@ -0,0 +1,23 @@ +create extension timescaledb; + +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); + +-- 2.将会话恢复为原有权限 +RESET ROLE; + +-- 3.赋值role2的chunk_schema权限给role1 +GRANT CREATE ON SCHEMA chunk_schema TO lhy1; + +-- 4.切换至role1创建超表 +set role lhy1 password 'Test@123'; +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); + +-- 5.查看创建超表的命令 +SELECT * FROM _timescaledb_internal.get_create_command('test_table'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/HypertableCustomTypeRelation.sql b/contrib/timescaledb/regress/sql/HypertableCustomTypeRelation.sql new file mode 100644 index 000000000..d2d4e382e --- /dev/null +++ b/contrib/timescaledb/regress/sql/HypertableCustomTypeRelation.sql @@ -0,0 +1,26 @@ +create extension timescaledb; + +-- 1.转换为超表 +\c test1 +CREATE TABLE test_table_of_type (time timestamp, temp float); +SELECT create_hypertable('test_table_of_type', 'time'); +-- 2.插入数据 +INSERT INTO test_table_of_type VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +-- 3.创建自定义数据类型 +CREATE TYPE test_type AS (time timestamp, temp float); +-- 4.超表链接到组合类型test_type +ALTER TABLE test_table_of_type OF test_type; +-- 5.删除自定义数据类型 +DROP TYPE test_type; +-- 6.加cascade删除数据类型后rollback +BEGIN; +DROP TYPE test_type CASCADE; +ROLLBACK; +-- 7.不加CASCADE再次删除自定义数据类型 +DROP TYPE test_type; +-- 8.超表解除自定义数据类型后删除自定义数据类型 +ALTER TABLE test_table_of_type NOT OF; +DROP TYPE test_type; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/HypertableSchemaRename.sql b/contrib/timescaledb/regress/sql/HypertableSchemaRename.sql new file mode 100644 index 000000000..6b188a4a6 --- /dev/null +++ b/contrib/timescaledb/regress/sql/HypertableSchemaRename.sql @@ -0,0 +1,21 @@ +create extension timescaledb; + +-- 1.自定义模式名创建超表 +\c test1 lhy; +CREATE SCHEMA IF NOT EXISTS original_name; +CREATE TABLE original_name.my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('original_name.my_table','date'); + +-- 2.插入数据并更改超表模式名 +INSERT INTO original_name.my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +ALTER SCHEMA original_name RENAME TO new_name; + +-- 3.清理环境 +DROP TABLE new_name.my_table; +DROP SCHEMA new_name; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/HypertableTablespaceNoAccumulation.sql b/contrib/timescaledb/regress/sql/HypertableTablespaceNoAccumulation.sql new file mode 100644 index 000000000..e40e632e2 --- /dev/null +++ b/contrib/timescaledb/regress/sql/HypertableTablespaceNoAccumulation.sql @@ -0,0 +1,48 @@ +create extension timescaledb; + +-- 1.创建普通表并转换为超表 +\c test1 lhy; +SET client_min_messages = ERROR; +drop table if exists hyper_in_space; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +CREATE TABLE hyper_in_space(time bigint, temp float, device int) TABLESPACE tablespace1; +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); + +-- 2.插入数据 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); + +-- 3.查看超表id下有唯一的表空间tablespace1 +SELECT * FROM _timescaledb_catalog.tablespace; + +-- 4.通过alter table设置超表的表空间为tablespace2 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace2; +SELECT * FROM _timescaledb_catalog.tablespace; + +-- 5.通过alter table重新设置超表的表空间为tablespace1 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; +SELECT * FROM _timescaledb_catalog.tablespace; + +-- 6.查看chunk与超表附加的表空间信息 +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + +-- 7.超表hyper_in_space分离表空间tablespace1 +SELECT detach_tablespace('tablespace1', 'hyper_in_space'); + +-- 8.超表插入数据后查看表空间信息 +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (7, 23, 1); +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + +-- 9.系统表_timescaledb_catalog.tablespace查看附加的表空间信息 +SELECT * FROM _timescaledb_catalog.tablespace; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/HypertableTriggerExists.sql b/contrib/timescaledb/regress/sql/HypertableTriggerExists.sql new file mode 100644 index 000000000..e1fa2075a --- /dev/null +++ b/contrib/timescaledb/regress/sql/HypertableTriggerExists.sql @@ -0,0 +1,29 @@ +create extension timescaledb; + +-- 1.创建触发器测试函数 +\c test1 +CREATE SCHEMA IF NOT EXISTS test; +GRANT USAGE ON SCHEMA test TO PUBLIC; +CREATE OR REPLACE FUNCTION test.show_triggers(rel regclass, show_internal boolean = false) +RETURNS TABLE("Trigger" name, + "Type" smallint, + "Function" regproc) LANGUAGE SQL STABLE AS +$BODY$ + SELECT t.tgname, + t.tgtype, + t.tgfoid::regproc + FROM pg_trigger t + WHERE t.tgrelid = rel + AND t.tgisinternal = show_internal + ORDER BY t.tgname; +$BODY$; + +-- 2.创建超表 +create table test_schema.test_table2(time date); +select * from create_hypertable('test_schema.test_table2', 'time'); + +-- 3.查看超表的触发器 +SELECT * FROM test.show_triggers('test_schema.test_table2'); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/IndexTablespaceUpdateValidation.sql b/contrib/timescaledb/regress/sql/IndexTablespaceUpdateValidation.sql new file mode 100644 index 000000000..f179fd4f6 --- /dev/null +++ b/contrib/timescaledb/regress/sql/IndexTablespaceUpdateValidation.sql @@ -0,0 +1,52 @@ +create extension timescaledb; + +-- 1.创建表空间 +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; + +-- 2.在表空间tablespace1上创建具有主键索引的表(复合主键) +CREATE TABLE series( + time timestamptz not null, + device int, + value float, + CONSTRAINT series_pk PRIMARY KEY (time, device) USING INDEX TABLESPACE tablespace1); +SELECT create_hypertable('series', 'time', create_default_indexes => FALSE); + +-- 3.插入数据以创建初始块 +INSERT INTO series VALUES ('2019-04-21 10:12', 1, 1.01); + +-- 4.创建索引series_value并指定表空间为tablespace2 +CREATE INDEX series_value ON series (value, time) TABLESPACE tablespace2; + +-- 5.查看系统表pg_indexes的索引信息 +SELECT schemaname, tablename, indexname, tablespace +FROM pg_indexes +WHERE indexname LIKE '%series%' +ORDER BY indexname; + +-- 6.使用alter index改变复合主键约束的索引表空间为tablespace2 +ALTER INDEX series_pk SET TABLESPACE tablespace2; + +-- 7.time字段创建索引,设置series_value索引的表空间为默认表空间 +CREATE INDEX ON series (time) TABLESPACE tablespace1; +ALTER INDEX series_value SET TABLESPACE pg_default; + +-- 8.插入新数据以创建新的chunk +INSERT INTO series VALUES ('2019-04-29 10:12', 2, 1.31); + +-- 9.更新索引的表空间后,在当前的表空间tablespace2中创建新的chunk +SELECT schemaname, tablename, indexname, tablespace +FROM pg_indexes +WHERE indexname LIKE '%series%' +ORDER BY indexname; + +-- 10.清理环境 +DROP TABLE series; +DROP TABLESPACE tablespace1; +DROP TABLESPACE tablespace2; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/InvalidFunctionAddPartitionFail.sql b/contrib/timescaledb/regress/sql/InvalidFunctionAddPartitionFail.sql new file mode 100644 index 000000000..551ecc0aa --- /dev/null +++ b/contrib/timescaledb/regress/sql/InvalidFunctionAddPartitionFail.sql @@ -0,0 +1,34 @@ +create extension timescaledb; + +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +CREATE OR REPLACE FUNCTION invalid_partfunc(source integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN NULL; +END +$BODY$; +CREATE OR REPLACE FUNCTION time_partfunc(source text) + RETURNS TIMESTAMPTZ LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN timezone('UTC', to_timestamp(source)); +END +$BODY$; +-- 2.创建超表 +drop table if exists test_schema.test_invalid_func; +CREATE TABLE test_schema.test_invalid_func(time timestamptz, temp float8, device text); +SELECT create_hypertable('test_schema.test_invalid_func', 'time'); +-- 3.增加分区维度使用无效的自定义函数 +SELECT add_dimension('test_schema.test_invalid_func', 'device', 2, partitioning_func => 'invalid_partfunc'); +-- 4.创建超表 +drop table if exists test_schema.open_dim_part_func; +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'time_partfunc'); +-- 5.使用无效的自定义函数增加分区维度 +SELECT add_dimension('test_schema.open_dim_part_func', 'event_time', chunk_time_interval => interval '1 day', partitioning_func => 'invalid_partfunc'); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/InvalidFunctionHypertableCreationFail.sql b/contrib/timescaledb/regress/sql/InvalidFunctionHypertableCreationFail.sql new file mode 100644 index 000000000..62d0ea5a0 --- /dev/null +++ b/contrib/timescaledb/regress/sql/InvalidFunctionHypertableCreationFail.sql @@ -0,0 +1,23 @@ +create extension timescaledb; + +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +CREATE OR REPLACE FUNCTION invalid_partfunc(source integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN NULL; +END +$BODY$; +-- 2.分区为时间、文本类型使用无效的自定义函数 +drop table if exists test_schema.test_invalid_func; +CREATE TABLE test_schema.test_invalid_func(time timestamptz, temp float8, device text); +SELECT create_hypertable('test_schema.test_invalid_func', 'time', 'device', 2, partitioning_func => 'invalid_partfunc'); +-- 3.分区为文本类型使用自定义函数 +drop table if exists test_schema.open_dim_part_func; +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'invalid_partfunc'); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/InvalidPartitionFunctionFailure.sql b/contrib/timescaledb/regress/sql/InvalidPartitionFunctionFailure.sql new file mode 100644 index 000000000..09518af5a --- /dev/null +++ b/contrib/timescaledb/regress/sql/InvalidPartitionFunctionFailure.sql @@ -0,0 +1,47 @@ +create extension timescaledb; + +-- 1.使用role1登入数据库 +\c test1 +alter role lhy1 login; +-- \c test_speed7 role1; +-- 2.从role2角色中收回role1角色的权限 +revoke lhy1 from lhy2; +-- 3.创建自定义分区函数 +CREATE OR REPLACE FUNCTION partfunc_not_immutable(source anyelement) + RETURNS INTEGER LANGUAGE PLPGSQL AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +CREATE OR REPLACE FUNCTION partfunc_bad_return_type(source anyelement) + RETURNS BIGINT LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +CREATE OR REPLACE FUNCTION partfunc_bad_arg_type(source text) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +CREATE OR REPLACE FUNCTION partfunc_bad_multi_arg(source anyelement, extra_arg integer) + RETURNS INTEGER LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN _timescaledb_internal.get_partition_hash(source); +END +$BODY$; +-- 4.创建普通表 +create table test_schema.test_partfunc(time timestamptz, temp float, device int); +-- 5.自定义分区功能函数无效导致创建超表失败 +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_not_immutable'); +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_bad_return_type'); +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_bad_arg_type'); +select create_hypertable('test_schema.test_partfunc', 'time', 'device', 2, partitioning_func => 'partfunc_bad_multi_arg'); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/MultipleHypertablesRenameSuccess.sql b/contrib/timescaledb/regress/sql/MultipleHypertablesRenameSuccess.sql new file mode 100644 index 000000000..d3350c034 --- /dev/null +++ b/contrib/timescaledb/regress/sql/MultipleHypertablesRenameSuccess.sql @@ -0,0 +1,35 @@ +create extension timescaledb; + +-- 1.自定义模式名创建超表 +\c test1 lhy; +CREATE SCHEMA IF NOT EXISTS original_name; +CREATE TABLE original_name.my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +CREATE TABLE original_name.my_table2 ( + date timestamp with time zone NOT NULL, + quantity double precision +); +CREATE TABLE regular_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('original_name.my_table','date'); +SELECT create_hypertable('original_name.my_table2','date'); +SELECT create_hypertable('regular_table','date'); + +-- 2.插入数据并更改超表的模式名 +INSERT INTO original_name.my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +INSERT INTO original_name.my_table2 (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +INSERT INTO regular_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +ALTER SCHEMA original_name RENAME TO new_name; + +-- 3.清理环境 +DROP TABLE new_name.my_table; +DROP TABLE new_name.my_table2; +DROP TABLE regular_table; +DROP SCHEMA new_name; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/PartitionCountChangeError.sql b/contrib/timescaledb/regress/sql/PartitionCountChangeError.sql new file mode 100644 index 000000000..7af3c9a56 --- /dev/null +++ b/contrib/timescaledb/regress/sql/PartitionCountChangeError.sql @@ -0,0 +1,24 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); + +-- 2.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); + +-- 3.未指明要更改的分区数量,合理报错 +SELECT set_number_partitions('test_schema.test_table', 1); + +-- 4.分区数量边界值测试,合理报错 +SELECT set_number_partitions('test_schema.test_table', 0, 'location'); +SELECT set_number_partitions('test_schema.test_table', 32768, 'location'); + +-- 5.get_create_command仅支持最多2个分区维度超级表,多维合理报错 + SELECT * FROM _timescaledb_internal.get_create_command('test_table'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/PartitionCountChangeSuccess.sql b/contrib/timescaledb/regress/sql/PartitionCountChangeSuccess.sql new file mode 100644 index 000000000..f3923033c --- /dev/null +++ b/contrib/timescaledb/regress/sql/PartitionCountChangeSuccess.sql @@ -0,0 +1,29 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); + +-- 2.更改超表的分区数量为1,合理报错 +SELECT set_number_partitions('test_schema.test_table', 1, 'location'); + +-- 3.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); + +-- 4.更改超表的分区数量为1 +SELECT set_number_partitions('test_schema.test_table', 1, 'location'); + +-- 5.查看超表的分区信息 +select * from _timescaledb_catalog.dimension WHERE column_name = 'location'; + +-- 6.更改超表的分区数量为2 +SELECT set_number_partitions('test_schema.test_table', 2, 'location'); + +-- 7.查看超表的分区信息 +select * from _timescaledb_catalog.dimension WHERE column_name = 'location'; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/PartitionDimensionAddSuccess.sql b/contrib/timescaledb/regress/sql/PartitionDimensionAddSuccess.sql new file mode 100644 index 000000000..92ec1faf4 --- /dev/null +++ b/contrib/timescaledb/regress/sql/PartitionDimensionAddSuccess.sql @@ -0,0 +1,20 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); + +-- 2.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); + +-- 3.查看超表信息 +select * from _timescaledb_catalog.hypertable where table_name = 'test_table'; + +-- 4.查看超表的分区维度信息 +select * from _timescaledb_catalog.dimension; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/PluginSchemaRenameErrorHandling.sql b/contrib/timescaledb/regress/sql/PluginSchemaRenameErrorHandling.sql new file mode 100644 index 000000000..a6c3c775e --- /dev/null +++ b/contrib/timescaledb/regress/sql/PluginSchemaRenameErrorHandling.sql @@ -0,0 +1,11 @@ +create extension timescaledb; + +-- 1.重命名插件引入schema +\c test1 lhy; +ALTER SCHEMA _timescaledb_internal RENAME TO my_new_schema_name; +ALTER SCHEMA _timescaledb_catalog RENAME TO my_new_schema_name; +ALTER SCHEMA _timescaledb_cache RENAME TO my_new_schema_name; +ALTER SCHEMA _timescaledb_config RENAME TO my_new_schema_name; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/RoleInheritanceInsertTest.sql b/contrib/timescaledb/regress/sql/RoleInheritanceInsertTest.sql new file mode 100644 index 000000000..7b5e909ee --- /dev/null +++ b/contrib/timescaledb/regress/sql/RoleInheritanceInsertTest.sql @@ -0,0 +1,25 @@ +create extension timescaledb; + +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_table_no_not_null(time BIGINT, device_id text); + +-- 2.将会话恢复为原有权限 +RESET ROLE; + +-- 3.role2继承role1权限并切换至role2角色 +grant lhy1 to lhy2; +set role lhy2 password 'Test@123'; + +-- 4.在role2创建超表 + select * from create_hypertable('test_schema.test_table_no_not_null', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month')); + +-- 5.验证时间列time为空插入数据合理报错 +insert into test_schema.test_table_no_not_null (device_id) VALUES('foo'); + +-- 6.验证时间列time不为空插入数据成功 +insert into test_schema.test_table_no_not_null (time, device_id) VALUES(1, 'foo'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/RoleSchemaHypertableFail.sql b/contrib/timescaledb/regress/sql/RoleSchemaHypertableFail.sql new file mode 100644 index 000000000..796e7e60e --- /dev/null +++ b/contrib/timescaledb/regress/sql/RoleSchemaHypertableFail.sql @@ -0,0 +1,15 @@ +create extension timescaledb; + +-- 1.将会话恢复为原有权限 +\c test1 +RESET ROLE; + +-- 2.在role1下创建普通表 +set role lhy1 password 'Test@123'; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); + +-- 3.创建超表 +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/RoleSchemaPermHypertableSuccess.sql b/contrib/timescaledb/regress/sql/RoleSchemaPermHypertableSuccess.sql new file mode 100644 index 000000000..566a30b88 --- /dev/null +++ b/contrib/timescaledb/regress/sql/RoleSchemaPermHypertableSuccess.sql @@ -0,0 +1,19 @@ +create extension timescaledb; + +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); + +-- 2.将会话恢复为原有权限 +RESET ROLE; + +-- 3.赋值role2的chunk_schema权限给role1 +GRANT CREATE ON SCHEMA chunk_schema TO lhy1; + +-- 4.切换至role1创建超表 +set role lhy1 password 'Test@123'; +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/SchemaDeletionCascadeHypertables.sql b/contrib/timescaledb/regress/sql/SchemaDeletionCascadeHypertables.sql new file mode 100644 index 000000000..7a4456a9a --- /dev/null +++ b/contrib/timescaledb/regress/sql/SchemaDeletionCascadeHypertables.sql @@ -0,0 +1,29 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 lhy; +CREATE SCHEMA IF NOT EXISTS original_name; +CREATE TABLE original_name.my_table ( + date timestamp with time zone NOT NULL, + quantity double precision +); +CREATE TABLE original_name.my_table2 ( + date timestamp with time zone NOT NULL, + quantity double precision +); +SELECT create_hypertable('original_name.my_table','date'); +SELECT create_hypertable('original_name.my_table2','date'); + +-- 2.插入数据 +INSERT INTO original_name.my_table (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); +INSERT INTO original_name.my_table2 (date, quantity) VALUES ('2018-07-04T21:00:00+00:00', 8); + +-- 3.更改模式名后删除修改后的模式名 +ALTER SCHEMA original_name RENAME TO new_name; +DROP SCHEMA new_name CASCADE; + +-- 4.查看超表是否存在 +\dt new_name.*; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/SchemaPermRoleHypertableFail.sql b/contrib/timescaledb/regress/sql/SchemaPermRoleHypertableFail.sql new file mode 100644 index 000000000..8effc2213 --- /dev/null +++ b/contrib/timescaledb/regress/sql/SchemaPermRoleHypertableFail.sql @@ -0,0 +1,16 @@ +create extension timescaledb; + +-- 1.在role1下创建普通表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_table_no_not_null(time BIGINT, device_id text); + +-- 2.在role1角色下给role2赋test_schmea的所有权限 +GRANT ALL ON SCHEMA test_schema TO lhy2; + +-- 3.切换角色到role2创建超表 +set role lhy2 password 'Test@123'; + select * from create_hypertable('test_schema.test_table_no_not_null', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month')); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/SetIntegerNowFuncTest.sql b/contrib/timescaledb/regress/sql/SetIntegerNowFuncTest.sql new file mode 100644 index 000000000..4c187fc58 --- /dev/null +++ b/contrib/timescaledb/regress/sql/SetIntegerNowFuncTest.sql @@ -0,0 +1,42 @@ +create extension timescaledb; + +-- 1.role1角色登入pg兼容库test1 +alter role lhy1 login; +\c test1 lhy1 +-- 2.创建超表并返回超表ID +drop table if exists test_table_int; +CREATE TABLE test_table_int(time bigint, junk int); +SELECT hypertable_id AS "TEST_TABLE_INT_HYPERTABLE_ID" FROM create_hypertable('test_table_int', 'time', chunk_time_interval => 1); +-- 3.og初始用户role登入该兼容库test1 +\c test1 lhy1 +-- 4.创建函数及模式名并进行赋权 +CREATE SCHEMA IF NOT EXISTS my_schema; +create or replace function my_schema.dummy_now2() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +grant execute on ALL FUNCTIONS IN SCHEMA my_schema to public; +create or replace function dummy_now3() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +grant execute on ALL FUNCTIONS IN SCHEMA my_schema to public; +REVOKE execute ON function dummy_now3() FROM PUBLIC; +CREATE SCHEMA IF NOT EXISTS my_user_schema; +GRANT ALL ON SCHEMA my_user_schema to PUBLIC; +-- 5.role1角色登入pg兼容库test1,创建函数 +\c test1 lhy1 +create or replace function dummy_now() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +create or replace function my_user_schema.dummy_now4() returns BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 1::BIGINT'; +-- 6.设置整数类超表当前时间函数,查看超表分区信息 +select set_integer_now_func('test_table_int', 'dummy_now'); +select * from _timescaledb_catalog.dimension WHERE hypertable_id = 88; +-- 7.重复设置整数类超表当前时间函数 +select set_integer_now_func('test_table_int', 'dummy_now'); +-- 8.当前用户无权限,设置整数类超表当前时间函数 +select set_integer_now_func('test_table_int', 'my_schema.dummy_now2', replace_if_exists => TRUE); +select set_integer_now_func('test_table_int', 'dummy_now3', replace_if_exists => TRUE); +-- 9.设置整数类超表指定replace_if_exists参数为true +select set_integer_now_func('test_table_int', 'my_user_schema.dummy_now4', replace_if_exists => TRUE); +10.再次通过og初始用户role登入pg兼容库 +\c test1 lhy +-- 11.查看超表分区信息 +ALTER SCHEMA my_user_schema RENAME TO my_new_schema; +select * from _timescaledb_catalog.dimension WHERE hypertable_id = 88; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ShowBlocksInSchema.sql b/contrib/timescaledb/regress/sql/ShowBlocksInSchema.sql new file mode 100644 index 000000000..079b3a555 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ShowBlocksInSchema.sql @@ -0,0 +1,15 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +-- 2.插入数据 +insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1); +-- 3.查看关联模式的chunk + \dt "chunk_schema".* + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/TableDataMigrateSuccess.sql b/contrib/timescaledb/regress/sql/TableDataMigrateSuccess.sql new file mode 100644 index 000000000..724ccf00e --- /dev/null +++ b/contrib/timescaledb/regress/sql/TableDataMigrateSuccess.sql @@ -0,0 +1,14 @@ +create extension timescaledb; + +-- 1.创建表并插入数据 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_migrate; +create table test_schema.test_migrate(time timestamp, temp float); +insert into test_schema.test_migrate VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +select * from only test_schema.test_migrate; +-- 2.转换为超表 +select create_hypertable('test_schema.test_migrate', 'time', migrate_data => true); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/TableDataNoMigrateError.sql b/contrib/timescaledb/regress/sql/TableDataNoMigrateError.sql new file mode 100644 index 000000000..837fb95f2 --- /dev/null +++ b/contrib/timescaledb/regress/sql/TableDataNoMigrateError.sql @@ -0,0 +1,14 @@ +create extension timescaledb; + +-- 1.创建表并插入数据 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_migrate; +create table test_schema.test_migrate(time timestamp, temp float); +insert into test_schema.test_migrate VALUES ('2004-10-19 10:23:54+02', 1.0), ('2004-12-19 10:23:54+02', 2.0); +select * from only test_schema.test_migrate; +-- 2.转换为超表 +select create_hypertable('test_schema.test_migrate', 'time'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/TablespaceFunctionHandling.sql b/contrib/timescaledb/regress/sql/TablespaceFunctionHandling.sql new file mode 100644 index 000000000..29bdcf9ab --- /dev/null +++ b/contrib/timescaledb/regress/sql/TablespaceFunctionHandling.sql @@ -0,0 +1,57 @@ +create extension timescaledb; + +-- 1.创建普通表并转换为超表 +\c test1 lhy; +SET client_min_messages = ERROR; +drop table if exists hyper_in_space cascade; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +CREATE TABLE hyper_in_space(time bigint, temp float, device int) TABLESPACE tablespace1; +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); + +-- 2.插入数据 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); + +-- 3.detach_tablespace分离超表的表空间tablespace1 +SELECT detach_tablespace('tablespace1', 'hyper_in_space'); + +-- 4.再次插入数据 +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (7, 23, 1); + +-- 5.attach_tablespace在超表添加默认表空间与tablespace2 +SELECT attach_tablespace('pg_default', 'hyper_in_space'); +SELECT attach_tablespace('tablespace2', 'hyper_in_space'); + +-- 6.查看超表hyper_in_space、超表的chunk的表空间 +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + +-- 7.系统表_timescaledb_catalog.tablespace查看超表的表空间 +SELECT * FROM _timescaledb_catalog.tablespace; + +-- 8.再次插入数据后查看超表hyper_in_space、chunk的表空间 +INSERT INTO hyper_in_space(time, temp, device) VALUES (12, 22, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (13, 23, 2); +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + +-- 9.分离超表的默认表空间 +SELECT detach_tablespace('pg_default', 'hyper_in_space'); + +-- 10.通过alter table设置超表的表空间为默认表空间并通过pg_tables表查看超表及子表的表空间 +ALTER TABLE hyper_in_space SET TABLESPACE pg_default; +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + +-- 11.分离超表hyper_in_space的默认表空间并删除超表 +SELECT detach_tablespace('pg_default', 'hyper_in_space'); +DROP TABLE hyper_in_space; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/TablespaceToHypertable.sql b/contrib/timescaledb/regress/sql/TablespaceToHypertable.sql new file mode 100644 index 000000000..5b3605b00 --- /dev/null +++ b/contrib/timescaledb/regress/sql/TablespaceToHypertable.sql @@ -0,0 +1,32 @@ +create extension timescaledb; + +-- 1.创建普通表并转换为超表 +\c test1 lhy; +SET client_min_messages = ERROR; +DROP TABLESPACE IF EXISTS tablespace1; +DROP TABLESPACE IF EXISTS tablespace2; +SET client_min_messages = NOTICE; +CREATE TABLESPACE tablespace1 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace1'; +CREATE TABLESPACE tablespace2 OWNER lhy1 location '/home/lhy/og_dev/openGauss-server/contrib/timescaledb/test/tablespace2'; +CREATE TABLE hyper_in_space(time bigint, temp float, device int) TABLESPACE tablespace1; +SELECT create_hypertable('hyper_in_space', 'time', 'device', 4, chunk_time_interval=>1); + +-- 2.插入数据后查看表空间下的表信息 +INSERT INTO hyper_in_space(time, temp, device) VALUES (1, 20, 1); +INSERT INTO hyper_in_space(time, temp, device) VALUES (3, 21, 2); +INSERT INTO hyper_in_space(time, temp, device) VALUES (5, 23, 1); +SELECT tablename, tablespace FROM pg_tables +WHERE tablename = 'hyper_in_space' OR tablename ~ '_hyper_\d+_\d+_chunk' ORDER BY tablename; + +-- 3.超表hyper_in_space附加到tablespace2表空间 +SELECT attach_tablespace('tablespace2', 'hyper_in_space'); + +-- 4.超表附加的表空间大于1个时,设置超表的表空间 +ALTER TABLE hyper_in_space SET TABLESPACE tablespace1; + +-- 5.分离超表的表空间 +SELECT detach_tablespace('tablespace2', 'hyper_in_space'); +SELECT * FROM _timescaledb_catalog.tablespace; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/TestAddMultipleDimensions.sql b/contrib/timescaledb/regress/sql/TestAddMultipleDimensions.sql new file mode 100644 index 000000000..1ba9a543e --- /dev/null +++ b/contrib/timescaledb/regress/sql/TestAddMultipleDimensions.sql @@ -0,0 +1,18 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +-- 2.添加分区维度 +select add_dimension('test_schema.test_table', 'location', 4); +-- 3.再次添加分区维度 +select add_dimension('test_schema.test_table', 'id', chunk_time_interval => 1000); +-- 4.查看超表信息及分区维度信息 +select * from _timescaledb_catalog.hypertable where table_name = 'test_table'; +select * from _timescaledb_catalog.dimension; + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/TestTimeDimensionPartition.sql b/contrib/timescaledb/regress/sql/TestTimeDimensionPartition.sql new file mode 100644 index 000000000..2d98c67e3 --- /dev/null +++ b/contrib/timescaledb/regress/sql/TestTimeDimensionPartition.sql @@ -0,0 +1,16 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy1 password 'Test@123'; +create table test_schema.test_1dim(time timestamp, temp float); +select create_hypertable('test_schema.test_1dim', 'time'); +-- 2.查看超表创建信息 +SELECT * FROM _timescaledb_internal.get_create_command('test_1dim'); +-- 3.查看test_schema模式下的表 +\dt "test_schema".* +-- 4.指定if_not_exists为true再次创建超表 +select create_hypertable('test_schema.test_1dim', 'time', if_not_exists => true); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidFunctionAddPartitionSuccess.sql b/contrib/timescaledb/regress/sql/ValidFunctionAddPartitionSuccess.sql new file mode 100755 index 000000000..2a360aaa9 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidFunctionAddPartitionSuccess.sql @@ -0,0 +1,21 @@ +create extension timescaledb; + +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +CREATE OR REPLACE FUNCTION time_partfunc(source text) + RETURNS TIMESTAMPTZ LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN timezone('UTC', to_timestamp(source)); +END +$BODY$; +-- 2.使用自定义函数创建超表 +drop table if exists test_schema.open_dim_part_func; +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'time_partfunc'); +-- 3.新增超表的分区维度 +SELECT add_dimension('test_schema.open_dim_part_func', 'event_time', chunk_time_interval => interval '1 day', partitioning_func => 'time_partfunc'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidFunctionHypertableCreationSuccess.sql b/contrib/timescaledb/regress/sql/ValidFunctionHypertableCreationSuccess.sql new file mode 100755 index 000000000..4efc9bee1 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidFunctionHypertableCreationSuccess.sql @@ -0,0 +1,19 @@ +create extension timescaledb; + +-- 1.创建自定义函数 +\c test1 +set role lhy password 'Test@123'; +CREATE OR REPLACE FUNCTION time_partfunc(source text) + RETURNS TIMESTAMPTZ LANGUAGE PLPGSQL IMMUTABLE AS +$BODY$ +BEGIN + RETURN timezone('UTC', to_timestamp(source)); +END +$BODY$; +-- 2.使用自定义函数创建超表 +drop table if exists test_schema.open_dim_part_func; +CREATE TABLE test_schema.open_dim_part_func(time text, temp float8, device text, event_time text); +SELECT create_hypertable('test_schema.open_dim_part_func', 'time', time_partitioning_func => 'time_partfunc'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateAddBigIntDimension.sql b/contrib/timescaledb/regress/sql/ValidateAddBigIntDimension.sql new file mode 100644 index 000000000..de389dec2 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateAddBigIntDimension.sql @@ -0,0 +1,17 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy password 'Test@123'; +drop table if exists dim_test_time; +CREATE TABLE dim_test_time(time TIMESTAMPTZ, time2 TIMESTAMPTZ, time3 BIGINT, temp float8, device int, location int); +SELECT create_hypertable('dim_test_time', 'time'); +-- 2.使用时间间隔方式,新增bigint作为分区维度,合理报错 +SELECT add_dimension('dim_test_time', 'time3', chunk_time_interval => INTERVAL '1 day'); +-- 3.使用字符串,新增bigint作为分区维度,合理报错 +SELECT add_dimension('dim_test_time', 'time3', chunk_time_interval => 'foo'::TEXT); +-- 4.使用显式新增分区维度成功 +SELECT add_dimension('dim_test_time', 'time3', chunk_time_interval => 500); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateAddDimensionExplicitType.sql b/contrib/timescaledb/regress/sql/ValidateAddDimensionExplicitType.sql new file mode 100644 index 000000000..46890f05b --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateAddDimensionExplicitType.sql @@ -0,0 +1,11 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +CREATE TABLE dim_test_time2(time TIMESTAMPTZ, time2 TIMESTAMPTZ, temp float8, device int, location int); +SELECT create_hypertable('dim_test_time2', 'time'); +-- 2.add_dimension为TIMESTAMPTZ列使用显式类型 +SELECT add_dimension('dim_test_time2', 'time2', chunk_time_interval => 500); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateAddDimensionIfNotExists.sql b/contrib/timescaledb/regress/sql/ValidateAddDimensionIfNotExists.sql new file mode 100644 index 000000000..360cbe7e3 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateAddDimensionIfNotExists.sql @@ -0,0 +1,14 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +drop table if exists dim_test_time2; +CREATE TABLE dim_test_time2(time TIMESTAMPTZ, time2 TIMESTAMPTZ, temp float8, device int, location int); +SELECT create_hypertable('dim_test_time2', 'time'); +-- 2.add_dimension为TIMESTAMPTZ列使用显式类型 +SELECT add_dimension('dim_test_time2', 'time2', chunk_time_interval => 500); +-- 3.指定if_not_exists为true重复添加分区维度给出提示信息 +SELECT add_dimension('dim_test_time2', 'time2', chunk_time_interval => 500, if_not_exists => true); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/ValidateAddDimensionWithInterval.sql b/contrib/timescaledb/regress/sql/ValidateAddDimensionWithInterval.sql new file mode 100644 index 000000000..5d18ab0be --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateAddDimensionWithInterval.sql @@ -0,0 +1,12 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +set role lhy password 'Test@123'; +CREATE TABLE dim_test_time(time TIMESTAMPTZ, time2 TIMESTAMPTZ, time3 BIGINT, temp float8, device int, location int); +SELECT create_hypertable('dim_test_time', 'time'); +-- 2.使用时间间隔创建分区维度 +SELECT add_dimension('dim_test_time', 'time2', chunk_time_interval => INTERVAL '1 day'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateConflictingPartitionParamsError.sql b/contrib/timescaledb/regress/sql/ValidateConflictingPartitionParamsError.sql new file mode 100644 index 000000000..5fb7a62ff --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateConflictingPartitionParamsError.sql @@ -0,0 +1,12 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +-- 2.同时指定number_partitions、chunk_time_interval参数添加分区维度 +select add_dimension('test_schema.test_table', 'id2', number_partitions => 2, chunk_time_interval => 1000); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateCreateCommand.sql b/contrib/timescaledb/regress/sql/ValidateCreateCommand.sql new file mode 100644 index 000000000..9cd391663 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateCreateCommand.sql @@ -0,0 +1,29 @@ +create extension timescaledb; + +-- 1.创建test.execute_sql测试函数 +\c test1 lhy +CREATE SCHEMA IF NOT EXISTS test; +GRANT USAGE ON SCHEMA test TO PUBLIC; +CREATE OR REPLACE FUNCTION test.execute_sql(cmd TEXT) +RETURNS TEXT LANGUAGE PLPGSQL AS $BODY$ +BEGIN + EXECUTE cmd; + RETURN cmd; +END +$BODY$; +-- 2.创建超表 +set role lhy1 password 'Test@123'; +DROP TABLE if exists test_schema.test_sql_cmd CASCADE; +CREATE TABLE test_schema.test_sql_cmd(time TIMESTAMPTZ, temp FLOAT8, device_id TEXT, device_type TEXT, location TEXT, id INT, id2 INT); +SELECT create_hypertable('test_schema.test_sql_cmd','time'); +-- 3.验证get_create_command命令 +SELECT * FROM _timescaledb_internal.get_create_command('test_sql_cmd'); +SELECT _timescaledb_internal.get_create_command('test_sql_cmd') AS create_cmd; +-- 4.删除超表,创建普通表 +DROP TABLE test_schema.test_sql_cmd CASCADE; +CREATE TABLE test_schema.test_sql_cmd(time TIMESTAMPTZ, temp FLOAT8, device_id TEXT, device_type TEXT, location TEXT, id INT, id2 INT); +-- 5.test.execute_sql测试函数验证 +SELECT test.execute_sql(:'create_cmd'); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateDataExistsDimensionError.sql b/contrib/timescaledb/regress/sql/ValidateDataExistsDimensionError.sql new file mode 100644 index 000000000..e4e596caa --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateDataExistsDimensionError.sql @@ -0,0 +1,20 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +-- 2.新增分区维度 +select add_dimension('test_schema.test_table', 'location', 2); +-- 3.插入数据 +insert into test_schema.test_table values (123456789, 23.8, 'blue', 'type1', 'nyc', 1, 1); +-- 4.添加分区维度 +select add_dimension('test_schema.test_table', 'device_type', 2); +-- 5.if_not_exists参数设置为true添加分区维度 +select add_dimension('test_schema.test_table', 'device_type', 2, if_not_exists => true); +-- 6.if_not_exists参数设置为true,添加已有分区维度 +select add_dimension('test_schema.test_table', 'location', 2, if_not_exists => true); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateDuplicateDimensionError.sql b/contrib/timescaledb/regress/sql/ValidateDuplicateDimensionError.sql new file mode 100644 index 000000000..52ae79599 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateDuplicateDimensionError.sql @@ -0,0 +1,13 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +-- 2.重复增加分区维度 +select add_dimension('test_schema.test_table', 'location', 2); +select add_dimension('test_schema.test_table', 'location', 2); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateMissingFieldError.sql b/contrib/timescaledb/regress/sql/ValidateMissingFieldError.sql new file mode 100644 index 000000000..6f87e5eb4 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateMissingFieldError.sql @@ -0,0 +1,12 @@ +create extension timescaledb; + +-- 1.创建超表 +\c test1 +drop table if exists test_schema.test_table; +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); +select * from create_hypertable('test_schema.test_table', 'time', 'device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'), associated_schema_name => 'chunk_schema'); +-- 2.超表的列字段不存在,添加分区维度合理报错 +SELECT add_dimension('test_schema.test_table', 'nope', 2); + +\c test1 lhy; +drop extension timescaledb cascade; diff --git a/contrib/timescaledb/regress/sql/ValidatePartitionDimensionAddFail.sql b/contrib/timescaledb/regress/sql/ValidatePartitionDimensionAddFail.sql new file mode 100644 index 000000000..3ab7fcc30 --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidatePartitionDimensionAddFail.sql @@ -0,0 +1,10 @@ +create extension timescaledb; + +-- 1.建表 +\c test1 +CREATE TABLE not_hypertable(time TIMESTAMPTZ, temp float8, device int, location int); +-- 2.添加分区维度 +SELECT add_dimension('not_hypertable', 'time', chunk_time_interval => 500); + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/ValidateRegularTableHypertableError.sql b/contrib/timescaledb/regress/sql/ValidateRegularTableHypertableError.sql new file mode 100644 index 000000000..696d3501b --- /dev/null +++ b/contrib/timescaledb/regress/sql/ValidateRegularTableHypertableError.sql @@ -0,0 +1,23 @@ +create extension timescaledb; + +-- 1.创建role及schema +\c test1 +CREATE ROLE lhy1 IDENTIFIED BY 'Test@123'; +CREATE ROLE lhy2 IDENTIFIED BY 'Test@123'; +CREATE SCHEMA test_schema AUTHORIZATION lhy1; +CREATE SCHEMA chunk_schema AUTHORIZATION lhy2; + +-- 2.切换至role1 +set role lhy1 password 'Test@123'; + +-- 3.创建普通表 +create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int); + +-- 4.get_create_command查看非超表合理报错 +SELECT * FROM _timescaledb_internal.get_create_command('test_table'); + +-- 5.查看模式名test_schema下的表 + \dt "test_schema".* + +\c test1 lhy; +drop extension timescaledb cascade; \ No newline at end of file diff --git a/contrib/timescaledb/regress/sql/lhy1.sql b/contrib/timescaledb/regress/sql/lhy1.sql new file mode 100755 index 000000000..387c4535d --- /dev/null +++ b/contrib/timescaledb/regress/sql/lhy1.sql @@ -0,0 +1,2 @@ +create user lhy1 with password 'Test@123'; +create user lhy2 with password 'Test@123'; diff --git a/contrib/timescaledb/temp-config.conf b/contrib/timescaledb/temp-config.conf new file mode 100644 index 000000000..cf4aa9d04 --- /dev/null +++ b/contrib/timescaledb/temp-config.conf @@ -0,0 +1 @@ +shared_preload_libraries = '/home/lhy/self_detection/libs/timescaledb' \ No newline at end of file diff --git a/contrib/timescaledb/timescaledb--1.7.4.sql b/contrib/timescaledb/timescaledb--1.7.4.sql new file mode 100755 index 000000000..5c3aeb267 --- /dev/null +++ b/contrib/timescaledb/timescaledb--1.7.4.sql @@ -0,0 +1,2493 @@ +-- 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. + +CREATE SCHEMA _timescaledb_catalog; +CREATE SCHEMA _timescaledb_internal; +CREATE SCHEMA _timescaledb_cache; +CREATE SCHEMA _timescaledb_config; +GRANT USAGE ON SCHEMA _timescaledb_cache, _timescaledb_catalog, _timescaledb_internal, _timescaledb_config TO PUBLIC; +-- 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. + +-- Postgres has special types such as timestamp, date, timestamptz, etc. to +-- represent logical time values. On top of these, TimescaleDB allows integers +-- to represent logical time values. Postgres INTERVAL types are suited only for +-- logical time types in postgres. The type defined below is an INTERVAL equivalent +-- for TimescaleDB and enables to represent time intervals for both postgres time +-- type valued and integer valued time columns. +CREATE TYPE _timescaledb_catalog.ts_interval AS ( + is_time_interval BOOLEAN, + time_interval INTERVAL, + integer_interval BIGINT + ); + +-- +-- The general compressed_data type; +-- + +CREATE TYPE _timescaledb_internal.compressed_data; + +-- 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. + + +-- Functions have to be run in 2 places: +-- 1) In pre-install between types.pre.sql and types.post.sql to set up the types. +-- 2) On every update to make sure the function points to the correct versioned.so + + +-- PostgreSQL composite types do not support constraint checks. That is why any table having a ts_interval column must use the following +-- function for constraint validation. +-- This function needs to be defined before executing pre_install/tables.sql because it is used as +-- validation constraint for columns of type ts_interval. +CREATE OR REPLACE FUNCTION _timescaledb_internal.valid_ts_interval(invl _timescaledb_catalog.ts_interval) +RETURNS BOOLEAN AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_valid_ts_interval' LANGUAGE C VOLATILE STRICT; + +--the textual input/output is simply base64 encoding of the binary representation +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_in(CSTRING) + RETURNS _timescaledb_internal.compressed_data + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_in' + LANGUAGE C IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_out(_timescaledb_internal.compressed_data) + RETURNS CSTRING + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_out' + LANGUAGE C IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_send(_timescaledb_internal.compressed_data) + RETURNS BYTEA + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_send' + LANGUAGE C IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_recv(internal) + RETURNS _timescaledb_internal.compressed_data + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_recv' + LANGUAGE C IMMUTABLE STRICT; +-- 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. + +-- +-- The general compressed_data type; +-- +CREATE TYPE _timescaledb_internal.compressed_data ( + INTERNALLENGTH = VARIABLE, + STORAGE = EXTERNAL, + ALIGNMENT = DOUBLE, --needed for alignment in ARRAY type compression + INPUT = _timescaledb_internal.compressed_data_in, + OUTPUT = _timescaledb_internal.compressed_data_out, + RECEIVE = _timescaledb_internal.compressed_data_recv, + SEND = _timescaledb_internal.compressed_data_send +); +-- 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. + +--NOTICE: UPGRADE-SCRIPT-NEEDED contents in this file are not auto-upgraded. + +-- This file contains table definitions for various abstractions and data +-- structures for representing hypertables and lower-level concepts. + +-- Hypertable +-- ========== +-- +-- The hypertable is an abstraction that represents a table that is +-- partitioned in N dimensions, where each dimension maps to a column +-- in the table. A dimension can either be 'open' or 'closed', which +-- reflects the scheme that divides the dimension's keyspace into +-- "slices". +-- +-- Conceptually, a partition -- called a "chunk", is a hypercube in +-- the N-dimensional space. A chunk stores a subset of the +-- hypertable's tuples on disk in its own distinct table. The slices +-- that span the chunk's hypercube each correspond to a constraint on +-- the chunk's table, enabling constraint exclusion during queries on +-- the hypertable's data. +-- +-- +-- Open dimensions +------------------ +-- An open dimension does on-demand slicing, creating a new slice +-- based on a configurable interval whenever a tuple falls outside the +-- existing slices. Open dimensions fit well with columns that are +-- incrementally increasing, such as time-based ones. +-- +-- Closed dimensions +-------------------- +-- A closed dimension completely divides its keyspace into a +-- configurable number of slices. The number of slices can be +-- reconfigured, but the new partitioning only affects newly created +-- chunks. +-- +CREATE TABLE _timescaledb_catalog.hypertable ( + id SERIAL PRIMARY KEY, + schema_name NAME NOT NULL CHECK (schema_name != '_timescaledb_catalog'), + table_name NAME NOT NULL, + associated_schema_name NAME NOT NULL, + associated_table_prefix NAME NOT NULL, + num_dimensions SMALLINT NOT NULL, + chunk_sizing_func_schema NAME NOT NULL, + chunk_sizing_func_name NAME NOT NULL, + chunk_target_size BIGINT NOT NULL CHECK (chunk_target_size >= 0), -- size in bytes + compressed BOOLEAN NOT NULL DEFAULT false, + compressed_hypertable_id INTEGER REFERENCES _timescaledb_catalog.hypertable(id), + UNIQUE (id, schema_name), + UNIQUE (schema_name, table_name), + UNIQUE (associated_schema_name, associated_table_prefix), + constraint hypertable_dim_compress_check check ( num_dimensions > 0 or compressed = true ), + constraint hypertable_compress_check check ( compressed = false or (compressed = true and compressed_hypertable_id is null )) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable', ''); +SELECT pg_catalog.pg_extension_config_dump(pg_get_serial_sequence('_timescaledb_catalog.hypertable','id'), ''); + +-- The tablespace table maps tablespaces to hypertables. +-- This allows spreading a hypertable's chunks across multiple disks. +CREATE TABLE _timescaledb_catalog.tablespace ( + id SERIAL PRIMARY KEY, + hypertable_id INT NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + tablespace_name NAME NOT NULL, + UNIQUE (hypertable_id, tablespace_name) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.tablespace', ''); + +-- A dimension represents an axis along which data is partitioned. +CREATE TABLE _timescaledb_catalog.dimension ( + id SERIAL NOT NULL PRIMARY KEY, + hypertable_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + column_name NAME NOT NULL, + column_type REGTYPE NOT NULL, + aligned BOOLEAN NOT NULL, + -- closed dimensions + num_slices SMALLINT NULL, + partitioning_func_schema NAME NULL, + partitioning_func NAME NULL, + -- open dimensions (e.g., time) + interval_length BIGINT NULL CHECK(interval_length IS NULL OR interval_length > 0), + integer_now_func_schema NAME NULL, + integer_now_func NAME NULL, + CHECK ( + (partitioning_func_schema IS NULL AND partitioning_func IS NULL) OR + (partitioning_func_schema IS NOT NULL AND partitioning_func IS NOT NULL) + ), + CHECK ( + (num_slices IS NULL AND interval_length IS NOT NULL) OR + (num_slices IS NOT NULL AND interval_length IS NULL) + ), + CHECK ( + (integer_now_func_schema IS NULL AND integer_now_func IS NULL) OR + (integer_now_func_schema IS NOT NULL AND integer_now_func IS NOT NULL) + ), + UNIQUE (hypertable_id, column_name) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.dimension', ''); +SELECT pg_catalog.pg_extension_config_dump(pg_get_serial_sequence('_timescaledb_catalog.dimension','id'), ''); + +-- A dimension slice defines a keyspace range along a dimension axis. +CREATE TABLE _timescaledb_catalog.dimension_slice ( + id SERIAL NOT NULL PRIMARY KEY, + dimension_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.dimension(id) ON DELETE CASCADE, + range_start BIGINT NOT NULL, + range_end BIGINT NOT NULL, + CHECK (range_start <= range_end), + UNIQUE (dimension_id, range_start, range_end) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.dimension_slice', ''); +SELECT pg_catalog.pg_extension_config_dump(pg_get_serial_sequence('_timescaledb_catalog.dimension_slice','id'), ''); + +-- A chunk is a partition (hypercube) in an N-dimensional +-- hyperspace. Each chunk is associated with N constraints that define +-- the chunk's hypercube. Tuples that fall within the chunk's +-- hypercube are stored in the chunk's data table, as given by +-- 'schema_name' and 'table_name'. +CREATE TABLE _timescaledb_catalog.chunk ( + id SERIAL NOT NULL PRIMARY KEY, + hypertable_id INT NOT NULL REFERENCES _timescaledb_catalog.hypertable(id), + schema_name NAME NOT NULL, + table_name NAME NOT NULL, + compressed_chunk_id INTEGER REFERENCES _timescaledb_catalog.chunk(id), + dropped BOOLEAN NOT NULL DEFAULT false, + UNIQUE (schema_name, table_name) +); +CREATE INDEX chunk_hypertable_id_idx +ON _timescaledb_catalog.chunk(hypertable_id); +CREATE INDEX chunk_compressed_chunk_id_idx +ON _timescaledb_catalog.chunk(compressed_chunk_id); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk', ''); +SELECT pg_catalog.pg_extension_config_dump(pg_get_serial_sequence('_timescaledb_catalog.chunk','id'), ''); + +-- A chunk constraint maps a dimension slice to a chunk. Each +-- constraint associated with a chunk will also be a table constraint +-- on the chunk's data table. +CREATE TABLE _timescaledb_catalog.chunk_constraint ( + chunk_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.chunk(id), + dimension_slice_id INTEGER NULL REFERENCES _timescaledb_catalog.dimension_slice(id), + constraint_name NAME NOT NULL, + hypertable_constraint_name NAME NULL, + UNIQUE(chunk_id, constraint_name) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_constraint', ''); +CREATE INDEX chunk_constraint_chunk_id_dimension_slice_id_idx +ON _timescaledb_catalog.chunk_constraint(chunk_id, dimension_slice_id); + +CREATE SEQUENCE _timescaledb_catalog.chunk_constraint_name; +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_constraint_name', ''); + +CREATE TABLE _timescaledb_catalog.chunk_index ( + chunk_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.chunk(id) ON DELETE CASCADE, + index_name NAME NOT NULL, + hypertable_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + hypertable_index_name NAME NOT NULL, + UNIQUE(chunk_id, index_name) +); +CREATE INDEX chunk_index_hypertable_id_hypertable_index_name_idx +ON _timescaledb_catalog.chunk_index(hypertable_id, hypertable_index_name); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_index', ''); + +-- Default jobs are given the id space [1,1000). User-installed jobs and any jobs created inside tests +-- are given the id space [1000, INT_MAX). That way, we do not pg_dump jobs that are always default-installed +-- inside other .sql scripts. This avoids insertion conflicts during pg_restore. + +CREATE SEQUENCE _timescaledb_config.bgw_job_id_seq MINVALUE 1000; +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_job_id_seq', ''); + +CREATE TABLE _timescaledb_config.bgw_job ( + id INTEGER PRIMARY KEY DEFAULT nextval('_timescaledb_config.bgw_job_id_seq'), + application_name NAME NOT NULL, + job_type NAME NOT NULL, + schedule_interval INTERVAL NOT NULL, + max_runtime INTERVAL NOT NULL, + max_retries INT NOT NULL, + retry_period INTERVAL NOT NULL, + CONSTRAINT valid_job_type CHECK (job_type IN ('telemetry_and_version_check_if_enabled', 'reorder', 'drop_chunks', 'continuous_aggregate', 'compress_chunks')) +); +ALTER SEQUENCE _timescaledb_config.bgw_job_id_seq OWNED BY _timescaledb_config.bgw_job.id; + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_job', 'WHERE id >= 1000'); + +CREATE TABLE _timescaledb_internal.bgw_job_stat ( + job_id INTEGER PRIMARY KEY REFERENCES _timescaledb_config.bgw_job(id) ON DELETE CASCADE, + last_start TIMESTAMPTZ NOT NULL DEFAULT NOW(), + last_finish TIMESTAMPTZ NOT NULL, + next_start TIMESTAMPTZ NOT NULL, + last_successful_finish TIMESTAMPTZ NOT NULL, + last_run_success BOOL NOT NULL, + total_runs BIGINT NOT NULL, + total_duration INTERVAL NOT NULL, + total_successes BIGINT NOT NULL, + total_failures BIGINT NOT NULL, + total_crashes BIGINT NOT NULL, + consecutive_failures INT NOT NULL, + consecutive_crashes INT NOT NULL +); +--The job_stat table is not dumped by pg_dump on purpose because +--the statistics probably aren't very meaningful across instances. + +--Now we define the argument tables for available BGW policies. +CREATE TABLE _timescaledb_config.bgw_policy_reorder ( + job_id INTEGER PRIMARY KEY REFERENCES _timescaledb_config.bgw_job(id) ON DELETE CASCADE, + hypertable_id INTEGER UNIQUE NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + hypertable_index_name NAME NOT NULL +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_policy_reorder', ''); + +CREATE TABLE _timescaledb_config.bgw_policy_drop_chunks ( + job_id INTEGER PRIMARY KEY REFERENCES _timescaledb_config.bgw_job(id) ON DELETE CASCADE, + hypertable_id INTEGER UNIQUE NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + older_than _timescaledb_catalog.ts_interval NOT NULL, + cascade BOOLEAN NOT NULL, + cascade_to_materializations BOOLEAN, + CONSTRAINT valid_older_than CHECK(_timescaledb_internal.valid_ts_interval(older_than)) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_policy_drop_chunks', ''); + +----- End BGW policy table definitions + +-- Now we define a special stats table for each job/chunk pair. This will be used by the scheduler +-- to determine whether to run a specific job on a specific chunk. +CREATE TABLE _timescaledb_internal.bgw_policy_chunk_stats ( + job_id INTEGER NOT NULL REFERENCES _timescaledb_config.bgw_job(id) ON DELETE CASCADE, + chunk_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.chunk(id) ON DELETE CASCADE, + num_times_job_run INTEGER, + last_time_job_run TIMESTAMPTZ, + UNIQUE(job_id,chunk_id) +); + +CREATE TABLE _timescaledb_catalog.metadata ( + key NAME NOT NULL PRIMARY KEY, + value TEXT NOT NULL, + include_in_telemetry BOOLEAN --//tsdb,本来是not null +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.metadata', $$WHERE key='exported_uuid'$$); + +CREATE TABLE _timescaledb_catalog.continuous_agg ( + mat_hypertable_id INTEGER PRIMARY KEY REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + raw_hypertable_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + user_view_schema NAME NOT NULL, + user_view_name NAME NOT NULL, + partial_view_schema NAME NOT NULL, + partial_view_name NAME NOT NULL, + bucket_width BIGINT NOT NULL, + job_id INTEGER UNIQUE NOT NULL REFERENCES _timescaledb_config.bgw_job(id) ON DELETE RESTRICT, + refresh_lag BIGINT NOT NULL, + direct_view_schema NAME NOT NULL, + direct_view_name NAME NOT NULL, + max_interval_per_job BIGINT NOT NULL, + ignore_invalidation_older_than BIGINT NOT NULL DEFAULT BIGINT '9223372036854775807', + materialized_only BOOL NOT NULL DEFAULT false, + UNIQUE(user_view_schema, user_view_name), + UNIQUE(partial_view_schema, partial_view_name) +); + +CREATE INDEX continuous_agg_raw_hypertable_id_idx + ON _timescaledb_catalog.continuous_agg(raw_hypertable_id); + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', ''); + +CREATE TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold( + hypertable_id INTEGER PRIMARY KEY REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + watermark BIGINT NOT NULL +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_invalidation_threshold', ''); + +CREATE TABLE _timescaledb_catalog.continuous_aggs_completed_threshold( + materialization_id INTEGER PRIMARY KEY + REFERENCES _timescaledb_catalog.continuous_agg(mat_hypertable_id) + ON DELETE CASCADE, + watermark BIGINT NOT NULL --exclusive (everything up to but not including watermark is done) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_completed_threshold', ''); + +-- this does not have an FK on the materialization table since INSERTs to this +-- table are performance critical +CREATE TABLE _timescaledb_catalog.continuous_aggs_hypertable_invalidation_log( + hypertable_id INTEGER NOT NULL, + modification_time BIGINT NOT NULL, --now time for txn when the raw table was modified + lowest_modified_value BIGINT NOT NULL, + greatest_modified_value BIGINT NOT NULL +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_hypertable_invalidation_log', ''); + +CREATE INDEX continuous_aggs_hypertable_invalidation_log_idx + ON _timescaledb_catalog.continuous_aggs_hypertable_invalidation_log (hypertable_id, lowest_modified_value ASC); + +-- per cagg copy of invalidation log +CREATE TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log( + materialization_id INTEGER + REFERENCES _timescaledb_catalog.continuous_agg(mat_hypertable_id) + ON DELETE CASCADE, + modification_time BIGINT NOT NULL, --now time for txn when the raw table was modified + lowest_modified_value BIGINT NOT NULL, + greatest_modified_value BIGINT NOT NULL +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_materialization_invalidation_log', ''); + +CREATE INDEX continuous_aggs_materialization_invalidation_log_idx + ON _timescaledb_catalog.continuous_aggs_materialization_invalidation_log (materialization_id, lowest_modified_value ASC); + +/* the source of this data is the enum from the source code that lists + * the algorithms. This table is NOT dumped. +*/ +CREATE TABLE _timescaledb_catalog.compression_algorithm( + id SMALLINT PRIMARY KEY, + version SMALLINT NOT NULL, + name NAME NOT NULL, + description TEXT +); + + +CREATE TABLE _timescaledb_catalog.hypertable_compression ( + hypertable_id INTEGER REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + attname NAME NOT NULL, + compression_algorithm_id SMALLINT REFERENCES _timescaledb_catalog.compression_algorithm(id), + segmentby_column_index SMALLINT , + orderby_column_index SMALLINT, + orderby_asc BOOLEAN, + orderby_nullsfirst BOOLEAN, + PRIMARY KEY (hypertable_id, attname), + UNIQUE (hypertable_id, segmentby_column_index), + UNIQUE (hypertable_id, orderby_column_index) +); + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_compression', ''); + +CREATE TABLE _timescaledb_catalog.compression_chunk_size ( + + chunk_id INTEGER REFERENCES _timescaledb_catalog.chunk(id) ON DELETE CASCADE, + compressed_chunk_id INTEGER REFERENCES _timescaledb_catalog.chunk(id) ON DELETE CASCADE, + uncompressed_heap_size BIGINT NOT NULL, + uncompressed_toast_size BIGINT NOT NULL, + uncompressed_index_size BIGINT NOT NULL, + compressed_heap_size BIGINT NOT NULL, + compressed_toast_size BIGINT NOT NULL, + compressed_index_size BIGINT NOT NULL, + PRIMARY KEY(chunk_id, compressed_chunk_id) +); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.compression_chunk_size', ''); + +CREATE TABLE _timescaledb_config.bgw_policy_compress_chunks( + job_id INTEGER PRIMARY KEY REFERENCES _timescaledb_config.bgw_job(id) ON DELETE CASCADE, + hypertable_id INTEGER UNIQUE NOT NULL REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + older_than _timescaledb_catalog.ts_interval NOT NULL, + CONSTRAINT valid_older_than CHECK(_timescaledb_internal.valid_ts_interval(older_than)) +); + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_policy_compress_chunks', ''); + + +-- Set table permissions +-- We need to grant SELECT to PUBLIC for all tables even those not +-- marked as being dumped because pg_dump will try to access all +-- tables initially to detect inheritance chains and then decide +-- which objects actually need to be dumped. +GRANT SELECT ON ALL TABLES IN SCHEMA _timescaledb_catalog TO PUBLIC; +GRANT SELECT ON ALL TABLES IN SCHEMA _timescaledb_config TO PUBLIC; +GRANT SELECT ON ALL TABLES IN SCHEMA _timescaledb_internal TO PUBLIC; +GRANT SELECT ON ALL SEQUENCES IN SCHEMA _timescaledb_catalog TO PUBLIC; +GRANT SELECT ON ALL SEQUENCES IN SCHEMA _timescaledb_config TO PUBLIC; +GRANT SELECT ON ALL SEQUENCES IN SCHEMA _timescaledb_internal TO PUBLIC; + +-- 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. + +--insert data for compression_algorithm -- +insert into _timescaledb_catalog.compression_algorithm( id, version, name, description) values +( 0, 1, 'COMPRESSION_ALGORITHM_NONE', 'no compression'), +( 1, 1, 'COMPRESSION_ALGORITHM_ARRAY', 'array'), +( 2, 1, 'COMPRESSION_ALGORITHM_DICTIONARY', 'dictionary'), +( 3, 1, 'COMPRESSION_ALGORITHM_GORILLA', 'gorilla'), +( 4, 1, 'COMPRESSION_ALGORITHM_DELTADELTA', 'deltadelta'); +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.restart_background_workers() +RETURNS BOOL +AS ' /home/lhy/self_detection/lib/timescaledb', 'ts_bgw_db_workers_restart' +LANGUAGE C VOLATILE; + +SELECT _timescaledb_internal.restart_background_workers(); +-- 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. + + +-- Functions have to be run in 2 places: +-- 1) In pre-install between types.pre.sql and types.post.sql to set up the types. +-- 2) On every update to make sure the function points to the correct versioned.so + + +-- PostgreSQL composite types do not support constraint checks. That is why any table having a ts_interval column must use the following +-- function for constraint validation. +-- This function needs to be defined before executing pre_install/tables.sql because it is used as +-- validation constraint for columns of type ts_interval. +CREATE OR REPLACE FUNCTION _timescaledb_internal.valid_ts_interval(invl _timescaledb_catalog.ts_interval) +RETURNS BOOLEAN AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_valid_ts_interval' LANGUAGE C VOLATILE STRICT; + +--the textual input/output is simply base64 encoding of the binary representation +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_in(CSTRING) + RETURNS _timescaledb_internal.compressed_data + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_in' + LANGUAGE C IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_out(_timescaledb_internal.compressed_data) + RETURNS CSTRING + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_out' + LANGUAGE C IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_send(_timescaledb_internal.compressed_data) + RETURNS BYTEA + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_send' + LANGUAGE C IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_data_recv(internal) + RETURNS _timescaledb_internal.compressed_data + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compressed_data_recv' + LANGUAGE C IMMUTABLE STRICT; +-- 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. + +-- Trigger that blocks INSERTs on the hypertable's root table +CREATE OR REPLACE FUNCTION _timescaledb_internal.insert_blocker() RETURNS trigger +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hypertable_insert_blocker' LANGUAGE C; + +-- Records mutations or INSERTs which would invalidate a continuous aggregate +CREATE OR REPLACE FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger() RETURNS TRIGGER +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_continuous_agg_invalidation_trigger' LANGUAGE C; + +CREATE OR REPLACE FUNCTION set_integer_now_func(hypertable REGCLASS, integer_now_func REGPROC, replace_if_exists BOOL = false) RETURNS VOID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hypertable_set_integer_now_func' +LANGUAGE C VOLATILE STRICT; +-- 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. + +-- Built-in function for calculating the next chunk interval when +-- using adaptive chunking. The function can be replaced by a +-- user-defined function with the same signature. +-- +-- The parameters passed to the function are as follows: +-- +-- dimension_id: the ID of the dimension to calculate the interval for +-- dimension_coord: the coordinate / point on the dimensional axis +-- where the tuple that triggered this chunk creation falls. +-- chunk_target_size: the target size in bytes that the chunk should have. +-- +-- The function should return the new interval in dimension-specific +-- time (ususally microseconds). +CREATE OR REPLACE FUNCTION _timescaledb_internal.calculate_chunk_interval( + dimension_id INTEGER, + dimension_coord BIGINT, + chunk_target_size BIGINT +) RETURNS BIGINT AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_calculate_chunk_interval' LANGUAGE C; + +-- Function for explicit chunk exclusion. Supply a record and an array +-- of chunk ids as input. +-- Intended to be used in WHERE clause. +-- An example: SELECT * FROM hypertable WHERE _timescaledb_internal.chunks_in(hypertable, ARRAY[1,2]); +-- +-- Use it with care as this function directly affects what chunks are being scanned for data. +-- Although this function is immutable (always returns true), we declare it here as volatile +-- so that the PostgreSQL optimizer does not try to evaluate/reduce it in the planner phase +CREATE OR REPLACE FUNCTION _timescaledb_internal.chunks_in(record RECORD, chunks INTEGER[]) RETURNS BOOL +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunks_in' LANGUAGE C VOLATILE STRICT; + +--given a chunk's relid, return the id. Error out if not a chunk relid. +CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_id_from_relid(relid OID) RETURNS INTEGER +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunk_id_from_relid' LANGUAGE C STABLE STRICT ; + +--trigger to block dml on a chunk -- +CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_dml_blocker() RETURNS trigger +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunk_dml_blocker' LANGUAGE C; +-- 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. + +--documentation of these function located in chunk_index.h +CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_index_clone(chunk_index_oid OID) RETURNS OID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunk_index_clone' LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_index_replace(chunk_index_oid_old OID, chunk_index_oid_new OID) RETURNS VOID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunk_index_replace' LANGUAGE C VOLATILE STRICT; +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.enterprise_enabled() RETURNS BOOLEAN +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_enterprise_enabled' LANGUAGE C; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.current_license_key() RETURNS TEXT +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_current_license_key' LANGUAGE C; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.tsl_loaded() RETURNS BOOLEAN +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_tsl_loaded' LANGUAGE C; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.license_expiration_time() RETURNS TIMESTAMPTZ +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_license_expiration_time' LANGUAGE C; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.print_license_expiration_info() RETURNS VOID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_print_tsl_license_expiration_info' LANGUAGE C; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.license_edition() RETURNS TEXT +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_license_edition' LANGUAGE C; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.current_db_set_license_key(new_key TEXT) RETURNS TEXT AS +$BODY$ +DECLARE + db text; +BEGIN + SELECT current_database() INTO db; + EXECUTE format('ALTER DATABASE %I SET timescaledb.license_key = %L', db, new_key); + EXECUTE format('SET SESSION timescaledb.license_key = %L', new_key); + PERFORM _timescaledb_internal.restart_background_workers(); + RETURN new_key; +END +$BODY$ +LANGUAGE PLPGSQL; + + +-- 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. + +-- This file contains utilities for time conversion. +CREATE OR REPLACE FUNCTION _timescaledb_internal.to_unix_microseconds(ts TIMESTAMPTZ) RETURNS BIGINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_pg_timestamp_to_unix_microseconds' LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.to_timestamp(unixtime_us BIGINT) RETURNS TIMESTAMPTZ + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_pg_unix_microseconds_to_timestamp' LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.to_timestamp_without_timezone(unixtime_us BIGINT) + RETURNS TIMESTAMP + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_pg_unix_microseconds_to_timestamp' + LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.to_date(unixtime_us BIGINT) + RETURNS DATE + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_pg_unix_microseconds_to_date' + LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.to_interval(unixtime_us BIGINT) RETURNS INTERVAL + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_pg_unix_microseconds_to_interval' LANGUAGE C IMMUTABLE STRICT ; + +-- Time can be represented in a hypertable as an int* (bigint/integer/smallint) or as a timestamp type ( +-- with or without timezones). In metatables and other internal systems all time values are stored as bigint. +-- Converting from int* columns to internal representation is a cast to bigint. +-- Converting from timestamps to internal representation is conversion to epoch (in microseconds). + +-- Gets the sql code for representing the literal for the given time value (in the internal representation) as the column_type. +CREATE OR REPLACE FUNCTION _timescaledb_internal.time_literal_sql( + time_value BIGINT, + column_type REGTYPE +) + RETURNS text LANGUAGE PLPGSQL STABLE AS +$BODY$ +DECLARE + ret text; +BEGIN + IF time_value IS NULL THEN + RETURN format('%L', NULL); + END IF; + CASE column_type + WHEN 'BIGINT'::regtype, 'INTEGER'::regtype, 'SMALLINT'::regtype THEN + RETURN format('%L', time_value); -- scale determined by user. + WHEN 'TIMESTAMP'::regtype THEN + --the time_value for timestamps w/o tz does not depend on local timezones. So perform at UTC. + RETURN format('TIMESTAMP %1$L', timezone('UTC',_timescaledb_internal.to_timestamp(time_value))); -- microseconds + WHEN 'TIMESTAMPTZ'::regtype THEN + -- assume time_value is in microsec + RETURN format('TIMESTAMPTZ %1$L', _timescaledb_internal.to_timestamp(time_value)); -- microseconds + WHEN 'DATE'::regtype THEN + RETURN format('%L', timezone('UTC',_timescaledb_internal.to_timestamp(time_value))::date); + ELSE + EXECUTE 'SELECT format(''%L'', $1::' || column_type::text || ')' into ret using time_value; + RETURN ret; + END CASE; +END +$BODY$; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.interval_to_usec( + chunk_interval INTERVAL +) +RETURNS BIGINT LANGUAGE SQL IMMUTABLE AS +$BODY$ + SELECT (int_sec * 1000000)::bigint from extract(epoch from chunk_interval) as int_sec; +$BODY$; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.time_to_internal(time_val ANYELEMENT) +RETURNS BIGINT AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_time_to_internal' LANGUAGE C VOLATILE STRICT; + +-- return the materialization watermark for a continuous aggregate materialization hypertable +-- returns NULL when no materialization has happened yet +CREATE OR REPLACE FUNCTION _timescaledb_internal.cagg_watermark(hypertable_id oid) +RETURNS INT8 LANGUAGE SQL AS +$BODY$ + + SELECT + watermark + FROM + _timescaledb_catalog.continuous_agg cagg + LEFT JOIN _timescaledb_catalog.continuous_aggs_completed_threshold completed ON completed.materialization_id = cagg.mat_hypertable_id + WHERE + cagg.mat_hypertable_id = $1; + +$BODY$ STABLE STRICT; + +-- 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. + +-- This file contains functions associated with creating new +-- hypertables. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.dimension_is_finite( + val BIGINT +) + RETURNS BOOLEAN LANGUAGE SQL IMMUTABLE AS +$BODY$ + --end values of bigint reserved for infinite + SELECT val > (-9223372036854775808)::bigint AND val < 9223372036854775807::bigint +$BODY$; + + +CREATE OR REPLACE FUNCTION _timescaledb_internal.dimension_slice_get_constraint_sql( + dimension_slice_id INTEGER +) + RETURNS TEXT LANGUAGE PLPGSQL VOLATILE AS +$BODY$ +DECLARE + dimension_slice_row _timescaledb_catalog.dimension_slice; + dimension_row _timescaledb_catalog.dimension; + dimension_def TEXT; + dimtype REGTYPE; + parts TEXT[]; +BEGIN + SELECT * INTO STRICT dimension_slice_row + FROM _timescaledb_catalog.dimension_slice + WHERE id = dimension_slice_id; + + SELECT * INTO STRICT dimension_row + FROM _timescaledb_catalog.dimension + WHERE id = dimension_slice_row.dimension_id; + + IF dimension_row.partitioning_func_schema IS NOT NULL AND + dimension_row.partitioning_func IS NOT NULL THEN + SELECT prorettype INTO STRICT dimtype + FROM pg_catalog.pg_proc pro + WHERE pro.oid = format('%I.%I', dimension_row.partitioning_func_schema, dimension_row.partitioning_func)::regproc::oid; + + dimension_def := format('%1$I.%2$I(%3$I)', + dimension_row.partitioning_func_schema, + dimension_row.partitioning_func, + dimension_row.column_name); + ELSE + dimension_def := format('%1$I', dimension_row.column_name); + dimtype := dimension_row.column_type; + END IF; + + IF dimension_row.num_slices IS NOT NULL THEN + + IF _timescaledb_internal.dimension_is_finite(dimension_slice_row.range_start) THEN + parts = parts || format(' %1$s >= %2$L ', dimension_def, dimension_slice_row.range_start); + END IF; + + IF _timescaledb_internal.dimension_is_finite(dimension_slice_row.range_end) THEN + parts = parts || format(' %1$s < %2$L ', dimension_def, dimension_slice_row.range_end); + END IF; + + IF array_length(parts, 1) = 0 THEN + RETURN NULL; + END IF; + return array_to_string(parts, 'AND'); + ELSE + --TODO: only works with time for now + IF _timescaledb_internal.time_literal_sql(dimension_slice_row.range_start, dimtype) = + _timescaledb_internal.time_literal_sql(dimension_slice_row.range_end, dimtype) THEN + RAISE 'time-based constraints have the same start and end values for column "%": %', + dimension_row.column_name, + _timescaledb_internal.time_literal_sql(dimension_slice_row.range_end, dimtype); + END IF; + + parts = ARRAY[]::text[]; + + IF _timescaledb_internal.dimension_is_finite(dimension_slice_row.range_start) THEN + parts = parts || format(' %1$s >= %2$s ', + dimension_def, + _timescaledb_internal.time_literal_sql(dimension_slice_row.range_start, dimtype)); + END IF; + + IF _timescaledb_internal.dimension_is_finite(dimension_slice_row.range_end) THEN + parts = parts || format(' %1$s < %2$s ', + dimension_def, + _timescaledb_internal.time_literal_sql(dimension_slice_row.range_end, dimtype)); + END IF; + + return array_to_string(parts, 'AND'); + END IF; +END +$BODY$; + +-- Outputs the create_hypertable command to recreate the given hypertable. +-- +-- This is currently used internally for our single hypertable backup tool +-- so that it knows how to restore the hypertable without user intervention. +-- +-- It only works for hypertables with up to 2 dimensions. +CREATE OR REPLACE FUNCTION _timescaledb_internal.get_create_command( + table_name NAME +) + RETURNS TEXT LANGUAGE PLPGSQL VOLATILE AS +$BODY$ +DECLARE + h_id INTEGER; + schema_name NAME; + time_column NAME; + time_interval BIGINT; + space_column NAME; + space_partitions INTEGER; + dimension_cnt INTEGER; + dimension_row record; + ret TEXT; + v_count INTEGER; +BEGIN + SELECT COUNT(*) + INTO v_count + FROM _timescaledb_catalog.hypertable AS h + WHERE h.table_name = get_create_command.table_name; + + IF v_count = 0 THEN + RAISE EXCEPTION 'hypertable "%" not found', table_name + USING ERRCODE = 'TS101'; + END IF; + + SELECT h.id, h.schema_name + FROM _timescaledb_catalog.hypertable AS h + WHERE h.table_name = get_create_command.table_name + INTO h_id, schema_name; + + SELECT COUNT(*) + FROM _timescaledb_catalog.dimension d + WHERE d.hypertable_id = h_id + INTO STRICT dimension_cnt; + + IF dimension_cnt > 2 THEN + RAISE EXCEPTION 'get_create_command only supports hypertables with up to 2 dimensions' + USING ERRCODE = 'TS101'; + END IF; + + FOR dimension_row IN + SELECT * + FROM _timescaledb_catalog.dimension d + WHERE d.hypertable_id = h_id + LOOP + IF dimension_row.interval_length IS NOT NULL THEN + time_column := dimension_row.column_name; + time_interval := dimension_row.interval_length; + ELSIF dimension_row.num_slices IS NOT NULL THEN + space_column := dimension_row.column_name; + space_partitions := dimension_row.num_slices; + END IF; + END LOOP; + + ret := format($$SELECT create_hypertable('%I.%I', '%s'$$, schema_name, table_name, time_column); + IF space_column IS NOT NULL THEN + ret := ret || format($$, '%I', %s$$, space_column, space_partitions); + END IF; + ret := ret || format($$, chunk_time_interval => %s, create_default_indexes=>FALSE);$$, time_interval); + + RETURN ret; +END +$BODY$; +-- 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. + +-- Creates a constraint on a chunk. +CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_constraint_add_table_constraint( + chunk_constraint_row _timescaledb_catalog.chunk_constraint +) + RETURNS VOID LANGUAGE PLPGSQL AS +$BODY$ +DECLARE + chunk_row _timescaledb_catalog.chunk; + hypertable_row _timescaledb_catalog.hypertable; + constraint_oid OID; + check_sql TEXT; + def TEXT; + indx_tablespace NAME; + tablespace_def TEXT; + constraint_exists BOOLEAN; + index_tablespace_exists BOOLEAN; + chunk_exists BOOLEAN; + hypertable_exists BOOLEAN; +BEGIN + -- 检查chunk是否存在 + SELECT EXISTS(SELECT 1 FROM _timescaledb_catalog.chunk c WHERE c.id = chunk_constraint_row.chunk_id) INTO chunk_exists; + IF chunk_exists THEN + SELECT * INTO chunk_row FROM _timescaledb_catalog.chunk c WHERE c.id = chunk_constraint_row.chunk_id; + ELSE + RAISE 'No chunk found for chunk_id %', chunk_constraint_row.chunk_id; + END IF; + + -- 检查hypertable是否存在 + SELECT EXISTS(SELECT 1 FROM _timescaledb_catalog.hypertable h WHERE h.id = chunk_row.hypertable_id) INTO hypertable_exists; + IF hypertable_exists THEN + SELECT * INTO hypertable_row FROM _timescaledb_catalog.hypertable h WHERE h.id = chunk_row.hypertable_id; + ELSE + RAISE 'No hypertable found for hypertable_id %', chunk_row.hypertable_id; + END IF; + + IF chunk_constraint_row.dimension_slice_id IS NOT NULL THEN + check_sql = _timescaledb_internal.dimension_slice_get_constraint_sql(chunk_constraint_row.dimension_slice_id); + IF check_sql IS NOT NULL THEN + def := format('CHECK (%s)', check_sql); + ELSE + def := NULL; + END IF; + ELSIF chunk_constraint_row.hypertable_constraint_name IS NOT NULL THEN + + SELECT EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = chunk_constraint_row.hypertable_constraint_name + AND conrelid = format('%I.%I', hypertable_row.schema_name, hypertable_row.table_name)::regclass::oid + ) INTO constraint_exists; + + IF constraint_exists THEN + SELECT oid INTO constraint_oid FROM pg_constraint + WHERE conname = chunk_constraint_row.hypertable_constraint_name + AND conrelid = format('%I.%I', hypertable_row.schema_name, hypertable_row.table_name)::regclass::oid; + ELSE + constraint_oid := NULL; + END IF; + + SELECT EXISTS ( + SELECT 1 FROM pg_constraint C, pg_class I, pg_tablespace T + WHERE C.oid = constraint_oid AND I.oid = C.conindid AND I.reltablespace = T.oid + ) INTO index_tablespace_exists; + + IF index_tablespace_exists THEN + SELECT T.spcname INTO indx_tablespace + FROM pg_constraint C, pg_class I, pg_tablespace T + WHERE C.oid = constraint_oid AND I.oid = C.conindid AND I.reltablespace = T.oid; + + tablespace_def := format(' USING INDEX TABLESPACE %I', indx_tablespace); + ELSE + tablespace_def := ''; + END IF; + def := pg_get_constraintdef(constraint_oid) || tablespace_def; + ELSE + RAISE 'unknown constraint type'; + END IF; + + IF def IS NOT NULL THEN + EXECUTE format( + $$ ALTER TABLE %I.%I ADD CONSTRAINT %I %s $$, + chunk_row.schema_name, chunk_row.table_name, chunk_constraint_row.constraint_name, def + ); + END IF; +END +$BODY$; +-- 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. + +-- Clone fk constraint from a hypertable +CREATE OR REPLACE FUNCTION _timescaledb_internal.hypertable_constraint_add_table_fk_constraint( + user_ht_constraint_name NAME, + user_ht_schema_name NAME, + user_ht_table_name NAME, + compress_ht_id INTEGER +) + RETURNS VOID LANGUAGE PLPGSQL AS +$BODY$ +DECLARE + compressed_ht_row _timescaledb_catalog.hypertable; + constraint_oid OID; + check_sql TEXT; + def TEXT; +BEGIN + SELECT * INTO STRICT compressed_ht_row FROM _timescaledb_catalog.hypertable h + WHERE h.id = compress_ht_id; + IF user_ht_constraint_name IS NOT NULL THEN + SELECT oid INTO STRICT constraint_oid FROM pg_constraint + WHERE conname=user_ht_constraint_name AND contype = 'f' AND + conrelid = format('%I.%I', user_ht_schema_name, user_ht_table_name)::regclass::oid; + def := pg_get_constraintdef(constraint_oid); + ELSE + RAISE 'unknown constraint type'; + END IF; + IF def IS NOT NULL THEN + EXECUTE format( + $$ ALTER TABLE %I.%I ADD CONSTRAINT %I %s $$, + compressed_ht_row.schema_name, compressed_ht_row.table_name, user_ht_constraint_name, def + ); + END IF; + +END +$BODY$; +-- 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. + +-- Deprecated partition hash function +CREATE OR REPLACE FUNCTION _timescaledb_internal.get_partition_for_key(val anyelement) + RETURNS int + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_get_partition_for_key' LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.get_partition_hash(val anyelement) + RETURNS int + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_get_partition_hash' LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.get_time_type(hypertable_id INTEGER) + RETURNS OID + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hypertable_get_time_type' LANGUAGE C STABLE STRICT; +-- 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. + +-- This file contains functions related to getting information about the +-- schema of a hypertable, including columns, their types, etc. + + +-- Check if a given table OID is a main table (i.e. the table a user +-- targets for SQL operations) for a hypertable +CREATE OR REPLACE FUNCTION _timescaledb_internal.is_main_table( + table_oid regclass +) + RETURNS bool LANGUAGE SQL STABLE AS +$BODY$ + SELECT EXISTS(SELECT 1 FROM _timescaledb_catalog.hypertable WHERE table_name = relname AND schema_name = nspname) + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + WHERE c.OID = table_oid; +$BODY$; + +-- Check if given table is a hypertable's main table +CREATE OR REPLACE FUNCTION _timescaledb_internal.is_main_table( + schema_name NAME, + table_name NAME +) + RETURNS BOOLEAN LANGUAGE SQL STABLE AS +$BODY$ + SELECT EXISTS( + SELECT 1 FROM _timescaledb_catalog.hypertable h + WHERE h.schema_name = is_main_table.schema_name AND + h.table_name = is_main_table.table_name + ); +$BODY$; + +-- Get a hypertable given its main table OID +CREATE OR REPLACE FUNCTION _timescaledb_internal.hypertable_from_main_table( + table_oid regclass +) + RETURNS _timescaledb_catalog.hypertable LANGUAGE SQL STABLE AS +$BODY$ + SELECT h.* + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + INNER JOIN _timescaledb_catalog.hypertable h ON (h.table_name = c.relname AND h.schema_name = n.nspname) + WHERE c.OID = table_oid; +$BODY$; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.main_table_from_hypertable( + hypertable_id int +) + RETURNS regclass LANGUAGE SQL STABLE AS +$BODY$ + SELECT format('%I.%I',h.schema_name, h.table_name)::regclass + FROM _timescaledb_catalog.hypertable h + WHERE id = hypertable_id; +$BODY$; + + +-- Get the name of the time column for a chunk. +-- +-- schema_name, table_name - name of the schema and table for the table represented by the crn. +CREATE OR REPLACE FUNCTION _timescaledb_internal.time_col_name_for_chunk( + schema_name NAME, + table_name NAME +) + RETURNS NAME LANGUAGE PLPGSQL STABLE AS +$BODY$ +DECLARE + time_col_name NAME; +BEGIN + SELECT h.time_column_name INTO STRICT time_col_name + FROM _timescaledb_catalog.hypertable h + INNER JOIN _timescaledb_catalog.chunk c ON (c.hypertable_id = h.id) + WHERE c.schema_name = time_col_name_for_chunk.schema_name AND + c.table_name = time_col_name_for_chunk.table_name; + RETURN time_col_name; +END +$BODY$; + +-- Get the type of the time column for a chunk. +-- +-- schema_name, table_name - name of the schema and table for the table represented by the crn. +CREATE OR REPLACE FUNCTION _timescaledb_internal.time_col_type_for_chunk( + schema_name NAME, + table_name NAME +) + RETURNS REGTYPE LANGUAGE PLPGSQL STABLE AS +$BODY$ +DECLARE + time_col_type REGTYPE; +BEGIN + SELECT h.time_column_type INTO STRICT time_col_type + FROM _timescaledb_catalog.hypertable h + INNER JOIN _timescaledb_catalog.chunk c ON (c.hypertable_id = h.id) + WHERE c.schema_name = time_col_type_for_chunk.schema_name AND + c.table_name = time_col_type_for_chunk.table_name; + RETURN time_col_type; +END +$BODY$; +-- 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. + +-- This file defines DDL functions for adding and manipulating hypertables. + +-- Converts a regular postgres table to a hypertable. +-- +-- main_table - The OID of the table to be converted +-- time_column_name - Name of the column that contains time for a given record +-- partitioning_column - Name of the column to partition data by +-- number_partitions - (Optional) Number of partitions for data +-- associated_schema_name - (Optional) Schema for internal hypertable tables +-- associated_table_prefix - (Optional) Prefix for internal hypertable table names +-- chunk_time_interval - (Optional) Initial time interval for a chunk +-- create_default_indexes - (Optional) Whether or not to create the default indexes +-- if_not_exists - (Optional) Do not fail if table is already a hypertable +-- partitioning_func - (Optional) The partitioning function to use for spatial partitioning +-- migrate_data - (Optional) Set to true to migrate any existing data in the table to chunks +-- chunk_target_size - (Optional) The target size for chunks (e.g., '1000MB', 'estimate', or 'off') +-- chunk_sizing_func - (Optional) A function to calculate the chunk time interval for new chunks +-- time_partitioning_func - (Optional) The partitioning function to use for "time" partitioning +CREATE OR REPLACE FUNCTION create_hypertable( + main_table REGCLASS, + time_column_name NAME, + partitioning_column NAME = NULL, + number_partitions INTEGER = NULL, + associated_schema_name NAME = NULL, + associated_table_prefix NAME = NULL, + chunk_time_interval ANYELEMENT = NULL::bigint, + create_default_indexes BOOLEAN = TRUE, + if_not_exists BOOLEAN = FALSE, + partitioning_func REGPROC = NULL, + migrate_data BOOLEAN = FALSE, + chunk_target_size TEXT = NULL, + chunk_sizing_func REGPROC = '_timescaledb_internal.calculate_chunk_interval'::regproc, + time_partitioning_func REGPROC = NULL +) RETURNS TABLE(hypertable_id INT, schema_name NAME, table_name NAME, created BOOL) AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hypertable_create' LANGUAGE C VOLATILE; + +-- Set adaptive chunking. To disable, set chunk_target_size => 'off'. +CREATE OR REPLACE FUNCTION set_adaptive_chunking( + hypertable REGCLASS, + chunk_target_size TEXT, + IN chunk_sizing_func REGPROC = '_timescaledb_internal.calculate_chunk_interval'::regproc, + OUT chunk_target_size BIGINT +) RETURNS RECORD AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunk_adaptive_set' LANGUAGE C VOLATILE; + +-- Update chunk_time_interval for a hypertable. +-- +-- main_table - The OID of the table corresponding to a hypertable whose time +-- interval should be updated +-- chunk_time_interval - The new time interval. For hypertables with integral +-- time columns, this must be an integral type. For hypertables with a +-- TIMESTAMP/TIMESTAMPTZ/DATE type, it can be integral which is treated as +-- microseconds, or an INTERVAL type. +CREATE OR REPLACE FUNCTION set_chunk_time_interval( + main_table REGCLASS, + chunk_time_interval ANYELEMENT, + dimension_name NAME = NULL +) RETURNS VOID AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_dimension_set_interval' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION set_number_partitions( + main_table REGCLASS, + number_partitions INTEGER, + dimension_name NAME = NULL +) RETURNS VOID AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_dimension_set_num_slices' LANGUAGE C VOLATILE; + +-- Drop chunks older than the given timestamp. If a hypertable name is given, +-- drop only chunks associated with this table. Any of the first three arguments +-- can be NULL meaning "all values". +CREATE OR REPLACE FUNCTION drop_chunks( + older_than "any" = NULL, + table_name NAME = NULL, + schema_name NAME = NULL, + cascade BOOLEAN = FALSE, + newer_than "any" = NULL, + verbose BOOLEAN = FALSE, + cascade_to_materializations BOOLEAN = NULL +) RETURNS SETOF TEXT AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunk_drop_chunks' +LANGUAGE C VOLATILE ; + +-- show chunks older than or newer than a specific time. +-- `hypertable` argument can be a valid hypertable or NULL. +-- In the latter case the function will try to list all +-- the chunks from all of the hypertables in the database. +-- older_than or newer_than or both can be NULL. +-- if `hypertable` argument is null but a time constraint is specified +-- through older_than or newer_than, the call will succeed +-- if and only if all the hypertables in the database +-- have the same type as the given time constraint argument +CREATE OR REPLACE FUNCTION show_chunks( + hypertable REGCLASS = NULL, + older_than "any" = NULL, + newer_than "any" = NULL +) RETURNS SETOF REGCLASS AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_chunk_show_chunks' +LANGUAGE C STABLE ; + +-- Add a dimension (of partitioning) to a hypertable +-- +-- main_table - OID of the table to add a dimension to +-- column_name - NAME of the column to use in partitioning for this dimension +-- number_partitions - Number of partitions, for non-time dimensions +-- interval_length - Size of intervals for time dimensions (can be integral or INTERVAL) +-- partitioning_func - Function used to partition the column +-- if_not_exists - If set, and the dimension already exists, generate a notice instead of an error +CREATE OR REPLACE FUNCTION add_dimension( + main_table REGCLASS, + column_name NAME, + number_partitions INTEGER = NULL, + chunk_time_interval ANYELEMENT = NULL::BIGINT, + partitioning_func REGPROC = NULL, + if_not_exists BOOLEAN = FALSE +) RETURNS TABLE(dimension_id INT, schema_name NAME, table_name NAME, column_name NAME, created BOOL) +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_dimension_add' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION attach_tablespace( + tablespace NAME, + hypertable REGCLASS, + if_not_attached BOOLEAN = false +) RETURNS VOID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_tablespace_attach' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION detach_tablespace( + tablespace NAME, + hypertable REGCLASS = NULL, + if_attached BOOLEAN = false +) RETURNS INTEGER +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_tablespace_detach' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION detach_tablespaces(hypertable REGCLASS) RETURNS INTEGER +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_tablespace_detach_all_from_hypertable' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION show_tablespaces(hypertable REGCLASS) RETURNS SETOF NAME +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_tablespace_show' LANGUAGE C VOLATILE STRICT; +-- 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. + +-- 注释到1221行 +DROP EVENT TRIGGER IF EXISTS timescaledb_ddl_command_end; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.process_ddl_event() RETURNS event_trigger +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_timescaledb_process_ddl_event' LANGUAGE C; + +--EVENT TRIGGER MUST exclude the ALTER EXTENSION tag. +CREATE EVENT TRIGGER timescaledb_ddl_command_end ON ddl_command_end +WHEN TAG IN ('ALTER TABLE','CREATE TRIGGER','CREATE TABLE','CREATE INDEX','ALTER INDEX', 'DROP TABLE', 'DROP INDEX') +EXECUTE PROCEDURE _timescaledb_internal.process_ddl_event(); + +DROP EVENT TRIGGER IF EXISTS timescaledb_ddl_sql_drop; +CREATE EVENT TRIGGER timescaledb_ddl_sql_drop ON sql_drop +EXECUTE PROCEDURE _timescaledb_internal.process_ddl_event(); +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.first_sfunc(internal, anyelement, "any") +RETURNS internal +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_first_sfunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.first_combinefunc(internal, internal) +RETURNS internal +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_first_combinefunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.last_sfunc(internal, anyelement, "any") +RETURNS internal +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_last_sfunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.last_combinefunc(internal, internal) +RETURNS internal +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_last_combinefunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.bookend_finalfunc(internal, anyelement, "any") +RETURNS anyelement +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_bookend_finalfunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.bookend_serializefunc(internal) +RETURNS bytea +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_bookend_serializefunc' +LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.bookend_deserializefunc(bytea, internal) +RETURNS internal +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_bookend_deserializefunc' +LANGUAGE C IMMUTABLE STRICT ; +-- 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. + +-- time_bucket returns the left edge of the bucket where ts falls into. +-- Buckets span an interval of time equal to the bucket_width and are aligned with the epoch. +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts TIMESTAMP) RETURNS TIMESTAMP + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_timestamp_bucket' LANGUAGE C IMMUTABLE ; + +-- bucketing of timestamptz happens at UTC time +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts TIMESTAMPTZ) RETURNS TIMESTAMPTZ + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_timestamptz_bucket' LANGUAGE C IMMUTABLE ; + +--bucketing on date should not do any timezone conversion +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts DATE) RETURNS DATE + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_date_bucket' LANGUAGE C IMMUTABLE ; + +--bucketing with origin +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts TIMESTAMP, origin TIMESTAMP) RETURNS TIMESTAMP + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_timestamp_bucket' LANGUAGE C IMMUTABLE ; +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts TIMESTAMPTZ, origin TIMESTAMPTZ) RETURNS TIMESTAMPTZ + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_timestamptz_bucket' LANGUAGE C IMMUTABLE ; +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts DATE, origin DATE) RETURNS DATE + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_date_bucket' LANGUAGE C IMMUTABLE ; + +-- bucketing of int +CREATE OR REPLACE FUNCTION time_bucket(bucket_width SMALLINT, ts SMALLINT) RETURNS SMALLINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_int16_bucket' LANGUAGE C IMMUTABLE ; +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INT, ts INT) RETURNS INT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_int32_bucket' LANGUAGE C IMMUTABLE ; +CREATE OR REPLACE FUNCTION time_bucket(bucket_width BIGINT, ts BIGINT) RETURNS BIGINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_int64_bucket' LANGUAGE C IMMUTABLE ; + +-- bucketing of int with offset +CREATE OR REPLACE FUNCTION time_bucket(bucket_width SMALLINT, ts SMALLINT, "offset" SMALLINT) RETURNS SMALLINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_int16_bucket' LANGUAGE C IMMUTABLE ; +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INT, ts INT, "offset" INT) RETURNS INT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_int32_bucket' LANGUAGE C IMMUTABLE ; +CREATE OR REPLACE FUNCTION time_bucket(bucket_width BIGINT, ts BIGINT, "offset" BIGINT) RETURNS BIGINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_int64_bucket' LANGUAGE C IMMUTABLE ; + +-- If an interval is given as the third argument, the bucket alignment is offset by the interval. +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts TIMESTAMP, "offset" INTERVAL) + RETURNS TIMESTAMP LANGUAGE SQL IMMUTABLE AS +$BODY$ + SELECT @extschema@.time_bucket(bucket_width, ts-"offset")+"offset"; +$BODY$; + +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts TIMESTAMPTZ, "offset" INTERVAL) + RETURNS TIMESTAMPTZ LANGUAGE SQL IMMUTABLE AS +$BODY$ + SELECT @extschema@.time_bucket(bucket_width, ts-"offset")+"offset"; +$BODY$; + +CREATE OR REPLACE FUNCTION time_bucket(bucket_width INTERVAL, ts DATE, "offset" INTERVAL) + RETURNS DATE LANGUAGE SQL IMMUTABLE AS +$BODY$ + SELECT (@extschema@.time_bucket(bucket_width, ts-"offset")+"offset")::date; +$BODY$; + +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.get_git_commit() RETURNS TEXT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_get_git_commit' LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.get_os_info() + RETURNS TABLE(sysname TEXT, version TEXT, release TEXT, version_pretty TEXT) + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_get_os_info' LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION get_telemetry_report(always_display_report boolean DEFAULT false) RETURNS TEXT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_get_telemetry_report' LANGUAGE C STABLE ; +-- 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. + +-- This file contains utility functions to get the relation size +-- of hypertables, chunks, and indexes on hypertables. + +-- Get relation size of hypertable +-- like pg_relation_size(hypertable) +-- (https://www.postgresql.org/docs/9.6/static/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE) +-- +-- main_table - hypertable to get size of +-- +-- Returns: +-- table_bytes - Disk space used by main_table (like pg_relation_size(main_table)) +-- index_bytes - Disk space used by indexes +-- toast_bytes - Disk space of toast tables +-- total_bytes - Total disk space used by the specified table, including all indexes and TOAST data + +CREATE OR REPLACE FUNCTION hypertable_relation_size( + main_table REGCLASS +) +RETURNS TABLE (table_bytes BIGINT, + index_bytes BIGINT, + toast_bytes BIGINT, + total_bytes BIGINT + ) LANGUAGE PLPGSQL STABLE STRICT + AS +$BODY$ +DECLARE + table_name NAME; + schema_name NAME; +BEGIN + SELECT relname, nspname + INTO STRICT table_name, schema_name + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + WHERE c.OID = main_table; + + RETURN QUERY EXECUTE format( + $$ + SELECT table_bytes, + index_bytes, + toast_bytes, + total_bytes + FROM ( + SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM ( + SELECT + sum(pg_total_relation_size(format('%%I.%%I', c.schema_name, c.table_name)))::bigint as total_bytes, + sum(pg_indexes_size(format('%%I.%%I', c.schema_name, c.table_name)))::bigint AS index_bytes, + sum(pg_total_relation_size(reltoastrelid))::bigint AS toast_bytes + FROM + _timescaledb_catalog.hypertable h, + _timescaledb_catalog.chunk c, + pg_class pgc, + pg_namespace pns + WHERE h.schema_name = %L + AND c.dropped = false + AND h.table_name = %L + AND c.hypertable_id = h.id + AND pgc.relname = h.table_name + AND pns.oid = pgc.relnamespace + AND pns.nspname = h.schema_name + AND relkind = 'r' + ) sub1 + ) sub2; + $$, + schema_name, table_name); + +END; +$BODY$; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.range_value_to_pretty( + time_value BIGINT, + column_type REGTYPE +) + RETURNS TEXT LANGUAGE PLPGSQL STABLE AS +$BODY$ +DECLARE +BEGIN + IF NOT _timescaledb_internal.dimension_is_finite(time_value) THEN + RETURN ''; + END IF; + IF time_value IS NULL THEN + RETURN format('%L', NULL); + END IF; + CASE column_type + WHEN 'BIGINT'::regtype, 'INTEGER'::regtype, 'SMALLINT'::regtype THEN + RETURN format('%L', time_value); -- scale determined by user. + WHEN 'TIMESTAMP'::regtype, 'TIMESTAMPTZ'::regtype THEN + -- assume time_value is in microsec + RETURN format('%1$L', _timescaledb_internal.to_timestamp(time_value)); -- microseconds + WHEN 'DATE'::regtype THEN + RETURN format('%L', timezone('UTC',_timescaledb_internal.to_timestamp(time_value))::date); + ELSE + RETURN time_value; + END CASE; +END +$BODY$; + + +CREATE OR REPLACE FUNCTION _timescaledb_internal.partitioning_column_to_pretty( + d _timescaledb_catalog.dimension +) + RETURNS TEXT LANGUAGE PLPGSQL STABLE STRICT AS +$BODY$ +DECLARE +BEGIN + IF d.partitioning_func IS NULL THEN + RETURN d.column_name; + ELSE + RETURN format('%I.%I(%I)', d.partitioning_func_schema, d.partitioning_func, d.column_name); + END IF; +END +$BODY$; + + +-- Get relation size of hypertable +-- like pg_relation_size(hypertable) +-- (https://www.postgresql.org/docs/9.6/static/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE) +-- +-- main_table - hypertable to get size of +-- +-- Returns: +-- table_size - Pretty output of table_bytes +-- index_bytes - Pretty output of index_bytes +-- toast_bytes - Pretty output of toast_bytes +-- total_size - Pretty output of total_bytes + +CREATE OR REPLACE FUNCTION hypertable_relation_size_pretty( + main_table REGCLASS +) +RETURNS TABLE (table_size TEXT, + index_size TEXT, + toast_size TEXT, + total_size TEXT) LANGUAGE PLPGSQL STABLE STRICT + AS +$BODY$ +DECLARE + table_name NAME; + schema_name NAME; +BEGIN + RETURN QUERY + SELECT pg_size_pretty(table_bytes) as table, + pg_size_pretty(index_bytes) as index, + pg_size_pretty(toast_bytes) as toast, + pg_size_pretty(total_bytes) as total + FROM @extschema@.hypertable_relation_size(main_table); + +END; +$BODY$; + + +-- Get relation size of the chunks of an hypertable +-- like pg_relation_size +-- (https://www.postgresql.org/docs/9.6/static/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE) +-- +-- main_table - hypertable to get size of +-- +-- Returns: +-- chunk_id - Timescaledb id of a chunk +-- chunk_table - Table used for the chunk +-- partitioning_columns - Partitioning column names +-- partitioning_column_types - Type of partitioning columns +-- partitioning_hash_functions - Hash functions of partitioning columns +-- ranges - Partition ranges for each dimension of the chunk +-- table_bytes - Disk space used by main_table +-- index_bytes - Disk space used by indexes +-- toast_bytes - Disk space of toast tables +-- total_bytes - Disk space used in total + +CREATE OR REPLACE FUNCTION chunk_relation_size( + main_table REGCLASS +) +RETURNS TABLE (chunk_id INT, + chunk_table TEXT, + partitioning_columns NAME[], + partitioning_column_types REGTYPE[], + partitioning_hash_functions TEXT[], + ranges int8range[], + table_bytes BIGINT, + index_bytes BIGINT, + toast_bytes BIGINT, + total_bytes BIGINT) + LANGUAGE PLPGSQL STABLE STRICT + AS +$BODY$ +DECLARE + table_name NAME; + schema_name NAME; +BEGIN + SELECT relname, nspname + INTO STRICT table_name, schema_name + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + WHERE c.OID = main_table; + + RETURN QUERY EXECUTE format( + $$ + + SELECT chunk_id, + chunk_table, + partitioning_columns, + partitioning_column_types, + partitioning_hash_functions, + ranges, + table_bytes, + index_bytes, + toast_bytes, + total_bytes + FROM ( + SELECT *, + total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes + FROM ( + SELECT c.id as chunk_id, + format('%%I.%%I', c.schema_name, c.table_name) as chunk_table, + pg_total_relation_size(format('%%I.%%I', c.schema_name, c.table_name)) AS total_bytes, + pg_indexes_size(format('%%I.%%I', c.schema_name, c.table_name)) AS index_bytes, + pg_total_relation_size(reltoastrelid) AS toast_bytes, + array_agg(d.column_name ORDER BY d.interval_length, d.column_name ASC) as partitioning_columns, + array_agg(d.column_type ORDER BY d.interval_length, d.column_name ASC) as partitioning_column_types, + array_agg(d.partitioning_func_schema || '.' || d.partitioning_func ORDER BY d.interval_length, d.column_name ASC) as partitioning_hash_functions, + array_agg(int8range(range_start, range_end) ORDER BY d.interval_length, d.column_name ASC) as ranges + FROM + _timescaledb_catalog.hypertable h, + _timescaledb_catalog.chunk c, + _timescaledb_catalog.chunk_constraint cc, + _timescaledb_catalog.dimension d, + _timescaledb_catalog.dimension_slice ds, + pg_class pgc, + pg_namespace pns + WHERE h.schema_name = %L + AND h.table_name = %L + AND pgc.relname = c.table_name + AND pns.oid = pgc.relnamespace + AND pns.nspname = c.schema_name + AND relkind = 'r' + AND c.hypertable_id = h.id + AND c.id = cc.chunk_id + AND cc.dimension_slice_id = ds.id + AND ds.dimension_id = d.id + GROUP BY c.id, pgc.reltoastrelid, pgc.oid ORDER BY c.id + ) sub1 + ) sub2; + $$, + schema_name, table_name); + +END; +$BODY$; + +-- Get relation size of the chunks of an hypertable +-- like pg_relation_size +-- (https://www.postgresql.org/docs/9.6/static/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE) +-- +-- main_table - hypertable to get size of +-- +-- Returns: +-- chunk_id - Timescaledb id of a chunk +-- chunk_table - Table used for the chunk +-- partitioning_columns - Partitioning column names +-- partitioning_column_types - Type of partitioning columns +-- partitioning_hash_functions - Hash functions of partitioning columns +-- ranges - Partition ranges for each dimension of the chunk +-- table_size - Pretty output of table_bytes +-- index_size - Pretty output of index_bytes +-- toast_size - Pretty output of toast_bytes +-- total_size - Pretty output of total_bytes + + +CREATE OR REPLACE FUNCTION chunk_relation_size_pretty( + main_table REGCLASS +) +RETURNS TABLE (chunk_id INT, + chunk_table TEXT, + partitioning_columns NAME[], + partitioning_column_types REGTYPE[], + partitioning_hash_functions TEXT[], + ranges TEXT[], + table_size TEXT, + index_size TEXT, + toast_size TEXT, + total_size TEXT + ) + LANGUAGE PLPGSQL STABLE STRICT + AS +$BODY$ +DECLARE + table_name NAME; + schema_name NAME; +BEGIN + SELECT relname, nspname + INTO STRICT table_name, schema_name + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + WHERE c.OID = main_table; + + RETURN QUERY EXECUTE format( + $$ + + SELECT chunk_id, + chunk_table, + partitioning_columns, + partitioning_column_types, + partitioning_functions, + ranges, + pg_size_pretty(table_bytes) AS table, + pg_size_pretty(index_bytes) AS index, + pg_size_pretty(toast_bytes) AS toast, + pg_size_pretty(total_bytes) AS total + FROM ( + SELECT *, + total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes + FROM ( + SELECT c.id as chunk_id, + format('%%I.%%I', c.schema_name, c.table_name) as chunk_table, + pg_total_relation_size(format('%%I.%%I', c.schema_name, c.table_name)) AS total_bytes, + pg_indexes_size(format('%%I.%%I', c.schema_name, c.table_name)) AS index_bytes, + pg_total_relation_size(reltoastrelid) AS toast_bytes, + array_agg(d.column_name ORDER BY d.interval_length, d.column_name ASC) as partitioning_columns, + array_agg(d.column_type ORDER BY d.interval_length, d.column_name ASC) as partitioning_column_types, + array_agg(d.partitioning_func_schema || '.' || d.partitioning_func ORDER BY d.interval_length, d.column_name ASC) as partitioning_functions, + array_agg('[' || _timescaledb_internal.range_value_to_pretty(range_start, column_type) || + ',' || + _timescaledb_internal.range_value_to_pretty(range_end, column_type) || ')' ORDER BY d.interval_length, d.column_name ASC) as ranges + FROM + _timescaledb_catalog.hypertable h, + _timescaledb_catalog.chunk c, + _timescaledb_catalog.chunk_constraint cc, + _timescaledb_catalog.dimension d, + _timescaledb_catalog.dimension_slice ds, + pg_class pgc, + pg_namespace pns + WHERE h.schema_name = %L + AND h.table_name = %L + AND pgc.relname = c.table_name + AND pns.oid = pgc.relnamespace + AND pns.nspname = c.schema_name + AND relkind = 'r' + AND c.hypertable_id = h.id + AND c.id = cc.chunk_id + AND cc.dimension_slice_id = ds.id + AND ds.dimension_id = d.id + GROUP BY c.id, pgc.reltoastrelid, pgc.oid ORDER BY c.id + ) sub1 + ) sub2; + $$, + schema_name, table_name); + +END; +$BODY$; + + +-- Get sizes of indexes on a hypertable +-- +-- main_table - hypertable to get index sizes of +-- +-- Returns: +-- index_name - index on hyper table +-- total_bytes - size of index on disk + +CREATE OR REPLACE FUNCTION indexes_relation_size( + main_table REGCLASS +) +RETURNS TABLE (index_name TEXT, + total_bytes BIGINT) + LANGUAGE PLPGSQL STABLE STRICT + AS +$BODY$ +<
> +DECLARE + table_name NAME; + schema_name NAME; +BEGIN + SELECT relname, nspname + INTO STRICT table_name, schema_name + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + WHERE c.OID = main_table; + + RETURN QUERY + SELECT format('%I.%I', h.schema_name, ci.hypertable_index_name), + sum(pg_relation_size(c.oid))::bigint + FROM + pg_class c, + pg_namespace n, + _timescaledb_catalog.hypertable h, + _timescaledb_catalog.chunk ch, + _timescaledb_catalog.chunk_index ci + WHERE ch.schema_name = n.nspname + AND c.relnamespace = n.oid + AND c.relname = ci.index_name + AND ch.id = ci.chunk_id + AND h.id = ci.hypertable_id + AND h.schema_name = main.schema_name + AND h.table_name = main.table_name + GROUP BY h.schema_name, ci.hypertable_index_name; +END; +$BODY$; + + +-- Get sizes of indexes on a hypertable +-- +-- main_table - hypertable to get index sizes of +-- +-- Returns: +-- index_name - index on hyper table +-- total_size - pretty output of total_bytes + +CREATE OR REPLACE FUNCTION indexes_relation_size_pretty( + main_table REGCLASS +) +RETURNS TABLE (index_name TEXT, + total_size TEXT) LANGUAGE PLPGSQL STABLE STRICT + AS +$BODY$ +BEGIN + RETURN QUERY + SELECT s.index_name, + pg_size_pretty(s.total_bytes) + FROM @extschema@.indexes_relation_size(main_table) s; +END; +$BODY$; + + +-- Convenience function to return approximate row count +-- +-- main_table - hypertable to get approximate row count for; if NULL, get count +-- for all hypertables +-- +-- Returns: +-- schema_name - Schema name of the hypertable +-- table_name - Table name of the hypertable +-- row_estimate - Estimated number of rows according to catalog tables +CREATE OR REPLACE FUNCTION hypertable_approximate_row_count( + main_table REGCLASS = NULL +) + RETURNS TABLE (schema_name NAME, + table_name NAME, + row_estimate BIGINT + ) LANGUAGE PLPGSQL VOLATILE + AS +$BODY$ +<
> +DECLARE + table_name NAME; + schema_name NAME; +BEGIN + IF main_table IS NOT NULL THEN + SELECT relname, nspname + INTO STRICT table_name, schema_name + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + WHERE c.OID = main_table; + END IF; + + RETURN QUERY + SELECT h.schema_name, + h.table_name, + row_estimate.row_estimate + FROM _timescaledb_catalog.hypertable h + JOIN ( + SELECT c.hypertable_id, + sum(cl.reltuples)::BIGINT AS row_estimate + FROM _timescaledb_catalog.chunk c + JOIN pg_class cl ON cl.relname = c.table_name + GROUP BY c.hypertable_id + ) row_estimate ON row_estimate.hypertable_id = h.id + WHERE (main.table_name IS NULL OR h.table_name = main.table_name) + AND (main.schema_name IS NULL OR h.schema_name = main.schema_name) + ORDER BY h.schema_name, h.table_name; +END +$BODY$; +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_sfunc (state INTERNAL, val DOUBLE PRECISION, MIN DOUBLE PRECISION, MAX DOUBLE PRECISION, nbuckets INTEGER) +RETURNS INTERNAL +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hist_sfunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_combinefunc(state1 INTERNAL, state2 INTERNAL) +RETURNS INTERNAL +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hist_combinefunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_serializefunc(INTERNAL) +RETURNS bytea +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hist_serializefunc' +LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_deserializefunc(bytea, INTERNAL) +RETURNS INTERNAL +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hist_deserializefunc' +LANGUAGE C IMMUTABLE STRICT ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_finalfunc(state INTERNAL, val DOUBLE PRECISION, MIN DOUBLE PRECISION, MAX DOUBLE PRECISION, nbuckets INTEGER) +RETURNS INTEGER[] +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_hist_finalfunc' +LANGUAGE C IMMUTABLE ; +-- 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. + +-- This file contains infrastructure for cache invalidation of TimescaleDB +-- metadata caches kept in C. Please look at cache_invalidate.c for a +-- description of how this works. +CREATE TABLE _timescaledb_cache.cache_inval_hypertable(just_for_og TEXT); + +-- For notifying the scheduler of changes to the bgw_job table. +CREATE TABLE _timescaledb_cache.cache_inval_bgw_job(just_for_og TEXT); + +-- This is pretty subtle. We create this dummy cache_inval_extension table +-- solely for the purpose of getting a relcache invalidation event when it is +-- deleted on DROP extension. It has no related triggers. When the table is +-- invalidated, all backends will be notified and will know that they must +-- invalidate all cached information, including catalog table and index OIDs, +-- etc. +CREATE TABLE _timescaledb_cache.cache_inval_extension(just_for_og TEXT); + +-- not actually strictly needed but good for sanity as all tables should be dumped. +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_cache.cache_inval_hypertable', ''); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_cache.cache_inval_extension', ''); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_cache.cache_inval_bgw_job', ''); + +GRANT SELECT ON ALL TABLES IN SCHEMA _timescaledb_cache TO PUBLIC; + +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.restart_background_workers() +RETURNS BOOL +AS ' /home/lhy/self_detection/lib/timescaledb', 'ts_bgw_db_workers_restart' +LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.stop_background_workers() +RETURNS BOOL +AS ' /home/lhy/self_detection/lib/timescaledb', 'ts_bgw_db_workers_stop' +LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.start_background_workers() +RETURNS BOOL +AS ' /home/lhy/self_detection/lib/timescaledb', 'ts_bgw_db_workers_start' +LANGUAGE C VOLATILE; + +INSERT INTO _timescaledb_config.bgw_job (id, application_name, job_type, schedule_INTERVAL, max_runtime, max_retries, retry_period) VALUES +(1, 'Telemetry Reporter', 'telemetry_and_version_check_if_enabled', INTERVAL '24h', INTERVAL '100s', -1, INTERVAL '1h'); + +CREATE OR REPLACE FUNCTION add_drop_chunks_policy(hypertable REGCLASS, older_than "any", cascade BOOL = FALSE, if_not_exists BOOL = false, cascade_to_materializations BOOL = false) +RETURNS INTEGER +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_add_drop_chunks_policy' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION add_reorder_policy(hypertable REGCLASS, index_name NAME, if_not_exists BOOL = false) RETURNS INTEGER +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_add_reorder_policy' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION add_compress_chunks_policy(hypertable REGCLASS, older_than "any", if_not_exists BOOL = false) +RETURNS INTEGER +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_add_compress_chunks_policy' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION remove_drop_chunks_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS VOID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_remove_drop_chunks_policy' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION remove_reorder_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS VOID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_remove_reorder_policy' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION remove_compress_chunks_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS BOOL +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_remove_compress_chunks_policy' +LANGUAGE C VOLATILE STRICT; + +-- Returns the updated job schedule values +CREATE OR REPLACE FUNCTION alter_job_schedule( + job_id INTEGER, + schedule_interval INTERVAL = NULL, + max_runtime INTERVAL = NULL, + max_retries INTEGER = NULL, + retry_period INTERVAL = NULL, + if_exists BOOL = FALSE, + next_start TIMESTAMPTZ = NULL +) +RETURNS TABLE (job_id INTEGER, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, next_start TIMESTAMPTZ) +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_alter_job_schedule' +LANGUAGE C VOLATILE; +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.generate_uuid() RETURNS UUID +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_uuid_generate' LANGUAGE C VOLATILE STRICT; + +-- Insert uuid and install_timestamp on database creation. Don't +-- create exported_uuid because it gets exported and installed during +-- pg_dump, which would cause a conflict. +INSERT INTO _timescaledb_catalog.metadata +SELECT 'uuid', _timescaledb_internal.generate_uuid(); +INSERT INTO _timescaledb_catalog.metadata +SELECT 'install_timestamp', now(); +-- 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. + +CREATE SCHEMA timescaledb_information; + +-- Convenience view to list all hypertables and their space usage + +CREATE OR REPLACE VIEW timescaledb_information.hypertable AS +WITH ht_size AS ( + SELECT ht.id, + ht.schema_name AS table_schema, + ht.table_name, + t.tableowner AS table_owner, + ht.num_dimensions, + ( + SELECT count(1) + FROM _timescaledb_catalog.chunk ch + WHERE ch.hypertable_id = ht.id + ) AS num_chunks, + COALESCE( + ( + SELECT b.table_bytes + FROM @extschema@.hypertable_relation_size( + CASE + WHEN has_schema_privilege(ht.schema_name, 'USAGE') + THEN format('%I.%I', ht.schema_name, ht.table_name) + ELSE NULL + END + ) AS b + ), 0) AS table_bytes, + COALESCE( + ( + SELECT b.index_bytes + FROM @extschema@.hypertable_relation_size( + CASE + WHEN has_schema_privilege(ht.schema_name, 'USAGE') + THEN format('%I.%I', ht.schema_name, ht.table_name) + ELSE NULL + END + ) AS b + ), 0) AS index_bytes, + COALESCE( + ( + SELECT b.toast_bytes + FROM @extschema@.hypertable_relation_size( + CASE + WHEN has_schema_privilege(ht.schema_name, 'USAGE') + THEN format('%I.%I', ht.schema_name, ht.table_name) + ELSE NULL + END + ) AS b + ), 0) AS toast_bytes, + COALESCE( + ( + SELECT b.total_bytes + FROM @extschema@.hypertable_relation_size( + CASE + WHEN has_schema_privilege(ht.schema_name, 'USAGE') + THEN format('%I.%I', ht.schema_name, ht.table_name) + ELSE NULL + END + ) AS b + ), 0) AS total_bytes + FROM _timescaledb_catalog.hypertable ht + LEFT OUTER JOIN pg_tables t + ON ht.table_name = t.tablename AND ht.schema_name = t.schemaname +), +compht_size AS ( + SELECT srcht.id, + sum(map.compressed_heap_size) AS heap_bytes, + sum(map.compressed_index_size) AS index_bytes, + sum(map.compressed_toast_size) AS toast_bytes, + sum(map.compressed_heap_size + map.compressed_toast_size + map.compressed_index_size) AS total_bytes + FROM _timescaledb_catalog.chunk srcch + JOIN _timescaledb_catalog.compression_chunk_size map ON map.chunk_id = srcch.id + JOIN _timescaledb_catalog.hypertable srcht ON srcht.id = srcch.hypertable_id + GROUP BY srcht.id +) +SELECT hts.table_schema, hts.table_name, hts.table_owner, + hts.num_dimensions, hts.num_chunks, + pg_size_pretty(COALESCE(hts.table_bytes + compht_size.heap_bytes, hts.table_bytes)) AS table_size, + pg_size_pretty(COALESCE(hts.index_bytes + compht_size.index_bytes, hts.index_bytes, compht_size.index_bytes)) AS index_size, + pg_size_pretty(COALESCE(hts.toast_bytes + compht_size.toast_bytes, hts.toast_bytes, compht_size.toast_bytes)) AS toast_size, + pg_size_pretty(COALESCE(hts.total_bytes + compht_size.total_bytes, hts.total_bytes)) AS total_size +FROM ht_size hts +LEFT JOIN compht_size ON hts.id = compht_size.id; + + +CREATE OR REPLACE VIEW timescaledb_information.license AS + SELECT _timescaledb_internal.license_edition() as edition, + _timescaledb_internal.license_expiration_time() <= now() AS expired, + _timescaledb_internal.license_expiration_time() AS expiration_time; + +CREATE OR REPLACE VIEW timescaledb_information.drop_chunks_policies as + SELECT format('%1$I.%2$I', ht.schema_name, ht.table_name)::regclass as hypertable, p.older_than, p.cascade, p.job_id, j.schedule_interval, + j.max_runtime, j.max_retries, j.retry_period, p.cascade_to_materializations + FROM _timescaledb_config.bgw_policy_drop_chunks p + INNER JOIN _timescaledb_catalog.hypertable ht ON p.hypertable_id = ht.id + INNER JOIN _timescaledb_config.bgw_job j ON p.job_id = j.id; + +CREATE OR REPLACE VIEW timescaledb_information.reorder_policies as + SELECT format('%1$I.%2$I', ht.schema_name, ht.table_name)::regclass as hypertable, p.hypertable_index_name, p.job_id, j.schedule_interval, + j.max_runtime, j.max_retries, j.retry_period + FROM _timescaledb_config.bgw_policy_reorder p + INNER JOIN _timescaledb_catalog.hypertable ht ON p.hypertable_id = ht.id + INNER JOIN _timescaledb_config.bgw_job j ON p.job_id = j.id; + +CREATE OR REPLACE VIEW timescaledb_information.policy_stats as + SELECT format('%1$I.%2$I', ht.schema_name, ht.table_name)::regclass as hypertable, p.job_id, j.job_type, js.last_run_success, js.last_finish, js.last_successful_finish, js.last_start, js.next_start, + js.total_runs, js.total_failures + FROM (SELECT job_id, hypertable_id FROM _timescaledb_config.bgw_policy_reorder + UNION SELECT job_id, hypertable_id FROM _timescaledb_config.bgw_policy_drop_chunks + UNION SELECT job_id, hypertable_id FROM _timescaledb_config.bgw_policy_compress_chunks + UNION SELECT job_id, raw_hypertable_id FROM _timescaledb_catalog.continuous_agg) p + INNER JOIN _timescaledb_catalog.hypertable ht ON p.hypertable_id = ht.id + INNER JOIN _timescaledb_config.bgw_job j ON p.job_id = j.id + INNER JOIN _timescaledb_internal.bgw_job_stat js on p.job_id = js.job_id + ORDER BY ht.schema_name, ht.table_name; + +-- views for continuous aggregate queries --- +--注释到2070行 +-- CREATE OR REPLACE VIEW timescaledb_information.continuous_aggregates as +-- SELECT format('%1$I.%2$I', cagg.user_view_schema, cagg.user_view_name)::regclass as view_name, +-- viewinfo.viewowner as view_owner, +-- CASE _timescaledb_internal.get_time_type(cagg.raw_hypertable_id) +-- WHEN 'TIMESTAMP'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.refresh_lag)::TEXT +-- WHEN 'TIMESTAMPTZ'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.refresh_lag)::TEXT +-- WHEN 'DATE'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.refresh_lag)::TEXT +-- ELSE cagg.refresh_lag::TEXT +-- END AS refresh_lag, +-- bgwjob.schedule_interval as refresh_interval, +-- CASE _timescaledb_internal.get_time_type(cagg.raw_hypertable_id) +-- WHEN 'TIMESTAMP'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.max_interval_per_job)::TEXT +-- WHEN 'TIMESTAMPTZ'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.max_interval_per_job)::TEXT +-- WHEN 'DATE'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.max_interval_per_job)::TEXT +-- ELSE cagg.max_interval_per_job::TEXT +-- END AS max_interval_per_job, +-- CASE +-- WHEN cagg.ignore_invalidation_older_than = BIGINT '9223372036854775807' +-- THEN NULL +-- ELSE +-- CASE _timescaledb_internal.get_time_type(cagg.raw_hypertable_id) +-- WHEN 'TIMESTAMP'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.ignore_invalidation_older_than)::TEXT +-- WHEN 'TIMESTAMPTZ'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.ignore_invalidation_older_than)::TEXT +-- WHEN 'DATE'::regtype +-- THEN _timescaledb_internal.to_interval(cagg.ignore_invalidation_older_than)::TEXT +-- ELSE cagg.ignore_invalidation_older_than::TEXT +-- END +-- END AS ignore_invalidation_older_than, +-- cagg.materialized_only, +-- format('%1$I.%2$I', ht.schema_name, ht.table_name)::regclass as materialization_hypertable, +-- directview.viewdefinition as view_definition +-- FROM _timescaledb_catalog.continuous_agg cagg, +-- _timescaledb_catalog.hypertable ht, LATERAL +-- ( select C.oid, pg_get_userbyid( C.relowner) as viewowner +-- FROM pg_class C LEFT JOIN pg_namespace N on (N.oid = C.relnamespace) +-- where C.relkind = 'v' and C.relname = cagg.user_view_name +-- and N.nspname = cagg.user_view_schema ) viewinfo, LATERAL +-- ( select schedule_interval +-- FROM _timescaledb_config.bgw_job +-- where id = cagg.job_id ) bgwjob, LATERAL +-- ( select pg_get_viewdef(C.oid) as viewdefinition +-- FROM pg_class C LEFT JOIN pg_namespace N on (N.oid = C.relnamespace) +-- where C.relkind = 'v' and C.relname = cagg.direct_view_name +-- and N.nspname = cagg.direct_view_schema ) directview +-- WHERE cagg.mat_hypertable_id = ht.id; + +--tsdb注释到2126 +-- CREATE OR REPLACE VIEW timescaledb_information.continuous_aggregate_stats as +-- SELECT format('%1$I.%2$I', cagg.user_view_schema, cagg.user_view_name)::regclass as view_name, +-- CASE _timescaledb_internal.get_time_type(cagg.raw_hypertable_id) +-- WHEN 'TIMESTAMP'::regtype +-- THEN _timescaledb_internal.to_timestamp_without_timezone(ct.watermark) +-- WHEN 'TIMESTAMPTZ'::regtype +-- THEN _timescaledb_internal.to_timestamp(ct.watermark) +-- WHEN 'DATE'::regtype +-- THEN _timescaledb_internal.to_date(ct.watermark) +-- ELSE ct.watermark +-- END AS completed_threshold, +-- CASE _timescaledb_internal.get_time_type(cagg.raw_hypertable_id) +-- WHEN 'TIMESTAMP'::regtype +-- THEN _timescaledb_internal.to_timestamp_without_timezone(it.watermark) +-- WHEN 'TIMESTAMPTZ'::regtype +-- THEN _timescaledb_internal.to_timestamp(it.watermark) +-- WHEN 'DATE'::regtype +-- THEN _timescaledb_internal.to_date(it.watermark) +-- ELSE it.watermark +-- END AS invalidation_threshold, +-- cagg.job_id as job_id, +-- bgw_job_stat.last_start as last_run_started_at, +-- bgw_job_stat.last_successful_finish as last_successful_finish, +-- CASE WHEN bgw_job_stat.last_finish < '4714-11-24 00:00:00+00 BC' THEN NULL +-- WHEN bgw_job_stat.last_finish IS NOT NULL THEN +-- CASE WHEN bgw_job_stat.last_run_success = 't' THEN 'Success' +-- WHEN bgw_job_stat.last_run_success = 'f' THEN 'Failed' +-- END +-- END as last_run_status, +-- CASE WHEN bgw_job_stat.last_finish < '4714-11-24 00:00:00+00 BC' THEN 'Running' +-- WHEN bgw_job_stat.next_start IS NOT NULL THEN 'Scheduled' +-- END as job_status, +-- CASE WHEN bgw_job_stat.last_finish > bgw_job_stat.last_start THEN (bgw_job_stat.last_finish - bgw_job_stat.last_start) +-- END as last_run_duration, +-- bgw_job_stat.next_start as next_scheduled_run, +-- bgw_job_stat.total_runs, +-- bgw_job_stat.total_successes, +-- bgw_job_stat.total_failures, +-- bgw_job_stat.total_crashes +-- FROM +-- _timescaledb_catalog.continuous_agg as cagg +-- LEFT JOIN _timescaledb_internal.bgw_job_stat as bgw_job_stat +-- ON ( cagg.job_id = bgw_job_stat.job_id ) +-- LEFT JOIN _timescaledb_catalog.continuous_aggs_invalidation_threshold as it +-- ON ( cagg.raw_hypertable_id = it.hypertable_id) +-- LEFT JOIN _timescaledb_catalog.continuous_aggs_completed_threshold as ct +-- ON ( cagg.mat_hypertable_id = ct.materialization_id); + +CREATE OR REPLACE VIEW timescaledb_information.compressed_chunk_stats +AS +WITH mapq as +(select + chunk_id, + pg_size_pretty(map.uncompressed_heap_size) as uncompressed_heap_bytes, + pg_size_pretty(map.uncompressed_index_size) as uncompressed_index_bytes, + pg_size_pretty(map.uncompressed_toast_size) as uncompressed_toast_bytes, + pg_size_pretty(map.uncompressed_heap_size + map.uncompressed_toast_size + map.uncompressed_index_size) as uncompressed_total_bytes, + pg_size_pretty(map.compressed_heap_size) as compressed_heap_bytes, + pg_size_pretty(map.compressed_index_size) as compressed_index_bytes, + pg_size_pretty(map.compressed_toast_size) as compressed_toast_bytes, + pg_size_pretty(map.compressed_heap_size + map.compressed_toast_size + map.compressed_index_size) as compressed_total_bytes + FROM _timescaledb_catalog.compression_chunk_size map ) + SELECT format('%1$I.%2$I', srcht.schema_name, srcht.table_name)::regclass as hypertable_name, + format('%1$I.%2$I', srcch.schema_name, srcch.table_name)::regclass as chunk_name, + CASE WHEN srcch.compressed_chunk_id IS NULL THEN 'Uncompressed' ELSE 'Compressed' END as compression_status, + mapq.uncompressed_heap_bytes, + mapq.uncompressed_index_bytes, + mapq.uncompressed_toast_bytes, + mapq.uncompressed_total_bytes, + mapq.compressed_heap_bytes, + mapq.compressed_index_bytes, + mapq.compressed_toast_bytes, + mapq.compressed_total_bytes + FROM _timescaledb_catalog.hypertable as srcht JOIN _timescaledb_catalog.chunk as srcch + ON srcht.id = srcch.hypertable_id and srcht.compressed_hypertable_id IS NOT NULL and srcch.dropped = false + LEFT JOIN mapq + ON srcch.id = mapq.chunk_id ; + +CREATE OR REPLACE VIEW timescaledb_information.compressed_hypertable_stats +AS + SELECT format('%1$I.%2$I', srcht.schema_name, srcht.table_name)::regclass as hypertable_name, + ( select count(*) from _timescaledb_catalog.chunk where hypertable_id = srcht.id) as total_chunks, + count(*) as number_compressed_chunks, + pg_size_pretty(sum(map.uncompressed_heap_size)) as uncompressed_heap_bytes, + pg_size_pretty(sum(map.uncompressed_index_size)) as uncompressed_index_bytes, + pg_size_pretty(sum(map.uncompressed_toast_size)) as uncompressed_toast_bytes, + pg_size_pretty(sum(map.uncompressed_heap_size) + sum(map.uncompressed_toast_size) + sum(map.uncompressed_index_size)) as uncompressed_total_bytes, + pg_size_pretty(sum(map.compressed_heap_size)) as compressed_heap_bytes, + pg_size_pretty(sum(map.compressed_index_size)) as compressed_index_bytes, + pg_size_pretty(sum(map.compressed_toast_size)) as compressed_toast_bytes, + pg_size_pretty(sum(map.compressed_heap_size) + sum(map.compressed_toast_size) + sum(map.compressed_index_size)) as compressed_total_bytes + FROM _timescaledb_catalog.chunk srcch, _timescaledb_catalog.compression_chunk_size map, + _timescaledb_catalog.hypertable srcht + where map.chunk_id = srcch.id and srcht.id = srcch.hypertable_id + group by srcht.id; + +GRANT USAGE ON SCHEMA timescaledb_information TO PUBLIC; +GRANT SELECT ON ALL TABLES IN SCHEMA timescaledb_information TO PUBLIC; +-- 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. + +CREATE OR REPLACE FUNCTION time_bucket_gapfill(bucket_width SMALLINT, ts SMALLINT, start SMALLINT=NULL, finish SMALLINT=NULL) RETURNS SMALLINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_int16_bucket' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION time_bucket_gapfill(bucket_width INT, ts INT, start INT=NULL, finish INT=NULL) RETURNS INT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_int32_bucket' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION time_bucket_gapfill(bucket_width BIGINT, ts BIGINT, start BIGINT=NULL, finish BIGINT=NULL) RETURNS BIGINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_int64_bucket' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION time_bucket_gapfill(bucket_width INTERVAL, ts DATE, start DATE=NULL, finish DATE=NULL) RETURNS DATE + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_date_bucket' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION time_bucket_gapfill(bucket_width INTERVAL, ts TIMESTAMP, start TIMESTAMP=NULL, finish TIMESTAMP=NULL) RETURNS TIMESTAMP + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_timestamp_bucket' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION time_bucket_gapfill(bucket_width INTERVAL, ts TIMESTAMPTZ, start TIMESTAMPTZ=NULL, finish TIMESTAMPTZ=NULL) RETURNS TIMESTAMPTZ + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_timestamptz_bucket' LANGUAGE C VOLATILE ; + +-- locf function +CREATE OR REPLACE FUNCTION locf(value ANYELEMENT, prev ANYELEMENT=NULL, treat_null_as_missing BOOL=false) RETURNS ANYELEMENT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_marker' LANGUAGE C VOLATILE ; + +-- interpolate functions +CREATE OR REPLACE FUNCTION interpolate(value SMALLINT,prev RECORD=NULL,next RECORD=NULL) RETURNS SMALLINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_marker' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION interpolate(value INT,prev RECORD=NULL,next RECORD=NULL) RETURNS INT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_marker' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION interpolate(value BIGINT,prev RECORD=NULL,next RECORD=NULL) RETURNS BIGINT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_marker' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION interpolate(value REAL,prev RECORD=NULL,next RECORD=NULL) RETURNS REAL + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_marker' LANGUAGE C VOLATILE ; + +CREATE OR REPLACE FUNCTION interpolate(value FLOAT,prev RECORD=NULL,next RECORD=NULL) RETURNS FLOAT + AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_gapfill_marker' LANGUAGE C VOLATILE ; + +-- 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. + +-- chunk - the OID of the chunk to be CLUSTERed +-- index - the OID of the index to be CLUSTERed on, or NULL to use the index +-- last used +CREATE OR REPLACE FUNCTION reorder_chunk( + chunk REGCLASS, + index REGCLASS=NULL, + verbose BOOLEAN=FALSE +) RETURNS VOID AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_reorder_chunk' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION move_chunk( + chunk REGCLASS, + destination_tablespace Name, + index_destination_tablespace Name=NULL, + reorder_index REGCLASS=NULL, + verbose BOOLEAN=FALSE +) RETURNS VOID AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_move_chunk' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION compress_chunk( + uncompressed_chunk REGCLASS, + if_not_compressed BOOLEAN = false +) RETURNS REGCLASS AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_compress_chunk' LANGUAGE C STRICT VOLATILE; + +CREATE OR REPLACE FUNCTION decompress_chunk( + uncompressed_chunk REGCLASS, + if_compressed BOOLEAN = false +) RETURNS REGCLASS AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_decompress_chunk' LANGUAGE C STRICT VOLATILE; +-- 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. + +CREATE OR REPLACE FUNCTION _timescaledb_internal.partialize_agg(arg ANYELEMENT) +RETURNS BYTEA AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_partialize_agg' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.finalize_agg_sfunc( +tstate internal, aggfn TEXT, inner_agg_collation_schema NAME, inner_agg_collation_name NAME, inner_agg_input_types NAME[][], inner_agg_serialized_state BYTEA, return_type_dummy_val ANYELEMENT) +RETURNS internal +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_finalize_agg_sfunc' +LANGUAGE C IMMUTABLE ; + +CREATE OR REPLACE FUNCTION _timescaledb_internal.finalize_agg_ffunc( +tstate internal, aggfn TEXT, inner_agg_collation_schema NAME, inner_agg_collation_name NAME, inner_agg_input_types NAME[][], inner_agg_serialized_state BYTEA, return_type_dummy_val ANYELEMENT) +RETURNS anyelement +AS ' /home/lhy/self_detection/lib/timescaledb-1.7.4', 'ts_finalize_agg_ffunc' +LANGUAGE C IMMUTABLE ; + +-- 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. + +CREATE OR REPLACE FUNCTION timescaledb_pre_restore() RETURNS BOOL AS +$BODY$ +DECLARE + db text; +BEGIN + SELECT current_database() INTO db; + EXECUTE format($$ALTER DATABASE %I SET timescaledb.restoring ='on'$$, db); + SET SESSION timescaledb.restoring = 'on'; + PERFORM _timescaledb_internal.stop_background_workers(); + --exported uuid may be included in the dump so backup the version + UPDATE _timescaledb_catalog.metadata SET key='exported_uuid_bak' WHERE key='exported_uuid'; + RETURN true; +END +$BODY$ +LANGUAGE PLPGSQL; + + +CREATE OR REPLACE FUNCTION timescaledb_post_restore() RETURNS BOOL AS +$BODY$ +DECLARE + db text; +BEGIN + SELECT current_database() INTO db; + EXECUTE format($$ALTER DATABASE %I RESET timescaledb.restoring $$, db); + RESET timescaledb.restoring; + PERFORM _timescaledb_internal.restart_background_workers(); + + --try to restore the backed up uuid, if the restore did not set one + INSERT INTO _timescaledb_catalog.metadata + SELECT 'exported_uuid', value, include_in_telemetry FROM _timescaledb_catalog.metadata WHERE key='exported_uuid_bak'; + DELETE FROM _timescaledb_catalog.metadata WHERE key='exported_uuid_bak'; + + RETURN true; +END +$BODY$ +LANGUAGE PLPGSQL; +-- 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. + +-- This file is meant to contain aggregate functions that need to be created only +-- once and not recreated during updates. +-- There is no CREATE OR REPLACE AGGREGATE which means that the only way to replace +-- an aggregate is to DROP then CREATE which is problematic as it will fail +-- if the previous version of the aggregate has dependencies. +-- NOTE that WHEN CREATING NEW FUNCTIONS HERE you should also make sure they are +-- created in an update script so that both new users and people updating from a +-- previous version get the new function + + +--This aggregate returns the "first" element of the first argument when ordered by the second argument. +--Ex. first(temp, time) returns the temp value for the row with the lowest time + +--tsdb 注释到2363行 +-- CREATE AGGREGATE first(anyelement, "any") ( +-- SFUNC = _timescaledb_internal.first_sfunc, +-- STYPE = internal, +-- COMBINEFUNC = _timescaledb_internal.first_combinefunc, +-- SERIALFUNC = _timescaledb_internal.bookend_serializefunc, +-- DESERIALFUNC = _timescaledb_internal.bookend_deserializefunc, + +-- FINALFUNC = _timescaledb_internal.bookend_finalfunc, +-- FINALFUNC_EXTRA +-- ); + +-- --This aggregate returns the "last" element of the first argument when ordered by the second argument. +-- --Ex. last(temp, time) returns the temp value for the row with highest time +-- CREATE AGGREGATE last(anyelement, "any") ( +-- SFUNC = _timescaledb_internal.last_sfunc, +-- STYPE = internal, +-- COMBINEFUNC = _timescaledb_internal.last_combinefunc, +-- SERIALFUNC = _timescaledb_internal.bookend_serializefunc, +-- DESERIALFUNC = _timescaledb_internal.bookend_deserializefunc, + +-- FINALFUNC = _timescaledb_internal.bookend_finalfunc, +-- FINALFUNC_EXTRA +-- ); + +-- -- This aggregate partitions the dataset into a specified number of buckets (nbuckets) ranging +-- -- from the inputted min to max values. +-- CREATE AGGREGATE histogram (DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION, INTEGER) ( +-- SFUNC = _timescaledb_internal.hist_sfunc, +-- STYPE = INTERNAL, +-- COMBINEFUNC = _timescaledb_internal.hist_combinefunc, +-- SERIALFUNC = _timescaledb_internal.hist_serializefunc, +-- DESERIALFUNC = _timescaledb_internal.hist_deserializefunc, + +-- FINALFUNC = _timescaledb_internal.hist_finalfunc, +-- FINALFUNC_EXTRA +-- ); +--#注释到2359行 +-- CREATE AGGREGATE _timescaledb_internal.finalize_agg(agg_name TEXT, inner_agg_collation_schema NAME, inner_agg_collation_name NAME, inner_agg_input_types NAME[][], inner_agg_serialized_state BYTEA, return_type_dummy_val anyelement) ( +-- SFUNC = _timescaledb_internal.finalize_agg_sfunc, +-- STYPE = internal, +-- FINALFUNC = _timescaledb_internal.finalize_agg_ffunc, +-- FINALFUNC_EXTRA +-- ); +-- 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. + +DO language plpgsql $$ +DECLARE + end_time TIMESTAMPTZ; + expiration_time_string TEXT; + telemetry_string TEXT; +BEGIN + end_time := _timescaledb_internal.license_expiration_time(); + + IF end_time IS NOT NULL AND isfinite(end_time) + THEN + expiration_time_string = format(E'\nYour license expires on %s\n', end_time); + ELSE + expiration_time_string = ''; + END IF; + + IF current_setting('timescaledb.telemetry_level') = 'off' + THEN + telemetry_string = E'Note: Please enable telemetry to help us improve our product by running: ALTER DATABASE "' || current_database() || E'" SET timescaledb.telemetry_level = ''basic'';'; + ELSE + telemetry_string = E'Note: TimescaleDB collects anonymous reports to better understand and assist our users.\nFor more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.'; + END IF; + + RAISE WARNING E'%\n%\n%', + E'\nWELCOME TO\n' || + E' _____ _ _ ____________ \n' || + E'|_ _(_) | | | _ \\ ___ \\ \n' || + E' | | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ / \n' || + ' | | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \ ' || E'\n' || + ' | | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ /' || E'\n' || + ' |_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/' || E'\n' || + E' Running version ' || '1.7.4' || E'\n' || + + E'For more information on TimescaleDB, please visit the following links:\n\n' + || + E' 1. Getting started: https://docs.timescale.com/getting-started\n' || + E' 2. API reference documentation: https://docs.timescale.com/api\n' || + E' 3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture\n', + telemetry_string, + expiration_time_string; + +IF now() > end_time +THEN + RAISE WARNING E'%\n', format('Your license expired on %s', end_time); +ELSIF now() + INTERVAL '1 week' >= end_time +THEN + RAISE WARNING E'%\n', format('Your license will expire on %s', end_time); +END IF; + +END; +$$; diff --git a/contrib/timescaledb/timescaledb.so b/contrib/timescaledb/timescaledb.so new file mode 100755 index 0000000000000000000000000000000000000000..0c86f161394062827c67b0d22932418a7845fc1e GIT binary patch literal 7200 zcmeHMU1%It6uz5n+B9vNv}*qpJFOHf#WAh+m!@u#CYeBz(wd@z<#w_=$u8_q*qKOD z5CgT4Qj2|2B8U$y6#F8Ah(&y`REm%FO?{BQ6jJaZ;!8zHJZI*7o0-|&Qp6|O8)nWu z-}$+B&b>Qx?#X+7L;X#OghETI82Q}Fn>&k=6W6>t1(MjRyma2;G}Jy9qXwd>hs zPiv)f#hj<~I1!}>M~8LBDLWH6*K^9F!@c=Z(HXVJ@=hSDEz#*|n;qEs+<8akb7QWT zN$=fjx+U`TIY%zpae38YY5YGD-?VjN5Bkcd@5FYkpUHHAly4-wmouRCY-+Rpq zd&$tc@I%X;z~l0Pqa<41eT?qyJ5tnRKFh*~_m`>d-p@R5r-%25wXSrXBH)a5rFoF3 zb>xwC>4CS6hS<(54bgUX`Tn@szTk3cy8(HznfmYwmo+YxkZZ9RRON-X+ zh1aaaUF)YMZ!0tk93$S8 zi6Tv%lOz%6pLvnD2IlIn&~-w$3gvSVw_B1|BG>E;VD+?6{YM zYZTT$inmnueH34-W^2SLNhf#IKcf28=V+EE>DM)n4IeT{sa0tx=e^)_-DZ>E@p(Q^xDg%F z=Z@CF2kYP}UG`jWYJA*GtCbRs_6j=9MH-jtC7F_*$d|_Kyv}%~va9W>X_YP&Ci9Nx zWXyv{UhS-{*<(b#azL}_WoK@)uI^8~X^ieZ+9C0DFArK#|8l9;e62o^uc2_#T29GFW{60;^%_a4cXy zCkY8C@*&6(KRo{%V&5YU@qMjO!P&lpuDHET7{_EaUEEM_21Q;ONQ1ee&-87&!uGSW zu%Pioh3CKxbb|U}dwkbHfAzIjZmgb@zBcYFd2i_HX#20x2Xj~uhgZ;bI z;cu=iTP2^s|0Cl1;6X2uZF|TbdB;^b06>pa{01KMBSLxYFh24V{Qt#}2ZJ1Th~sBu z%khI8dCV=I6g4X#l{@S~uahKfU&(i50O-L%oWDr|#xOpj`!9Gl}_F+Xs#y4aGJVU}4=)(N*`{VtExrgmj^5RHiAQ8q`&Jb(bU*`d-eG`z% HJ#POGqC@!c literal 0 HcmV?d00001 -- Gitee