Skip to content

Implicit database constraints

juliencorman edited this page Aug 8, 2017 · 5 revisions

valid for Ontop Version 1

Background

Primary and foreign keys are of paramount importance for ontop to generate fast sql. The lack of primary keys can lead to "self-joins" which may render the sql queries impossible to execute in the given constraints of memory and time. The best solution to this is usually to have primary keys in all tables and add all foreign keys. In some situations this may not be possible. Acknowledging these issues, ontop allows the user to supply a list of primary and foreign keys in the initialization of quest.

Only provide correct keys

Although these keys are not in the metadata of the database, these must of course still be correct primary and foreign keys, in the abstract sense: primary keys must be unique and non-null, and foreign keys must refer to existing values in a key column. Ontop does not check that the user-provided keys are correct. The correctness of the algorithms behind ontop depends on only correct keys being provided. Wrong keys may lead to wrong and lacking answers to queries. If you are unsure whether column c in table t is a key, compare the answers to select count(*) from t and select count(distinct c) from t.

File format

The keys are listed in a plain-text file. Each line describes a primary or foreign key. Lines describing a primary key starts with the table name, a colon, and then a comma-separated list of the columns in the key. The lines describing foreign keys start the same way as primary keys, and then after a colon, the target of the constraint is described in the same colon- and comma-separated way. An example:

TABLE1:COL1

TABLE1:COL2,COL3:TABLE2:COL1:COL2

COL1 is a key of TABLE1, while COL2 and COL3 are a combined foreign key referring to COL1 and COL2 of TABLE 2.

Usage in Protege

When using the protege plugin, just provide the file above with the same prefix as the ontology, and suffix db_prefs. For example, if your ontology file is ontology.owl, put the constraints in the file ontology.db_prefs in the same folder.

Usage in the owl-api

The name of such a text file is given as input to the constructor of UserConstraints. The resulting object is passed to the method setUserConstraints of the QuestOWLFactory. And thats all.

For example, assuming factory is an initialized object of type QuestOWLFactory:

ImplicitDBConstraints constr = new ImplicitDBConstraints(<name of file containing user-supplied constraints>);

factory.setImplicitDBConstraints(constr);

Usage in the sesame-api

For use with SeseameVirtualRepo, just pass the ImplicitDBConstraints object to the method setImplicitDBConstraints method before calling initialize, for example:

`SesameVirtualRepo repo = new SesameVirtualRepo(repoName, owlfile, r2rmlFile, configFile);

ImplicitDBConstraints constr = new ImplicitDBConstraints(<name of file containing user-supplied constraints>);

repo.setImplicitDBConstraints(constr); repo.initialize(); repo.getQuestConnection()

Clone this wiki locally