should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
# name: test/sql/transactions/aborted_transaction_commit.test
# description: Commiting an aborted transaction turns it into a rollback.
# group: [transactions]
statement ok
CREATE TABLE keys(i INTEGER PRIMARY KEY);
statement ok
BEGIN;
statement ok
INSERT INTO keys VALUES (1);
statement error
INSERT INTO keys VALUES (1);
----
<REGEX>:Constraint Error.*constraint violation.*
# Implicit ROLLBACK.
statement ok
COMMIT
query I
SELECT COUNT(*) FROM keys
----
0
statement ok
BEGIN;
statement ok
INSERT INTO keys VALUES (1);
statement error
INSERT INTO keys VALUES (1);
----
<REGEX>:Constraint Error.*constraint violation.*
statement error
SELECT 42;
----
<REGEX>:TransactionContext Error.*transaction is aborted.*

View File

@@ -0,0 +1,66 @@
# name: test/sql/transactions/conflict_drop_then_delete.test
# description: Conflict: drop a table, then delete from a table in another transaction
# group: [transactions]
load __TEST_DIR__/conflict_drop_then_delete.db
statement ok
create or replace table original_table as from range(10) select 1 as col
statement ok
SET immediate_transaction_mode=true
# drop a table, then delete from that table in another transaction
statement ok con1
BEGIN
statement ok con2
BEGIN
statement ok con1
create table new_incremental as
from range(10000)
select 42 as col
statement ok con2
drop table original_table
statement ok con2
COMMIT
statement ok con1
delete from original_table where rowid % 2 = 0
statement error con1
COMMIT
----
another transaction has dropped this table
statement ok
create or replace table original_table as from range(10) select 1 as col
# do the same - but now reverse: delete from the table, then drop
statement ok con1
BEGIN
statement ok con2
BEGIN
statement ok con1
delete from original_table where rowid % 2 = 0
statement ok con1
create table new_incremental as
from range(10000)
select 42 as col
statement ok con2
drop table original_table
statement ok con2
COMMIT
statement error con1
COMMIT
----
another transaction has dropped this table

View File

@@ -0,0 +1,57 @@
# name: test/sql/transactions/conflict_rename_append.test
# description: Conflict: rename, then drop a table, then append to it from another transaction
# group: [transactions]
load __TEST_DIR__/conflict_rename_append.db
statement ok
create or replace table original_table as from range(10) select 1 as col
statement ok
SET immediate_transaction_mode=true
statement ok con1
BEGIN
statement ok con2
BEGIN
statement ok con1
create table new_incremental as
from range(10000)
select 42 as col
statement ok con1
insert into original_table
from new_incremental
statement ok con1
drop table new_incremental
statement ok con1
create table new_incremental as
from range(10000)
select 42 as col
statement ok con2
alter table original_table rename to backup_table
statement ok con2
create table temp_table as
from range(100) select 2 as col
statement ok con2
alter table temp_table rename to original_table
statement ok con2
drop table backup_table
statement ok con2
COMMIT
statement error con1
COMMIT
----
dropped
restart

View File

@@ -0,0 +1,71 @@
# name: test/sql/transactions/count_star_transactions.test
# description: Test COUNT(*) with transaction local changes
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE tbl (id INT);
statement ok
INSERT INTO tbl FROM range(10000);
query I
SELECT COUNT(*) FROM tbl
----
10000
# deletes
statement ok con1
BEGIN;
query I con1
DELETE FROM tbl WHERE id%2=0
----
5000
query I con1
SELECT COUNT(*) FROM tbl
----
5000
query II
SELECT COUNT(*), COUNT(*) + 1 FROM tbl
----
10000 10001
statement ok con1
COMMIT;
query I
SELECT COUNT(*) FROM tbl
----
5000
# transaction local appends
statement ok con1
BEGIN;
query I con1
INSERT INTO tbl FROM range(10000, 15000)
----
5000
query I con1
SELECT COUNT(*) FROM tbl
----
10000
query I
SELECT COUNT(*) FROM tbl
----
5000
statement ok con1
COMMIT;
query I
SELECT COUNT(*) FROM tbl
----
10000

View File

@@ -0,0 +1,23 @@
# name: test/sql/transactions/delete_and_drop_in_same_transaction.test
# group: [transactions]
statement ok
CREATE OR REPLACE TABLE SampleTable AS
SELECT DISTINCT id
FROM (VALUES
('one'),
('two'),
('three')
) AS t(id);
statement ok
BEGIN TRANSACTION;
statement ok
DELETE FROM sampletable;
statement ok
DROP TABLE SampleTable;
statement ok
COMMIT TRANSACTION;

View File

@@ -0,0 +1,53 @@
# name: test/sql/transactions/delete_index_lookup_transactions.test
# description: Verify indexes still correctly refer to the old state when data is deleted
# group: [transactions]
statement ok
CREATE TABLE tbl (id INT PRIMARY KEY, payload VARCHAR);
statement ok
INSERT INTO tbl VALUES (1, 'first payload');
statement ok old
BEGIN;
statement ok old
INSERT INTO tbl VALUES (5, 'con2 payload');
statement ok con1
BEGIN;
statement ok con1
DELETE FROM tbl;
statement ok con1
COMMIT;
# old should still see first_payload
query II old
SELECT id, payload FROM tbl WHERE id = 1 ORDER BY ALL;
----
1 first payload
query II old
SELECT id, payload FROM tbl WHERE id = 5 ORDER BY ALL;
----
5 con2 payload
# new should see nothing (everything is deleted)
query III con1
SELECT id, payload, rowid FROM tbl WHERE id = 1 ORDER BY ALL;
----
statement ok old
COMMIT
# after commit the first payload is gone, but the new payload is not
query II
SELECT id, payload FROM tbl WHERE id = 1 ORDER BY ALL;
----
query II
SELECT id, payload FROM tbl WHERE id = 5 ORDER BY ALL;
----
5 con2 payload

View File

@@ -0,0 +1,28 @@
# name: test/sql/transactions/rollback_drop.test
# description: Rollback a drop then try to delete
# group: [transactions]
load __TEST_DIR__/rollback_drop.db
statement ok
create or replace table original_table as from range(10) select 1 as col
statement ok
SET immediate_transaction_mode=true
statement ok
BEGIN
statement ok
DROP TABLE original_table
statement ok
ROLLBACK
statement ok
delete from original_table where rowid % 2 = 0
query I
SELECT COUNT(*) FROM original_table;
----
5

View File

@@ -0,0 +1,43 @@
# name: test/sql/transactions/test_alter_sequence_ownership_conflict.test
# description: Test write-write conflict with a DROP and an ALTER
# group: [transactions]
require noforcestorage
load __TEST_DIR__/alter_sequence_conflict1.db;
statement ok
CREATE TABLE tbl1 (id INT);
statement ok
CREATE SEQUENCE seq;
statement ok
CREATE TABLE tbl2 (
id INT DEFAULT nextval('seq')
);
statement ok
ALTER SEQUENCE seq OWNED BY tbl1;
statement ok con1
START TRANSACTION;
statement ok con1
DROP TABLE tbl1 CASCADE;
statement ok con2
START TRANSACTION;
# This fails because a newer version of 'seq' exists, as a DELETED_ENTRY
# because of the 'DROP TABLE tbl1 CASCADE'
statement error con2
ALTER SEQUENCE seq OWNED BY tbl2;
----
write-write conflict on alter with "seq"
statement ok con1
COMMIT;
statement ok con2
COMMIT;

