Last active
March 13, 2023 04:34
-
-
Save philzook58/b543fc07444fb27bba846b4c4be35a6e to your computer and use it in GitHub Desktop.
Transitive closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE tc(a INTEGER, b INTEGER, PRIMARY KEY (a,b)); | |
INSERT OR IGNORE INTO tc(a,b) | |
VALUES (1,2),(2,3),(3,4); | |
-- repeat this query many times for naive iteration | |
-- path(x,z) :- path(x,y), path(y,z). | |
INSERT OR IGNORE INTO tc SELECT DISTINCT tc0.a, tc1.b -- the head of the rule gives the insert and select fields | |
FROM tc as tc0, tc as tc1 | |
WHERE tc0.b = tc1.a; -- The body of the rule gives FROM and WHERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment