Skip to content

Commit 4ceaba3

Browse files
committed
Add Doltlite PHPUnit workflow
Run the mysql-on-sqlite PHPUnit suite against Doltlite by building https://github.com/dolthub/doltlite from source and installing its shared library as the libsqlite3 resolved by PHP's pdo_sqlite. Keep the CI-only Doltlite compatibility patches in .github/doltlite-patches, with fast workflow reductions that verify each patched behavior before the full PHPUnit run.
1 parent ef143d3 commit 4ceaba3

5 files changed

Lines changed: 545 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Use current cursor key for auxiliary index deletes
2+
3+
Doltlite's delete path used the cached seek key for BTREE_AUXDELETE even when
4+
that seek key no longer matched the current cursor row. When SQLite deletes a
5+
row through a non-key predicate, secondary index deletes can then target a
6+
stale key and leave the real index entry visible in the transaction. A later
7+
insert or update into the deleted key fails with a false UNIQUE violation.
8+
9+
Trust the cached seek key only when it matches the current cursor state; the
10+
existing fallback paths can derive the key from the current mutmap entry,
11+
cached payload, or tree cursor.
12+
13+
Reproduces deterministically on:
14+
15+
CREATE TABLE s (
16+
a TEXT COLLATE NOCASE,
17+
b TEXT COLLATE NOCASE,
18+
idx TEXT COLLATE NOCASE,
19+
seq INT,
20+
col TEXT COLLATE NOCASE,
21+
PRIMARY KEY (a, b, idx, seq),
22+
UNIQUE (a, b, idx, seq)
23+
) STRICT;
24+
INSERT INTO s VALUES ('sqlite_database', 't', 'u', 1, 'b');
25+
INSERT INTO s VALUES ('sqlite_database', 't', 'u', 2, 'c');
26+
BEGIN IMMEDIATE;
27+
DELETE FROM s WHERE col = 'b';
28+
UPDATE s SET seq = 1 WHERE col = 'c';
29+
30+
diff --git a/src/prolly_btree.c b/src/prolly_btree.c
31+
index 7085abb..9d73876 100644
32+
--- a/src/prolly_btree.c
33+
+++ b/src/prolly_btree.c
34+
@@ -7988,2 +7988 @@ static int prollyBtCursorDelete(BtCursor *pCur, u8 flags){
35+
- if( pCur->nSeekSortKey>0
36+
- && ((flags & BTREE_AUXDELETE) || cachedSeekKeyMatchesCurrent(pCur)) ){
37+
+ if( pCur->nSeekSortKey>0 && cachedSeekKeyMatchesCurrent(pCur) ){
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Strip SQL comments while canonicalizing sqlite_schema SQL
2+
3+
Doltlite canonicalizes schema SQL by collapsing whitespace before storing
4+
sqlite_schema rows after rollback/restore paths. When the SQL contains line
5+
comments, collapsing newlines but keeping `--` makes the comment consume the
6+
rest of the CREATE statement, so SQLite later reports "malformed database
7+
schema ... incomplete input".
8+
9+
Skip line and block comments outside quoted strings during schema SQL
10+
canonicalization. This keeps canonicalized schema text parseable while
11+
preserving the existing whitespace normalization behavior.
12+
13+
Reproduces deterministically on:
14+
15+
CREATE TABLE c (
16+
id INT CHECK (id > 0) -- inline comment
17+
) STRICT;
18+
BEGIN IMMEDIATE;
19+
INSERT INTO c VALUES (0); -- CHECK failure
20+
ROLLBACK;
21+
SELECT * FROM c; -- malformed schema without this fix
22+
23+
diff --git a/src/doltlite_hashof.c b/src/doltlite_hashof.c
24+
index 4682333..ac1297e 100644
25+
--- a/src/doltlite_hashof.c
26+
+++ b/src/doltlite_hashof.c
27+
@@ -257,0 +258,24 @@ char *doltliteCanonicalizeSchemaSql(const char *zSql, const char *zName){
28+
+ if( c=='-' && z[1]=='-' ){
29+
+ z += 2;
30+
+ while( *z && *z!='\n' && *z!='\r' ) z++;
31+
+ pendingSpace = 1;
32+
+ if( *z==0 ){
33+
+ z--;
34+
+ }else if( z[0]=='\r' && z[1]=='\n' ){
35+
+ z++;
36+
+ }
37+
+ continue;
38+
+ }
39+
+ if( c=='/' && z[1]=='*' ){
40+
+ const char *zEnd = z + 2;
41+
+ while( zEnd[0] && !(zEnd[0]=='*' && zEnd[1]=='/') ){
42+
+ zEnd++;
43+
+ }
44+
+ pendingSpace = 1;
45+
+ if( zEnd[0]=='*' ){
46+
+ z = zEnd + 1;
47+
+ }else{
48+
+ z = zEnd - 1;
49+
+ }
50+
+ continue;
51+
+ }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Keep mysql-on-sqlite tables as rowid tables
2+
3+
Doltlite auto-converts ordinary primary-key tables without an integer rowid
4+
to WITHOUT ROWID. mysql-on-sqlite currently relies on rowid access for
5+
table recreation, limited UPDATE/DELETE rewrites, on-update triggers,
6+
zero-column result statements, and information-schema ordering. Keep the
7+
tables in rowid mode for the Doltlite compatibility test run.
8+
9+
--- a/src/build.c
10+
+++ b/src/build.c
11+
@@ -2778,7 +2778,7 @@
12+
&& (p->tabFlags & TF_HasPrimaryKey)!=0
13+
&& p->iPKey<0
14+
&& (tabOpts & TF_WithoutRowid)==0 ){
15+
- tabOpts |= TF_WithoutRowid;
16+
+ /* patched off in CI: keep mysql-on-sqlite tables as rowid tables */ (void)0;
17+
}
18+
-
19+
+
20+
/* Doltlite: dolt_ignore is a user-created system table whose
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Keep mergeScan aligned with mutmap changes
2+
3+
Doltlite merges committed prolly-tree rows with transaction-local mutmap
4+
entries during cursor scans. Two edge cases currently leak stale tree rows:
5+
6+
1) A cursor can be positioned directly at a mutmap INSERT via
7+
setCursorToMutMapEntryPhys(), which jumps mmIdx past earlier mutmap
8+
entries. A later tree emission must still notice a mutmap DELETE for
9+
that same tree key, otherwise SQLite follows a rowid that the mutmap says
10+
is deleted and reports "database disk image is malformed".
11+
12+
2) After emitting a mutmap-only row, the committed tree cursor can still be
13+
parked before the seek prefix used to find that mutmap row. The next scan
14+
step can then emit a committed tree row that does not satisfy the original
15+
prefix constraint.
16+
17+
Fix both cases in mergeScan/mergeStep by checking tree keys against mutmap
18+
DELETE entries and by advancing the tree cursor past the emitted mutmap key.
19+
20+
Reproduces deterministically on:
21+
22+
CREATE TABLE c (ka TEXT, kb TEXT, kc TEXT, v TEXT,
23+
PRIMARY KEY (ka, kb, kc));
24+
INSERT INTO c VALUES ('db','t','a','');
25+
BEGIN IMMEDIATE;
26+
INSERT INTO c VALUES ('db','t','b','');
27+
DELETE FROM c WHERE ka='db' AND kb='t' AND kc='a';
28+
UPDATE c SET v = 'x' WHERE ka='db' AND kb='t'; -- malformed w/o fix
29+
30+
And on:
31+
32+
CREATE TABLE c (ts TEXT NOT NULL COLLATE NOCASE,
33+
tn TEXT NOT NULL COLLATE NOCASE,
34+
cn TEXT NOT NULL COLLATE NOCASE,
35+
ordinal INT NOT NULL,
36+
PRIMARY KEY (ts, tn, cn)) STRICT;
37+
BEGIN IMMEDIATE;
38+
INSERT INTO c VALUES ('sqlite_database', 't1', 'id', 1);
39+
COMMIT;
40+
BEGIN IMMEDIATE;
41+
INSERT INTO c VALUES ('sqlite_database', 't2', 'id', 1);
42+
SELECT tn FROM c WHERE ts = 'sqlite_database' AND tn = 't2';
43+
-- returns t2,t1 without the tree-cursor alignment fix
44+
45+
diff --git a/src/prolly_btree.c b/src/prolly_btree.c
46+
index 7085abb..f9e7d31 100644
47+
--- a/src/prolly_btree.c
48+
+++ b/src/prolly_btree.c
49+
@@ -6026,0 +6027,33 @@ static int mergeCompare(BtCursor *pCur, ProllyMutMapEntry *e){
50+
+static int skipDeletedTreeEntry(BtCursor *pCur, int dir, int *pSkipped){
51+
+ ProllyMutMapEntry *delE = 0;
52+
+ int rc;
53+
+ *pSkipped = 0;
54+
+ if( pCur->curIntKey ){
55+
+ rc = prollyMutMapFindRc(pCur->pMutMap, 0, 0,
56+
+ prollyCursorIntKey(&pCur->pCur), &delE);
57+
+ }else{
58+
+ const u8 *pK; int nK;
59+
+ prollyCursorKey(&pCur->pCur, &pK, &nK);
60+
+ rc = prollyMutMapFindRc(pCur->pMutMap, pK, nK, 0, &delE);
61+
+ }
62+
+ if( rc!=SQLITE_OK ) return rc;
63+
+ if( delE && delE->op==PROLLY_EDIT_DELETE ){
64+
+ rc = advanceTreeCursor(pCur, dir);
65+
+ if( rc!=SQLITE_OK ) return rc;
66+
+ *pSkipped = 1;
67+
+ }
68+
+ return SQLITE_OK;
69+
+}
70+
+
71+
+static int advanceTreePastMutEntry(BtCursor *pCur, ProllyMutMapEntry *e, int dir){
72+
+ int rc;
73+
+ if( !e ) return SQLITE_OK;
74+
+ while( pCur->pCur.eState==PROLLY_CURSOR_VALID ){
75+
+ int cmp = mergeCompare(pCur, e);
76+
+ if( (dir>0 && cmp>0) || (dir<0 && cmp<0) ) break;
77+
+ rc = advanceTreeCursor(pCur, dir);
78+
+ if( rc!=SQLITE_OK ) return rc;
79+
+ }
80+
+ return SQLITE_OK;
81+
+}
82+
+
83+
@@ -6044,0 +6078,4 @@ static int mergeScan(BtCursor *pCur, int dir, int *pRes){
84+
+ int skipped = 0;
85+
+ int rc = skipDeletedTreeEntry(pCur, dir, &skipped);
86+
+ if( rc!=SQLITE_OK ) return rc;
87+
+ if( skipped ) continue;
88+
@@ -6057,0 +6095,11 @@ static int mergeScan(BtCursor *pCur, int dir, int *pRes){
89+
+ /* Tree entry is ahead of mutmap[mmIdx] in scan direction.
90+
+ ** Check whether the mutmap has a DELETE entry for the tree
91+
+ ** key at an order index the iteration has already walked
92+
+ ** past (e.g. after setCursorToMutMapEntryPhys jumped mmIdx
93+
+ ** directly to a later INSERT). Without this check the scan
94+
+ ** would emit a logically-deleted tree row and SQLite would
95+
+ ** later TableMoveto a rowid that mutmap says is gone. */
96+
+ int skipped = 0;
97+
+ int rc = skipDeletedTreeEntry(pCur, dir, &skipped);
98+
+ if( rc!=SQLITE_OK ) return rc;
99+
+ if( skipped ) continue;
100+
@@ -6115 +6163 @@ static int mergeStepForward(BtCursor *pCur){
101+
- if( pCur->mergeSrc==MERGE_SRC_TREE || pCur->mergeSrc==MERGE_SRC_BOTH ){
102+
+ if( pCur->mergeSrc==MERGE_SRC_TREE ){
103+
@@ -6117,0 +6166,8 @@ static int mergeStepForward(BtCursor *pCur){
104+
+ }else if( pCur->mergeSrc==MERGE_SRC_MUT
105+
+ || pCur->mergeSrc==MERGE_SRC_BOTH ){
106+
+ ProllyMutMapEntry *e = 0;
107+
+ if( pCur->mmIdx >= 0 && pCur->mmIdx < pCur->pMutMap->nEntries ){
108+
+ e = orderedMutMapEntryAt(pCur->pMutMap, pCur->mmIdx);
109+
+ }
110+
+ rc = advanceTreePastMutEntry(pCur, e, 1);
111+
+ if( rc!=SQLITE_OK ) return rc;
112+
@@ -6119 +6175 @@ static int mergeStepForward(BtCursor *pCur){
113+
- if( pCur->mergeSrc==MERGE_SRC_MUT || pCur->mergeSrc==MERGE_SRC_BOTH )
114+
+ if( pCur->mergeSrc==MERGE_SRC_MUT || pCur->mergeSrc==MERGE_SRC_BOTH ){
115+
@@ -6120,0 +6177 @@ static int mergeStepForward(BtCursor *pCur){
116+
+ }
117+
@@ -6129 +6186 @@ static int mergeStepBackward(BtCursor *pCur){
118+
- if( pCur->mergeSrc==MERGE_SRC_TREE || pCur->mergeSrc==MERGE_SRC_BOTH ){
119+
+ if( pCur->mergeSrc==MERGE_SRC_TREE ){
120+
@@ -6131,0 +6189,8 @@ static int mergeStepBackward(BtCursor *pCur){
121+
+ }else if( pCur->mergeSrc==MERGE_SRC_MUT
122+
+ || pCur->mergeSrc==MERGE_SRC_BOTH ){
123+
+ ProllyMutMapEntry *e = 0;
124+
+ if( pCur->mmIdx >= 0 && pCur->mmIdx < pCur->pMutMap->nEntries ){
125+
+ e = orderedMutMapEntryAt(pCur->pMutMap, pCur->mmIdx);
126+
+ }
127+
+ rc = advanceTreePastMutEntry(pCur, e, -1);
128+
+ if( rc!=SQLITE_OK ) return rc;
129+
@@ -6133 +6198 @@ static int mergeStepBackward(BtCursor *pCur){
130+
- if( pCur->mergeSrc==MERGE_SRC_MUT || pCur->mergeSrc==MERGE_SRC_BOTH )
131+
+ if( pCur->mergeSrc==MERGE_SRC_MUT || pCur->mergeSrc==MERGE_SRC_BOTH ){
132+
@@ -6134,0 +6200 @@ static int mergeStepBackward(BtCursor *pCur){
133+
+ }

0 commit comments

Comments
 (0)