* Assign an integer id to every row in the ValidPaths table in order
to make the Refs table more space-efficient. For instance, this reduces the size of the database on my laptop from 93 MiB to 18 MiB. (It was 72 MiB with the old schema on an ext3 disk with a 1 KiB block size.)
This commit is contained in:
parent
c1a07f9445
commit
dbddac0fe9
2 changed files with 25 additions and 14 deletions
|
@ -1230,6 +1230,8 @@ void LocalStore::upgradeStore6()
|
||||||
if (sqlite3_exec(db, "begin;", 0, 0, 0) != SQLITE_OK)
|
if (sqlite3_exec(db, "begin;", 0, 0, 0) != SQLITE_OK)
|
||||||
throw SQLiteError(db, "running `begin' command");
|
throw SQLiteError(db, "running `begin' command");
|
||||||
|
|
||||||
|
std::map<Path, sqlite3_int64> pathToId;
|
||||||
|
|
||||||
foreach (PathSet::iterator, i, validPaths) {
|
foreach (PathSet::iterator, i, validPaths) {
|
||||||
ValidPathInfo info = queryPathInfo(*i, true);
|
ValidPathInfo info = queryPathInfo(*i, true);
|
||||||
|
|
||||||
|
@ -1245,12 +1247,24 @@ void LocalStore::upgradeStore6()
|
||||||
if (sqlite3_step(registerStmt) != SQLITE_DONE)
|
if (sqlite3_step(registerStmt) != SQLITE_DONE)
|
||||||
throw SQLiteError(db, "registering valid path in database");
|
throw SQLiteError(db, "registering valid path in database");
|
||||||
|
|
||||||
|
pathToId[*i] = sqlite3_last_insert_rowid(db);
|
||||||
|
|
||||||
|
std::cerr << ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "|";
|
||||||
|
|
||||||
|
foreach (PathSet::iterator, i, validPaths) {
|
||||||
|
ValidPathInfo info = queryPathInfo(*i, true);
|
||||||
|
|
||||||
foreach (PathSet::iterator, j, info.references) {
|
foreach (PathSet::iterator, j, info.references) {
|
||||||
if (sqlite3_reset(addRefStmt) != SQLITE_OK)
|
if (sqlite3_reset(addRefStmt) != SQLITE_OK)
|
||||||
throw SQLiteError(db, "resetting statement");
|
throw SQLiteError(db, "resetting statement");
|
||||||
if (sqlite3_bind_text(addRefStmt, 1, i->c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK)
|
if (sqlite3_bind_int(addRefStmt, 1, pathToId[*i]) != SQLITE_OK)
|
||||||
throw SQLiteError(db, "binding argument 1");
|
throw SQLiteError(db, "binding argument 1");
|
||||||
if (sqlite3_bind_text(addRefStmt, 2, j->c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK)
|
if (pathToId.find(*j) == pathToId.end())
|
||||||
|
throw Error(format("path `%1%' referenced by `%2%' is invalid") % *j % *i);
|
||||||
|
if (sqlite3_bind_int(addRefStmt, 2, pathToId[*j]) != SQLITE_OK)
|
||||||
throw SQLiteError(db, "binding argument 2");
|
throw SQLiteError(db, "binding argument 2");
|
||||||
if (sqlite3_step(addRefStmt) != SQLITE_DONE)
|
if (sqlite3_step(addRefStmt) != SQLITE_DONE)
|
||||||
throw SQLiteError(db, "adding reference to database");
|
throw SQLiteError(db, "adding reference to database");
|
||||||
|
|
|
@ -1,27 +1,24 @@
|
||||||
pragma foreign_keys = on;
|
pragma foreign_keys = on;
|
||||||
|
|
||||||
create table if not exists ValidPaths (
|
create table if not exists ValidPaths (
|
||||||
path text primary key not null,
|
id integer primary key autoincrement not null,
|
||||||
|
path text unique not null,
|
||||||
hash text not null,
|
hash text not null,
|
||||||
registrationTime integer not null
|
registrationTime integer not null
|
||||||
);
|
);
|
||||||
|
|
||||||
create table if not exists Refs (
|
create table if not exists Refs (
|
||||||
referrer text not null,
|
referrer integer not null,
|
||||||
reference text not null,
|
reference integer not null,
|
||||||
primary key (referrer, reference),
|
primary key (referrer, reference),
|
||||||
foreign key (referrer) references ValidPaths(path)
|
foreign key (referrer) references ValidPaths(id) on delete cascade,
|
||||||
on delete cascade
|
foreign key (reference) references ValidPaths(id) on delete restrict
|
||||||
deferrable initially deferred,
|
|
||||||
foreign key (reference) references ValidPaths(path)
|
|
||||||
on delete restrict
|
|
||||||
deferrable initially deferred
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create index if not exists IndexReferrer on Refs(referrer);
|
||||||
|
create index if not exists IndexReference on Refs(reference);
|
||||||
|
|
||||||
create table if not exists FailedDerivations (
|
create table if not exists FailedDerivations (
|
||||||
path text primary key not null,
|
path text primary key not null,
|
||||||
time integer not null
|
time integer not null
|
||||||
);
|
);
|
||||||
|
|
||||||
create index IndexReferrer on Refs(referrer);
|
|
||||||
create index IndexReference on Refs(reference);
|
|
||||||
|
|
Loading…
Reference in a new issue