Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite98a4de

Browse files
committed
Use the correct tuplestore read pointer in a NamedTuplestoreScan.
Tom Kazimiers reported that transition tables don't work correctly whenthey are scanned by more than one executor node. That's because commit18ce3a4 allocated separate read pointers for each executor node, as itmust, but failed to make them active at the appropriate times. Repair.Thomas MunroDiscussion:https://postgr.es/m/20180224034748.bixarv6632vbxgeb%40dewberry.localdomain
1 parentc40e20a commite98a4de

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

‎src/backend/executor/nodeNamedtuplestorescan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ NamedTuplestoreScanNext(NamedTuplestoreScanState *node)
4040
* Get the next tuple from tuplestore. Return NULL if no more tuples.
4141
*/
4242
slot=node->ss.ss_ScanTupleSlot;
43+
tuplestore_select_read_pointer(node->relation,node->readptr);
4344
(void)tuplestore_gettupleslot(node->relation, true, false,slot);
4445
returnslot;
4546
}
@@ -116,6 +117,7 @@ ExecInitNamedTuplestoreScan(NamedTuplestoreScan *node, EState *estate, int eflag
116117
* The new read pointer copies its position from read pointer 0, which
117118
* could be anywhere, so explicitly rewind it.
118119
*/
120+
tuplestore_select_read_pointer(scanstate->relation,scanstate->readptr);
119121
tuplestore_rescan(scanstate->relation);
120122

121123
/*

‎src/test/regress/expected/plpgsql.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5559,6 +5559,28 @@ LINE 1: SELECT (SELECT string_agg(id || '=' || name, ',') FROM d)
55595559
QUERY: SELECT (SELECT string_agg(id || '=' || name, ',') FROM d)
55605560
CONTEXT: PL/pgSQL function alter_table_under_transition_tables_upd_func() line 3 at RAISE
55615561
--
5562+
-- Test multiple reference to a transition table
5563+
--
5564+
CREATE TABLE multi_test (i int);
5565+
INSERT INTO multi_test VALUES (1);
5566+
CREATE OR REPLACE FUNCTION multi_test_trig() RETURNS trigger
5567+
LANGUAGE plpgsql AS $$
5568+
BEGIN
5569+
RAISE NOTICE 'count = %', (SELECT COUNT(*) FROM new_test);
5570+
RAISE NOTICE 'count union = %',
5571+
(SELECT COUNT(*)
5572+
FROM (SELECT * FROM new_test UNION ALL SELECT * FROM new_test) ss);
5573+
RETURN NULL;
5574+
END$$;
5575+
CREATE TRIGGER my_trigger AFTER UPDATE ON multi_test
5576+
REFERENCING NEW TABLE AS new_test OLD TABLE as old_test
5577+
FOR EACH STATEMENT EXECUTE PROCEDURE multi_test_trig();
5578+
UPDATE multi_test SET i = i;
5579+
NOTICE: count = 1
5580+
NOTICE: count union = 2
5581+
DROP TABLE multi_test;
5582+
DROP FUNCTION multi_test_trig();
5583+
--
55625584
-- Check type parsing and record fetching from partitioned tables
55635585
--
55645586
CREATE TABLE partitioned_table (a int, b text) PARTITION BY LIST (a);

‎src/test/regress/sql/plpgsql.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4503,6 +4503,32 @@ ALTER TABLE alter_table_under_transition_tables
45034503
UPDATE alter_table_under_transition_tables
45044504
SET id= id;
45054505

4506+
--
4507+
-- Test multiple reference to a transition table
4508+
--
4509+
4510+
CREATETABLEmulti_test (iint);
4511+
INSERT INTO multi_testVALUES (1);
4512+
4513+
CREATE OR REPLACEFUNCTIONmulti_test_trig() RETURNS trigger
4514+
LANGUAGE plpgsqlAS $$
4515+
BEGIN
4516+
RAISE NOTICE'count = %', (SELECTCOUNT(*)FROM new_test);
4517+
RAISE NOTICE'count union = %',
4518+
(SELECTCOUNT(*)
4519+
FROM (SELECT*FROM new_testUNION ALLSELECT*FROM new_test) ss);
4520+
RETURNNULL;
4521+
END$$;
4522+
4523+
CREATETRIGGERmy_trigger AFTERUPDATEON multi_test
4524+
REFERENCING NEW TABLEAS new_test OLD TABLEas old_test
4525+
FOR EACH STATEMENT EXECUTE PROCEDURE multi_test_trig();
4526+
4527+
UPDATE multi_testSET i= i;
4528+
4529+
DROPTABLE multi_test;
4530+
DROPFUNCTION multi_test_trig();
4531+
45064532
--
45074533
-- Check type parsing and record fetching from partitioned tables
45084534
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp