Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only load PSO and POS permutations and NO patterns #476

Merged
merged 5 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/ServerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct option options[] = {
{"no-patterns", no_argument, NULL, 'P'},
{"no-pattern-trick", no_argument, NULL, 'T'},
{"text", no_argument, NULL, 't'},
{"only-pso-and-pos-permutations", no_argument, NULL, 'o'},
{NULL, 0, NULL, 0}};

void printUsage(char* execName) {
Expand Down Expand Up @@ -88,6 +89,9 @@ void printUsage(char* execName) {
<< "Enables the usage of text." << endl;
cout << " " << std::setw(20) << "j, worker-threads" << std::setw(1) << " "
<< "Sets the number of worker threads to use" << endl;
cout << " " << std::setw(20) << "o, only-pos-and-pso-permutations"
<< std::setw(1) << " "
<< "Only load PSO and POS permutations" << endl;
cout.copyfmt(coutState);
}

Expand All @@ -108,13 +112,14 @@ int main(int argc, char** argv) {
int numThreads = 1;
bool usePatterns = true;
bool enablePatternTrick = true;
bool loadAllPermutations = true;

size_t memLimit = DEFAULT_MEM_FOR_QUERIES_IN_GB;

optind = 1;
// Process command line arguments.
while (true) {
int c = getopt_long(argc, argv, "i:p:j:tauhm:lc:e:k:T", options, NULL);
int c = getopt_long(argc, argv, "i:p:j:tauhm:lc:e:k:TPo", options, NULL);
if (c == -1) break;
switch (c) {
case 'i':
Expand Down Expand Up @@ -156,6 +161,9 @@ int main(int argc, char** argv) {
case 'k':
RuntimeParameters().set<"cache-max-num-entries">(atoi(optarg));
break;
case 'o':
loadAllPermutations = false;
break;
default:
cout << endl
<< "! ERROR in processing options (getopt returned '" << c
Expand Down Expand Up @@ -186,6 +194,7 @@ int main(int argc, char** argv) {

try {
Server server(port, numThreads, memLimit);
server.index().setLoadAllPermutations(loadAllPermutations);
server.run(index, text, usePatterns, enablePatternTrick);
} catch (const std::exception& e) {
// This code should never be reached as all exceptions should be handled
Expand Down
9 changes: 9 additions & 0 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,14 @@ vector<QueryPlanner::SubtreePlan> QueryPlanner::seedWithScansAndText(
}
// Simple iris can be resolved directly.
if (node._triple._p._operation == PropertyPath::Operation::IRI) {
if (_qec && !_qec->getIndex().hasAllPermutations() &&
isVariable(node._triple._p._iri)) {
AD_THROW(ad_semsearch::Exception::BAD_QUERY,
"The query contains a predicate variable, but only the PSO "
"and POS permutations were loaded. Rerun the server without "
"the option --only-pso-and-pos-permutations and if "
"necessary also rebuild the index.");
}
if (node._variables.size() == 1) {
// Just pick one direction, they should be equivalent.
SubtreePlan plan(_qec);
Expand Down Expand Up @@ -1239,6 +1247,7 @@ vector<QueryPlanner::SubtreePlan> QueryPlanner::seedWithScansAndText(
auto scan = std::make_shared<IndexScan>(
_qec, IndexScan::ScanType::PSO_FREE_S);
scan->setSubject(node._triple._s);

scan->setPredicate(node._triple._p._iri);
scan->setObject(filterVar);
scan->precomputeSizeEstimate();
Expand Down
3 changes: 3 additions & 0 deletions src/engine/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Server {
void run(const string& ontologyBaseName, bool useText,
bool usePatterns = true, bool usePatternTrick = true);

Index& index() { return _index; }
const Index& index() const { return _index; }

private:
const int _numThreads;
int _port;
Expand Down
5 changes: 5 additions & 0 deletions src/index/CompressedRelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ template <class Permutation, typename IdTableImpl>
void CompressedRelationMetaData::scan(
Id col0Id, IdTableImpl* result, const Permutation& permutation,
ad_utility::SharedConcurrentTimeoutTimer timer) {
if (!permutation._isLoaded) {
throw std::runtime_error("This query requires the permutation " +
permutation._readableName +
", which was not loaded");
}
if constexpr (!ad_utility::isVector<IdTableImpl>) {
AD_CHECK(result->cols() == 2);
}
Expand Down
22 changes: 18 additions & 4 deletions src/index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,19 @@ void Index::createFromOnDiskIndex(const string& onDiskBase) {
LOG(INFO) << "total vocab size is " << _totalVocabularySize << std::endl;
_PSO.loadFromDisk(_onDiskBase);
_POS.loadFromDisk(_onDiskBase);
_OPS.loadFromDisk(_onDiskBase);
_OSP.loadFromDisk(_onDiskBase);
_SPO.loadFromDisk(_onDiskBase);
_SOP.loadFromDisk(_onDiskBase);

if (_loadAllPermutations) {
_OPS.loadFromDisk(_onDiskBase);
_OSP.loadFromDisk(_onDiskBase);
_SPO.loadFromDisk(_onDiskBase);
_SOP.loadFromDisk(_onDiskBase);
} else {
LOG(INFO)
<< "Only the PSO and POS permutation were loaded. Queries that contain "
"predicate variables will therefore not work on this QLever "
"instance."
<< std::endl;
}

if (_usePatterns) {
// Read the pattern info from the patterns file
Expand Down Expand Up @@ -1160,6 +1169,11 @@ void Index::setKeepTempFiles(bool keepTempFiles) {
// _____________________________________________________________________________
void Index::setUsePatterns(bool usePatterns) { _usePatterns = usePatterns; }

// _____________________________________________________________________________
void Index::setLoadAllPermutations(bool loadAllPermutations) {
_loadAllPermutations = loadAllPermutations;
}

// ____________________________________________________________________________
void Index::setSettingsFile(const std::string& filename) {
_settingsFileName = filename;
Expand Down
7 changes: 6 additions & 1 deletion src/index/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ class Index {

void setUsePatterns(bool usePatterns);

void setLoadAllPermutations(bool loadAllPermutations);

void setOnDiskLiterals(bool onDiskLiterals);

void setKeepTempFiles(bool keepTempFiles);
Expand Down Expand Up @@ -316,7 +318,7 @@ class Index {

size_t getNofPredicates() const { return _PSO.metaData().getNofDistinctC1(); }

bool hasAllPermutations() const { return SPO()._file.isOpen(); }
bool hasAllPermutations() const { return SPO()._isLoaded; }

// _____________________________________________________________________________
template <class PermutationImpl>
Expand Down Expand Up @@ -438,6 +440,9 @@ class Index {
off_t _currentoff_t;
mutable ad_utility::File _textIndexFile;

// If false, only PSO and POS permutations are loaded and expected.
bool _loadAllPermutations = true;

// Pattern trick data
static const uint32_t PATTERNS_FILE_VERSION;
bool _usePatterns;
Expand Down
3 changes: 3 additions & 0 deletions src/index/Permutations.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PermutationImpl {
_meta.readFromFile(&_file);
LOG(INFO) << "Registered " << _readableName
<< " permutation: " << _meta.statistics() << std::endl;
_isLoaded = true;
}

// _______________________________________________________
Expand All @@ -68,6 +69,8 @@ class PermutationImpl {
MetaData _meta;

mutable ad_utility::File _file;

bool _isLoaded = false;
};

// Type aliases for the 6 permutations used by QLever
Expand Down