Efficient way to query the root verticies (nodes) of a graph? #5795
Unanswered
ActuallyHappening
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Could a query such as SELECT *, ->parent->thing AS parents, <-parent<-thing AS children FROM thing:4rmjxi39gbewv98kx6qd; be a possible solution for your requirements? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Root nodes meaning nodes that don’t have parents |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The data I want to map: I have a table of
thing
s, that is the primary data of my project. I want these things to have some way of expressing they have parents (plural), which are otherthing
s. Initially I added a field to thething
table like this:parents: set<record<thing>>
, which works fine.But then for some reason I tried using graph relations, my requirements haven't changed. I created a relations table
parents
which had both itsin
andout
parameters with a type ofthing
. Now I'm writing this, I realise maybe continuing without a graph table would potentially be better, because I need to define a few functions:Efficient access of root nodes
So far, using the graph implementation, I've come up with this working function:
Usage:
Example output:
The problem with this query is that, to my knowledge, it has to linearly scan + collect all of the parents relational table then perform another superlinear array/set comparison compared to the sizes of the
thing
andparent
tables.Efficient access of child and parent nodes
Also, I want given a specific ID of a
thing
record e.g.thing:4rmjxi39gbewv98kx6qd
to be able to list its children's IDs and parent IDs, ideally that scales well with lots ofthing
andparent
recordsThe question
Is such a solution possible with the graph feature of
surrealdb
? SurrealDB is the first databasing solution I've used to construct my own schemas, so I don't even have a reference frame compared to other database implementations.I'm assuming this sort of problem is solvable with some clever
DEFINE INDEX
, but before I prematurely optimize (which is the root of all evil ofc) I wanted to ask the community before commiting to the graph/relational pathBeta Was this translation helpful? Give feedback.
All reactions