diff options
author | Théophane Hufschmitt <regnat@users.noreply.github.com> | 2021-12-14 09:08:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-14 09:08:17 +0100 |
commit | 3fc8042f77d488d3ebc9b3aefb3c54cec38fa432 (patch) | |
tree | 4ccdd4ee9a765eee358180549d57e55a72a0a009 /src | |
parent | bcd4d2e4c6c8ec03ec8cf5d3558975c9152314d5 (diff) | |
parent | edfc5b2f127bfbaebbd48fcd7b35034345ce2cfa (diff) |
Merge pull request #5366 from trofi/speedup-ca-query
ca-specific-schema.sql: add index on RealisationsRefs(referrer)
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/ca-specific-schema.sql | 5 | ||||
-rw-r--r-- | src/libstore/local-store.cc | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/libstore/ca-specific-schema.sql b/src/libstore/ca-specific-schema.sql index 08af0cc1f..64cc97fde 100644 --- a/src/libstore/ca-specific-schema.sql +++ b/src/libstore/ca-specific-schema.sql @@ -19,3 +19,8 @@ create table if not exists RealisationsRefs ( foreign key (referrer) references Realisations(id) on delete cascade, foreign key (realisationReference) references Realisations(id) on delete restrict ); + +-- used by QueryRealisationReferences +create index if not exists IndexRealisationsRefs on RealisationsRefs(referrer); +-- used by cascade deletion when ValidPaths is deleted +create index if not exists IndexRealisationsRefsOnOutputPath on Realisations(outputPath); diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 79011b522..1b8e77ead 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -80,7 +80,7 @@ int getSchema(Path schemaPath) void migrateCASchema(SQLite& db, Path schemaPath, AutoCloseFD& lockFd) { - const int nixCASchemaVersion = 2; + const int nixCASchemaVersion = 3; int curCASchema = getSchema(schemaPath); if (curCASchema != nixCASchemaVersion) { if (curCASchema > nixCASchemaVersion) { @@ -131,6 +131,17 @@ void migrateCASchema(SQLite& db, Path schemaPath, AutoCloseFD& lockFd) txn.commit(); } + if (curCASchema < 3) { + SQLiteTxn txn(db); + // Apply new indices added in this schema update. + db.exec(R"( + -- used by QueryRealisationReferences + create index if not exists IndexRealisationsRefs on RealisationsRefs(referrer); + -- used by cascade deletion when ValidPaths is deleted + create index if not exists IndexRealisationsRefsOnOutputPath on Realisations(outputPath); + )"); + txn.commit(); + } writeFile(schemaPath, fmt("%d", nixCASchemaVersion)); lockFile(lockFd.get(), ltRead, true); } |