简体   繁体   English

CLP和SQL之间有什么关系?

[英]What is the relationship between CLP and SQL?

In reading up on constraint-logic programming , I can't help but notice an apparent relationship with SQL programming. 在阅读约束逻辑编程时 ,我不禁注意到与SQL编程的明显关系。 Is SQL an example of "constraint logic programming" in action? SQL是否是“约束逻辑编程”的一个例子?

They are very similar from a high level. 从高层次来看它们非常相似。 Both are declarative or set based rather than iterative (meaning you ask for what you want - you don't loop through and process individual items one by one). 两者都是声明性的或基于集合而不是迭代的(意味着你要求你想要的东西 - 你不会逐个循环并逐个处理单个项目)。

CLP can be modeled in SQL but it is a case of finding a better solution to a problem. CLP可以在SQL中建模,但它可以找到更好的问题解决方案。 SQL is good for finding answers in a given data set that is already explicitly defined. SQL适用于在已明确定义的给定数据集中查找答案。 CLP is good for finding answers in domains that are loosely or sometimes even not even completely defined. CLP适用于在松散或有时甚至不完全定义的域中查找答案。

As an example. 举个例子。 If I wanted to to return all the even numbers between 1 and 10 million using SQL I would need a table with all the numbers listed to select from (an existing data set). 如果我想使用SQL返回1到1000万之间的所有偶数,我需要一个包含列出的所有数字的表(现有数据集)。 Using CLP I would just need a bound (10M) but wouldn't have to explicit create all the records. 使用CLP我只需要一个绑定(10M),但不必显式创建所有记录。

Internally CLP engines (CSP problems) can also infer constraints to make them faster. 内部CLP引擎(CSP问题)也可以推断出约束以使它们更快。 SQL you would have to figure out those rules and explicitly state them. SQL你必须弄清楚这些规则并明确说明它们。 For example if your SQL is where A=B and B=C, a CLP engine might figure out that A=C and use that to run faster where SQL would not. 例如,如果您的SQL位于A = B和B = C的位置,则CLP引擎可能会发现A = C并使用它在SQL不能运行的情况下运行得更快。 They can similarly infer domains as well to optimize run time (if I know that the even numbers are never returned a CLP will throw them out from consideration - SQL will still consider them but not return as a "solution"). 他们也可以类似地推断域以优化运行时间(如果我知道永远不会返回偶数,CLP会将它们从考虑中抛出 - SQL仍会考虑它们但不会返回作为“解决方案”)。

Hopefully that helps - I can get more technical if you need it. 希望这会有所帮助 - 如果您需要,我可以获得更多技术。 The key point to remember is the two are similar but which you use depends on the problem model. 要记住的关键点是两者相似但你使用的取决于问题模型。 If you can say "these are my variables, and these are how the interrelate, give me any valid solution" then CLP is a good candidate. 如果你能说“这些是我的变量,这些是相互关联的,给我任何有效的解决方案”,那么CLP是一个很好的候选人。 If you can say "there are my variables, and these are the specifics, give me back a subset of my existing data that fits" then SQL is a better candidate. 如果你可以说“有我的变量,这些是具体的,给我一些适合的现有数据的子集”,那么SQL是一个更好的候选者。

i don't have a full answer, but you might find it interesting to look at Datalog and DLV. 我没有完整的答案,但你会发现看看Datalog和DLV很有意思。 They are perhaps the "missing link" between Logic Programming (but not CLP) and SQL that will help you understand things more clearly. 它们可能是逻辑编程(但不是CLP)与SQL之间的“缺失环节”,它将帮助您更清楚地理解事物。

Since this is more about LP than CLP I may have missed something - if so, sorry. 由于这更多是关于LP而不是CLP,我可能错过了一些东西 - 如果是的话,抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM