summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-07-01 00:52:04 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-07-01 00:52:04 +0000
commit573a71a5da70d6e2503c8f53e3b4f26b3b6d738d (patch)
tree070f677b0043631518f83ce84ff201bf8fda700f /src/test
parent4c9aa572fa2ee60e8ac557b866eccc7310df0a09 (diff)
Nested transactions. There is still much left to do, especially on the
performance front, but with feature freeze upon us I think it's time to drive a stake in the ground and say that this will be in 7.5. Alvaro Herrera, with some help from Tom Lane.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/transactions.out67
-rw-r--r--src/test/regress/expected/without_oid.out23
-rw-r--r--src/test/regress/sql/transactions.sql45
-rw-r--r--src/test/regress/sql/without_oid.sql21
4 files changed, 152 insertions, 4 deletions
diff --git a/src/test/regress/expected/transactions.out b/src/test/regress/expected/transactions.out
index b72ca5f36e5..6cc89b5c5e4 100644
--- a/src/test/regress/expected/transactions.out
+++ b/src/test/regress/expected/transactions.out
@@ -68,3 +68,70 @@ ERROR: transaction is read-only
START TRANSACTION READ WRITE;
DROP TABLE writetest; -- ok
COMMIT;
+-- Subtransactions, basic tests
+-- create & drop tables
+SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE;
+CREATE TABLE foobar (a int);
+BEGIN;
+ CREATE TABLE foo (a int);
+ BEGIN;
+ DROP TABLE foo;
+ CREATE TABLE bar (a int);
+ ROLLBACK;
+ BEGIN;
+ CREATE TABLE baz (a int);
+ COMMIT;
+ drop TABLE foobar;
+ CREATE TABLE barbaz (a int);
+COMMIT;
+-- should exist: barbaz, baz, foo
+SELECT * FROM foo; -- should be empty
+ a
+---
+(0 rows)
+
+SELECT * FROM bar; -- shouldn't exist
+ERROR: relation "bar" does not exist
+SELECT * FROM barbaz; -- should be empty
+ a
+---
+(0 rows)
+
+SELECT * FROM baz; -- should be empty
+ a
+---
+(0 rows)
+
+-- inserts
+BEGIN;
+ INSERT INTO foo VALUES (1);
+ BEGIN;
+ INSERT into bar VALUES (1);
+ERROR: relation "bar" does not exist
+ ROLLBACK;
+ BEGIN;
+ INSERT into barbaz VALUES (1);
+ COMMIT;
+ BEGIN;
+ BEGIN;
+ INSERT INTO foo VALUES (2);
+ COMMIT;
+ ROLLBACK;
+ INSERT INTO foo VALUES (3);
+COMMIT;
+SELECT * FROM foo; -- should have 1 and 3
+ a
+---
+ 1
+ 3
+(2 rows)
+
+SELECT * FROM barbaz; -- should have 1
+ a
+---
+ 1
+(1 row)
+
+DROP TABLE foo;
+DROP TABLE baz;
+DROP TABLE barbaz;
diff --git a/src/test/regress/expected/without_oid.out b/src/test/regress/expected/without_oid.out
index ef373e6e3c3..708c4c5e94d 100644
--- a/src/test/regress/expected/without_oid.out
+++ b/src/test/regress/expected/without_oid.out
@@ -1,8 +1,18 @@
--
-- WITHOUT OID
--
-CREATE TABLE wi (i INT) WITH OIDS;
-CREATE TABLE wo (i INT) WITHOUT OIDS;
+--
+-- This test tries to verify that WITHOUT OIDS actually saves space.
+-- On machines where MAXALIGN is 8, WITHOUT OIDS may or may not save any
+-- space, depending on the size of the tuple header + null bitmap.
+-- As of 7.5 we need a 9-bit null bitmap to force the difference to appear.
+--
+CREATE TABLE wi (i INT,
+ n1 int, n2 int, n3 int, n4 int,
+ n5 int, n6 int, n7 int, n8 int) WITH OIDS;
+CREATE TABLE wo (i INT,
+ n1 int, n2 int, n3 int, n4 int,
+ n5 int, n6 int, n7 int, n8 int) WITHOUT OIDS;
INSERT INTO wi VALUES (1); -- 1
INSERT INTO wo SELECT i FROM wi; -- 1
INSERT INTO wo SELECT i+1 FROM wi; -- 1+1=2
@@ -24,6 +34,15 @@ INSERT INTO wo SELECT i+896 FROM wi; -- 896+2448=3344
INSERT INTO wo SELECT i+3344 FROM wo; -- 3344+3344=6688
INSERT INTO wi SELECT i+2448 FROM wo; -- 2448+6688=9136
INSERT INTO wo SELECT i+6688 FROM wi WHERE i<=2448; -- 6688+2448=9136
+SELECT count(oid) FROM wi;
+ count
+-------
+ 9136
+(1 row)
+
+-- should fail
+SELECT count(oid) FROM wo;
+ERROR: column "oid" does not exist
VACUUM ANALYZE wi;
VACUUM ANALYZE wo;
SELECT min(relpages) < max(relpages), min(reltuples) - max(reltuples)
diff --git a/src/test/regress/sql/transactions.sql b/src/test/regress/sql/transactions.sql
index 10ef759998b..a656c393b4f 100644
--- a/src/test/regress/sql/transactions.sql
+++ b/src/test/regress/sql/transactions.sql
@@ -54,3 +54,48 @@ CREATE TABLE test AS SELECT * FROM writetest; -- fail
START TRANSACTION READ WRITE;
DROP TABLE writetest; -- ok
COMMIT;
+
+-- Subtransactions, basic tests
+-- create & drop tables
+SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE;
+CREATE TABLE foobar (a int);
+BEGIN;
+ CREATE TABLE foo (a int);
+ BEGIN;
+ DROP TABLE foo;
+ CREATE TABLE bar (a int);
+ ROLLBACK;
+ BEGIN;
+ CREATE TABLE baz (a int);
+ COMMIT;
+ drop TABLE foobar;
+ CREATE TABLE barbaz (a int);
+COMMIT;
+-- should exist: barbaz, baz, foo
+SELECT * FROM foo; -- should be empty
+SELECT * FROM bar; -- shouldn't exist
+SELECT * FROM barbaz; -- should be empty
+SELECT * FROM baz; -- should be empty
+
+-- inserts
+BEGIN;
+ INSERT INTO foo VALUES (1);
+ BEGIN;
+ INSERT into bar VALUES (1);
+ ROLLBACK;
+ BEGIN;
+ INSERT into barbaz VALUES (1);
+ COMMIT;
+ BEGIN;
+ BEGIN;
+ INSERT INTO foo VALUES (2);
+ COMMIT;
+ ROLLBACK;
+ INSERT INTO foo VALUES (3);
+COMMIT;
+SELECT * FROM foo; -- should have 1 and 3
+SELECT * FROM barbaz; -- should have 1
+
+DROP TABLE foo;
+DROP TABLE baz;
+DROP TABLE barbaz;
diff --git a/src/test/regress/sql/without_oid.sql b/src/test/regress/sql/without_oid.sql
index 4cb961941a9..2c176c8e3e2 100644
--- a/src/test/regress/sql/without_oid.sql
+++ b/src/test/regress/sql/without_oid.sql
@@ -2,8 +2,19 @@
-- WITHOUT OID
--
-CREATE TABLE wi (i INT) WITH OIDS;
-CREATE TABLE wo (i INT) WITHOUT OIDS;
+--
+-- This test tries to verify that WITHOUT OIDS actually saves space.
+-- On machines where MAXALIGN is 8, WITHOUT OIDS may or may not save any
+-- space, depending on the size of the tuple header + null bitmap.
+-- As of 7.5 we need a 9-bit null bitmap to force the difference to appear.
+--
+CREATE TABLE wi (i INT,
+ n1 int, n2 int, n3 int, n4 int,
+ n5 int, n6 int, n7 int, n8 int) WITH OIDS;
+CREATE TABLE wo (i INT,
+ n1 int, n2 int, n3 int, n4 int,
+ n5 int, n6 int, n7 int, n8 int) WITHOUT OIDS;
+
INSERT INTO wi VALUES (1); -- 1
INSERT INTO wo SELECT i FROM wi; -- 1
INSERT INTO wo SELECT i+1 FROM wi; -- 1+1=2
@@ -25,8 +36,14 @@ INSERT INTO wo SELECT i+896 FROM wi; -- 896+2448=3344
INSERT INTO wo SELECT i+3344 FROM wo; -- 3344+3344=6688
INSERT INTO wi SELECT i+2448 FROM wo; -- 2448+6688=9136
INSERT INTO wo SELECT i+6688 FROM wi WHERE i<=2448; -- 6688+2448=9136
+
+SELECT count(oid) FROM wi;
+-- should fail
+SELECT count(oid) FROM wo;
+
VACUUM ANALYZE wi;
VACUUM ANALYZE wo;
+
SELECT min(relpages) < max(relpages), min(reltuples) - max(reltuples)
FROM pg_class
WHERE relname IN ('wi', 'wo');