Storing Multiple Independent Tress

I want to store multiple independent trees(there is no relation between those trees). I think to generate and assign a unique label to every independent tree. Then every query will have a filter using those labels. So if there are 10,000 trees, I would have to generate 10,000 different labels. Is there a better solution like a multi-graph or something else available?

In Neo4J 4.0 multi graph (multi db) feature is available. You can create a db for each graph and store the corresponding graph in that db.

Depending on your queries you could still keep all your trees in the same database. You may not even need labels.

You could use properties instead, ensuring that all nodes of a tree had the same tree or treeId property or similar. That would be useful for creating a composite index, which would be like a regular index on a property you'd want to look up, but also include the treeId, ensuring you're looking up the node from the relevant tree.

From there it's just traversal within your tree, and if there's nothing connecting the trees together (or at least if there are certain relationship types that connect them that you could filter out in your query) there shouldn't be any way to cross into another tree by mistake.

1 Like

@andrew_bowman, Thanks for the information.

I want to store only BOM trees in neo4j. Suppose there are 10^5 BOM trees where every tree has 10^5 nodes in it, so in total there are 10^10 nodes.

Case 1: Assign a unique label to every tree. So to get a node with node Id 100 from 2 different trees, my query would be:
"MATCH(n : label1 { nodeId: 100} ) return n"
"MATCH(n : label2 { nodeId: 100} ) return n"

Case 2: Assign a common label to every node and add a property tree id. So to get a node with node Id 100 from 2 different trees, my query would be:
"MATCH(n : bomNode { nodeId: 100, treeId: 1 } ) return n"
"MATCH(n : bomNode { nodeId: 100, treeId: 2 } ) return n"

Which one is better in terms of time complexity and why?

Later I would fire a query to get the whole tree. Can you please comment on which case from above 2 should be chosen? Please suggest if you have some better design