mirror of https://github.com/citusdata/citus.git
448 lines
16 KiB
Plaintext
448 lines
16 KiB
Plaintext
SET citus.shard_count TO 2;
|
|
SET citus.next_shard_id TO 750000;
|
|
SET citus.next_placement_id TO 750000;
|
|
CREATE SCHEMA indirections;
|
|
SET search_path TO indirections;
|
|
-- specific tests related to get_update_query_targetlist_def
|
|
-- we test only queries with sublinks, like:
|
|
-- ( ... SET (...) = (SELECT ...))
|
|
-- Reference tables
|
|
CREATE TABLE test_ref_indirection (
|
|
id bigint primary key
|
|
, col_bool bool , col_date date , col_int integer , col_text text
|
|
);
|
|
SELECT create_reference_table('indirections.test_ref_indirection');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE test_ref_indirection_new (
|
|
id bigint primary key
|
|
, col_bool bool , col_date date , col_int integer , col_text text
|
|
);
|
|
SELECT create_reference_table('indirections.test_ref_indirection_new');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
-- Distributed tables
|
|
CREATE TABLE test_dist_indirection (
|
|
id bigint primary key
|
|
, col_bool bool , col_date date , col_int integer , col_text text
|
|
);
|
|
SELECT create_distributed_table('indirections.test_dist_indirection', 'id');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE test_dist_indirection_new (
|
|
id bigint primary key
|
|
, col_bool bool , col_date date , col_int integer , col_text text
|
|
);
|
|
SELECT create_distributed_table('indirections.test_dist_indirection_new', 'id');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
-- Local tables required ?
|
|
-- those should work:
|
|
INSERT INTO test_ref_indirection (id, col_bool, col_date, col_int, col_text)
|
|
SELECT 1, true, '1970-01-01'::date, 1, 'one';
|
|
INSERT INTO test_dist_indirection (id, col_bool, col_date, col_int, col_text)
|
|
SELECT 1, true, '1970-01-01'::date, 1, 'one';
|
|
INSERT INTO test_ref_indirection (id, col_text, col_bool, col_date, col_int)
|
|
SELECT 2, 'two', false, '1970-01-01'::date, 2;
|
|
INSERT INTO test_dist_indirection (id, col_text, col_bool, col_date, col_int)
|
|
SELECT 2, 'two', false, '1970-01-01'::date, 2;
|
|
INSERT INTO test_ref_indirection SELECT 3, false, '1970-01-01'::date, 0, 'empty';
|
|
INSERT INTO test_dist_indirection SELECT 3, false, '1970-01-01'::date, 0, 'empty';
|
|
INSERT INTO test_ref_indirection SELECT 4, false, '1970-01-01'::date, 0, 'empty';
|
|
INSERT INTO test_dist_indirection SELECT 4, false, '1970-01-01'::date, 0, 'empty';
|
|
INSERT INTO test_ref_indirection_new SELECT * FROM test_ref_indirection;
|
|
INSERT INTO test_dist_indirection_new SELECT * FROM test_dist_indirection;
|
|
SELECT * FROM test_ref_indirection ORDER BY id;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1970 | 1 | one
|
|
2 | f | 01-01-1970 | 2 | two
|
|
3 | f | 01-01-1970 | 0 | empty
|
|
4 | f | 01-01-1970 | 0 | empty
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_dist_indirection ORDER BY id;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1970 | 1 | one
|
|
2 | f | 01-01-1970 | 2 | two
|
|
3 | f | 01-01-1970 | 0 | empty
|
|
4 | f | 01-01-1970 | 0 | empty
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_ref_indirection_new ORDER BY id;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1970 | 1 | one
|
|
2 | f | 01-01-1970 | 2 | two
|
|
3 | f | 01-01-1970 | 0 | empty
|
|
4 | f | 01-01-1970 | 0 | empty
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_dist_indirection_new ORDER BY id;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1970 | 1 | one
|
|
2 | f | 01-01-1970 | 2 | two
|
|
3 | f | 01-01-1970 | 0 | empty
|
|
4 | f | 01-01-1970 | 0 | empty
|
|
(4 rows)
|
|
|
|
-- now UPDATEs
|
|
UPDATE test_ref_indirection
|
|
SET (col_bool, col_date, col_int, col_text)
|
|
= (SELECT true, '1970-01-01'::date, 1, 'ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1970 | 1 | ok
|
|
2 | t | 01-01-1970 | 1 | ok
|
|
3 | t | 01-01-1970 | 1 | ok
|
|
4 | t | 01-01-1970 | 1 | ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_bool, col_date, col_int, col_text)
|
|
= (SELECT true, '1970-01-01'::date, 1, 'ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1970 | 1 | ok
|
|
2 | t | 01-01-1970 | 1 | ok
|
|
3 | t | 01-01-1970 | 1 | ok
|
|
4 | t | 01-01-1970 | 1 | ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_bool, col_date) = (select false, '1971-01-01'::date)
|
|
, (col_int, col_text) = (select 2, '2 ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1971 | 2 | 2 ok
|
|
2 | f | 01-01-1971 | 2 | 2 ok
|
|
3 | f | 01-01-1971 | 2 | 2 ok
|
|
4 | f | 01-01-1971 | 2 | 2 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_bool, col_date) = (select false, '1971-01-01'::date)
|
|
, (col_int, col_text) = (select 2, '2 ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1971 | 2 | 2 ok
|
|
2 | f | 01-01-1971 | 2 | 2 ok
|
|
3 | f | 01-01-1971 | 2 | 2 ok
|
|
4 | f | 01-01-1971 | 2 | 2 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_bool, col_int) = (select true, 3)
|
|
, (col_text) = (select '3 ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1971 | 3 | 3 ok
|
|
2 | t | 01-01-1971 | 3 | 3 ok
|
|
3 | t | 01-01-1971 | 3 | 3 ok
|
|
4 | t | 01-01-1971 | 3 | 3 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_bool, col_int) = (select true, 3)
|
|
, (col_text) = (select '3 ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1971 | 3 | 3 ok
|
|
2 | t | 01-01-1971 | 3 | 3 ok
|
|
3 | t | 01-01-1971 | 3 | 3 ok
|
|
4 | t | 01-01-1971 | 3 | 3 ok
|
|
(4 rows)
|
|
|
|
-- but those should work since 13.X
|
|
UPDATE test_ref_indirection
|
|
SET (col_date, col_text, col_int, col_bool)
|
|
= (SELECT '1972-01-01'::date, '4 ok', 4, false)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1972 | 4 | 4 ok
|
|
2 | f | 01-01-1972 | 4 | 4 ok
|
|
3 | f | 01-01-1972 | 4 | 4 ok
|
|
4 | f | 01-01-1972 | 4 | 4 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_date, col_text, col_int, col_bool)
|
|
= (SELECT '1972-01-01'::date, '4 ok', 4, false)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1972 | 4 | 4 ok
|
|
2 | f | 01-01-1972 | 4 | 4 ok
|
|
3 | f | 01-01-1972 | 4 | 4 ok
|
|
4 | f | 01-01-1972 | 4 | 4 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_int, col_text) = (select 5, '5 ok')
|
|
, (col_bool) = (select true)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1972 | 5 | 5 ok
|
|
2 | t | 01-01-1972 | 5 | 5 ok
|
|
3 | t | 01-01-1972 | 5 | 5 ok
|
|
4 | t | 01-01-1972 | 5 | 5 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_int, col_text) = (select 5, '5 ok')
|
|
, (col_bool) = (select true)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1972 | 5 | 5 ok
|
|
2 | t | 01-01-1972 | 5 | 5 ok
|
|
3 | t | 01-01-1972 | 5 | 5 ok
|
|
4 | t | 01-01-1972 | 5 | 5 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_int, col_date) = (select 6, '1973-01-01'::date)
|
|
, (col_text, col_bool) = (select '6 ok', false)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1973 | 6 | 6 ok
|
|
2 | f | 01-01-1973 | 6 | 6 ok
|
|
3 | f | 01-01-1973 | 6 | 6 ok
|
|
4 | f | 01-01-1973 | 6 | 6 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_int, col_date) = (select 6, '1973-01-01'::date)
|
|
, (col_text, col_bool) = (select '6 ok', false)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1973 | 6 | 6 ok
|
|
2 | f | 01-01-1973 | 6 | 6 ok
|
|
3 | f | 01-01-1973 | 6 | 6 ok
|
|
4 | f | 01-01-1973 | 6 | 6 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_int, col_date, col_text) = (select 7, '1974-01-01'::date, '7 ok')
|
|
, (col_bool) = (select true)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1974 | 7 | 7 ok
|
|
2 | t | 01-01-1974 | 7 | 7 ok
|
|
3 | t | 01-01-1974 | 7 | 7 ok
|
|
4 | t | 01-01-1974 | 7 | 7 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_int, col_date, col_text) = (select 7, '1974-01-01'::date, '7 ok')
|
|
, (col_bool) = (select true)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1974 | 7 | 7 ok
|
|
2 | t | 01-01-1974 | 7 | 7 ok
|
|
3 | t | 01-01-1974 | 7 | 7 ok
|
|
4 | t | 01-01-1974 | 7 | 7 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_date, col_text) = (select '1975-01-01'::date, '8 ok')
|
|
, (col_int) = (select 8)
|
|
, (col_bool) = (select false)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1975 | 8 | 8 ok
|
|
2 | f | 01-01-1975 | 8 | 8 ok
|
|
3 | f | 01-01-1975 | 8 | 8 ok
|
|
4 | f | 01-01-1975 | 8 | 8 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_date, col_text) = (select '1975-01-01'::date, '8 ok')
|
|
, (col_int) = (select 8)
|
|
, (col_bool) = (select false)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1975 | 8 | 8 ok
|
|
2 | f | 01-01-1975 | 8 | 8 ok
|
|
3 | f | 01-01-1975 | 8 | 8 ok
|
|
4 | f | 01-01-1975 | 8 | 8 ok
|
|
(4 rows)
|
|
|
|
--
|
|
-- more restrictive ones, just in case we miss a wrong value
|
|
--
|
|
-- those should work
|
|
UPDATE test_ref_indirection
|
|
SET (col_bool, col_text) = (SELECT true, '9 ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1975 | 8 | 9 ok
|
|
2 | t | 01-01-1975 | 8 | 9 ok
|
|
3 | t | 01-01-1975 | 8 | 9 ok
|
|
4 | t | 01-01-1975 | 8 | 9 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_bool, col_text) = (SELECT true, '9 ok')
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1975 | 8 | 9 ok
|
|
2 | t | 01-01-1975 | 8 | 9 ok
|
|
3 | t | 01-01-1975 | 8 | 9 ok
|
|
4 | t | 01-01-1975 | 8 | 9 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_bool, col_text) = (SELECT false, '10 ok')
|
|
WHERE id = 1
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1975 | 8 | 10 ok
|
|
(1 row)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_bool, col_text) = (SELECT false, '10 ok')
|
|
WHERE id = 1
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | f | 01-01-1975 | 8 | 10 ok
|
|
(1 row)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_text, col_bool) = (SELECT '11 ok', true)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1975 | 8 | 11 ok
|
|
2 | t | 01-01-1975 | 8 | 11 ok
|
|
3 | t | 01-01-1975 | 8 | 11 ok
|
|
4 | t | 01-01-1975 | 8 | 11 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_text, col_bool) = (SELECT '11 ok', true)
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
1 | t | 01-01-1975 | 8 | 11 ok
|
|
2 | t | 01-01-1975 | 8 | 11 ok
|
|
3 | t | 01-01-1975 | 8 | 11 ok
|
|
4 | t | 01-01-1975 | 8 | 11 ok
|
|
(4 rows)
|
|
|
|
UPDATE test_ref_indirection
|
|
SET (col_text, col_bool) = (SELECT '12 ok', false)
|
|
WHERE id = 2
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
2 | f | 01-01-1975 | 8 | 12 ok
|
|
(1 row)
|
|
|
|
UPDATE test_dist_indirection
|
|
SET (col_text, col_bool) = (SELECT '12 ok', false)
|
|
WHERE id = 2
|
|
RETURNING *;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
2 | f | 01-01-1975 | 8 | 12 ok
|
|
(1 row)
|
|
|
|
-- several updates in CTE shoult not work
|
|
with qq3 as (
|
|
update test_ref_indirection
|
|
SET (col_text, col_bool)
|
|
= (SELECT '13', true)
|
|
where id = 3
|
|
returning *
|
|
),
|
|
qq4 as (
|
|
update test_ref_indirection
|
|
SET (col_text, col_bool)
|
|
= (SELECT '14', false)
|
|
where id = 4
|
|
returning *
|
|
)
|
|
select * from qq3 union all select * from qq4;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
3 | t | 01-01-1975 | 8 | 13
|
|
4 | f | 01-01-1975 | 8 | 14
|
|
(2 rows)
|
|
|
|
with qq3 as (
|
|
update test_dist_indirection
|
|
SET (col_text, col_bool)
|
|
= (SELECT '13', true)
|
|
where id = 3
|
|
returning *
|
|
),
|
|
qq4 as (
|
|
update test_dist_indirection
|
|
SET (col_text, col_bool)
|
|
= (SELECT '14', false)
|
|
where id = 4
|
|
returning *
|
|
)
|
|
select * from qq3 union all select * from qq4;
|
|
id | col_bool | col_date | col_int | col_text
|
|
---------------------------------------------------------------------
|
|
3 | t | 01-01-1975 | 8 | 13
|
|
4 | f | 01-01-1975 | 8 | 14
|
|
(2 rows)
|
|
|
|
DROP TABLE test_dist_indirection;
|
|
DROP TABLE test_dist_indirection_new;
|
|
DROP TABLE test_ref_indirection;
|
|
DROP TABLE test_ref_indirection_new;
|
|
-- https://github.com/citusdata/citus/issues/4092
|
|
CREATE TABLE update_test (
|
|
a INT DEFAULT 10,
|
|
b INT,
|
|
c TEXT
|
|
);
|
|
SELECT create_reference_table('indirections.update_test');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
UPDATE update_test
|
|
SET (b,a) = (select a,b from update_test where b = 41 and c = 'car')
|
|
WHERE a = 100 AND b = 20;
|
|
-- https://github.com/citusdata/citus/pull/5692
|
|
set client_min_messages to ERROR;
|
|
DROP SCHEMA indirections CASCADE;
|