View File

@@ -0,0 +1,49 @@
# name: test/sql/transactions/test_alter_sequence_ownership_conflict2.test
# description: Test DROP and OWNED BY transactionality | ownership commits first
# group: [transactions]
require noforcestorage
load __TEST_DIR__/alter_sequence_ownership2.db;
statement ok
CREATE TABLE tbl1 (
id INT
);
statement ok
CREATE SEQUENCE seq;
statement ok con1
START TRANSACTION;
# drop 'tbl1' in a transaction
statement ok con1
DROP TABLE tbl1 CASCADE;
statement ok con2
START TRANSACTION;
# change ownership of 'seq' to 'tbl1' in a transaction
statement ok con2
ALTER SEQUENCE seq OWNED BY tbl1;
# commit the ownership change
statement ok con2
COMMIT;
# This should no longer be able to commit
# New dependencies were introduced on 'tbl1'
statement error con1
COMMIT;
----
Could not commit DROP of "tbl1"
statement ok
drop table tbl1
# tbl1 owns 'seq', so it was already dropped
statement error
drop sequence seq
----
Sequence with name seq does not exist

View File

@@ -0,0 +1,47 @@
# name: test/sql/transactions/test_alter_sequence_ownership_conflict3.test
# description: Test DROP and OWNED BY transactionality | drop commits first
# group: [transactions]
load __TEST_DIR__/alter_sequence_ownership3.db;
statement ok
CREATE TABLE tbl1 (
id INT
);
statement ok
CREATE SEQUENCE seq;
statement ok con1
START TRANSACTION;
# Drop 'tbl1' in a transaction
statement ok con1
DROP TABLE tbl1 CASCADE;
statement ok con2
START TRANSACTION;
# Change ownership of 'seq' to 'tbl1' in a transaction
statement ok con2
ALTER SEQUENCE seq OWNED BY tbl1;
# Commit the drop
statement ok con1
COMMIT;
# This should no longer be able to commit
# The sequence and the table were already dropped
statement error con2
COMMIT;
----
Could not commit creation of dependency, subject "tbl1" has been deleted
statement error
drop table tbl1
----
Table with name tbl1 does not exist
# tbl1 does not own 'seq', so it has to be dropped manually
statement ok
drop sequence seq

View File

@@ -0,0 +1,82 @@
# name: test/sql/transactions/test_basic_transactions.test
# description: Simple table creation transaction tests
# group: [transactions]
# start transactions
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# create a table on connection one
statement ok con1
CREATE TABLE integers(i INTEGER)
# connection one should be able to query the table
query I con1
SELECT * FROM integers
----
# connection two should not be able to
statement error con2
SELECT * FROM integers
----
<REGEX>:.*Catalog Error.*Table.*not exist.*
# if we rollback, nobody should be able to query the table
statement ok con1
ROLLBACK
statement error con1
SELECT * FROM integers
----
<REGEX>:.*Catalog Error.*Table.*not exist.*
statement error con2
SELECT * FROM integers
----
<REGEX>:.*Catalog Error.*Table.*not exist.*
# now if we commit the table
statement ok con1
BEGIN TRANSACTION
statement ok con1
CREATE TABLE integers(i INTEGER)
statement ok con1
COMMIT
# con two STILL should not see it because it was started before the
# transaction committed
statement error con2
SELECT * FROM integers
----
<REGEX>:.*Catalog Error.*Table.*not exist.*
# but if we rollback and start a new transaction it should see it
statement ok con2
ROLLBACK
query I con2
SELECT * FROM integers
----
# serialize conflict
# start transactions
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# create a table on connection one
statement ok con1
CREATE TABLE integers2(i INTEGER)
# create a table on connection two with the same name
statement error con1
CREATE TABLE integers2(i INTEGER)
----
<REGEX>:.*Catalog Error.*Table.*already exists.*

View File

@@ -0,0 +1,30 @@
# name: test/sql/transactions/test_create_drop_conflict.test
# description: Test a conflict with create/drop across transactions
# group: [transactions]
load __TEST_DIR__/broken.db
statement ok
CREATE SCHEMA foo;
statement ok con2
START TRANSACTION;
# Drop the schema in con2
statement ok con2
DROP SCHEMA IF EXISTS foo CASCADE;
# Create a table on the schema we're dropping
# This should succeed because the schema drop isn't committed yet
statement ok con1
create table foo.bar as select 42;
# This now fails because the 'create table' was committed
statement error con2
COMMIT;
----
Could not commit DROP
statement ok
DROP SCHEMA foo CASCADE;

View File

@@ -0,0 +1,50 @@
# name: test/sql/transactions/test_create_drop_conflict_variation1.test
# description: Test a conflict with create/drop across transactions
# group: [transactions]
###
### The variation is that con1's query is now *also* in a transaction, we first commit the DROP SCHEMA (con2's transaction)
###
load __TEST_DIR__/broken.db
statement ok
CREATE SCHEMA foo;
statement ok con2
START TRANSACTION;
# Drop the schema in con2
statement ok con2
DROP SCHEMA IF EXISTS foo CASCADE;
statement ok con1
START TRANSACTION
# Create a table on the schema we're dropping
# This should succeed because the schema drop isn't committed yet
statement ok con1
create table foo.bar as select 42;
# This passes because the 'create table' was not committed yet
statement ok con2
COMMIT;
# This fails because the schema has been dropped
statement error con1
COMMIT;
----
statement error
DROP SCHEMA foo CASCADE;
----
Schema with name foo does not exist!
statement error
select * from foo.bar;
----
Table with name bar does not exist!
query I
select schema_name from duckdb_schemas() where schema_name = 'foo';
----

View File

@@ -0,0 +1,48 @@
# name: test/sql/transactions/test_create_drop_conflict_variation2.test
# description: Test a conflict with create/drop across transactions
# group: [transactions]
###
### The variation is that con1's query is now *also* in a transaction, we first commit the CREATE TABLE (con1's query)
###
load __TEST_DIR__/broken.db
statement ok
CREATE SCHEMA foo;
statement ok con2
START TRANSACTION;
# Drop the schema in con2
statement ok con2
DROP SCHEMA IF EXISTS foo CASCADE;
statement ok con1
START TRANSACTION
# Create a table on the schema we're dropping
# This should succeed because the schema drop isn't committed yet
statement ok con1
create table foo.bar as select 42;
# This passes because the 'drop schema' was not committed yet
statement ok con1
COMMIT;
# This fails because the create table introduces a new dependency
statement error con2
COMMIT;
----
statement ok
DROP SCHEMA foo CASCADE;
statement error
select * from foo.bar;
----
Table with name bar does not exist!
query I
select schema_name from duckdb_schemas() where schema_name = 'foo';
----

View File

