mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Make viewquery a copy in rewriteTargetView()
Rather than expect the Query returned by get_view_query() to be
read-only and then copy bits and pieces of it out, simply copy the
entire structure when we get it. This addresses an issue where
AcquireRewriteLocks, which is called by acquireLocksOnSubLinks(),
scribbles on the parsetree passed in, which was actually an entry
in relcache, leading to segfaults with certain view definitions.
This also future-proofs us a bit for anyone adding more code to this
path.
The acquireLocksOnSubLinks() was added in commit c3e0ddd40
.
Back-patch to 9.3 as that commit was.
This commit is contained in:
@ -2353,3 +2353,70 @@ DROP TABLE t1, t11, t12, t111 CASCADE;
|
||||
NOTICE: drop cascades to view v1
|
||||
DROP FUNCTION snoop(anyelement);
|
||||
DROP FUNCTION leakproof(anyelement);
|
||||
CREATE TABLE tx1 (a integer);
|
||||
CREATE TABLE tx2 (b integer);
|
||||
CREATE TABLE tx3 (c integer);
|
||||
CREATE VIEW vx1 AS SELECT a FROM tx1 WHERE EXISTS(SELECT 1 FROM tx2 JOIN tx3 ON b=c);
|
||||
INSERT INTO vx1 values (1);
|
||||
SELECT * FROM tx1;
|
||||
a
|
||||
---
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM vx1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
DROP VIEW vx1;
|
||||
DROP TABLE tx1;
|
||||
DROP TABLE tx2;
|
||||
DROP TABLE tx3;
|
||||
CREATE TABLE tx1 (a integer);
|
||||
CREATE TABLE tx2 (b integer);
|
||||
CREATE TABLE tx3 (c integer);
|
||||
CREATE VIEW vx1 AS SELECT a FROM tx1 WHERE EXISTS(SELECT 1 FROM tx2 JOIN tx3 ON b=c);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
SELECT * FROM tx1;
|
||||
a
|
||||
---
|
||||
1
|
||||
1
|
||||
(2 rows)
|
||||
|
||||
SELECT * FROM vx1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
DROP VIEW vx1;
|
||||
DROP TABLE tx1;
|
||||
DROP TABLE tx2;
|
||||
DROP TABLE tx3;
|
||||
CREATE TABLE tx1 (a integer, b integer);
|
||||
CREATE TABLE tx2 (b integer, c integer);
|
||||
CREATE TABLE tx3 (c integer, d integer);
|
||||
ALTER TABLE tx1 DROP COLUMN b;
|
||||
ALTER TABLE tx2 DROP COLUMN c;
|
||||
ALTER TABLE tx3 DROP COLUMN d;
|
||||
CREATE VIEW vx1 AS SELECT a FROM tx1 WHERE EXISTS(SELECT 1 FROM tx2 JOIN tx3 ON b=c);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
SELECT * FROM tx1;
|
||||
a
|
||||
---
|
||||
1
|
||||
1
|
||||
(2 rows)
|
||||
|
||||
SELECT * FROM vx1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
DROP VIEW vx1;
|
||||
DROP TABLE tx1;
|
||||
DROP TABLE tx2;
|
||||
DROP TABLE tx3;
|
||||
|
@ -1020,3 +1020,47 @@ TABLE t1; -- verify all a<=5 are intact
|
||||
DROP TABLE t1, t11, t12, t111 CASCADE;
|
||||
DROP FUNCTION snoop(anyelement);
|
||||
DROP FUNCTION leakproof(anyelement);
|
||||
|
||||
CREATE TABLE tx1 (a integer);
|
||||
CREATE TABLE tx2 (b integer);
|
||||
CREATE TABLE tx3 (c integer);
|
||||
CREATE VIEW vx1 AS SELECT a FROM tx1 WHERE EXISTS(SELECT 1 FROM tx2 JOIN tx3 ON b=c);
|
||||
INSERT INTO vx1 values (1);
|
||||
SELECT * FROM tx1;
|
||||
SELECT * FROM vx1;
|
||||
|
||||
DROP VIEW vx1;
|
||||
DROP TABLE tx1;
|
||||
DROP TABLE tx2;
|
||||
DROP TABLE tx3;
|
||||
|
||||
CREATE TABLE tx1 (a integer);
|
||||
CREATE TABLE tx2 (b integer);
|
||||
CREATE TABLE tx3 (c integer);
|
||||
CREATE VIEW vx1 AS SELECT a FROM tx1 WHERE EXISTS(SELECT 1 FROM tx2 JOIN tx3 ON b=c);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
SELECT * FROM tx1;
|
||||
SELECT * FROM vx1;
|
||||
|
||||
DROP VIEW vx1;
|
||||
DROP TABLE tx1;
|
||||
DROP TABLE tx2;
|
||||
DROP TABLE tx3;
|
||||
|
||||
CREATE TABLE tx1 (a integer, b integer);
|
||||
CREATE TABLE tx2 (b integer, c integer);
|
||||
CREATE TABLE tx3 (c integer, d integer);
|
||||
ALTER TABLE tx1 DROP COLUMN b;
|
||||
ALTER TABLE tx2 DROP COLUMN c;
|
||||
ALTER TABLE tx3 DROP COLUMN d;
|
||||
CREATE VIEW vx1 AS SELECT a FROM tx1 WHERE EXISTS(SELECT 1 FROM tx2 JOIN tx3 ON b=c);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
INSERT INTO vx1 VALUES (1);
|
||||
SELECT * FROM tx1;
|
||||
SELECT * FROM vx1;
|
||||
|
||||
DROP VIEW vx1;
|
||||
DROP TABLE tx1;
|
||||
DROP TABLE tx2;
|
||||
DROP TABLE tx3;
|
||||
|
Reference in New Issue
Block a user