79493015

Date: 2025-03-07 17:19:16
Score: 1
Natty:
Report link

Good question, Raj!

You can define a "virtual" edge by reusing the existing node table `Interest`. This technique is recommended by us at the user guide: https://cloud.google.com/spanner/docs/graph/best-practices-designing-schema#merging-node-and-edge-input-tables

CREATE PROPERTY GRAPH TestGraph
NODE TABLES (
  InterestCategory,
  Interest,
)
EDGE TABLES (
  Interest AS ContainsInterest
    SOURCE KEY (interest_category_id) REFERENCES InterestCategory
    DESTINATION KEY (interest_id) REFERENCES Interest
)

Query will appear as

GRAPH TestGraph
MATCH p = (n:InterestCategory)-[:ContainsInterest]->(b:Interest)
RETURN TO_JSON(p) as interest_paths;

Given that the two tables have FK reference constraint and shares the prefix key, you can employ INTERLEAVE IN PARENT technique to optimize the schema design, as we recommended here in the user guide: https://cloud.google.com/spanner/docs/graph/best-practices-designing-schema#optimize-forward-edge-traversal

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Charlie Qian