@@ -0,0 +1,46 @@
# name: test/sql/transactions/test_from_update_conflict.test
# description: Test correct checking for out-of-order row id updates
# group: [transactions]
statement ok con1
CREATE TABLE test AS SELECT i AS a FROM range (2048, 5000, 1) t1(i)
statement ok con1
INSERT INTO test VALUES (1), (2), (3)
statement ok con1
CREATE TABLE src(b INTEGER)
statement ok con1
INSERT INTO src VALUES (3), (2), (1), (4)
query IIII con1
SELECT src.rowid sr, b, test.rowid tr, a FROM src, test WHERE src.b = test.a ORDER BY a;
----
2 1 2952 1
1 2 2953 2
0 3 2954 3
statement ok con1
BEGIN TRANSACTION
statement ok con1
UPDATE src SET b = 10000 WHERE src.rowid = 0 OR src.rowid = 1 OR src.rowid = 3
query I con1
SELECT b FROM src
----
10000
10000
1
10000
statement ok con2
BEGIN TRANSACTION
statement error con2
UPDATE src SET b = 20000 FROM test WHERE src.b = test.a;
----
<REGEX>:.*TransactionContext Error.*Conflict on update.*

View File

@@ -0,0 +1,56 @@
# name: test/sql/transactions/test_index_abort.test
# description: Test abort of update/delete
# group: [transactions]
statement ok con1
CREATE TABLE integers(i INTEGER PRIMARY KEY, j INTEGER)
statement ok con1
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3)
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# insert the value "4" for both transactions
statement ok con1
INSERT INTO integers VALUES (4, 4)
statement ok con2
INSERT INTO integers VALUES (4, 4)
# perform some other operations
statement ok con2
UPDATE integers SET j=j+1
statement ok con2
DELETE FROM integers WHERE i=2
statement ok con2
CREATE TABLE test(i INTEGER)
# commit both transactions, con2 should now fail
statement ok con1
COMMIT
statement error con2
COMMIT
----
<REGEX>:.*TransactionContext Error.*Failed to commit.*duplicate key.*
# verify that the data is (1, 1), (...), (4, 4)
query II con1
SELECT * FROM integers ORDER BY i
----
1 1
2 2
3 3
4 4
# table test should not exist
statement error con1
SELECT * FROM test
----
<REGEX>:.*Catalog Error.*does not exist.*

View File

@@ -0,0 +1,53 @@
# name: test/sql/transactions/test_index_huge_aborted_append.test
# description: Test abort of big append (bigger than block size)
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER PRIMARY KEY);
# insert the value [1] into the table
statement ok
INSERT INTO integers VALUES (1);
# start a transaction where we insert a lot of values, and finally insert the conflict
statement ok
BEGIN TRANSACTION
statement ok
INSERT INTO integers SELECT i FROM range(2, 131068, 1) t1(i)
# inserting the value "1" here fails
statement error
INSERT INTO integers VALUES (1)
----
# now we need to rollback
statement ok
ROLLBACK
query I
SELECT * FROM integers
----
1
# now append some rows again
statement ok
INSERT INTO integers VALUES (2);
statement ok
INSERT INTO integers VALUES (3);
statement ok
INSERT INTO integers VALUES (4);
query I
SELECT * FROM integers ORDER BY 1
----
1
2
3
4

View File

@@ -0,0 +1,63 @@
# name: test/sql/transactions/test_index_large_aborted_append.test
# description: Test that index entries are properly removed after aborted append
# group: [transactions]
statement ok
PRAGMA enable_verification
loop i 1 9
statement ok con1
CREATE TABLE integers(i INTEGER UNIQUE);
statement ok con1
BEGIN TRANSACTION;
statement ok con2
BEGIN TRANSACTION;
statement ok con1
INSERT INTO integers SELECT -10 + i FROM RANGE(${i}) tbl(i);
# insert the values [2..2048] into the table
statement ok con2
INSERT INTO integers SELECT case when i%2=0 then null else i end FROM range(2, 2049, 1) t1(i)
statement ok con2
INSERT INTO integers VALUES (-10);
# con commits first
statement ok con1
COMMIT;
# con2 fails to commit because of the conflict
statement error con2
COMMIT;
----
query I con1
SELECT COUNT(*)=${i} FROM integers
----
true
# now append the rows [2..2048 again]
statement ok con2
BEGIN TRANSACTION;
statement ok con2
INSERT INTO integers SELECT i FROM range(2, 2049, 1) t1(i)
# this time the commit should work
statement ok con2
COMMIT;
query IIII con1
SELECT (COUNT(*)-2047)=${i}, MIN(i), MAX(i), (COUNT(i)-2047)=${i} FROM integers ORDER BY 1
----
true -10 2048 true
statement ok
DROP TABLE integers;
endloop

View File

@@ -0,0 +1,77 @@
# name: test/sql/transactions/test_index_local_update.test
# description: Test index with transaction local updates
# group: [transactions]
statement ok
CREATE TABLE integers(i INTEGER PRIMARY KEY)
statement ok
INSERT INTO integers VALUES (1), (2), (3)
statement ok
BEGIN TRANSACTION
statement error
INSERT INTO integers VALUES (3)
----
<REGEX>:Constraint Error.*violates primary key constraint.*
statement ok
ROLLBACK
# Inserting a non-conflicting value succeeds, but we cannot update it to a conflicting value.
statement ok
BEGIN TRANSACTION
statement ok
INSERT INTO integers VALUES (4)
query I
SELECT COUNT(*) FROM integers
----
4
statement error
UPDATE integers SET i = 3 WHERE i = 4
----
<REGEX>:Constraint Error.*violates primary key constraint.*
statement ok
ROLLBACK
# Inserting a non-conflicting value succeeds, and updating it to another non-conflicting value is possible.
statement ok
BEGIN TRANSACTION
statement ok
INSERT INTO integers VALUES (4)
query I
SELECT COUNT(*) FROM integers
----
4
statement ok
UPDATE integers SET i = 5 WHERE i = 4
query I
SELECT i FROM integers WHERE i = 5
----
5
query I
SELECT i FROM integers WHERE i = 4
----
statement ok
COMMIT
query I
SELECT i FROM integers ORDER BY i
----
1
2
3
5

View File

@@ -0,0 +1,36 @@
# name: test/sql/transactions/test_index_pending_delete.test
# description: Test index with pending deletes
# group: [transactions]
# we can create an index with pending deletes
statement ok con1
CREATE TABLE integers(i INTEGER)
statement ok con1
INSERT INTO integers VALUES (1), (2), (3)
# delete a value
statement ok con2
BEGIN TRANSACTION
statement ok con2
DELETE FROM integers WHERE i=1
# we can create an index with pending deletes
statement ok con1
CREATE INDEX i_index ON integers using art(i)
# now we commit
statement ok con2
COMMIT
query I con1
SELECT COUNT(*) FROM integers WHERE i=1
----
0
query I con2
SELECT COUNT(*) FROM integers WHERE i=1
----
0

View File

@@ -0,0 +1,41 @@
# name: test/sql/transactions/test_index_pending_insert.test
# description: Test index with pending insertions
# group: [transactions]
# we can create an index with pending insertions
statement ok con1
CREATE TABLE integers(i INTEGER)
statement ok con2
BEGIN TRANSACTION
statement ok con2
INSERT INTO integers VALUES (1), (2), (3)
statement ok con1
CREATE INDEX i_index ON integers using art(i)
query I con1
SELECT COUNT(*) FROM integers WHERE i=1
----
0
query I con2
SELECT COUNT(*) FROM integers WHERE i=1
----
1
# after committing, the values are added to the index
statement ok con2
COMMIT
query I con1
SELECT COUNT(*) FROM integers WHERE i=1
----
1
query I con2
SELECT COUNT(*) FROM integers WHERE i=1
----
1

View File

@@ -0,0 +1,41 @@
# name: test/sql/transactions/test_index_pending_update.test
# description: Test index with pending updates
# group: [transactions]
# we cannot create an index with pending updates
statement ok con1
CREATE TABLE integers(i INTEGER)
statement ok con1
INSERT INTO integers VALUES (1), (2), (3)
# update a value
statement ok con2
BEGIN TRANSACTION
statement ok con2
UPDATE integers SET i=4 WHERE i=1
# failed to create an index: pending updates
statement error con1
CREATE INDEX i_index ON integers using art(i)
----
# now we commit
statement ok con2
COMMIT
# no more pending updates: creating the index works now
statement ok con1
CREATE INDEX i_index ON integers using art(i)
query I con1
SELECT COUNT(*) FROM integers WHERE i=4
----
1
query I con2
SELECT COUNT(*) FROM integers WHERE i=4
----
1

View File

@@ -0,0 +1,43 @@
# name: test/sql/transactions/test_index_rollback_flushed_data.test
# description: Test that we revert the global storage correctly after a constraint violation
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok con1
CREATE TABLE integers(i INTEGER UNIQUE);
statement ok con1
BEGIN TRANSACTION;
statement ok con2
BEGIN TRANSACTION;
statement ok con1
INSERT INTO integers VALUES (-10);
statement ok con2
INSERT INTO integers SELECT range FROM range(2, 4097, 1);
# constraint violation
statement ok con2
INSERT INTO integers VALUES (-10);
# con1 commits first
statement ok con1
COMMIT;
# con2 fails to commit because of the conflict
statement error con2
COMMIT;
----
PRIMARY KEY or UNIQUE constraint violation
statement ok
INSERT INTO integers SELECT i FROM range(2, 4097, 1) t1(i)
query I
SELECT MAX(i) FROM integers
----
4096

View File

@@ -0,0 +1,125 @@
# name: test/sql/transactions/test_index_transaction_local.test
# description: Test index with transaction local commits
# group: [transactions]
# first test simple index usage
statement ok con1
CREATE TABLE integers(i INTEGER PRIMARY KEY)
statement ok con1
INSERT INTO integers VALUES (1), (2), (3)
# inserting a duplicate value fails
statement error con1
INSERT INTO integers VALUES (1)
----
# inserting a non-duplicate value works
statement ok con1
INSERT INTO integers VALUES (4)
# updating a primary key to an existing value fails
statement error con1
UPDATE integers SET i=1 WHERE i=4
----
# but updating to a non-existing value works
statement ok con1
UPDATE integers SET i=5 WHERE i=4
# if we first delete a value, we can insert that value again
statement ok con1
DELETE FROM integers WHERE i=1
statement ok con1
INSERT INTO integers VALUES (1)
statement ok con1
DELETE FROM integers WHERE i >= 4
query I con1
SELECT COUNT(*) FROM integers
----
3
query I con2
SELECT COUNT(*) FROM integers
----
3
# now test with multiple transactions
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# both transactions can insert the same value
statement ok con1
INSERT INTO integers VALUES (4)
statement ok con2
INSERT INTO integers VALUES (4)
query I con1
SELECT COUNT(*) FROM integers
----
4
query I con2
SELECT COUNT(*) FROM integers
----
4
# also using the index is fine
query I con1
SELECT COUNT(*) FROM integers WHERE i=1
----
1
query I con2
SELECT COUNT(*) FROM integers WHERE i=1
----
1
query I con1
SELECT COUNT(*) FROM integers WHERE i=4
----
1
query I con2
SELECT COUNT(*) FROM integers WHERE i=4
----
1
# conflict happens on commit
# we can commit con
statement ok con1
COMMIT
# but then con2 fails to commit
statement error con2
COMMIT
----
# Issue #2241: Delete and reinsert fails on unique/indexed column
statement ok
BEGIN TRANSACTION;
statement ok
CREATE TABLE issue2241 (id text primary key);
statement ok
INSERT INTO issue2241 VALUES ('Alice');
statement ok
INSERT INTO issue2241 VALUES ('Bob');
statement ok
DELETE FROM issue2241 WHERE id = 'Bob';
statement ok
INSERT INTO issue2241 VALUES ('Bob');
statement ok
COMMIT;

View File

@@ -0,0 +1,126 @@
# name: test/sql/transactions/test_index_versioned_deletes.test
# description: Test index with versioned data from deletes
# group: [transactions]
statement ok con1
CREATE TABLE integers(i INTEGER PRIMARY KEY)
statement ok con1
INSERT INTO integers VALUES (1), (2), (3)
# local delete
statement ok con1
BEGIN TRANSACTION
# "1" exists for both transactions
query I con1
SELECT i FROM integers WHERE i=1
----
1
query I con2
SELECT i FROM integers WHERE i=1
----
1
statement ok con1
DELETE FROM integers WHERE i=1
# "1" only exists for con2
query I con1
SELECT i FROM integers WHERE i=1
----
query I con2
SELECT i FROM integers WHERE i=1
----
1
# rollback
statement ok con1
DELETE FROM integers WHERE i=1
statement ok con1
ROLLBACK
query I con1
SELECT i FROM integers WHERE i=1
----
1
query I con2
SELECT i FROM integers WHERE i=1
----
1
# local update of primary key column
statement ok con1
BEGIN TRANSACTION
# 1 => 4
statement ok con1
UPDATE integers SET i=4 WHERE i=1
query I con1
SELECT i FROM integers WHERE i=1
----
query I con2
SELECT i FROM integers WHERE i=1
----
1
query I con1
SELECT i FROM integers WHERE i=4
----
4
query I con2
SELECT i FROM integers WHERE i=4
----
# delete 4
statement ok con1
DELETE FROM integers WHERE i=4
query I con1
SELECT i FROM integers WHERE i=1
----
query I con2
SELECT i FROM integers WHERE i=1
----
1
query I con1
SELECT i FROM integers WHERE i=4
----
query I con2
SELECT i FROM integers WHERE i=4
----
# commit
statement ok con1
COMMIT
query I con1
SELECT i FROM integers WHERE i=1
----
query I con2
SELECT i FROM integers WHERE i=1
----
query I con1
SELECT i FROM integers ORDER BY i
----
2
3
query I con2
SELECT i FROM integers ORDER BY i
----
2
3

View File

