mirror of
https://github.com/postgres/postgres.git
synced 2026-03-01 12:50:55 -05:00
Many of the objects we create during the regression tests are put in the public schema, so that using the same names in different regression tests creates a hazard of test failures if any two such scripts run concurrently. This patch cleans up a bunch of latent hazards of that sort, as well as two live hazards. The current situation in this regard is far worse than it was a year or two back, because practically all of the partitioning-related test cases have reused table names with enthusiasm. I despaired of cleaning up that mess within the five most-affected tests (create_table, alter_table, insert, update, inherit); fortunately those don't run concurrently. Other than partitioning problems, most of the issues boil down to using names like "foo", "bar", "tmp", etc, without thought for the fact that other test scripts might use similar names concurrently. I've made an effort to make all such names more specific. One of the live hazards was that commit7421f4b8caused with.sql to create a table named "test", conflicting with a similarly-named table in alter_table.sql; this was exposed in the buildfarm recently. The other one was that join.sql and transactions.sql both create tables named "foo" and "bar"; but join.sql's uses of those names date back only to December or so. Since commit7421f4b8was back-patched to v10, back-patch a minimal fix for that problem. The rest of this is just future-proofing. Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
61 lines
2.7 KiB
PL/PgSQL
61 lines
2.7 KiB
PL/PgSQL
CREATE TABLE indtoasttest(descr text, cnt int DEFAULT 0, f1 text, f2 text);
|
|
|
|
INSERT INTO indtoasttest(descr, f1, f2) VALUES('two-compressed', repeat('1234567890',1000), repeat('1234567890',1000));
|
|
INSERT INTO indtoasttest(descr, f1, f2) VALUES('two-toasted', repeat('1234567890',30000), repeat('1234567890',50000));
|
|
INSERT INTO indtoasttest(descr, f1, f2) VALUES('one-compressed,one-null', NULL, repeat('1234567890',1000));
|
|
INSERT INTO indtoasttest(descr, f1, f2) VALUES('one-toasted,one-null', NULL, repeat('1234567890',50000));
|
|
|
|
-- check whether indirect tuples works on the most basic level
|
|
SELECT descr, substring(make_tuple_indirect(indtoasttest)::text, 1, 200) FROM indtoasttest;
|
|
|
|
-- modification without changing varlenas
|
|
UPDATE indtoasttest SET cnt = cnt +1 RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
-- modification without modifying assigned value
|
|
UPDATE indtoasttest SET cnt = cnt +1, f1 = f1 RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
-- modification modifying, but effectively not changing
|
|
UPDATE indtoasttest SET cnt = cnt +1, f1 = f1||'' RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
UPDATE indtoasttest SET cnt = cnt +1, f1 = '-'||f1||'-' RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
|
|
-- check we didn't screw with main/toast tuple visibility
|
|
VACUUM FREEZE indtoasttest;
|
|
SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
|
|
|
|
-- now create a trigger that forces all Datums to be indirect ones
|
|
CREATE FUNCTION update_using_indirect()
|
|
RETURNS trigger
|
|
LANGUAGE plpgsql AS $$
|
|
BEGIN
|
|
NEW := make_tuple_indirect(NEW);
|
|
RETURN NEW;
|
|
END$$;
|
|
|
|
CREATE TRIGGER indtoasttest_update_indirect
|
|
BEFORE INSERT OR UPDATE
|
|
ON indtoasttest
|
|
FOR EACH ROW
|
|
EXECUTE PROCEDURE update_using_indirect();
|
|
|
|
-- modification without changing varlenas
|
|
UPDATE indtoasttest SET cnt = cnt +1 RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
-- modification without modifying assigned value
|
|
UPDATE indtoasttest SET cnt = cnt +1, f1 = f1 RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
-- modification modifying, but effectively not changing
|
|
UPDATE indtoasttest SET cnt = cnt +1, f1 = f1||'' RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
UPDATE indtoasttest SET cnt = cnt +1, f1 = '-'||f1||'-' RETURNING substring(indtoasttest::text, 1, 200);
|
|
|
|
INSERT INTO indtoasttest(descr, f1, f2) VALUES('one-toasted,one-null, via indirect', repeat('1234567890',30000), NULL);
|
|
|
|
SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
|
|
-- check we didn't screw with main/toast tuple visibility
|
|
VACUUM FREEZE indtoasttest;
|
|
SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
|
|
|
|
DROP TABLE indtoasttest;
|
|
DROP FUNCTION update_using_indirect();
|