Does it scan every _row_ or not, though? That’s what matters here.
Does it scan every row or not, though? That’s what matters here.
*. I’m not at a computer but try it with D1 (or libsql) so you can see the row counts. Time isn’t accurate.foreign key mismatch - "new_Post" referencing "User" on D1. Any help, please?USER table, even before it gets modified. Something like the below should work:PRAGMA foreign_keys=off is a no-op (per SQLite spec). The defer works, as you can see.
var batch_arr = [];
const delete_r = env.DB.prepare("DELETE FROM table");
batch_arr.push(delete_r);
const stmt = env.DB.prepare("INSERT INTO table (n, v) VALUES (?1, ?2)");
for(var i = 0; i < 100; i++) {
batch_arr.push(stmt.bind( i, 'str' ));
}
const batch = await env.DB.batch(batch_arr);SELECT * FROM <table> query against a table with 4 rows from the D1 dashboard console.speed.cloudflare.com. I'm in Melb, Aus.
0:28bfd358ee-8478-4a08-a37d-75dcabbf231bCREATE TABLE "Post" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"authorId" INTEGER,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Post" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"authorId" INTEGER,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("uid") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_Post" ("authorId", "id") SELECT "authorId", "id" FROM "Post";
DROP TABLE "Post";
ALTER TABLE "new_Post" RENAME TO "Post";
CREATE TABLE "new_User" (
"uid" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);
DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;PRAGMA defer_foreign_keys = on;
CREATE TABLE "new_User" (
"uid" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);
DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";
CREATE TABLE "new_Post" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"authorId" INTEGER,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("uid") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_Post" ("authorId", "id") SELECT "authorId", "id" FROM "Post";
DROP TABLE "Post";
ALTER TABLE "new_Post" RENAME TO "Post";
PRAGMA defer_foreign_keys = off;var batch_arr = [];
const delete_r = env.DB.prepare("DELETE FROM table");
batch_arr.push(delete_r);
const stmt = env.DB.prepare("INSERT INTO table (n, v) VALUES (?1, ?2)");
for(var i = 0; i < 100; i++) {
batch_arr.push(stmt.bind( i, 'str' ));
}
const batch = await env.DB.batch(batch_arr);