@@ -0,0 +1,39 @@
# name: test/sql/transactions/test_index_versioned_updates.test
# description: Test index with versioned data from updates in secondary columns
# group: [transactions]
statement ok con1
CREATE TABLE integers(i INTEGER PRIMARY KEY, j INTEGER)
statement ok con1
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3)
statement ok con1
BEGIN TRANSACTION
statement ok con1
UPDATE integers SET j=4 WHERE i=1
query I con1
SELECT j FROM integers WHERE i=1
----
4
query I con2
SELECT j FROM integers WHERE i=1
----
1
statement ok con1
ROLLBACK
query I con1
SELECT j FROM integers WHERE i=1
----
1
query I con2
SELECT j FROM integers WHERE i=1
----
1

View File

@@ -0,0 +1,141 @@
# name: test/sql/transactions/test_interleaved_versions.test
# description: Test interleaved versions of tuples
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER)
statement ok con1
BEGIN TRANSACTION
statement ok con1
INSERT INTO integers VALUES (1)
statement ok con2
BEGIN TRANSACTION
statement ok con2
INSERT INTO integers VALUES (2)
# transaction local only
query I con1
SELECT SUM(i) FROM integers
----
1
query I con2
SELECT SUM(i) FROM integers
----
2
query I con3
SELECT SUM(i) FROM integers
----
NULL
# commit con1 only
statement ok con1
COMMIT
query I con1
SELECT SUM(i) FROM integers
----
1
query I con2
SELECT SUM(i) FROM integers
----
2
query I con3
SELECT SUM(i) FROM integers
----
1
# commit con2 as well
statement ok con2
COMMIT
query I con1
SELECT SUM(i) FROM integers
----
3
query I con2
SELECT SUM(i) FROM integers
----
3
query I con3
SELECT SUM(i) FROM integers
----
3
# now delete a tuple in both con1 and con2
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
statement ok con1
DELETE FROM integers WHERE i=1
statement ok con2
DELETE FROM integers WHERE i=2
query I con1
SELECT SUM(i) FROM integers
----
2
query I con2
SELECT SUM(i) FROM integers
----
1
query I con3
SELECT SUM(i) FROM integers
----
3
# commit con1
statement ok con1
COMMIT
query I con1
SELECT SUM(i) FROM integers
----
2
query I con2
SELECT SUM(i) FROM integers
----
1
query I con3
SELECT SUM(i) FROM integers
----
2
# commit con2
statement ok con2
COMMIT
query I con1
SELECT SUM(i) FROM integers
----
NULL
query I con2
SELECT SUM(i) FROM integers
----
NULL
query I con3
SELECT SUM(i) FROM integers
----
NULL

View File

@@ -0,0 +1,107 @@
# name: test/sql/transactions/test_multi_transaction_append.test
# description: Test appends with multiple transactions
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok con1
CREATE TABLE integers(i INTEGER, j INTEGER)
# begin two transactions
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# append a tuple, con2 cannot see this tuple yet
statement ok con1
INSERT INTO integers VALUES (1, 3)
query I con2
SELECT COUNT(*) FROM integers
----
0
query I con2
SELECT COUNT(*) FROM integers WHERE i=1
----
0
# after committing, con2 still cannot see this tuple
statement ok con1
COMMIT
query I con2
SELECT COUNT(*) FROM integers
----
0
query I con2
SELECT COUNT(*) FROM integers WHERE i=1
----
0
# after con2 commits, it can see this tuple
statement ok con2
COMMIT
query I con2
SELECT COUNT(*) FROM integers
----
1
query I con2
SELECT COUNT(*) FROM integers WHERE i=1
----
1
# now both transactions append one tuple
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
statement ok con1
INSERT INTO integers VALUES (1, 3)
statement ok con2
INSERT INTO integers VALUES (1, 3)
# they cannot see each others tuple yet
query I con1
SELECT COUNT(*) FROM integers
----
2
query I con2
SELECT COUNT(*) FROM integers
----
2
# until they both commit
statement ok con1
COMMIT
statement ok con2
COMMIT
query I con1
SELECT COUNT(*) FROM integers
----
3
query I con2
SELECT COUNT(*) FROM integers
----
3
query II con1
SELECT * FROM integers
----
1 3
1 3
1 3

View File

@@ -0,0 +1,98 @@
# name: test/sql/transactions/test_multi_version.test
# description: Test multiple versions of the same data
# group: [transactions]
statement ok
PRAGMA enable_verification
# initialize the database
statement ok con1
CREATE TABLE integers(i INTEGER);
statement ok con1
INSERT INTO integers VALUES (1), (2), (3);
# we can query the database using both connections
query R con1
SELECT SUM(i) FROM integers
----
6.000000
query R con2
SELECT SUM(i) FROM integers
----
6.000000
# now update the database in connection 1
statement ok con1
BEGIN TRANSACTION;
statement ok con1
UPDATE integers SET i=5 WHERE i=1;
query R con1
SELECT SUM(i) FROM integers
----
10.000000
# con 2 still has the same result
query R con2
SELECT SUM(i) FROM integers
----
6.000000
# we can update the same data point again in con 1
statement ok con1
UPDATE integers SET i=10 WHERE i=5;
query R con1
SELECT SUM(i) FROM integers
----
15.000000
# con 2 still has the same result
query R con2
SELECT SUM(i) FROM integers
----
6.000000
# now delete it
statement ok con1
DELETE FROM integers WHERE i>5;
query R con1
SELECT SUM(i) FROM integers
----
5.000000
# con 2 still has the same result
query R con2
SELECT SUM(i) FROM integers
----
6.000000
# insert some new data again
statement ok con1
INSERT INTO integers VALUES (1), (2)
query R con1
SELECT SUM(i) FROM integers
----
8.000000
# con 2 still has the same result
query R con2
SELECT SUM(i) FROM integers
----
6.000000
# now commit
statement ok con1
COMMIT
# con 2 now has the updated results
query R con2
SELECT SUM(i) FROM integers
----
8.000000

View File

