Skip to content

Commit

Permalink
Access method renaming and conditions (#231)
Browse files Browse the repository at this point in the history
* Renamed pg_tde -> pg_tde_basic

* The "fork" extension is only visible when it's actally built

* Update sysbench tests to use pg_tde_basic
  • Loading branch information
dutow authored Jul 9, 2024
1 parent f56dda0 commit 8a2b8ec
Show file tree
Hide file tree
Showing 37 changed files with 107 additions and 96 deletions.
4 changes: 2 additions & 2 deletions expected/change_access_method.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde;
) using pg_tde_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand Down Expand Up @@ -60,7 +60,7 @@ SELECT pgtde_is_encrypted('country_table');
(1 row)

-- Change it back to encrypted
ALTER TABLE country_table SET access method pg_tde;
ALTER TABLE country_table SET access method pg_tde_basic;
INSERT INTO country_table (country_name, continent)
VALUES ('China', 'Asia'),
('Brazil', 'South America'),
Expand Down
2 changes: 1 addition & 1 deletion expected/insert_update_delete.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE albums (
artist VARCHAR(256),
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde;
) USING pg_tde_basic;
INSERT INTO albums (artist, title, released) VALUES
('Graindelavoix', 'Jisquin The Undead', '2021-06-12'),
('Graindelavoix', 'Tenebrae Responsoria - Carlo Gesualdo', '2019-08-06'),
Expand Down
2 changes: 1 addition & 1 deletion expected/move_large_tuples.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE sbtest2(
id SERIAL,
k TEXT STORAGE PLAIN,
PRIMARY KEY (id)
) USING pg_tde;
) USING pg_tde_basic;
INSERT INTO sbtest2(k) VALUES(repeat('a', 2500));
INSERT INTO sbtest2(k) VALUES(repeat('b', 2500));
INSERT INTO sbtest2(k) VALUES(repeat('c', 2500));
Expand Down
4 changes: 2 additions & 2 deletions expected/multi_insert.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CREATE TABLE albums (
artist_id INTEGER,
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde;
) USING pg_tde_basic;
COPY albums FROM stdin CSV HEADER;
SELECT * FROM albums;
album_id | artist_id | title | released
Expand Down Expand Up @@ -69,7 +69,7 @@ CREATE TABLE Towns (
name TEXT NOT NULL,
department VARCHAR(4) NOT NULL,
UNIQUE (code, department)
) USING pg_tde;
) USING pg_tde_basic;
COPY towns (id, code, article, name, department) FROM stdin;
SELECT count(*) FROM towns;
count
Expand Down
2 changes: 1 addition & 1 deletion expected/non_sorted_off_compact.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CREATE TABLE sbtest1(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde;
) USING pg_tde_basic;
INSERT INTO sbtest1(k) VALUES
(1),
(2),
Expand Down
8 changes: 4 additions & 4 deletions expected/pgtde_is_encrypted.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ CREATE TABLE test_enc(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde;
) USING pg_tde_basic;
CREATE TABLE test_norm(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING heap;
SELECT amname FROM pg_class INNER JOIN pg_am ON pg_am.oid = pg_class.relam WHERE relname = 'test_enc';
amname
--------
pg_tde
amname
--------------
pg_tde_basic
(1 row)

SELECT amname FROM pg_class INNER JOIN pg_am ON pg_am.oid = pg_class.relam WHERE relname = 'test_norm';
Expand Down
6 changes: 3 additions & 3 deletions expected/test_issue_153_fix.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CREATE TABLE dept (
deptno NUMERIC(2) NOT NULL CONSTRAINT dept_pk PRIMARY KEY,
dname VARCHAR(14) CONSTRAINT dept_dname_uq UNIQUE,
loc VARCHAR(13)
)using pg_tde;
)using pg_tde_basic;
--
-- Create the 'emp' table
--
Expand All @@ -45,7 +45,7 @@ CREATE TABLE emp (
comm NUMERIC(7,2),
deptno NUMERIC(2) CONSTRAINT emp_ref_dept_fk
REFERENCES dept(deptno)
)using pg_tde;
)using pg_tde_basic;
--
-- Create the 'jobhist' table
--
Expand All @@ -64,7 +64,7 @@ CREATE TABLE jobhist (
CONSTRAINT jobhist_ref_dept_fk FOREIGN KEY (deptno)
REFERENCES dept (deptno) ON DELETE SET NULL,
CONSTRAINT jobhist_date_chk CHECK (startdate <= enddate)
)using pg_tde;
)using pg_tde_basic;
--
-- Create the 'salesemp' view
--
Expand Down
2 changes: 1 addition & 1 deletion expected/toast_decrypt.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
t
(1 row)

