Legendary
Legendary
ATApache TinkerPop
Created by Legendary on 4/1/2023 in #questions
Isolated vertices vs connected vertices with no join benefit
Is there any downside to storing an isolated vertex with references to other nodes? Creating relationships makes the query more complicated than it needs to be, but storing references to other vertices seems like an anti-pattern/smell. The relationship between nodes is defined as follows:
g.addV('batch').property(id,'batch-a').as('a').
addV('batch').property(id,'batch-b')as('b').
addV('reusable').property(id, 123).as('r1').
addV('reusable').property(id, 123).as('r2').
addE('link').from('a').to('r').
addE('link').from('b').to('r2').iterate()
g.addV('batch').property(id,'batch-a').as('a').
addV('batch').property(id,'batch-b')as('b').
addV('reusable').property(id, 123).as('r1').
addV('reusable').property(id, 123).as('r2').
addE('link').from('a').to('r').
addE('link').from('b').to('r2').iterate()
g.addV('connected').property('property", 'abc').as('coonected-v).addE('relates_to_batch').from('connected-a).to('batch-a').addE('related_to_reusable').from('connected-a').to('r1).iterate()
g.addV('connected').property('property", 'abc').as('coonected-v).addE('relates_to_batch').from('connected-a).to('batch-a').addE('related_to_reusable').from('connected-a').to('r1).iterate()
Querying this looks like:
g.V('batch-a').project('batchId', 'reusableId', 'connected').by(T.id).by(__.in('relates_to_batch').out("relates_to_reusable").id()).by(__.in("relates_to_batch").elementMap().fold()).toList()
g.V('batch-a').project('batchId', 'reusableId', 'connected').by(T.id).by(__.in('relates_to_batch').out("relates_to_reusable").id()).by(__.in("relates_to_batch").elementMap().fold()).toList()
With an isolated vertex:
g.addV('isoalted').property('property", 'abc').property('batchId', 'batch-a').property('reusableId', 'r2).iterate()
g.addV('isoalted').property('property", 'abc').property('batchId', 'batch-a').property('reusableId', 'r2).iterate()
Querying in this way produces the same result:
g.V().hasLabel('isolated').has('batchId', 'batch-a').elementMap().toList()
g.V().hasLabel('isolated').has('batchId', 'batch-a').elementMap().toList()
Please let me know if this doesn't make sense
34 replies