Efficient Tolog Querying

Currently the query engine performs no optimisation of queries. However as with all query languages it is wise to be aware of how to write an efficient query. This section provides some useful tips on query writing.

Tip

Without clause-ordering optimisation, all predicates in the query are evaluated from left to right. It is most efficient to put those predicates which will narrow down the range of matches quickest at the start of the query - this reduces the amount of processing that the following predicates are required to perform.

Tip

Alternates can be a source of explosion in the size of a query set - be careful when using them.

Tip

This is not so much a tip as a word of warning. A not() clause cannot be evaluated if it contains unbound variables. When reordering clauses for efficiency, be careful to put the not() clause in a position where it will only receive bound variables - the easiest way to check this (although not fool-proof) is to trace backwards from the not() clause for each variable reference it contains. If you find the same variable reference in some predicate to the left of the not() clause, then you are probably OK. However, be careful with alternates (each list of predicates separated by the '|' character should be traced as a separate branch) and also with extension predicates (they may not always bind all of the variables passed in as parameters).