How similar are relational database languages ​​and logic programming?

What are the similarities and differences in terms of fundamental concepts and implementations between the relational database language sql and the logical programming language such as prolog and clojure core.logic ? Are these two interchangeable?

+7
source share
3 answers

Similarities are recorded in the Datalog query language. Here is motivation and the best explanation of the relationship between logic and databases. In this excerpt you should ask your question:

However, the relationship between Prolog and relational databases shows some dissonance. The facts and rules in the Prolog are organized in a general manner and the semantics of the Prolog program depend on this order. In contrast, relationships in the database are considered unordered sets of tuples and the query result is independent of any physical order. Processing Prolog programs is tuple oriented, while relational databases are oriented. The prologue offers procedural functions, such as the slice predicate, which allows the programmer to control the output. The evaluation procedure of the Prolog program is predetermined, while the expressions in relational terms are purely declarative , and the actual evaluation is left to the query processor, which can modify the query for optimization purposes. query optimization is critical to the success of relational databases. The procedural nature of the Prolog engine leaves the burden of optimization with the programmer.

+3
source

An important difference is that SQL is just Turing in its entirety with some pretty crazy tricks that were not possible before ANSI SQL 99. Prolog terminates Turing and is therefore a general-purpose programming language.

+4
source

Although SQL and Prolog demonstrate first-order logical concepts, none of them are a complete version of the predicate calculus .

Prolog and other logical programming languages ​​are highly dependent on recursion, both for defining data structures and for predicates.

SQL itself does not allow recursion, and the introduction of stored procedures is performed with restrictions on the depth of nesting of such calls. For example. SQL Server 2000 until 2012 allows a maximum of 32 nested calls .

In relational databases, “relationships” are repeated as tables (or more flexibly, as representations). The most similar aspect of Prolog is the dynamic facts, which in some implementations (SWI, Amzi) allow indexing of performance, very similar to indexing relational tables for performance in SQL.

Although SQL RDBMSs are designed to work with large amounts of data efficiently than the Prolog implementation usually requires, Prolog can at least be used to prototype both the database and aspects of the system design process.

See here for the 2005 thesis , which explores the expansion of relational databases using Prolog output.

+2
source

All Articles