Update reference table test to correct vkey value in update statement

pull/7897/head
Mehmet Yilmaz 2025-02-13 06:00:25 +00:00 committed by Mehmet YILMAZ
parent 54d03be16a
commit c51d26b2fd
2 changed files with 2 additions and 14 deletions

View File

@ -3,14 +3,12 @@
-- https://github.com/citusdata/citus/issues/7891 -- https://github.com/citusdata/citus/issues/7891
CREATE SCHEMA issue_7891; CREATE SCHEMA issue_7891;
SET search_path TO issue_7891; SET search_path TO issue_7891;
-- Create tables -- Create tables
CREATE TABLE t2_ref ( CREATE TABLE t2_ref (
vkey INT, vkey INT,
pkey INT, pkey INT,
c15 TIMESTAMP c15 TIMESTAMP
); );
CREATE TABLE t4_pg ( CREATE TABLE t4_pg (
vkey INT, vkey INT,
pkey INT, pkey INT,
@ -18,13 +16,11 @@ CREATE TABLE t4_pg (
c23 TEXT, c23 TEXT,
c24 TIMESTAMP c24 TIMESTAMP
); );
CREATE TABLE t6_pg ( CREATE TABLE t6_pg (
vkey INT, vkey INT,
pkey INT, pkey INT,
c26 TEXT c26 TEXT
); );
-- Mark t2_ref as a reference table -- Mark t2_ref as a reference table
SELECT create_reference_table('t2_ref'); SELECT create_reference_table('t2_ref');
create_reference_table create_reference_table
@ -32,14 +28,12 @@ SELECT create_reference_table('t2_ref');
(1 row) (1 row)
-- Insert sample data -- Insert sample data
INSERT INTO t6_pg (vkey, pkey, c26) VALUES (2, 12000, ''); INSERT INTO t6_pg (vkey, pkey, c26) VALUES (2, 12000, '');
INSERT INTO t4_pg (vkey, pkey, c22, c23, c24) INSERT INTO t4_pg (vkey, pkey, c22, c23, c24)
VALUES (5, 15000, 0.0, ']]?', MAKE_TIMESTAMP(2071, 10, 26, 16, 20, 5)); VALUES (5, 15000, 0.0, ']]?', MAKE_TIMESTAMP(2071, 10, 26, 16, 20, 5));
INSERT INTO t2_ref (vkey, pkey, c15) INSERT INTO t2_ref (vkey, pkey, c15)
VALUES (14, 24000, NULL::timestamp); VALUES (14, 24000, NULL::timestamp);
-- Show initial data -- Show initial data
SELECT 't6_pg before' AS label, * FROM t6_pg; SELECT 't6_pg before' AS label, * FROM t6_pg;
label | vkey | pkey | c26 label | vkey | pkey | c26
@ -59,13 +53,11 @@ SELECT 't2_ref data' AS label, * FROM t2_ref;
t2_ref data | 14 | 24000 | t2_ref data | 14 | 24000 |
(1 row) (1 row)
-- --
-- The problematic query: update t6_pg referencing t4_pg and sub-subquery on t2_ref. -- The problematic query: update t6_pg referencing t4_pg and sub-subquery on t2_ref.
-- Historically might produce a 0-task plan if the planner incorrectly fails to -- Historically might produce a 0-task plan if the planner incorrectly fails to
-- treat t4_pg/t2_ref as local/reference. -- treat t4_pg/t2_ref as local/reference.
-- --
-- The outer subquery iterates over every row in table t4_pg. -- The outer subquery iterates over every row in table t4_pg.
UPDATE t6_pg UPDATE t6_pg
SET vkey = 43 SET vkey = 43
@ -73,7 +65,6 @@ UPDATE t6_pg
SELECT (SELECT c15 FROM t2_ref) SELECT (SELECT c15 FROM t2_ref)
FROM t4_pg FROM t4_pg
); );
-- Show final data -- Show final data
SELECT 't6_pg after' AS label, * FROM t6_pg; SELECT 't6_pg after' AS label, * FROM t6_pg;
label | vkey | pkey | c26 label | vkey | pkey | c26
@ -81,17 +72,15 @@ SELECT 't6_pg after' AS label, * FROM t6_pg;
t6_pg after | 43 | 12000 | t6_pg after | 43 | 12000 |
(1 row) (1 row)
-- The outer subquery iterates over rows from the reference table t2_ref -- The outer subquery iterates over rows from the reference table t2_ref
UPDATE t6_pg UPDATE t6_pg
SET vkey = 43 SET vkey = 44
WHERE EXISTS ( WHERE EXISTS (
SELECT (SELECT c22 FROM t4_pg) SELECT (SELECT c22 FROM t4_pg)
FROM t2_ref FROM t2_ref
); );
ERROR: relation "issue_7891.t6_pg" does not exist ERROR: relation "issue_7891.t6_pg" does not exist
CONTEXT: while executing command on localhost:xxxxx CONTEXT: while executing command on localhost:xxxxx
-- Show final data -- Show final data
SELECT 't6_pg after' AS label, * FROM t6_pg; SELECT 't6_pg after' AS label, * FROM t6_pg;
label | vkey | pkey | c26 label | vkey | pkey | c26
@ -99,6 +88,5 @@ SELECT 't6_pg after' AS label, * FROM t6_pg;
t6_pg after | 43 | 12000 | t6_pg after | 43 | 12000 |
(1 row) (1 row)
SET client_min_messages TO WARNING; SET client_min_messages TO WARNING;
DROP SCHEMA issue_7891 CASCADE; DROP SCHEMA issue_7891 CASCADE;

View File

@ -59,7 +59,7 @@ SELECT 't6_pg after' AS label, * FROM t6_pg;
-- The outer subquery iterates over rows from the reference table t2_ref -- The outer subquery iterates over rows from the reference table t2_ref
UPDATE t6_pg UPDATE t6_pg
SET vkey = 43 SET vkey = 44
WHERE EXISTS ( WHERE EXISTS (
SELECT (SELECT c22 FROM t4_pg) SELECT (SELECT c22 FROM t4_pg)
FROM t2_ref FROM t2_ref