You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by GitBox <gi...@apache.org> on 2021/11/30 09:24:55 UTC

[GitHub] [incubator-age] pdpotter edited a comment on issue #45: unique properties / indexing

pdpotter edited a comment on issue #45:
URL: https://github.com/apache/incubator-age/issues/45#issuecomment-812524846


   It would indeed be very useful to enable the creation of constraints / indexes. This could help to accelerate the creation of edges between nodes that were added earlier, which slows down a lot when there are a lot of nodes with the same label:
   ```
   SELECT * FROM cypher('graph_name', $$
   MATCH (d:LabelA {id: 1}), (r:LabelB {id: 2})
   CREATE (d)-[:Relation {prop: 'value'}]->(r)
   $$) as (a agtype)
   ```
   
   The `CREATE UNIQUE`, `CREATE CONSTRAINT`, and `CREATE INDEX` clauses / commands [are part of cypher, but not of openCypher](https://github.com/opencypher/openCypher/blob/master/docs/standardisation-scope.adoc#language-features-excluded-from-opencypher), so I don't know what the best approach would be here.
   
   @ehsanonline
   <details>
   <summary>See comment below for an update. Click here to view the original comment content.</summary>
   You can create a unique index, which will prevent the creation of duplicate values, but will not speed up matching, by creating an immutable function that casts to json over text
   
   ```
   CREATE OR REPLACE FUNCTION get_name(properties agtype) 
     RETURNS text
   AS
   $BODY$
       select $1::text::json->>'name';
   $BODY$
   LANGUAGE sql
   IMMUTABLE;
   ```
   
   and using that immutable function in the create index command
   
   ```
   CREATE UNIQUE INDEX person_name_idx ON mygraph.person(get_name(properties)) ;
   ```
   
   </details>
   
   [Link to the mentioned comment below](https://github.com/apache/incubator-age/issues/45#issuecomment-982438807)


-- 
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-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org