diff --git a/core/translate/insert.rs b/core/translate/insert.rs index 28a9a64e6d8..d31d38728a3 100644 --- a/core/translate/insert.rs +++ b/core/translate/insert.rs @@ -712,6 +712,11 @@ pub fn translate_insert( connection, table_references: &mut table_references, }; + // NOT NULL default substitution must happen before index key registers are + // copied in preflight constraint checks. Otherwise the index entry gets NULL + // while the table row gets the default value, causing integrity_check failures. + emit_notnulls(program, &ctx, &insertion, resolver)?; + emit_preflight_constraint_checks( program, &mut ctx, @@ -721,8 +726,6 @@ pub fn translate_insert( &mut preflight_ctx, )?; - emit_notnulls(program, &ctx, &insertion, resolver)?; - // Create and insert the record let affinity_str = insertion .col_mappings diff --git a/testing/runner/tests/insert_not_null_default_index.sqltest b/testing/runner/tests/insert_not_null_default_index.sqltest new file mode 100644 index 00000000000..d9c952f1549 --- /dev/null +++ b/testing/runner/tests/insert_not_null_default_index.sqltest @@ -0,0 +1,79 @@ +@database :memory: + +# Regression test: INSERT OR REPLACE with a NOT NULL DEFAULT column and a +# secondary UNIQUE index. When a column expression evaluates to NULL at +# runtime (e.g. expr + NULL), the NOT NULL default substitution must happen +# BEFORE index key registers are copied, otherwise the index entry gets NULL +# while the table row gets the default value → integrity_check fails. + +setup schema { + CREATE TABLE t (a INTEGER PRIMARY KEY, b INTEGER, c INTEGER NOT NULL DEFAULT 0, d INTEGER CHECK (d > 0)); + CREATE UNIQUE INDEX idx ON t (b DESC, c, d DESC); +} + +@setup schema +@cross-check-integrity +test insert-or-replace-null-expr-not-null-default { + INSERT OR REPLACE INTO t (a, b, c, d) VALUES (1, NULL, 1892229699219097912 + -NULL, 100); + PRAGMA integrity_check; +} +expect { + ok +} + +@setup schema +@cross-check-integrity +test insert-or-replace-null-expr-select-back { + INSERT OR REPLACE INTO t (a, b, c, d) VALUES (1, NULL, 1892229699219097912 + -NULL, 100); + SELECT a, b, c, d FROM t; +} +expect { + 1||0|100 +} + +@setup schema +@cross-check-integrity +test insert-or-replace-null-expr-not-null-default-text { + CREATE TABLE t2 (id INTEGER PRIMARY KEY, x TEXT NOT NULL DEFAULT 'fallback', y INTEGER); + CREATE UNIQUE INDEX idx2 ON t2 (x, y); + INSERT OR REPLACE INTO t2 (id, x, y) VALUES (1, NULL || NULL, 42); + PRAGMA integrity_check; +} +expect { + ok +} + +@setup schema +@cross-check-integrity +test insert-or-replace-null-expr-not-null-default-text-select { + CREATE TABLE t2 (id INTEGER PRIMARY KEY, x TEXT NOT NULL DEFAULT 'fallback', y INTEGER); + CREATE UNIQUE INDEX idx2 ON t2 (x, y); + INSERT OR REPLACE INTO t2 (id, x, y) VALUES (1, NULL || NULL, 42); + SELECT id, x, y FROM t2; +} +expect { + 1|fallback|42 +} + +@setup schema +@cross-check-integrity +test insert-not-null-default-middle-column-index { + INSERT OR REPLACE INTO t (a, b, c, d) VALUES (1, 5, NULL, 10); + INSERT OR REPLACE INTO t (a, b, c, d) VALUES (2, 6, 0 * NULL, 20); + PRAGMA integrity_check; +} +expect { + ok +} + +@setup schema +@cross-check-integrity +test insert-not-null-default-middle-column-select { + INSERT OR REPLACE INTO t (a, b, c, d) VALUES (1, 5, NULL, 10); + INSERT OR REPLACE INTO t (a, b, c, d) VALUES (2, 6, 0 * NULL, 20); + SELECT a, b, c, d FROM t ORDER BY a; +} +expect { + 1|5|0|10 + 2|6|0|20 +} diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-multiple-rows.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-multiple-rows.snap index 1fc5656c1e1..90f855f1322 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-multiple-rows.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-multiple-rows.snap @@ -55,12 +55,12 @@ addr opcode p1 p2 p3 p4 p5 comment 33 Goto 0 35 0 0 34 NewRowid 1 8 0 0 r[8]=rowid 35 Affinity 9 5 0 0 r[9..14] = D, B, E, D, B - 36 NotExists 1 38 8 0 - 37 Halt 1555 0 0 products.id 0 - 38 Copy 13 15 0 0 r[15]=r[13] - 39 Copy 8 16 0 0 r[16]=r[8] - 40 HaltIfNull 1299 0 10 products.name 0 - 41 HaltIfNull 1299 0 11 products.price 0 + 36 HaltIfNull 1299 0 10 products.name 0 + 37 HaltIfNull 1299 0 11 products.price 0 + 38 NotExists 1 40 8 0 + 39 Halt 1555 0 0 products.id 0 + 40 Copy 13 15 0 0 r[15]=r[13] + 41 Copy 8 16 0 0 r[16]=r[8] 42 MakeRecord 9 5 14 0 r[14]=mkrec(r[9..13]) 43 Copy 13 17 0 0 r[17]=r[13] 44 Copy 8 18 0 0 r[18]=r[8] diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-abort-multi-unique.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-abort-multi-unique.snap index 3594ec06c29..91ce3059c9c 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-abort-multi-unique.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-abort-multi-unique.snap @@ -29,20 +29,20 @@ addr opcode p1 p2 p3 p4 p5 comment 12 Goto 0 14 0 0 13 NewRowid 2 2 0 0 r[2]=rowid 14 Affinity 3 4 0 0 r[3..7] = D, B, B, B - 15 NotExists 2 17 2 0 - 16 Halt 1555 0 0 items.id 0 - 17 Copy 5 8 0 0 r[8]=r[5] - 18 Copy 2 9 0 0 r[9]=r[2] - 19 Affinity 8 1 0 0 r[8..9] = B - 20 NoConflict 0 22 8 1 0 key=r[8..8] - 21 Halt 2067 0 0 items.barcode 0 - 22 Copy 4 10 0 0 r[10]=r[4] - 23 Copy 2 11 0 0 r[11]=r[2] - 24 Affinity 10 1 0 0 r[10..11] = B - 25 NoConflict 1 27 10 1 0 key=r[10..10] - 26 Halt 2067 0 0 items.sku 0 - 27 HaltIfNull 1299 0 4 items.sku 0 - 28 HaltIfNull 1299 0 5 items.barcode 0 + 15 HaltIfNull 1299 0 4 items.sku 0 + 16 HaltIfNull 1299 0 5 items.barcode 0 + 17 NotExists 2 19 2 0 + 18 Halt 1555 0 0 items.id 0 + 19 Copy 5 8 0 0 r[8]=r[5] + 20 Copy 2 9 0 0 r[9]=r[2] + 21 Affinity 8 1 0 0 r[8..9] = B + 22 NoConflict 0 24 8 1 0 key=r[8..8] + 23 Halt 2067 0 0 items.barcode 0 + 24 Copy 4 10 0 0 r[10]=r[4] + 25 Copy 2 11 0 0 r[11]=r[2] + 26 Affinity 10 1 0 0 r[10..11] = B + 27 NoConflict 1 29 10 1 0 key=r[10..10] + 28 Halt 2067 0 0 items.sku 0 29 MakeRecord 3 4 7 0 r[7]=mkrec(r[3..6]) 30 Copy 5 12 0 0 r[12]=r[5] 31 Copy 2 13 0 0 r[13]=r[2] diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-fail-multi-unique.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-fail-multi-unique.snap index 369b38c681b..9f5934caa06 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-fail-multi-unique.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-fail-multi-unique.snap @@ -29,20 +29,20 @@ addr opcode p1 p2 p3 p4 p5 comment 12 Goto 0 14 0 0 13 NewRowid 2 2 0 0 r[2]=rowid 14 Affinity 3 4 0 0 r[3..7] = D, B, B, B - 15 NotExists 2 17 2 0 - 16 Halt 1555 0 0 items.id 0 - 17 Copy 5 8 0 0 r[8]=r[5] - 18 Copy 2 9 0 0 r[9]=r[2] - 19 Affinity 8 1 0 0 r[8..9] = B - 20 NoConflict 0 22 8 1 0 key=r[8..8] - 21 Halt 2067 0 0 items.barcode 0 - 22 Copy 4 10 0 0 r[10]=r[4] - 23 Copy 2 11 0 0 r[11]=r[2] - 24 Affinity 10 1 0 0 r[10..11] = B - 25 NoConflict 1 27 10 1 0 key=r[10..10] - 26 Halt 2067 0 0 items.sku 0 - 27 HaltIfNull 1299 0 4 items.sku 0 - 28 HaltIfNull 1299 0 5 items.barcode 0 + 15 HaltIfNull 1299 0 4 items.sku 0 + 16 HaltIfNull 1299 0 5 items.barcode 0 + 17 NotExists 2 19 2 0 + 18 Halt 1555 0 0 items.id 0 + 19 Copy 5 8 0 0 r[8]=r[5] + 20 Copy 2 9 0 0 r[9]=r[2] + 21 Affinity 8 1 0 0 r[8..9] = B + 22 NoConflict 0 24 8 1 0 key=r[8..8] + 23 Halt 2067 0 0 items.barcode 0 + 24 Copy 4 10 0 0 r[10]=r[4] + 25 Copy 2 11 0 0 r[11]=r[2] + 26 Affinity 10 1 0 0 r[10..11] = B + 27 NoConflict 1 29 10 1 0 key=r[10..10] + 28 Halt 2067 0 0 items.sku 0 29 MakeRecord 3 4 7 0 r[7]=mkrec(r[3..6]) 30 Copy 5 12 0 0 r[12]=r[5] 31 Copy 2 13 0 0 r[13]=r[2] diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore-multi-unique.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore-multi-unique.snap index fc1c6a14c1d..8d6763d9c0a 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore-multi-unique.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore-multi-unique.snap @@ -29,23 +29,23 @@ addr opcode p1 p2 p3 p4 p5 comment 12 Goto 0 14 0 0 13 NewRowid 2 2 0 0 r[2]=rowid 14 Affinity 3 4 0 0 r[3..7] = D, B, B, B - 15 NotExists 2 18 2 0 - 16 Copy 2 1 0 0 r[1]=r[2] - 17 Goto 0 43 0 0 - 18 Copy 5 8 0 0 r[8]=r[5] - 19 Copy 2 9 0 0 r[9]=r[2] - 20 Affinity 8 1 0 0 r[8..9] = B - 21 NoConflict 0 24 8 1 0 key=r[8..8] - 22 Goto 0 44 0 0 - 23 Halt 2067 0 0 items.barcode 0 - 24 Copy 4 10 0 0 r[10]=r[4] - 25 Copy 2 11 0 0 r[11]=r[2] - 26 Affinity 10 1 0 0 r[10..11] = B - 27 NoConflict 1 30 10 1 0 key=r[10..10] - 28 Goto 0 44 0 0 - 29 Halt 2067 0 0 items.sku 0 - 30 IsNull 4 44 0 0 if (r[4]==NULL) goto 44 - 31 IsNull 5 44 0 0 if (r[5]==NULL) goto 44 + 15 IsNull 4 44 0 0 if (r[4]==NULL) goto 44 + 16 IsNull 5 44 0 0 if (r[5]==NULL) goto 44 + 17 NotExists 2 20 2 0 + 18 Copy 2 1 0 0 r[1]=r[2] + 19 Goto 0 43 0 0 + 20 Copy 5 8 0 0 r[8]=r[5] + 21 Copy 2 9 0 0 r[9]=r[2] + 22 Affinity 8 1 0 0 r[8..9] = B + 23 NoConflict 0 26 8 1 0 key=r[8..8] + 24 Goto 0 44 0 0 + 25 Halt 2067 0 0 items.barcode 0 + 26 Copy 4 10 0 0 r[10]=r[4] + 27 Copy 2 11 0 0 r[11]=r[2] + 28 Affinity 10 1 0 0 r[10..11] = B + 29 NoConflict 1 32 10 1 0 key=r[10..10] + 30 Goto 0 44 0 0 + 31 Halt 2067 0 0 items.sku 0 32 MakeRecord 3 4 7 0 r[7]=mkrec(r[3..6]) 33 Copy 5 12 0 0 r[12]=r[5] 34 Copy 2 13 0 0 r[13]=r[2] diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore.snap index 79f97cbc53a..b0cd1f51157 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-ignore.snap @@ -28,17 +28,17 @@ addr opcode p1 p2 p3 p4 p5 comment 11 Goto 0 13 0 0 12 NewRowid 1 2 0 0 r[2]=rowid 13 Affinity 3 4 0 0 r[3..7] = D, B, B, B - 14 NotExists 1 17 2 0 - 15 Copy 2 1 0 0 r[1]=r[2] - 16 Goto 0 32 0 0 - 17 Copy 4 8 0 0 r[8]=r[4] - 18 Copy 2 9 0 0 r[9]=r[2] - 19 Affinity 8 1 0 0 r[8..9] = B - 20 NoConflict 0 23 8 1 0 key=r[8..8] - 21 Goto 0 33 0 0 - 22 Halt 2067 0 0 users.email 0 - 23 IsNull 4 33 0 0 if (r[4]==NULL) goto 33 - 24 IsNull 5 33 0 0 if (r[5]==NULL) goto 33 + 14 IsNull 4 33 0 0 if (r[4]==NULL) goto 33 + 15 IsNull 5 33 0 0 if (r[5]==NULL) goto 33 + 16 NotExists 1 19 2 0 + 17 Copy 2 1 0 0 r[1]=r[2] + 18 Goto 0 32 0 0 + 19 Copy 4 8 0 0 r[8]=r[4] + 20 Copy 2 9 0 0 r[9]=r[2] + 21 Affinity 8 1 0 0 r[8..9] = B + 22 NoConflict 0 25 8 1 0 key=r[8..8] + 23 Goto 0 33 0 0 + 24 Halt 2067 0 0 users.email 0 25 MakeRecord 3 4 7 0 r[7]=mkrec(r[3..6]) 26 Copy 4 10 0 0 r[10]=r[4] 27 Copy 2 11 0 0 r[11]=r[2] diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default-partial.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default-partial.snap index df4b0ca5bd7..13a674b4c2e 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default-partial.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default-partial.snap @@ -23,17 +23,17 @@ addr opcode p1 p2 p3 p4 p5 comment 8 Goto 0 10 0 0 9 NewRowid 0 2 0 0 r[2]=rowid 10 Affinity 3 3 0 0 r[3..6] = D, D, B - 11 NotExists 0 16 2 0 - 12 Copy 2 1 0 0 r[1]=r[2] - 13 SeekRowid 0 1 26 0 if (r[1]!=cursor 0 for table t_defaults.rowid) goto 26 - 14 Delete 0 0 0 t_defaults 0 - 15 Goto 0 16 0 0 - 16 NotNull 4 18 0 0 r[4]!=NULL -> goto 18 - 17 Integer 42 4 0 0 r[4]=42 - 18 HaltIfNull 1299 0 4 t_defaults.val 0 - 19 NotNull 5 21 0 0 r[5]!=NULL -> goto 21 - 20 String8 0 5 0 unnamed 0 r[5]='unnamed' - 21 HaltIfNull 1299 0 5 t_defaults.name 0 + 11 NotNull 4 13 0 0 r[4]!=NULL -> goto 13 + 12 Integer 42 4 0 0 r[4]=42 + 13 HaltIfNull 1299 0 4 t_defaults.val 0 + 14 NotNull 5 16 0 0 r[5]!=NULL -> goto 16 + 15 String8 0 5 0 unnamed 0 r[5]='unnamed' + 16 HaltIfNull 1299 0 5 t_defaults.name 0 + 17 NotExists 0 22 2 0 + 18 Copy 2 1 0 0 r[1]=r[2] + 19 SeekRowid 0 1 26 0 if (r[1]!=cursor 0 for table t_defaults.rowid) goto 26 + 20 Delete 0 0 0 t_defaults 0 + 21 Goto 0 22 0 0 22 MakeRecord 3 3 6 0 r[6]=mkrec(r[3..5]) 23 Insert 0 6 2 t_defaults 2 intkey=r[2] data=r[6] 24 Goto 0 25 0 0 diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default.snap index 889cc46a67e..344aafdea32 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-notnull-default.snap @@ -24,17 +24,17 @@ addr opcode p1 p2 p3 p4 p5 comment 9 Goto 0 11 0 0 10 NewRowid 0 2 0 0 r[2]=rowid 11 Affinity 3 3 0 0 r[3..6] = D, D, B - 12 NotExists 0 17 2 0 - 13 Copy 2 1 0 0 r[1]=r[2] - 14 SeekRowid 0 1 27 0 if (r[1]!=cursor 0 for table t_defaults.rowid) goto 27 - 15 Delete 0 0 0 t_defaults 0 - 16 Goto 0 17 0 0 - 17 NotNull 4 19 0 0 r[4]!=NULL -> goto 19 - 18 Integer 42 4 0 0 r[4]=42 - 19 HaltIfNull 1299 0 4 t_defaults.val 0 - 20 NotNull 5 22 0 0 r[5]!=NULL -> goto 22 - 21 String8 0 5 0 unnamed 0 r[5]='unnamed' - 22 HaltIfNull 1299 0 5 t_defaults.name 0 + 12 NotNull 4 14 0 0 r[4]!=NULL -> goto 14 + 13 Integer 42 4 0 0 r[4]=42 + 14 HaltIfNull 1299 0 4 t_defaults.val 0 + 15 NotNull 5 17 0 0 r[5]!=NULL -> goto 17 + 16 String8 0 5 0 unnamed 0 r[5]='unnamed' + 17 HaltIfNull 1299 0 5 t_defaults.name 0 + 18 NotExists 0 23 2 0 + 19 Copy 2 1 0 0 r[1]=r[2] + 20 SeekRowid 0 1 27 0 if (r[1]!=cursor 0 for table t_defaults.rowid) goto 27 + 21 Delete 0 0 0 t_defaults 0 + 22 Goto 0 23 0 0 23 MakeRecord 3 3 6 0 r[6]=mkrec(r[3..5]) 24 Insert 0 6 2 t_defaults 2 intkey=r[2] data=r[6] 25 Goto 0 26 0 0 diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-unique.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-unique.snap index 789be3fa149..5ffe26d15ea 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-unique.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace-multi-unique.snap @@ -29,51 +29,51 @@ addr opcode p1 p2 p3 p4 p5 comment 12 Goto 0 14 0 0 13 NewRowid 2 2 0 0 r[2]=rowid 14 Affinity 3 4 0 0 r[3..7] = D, B, B, B - 15 NotExists 2 26 2 0 - 16 Copy 2 1 0 0 r[1]=r[2] - 17 SeekRowid 2 1 64 0 if (r[1]!=cursor 2 for table items.rowid) goto 64 - 18 Column 2 2 8 0 r[8]=items.barcode - 19 Copy 1 9 0 0 r[9]=r[1] - 20 IdxDelete 0 8 2 1 - 21 Column 2 1 10 0 r[10]=items.sku - 22 Copy 1 11 0 0 r[11]=r[1] - 23 IdxDelete 1 10 2 1 - 24 Delete 2 0 0 items 0 - 25 Goto 0 26 0 0 - 26 Copy 5 12 0 0 r[12]=r[5] - 27 Copy 2 13 0 0 r[13]=r[2] - 28 Affinity 12 1 0 0 r[12..13] = B - 29 NoConflict 0 40 12 1 0 key=r[12..12] - 30 IdxRowId 0 1 0 0 r[1]=cursor 0.rowid - 31 SeekRowid 2 1 64 0 if (r[1]!=cursor 2 for table items.rowid) goto 64 - 32 Column 2 2 14 0 r[14]=items.barcode - 33 Copy 1 15 0 0 r[15]=r[1] - 34 IdxDelete 0 14 2 1 - 35 Column 2 1 16 0 r[16]=items.sku - 36 Copy 1 17 0 0 r[17]=r[1] - 37 IdxDelete 1 16 2 1 - 38 Delete 2 0 0 items 0 - 39 Goto 0 40 0 0 - 40 MakeRecord 12 2 18 0 r[18]=mkrec(r[12..13]); for sqlite_autoindex_items_2 - 41 IdxInsert 0 18 12 2 key=r[18] - 42 Copy 4 19 0 0 r[19]=r[4] - 43 Copy 2 20 0 0 r[20]=r[2] - 44 Affinity 19 1 0 0 r[19..20] = B - 45 NoConflict 1 56 19 1 0 key=r[19..19] - 46 IdxRowId 1 1 0 0 r[1]=cursor 1.rowid - 47 SeekRowid 2 1 64 0 if (r[1]!=cursor 2 for table items.rowid) goto 64 - 48 Column 2 2 21 0 r[21]=items.barcode - 49 Copy 1 22 0 0 r[22]=r[1] - 50 IdxDelete 0 21 2 1 - 51 Column 2 1 23 0 r[23]=items.sku - 52 Copy 1 24 0 0 r[24]=r[1] - 53 IdxDelete 1 23 2 1 - 54 Delete 2 0 0 items 0 - 55 Goto 0 56 0 0 - 56 MakeRecord 19 2 25 0 r[25]=mkrec(r[19..20]); for sqlite_autoindex_items_1 - 57 IdxInsert 1 25 19 2 key=r[25] - 58 HaltIfNull 1299 0 4 items.sku 0 - 59 HaltIfNull 1299 0 5 items.barcode 0 + 15 HaltIfNull 1299 0 4 items.sku 0 + 16 HaltIfNull 1299 0 5 items.barcode 0 + 17 NotExists 2 28 2 0 + 18 Copy 2 1 0 0 r[1]=r[2] + 19 SeekRowid 2 1 64 0 if (r[1]!=cursor 2 for table items.rowid) goto 64 + 20 Column 2 2 8 0 r[8]=items.barcode + 21 Copy 1 9 0 0 r[9]=r[1] + 22 IdxDelete 0 8 2 1 + 23 Column 2 1 10 0 r[10]=items.sku + 24 Copy 1 11 0 0 r[11]=r[1] + 25 IdxDelete 1 10 2 1 + 26 Delete 2 0 0 items 0 + 27 Goto 0 28 0 0 + 28 Copy 5 12 0 0 r[12]=r[5] + 29 Copy 2 13 0 0 r[13]=r[2] + 30 Affinity 12 1 0 0 r[12..13] = B + 31 NoConflict 0 42 12 1 0 key=r[12..12] + 32 IdxRowId 0 1 0 0 r[1]=cursor 0.rowid + 33 SeekRowid 2 1 64 0 if (r[1]!=cursor 2 for table items.rowid) goto 64 + 34 Column 2 2 14 0 r[14]=items.barcode + 35 Copy 1 15 0 0 r[15]=r[1] + 36 IdxDelete 0 14 2 1 + 37 Column 2 1 16 0 r[16]=items.sku + 38 Copy 1 17 0 0 r[17]=r[1] + 39 IdxDelete 1 16 2 1 + 40 Delete 2 0 0 items 0 + 41 Goto 0 42 0 0 + 42 MakeRecord 12 2 18 0 r[18]=mkrec(r[12..13]); for sqlite_autoindex_items_2 + 43 IdxInsert 0 18 12 2 key=r[18] + 44 Copy 4 19 0 0 r[19]=r[4] + 45 Copy 2 20 0 0 r[20]=r[2] + 46 Affinity 19 1 0 0 r[19..20] = B + 47 NoConflict 1 58 19 1 0 key=r[19..19] + 48 IdxRowId 1 1 0 0 r[1]=cursor 1.rowid + 49 SeekRowid 2 1 64 0 if (r[1]!=cursor 2 for table items.rowid) goto 64 + 50 Column 2 2 21 0 r[21]=items.barcode + 51 Copy 1 22 0 0 r[22]=r[1] + 52 IdxDelete 0 21 2 1 + 53 Column 2 1 23 0 r[23]=items.sku + 54 Copy 1 24 0 0 r[24]=r[1] + 55 IdxDelete 1 23 2 1 + 56 Delete 2 0 0 items 0 + 57 Goto 0 58 0 0 + 58 MakeRecord 19 2 25 0 r[25]=mkrec(r[19..20]); for sqlite_autoindex_items_1 + 59 IdxInsert 1 25 19 2 key=r[25] 60 MakeRecord 3 4 7 0 r[7]=mkrec(r[3..6]) 61 Insert 2 7 2 items 2 intkey=r[2] data=r[7] 62 Goto 0 63 0 0 diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace.snap index ee05682efb2..2c3cf42b3a0 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-replace.snap @@ -28,29 +28,29 @@ addr opcode p1 p2 p3 p4 p5 comment 11 Goto 0 13 0 0 12 NewRowid 1 2 0 0 r[2]=rowid 13 Affinity 3 4 0 0 r[3..7] = D, B, B, B - 14 NotExists 1 22 2 0 - 15 Copy 2 1 0 0 r[1]=r[2] - 16 SeekRowid 1 1 41 0 if (r[1]!=cursor 1 for table users.rowid) goto 41 - 17 Column 1 1 8 0 r[8]=users.email - 18 Copy 1 9 0 0 r[9]=r[1] - 19 IdxDelete 0 8 2 1 - 20 Delete 1 0 0 users 0 - 21 Goto 0 22 0 0 - 22 Copy 4 10 0 0 r[10]=r[4] - 23 Copy 2 11 0 0 r[11]=r[2] - 24 Affinity 10 1 0 0 r[10..11] = B - 25 NoConflict 0 33 10 1 0 key=r[10..10] - 26 IdxRowId 0 1 0 0 r[1]=cursor 0.rowid - 27 SeekRowid 1 1 41 0 if (r[1]!=cursor 1 for table users.rowid) goto 41 - 28 Column 1 1 12 0 r[12]=users.email - 29 Copy 1 13 0 0 r[13]=r[1] - 30 IdxDelete 0 12 2 1 - 31 Delete 1 0 0 users 0 - 32 Goto 0 33 0 0 - 33 MakeRecord 10 2 14 0 r[14]=mkrec(r[10..11]); for sqlite_autoindex_users_1 - 34 IdxInsert 0 14 10 2 key=r[14] - 35 HaltIfNull 1299 0 4 users.email 0 - 36 HaltIfNull 1299 0 5 users.name 0 + 14 HaltIfNull 1299 0 4 users.email 0 + 15 HaltIfNull 1299 0 5 users.name 0 + 16 NotExists 1 24 2 0 + 17 Copy 2 1 0 0 r[1]=r[2] + 18 SeekRowid 1 1 41 0 if (r[1]!=cursor 1 for table users.rowid) goto 41 + 19 Column 1 1 8 0 r[8]=users.email + 20 Copy 1 9 0 0 r[9]=r[1] + 21 IdxDelete 0 8 2 1 + 22 Delete 1 0 0 users 0 + 23 Goto 0 24 0 0 + 24 Copy 4 10 0 0 r[10]=r[4] + 25 Copy 2 11 0 0 r[11]=r[2] + 26 Affinity 10 1 0 0 r[10..11] = B + 27 NoConflict 0 35 10 1 0 key=r[10..10] + 28 IdxRowId 0 1 0 0 r[1]=cursor 0.rowid + 29 SeekRowid 1 1 41 0 if (r[1]!=cursor 1 for table users.rowid) goto 41 + 30 Column 1 1 12 0 r[12]=users.email + 31 Copy 1 13 0 0 r[13]=r[1] + 32 IdxDelete 0 12 2 1 + 33 Delete 1 0 0 users 0 + 34 Goto 0 35 0 0 + 35 MakeRecord 10 2 14 0 r[14]=mkrec(r[10..11]); for sqlite_autoindex_users_1 + 36 IdxInsert 0 14 10 2 key=r[14] 37 MakeRecord 3 4 7 0 r[7]=mkrec(r[3..6]) 38 Insert 1 7 2 users 2 intkey=r[2] data=r[7] 39 Goto 0 40 0 0 diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-rollback-multi-unique.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-rollback-multi-unique.snap index c05cc73ea5a..b7034b9fc28 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-rollback-multi-unique.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-or-rollback-multi-unique.snap @@ -29,20 +29,20 @@ addr opcode p1 p2 p3 p4 p5 comment 12 Goto 0 14 0 0 13 NewRowid 2 2 0 0 r[2]=rowid 14 Affinity 3 4 0 0 r[3..7] = D, B, B, B - 15 NotExists 2 17 2 0 - 16 Halt 1555 0 0 items.id 0 - 17 Copy 5 8 0 0 r[8]=r[5] - 18 Copy 2 9 0 0 r[9]=r[2] - 19 Affinity 8 1 0 0 r[8..9] = B - 20 NoConflict 0 22 8 1 0 key=r[8..8] - 21 Halt 2067 0 0 items.barcode 0 - 22 Copy 4 10 0 0 r[10]=r[4] - 23 Copy 2 11 0 0 r[11]=r[2] - 24 Affinity 10 1 0 0 r[10..11] = B - 25 NoConflict 1 27 10 1 0 key=r[10..10] - 26 Halt 2067 0 0 items.sku 0 - 27 HaltIfNull 1299 0 4 items.sku 0 - 28 HaltIfNull 1299 0 5 items.barcode 0 + 15 HaltIfNull 1299 0 4 items.sku 0 + 16 HaltIfNull 1299 0 5 items.barcode 0 + 17 NotExists 2 19 2 0 + 18 Halt 1555 0 0 items.id 0 + 19 Copy 5 8 0 0 r[8]=r[5] + 20 Copy 2 9 0 0 r[9]=r[2] + 21 Affinity 8 1 0 0 r[8..9] = B + 22 NoConflict 0 24 8 1 0 key=r[8..8] + 23 Halt 2067 0 0 items.barcode 0 + 24 Copy 4 10 0 0 r[10]=r[4] + 25 Copy 2 11 0 0 r[11]=r[2] + 26 Affinity 10 1 0 0 r[10..11] = B + 27 NoConflict 1 29 10 1 0 key=r[10..10] + 28 Halt 2067 0 0 items.sku 0 29 MakeRecord 3 4 7 0 r[7]=mkrec(r[3..6]) 30 Copy 5 12 0 0 r[12]=r[5] 31 Copy 2 13 0 0 r[13]=r[2] diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-select.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-select.snap index f27041bcd4b..f521b58051b 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-select.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-select.snap @@ -49,12 +49,12 @@ addr opcode p1 p2 p3 p4 p5 comment 27 Goto 0 29 0 0 28 NewRowid 1 11 0 0 r[11]=rowid 29 Affinity 12 6 0 0 r[12..18] = D, D, D, D, E, B - 30 NotExists 1 32 11 0 - 31 Halt 1555 0 0 order_archive.id 0 - 32 HaltIfNull 1299 0 13 order_archive.user_id 0 - 33 HaltIfNull 1299 0 14 order_archive.product_id 0 - 34 HaltIfNull 1299 0 15 order_archive.quantity 0 - 35 HaltIfNull 1299 0 16 order_archive.total_price 0 + 30 HaltIfNull 1299 0 13 order_archive.user_id 0 + 31 HaltIfNull 1299 0 14 order_archive.product_id 0 + 32 HaltIfNull 1299 0 15 order_archive.quantity 0 + 33 HaltIfNull 1299 0 16 order_archive.total_price 0 + 34 NotExists 1 36 11 0 + 35 Halt 1555 0 0 order_archive.id 0 36 MakeRecord 12 6 18 0 r[18]=mkrec(r[12..17]) 37 Insert 1 18 11 order_archive 0 intkey=r[11] data=r[18] 38 Goto 0 39 0 0 diff --git a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-single-row.snap b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-single-row.snap index 9383f4a0a68..db5f67401bb 100644 --- a/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-single-row.snap +++ b/testing/runner/tests/snapshot_tests/modifications/snapshots/modifications__insert-single-row.snap @@ -31,12 +31,12 @@ addr opcode p1 p2 p3 p4 p5 comment 12 Goto 0 14 0 0 13 NewRowid 1 2 0 0 r[2]=rowid 14 Affinity 3 5 0 0 r[3..8] = D, B, E, D, B - 15 NotExists 1 17 2 0 - 16 Halt 1555 0 0 products.id 0 - 17 Copy 7 9 0 0 r[9]=r[7] - 18 Copy 2 10 0 0 r[10]=r[2] - 19 HaltIfNull 1299 0 4 products.name 0 - 20 HaltIfNull 1299 0 5 products.price 0 + 15 HaltIfNull 1299 0 4 products.name 0 + 16 HaltIfNull 1299 0 5 products.price 0 + 17 NotExists 1 19 2 0 + 18 Halt 1555 0 0 products.id 0 + 19 Copy 7 9 0 0 r[9]=r[7] + 20 Copy 2 10 0 0 r[10]=r[2] 21 MakeRecord 3 5 8 0 r[8]=mkrec(r[3..7]) 22 Copy 7 11 0 0 r[11]=r[7] 23 Copy 2 12 0 0 r[12]=r[2]