diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/modules/Makefile | 1 | ||||
| -rw-r--r-- | src/test/modules/meson.build | 1 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/.gitignore | 4 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/Makefile | 23 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/expected/test_tam_options.out | 36 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/meson.build | 33 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/sql/test_tam_options.sql | 25 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/test_tam_options--1.0.sql | 12 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/test_tam_options.c | 66 | ||||
| -rw-r--r-- | src/test/modules/test_tam_options/test_tam_options.control | 4 |
10 files changed, 205 insertions, 0 deletions
diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile index 256799f520a..8f661525399 100644 --- a/src/test/modules/Makefile +++ b/src/test/modules/Makefile @@ -36,6 +36,7 @@ SUBDIRS = \ test_rls_hooks \ test_shm_mq \ test_slru \ + test_tam_options \ test_tidstore \ unsafe_tests \ worker_spi \ diff --git a/src/test/modules/meson.build b/src/test/modules/meson.build index d8fe059d236..235e342dfaa 100644 --- a/src/test/modules/meson.build +++ b/src/test/modules/meson.build @@ -35,6 +35,7 @@ subdir('test_resowner') subdir('test_rls_hooks') subdir('test_shm_mq') subdir('test_slru') +subdir('test_tam_options') subdir('test_tidstore') subdir('unsafe_tests') subdir('worker_spi') diff --git a/src/test/modules/test_tam_options/.gitignore b/src/test/modules/test_tam_options/.gitignore new file mode 100644 index 00000000000..5dcb3ff9723 --- /dev/null +++ b/src/test/modules/test_tam_options/.gitignore @@ -0,0 +1,4 @@ +# Generated subdirectories +/log/ +/results/ +/tmp_check/ diff --git a/src/test/modules/test_tam_options/Makefile b/src/test/modules/test_tam_options/Makefile new file mode 100644 index 00000000000..bd6d4599a14 --- /dev/null +++ b/src/test/modules/test_tam_options/Makefile @@ -0,0 +1,23 @@ +# src/test/modules/test_tam_options/Makefile + +MODULE_big = test_tam_options +OBJS = \ + $(WIN32RES) \ + test_tam_options.o +PGFILEDESC = "test_tam_options - test code for table access method reloptions" + +EXTENSION = test_tam_options +DATA = test_tam_options--1.0.sql + +REGRESS = test_tam_options + +ifdef USE_PGXS +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) +else +subdir = src/test/modules/test_tam_options +top_builddir = ../../../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/contrib/contrib-global.mk +endif diff --git a/src/test/modules/test_tam_options/expected/test_tam_options.out b/src/test/modules/test_tam_options/expected/test_tam_options.out new file mode 100644 index 00000000000..c921afcb270 --- /dev/null +++ b/src/test/modules/test_tam_options/expected/test_tam_options.out @@ -0,0 +1,36 @@ +CREATE EXTENSION test_tam_options; +-- encourage use of parallel plans +SET parallel_setup_cost = 0; +SET parallel_tuple_cost = 0; +SET min_parallel_table_scan_size = 0; +SET max_parallel_workers_per_gather = 4; +CREATE TABLE test (i int) USING heap_alter_options; +INSERT INTO test SELECT i FROM generate_series(1, 10000) i; +VACUUM ANALYZE test; +EXPLAIN (costs off) +SELECT * FROM test; + QUERY PLAN +--------------------------------- + Gather + Workers Planned: 4 + -> Parallel Seq Scan on test +(3 rows) + +ALTER TABLE test SET (enable_parallel = OFF); +EXPLAIN (costs off) +SELECT * FROM test; + QUERY PLAN +------------------ + Seq Scan on test +(1 row) + +ALTER TABLE test SET (enable_parallel = ON); +EXPLAIN (costs off) +SELECT * FROM test; + QUERY PLAN +--------------------------------- + Gather + Workers Planned: 4 + -> Parallel Seq Scan on test +(3 rows) + diff --git a/src/test/modules/test_tam_options/meson.build b/src/test/modules/test_tam_options/meson.build new file mode 100644 index 00000000000..d41a32a6803 --- /dev/null +++ b/src/test/modules/test_tam_options/meson.build @@ -0,0 +1,33 @@ +# Copyright (c) 2024, PostgreSQL Global Development Group + +test_tam_options_sources = files( + 'test_tam_options.c', +) + +if host_system == 'windows' + test_tam_options_sources += rc_lib_gen.process(win32ver_rc, extra_args: [ + '--NAME', 'test_tam_options', + '--FILEDESC', 'test_tam_options - test code for table access method reloptions',]) +endif + +test_tam_options = shared_module('test_tam_options', + test_tam_options_sources, + kwargs: pg_test_mod_args, +) +test_install_libs += test_tam_options + +test_install_data += files( + 'test_tam_options.control', + 'test_tam_options--1.0.sql', +) + +tests += { + 'name': 'test_tam_options', + 'sd': meson.current_source_dir(), + 'bd': meson.current_build_dir(), + 'regress': { + 'sql': [ + 'test_tam_options', + ], + }, +} diff --git a/src/test/modules/test_tam_options/sql/test_tam_options.sql b/src/test/modules/test_tam_options/sql/test_tam_options.sql new file mode 100644 index 00000000000..4f975046568 --- /dev/null +++ b/src/test/modules/test_tam_options/sql/test_tam_options.sql @@ -0,0 +1,25 @@ +CREATE EXTENSION test_tam_options; + +-- encourage use of parallel plans +SET parallel_setup_cost = 0; +SET parallel_tuple_cost = 0; +SET min_parallel_table_scan_size = 0; +SET max_parallel_workers_per_gather = 4; + +CREATE TABLE test (i int) USING heap_alter_options; + +INSERT INTO test SELECT i FROM generate_series(1, 10000) i; +VACUUM ANALYZE test; + +EXPLAIN (costs off) +SELECT * FROM test; + +ALTER TABLE test SET (enable_parallel = OFF); + +EXPLAIN (costs off) +SELECT * FROM test; + +ALTER TABLE test SET (enable_parallel = ON); + +EXPLAIN (costs off) +SELECT * FROM test; diff --git a/src/test/modules/test_tam_options/test_tam_options--1.0.sql b/src/test/modules/test_tam_options/test_tam_options--1.0.sql new file mode 100644 index 00000000000..07569f7b5f1 --- /dev/null +++ b/src/test/modules/test_tam_options/test_tam_options--1.0.sql @@ -0,0 +1,12 @@ +/* src/test/modules/test_tam_options/test_tam_options--1.0.sql */ + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION test_tam_options" to load this file. \quit + +CREATE FUNCTION heap_alter_options_tam_handler(internal) +RETURNS table_am_handler +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +CREATE ACCESS METHOD heap_alter_options TYPE TABLE +HANDLER heap_alter_options_tam_handler; diff --git a/src/test/modules/test_tam_options/test_tam_options.c b/src/test/modules/test_tam_options/test_tam_options.c new file mode 100644 index 00000000000..13e227e85b5 --- /dev/null +++ b/src/test/modules/test_tam_options/test_tam_options.c @@ -0,0 +1,66 @@ +/*-------------------------------------------------------------------------- + * + * test_tam_options.c + * Test code for table access method reloptions. + * + * Copyright (c) 2024, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/test/modules/test_tam_options/test_tam_options.c + * + * ------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include "access/reloptions.h" +#include "access/tableam.h" + +PG_MODULE_MAGIC; + +PG_FUNCTION_INFO_V1(heap_alter_options_tam_handler); + +/* An alternative relation options for heap */ +typedef struct +{ + int32 vl_len_; /* varlena header (do not touch directly!) */ + bool enable_parallel; /* enable parallel scans? */ +} HeapAlterRdOptions; + +static bytea * +heap_alter_reloptions(char relkind, Datum reloptions, + CommonRdOptions *common, bool validate) +{ + local_relopts relopts; + HeapAlterRdOptions *result; + + Assert(relkind == RELKIND_RELATION || + relkind == RELKIND_TOASTVALUE || + relkind == RELKIND_MATVIEW); + + init_local_reloptions(&relopts, sizeof(HeapAlterRdOptions)); + add_local_bool_reloption(&relopts, "enable_parallel", + "enable parallel scan", true, + offsetof(HeapAlterRdOptions, enable_parallel)); + + result = (HeapAlterRdOptions *) build_local_reloptions(&relopts, + reloptions, + validate); + + if (result != NULL && common != NULL) + { + common->parallel_workers = result->enable_parallel ? -1 : 0; + } + + return (bytea *) result; +} + +Datum +heap_alter_options_tam_handler(PG_FUNCTION_ARGS) +{ + static TableAmRoutine tam_routine; + + tam_routine = *GetHeapamTableAmRoutine(); + tam_routine.reloptions = heap_alter_reloptions; + + PG_RETURN_POINTER(&tam_routine); +} diff --git a/src/test/modules/test_tam_options/test_tam_options.control b/src/test/modules/test_tam_options/test_tam_options.control new file mode 100644 index 00000000000..dd6682edcdf --- /dev/null +++ b/src/test/modules/test_tam_options/test_tam_options.control @@ -0,0 +1,4 @@ +comment = 'Test code for table access method reloptions' +default_version = '1.0' +module_pathname = '$libdir/test_tam_options' +relocatable = true |
