From 350bfdb5ea9b4f7e50746c50a46d8032cbc5a104 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 8 Nov 2017 14:53:26 -0500 Subject: Created database versioning system Also added an ANALYZE statement to the end of the datafile generation process. This generates information that allows sqlite to sometimes come up with a better query plan, and in many cases can significant speed up queries. This constitutes a minor database update, but because this is the first version that uses the database versioning system, older versions are essentially incompatible. refs #2 --- generator/generator.cpp | 23 +++++++++++++++++++++++ generator/generator.h | 4 ++++ generator/schema.sql | 5 +++++ 3 files changed, 32 insertions(+) (limited to 'generator') diff --git a/generator/generator.cpp b/generator/generator.cpp index e125b4a..d774bd9 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -11,6 +11,7 @@ #include "part.h" #include "field.h" #include "../lib/util.h" +#include "../lib/version.h" namespace verbly { namespace generator { @@ -112,6 +113,9 @@ namespace verbly { // Writes the database schema writeSchema(); + // Writes the database version + writeVersion(); + // Dumps data to the database dumpObjects(); @@ -154,6 +158,9 @@ namespace verbly { // Populates the adjective similarity relationship from WordNet readWordNetSimilarity(); + + // Generates analysis data to assist in query planning. + analyzeDatabase(); } void generator::readWordNetSynsets() @@ -581,6 +588,15 @@ namespace verbly { } } + void generator::writeVersion() + { + std::list fields; + fields.emplace_back("major", DATABASE_MAJOR_VERSION); + fields.emplace_back("minor", DATABASE_MINOR_VERSION); + + db_.insertIntoTable("version", std::move(fields)); + } + void generator::dumpObjects() { { @@ -1110,6 +1126,13 @@ namespace verbly { } } + void generator::analyzeDatabase() + { + std::cout << "Analyzing data..." << std::endl; + + db_.runQuery("ANALYZE"); + } + std::list generator::readFile(std::string path) { std::ifstream file(path); diff --git a/generator/generator.h b/generator/generator.h index 43b3272..5458c97 100644 --- a/generator/generator.h +++ b/generator/generator.h @@ -60,6 +60,8 @@ namespace verbly { void writeSchema(); + void writeVersion(); + void dumpObjects(); void readWordNetAntonymy(); @@ -88,6 +90,8 @@ namespace verbly { void readWordNetSimilarity(); + void analyzeDatabase(); + // Helpers std::list readFile(std::string path); diff --git a/generator/schema.sql b/generator/schema.sql index c0f2bcb..d97c06e 100644 --- a/generator/schema.sql +++ b/generator/schema.sql @@ -1,3 +1,8 @@ +CREATE TABLE `version` ( + `major` INTEGER NOT NULL, + `minor` INTEGER NOT NULL +); + CREATE TABLE `notions` ( `notion_id` INTEGER PRIMARY KEY, `part_of_speech` SMALLINT NOT NULL, -- cgit 1.4.1