CREATE TABLE src (f1 TEXT STORAGE EXTERNAL) USING pg_tde;
CREATE TABLE src (f1 TEXT STORAGE EXTERNAL) USING pg_tde_basic;
INSERT INTO src VALUES(repeat('abcdeF',1000));
SELECT * FROM src;
f1
Expand Down
6 changes: 3 additions & 3 deletions expected/toast_extended_storage.out

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions expected/trigger_on_view.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
--
-- 2 -- Test triggers on a join view
--
SET default_table_access_method TO 'pg_tde';
SET default_table_access_method TO 'pg_tde_basic';
DROP VIEW IF EXISTS city_view CASCADE;
NOTICE: view "city_view" does not exist, skipping
DROP TABLE IF exists country_table CASCADE;
Expand All @@ -25,7 +25,7 @@ NOTICE: table "city_table" does not exist, skipping
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde;
) using pg_tde_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand All @@ -45,7 +45,7 @@ NOTICE: table "city_table" does not exist, skipping
city_name text not null,
population bigint,
country_id int references country_table
) using pg_tde;
) using pg_tde_basic;

CREATE VIEW city_view AS
SELECT city_id, city_name, population, country_name, continent
Expand Down
2 changes: 1 addition & 1 deletion expected/update_compare_indexes.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');

DROP TABLE IF EXISTS pvactst;
NOTICE: table "pvactst" does not exist, skipping
CREATE TABLE pvactst (i INT, a INT[], p POINT) USING pg_tde;
CREATE TABLE pvactst (i INT, a INT[], p POINT) USING pg_tde_basic;
INSERT INTO pvactst SELECT i, array[1,2,3], point(i, i+1) FROM generate_series(1,1000) i;
CREATE INDEX spgist_pvactst ON pvactst USING spgist (p);
UPDATE pvactst SET i = i WHERE i < 1000;
Expand Down
2 changes: 1 addition & 1 deletion expected/vault_v2_test.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE test_enc(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde;
) USING pg_tde_basic;
INSERT INTO test_enc (k) VALUES (1);
INSERT INTO test_enc (k) VALUES (2);
INSERT INTO test_enc (k) VALUES (3);
Expand Down
67 changes: 37 additions & 30 deletions pg_tde--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ $$
LANGUAGE SQL;

-- Table access method
CREATE FUNCTION pg_tdeam_handler(internal)
RETURNS table_am_handler
AS 'MODULE_PATHNAME'
LANGUAGE C;

-- Table access method
CREATE FUNCTION pg_tde2am_handler(internal)
CREATE FUNCTION pg_tdeam_basic_handler(internal)
RETURNS table_am_handler
AS 'MODULE_PATHNAME'
LANGUAGE C;
Expand All @@ -75,7 +69,7 @@ SELECT EXISTS (
SELECT 1
FROM pg_catalog.pg_class
WHERE relname = table_name
AND relam = (SELECT oid FROM pg_catalog.pg_am WHERE amname = 'pg_tde')
AND relam = (SELECT oid FROM pg_catalog.pg_am WHERE amname = 'pg_tde_basic')
)$$
LANGUAGE SQL;