@@ -0,0 +1,338 @@
# name: test/sql/transactions/test_multi_version_large.test
# description: Test multiple versions of the same data with a data set that exceeds a single block
# group: [transactions]
statement ok
PRAGMA enable_verification
# set up the database
statement ok con1
CREATE TABLE integers(i INTEGER);
statement ok con1
INSERT INTO integers VALUES (1), (2), (3), (4);
# 4 -> 8
statement ok con1
INSERT INTO integers SELECT * FROM integers
# 8 -> 16
statement ok con1
INSERT INTO integers SELECT * FROM integers
# 16 -> 32
statement ok con1
INSERT INTO integers SELECT * FROM integers
# 32 -> 64
statement ok con1
INSERT INTO integers SELECT * FROM integers
query I con1
SELECT COUNT(*) FROM integers WHERE i=1
----
16
# 64 -> 128
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
32 32
# 128 -> 256
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
64 64
# 256 -> 512
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
128 128
# 512 -> 1024
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
256 256
# 1024 -> 2048
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
512 512
# 2048 -> 4096
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
1024 1024
# 4096 -> 8192
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
2048 2048
# 8192 -> 16384
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
4096 4096
# 16384 -> 32768
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
8192 8192
# 32768 -> 65536
statement ok con1
INSERT INTO integers SELECT * FROM integers
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
16384 16384
# 65536 -> 131072
statement ok con1
INSERT INTO integers SELECT * FROM integers
# verify the count and sum
query I con1
SELECT COUNT(*) FROM integers
----
131072
query R con1
SELECT SUM(i) FROM integers
----
327680
query II con1
SELECT COUNT(*), COUNT(DISTINCT ROWID) FROM integers WHERE i=1
----
32768 32768
query I con1
SELECT COUNT(*) FROM integers WHERE i=2
----
32768
query I con1
SELECT COUNT(*) FROM integers WHERE i=3
----
32768
query I con1
SELECT COUNT(*) FROM integers WHERE i=4
----
32768
# now delete some tuples
statement ok con1
BEGIN TRANSACTION;
query I con1
DELETE FROM integers WHERE i=1
----
32768
# check the updated count and sum
query I con1
SELECT COUNT(*) FROM integers
----
98304
query R con1
SELECT SUM(i) FROM integers
----
294912.000000
# con2 still has the same count and sum
query I con2
SELECT COUNT(*) FROM integers
----
131072
query R con2
SELECT SUM(i) FROM integers
----
327680.000000
# rollback
statement ok con1
ROLLBACK;
# now the count and sum are back to normal
query I con1
SELECT COUNT(*) FROM integers
----
131072
query R con1
SELECT SUM(i) FROM integers
----
327680.000000
# now delete some tuples
statement ok con1
BEGIN TRANSACTION;
statement ok con1
DELETE FROM integers WHERE i=2
# check the updated count and sum
query I con1
SELECT COUNT(*) FROM integers
----
98304
query R con1
SELECT SUM(i) FROM integers
----
262144.000000
# con2 still has the same count and sum
query I con2
SELECT COUNT(*) FROM integers
----
131072
query R con2
SELECT SUM(i) FROM integers
----
327680.000000
# rollback
statement ok con1
ROLLBACK;
# now the count and sum are back to normal
query I con1
SELECT COUNT(*) FROM integers
----
131072
query R con1
SELECT SUM(i) FROM integers
----
327680.000000
# now delete some tuples
statement ok con1
BEGIN TRANSACTION;
statement ok con1
DELETE FROM integers WHERE i=3
# check the updated count and sum
query I con1
SELECT COUNT(*) FROM integers
----
98304
query R con1
SELECT SUM(i) FROM integers
----
229376.000000
# con2 still has the same count and sum
query I con2
SELECT COUNT(*) FROM integers
----
131072
query R con2
SELECT SUM(i) FROM integers
----
327680.000000
# rollback
statement ok con1
ROLLBACK;
# now the count and sum are back to normal
query I con1
SELECT COUNT(*) FROM integers
----
131072
query R con1
SELECT SUM(i) FROM integers
----
327680.000000
# now delete some tuples
statement ok con1
BEGIN TRANSACTION;
statement ok con1
DELETE FROM integers WHERE i=4
# check the updated count and sum
query I con1
SELECT COUNT(*) FROM integers
----
98304
query R con1
SELECT SUM(i) FROM integers
----
196608.000000
# con2 still has the same count and sum
query I con2
SELECT COUNT(*) FROM integers
----
131072
query R con2
SELECT SUM(i) FROM integers
----
327680.000000
# rollback
statement ok con1
ROLLBACK;
# now the count and sum are back to normal
query I con1
SELECT COUNT(*) FROM integers
----
131072
query R con1
SELECT SUM(i) FROM integers
----
327680.000000

View File

@@ -0,0 +1,50 @@
# name: test/sql/transactions/test_null_version.test
# description: Test NULL versions
# group: [transactions]
statement ok
SET immediate_transaction_mode=true
statement ok
PRAGMA enable_verification
statement ok con1
CREATE TABLE integers(i INTEGER, j INTEGER)
statement ok con1
INSERT INTO integers VALUES (NULL, 3)
query II con1
SELECT * FROM integers
----
NULL 3
# begin a transaction in con2
statement ok con2
BEGIN TRANSACTION
# update the row in con1
statement ok con1
UPDATE integers SET i=1,j=1
# con1 should see the value "1"
query II con1
SELECT * FROM integers
----
1 1
# con2 should see the value "NULL"
query II con2
SELECT * FROM integers
----
NULL 3
# after a rollback con2 should see the value "1" as well
statement ok con2
ROLLBACK
query II con1
SELECT * FROM integers
----
1 1

View File

@@ -0,0 +1,30 @@
# name: test/sql/transactions/test_read_only_transactions.test
# description: Test read only transactions
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE a(i INTEGER)
statement ok
INSERT INTO a VALUES (42)
statement ok
BEGIN TRANSACTION READ ONLY
# we can read from the database
query I
SELECT * FROM a
----
42
# we cannot modify the database in a read-only transaction
statement error
INSERT INTO a VALUES (48)
----
transaction is launched in read-only mode
statement ok
COMMIT

View File

@@ -0,0 +1,65 @@
# name: test/sql/transactions/test_stacked_schema_change.test
# description: Stacked schema changes
# group: [transactions]
statement ok
CREATE TABLE a(i INTEGER)
statement ok
INSERT INTO a VALUES (44)
query I
SELECT i FROM a
----
44
statement ok
BEGIN TRANSACTION
statement ok
DROP TABLE a
statement ok
CREATE TABLE a(i INTEGER)
statement ok
INSERT INTO a VALUES (45)
query I
SELECT i FROM a
----
45
statement ok
ROLLBACK
query I
SELECT i FROM a
----
44
statement ok
BEGIN TRANSACTION
statement ok
DROP TABLE a
statement ok
CREATE TABLE a(i INTEGER)
statement ok
INSERT INTO a VALUES (46)
query I
SELECT i FROM a
----
46
statement ok
COMMIT
query I
SELECT i FROM a
----
46

View File

@@ -0,0 +1,58 @@
# name: test/sql/transactions/test_transaction_abort.test
# description: Test transaction aborts after failures
# group: [transactions]
statement ok
PRAGMA enable_verification
# set up a table
statement ok
CREATE TABLE integers(i INTEGER PRIMARY KEY)
statement ok
INSERT INTO integers VALUES (1), (2)
# start a transaction
statement ok
BEGIN TRANSACTION
# parser errors do not invalidate the current transaction
statement error
SELEC 42
----
Parser Error: syntax error at or near "SELEC"
query I
SELECT 42
----
42
# neither do binder errors
statement error
SELECT * FROM nonexistanttable
----
query I
SELECT 42
----
42
# however primary key conflicts do invalidate it
statement error
UPDATE integers SET i=2
----
statement error
SELECT 42
----
# now we need to rollback
statement ok
ROLLBACK
query I
SELECT * FROM integers ORDER BY 1
----
1
2

View File

@@ -0,0 +1,29 @@
# name: test/sql/transactions/test_transaction_functionality.test
# description: Test basic transaction functionality
# group: [transactions]
statement ok
PRAGMA enable_verification
# cannot commit or rollback in auto commit mode
statement error
COMMIT
----
statement error
ROLLBACK
----
# we can start a transaction
statement ok
START TRANSACTION
# but we cannot start a transaction within a transaction!
statement error
START TRANSACTION
----
# now we can rollback
statement ok
ROLLBACK

