postgreSQL as deductive DBMS

Started by Dmitriy Letuchyover 20 years ago3 messages
#1Dmitriy Letuchy
dm.l@mail.ru

Hello all,

I have some ideas how to increase expressive power of the PostgreSQL query language. It is not a secret that SQL is very poor to express many important queries, and we have to use means of procedural extensions of SQL to realize them. However this is not good idea to split query language into two parts (declarative and procedural) at least because query language must finally operate with the objects of data domain, not with the bits the objects consist of. Thus another alternative to increase expressive power of query language is to develop its declarative (i.e. nonprocedural) part. And here we come to deductive database (DDB) with its logic language Datalog.
Every logic query is a set of inverse implications, which describe what to find (i.e. exactly declarative approach) and not how to find (i.e. exactly procedural approach). We can translate logic query into set of SQL commands and then run them to get result. Some samples with the DLQ compiler can be downloaded from www.datalab.kharkov.ua (DLQ is our original version of Datalog which was developed with the purpose to tie closely RDB and DDB).
Now some words about what must be done to realize described feature. The simple quickest way but the way without future is to write language handler. Other more correct way is to slightly extend DML part of SQL and more essentially extend DDL. For example, we have relation Inheritance with two attributes ClassID and ParentID. Now we want to define all descendants or all ancestors. For this goal we define predicate inheritance_all with the next two rules (i.e. inverse implications):

inheritance_all(ClassID, ParentID) :- inheritance(ClassID, ParentID);
inheritance_all(ClassID, ParentID) :- inheritance(ClassID, X),
inheritance_all(X, ParentID).

We put this rules into database and call, for example, the next SQL commands:

-- find all descendents
SELECT * FROM ddb_name.inheritance_all(_, _)

-- find all descendents from ParentID = 1
SELECT * FROM ddb_name.inheritance_all(_, 1)

where ddb_name is the name of deductive database where our rules are kept, _" designates anonymous variable (see Prolog notation for details).

Regards, Dmitriy

#2Michael Meskes
meskes@postgresql.org
In reply to: Dmitriy Letuchy (#1)
Re: postgreSQL as deductive DBMS

Having written my thesis about deductive DBS I cannot resist giving my 2
cent.

On Mon, May 16, 2005 at 01:42:24PM +0400, Dmitriy Letuchy wrote:

Now some words about what must be done to realize described feature. The simple quickest way but the way without future is to write language handler. Other more correct way is to slightly extend DML part of SQL and more essentially extend DDL. For example, we have relation Inheritance with two attributes ClassID and ParentID. Now we want to define all descendants or all ancestors. For this goal we define predicate inheritance_all with the next two rules (i.e. inverse implications):

inheritance_all(ClassID, ParentID) :- inheritance(ClassID, ParentID);
inheritance_all(ClassID, ParentID) :- inheritance(ClassID, X),
inheritance_all(X, ParentID).

We put this rules into database and call, for example, the next SQL commands:

-- find all descendents
SELECT * FROM ddb_name.inheritance_all(_, _)

How do you plan to execute this statement. As you mentioned above all
logic queries can be rewritten into SQL ones, but you have to find a way
to handle recursion. I would think the best way is to add recursion to
SQL and then completely rewrite the statements.

Also, and that's where it starts to become interesting, how do you plan
to handle negation inside recursion?

Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!

#3Josh Berkus
josh@agliodbs.com
In reply to: Dmitriy Letuchy (#1)
Re: postgreSQL as deductive DBMS

Dimitry,

Thus another alternative to increase expressive power of query language is
to develop its declarative (i.e. nonprocedural) part. And here we come to
deductive database (DDB) with its logic language Datalog.

You may want to look at the work of Rada Chirkova, who has already written a
PostgreSQL-parse-tree-to-DataLog converter:
http://research.csc.ncsu.edu/selftune/Report_031005.pdf

--
Josh Berkus
Aglio Database Solutions
San Francisco