Add basic read-only transaction tests

pull/1208/head
Marco Slot 2017-04-07 12:18:34 +02:00
parent f838c83809
commit 3d99cdfcc7
6 changed files with 57 additions and 0 deletions

View File

@ -22,6 +22,16 @@ SELECT avg(l_extendedprice) FROM lineitem;
38141.835375000000
(1 row)
-- Verify that we can do queries in read-only mode
BEGIN;
SET TRANSACTION READ ONLY;
SELECT count(*) FROM lineitem;
count
-------
12000
(1 row)
COMMIT;
-- Verify temp tables which are used for final result aggregation don't persist.
SELECT count(*) FROM pg_class WHERE relname LIKE 'pg_merge_job_%' AND relkind = 'r';
count

View File

@ -2023,6 +2023,26 @@ DEBUG: Plan is router executable
41 | 1 | aznavour | 11814
(5 rows)
END;
-- queries inside read-only transactions can be router plannable
BEGIN;
SET TRANSACTION READ ONLY;
SELECT *
FROM articles_hash
WHERE author_id = 1
ORDER BY id;
DEBUG: predicate pruning for shardId 840001
DEBUG: Creating router plan
DEBUG: Plan is router executable
id | author_id | title | word_count
----+-----------+--------------+------------
1 | 1 | arsenous | 9572
11 | 1 | alamo | 1347
21 | 1 | arcading | 5890
31 | 1 | athwartships | 7271
41 | 1 | aznavour | 11814
(5 rows)
END;
-- cursor queries are router plannable
BEGIN;

View File

@ -19,6 +19,12 @@ SELECT master_create_worker_shards('sharded_table', 2, 1);
COPY sharded_table TO STDOUT;
COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT;
0
BEGIN;
SET TRANSACTION READ ONLY;
COPY sharded_table TO STDOUT;
COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT;
0
COMMIT;
-- cursors may not involve distributed tables
DECLARE all_sharded_rows CURSOR FOR SELECT * FROM sharded_table;
ERROR: DECLARE CURSOR can only be used in transaction blocks

View File

@ -15,5 +15,11 @@ SELECT sum(l_extendedprice) FROM lineitem;
SELECT avg(l_extendedprice) FROM lineitem;
-- Verify that we can do queries in read-only mode
BEGIN;
SET TRANSACTION READ ONLY;
SELECT count(*) FROM lineitem;
COMMIT;
-- Verify temp tables which are used for final result aggregation don't persist.
SELECT count(*) FROM pg_class WHERE relname LIKE 'pg_merge_job_%' AND relkind = 'r';

View File

@ -906,6 +906,15 @@ SELECT *
ORDER BY id;
END;
-- queries inside read-only transactions can be router plannable
BEGIN;
SET TRANSACTION READ ONLY;
SELECT *
FROM articles_hash
WHERE author_id = 1
ORDER BY id;
END;
-- cursor queries are router plannable
BEGIN;
DECLARE test_cursor CURSOR FOR

View File

@ -14,6 +14,12 @@ SELECT master_create_worker_shards('sharded_table', 2, 1);
COPY sharded_table TO STDOUT;
COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT;
BEGIN;
SET TRANSACTION READ ONLY;
COPY sharded_table TO STDOUT;
COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT;
COMMIT;
-- cursors may not involve distributed tables
DECLARE all_sharded_rows CURSOR FOR SELECT * FROM sharded_table;