Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/include/souffle/io/WriteStreamSQLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,31 @@ class WriteStreamSQLite : public WriteStream {
void createRelationTable() {
std::stringstream createTableText;
createTableText << "CREATE TABLE IF NOT EXISTS '_" << relationName << "' (";
// 8 bytes per datum worst case + 1 byte per datum in header + 1 byte header length < ~1/20 DB page
// (4096 bytes) size See https://sqlite.org/withoutrowid.html#when_to_use_without_rowid and
// https://sqlite.org/fileformat2.html#record_format for justification
// 22*9+1 = 199 < 200
bool shouldUseWithoutRowid = (arity > 0 && arity < 23);
if (arity > 0) {
createTableText << "'0' INTEGER";
for (unsigned int i = 1; i < arity; i++) {
createTableText << ",'" << std::to_string(i) << "' ";
createTableText << "INTEGER";
}
if (shouldUseWithoutRowid) {
createTableText << ", PRIMARY KEY (";
createTableText << "'0'";
for (unsigned int i = 1; i < arity; i++) {
createTableText << ",'" << std::to_string(i) << "' ";
}
createTableText << ")";
}
}
if (shouldUseWithoutRowid) {
createTableText << ") WITHOUT ROWID;";
} else {
createTableText << ");";
}
createTableText << ");";
executeSQL(createTableText.str(), db);
executeSQL("DELETE FROM '_" + relationName + "';", db);
}
Expand Down