View File

@@ -0,0 +1,36 @@
# name: test/sql/transactions/test_transaction_local_add.test
# description: Test ADD COLUMN on transaction local data
# group: [transactions]
statement ok
PRAGMA enable_verification
# perform different operations on the same data within one transaction
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER)
statement ok
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3)
statement ok
ALTER TABLE integers ADD COLUMN k INTEGER DEFAULT 4
query III
SELECT * FROM integers ORDER BY 1
----
1 1 4
2 2 4
3 3 4
statement ok
COMMIT
query III
SELECT * FROM integers ORDER BY 1
----
1 1 4
2 2 4
3 3 4

View File

@@ -0,0 +1,36 @@
# name: test/sql/transactions/test_transaction_local_alter_type.test
# description: Test ALTER TYPE on transaction local data
# group: [transactions]
statement ok
PRAGMA enable_verification
# perform different operations on the same data within one transaction
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER)
statement ok
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3)
statement ok
ALTER TABLE integers ALTER j TYPE BIGINT
query II
SELECT * FROM integers ORDER BY 1
----
1 1
2 2
3 3
statement ok
COMMIT
query II
SELECT * FROM integers ORDER BY 1
----
1 1
2 2
3 3

View File

@@ -0,0 +1,59 @@
# name: test/sql/transactions/test_transaction_local_data.test
# description: Test operations on transaction local data
# group: [transactions]
statement ok
PRAGMA enable_verification
# perform different operations on the same data within one transaction
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER)
# append
statement ok
INSERT INTO integers VALUES (1, 3), (2, 3)
query II
SELECT * FROM integers ORDER BY 1
----
1 3
2 3
# update
statement ok
UPDATE integers SET j=5 WHERE i=2
statement ok
UPDATE integers SET j=5 WHERE i=2
statement ok
UPDATE integers SET j=5 WHERE i=2
query II
SELECT * FROM integers ORDER BY 1
----
1 3
2 5
# delete
statement ok
DELETE FROM integers WHERE i=2
query II
SELECT * FROM integers ORDER BY 1
----
1 3
# commit
statement ok
COMMIT
# we can still read the table now
query II
SELECT * FROM integers ORDER BY 1
----
1 3

View File

@@ -0,0 +1,36 @@
# name: test/sql/transactions/test_transaction_local_drop.test
# description: Test DROP COLUMN on transaction local data
# group: [transactions]
statement ok
PRAGMA enable_verification
# perform different operations on the same data within one transaction
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER)
statement ok
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3)
statement ok
ALTER TABLE integers DROP COLUMN j
query I
SELECT * FROM integers ORDER BY 1
----
1
2
3
statement ok
COMMIT
query I
SELECT * FROM integers ORDER BY 1
----
1
2
3

View File

@@ -0,0 +1,31 @@
# name: test/sql/transactions/test_transaction_local_unique.test
# description: Test appends on transaction local data with unique indices
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER PRIMARY KEY, j INTEGER)
statement ok
INSERT INTO integers VALUES (1, 3)
# append only
statement ok
BEGIN TRANSACTION
statement error
INSERT INTO integers VALUES (1, 2)
----
statement ok
ROLLBACK
# if we delete we can insert that value again
statement ok
DELETE FROM integers
statement ok
INSERT INTO integers VALUES (1, 2)

View File

@@ -0,0 +1,100 @@
# name: test/sql/transactions/test_transaction_local_unique_ops.test
# description: Test operations on transaction local data with unique indices
# group: [transactions]
statement ok
PRAGMA enable_verification
# perform different operations on the same data within one transaction
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i INTEGER PRIMARY KEY, j INTEGER)
statement ok
INSERT INTO integers VALUES (1, 3), (2, 3)
query II
SELECT * FROM integers ORDER BY 1
----
1 3
2 3
# appending the same value again fails
statement error
INSERT INTO integers VALUES (1, 2)
----
statement ok
ROLLBACK
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i INTEGER PRIMARY KEY, j INTEGER)
statement ok
INSERT INTO integers VALUES (1, 3), (2, 3)
query II
SELECT * FROM integers ORDER BY 1
----
1 3
2 3
# updating also fails if there is a conflict
statement error
UPDATE integers SET i=1 WHERE i=2
----
statement ok
ROLLBACK
statement ok
BEGIN TRANSACTION
statement ok
CREATE TABLE integers(i INTEGER PRIMARY KEY, j INTEGER)
statement ok
INSERT INTO integers VALUES (1, 3), (2, 3)
query II
SELECT * FROM integers ORDER BY 1
----
1 3
2 3
# but not if there is no conflict
statement ok
UPDATE integers SET i=3 WHERE i=2
statement ok
COMMIT
query II
SELECT * FROM integers ORDER BY 1
----
1 3
3 3
# if we delete, we can insert the value again
statement ok
DELETE FROM integers WHERE i=1
query II
SELECT * FROM integers ORDER BY 1
----
3 3
statement ok
INSERT INTO integers VALUES (1, 3)
query II
SELECT * FROM integers ORDER BY 1
----
1 3
3 3

View File

@@ -0,0 +1,86 @@
# name: test/sql/transactions/test_transactional_sequences.test
# description: Test that sequences are transactional
# group: [transactions]
# start a transaction for both nodes
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# create a sequence in node one
statement ok con1
CREATE SEQUENCE seq;
# node one can see it
query I con1
SELECT nextval('seq');
----
1
# node two can't see it
statement error con2
SELECT nextval('seq');
----
# we commit the sequence
statement ok con1
COMMIT
# node two still can't see it
statement error con2
SELECT nextval('seq');
----
# now commit node two
statement ok con2
COMMIT
# we can now see the sequence in node two
query I con2
SELECT nextval('seq');
----
2
# drop sequence seq in a transaction
statement ok con1
BEGIN TRANSACTION
statement ok con1
DROP SEQUENCE seq;
# node one can't use it anymore
statement error con1
SELECT nextval('seq');
----
# node two can still use it
query I con2
SELECT nextval('seq');
----
3
# rollback cancels the drop sequence
statement ok con1
ROLLBACK;
# we can still use it
query I con2
SELECT nextval('seq');
----
4
# now we drop it for real
statement ok con1
DROP SEQUENCE seq;
# we can't use it anymore
statement error con1
SELECT nextval('seq');
----
statement error con2
SELECT nextval('seq');
----

View File

@@ -0,0 +1,24 @@
# name: test/sql/transactions/transaction_errors.test
# description: Error conditions of transactions
# group: [transactions]
# nothing to rollback
statement error
ROLLBACK;
----
# nothing to commit
statement error
COMMIT;
----
statement ok
BEGIN;
# cannot start a transaction in a transaction
statement error
BEGIN;
----
statement ok
ROLLBACK;

View File

