should be it
This commit is contained in:
142
external/duckdb/test/sql/index/art/constraints/test_art_compound_key_changes.test
vendored
Normal file
142
external/duckdb/test/sql/index/art/constraints/test_art_compound_key_changes.test
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
# name: test/sql/index/art/constraints/test_art_compound_key_changes.test
|
||||
# description: Tests various changes to compound indexes with out-of-order columns.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_comp (
|
||||
a INT,
|
||||
b VARCHAR UNIQUE,
|
||||
gen AS (2 * a),
|
||||
c INT,
|
||||
d VARCHAR,
|
||||
PRIMARY KEY (c, b));
|
||||
|
||||
statement ok
|
||||
CREATE UNIQUE INDEX unique_idx ON tbl_comp((d || 'hello'), (a + 42));
|
||||
|
||||
statement ok
|
||||
CREATE INDEX normal_idx ON tbl_comp(d, a, c);
|
||||
|
||||
statement ok
|
||||
CREATE UNIQUE INDEX lookup_idx ON tbl_comp(c);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_comp VALUES (1, 'hello', 1, 'hello');
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_comp VALUES (2, 'hello', 1, 'world')
|
||||
ON CONFLICT (c, b) DO UPDATE SET a = excluded.a, d = excluded.d;
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp WHERE c = 1;
|
||||
----
|
||||
2 hello 4 1 world
|
||||
|
||||
# Trigger unique_idx.
|
||||
|
||||
statement error
|
||||
INSERT INTO tbl_comp VALUES (2, 'hola', 5, 'world');
|
||||
----
|
||||
<REGEX>:Constraint Error.*violates unique constraint.*
|
||||
|
||||
# Trigger lookup_idx.
|
||||
|
||||
statement error
|
||||
INSERT INTO tbl_comp VALUES (3, 'hoi', 1, 'wereld');
|
||||
----
|
||||
<REGEX>:Constraint Error.*violates unique constraint.*
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_comp VALUES (3, 'hoi', 2, 'wereld');
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp ORDER BY ALL;
|
||||
----
|
||||
2 hello 4 1 world
|
||||
3 hoi 6 2 wereld
|
||||
|
||||
# Trigger the primary key.
|
||||
|
||||
statement error
|
||||
INSERT INTO tbl_comp VALUES (42, 'hoi', 2, 'welt');
|
||||
----
|
||||
<REGEX>:Constraint Error.*violates unique constraint.*
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
statement ok old
|
||||
INSERT INTO tbl_comp VALUES (42, 'hoii', 22, 'welt');
|
||||
|
||||
# con1 open.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
DELETE FROM tbl_comp;
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl_comp VALUES (200, 'hello', 1, 'world'), (300, 'hoi', 2, 'wereld');
|
||||
|
||||
# Ensure that we can still see the old value.
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp WHERE c = 2;
|
||||
----
|
||||
3 hoi 6 2 wereld
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp WHERE c = 1;
|
||||
----
|
||||
2 hello 4 1 world
|
||||
|
||||
# Now commit the changes.
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp ORDER BY ALL;
|
||||
----
|
||||
200 hello 400 1 world
|
||||
300 hoi 600 2 wereld
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp WHERE c = 2;
|
||||
----
|
||||
300 hoi 600 2 wereld
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp WHERE c = 1;
|
||||
----
|
||||
200 hello 400 1 world
|
||||
|
||||
# Ensure that the old transaction can still see the old storage.
|
||||
|
||||
query IIIII old
|
||||
SELECT a, b, gen, c, d FROM tbl_comp WHERE c = 2;
|
||||
----
|
||||
3 hoi 6 2 wereld
|
||||
|
||||
query IIIII old
|
||||
SELECT a, b, gen, c, d FROM tbl_comp WHERE c = 1;
|
||||
----
|
||||
2 hello 4 1 world
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
# Final results.
|
||||
|
||||
query IIIII
|
||||
SELECT a, b, gen, c, d FROM tbl_comp ORDER BY ALL;
|
||||
----
|
||||
42 hoii 84 22 welt
|
||||
200 hello 400 1 world
|
||||
300 hoi 600 2 wereld
|
||||
51
external/duckdb/test/sql/index/art/constraints/test_art_concurrent_loop.test_slow
vendored
Normal file
51
external/duckdb/test/sql/index/art/constraints/test_art_concurrent_loop.test_slow
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
# name: test/sql/index/art/constraints/test_art_concurrent_loop.test_slow
|
||||
# description: Test repeated DELETE + INSERT in a concurrent loop.
|
||||
# group: [constraints]
|
||||
|
||||
# We must never throw a constraint violation.
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (i INT PRIMARY KEY);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl SELECT * FROM range(10000);
|
||||
|
||||
concurrentloop threadid 0 20
|
||||
|
||||
loop i 0 100
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement maybe
|
||||
DELETE FROM tbl WHERE i = ${i} + ${threadid} * 10;
|
||||
----
|
||||
TransactionContext Error
|
||||
|
||||
statement maybe
|
||||
INSERT INTO tbl VALUES (${i} + ${threadid} * 10);
|
||||
----
|
||||
TransactionContext Error
|
||||
|
||||
statement maybe
|
||||
COMMIT;
|
||||
----
|
||||
TransactionContext Error
|
||||
|
||||
endloop
|
||||
|
||||
endloop
|
||||
|
||||
query II
|
||||
SELECT COUNT(*), SUM(i) FROM tbl;
|
||||
----
|
||||
10000 49995000
|
||||
|
||||
loop i 0 10000
|
||||
|
||||
query I
|
||||
SELECT i = ${i} FROM tbl WHERE i = ${i};
|
||||
----
|
||||
true
|
||||
|
||||
endloop
|
||||
48
external/duckdb/test/sql/index/art/constraints/test_art_eager_batch_insert.test
vendored
Normal file
48
external/duckdb/test/sql/index/art/constraints/test_art_eager_batch_insert.test
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# name: test/sql/index/art/constraints/test_art_eager_batch_insert.test
|
||||
# description: Test eager constraint checking during batch inserts.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test1 (id INT PRIMARY KEY, payload VARCHAR);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test2 (id INT PRIMARY KEY, payload VARCHAR);
|
||||
|
||||
statement ok
|
||||
INSERT INTO test1 VALUES (1, 'row 1');
|
||||
|
||||
statement ok
|
||||
INSERT INTO test2 VALUES (1, 'row 1 from test 2');
|
||||
|
||||
query II
|
||||
SELECT id, payload FROM test1;
|
||||
----
|
||||
1 row 1
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement ok
|
||||
DELETE FROM test1 WHERE id = 1;
|
||||
|
||||
query II
|
||||
SELECT id, payload FROM test1;
|
||||
----
|
||||
|
||||
statement ok
|
||||
INSERT INTO test1 SELECT * FROM test2;
|
||||
|
||||
query II
|
||||
SELECT id, payload FROM test1;
|
||||
----
|
||||
1 row 1 from test 2
|
||||
|
||||
statement ok
|
||||
COMMIT
|
||||
|
||||
query II
|
||||
SELECT id, payload FROM test1;
|
||||
----
|
||||
1 row 1 from test 2
|
||||
|
||||
|
||||
266
external/duckdb/test/sql/index/art/constraints/test_art_eager_constraint_checking.test
vendored
Normal file
266
external/duckdb/test/sql/index/art/constraints/test_art_eager_constraint_checking.test
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
# name: test/sql/index/art/constraints/test_art_eager_constraint_checking.test
|
||||
# description: Contains tests previously triggering the eager constraint checking limitation.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
# Original issue: 7182
|
||||
|
||||
statement ok
|
||||
CREATE TABLE t_7182 (it INTEGER PRIMARY KEY, jt INTEGER);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE u_7182 (iu INTEGER PRIMARY KEY, ju INTEGER REFERENCES t_7182 (it));
|
||||
|
||||
statement ok
|
||||
INSERT INTO t_7182 VALUES (1, 1);
|
||||
|
||||
statement ok
|
||||
INSERT INTO u_7182 VALUES (1, NULL);
|
||||
|
||||
statement ok
|
||||
UPDATE u_7182 SET ju = 1 WHERE iu = 1;
|
||||
|
||||
query III
|
||||
SELECT iu, ju, rowid FROM u_7182 WHERE iu = 1;
|
||||
----
|
||||
1 1 1
|
||||
|
||||
# Original issue: 5807
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tunion_5807 (id INTEGER PRIMARY KEY, u UNION (i int));
|
||||
|
||||
statement ok
|
||||
INSERT INTO tunion_5807 SELECT 1, 41;
|
||||
|
||||
statement ok
|
||||
UPDATE tunion_5807 SET u = 42 WHERE id = 1;
|
||||
|
||||
query III
|
||||
SELECT id, u, rowid FROM tunion_5807 WHERE id = 1;
|
||||
----
|
||||
1 42 1
|
||||
|
||||
# Original issue: 5771
|
||||
|
||||
statement ok
|
||||
CREATE TABLE IF NOT EXISTS workers_5771 (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
worker VARCHAR(150) UNIQUE NOT NULL,
|
||||
phone VARCHAR(20) NOT NULL);
|
||||
|
||||
statement ok
|
||||
INSERT INTO workers_5771 VALUES (1, 'wagner', '123');
|
||||
|
||||
statement ok
|
||||
UPDATE workers_5771 SET phone = '345' WHERE id = 1;
|
||||
|
||||
statement ok
|
||||
UPDATE workers_5771 SET worker = 'leo' WHERE id = 1;
|
||||
|
||||
query IIII
|
||||
SELECT id, worker, phone, rowid FROM workers_5771 WHERE id = 1;
|
||||
----
|
||||
1 leo 345 1
|
||||
|
||||
# Original issue: 4886
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test_4886 (i INTEGER PRIMARY KEY);
|
||||
|
||||
statement ok
|
||||
INSERT INTO test_4886 VALUES (1);
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement ok
|
||||
UPDATE test_4886 SET i = 4 WHERE i = 1;
|
||||
|
||||
statement ok
|
||||
INSERT INTO test_4886 VALUES (1);
|
||||
|
||||
statement ok
|
||||
COMMIT
|
||||
|
||||
query II
|
||||
SELECT i, rowid FROM test_4886 ORDER BY ALL;
|
||||
----
|
||||
1 2
|
||||
4 1
|
||||
|
||||
query II
|
||||
SELECT i, rowid FROM test_4886 WHERE i = 1;
|
||||
----
|
||||
1 2
|
||||
|
||||
query II
|
||||
SELECT i, rowid FROM test_4886 WHERE i = 4;
|
||||
----
|
||||
4 1
|
||||
|
||||
# Original issue: 1631
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_1631 (
|
||||
id INTEGER PRIMARY KEY,
|
||||
c1 text NOT NULL UNIQUE,
|
||||
c2 text NOT NULL);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_1631 VALUES (1, 'abc', 'def'), (2, 'asdf', 'jkl');
|
||||
|
||||
statement ok
|
||||
UPDATE tbl_1631 SET c1 = 'ghi', c2 = 'mno' WHERE id = 2;
|
||||
|
||||
query IIII
|
||||
SELECT id, c1, c2, rowid FROM tbl_1631 ORDER BY ALL;
|
||||
----
|
||||
1 abc def 0
|
||||
2 ghi mno 2
|
||||
|
||||
# Original issue: 4214
|
||||
|
||||
statement ok
|
||||
CREATE TABLE c_4214 (id INTEGER NOT NULL PRIMARY KEY);
|
||||
|
||||
statement ok
|
||||
CREATE TABLE a_4214 (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
c_id INTEGER NOT NULL,
|
||||
FOREIGN KEY(c_id) REFERENCES c_4214 (id)
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO c_4214 (id) VALUES (1), (2);
|
||||
|
||||
statement ok
|
||||
INSERT INTO a_4214 (id, c_id) VALUES (1, 1);
|
||||
|
||||
statement ok
|
||||
UPDATE a_4214 SET c_id = 2 WHERE id = 1;
|
||||
|
||||
query III
|
||||
SELECT id, c_id, rowid FROM a_4214 WHERE id = 1;
|
||||
----
|
||||
1 2 1
|
||||
|
||||
# Original issue: 8764 (altered)
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tag_8764 (
|
||||
key VARCHAR(65535) NOT NULL,
|
||||
name VARCHAR(65535) NULL,
|
||||
value VARCHAR(65535) NOT NULL,
|
||||
PRIMARY KEY (key, name)
|
||||
);
|
||||
|
||||
statement ok
|
||||
CREATE UNIQUE INDEX idx_name_8764 ON tag_8764(name);
|
||||
|
||||
statement ok
|
||||
CREATE UNIQUE INDEX idx_value_8764 ON tag_8764(value);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tag_8764 (key, name, value) VALUES ('key1', 'name1', 'value1');
|
||||
|
||||
statement ok
|
||||
UPDATE tag_8764 SET value = 'new_value' WHERE key = 'key1' AND name = 'name1';
|
||||
|
||||
query IIII
|
||||
SELECT key, name, value, rowid FROM tag_8764;
|
||||
----
|
||||
key1 name1 new_value 1
|
||||
|
||||
# Original issue: 11288
|
||||
|
||||
statement ok
|
||||
CREATE TABLE t_11288 (i INT PRIMARY KEY, j MAP(VARCHAR, VARCHAR));
|
||||
|
||||
statement ok
|
||||
INSERT INTO t_11288 VALUES (1, MAP(['a'], ['b']));
|
||||
|
||||
statement ok
|
||||
UPDATE t_11288 SET j = MAP(['c'], ['d']) WHERE i = 1;
|
||||
|
||||
query II
|
||||
SELECT i, j FROM t_11288 WHERE i = 1;
|
||||
----
|
||||
1 {c=d}
|
||||
|
||||
# Original issue: 4807
|
||||
|
||||
statement ok
|
||||
CREATE TABLE t_4807 (id INT PRIMARY KEY, u UNION (i INT));
|
||||
|
||||
statement ok
|
||||
INSERT INTO t_4807 SELECT 1, 41;
|
||||
|
||||
statement ok
|
||||
UPDATE t_4807 SET u = 42 WHERE id = 1;
|
||||
|
||||
query III
|
||||
SELECT id, u, rowid FROM t_4807;
|
||||
----
|
||||
1 42 1
|
||||
|
||||
# Original issue: 14133
|
||||
|
||||
statement ok
|
||||
CREATE TABLE t_14133 (i INT PRIMARY KEY, s VARCHAR);
|
||||
|
||||
statement ok
|
||||
INSERT INTO t_14133 SELECT i, i::string FROM generate_series(1, 100) s(i);
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement ok
|
||||
DELETE FROM t_14133 WHERE i IN (SELECT i FROM generate_series(1, 20) s(i));
|
||||
|
||||
statement ok
|
||||
INSERT OR REPLACE INTO t_14133 SELECT i, (i * 2)::string FROM generate_series(1, 20) s(i);
|
||||
|
||||
statement ok
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT COUNT(*), MIN(i), MAX(i) FROM t_14133;
|
||||
----
|
||||
100 1 100
|
||||
|
||||
# Original issue: 6500
|
||||
|
||||
load __TEST_DIR__/eager_constraint_issue.db
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_6500 (i INTEGER, j INTEGER);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_6500 VALUES (1, 100), (2, 200);
|
||||
|
||||
statement ok
|
||||
CREATE UNIQUE INDEX idx_6500 ON tbl_6500 (i);
|
||||
|
||||
statement ok
|
||||
CHECKPOINT;
|
||||
|
||||
statement ok
|
||||
INSERT OR IGNORE INTO tbl_6500 VALUES (1, 101), (2, 201);
|
||||
|
||||
query II
|
||||
SELECT i, j FROM tbl_6500 ORDER BY ALL;
|
||||
----
|
||||
1 100
|
||||
2 200
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_6500 VALUES (1,101), (2,201) ON CONFLICT DO NOTHING;
|
||||
|
||||
query II
|
||||
SELECT i, j FROM tbl_6500 ORDER BY ALL;
|
||||
----
|
||||
1 100
|
||||
2 200
|
||||
50
external/duckdb/test/sql/index/art/constraints/test_art_eager_update.test_slow
vendored
Normal file
50
external/duckdb/test/sql/index/art/constraints/test_art_eager_update.test_slow
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# name: test/sql/index/art/constraints/test_art_eager_update.test_slow
|
||||
# description: Test ART BIGINT key type
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
CREATE OR REPLACE TABLE t (
|
||||
s UUID,
|
||||
payload STRUCT(k VARCHAR)[],
|
||||
p STRUCT(e VARCHAR, s DOUBLE),
|
||||
payload2 STRUCT(x INT)[],
|
||||
other VARCHAR
|
||||
);
|
||||
|
||||
statement ok
|
||||
CREATE OR REPLACE TABLE t2 (
|
||||
s UUID,
|
||||
payload STRUCT(k VARCHAR)[],
|
||||
p STRUCT(e VARCHAR, s DOUBLE),
|
||||
payload2 STRUCT(x INT)[]
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO t(s, other) (
|
||||
SELECT s, SUBSTRING(s::VARCHAR, 1, 8) AS other
|
||||
FROM (SELECT uuid() AS s FROM range(300000))
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO t2 (
|
||||
SELECT
|
||||
s,
|
||||
[struct_pack(k := 'aaaa'), struct_pack(k := 'rrrr')],
|
||||
struct_pack(e := 'ddd', s := -9.0),
|
||||
[struct_pack(x := 99), struct_pack(x := 100), struct_pack(x := 101)]
|
||||
FROM t WHERE rowid % 2 = 0
|
||||
);
|
||||
|
||||
statement ok
|
||||
ALTER TABLE t ADD PRIMARY KEY (s);
|
||||
|
||||
statement ok
|
||||
ALTER TABLE t2 ADD PRIMARY KEY (s);
|
||||
|
||||
statement ok
|
||||
UPDATE t
|
||||
SET payload = t2.payload, p = t2.p, payload2 = t2.payload2
|
||||
FROM t2 WHERE t.s = t2.s;
|
||||
36
external/duckdb/test/sql/index/art/constraints/test_art_eager_with_wal.test
vendored
Normal file
36
external/duckdb/test/sql/index/art/constraints/test_art_eager_with_wal.test
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# name: test/sql/index/art/constraints/test_art_eager_with_wal.test
|
||||
# description: Test eager constraint checking with WAL replay.
|
||||
# group: [constraints]
|
||||
|
||||
load __TEST_DIR__/pk_duplicate_key_wal.db
|
||||
|
||||
statement ok
|
||||
SET checkpoint_threshold = '10.0 GB';
|
||||
|
||||
statement ok
|
||||
PRAGMA disable_checkpoint_on_shutdown;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (id INT PRIMARY KEY);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES (1);
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement ok
|
||||
DELETE FROM tbl WHERE id = 1;
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES (1);
|
||||
|
||||
statement ok
|
||||
COMMIT;
|
||||
|
||||
restart
|
||||
|
||||
statement error
|
||||
INSERT INTO tbl VALUES (1);
|
||||
----
|
||||
<REGEX>:Constraint Error.*violates primary key constraint.*
|
||||
56
external/duckdb/test/sql/index/art/constraints/test_art_large_abort.test
vendored
Normal file
56
external/duckdb/test/sql/index/art/constraints/test_art_large_abort.test
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
# name: test/sql/index/art/constraints/test_art_large_abort.test
|
||||
# description: Test abort of large insertion of negative values into index and verify that all elements are correctly deleted
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE a(id INTEGER PRIMARY KEY, c INT);
|
||||
|
||||
statement ok
|
||||
INSERT INTO a VALUES (1, 4)
|
||||
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
INSERT INTO a SELECT i id, NULL c FROM range(-2, -250000, -1) tbl(i)
|
||||
|
||||
statement error
|
||||
INSERT INTO a VALUES (1, 5)
|
||||
----
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
query I
|
||||
SELECT c FROM a WHERE id=1
|
||||
----
|
||||
4
|
||||
|
||||
query II
|
||||
SELECT * FROM a
|
||||
----
|
||||
1 4
|
||||
|
||||
# now with non-null values
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
INSERT INTO a SELECT i id, -i c FROM range(-2, -250000, -1) tbl(i)
|
||||
|
||||
statement error
|
||||
INSERT INTO a VALUES (1, 5)
|
||||
----
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
query I
|
||||
SELECT c FROM a WHERE id=1
|
||||
----
|
||||
4
|
||||
|
||||
query II
|
||||
SELECT * FROM a
|
||||
----
|
||||
1 4
|
||||
36
external/duckdb/test/sql/index/art/constraints/test_art_simple_update.test
vendored
Normal file
36
external/duckdb/test/sql/index/art/constraints/test_art_simple_update.test
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# name: test/sql/index/art/constraints/test_art_simple_update.test
|
||||
# description: Test a simple update on a PK with a LIST column.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (i BIGINT PRIMARY KEY, l1 BIGINT[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES(1, [1, 2, 3]), (2, [42]);
|
||||
|
||||
query III
|
||||
SELECT i, l1, rowid FROM tbl ORDER BY ALL;
|
||||
----
|
||||
1 [1, 2, 3] 0
|
||||
2 [42] 1
|
||||
|
||||
statement ok
|
||||
UPDATE tbl SET l1 = [1, 2, 4] WHERE i = 1;
|
||||
|
||||
query III
|
||||
SELECT i, l1, rowid FROM tbl ORDER BY ALL;
|
||||
----
|
||||
1 [1, 2, 4] 2
|
||||
2 [42] 1
|
||||
|
||||
statement ok
|
||||
INSERT OR REPLACE INTO tbl VALUES (2, [43]);
|
||||
|
||||
statement ok
|
||||
INSERT OR REPLACE INTO tbl VALUES (2, [44]);
|
||||
|
||||
query III
|
||||
SELECT i, l1, rowid FROM tbl ORDER BY ALL;
|
||||
----
|
||||
1 [1, 2, 4] 2
|
||||
2 [44] 4
|
||||
59
external/duckdb/test/sql/index/art/constraints/test_art_tx_delete_with_global_nested.test
vendored
Normal file
59
external/duckdb/test/sql/index/art/constraints/test_art_tx_delete_with_global_nested.test
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_delete_with_global_nested.test
|
||||
# description: Test DELETE + INSERT while the global ART has nested leaves.
|
||||
# group: [constraints]
|
||||
|
||||
load __TEST_DIR__/test_art_tx_delete_with_global_nested.db
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES (1, ['first payload']);
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
# Now update the ART via DELETE + INSERT.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
DELETE FROM tbl WHERE id = 1;
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl VALUES (1, ['con1 payload']);
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
# The ART leaf contains both the new and the old row ID.
|
||||
|
||||
statement ok con2
|
||||
BEGIN
|
||||
|
||||
statement ok con2
|
||||
DELETE FROM tbl WHERE id = 1;
|
||||
|
||||
statement ok con2
|
||||
INSERT INTO tbl VALUES (1, ['con2 payload']);
|
||||
|
||||
# Unique indexes can have a maximum of two row IDs in their leaves.
|
||||
|
||||
statement error con2
|
||||
COMMIT;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*write-write conflict on key.*
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 [con1 payload] 1
|
||||
75
external/duckdb/test/sql/index/art/constraints/test_art_tx_deletes_list.test
vendored
Normal file
75
external/duckdb/test/sql/index/art/constraints/test_art_tx_deletes_list.test
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_deletes_list.test
|
||||
# description: Test DELETE + INSERT with different connections and LIST payload.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_list (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_list VALUES (1, ['first payload']);
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
statement ok old
|
||||
INSERT INTO tbl_list VALUES (5, ['old payload']);
|
||||
|
||||
# con1 open.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
DELETE FROM tbl_list;
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl_list VALUES (1, ['con1 payload']);
|
||||
|
||||
# Ensure that we can still see the old value.
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [first payload] 0
|
||||
|
||||
# Try to delete again.
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement error
|
||||
DELETE FROM tbl_list;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*Conflict on tuple deletion.*
|
||||
|
||||
statement ok
|
||||
ROLLBACK;
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [con1 payload] 1
|
||||
|
||||
# Ensure that the old transaction can still see the old storage.
|
||||
|
||||
query III old
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [first payload] 0
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list ORDER BY ALL;
|
||||
----
|
||||
1 [con1 payload] 1
|
||||
5 [old payload] 2
|
||||
39
external/duckdb/test/sql/index/art/constraints/test_art_tx_deletes_rollback.test
vendored
Normal file
39
external/duckdb/test/sql/index/art/constraints/test_art_tx_deletes_rollback.test
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_deletes_rollback.test
|
||||
# description: Test DELETE + INSERT, then ROLLBACK due to a constraint violation.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_rollback (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_rollback VALUES (1, ['first payload']);
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
DELETE FROM tbl_rollback;
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl_rollback VALUES (1, ['con1 payload']);
|
||||
|
||||
statement error con1
|
||||
INSERT INTO tbl_rollback VALUES (1, ['con1 payload']);
|
||||
----
|
||||
<REGEX>:Constraint Error.*PRIMARY KEY or UNIQUE constraint violation.*
|
||||
|
||||
statement error con1
|
||||
SELECT 42;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*Current transaction is aborted.*
|
||||
|
||||
statement ok con1
|
||||
ROLLBACK;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_rollback ORDER BY ALL;
|
||||
----
|
||||
1 [first payload] 0
|
||||
76
external/duckdb/test/sql/index/art/constraints/test_art_tx_deletes_varchar.test
vendored
Normal file
76
external/duckdb/test/sql/index/art/constraints/test_art_tx_deletes_varchar.test
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_deletes_varchar.test
|
||||
# description: Test DELETE + INSERT with different connections and VARCHAR payload.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (id INT PRIMARY KEY, payload VARCHAR);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES (1, 'first payload');
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
statement ok old
|
||||
INSERT INTO tbl VALUES (5, 'old payload');
|
||||
|
||||
# con1 open.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
DELETE FROM tbl;
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl VALUES (1, 'con1 payload');
|
||||
|
||||
# Ensure that we can still see the old value.
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 first payload 0
|
||||
|
||||
# Try to delete again.
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement error
|
||||
DELETE FROM tbl;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*Conflict on tuple deletion.*
|
||||
|
||||
statement ok
|
||||
ROLLBACK;
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 con1 payload 1
|
||||
|
||||
# Ensure that the old transaction can still see the old storage.
|
||||
|
||||
query III old
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 first payload 0
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl ORDER BY ALL;
|
||||
----
|
||||
1 con1 payload 1
|
||||
5 old payload 2
|
||||
|
||||
35
external/duckdb/test/sql/index/art/constraints/test_art_tx_returning.test
vendored
Normal file
35
external/duckdb/test/sql/index/art/constraints/test_art_tx_returning.test
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_returning.test
|
||||
# description: Test updates on the primary key containing RETURNING.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_list (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_list SELECT range, [range || ' payload'] FROM range(5);
|
||||
|
||||
query II
|
||||
UPDATE tbl_list SET id = id + 5 RETURNING id, payload;
|
||||
----
|
||||
5 [0 payload]
|
||||
6 [1 payload]
|
||||
7 [2 payload]
|
||||
8 [3 payload]
|
||||
9 [4 payload]
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_list SELECT range + 10, [(range + 10) || ' payload'] FROM range(3000);
|
||||
|
||||
# For each incoming chunk, we add the row IDs to the delete index.
|
||||
# For standard_vector_size = 2048, we delete the first chunk, and then try to insert the incremented values.
|
||||
# This is expected to throw a constraint violation.
|
||||
# The value going into the next chunk is not yet in the delete index, as the chunk that would add that value hasn't been processed, yet.
|
||||
# This scenario is a known limitation (also in postgres).
|
||||
|
||||
statement error
|
||||
UPDATE tbl_list SET id = id + 1 RETURNING id, payload;
|
||||
----
|
||||
<REGEX>:Constraint Error.*violates primary key constraint.*
|
||||
29
external/duckdb/test/sql/index/art/constraints/test_art_tx_same_row_id.test
vendored
Normal file
29
external/duckdb/test/sql/index/art/constraints/test_art_tx_same_row_id.test
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_same_row_id.test
|
||||
# description: Test deletes that touch the same row ID repeatedly.
|
||||
# group: [constraints]
|
||||
|
||||
# FIXME: We need to fix the internal issue #3702
|
||||
mode skip
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_list (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_list SELECT range, [range || ' payload'] FROM range(10);
|
||||
|
||||
query II
|
||||
DELETE FROM tbl_list USING range(100) t(i) RETURNING id, payload;
|
||||
----
|
||||
0 [0 payload]
|
||||
1 [1 payload]
|
||||
2 [2 payload]
|
||||
3 [3 payload]
|
||||
4 [4 payload]
|
||||
5 [5 payload]
|
||||
6 [6 payload]
|
||||
7 [7 payload]
|
||||
8 [8 payload]
|
||||
9 [9 payload]
|
||||
56
external/duckdb/test/sql/index/art/constraints/test_art_tx_update_with_global_nested.test
vendored
Normal file
56
external/duckdb/test/sql/index/art/constraints/test_art_tx_update_with_global_nested.test
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_update_with_global_nested.test
|
||||
# description: Test UPDATE while the global ART has nested leaves.
|
||||
# group: [constraints]
|
||||
|
||||
load __TEST_DIR__/test_art_tx_update_with_global_nested.db
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES (1, ['first payload']);
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
# Now update the ART via UPDATE.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
UPDATE tbl SET payload = ['con1 payload'] WHERE id = 1;
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
# The ART leaf contains both the new and the old row ID.
|
||||
|
||||
statement ok con2
|
||||
BEGIN
|
||||
|
||||
statement ok con2
|
||||
UPDATE tbl SET payload = ['con2 payload'] WHERE id = 1;
|
||||
|
||||
# Unique indexes can have a maximum of two row IDs in their leaves.
|
||||
|
||||
statement error con2
|
||||
COMMIT;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*write-write conflict on key.*
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 [con1 payload] 1
|
||||
103
external/duckdb/test/sql/index/art/constraints/test_art_tx_updates_list.test
vendored
Normal file
103
external/duckdb/test/sql/index/art/constraints/test_art_tx_updates_list.test
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_updates_list.test
|
||||
# description: Test UPDATE with different connections and LIST payload.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_list (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_list VALUES (1, ['first payload']), (2, ['second payload']);
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
statement ok old
|
||||
INSERT INTO tbl_list VALUES (5, ['old payload']);
|
||||
|
||||
# con1 open.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
UPDATE tbl_list SET payload = ['con1 payload'] WHERE id = 1;
|
||||
|
||||
statement ok con1
|
||||
UPDATE tbl_list SET id = 3 WHERE id = 2;
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl_list VALUES (2, ['new payload']);
|
||||
|
||||
# Ensure that we can still see the old value.
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [first payload] 0
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 2;
|
||||
----
|
||||
2 [second payload] 1
|
||||
|
||||
# Try to update again.
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement error
|
||||
UPDATE tbl_list SET payload = ['second payload'] WHERE id = 1;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*Conflict on tuple deletion.*
|
||||
|
||||
statement ok
|
||||
ROLLBACK;
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [con1 payload] 2
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 2;
|
||||
----
|
||||
2 [new payload] 4
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 3;
|
||||
----
|
||||
3 [second payload] 3
|
||||
|
||||
# Ensure that the old transaction can still see the old storage.
|
||||
|
||||
query III old
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [first payload] 0
|
||||
|
||||
query III old
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 2;
|
||||
----
|
||||
2 [second payload] 1
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list ORDER BY ALL;
|
||||
----
|
||||
1 [con1 payload] 2
|
||||
2 [new payload] 4
|
||||
3 [second payload] 3
|
||||
5 [old payload] 5
|
||||
116
external/duckdb/test/sql/index/art/constraints/test_art_tx_updates_pk_col.test
vendored
Normal file
116
external/duckdb/test/sql/index/art/constraints/test_art_tx_updates_pk_col.test
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_updates_pk_col.test
|
||||
# description: Test UPDATE on the PK column with different connections and VARCHAR payload.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (id INT PRIMARY KEY, payload VARCHAR);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES (1, 'first payload');
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
statement ok old
|
||||
INSERT INTO tbl VALUES (5, 'old payload');
|
||||
|
||||
# con1 open.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
UPDATE tbl SET id = 3 WHERE id = 1;
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl VALUES (1, 'new payload');
|
||||
|
||||
# Ensure that we can still see the old value.
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 first payload 0
|
||||
|
||||
# Locally update the payload.
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement ok
|
||||
UPDATE tbl SET payload = 'second payload' WHERE id = 1;
|
||||
|
||||
# Transaction-local state.
|
||||
|
||||
query II
|
||||
SELECT id, payload FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 second payload
|
||||
|
||||
# Transaction-local state.
|
||||
|
||||
query II con1
|
||||
SELECT id, payload FROM tbl WHERE id = 3;
|
||||
----
|
||||
3 first payload
|
||||
|
||||
query II con1
|
||||
SELECT id, payload FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 new payload
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
# We only see the local changes.
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 second payload 0
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 3;
|
||||
----
|
||||
|
||||
# This runs into a write-write conflict on commit and rolls back.
|
||||
|
||||
statement ok
|
||||
COMMIT;
|
||||
|
||||
# The result are the committed changes of con1.
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 3;
|
||||
----
|
||||
3 first payload 1
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 new payload 2
|
||||
|
||||
# Ensure that the old transaction can still see the old storage.
|
||||
|
||||
query III old
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 first payload 0
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl ORDER BY ALL;
|
||||
----
|
||||
1 new payload 2
|
||||
3 first payload 1
|
||||
5 old payload 3
|
||||
39
external/duckdb/test/sql/index/art/constraints/test_art_tx_updates_rollback.test
vendored
Normal file
39
external/duckdb/test/sql/index/art/constraints/test_art_tx_updates_rollback.test
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_updates_rollback.test
|
||||
# description: Test UPDATE, then ROLLBACK due to a constraint violation.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_rollback (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_rollback VALUES (1, ['first payload']);
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
UPDATE tbl_rollback SET payload = ['con1 payload'] WHERE id = 1;
|
||||
|
||||
statement error con1
|
||||
INSERT INTO tbl_rollback VALUES (1, ['con1 payload']);
|
||||
----
|
||||
<REGEX>:Constraint Error.*PRIMARY KEY or UNIQUE constraint violation.*
|
||||
|
||||
statement error con1
|
||||
SELECT 42;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*Current transaction is aborted.*
|
||||
|
||||
statement ok con1
|
||||
ROLLBACK;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_rollback ORDER BY ALL;
|
||||
----
|
||||
1 [first payload] 0
|
||||
54
external/duckdb/test/sql/index/art/constraints/test_art_tx_upsert_with_global_nested.test
vendored
Normal file
54
external/duckdb/test/sql/index/art/constraints/test_art_tx_upsert_with_global_nested.test
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_upsert_with_global_nested.test
|
||||
# description: Test UPSERT while the global ART has nested leaves.
|
||||
# group: [constraints]
|
||||
|
||||
load __TEST_DIR__/test_art_tx_upsert_with_global_nested.db
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl VALUES (1, ['first payload']);
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
# Now update the ART via UPSERT.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
INSERT OR REPLACE INTO tbl VALUES (1, ['con1 payload']);
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
# The ART leaf contains both the new and the old row ID.
|
||||
|
||||
statement ok con2
|
||||
BEGIN
|
||||
|
||||
statement ok con2
|
||||
INSERT OR REPLACE INTO tbl VALUES (1, ['con2 payload']);
|
||||
|
||||
statement error con2
|
||||
COMMIT;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*write-write conflict on key.*
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl WHERE id = 1;
|
||||
----
|
||||
1 [con1 payload] 1
|
||||
75
external/duckdb/test/sql/index/art/constraints/test_art_tx_upserts_list.test
vendored
Normal file
75
external/duckdb/test/sql/index/art/constraints/test_art_tx_upserts_list.test
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_upserts_list.test
|
||||
# description: Test UPSERT with different connections and LIST payload.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_list (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_list VALUES (1, ['first payload']);
|
||||
|
||||
# Keep one connection open to ensure we still have the old value in the ART.
|
||||
|
||||
statement ok old
|
||||
BEGIN;
|
||||
|
||||
statement ok old
|
||||
INSERT INTO tbl_list VALUES (5, ['old payload']);
|
||||
|
||||
# con1 open.
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
INSERT OR REPLACE INTO tbl_list VALUES (1, ['con1 payload']);
|
||||
|
||||
# Ensure that we can still see the old value.
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [first payload] 0
|
||||
|
||||
# Try to upsert again.
|
||||
|
||||
statement ok
|
||||
BEGIN;
|
||||
|
||||
statement error
|
||||
INSERT OR REPLACE INTO tbl_list VALUES (1, ['second payload']);
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*Conflict on tuple deletion.*
|
||||
|
||||
statement ok
|
||||
ROLLBACK;
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [con1 payload] 1
|
||||
|
||||
# Ensure that the old transaction can still see the old storage.
|
||||
|
||||
query III old
|
||||
SELECT id, payload, rowid FROM tbl_list WHERE id = 1;
|
||||
----
|
||||
1 [first payload] 0
|
||||
|
||||
statement ok old
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_list ORDER BY ALL;
|
||||
----
|
||||
1 [con1 payload] 1
|
||||
5 [old payload] 2
|
||||
51
external/duckdb/test/sql/index/art/constraints/test_art_tx_upserts_local.test
vendored
Normal file
51
external/duckdb/test/sql/index/art/constraints/test_art_tx_upserts_local.test
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_upserts_local.test
|
||||
# description: Test multiple UPSERTs in a connection with LIST payload.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_local (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_local VALUES (1, ['first payload']);
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
INSERT OR REPLACE INTO tbl_local VALUES (1, ['con1 payload']);
|
||||
|
||||
statement ok con1
|
||||
INSERT OR REPLACE INTO tbl_local VALUES (1, ['local payload']);
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_local WHERE id = 1;
|
||||
----
|
||||
1 [first payload] 0
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_local WHERE id = 1;
|
||||
----
|
||||
1 [local payload] 1
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
INSERT OR REPLACE INTO tbl_local VALUES (1, ['val2 payload']), (1, ['val2 payload']);
|
||||
|
||||
statement ok con1
|
||||
COMMIT;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_local WHERE id = 1;
|
||||
----
|
||||
1 [val2 payload] 2
|
||||
42
external/duckdb/test/sql/index/art/constraints/test_art_tx_upserts_rollback.test
vendored
Normal file
42
external/duckdb/test/sql/index/art/constraints/test_art_tx_upserts_rollback.test
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
# name: test/sql/index/art/constraints/test_art_tx_upserts_rollback.test
|
||||
# description: Test UPSERT, then ROLLBACK due to a constraint violation.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
SET immediate_transaction_mode = true;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE tbl_rollback (id INT PRIMARY KEY, payload VARCHAR[]);
|
||||
|
||||
statement ok
|
||||
INSERT INTO tbl_rollback VALUES (1, ['first payload']);
|
||||
|
||||
statement ok con1
|
||||
BEGIN;
|
||||
|
||||
statement ok con1
|
||||
INSERT OR REPLACE INTO tbl_rollback VALUES (1, ['con1 payload']);
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO tbl_rollback VALUES (2, ['second payload']);
|
||||
|
||||
statement error con1
|
||||
INSERT INTO tbl_rollback VALUES (2, ['second payload']);
|
||||
----
|
||||
<REGEX>:Constraint Error.*PRIMARY KEY or UNIQUE constraint violation.*
|
||||
|
||||
statement error con1
|
||||
SELECT 42;
|
||||
----
|
||||
<REGEX>:TransactionContext Error.*Current transaction is aborted.*
|
||||
|
||||
statement ok con1
|
||||
ROLLBACK;
|
||||
|
||||
query III
|
||||
SELECT id, payload, rowid FROM tbl_rollback ORDER BY ALL;
|
||||
----
|
||||
1 [first payload] 0
|
||||
28
external/duckdb/test/sql/index/art/constraints/test_art_upsert_duplicate.test
vendored
Normal file
28
external/duckdb/test/sql/index/art/constraints/test_art_upsert_duplicate.test
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# name: test/sql/index/art/constraints/test_art_upsert_duplicate.test
|
||||
# description: Test an UPSERT with a duplicate in the VALUES list.
|
||||
# group: [constraints]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE hero (
|
||||
name VARCHAR NOT NULL,
|
||||
secret_name VARCHAR NOT NULL,
|
||||
age INTEGER,
|
||||
PRIMARY KEY (name));
|
||||
|
||||
statement ok
|
||||
CREATE INDEX ix_hero_age ON hero (age);
|
||||
|
||||
statement ok
|
||||
INSERT INTO hero (name, secret_name, age)
|
||||
VALUES
|
||||
('Captain North America', 'Esteban Rogelios', 93),
|
||||
('Rusty-Man', 'Tommy Sharp', 48),
|
||||
('Tarantula', 'Natalia Roman-on', 32),
|
||||
('Spider-Boy', 'Pedro Parqueador', 17),
|
||||
('Captain North America', 'Esteban Rogelios', 93)
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET secret_name = EXCLUDED.secret_name,
|
||||
age = EXCLUDED.age;
|
||||
46
external/duckdb/test/sql/index/art/constraints/test_art_upsert_other_index.test
vendored
Normal file
46
external/duckdb/test/sql/index/art/constraints/test_art_upsert_other_index.test
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# name: test/sql/index/art/constraints/test_art_upsert_other_index.test
|
||||
# description: Test an UPSERT SET expression targeting an indexed column.
|
||||
# group: [constraints]
|
||||
|
||||
# Original issue: 2382
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification;
|
||||
|
||||
statement ok
|
||||
CREATE TABLE kvp (
|
||||
"key" VARCHAR PRIMARY KEY,
|
||||
"value" VARCHAR,
|
||||
expiration BIGINT,
|
||||
"cache" BOOLEAN);
|
||||
|
||||
statement ok
|
||||
CREATE INDEX kve_idx ON kvp (expiration);
|
||||
|
||||
statement ok
|
||||
INSERT OR REPLACE INTO kvp VALUES ('/key', 'value', 0, false);
|
||||
|
||||
query IIII
|
||||
SELECT key, value, expiration, cache FROM kvp;
|
||||
----
|
||||
/key value 0 false
|
||||
|
||||
statement ok
|
||||
INSERT OR REPLACE INTO kvp VALUES ('/key', 'value', 10000000, false);
|
||||
|
||||
query IIII
|
||||
SELECT key, value, expiration, cache FROM kvp;
|
||||
----
|
||||
/key value 0 false
|
||||
|
||||
statement ok
|
||||
INSERT INTO kvp VALUES ('/key', 'value', 10000000, false)
|
||||
ON CONFLICT DO UPDATE SET
|
||||
value = excluded.value,
|
||||
expiration = excluded.expiration,
|
||||
cache = excluded.cache;
|
||||
|
||||
query IIII
|
||||
SELECT key, value, expiration, cache FROM kvp;
|
||||
----
|
||||
/key value 10000000 false
|
||||
Reference in New Issue
Block a user