WendelLana commented on issue #981: URL: https://github.com/apache/age/issues/981#issuecomment-1597409977
### **Basic node finding** Logic: each vertex and edge will have a unique identifier using the UUID type of Postgres. UUIDs provide a stronger guarantee of uniqueness compared to sequence generators. This eliminates the need for a separate table to store IDs that have been deleted and simplifies the process of transferring data between graphs and databases. **Creating vertices and edges:** Postgres provides a function called gen_random_uuid(), which we can utilize to generate our unique identifiers. We will replace the existing logic with this method. Query: ``` CREATE ()-[]->() ``` Pseudo-code: ``` UUID previous_vertex, next_vertex; FOR EACH node IN path IF node.type == VERTEX AND previous_vertex != next_vertex THEN previous_vertex = create_vertex() //generates UUID calling gen_random_uuid() and creates vertex ELSE IF node.type == EDGE next_vertex = create_vertex() create_edge(previous_vertex, next_vertex) //generates UUID and creates edge previous_vertex = next_vertex ENDIF NEXT node ``` - The loop iterates `n` times - Inside the loop, the operations `create_vertex()` and `create_edge()` have a constant time complexity - Therefore, the overall time complexity of this pseudo code is O(n) **Get all nodes** ``` MATCH (n) RETURN n ``` This query will sequentially scan all vertices. **Get all nodes with a label** ``` MATCH (movie:Movie) RETURN movie.title ``` This query will use an index to efficiently scan vertices with the label "movie". **Related nodes** ``` MATCH (director {name: 'Oliver Stone'})--(movie) RETURN movie.title ``` This query will sequentially scan all vertices, looking for nodes with the property `name` equal to 'Oliver Stone'. It will then scan all edges to find matches where the `start_id` or `end_id` correspond to the previously found nodes. **Match with labels** ``` MATCH (:Person {name: 'Oliver Stone'})--(movie:Movie) RETURN movie.title ``` This query will use the index for "Person" to efficiently find nodes with the name 'Oliver Stone'. Then, it will scan the edges to find connections between those nodes and other vertices. The query ensures that the connected vertices have the label "Movie" by utilizing an index for the "Movie" label. Note: I have prioritized filtering properties such as name when creating the query plan, but it is also possible to explore alternative search approaches. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@age.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org