@@ -0,0 +1,73 @@
# name: test/sql/transactions/transaction_insert_delete_chunks.test
# description: Test clean-up of chunks when mixing inserts and deletes
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER);
statement ok
INSERT INTO integers FROM range(1000);
statement ok
SET immediate_transaction_mode=true
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# con1 inserts rows 1000..3000
statement ok con1
INSERT INTO integers FROM range(1000, 3000);
statement ok con1
COMMIT
# con2 deletes the rows 1000.3000
query I con2
DELETE FROM integers
----
1000
statement ok con2
COMMIT
query III
SELECT MIN(i), MAX(i), COUNT(*) FROM integers
----
1000 2999 2000
# now do the same but with bigger chunks
statement ok
INSERT INTO integers FROM range(10000);
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# con1 inserts rows 1000..3000
statement ok con1
INSERT INTO integers FROM range(10000, 30000);
statement ok con1
COMMIT
# con2 deletes the rows 1000.3000
query I con2
DELETE FROM integers
----
12000
statement ok con2
COMMIT
query III
SELECT MIN(i), MAX(i), COUNT(*) FROM integers
----
10000 29999 20000

View File

@@ -0,0 +1,46 @@
# name: test/sql/transactions/transaction_insert_mixed_deletes.test
# description: Test clean-up of inserts and mixed deletes
# group: [transactions]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE integers(i INTEGER);
# insert 1000 integers
statement ok
INSERT INTO integers FROM range(1000);
statement ok
SET immediate_transaction_mode=true
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
# con1 inserts more rows
statement ok con1
INSERT INTO integers FROM range(1000,3000);
# con2 deletes all existing rows
query I con2
DELETE FROM integers
----
1000
statement ok con2
COMMIT
statement ok con1
COMMIT
statement ok con1
DELETE FROM integers
query I
SELECT COUNT(*) FROM integers
----
0

View File

@@ -0,0 +1,90 @@
# name: test/sql/transactions/types/test_hugeint_transactions.test
# description: Test transaction ops with hugeints
# group: [types]
statement ok
PRAGMA enable_verification
# create table
statement ok con1
CREATE TABLE hugeints (h HUGEINT);
statement ok con1
INSERT INTO hugeints VALUES (100::HUGEINT), (1023819078293589341789412412), (42);
# update
statement ok con1
BEGIN TRANSACTION;
statement ok con1
UPDATE hugeints SET h=100 WHERE h=42;
# now we only have two distinct values in con
query T con1
SELECT * FROM hugeints ORDER BY 1
----
100
100
1023819078293589341789412412
query I con1
SELECT COUNT(DISTINCT h) FROM hugeints
----
2
# in con2 we still have 3
query T con2
SELECT * FROM hugeints ORDER BY 1
----
42
100
1023819078293589341789412412
query I con2
SELECT COUNT(DISTINCT h) FROM hugeints
----
3
# rollback
statement ok con1
ROLLBACK
# after the rollback we are back to 3
query I con1
SELECT COUNT(DISTINCT h) FROM hugeints
----
3
# now commit it
statement ok con1
UPDATE hugeints SET h=100 WHERE h=42;
query TI con1
SELECT h, COUNT(*) FROM hugeints GROUP BY h ORDER BY 2 DESC
----
100 2
1023819078293589341789412412 1
query I con1
SELECT COUNT(DISTINCT h) FROM hugeints
----
2
query I con2
SELECT COUNT(DISTINCT h) FROM hugeints
----
2
# increment 100 by 1
statement ok
UPDATE hugeints SET h=h+1 WHERE h=100;
query I con1
SELECT COUNT(DISTINCT h) FROM hugeints
----
2
query I con2
SELECT COUNT(DISTINCT h) FROM hugeints
----
2

View File

@@ -0,0 +1,77 @@
# name: test/sql/transactions/types/test_interval_transactions.test
# description: Test transaction ops with intervals
# group: [types]
statement ok
PRAGMA enable_verification
# create table
statement ok con1
CREATE TABLE interval (t INTERVAL);
statement ok con1
INSERT INTO interval VALUES (INTERVAL '20' DAY), (INTERVAL '1' YEAR), (INTERVAL '1' MONTH);
# update
statement ok con1
BEGIN TRANSACTION;
statement ok con1
UPDATE interval SET t=INTERVAL '1' MONTH WHERE t=INTERVAL '20' DAY;
# now we only have two distinct values in con
query T con1
SELECT * FROM interval ORDER BY 1
----
1 month
1 month
1 year
query I con1
SELECT COUNT(DISTINCT t) FROM interval
----
2
# in con2 we still have 3
query T con2
SELECT * FROM interval ORDER BY 1
----
20 days
1 month
1 year
query I con2
SELECT COUNT(DISTINCT t) FROM interval
----
3
# rollback
statement ok con1
ROLLBACK
# after the rollback we are back to 3
query I con1
SELECT COUNT(DISTINCT t) FROM interval
----
3
# now commit it
statement ok con1
UPDATE interval SET t=INTERVAL '1' MONTH WHERE t=INTERVAL '20' DAY;
query TI con1
SELECT t, COUNT(*) FROM interval GROUP BY t ORDER BY 2 DESC
----
1 month 2
1 year 1
query I con1
SELECT COUNT(DISTINCT t) FROM interval
----
2
query I con2
SELECT COUNT(DISTINCT t) FROM interval
----
2

View File

@@ -0,0 +1,90 @@
# name: test/sql/transactions/types/test_uhugeint_transactions.test
# description: Test transaction ops with uhugeints
# group: [types]
statement ok
PRAGMA enable_verification
# create table
statement ok con1
CREATE TABLE uhugeints (h UHUGEINT);
statement ok con1
INSERT INTO uhugeints VALUES (100::UHUGEINT), (1023819078293589341789412412), (42);
# update
statement ok con1
BEGIN TRANSACTION;
statement ok con1
UPDATE uhugeints SET h=100 WHERE h=42;
# now we only have two distinct values in con
query T con1
SELECT * FROM uhugeints ORDER BY 1
----
100
100
1023819078293589341789412412
query I con1
SELECT COUNT(DISTINCT h) FROM uhugeints
----
2
# in con2 we still have 3
query T con2
SELECT * FROM uhugeints ORDER BY 1
----
42
100
1023819078293589341789412412
query I con2
SELECT COUNT(DISTINCT h) FROM uhugeints
----
3
# rollback
statement ok con1
ROLLBACK
# after the rollback we are back to 3
query I con1
SELECT COUNT(DISTINCT h) FROM uhugeints
----
3
# now commit it
statement ok con1
UPDATE uhugeints SET h=100 WHERE h=42;
query TI con1
SELECT h, COUNT(*) FROM uhugeints GROUP BY h ORDER BY 2 DESC
----
100 2
1023819078293589341789412412 1
query I con1
SELECT COUNT(DISTINCT h) FROM uhugeints
----
2
query I con2
SELECT COUNT(DISTINCT h) FROM uhugeints
----
2
# increment 100 by 1
statement ok
UPDATE uhugeints SET h=h+1 WHERE h=100;
query I con1
SELECT COUNT(DISTINCT h) FROM uhugeints
----
2
query I con2
SELECT COUNT(DISTINCT h) FROM uhugeints
----
2