Expand Down Expand Up @@ -107,29 +101,42 @@ LANGUAGE C;
CREATE FUNCTION pg_tde_version() RETURNS TEXT AS 'MODULE_PATHNAME' LANGUAGE C;

-- Access method
CREATE ACCESS METHOD pg_tde TYPE TABLE HANDLER pg_tdeam_handler;
COMMENT ON ACCESS METHOD pg_tde IS 'pg_tde table access method';

CREATE ACCESS METHOD pg_tde2 TYPE TABLE HANDLER pg_tde2am_handler;
COMMENT ON ACCESS METHOD pg_tde2 IS 'pg_tde2 table access method';
CREATE ACCESS METHOD pg_tde_basic TYPE TABLE HANDLER pg_tdeam_basic_handler;
COMMENT ON ACCESS METHOD pg_tde_basic IS 'pg_tde table access method';

DO $$
BEGIN
-- Table access method
CREATE FUNCTION pg_tdeam_handler(internal)
RETURNS table_am_handler
AS 'MODULE_PATHNAME'
LANGUAGE C;

CREATE ACCESS METHOD pg_tde TYPE TABLE HANDLER pg_tdeam_handler;
COMMENT ON ACCESS METHOD pg_tde IS 'pg_tde table access method';

CREATE OR REPLACE FUNCTION pg_tde_ddl_command_start_capture()
RETURNS event_trigger
AS 'MODULE_PATHNAME'
LANGUAGE C;

CREATE OR REPLACE FUNCTION pg_tde_ddl_command_end_capture()
RETURNS event_trigger
AS 'MODULE_PATHNAME'
LANGUAGE C;

CREATE EVENT TRIGGER pg_tde_trigger_create_index
ON ddl_command_start
EXECUTE FUNCTION pg_tde_ddl_command_start_capture();

CREATE EVENT TRIGGER pg_tde_trigger_create_index_2
ON ddl_command_end
EXECUTE FUNCTION pg_tde_ddl_command_end_capture();
EXCEPTION WHEN OTHERS THEN
NULL;
END;
$$;

-- Per database extension initialization
SELECT pg_tde_extension_initialize();

CREATE OR REPLACE FUNCTION pg_tde_ddl_command_start_capture()
RETURNS event_trigger
AS 'MODULE_PATHNAME'
LANGUAGE C;

CREATE OR REPLACE FUNCTION pg_tde_ddl_command_end_capture()
RETURNS event_trigger
AS 'MODULE_PATHNAME'
LANGUAGE C;

CREATE EVENT TRIGGER pg_tde_trigger_create_index
ON ddl_command_start
EXECUTE FUNCTION pg_tde_ddl_command_start_capture();

CREATE EVENT TRIGGER pg_tde_trigger_create_index_2
ON ddl_command_end
EXECUTE FUNCTION pg_tde_ddl_command_end_capture();
6 changes: 3 additions & 3 deletions sql/change_access_method.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde;
) using pg_tde_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand All @@ -30,7 +30,7 @@ SELECT * FROM country_table;
SELECT pgtde_is_encrypted('country_table');

-- Change it back to encrypted
ALTER TABLE country_table SET access method pg_tde;
ALTER TABLE country_table SET access method pg_tde_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('China', 'Asia'),
Expand All @@ -40,4 +40,4 @@ SELECT * FROM country_table;
SELECT pgtde_is_encrypted('country_table');

DROP TABLE country_table;
DROP EXTENSION pg_tde;
DROP EXTENSION pg_tde;
2 changes: 1 addition & 1 deletion sql/insert_update_delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE albums (
artist VARCHAR(256),
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde;
) USING pg_tde_basic;

INSERT INTO albums (artist, title, released) VALUES
('Graindelavoix', 'Jisquin The Undead', '2021-06-12'),
Expand Down
2 changes: 1 addition & 1 deletion sql/move_large_tuples.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE sbtest2(
id SERIAL,
k TEXT STORAGE PLAIN,
PRIMARY KEY (id)
) USING pg_tde;
) USING pg_tde_basic;

