Changeset: 4412f52fd48a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4412f52fd48a
Added Files:
        sql/test/concurrent/Tests/smart-segment-merge.test
Modified Files:
        sql/test/concurrent/Tests/All
Branch: smart-merge-jan22
Log Message:

Add smart merge test


diffs (truncated from 318 to 300 lines):

diff --git a/sql/test/concurrent/Tests/All b/sql/test/concurrent/Tests/All
--- a/sql/test/concurrent/Tests/All
+++ b/sql/test/concurrent/Tests/All
@@ -1,2 +1,3 @@
 simple_select
 crash_on_concurrent_use.SF-1411926
+smart-segment-merge
diff --git a/sql/test/concurrent/Tests/smart-segment-merge.test 
b/sql/test/concurrent/Tests/smart-segment-merge.test
new file mode 100644
--- /dev/null
+++ b/sql/test/concurrent/Tests/smart-segment-merge.test
@@ -0,0 +1,306 @@
+# INIT
+
+@connection(id=1, username=monetdb, password=monetdb)
+statement ok
+CREATE TABLE Test (k int);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+1
+
+@connection(id=1)
+statement ok
+INSERT INTO Test SELECT value FROM generate_series(1, 11);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+1
+
+
+# TEST INSERTS
+# the four uncommitted transactions create four new segments, appended to the 
tail of the segment list;
+# the first commit (id=1) does not merge any segments since active 
transactions prevent it;
+# the second commit (id=3) does not merge any segments since there is an 
uncommitted segment of id=2 between id=1 and id=3;
+# the third commit (id=4) is able to merge its segment plus the segment 
inserted by the transaction id=3,
+#  as they are next to each other and the active transaction is not able to 
read them;
+# the fourth commit is able to merge everything, as there are no active 
transactions and all segments are contiguous.
+
+@connection(id=1)
+statement ok
+begin transaction
+
+@connection(id=2, username=monetdb, password=monetdb)
+statement ok
+begin transaction
+
+@connection(id=3, username=monetdb, password=monetdb)
+statement ok
+begin transaction
+
+@connection(id=4, username=monetdb, password=monetdb)
+statement ok
+begin transaction
+
+@connection(id=1)
+statement ok
+INSERT INTO Test VALUES (11);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+2
+
+@connection(id=2)
+statement ok
+INSERT INTO Test VALUES (12);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+3
+
+@connection(id=3)
+statement ok
+INSERT INTO Test VALUES (13), (14);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+4
+
+@connection(id=4)
+statement ok
+INSERT INTO Test VALUES (15);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+5
+
+@connection(id=1)
+statement ok
+commit
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+5
+
+@connection(id=3)
+statement ok
+commit
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+5
+
+@connection(id=4)
+statement ok
+commit
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+4
+
+@connection(id=1)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,5,6,7,8,9,10,11,13,14,15
+
+@connection(id=2)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,5,6,7,8,9,10,12
+
+@connection(id=2)
+statement ok
+commit
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+1
+
+@connection(id=1)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
+
+
+# TEST DELETES
+# the first transaction is read only;
+# the second transaction deletes one row, splitting the segment;
+# the third transaction deletes another row, creating another split, but 
cannot merge as it is not contiguous with the second tx;
+# the fourth transaction deletes another row between the second and third txs, 
merging the segments.
+
+@connection(id=1)
+statement ok
+begin transaction
+
+@connection(id=2)
+statement ok
+DELETE FROM Test WHERE k = 5
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+3
+
+@connection(id=2)
+statement ok
+DELETE FROM Test WHERE k = 7
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+5
+
+@connection(id=1)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
+
+@connection(id=2)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,6,8,9,10,11,12,13,14,15
+
+@connection(id=2)
+statement ok
+DELETE FROM Test WHERE k = 6
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+3
+
+@connection(id=1)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
+
+@connection(id=2)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,8,9,10,11,12,13,14,15
+
+@connection(id=1)
+statement ok
+commit
+
+@connection(id=1)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,8,9,10,11,12,13,14,15
+
+
+# TEST FILLING HOLES
+# there are currently 3 segments, with the middle one referring to three 
deleted rows;
+# the first transaction is read-only;
+# the second transaction inserts a new row, which splits the deleted segment 
into two;
+#  it is not merged with the first segment due to the active transaction;
+# the third transaction inserts a new row, splitting the delete segment into 
another two;
+#  however, the two new inserted segments are merged, as they are contiguous 
and the active transactions
+#  cannot read them;
+# the first transaction commits but the segments remain the same since it is 
read-only;
+# the last transaction inserts another row and commits, merging everything 
back into one segment.
+
+@connection(id=1)
+statement ok
+begin transaction
+
+@connection(id=2)
+statement ok
+INSERT INTO TEST VALUES (16);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+4
+
+@connection(id=2)
+statement ok
+INSERT INTO TEST VALUES (17);
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+4
+
+@connection(id=1)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,8,9,10,11,12,13,14,15
+
+@connection(id=2)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,16,17,8,9,10,11,12,13,14,15
+
+@connection(id=1)
+statement ok
+commit
+
+@connection(id=1)
+query I
+SELECT segments FROM sys.deltas('sys', 'test');
+----
+4
+
+@connection(id=1)
+query T
+SELECT listagg(k) FROM test;
+----
+1,2,3,4,16,17,8,9,10,11,12,13,14,15
+
+@connection(id=2)
+statement ok
+INSERT INTO TEST VALUES (18);
+
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to