mirror of https://github.com/citusdata/citus.git
Fixes tests for ALTER TRIGGER RENAME consistency for part. tables
Relevant PG commit: 80ba4bb383538a2ee846fece6a7b8da9518b6866pg15_onder_gpid
parent
3402faf01d
commit
87db78eab8
|
@ -733,33 +733,29 @@ SELECT operation_type, product_sku, state_code FROM record_sale ORDER BY 1,2,3;
|
|||
--
|
||||
--Test ALTER TRIGGER
|
||||
--
|
||||
-- Pre PG15, renaming the trigger on the parent table didn't rename the same trigger on
|
||||
-- the children as well. Hence, let's not print the trigger names of the children
|
||||
-- In PG15, rename is consistent for all partitions of the parent
|
||||
-- This is tested in pg15.sql file.
|
||||
CREATE VIEW sale_triggers AS
|
||||
SELECT tgname, tgrelid::regclass, tgenabled
|
||||
FROM pg_trigger
|
||||
WHERE tgrelid::regclass::text like 'sale%'
|
||||
WHERE tgrelid::regclass::text = 'sale'
|
||||
ORDER BY 1, 2;
|
||||
SELECT * FROM sale_triggers ORDER BY 1,2;
|
||||
tgname | tgrelid | tgenabled
|
||||
---------------------------------------------------------------------
|
||||
record_sale_trigger | sale | O
|
||||
record_sale_trigger | sale_newyork | O
|
||||
record_sale_trigger | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale | O
|
||||
truncate_trigger_xxxxxxx | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale_newyork | O
|
||||
(6 rows)
|
||||
(2 rows)
|
||||
|
||||
ALTER TRIGGER "record_sale_trigger" ON "distributed_triggers"."sale" RENAME TO "new_record_sale_trigger";
|
||||
SELECT * FROM sale_triggers ORDER BY 1,2;
|
||||
tgname | tgrelid | tgenabled
|
||||
---------------------------------------------------------------------
|
||||
new_record_sale_trigger | sale | O
|
||||
record_sale_trigger | sale_newyork | O
|
||||
record_sale_trigger | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale | O
|
||||
truncate_trigger_xxxxxxx | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale_newyork | O
|
||||
(6 rows)
|
||||
(2 rows)
|
||||
|
||||
CREATE EXTENSION seg;
|
||||
ALTER TRIGGER "emptest_audit" ON "emptest" DEPENDS ON EXTENSION seg;
|
||||
|
|
|
@ -93,8 +93,87 @@ SELECT result FROM run_command_on_all_nodes('
|
|||
|
||||
(3 rows)
|
||||
|
||||
--
|
||||
-- In PG15, Renaming triggers on partitioned tables had two problems
|
||||
-- recurses to renaming the triggers on the partitions as well.
|
||||
-- Here we test that distributed triggers behave the same way.
|
||||
-- Relevant PG commit:
|
||||
-- 80ba4bb383538a2ee846fece6a7b8da9518b6866
|
||||
--
|
||||
SET citus.enable_unsafe_triggers TO true;
|
||||
CREATE TABLE sale(
|
||||
sale_date date not null,
|
||||
state_code text,
|
||||
product_sku text,
|
||||
units integer)
|
||||
PARTITION BY list (state_code);
|
||||
ALTER TABLE sale ADD CONSTRAINT sale_pk PRIMARY KEY (state_code, sale_date);
|
||||
CREATE TABLE sale_newyork PARTITION OF sale FOR VALUES IN ('NY');
|
||||
CREATE TABLE sale_california PARTITION OF sale FOR VALUES IN ('CA');
|
||||
CREATE TABLE record_sale(
|
||||
operation_type text not null,
|
||||
product_sku text,
|
||||
state_code text,
|
||||
units integer,
|
||||
PRIMARY KEY(state_code, product_sku, operation_type, units));
|
||||
SELECT create_distributed_table('sale', 'state_code');
|
||||
create_distributed_table
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT create_distributed_table('record_sale', 'state_code', colocate_with := 'sale');
|
||||
create_distributed_table
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE OR REPLACE FUNCTION record_sale()
|
||||
RETURNS trigger
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO pg15.record_sale(operation_type, product_sku, state_code, units)
|
||||
VALUES (TG_OP, NEW.product_sku, NEW.state_code, NEW.units);
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE TRIGGER record_sale_trigger
|
||||
AFTER INSERT OR UPDATE OR DELETE ON sale
|
||||
FOR EACH ROW EXECUTE FUNCTION pg15.record_sale();
|
||||
CREATE VIEW sale_triggers AS
|
||||
SELECT tgname, tgrelid::regclass, tgenabled
|
||||
FROM pg_trigger
|
||||
WHERE tgrelid::regclass::text like 'sale%'
|
||||
ORDER BY 1, 2;
|
||||
SELECT * FROM sale_triggers ORDER BY 1, 2;
|
||||
tgname | tgrelid | tgenabled
|
||||
---------------------------------------------------------------------
|
||||
record_sale_trigger | sale | O
|
||||
record_sale_trigger | sale_newyork | O
|
||||
record_sale_trigger | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale | O
|
||||
truncate_trigger_xxxxxxx | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale_newyork | O
|
||||
(6 rows)
|
||||
|
||||
ALTER TRIGGER "record_sale_trigger" ON "pg15"."sale" RENAME TO "new_record_sale_trigger";
|
||||
SELECT * FROM sale_triggers ORDER BY 1, 2;
|
||||
tgname | tgrelid | tgenabled
|
||||
---------------------------------------------------------------------
|
||||
new_record_sale_trigger | sale | O
|
||||
new_record_sale_trigger | sale_newyork | O
|
||||
new_record_sale_trigger | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale | O
|
||||
truncate_trigger_xxxxxxx | sale_california | O
|
||||
truncate_trigger_xxxxxxx | sale_newyork | O
|
||||
(6 rows)
|
||||
|
||||
-- Clean up
|
||||
DROP SCHEMA pg15 CASCADE;
|
||||
NOTICE: drop cascades to 2 other objects
|
||||
NOTICE: drop cascades to 6 other objects
|
||||
DETAIL: drop cascades to collation german_phonebook_test
|
||||
drop cascades to collation default_provider
|
||||
drop cascades to table sale
|
||||
drop cascades to table record_sale
|
||||
drop cascades to function record_sale()
|
||||
drop cascades to view sale_triggers
|
||||
|
|
|
@ -415,10 +415,15 @@ SELECT operation_type, product_sku, state_code FROM record_sale ORDER BY 1,2,3;
|
|||
--
|
||||
--Test ALTER TRIGGER
|
||||
--
|
||||
-- Pre PG15, renaming the trigger on the parent table didn't rename the same trigger on
|
||||
-- the children as well. Hence, let's not print the trigger names of the children
|
||||
-- In PG15, rename is consistent for all partitions of the parent
|
||||
-- This is tested in pg15.sql file.
|
||||
|
||||
CREATE VIEW sale_triggers AS
|
||||
SELECT tgname, tgrelid::regclass, tgenabled
|
||||
FROM pg_trigger
|
||||
WHERE tgrelid::regclass::text like 'sale%'
|
||||
WHERE tgrelid::regclass::text = 'sale'
|
||||
ORDER BY 1, 2;
|
||||
|
||||
SELECT * FROM sale_triggers ORDER BY 1,2;
|
||||
|
|
|
@ -58,5 +58,61 @@ SELECT result FROM run_command_on_all_nodes('
|
|||
SELECT colliculocale FROM pg_collation WHERE collname = ''default_provider'';
|
||||
');
|
||||
|
||||
--
|
||||
-- In PG15, Renaming triggers on partitioned tables had two problems
|
||||
-- recurses to renaming the triggers on the partitions as well.
|
||||
-- Here we test that distributed triggers behave the same way.
|
||||
-- Relevant PG commit:
|
||||
-- 80ba4bb383538a2ee846fece6a7b8da9518b6866
|
||||
--
|
||||
|
||||
SET citus.enable_unsafe_triggers TO true;
|
||||
|
||||
CREATE TABLE sale(
|
||||
sale_date date not null,
|
||||
state_code text,
|
||||
product_sku text,
|
||||
units integer)
|
||||
PARTITION BY list (state_code);
|
||||
|
||||
ALTER TABLE sale ADD CONSTRAINT sale_pk PRIMARY KEY (state_code, sale_date);
|
||||
|
||||
CREATE TABLE sale_newyork PARTITION OF sale FOR VALUES IN ('NY');
|
||||
CREATE TABLE sale_california PARTITION OF sale FOR VALUES IN ('CA');
|
||||
|
||||
CREATE TABLE record_sale(
|
||||
operation_type text not null,
|
||||
product_sku text,
|
||||
state_code text,
|
||||
units integer,
|
||||
PRIMARY KEY(state_code, product_sku, operation_type, units));
|
||||
|
||||
SELECT create_distributed_table('sale', 'state_code');
|
||||
SELECT create_distributed_table('record_sale', 'state_code', colocate_with := 'sale');
|
||||
|
||||
CREATE OR REPLACE FUNCTION record_sale()
|
||||
RETURNS trigger
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO pg15.record_sale(operation_type, product_sku, state_code, units)
|
||||
VALUES (TG_OP, NEW.product_sku, NEW.state_code, NEW.units);
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER record_sale_trigger
|
||||
AFTER INSERT OR UPDATE OR DELETE ON sale
|
||||
FOR EACH ROW EXECUTE FUNCTION pg15.record_sale();
|
||||
|
||||
CREATE VIEW sale_triggers AS
|
||||
SELECT tgname, tgrelid::regclass, tgenabled
|
||||
FROM pg_trigger
|
||||
WHERE tgrelid::regclass::text like 'sale%'
|
||||
ORDER BY 1, 2;
|
||||
|
||||
SELECT * FROM sale_triggers ORDER BY 1, 2;
|
||||
ALTER TRIGGER "record_sale_trigger" ON "pg15"."sale" RENAME TO "new_record_sale_trigger";
|
||||
SELECT * FROM sale_triggers ORDER BY 1, 2;
|
||||
|
||||
-- Clean up
|
||||
DROP SCHEMA pg15 CASCADE;
|
||||
|
|
Loading…
Reference in New Issue