INSERT INTO sbtest2(k) VALUES(repeat('a', 2500));
INSERT INTO sbtest2(k) VALUES(repeat('b', 2500));
Expand Down
4 changes: 2 additions & 2 deletions sql/multi_insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE albums (
artist_id INTEGER,
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde;
) USING pg_tde_basic;

COPY albums FROM stdin CSV HEADER;
album_id,artist_id,title,released
Expand Down Expand Up @@ -56,7 +56,7 @@ CREATE TABLE Towns (
name TEXT NOT NULL,
department VARCHAR(4) NOT NULL,
UNIQUE (code, department)
) USING pg_tde;
) USING pg_tde_basic;

COPY towns (id, code, article, name, department) FROM stdin;
1 001 some_text Abergement-Clémenciat 01
Expand Down
2 changes: 1 addition & 1 deletion sql/non_sorted_off_compact.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE sbtest1(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde;
) USING pg_tde_basic;

INSERT INTO sbtest1(k) VALUES
(1),
Expand Down
2 changes: 1 addition & 1 deletion sql/pgtde_is_encrypted.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE test_enc(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde;
) USING pg_tde_basic;

CREATE TABLE test_norm(
id SERIAL,
Expand Down
6 changes: 3 additions & 3 deletions sql/test_issue_153_fix.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CREATE TABLE dept (
deptno NUMERIC(2) NOT NULL CONSTRAINT dept_pk PRIMARY KEY,
dname VARCHAR(14) CONSTRAINT dept_dname_uq UNIQUE,
loc VARCHAR(13)
)using pg_tde;
)using pg_tde_basic;
--
-- Create the 'emp' table
--
Expand All @@ -36,7 +36,7 @@ CREATE TABLE emp (
comm NUMERIC(7,2),
deptno NUMERIC(2) CONSTRAINT emp_ref_dept_fk
REFERENCES dept(deptno)
)using pg_tde;
)using pg_tde_basic;
--
-- Create the 'jobhist' table
--
Expand All @@ -55,7 +55,7 @@ CREATE TABLE jobhist (
CONSTRAINT jobhist_ref_dept_fk FOREIGN KEY (deptno)
REFERENCES dept (deptno) ON DELETE SET NULL,
CONSTRAINT jobhist_date_chk CHECK (startdate <= enddate)
)using pg_tde;
)using pg_tde_basic;
--
-- Create the 'salesemp' view
--
Expand Down
2 changes: 1 addition & 1 deletion sql/toast_decrypt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CREATE EXTENSION pg_tde;
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');

CREATE TABLE src (f1 TEXT STORAGE EXTERNAL) USING pg_tde;
CREATE TABLE src (f1 TEXT STORAGE EXTERNAL) USING pg_tde_basic;
INSERT INTO src VALUES(repeat('abcdeF',1000));
SELECT * FROM src;

Expand Down
6 changes: 3 additions & 3 deletions sql/toast_extended_storage.sql

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sql/trigger_on_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
--
-- 2 -- Test triggers on a join view
--
SET default_table_access_method TO 'pg_tde';
SET default_table_access_method TO 'pg_tde_basic';

DROP VIEW IF EXISTS city_view CASCADE;
DROP TABLE IF exists country_table CASCADE;
Expand All @@ -16,7 +16,7 @@ DROP TABLE IF exists city_table cascade;
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde;
) using pg_tde_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand All @@ -29,7 +29,7 @@ DROP TABLE IF exists city_table cascade;
city_name text not null,
population bigint,
country_id int references country_table
) using pg_tde;
) using pg_tde_basic;

CREATE VIEW city_view AS
SELECT city_id, city_name, population, country_name, continent
Expand Down
Loading

0 comments on commit 8a2b8ec

Please sign in to comment.