-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive relationships #348
Comments
Also unfortunately:
UPDATE: I think this is non-sensical though π |
Ok what I was really trying to do was:
Works nicely |
Oh wow, actually this does work if I make the root loop on itself (
|
That's a clever workaround. I suppose it wouldn't hurt to make a utility wrapper command to make this pattern more convenient. Do you have some syntax in mind? By the way, the foreign key syntax is itself a convenience wrapper around inclusion dependencies which have been proven to be able to represent any database constraint. |
I've also been thinking about how to represent n-ary, nested relationships within a relation outside the scope of adjacency lists since we could leverage nested relations. However, the top-level relation type does not seem to be able to represent arbitrarily-nested relation types, so I don't see off-hand how to represent arbitrary levels of nesting. |
Thanks for the feedback π I'll try to think about a syntax for traversing recursive relationships. Datalog might be an inspiration ? I'm very interested in modeling n-ary relations but I don't quite visualise how to do it with a nested relation even for the arity 2 case. Could you give an example? |
Sort of broadening the scope quite a bit here, but I was wondering what are principled approaches to model graphs in a relation database. This seems like a very interesting paper on implementing graph algorithms in RDBMSes using new operations and a while syntax. https://dsl.cds.iisc.ac.in/~course/TIDS/papers/allinone.pdf
|
Thanks for linking to that paper- it proposes new SQL syntax to support said traversals. However, it is still limited by the capabilities of SQL (which Project:M36 is not). For example, Project:M36 supports algebraic data types and relation-valued attributes, both of which can be leveraged to represent graph more effectively. For example, relation-valued attributes would be a great way to query a database to service an ORM. Here's a sample dashboard using the C.J. Date example. This would typically done by an outer join in SQL, but the Project:M36 representation is quite natural:
We could consider some syntax addition to TutorialD which would generate graph traversals using RVAs, but I'm not yet sure what that would look like. |
I encounter this issue too when I want to record tree-like comments. I found an article talking about tree structure in sql (in Chinese). Basically, it says there are four ways to do that: Adjacency List: easiest to implement and understand |
There's actually a more natural way to represent graphs in the relational algebra which I have not seen before. It's not quite possible in Project:M36 because we don't support recursive data types, but it should be possible to support in the future. Here's an example that works today that hints at what could be possible:
If we could define a recursive type for the top-level relation, then we could conceivably enable unlimited levels of nested structures using nested relations. This would allow us, for example, to enable fine-grained constraints on the graph use normal database constraints. This is certainly more natural than adjanceny lists and less error-prone than number range-based graphs structures. |
Hi there π
I'm trying to work with recursive relationships.
It seems to work ok for a depth 1 traversal:
Also if I add an edge:
I can work out a way to do a depth 2 traversal:
Can this be generalised to a depth
n
traversal? Also would it be possible to group the result by depth?Thanks for your time!
Jun
The text was updated successfully, but these errors were encountered: