meta

The meta module provides a set of procedures for generating metadata about the database.

TraitValue
Module typeutil
ImplementationC++
Parallelismparallel

Procedures

stats_online()

The procedure retrieves the graph metadata in O(1) complexity. In order for it to work correctly, you need to set up a trigger by running the following query:

CREATE TRIGGER meta_trigger BEFORE COMMIT 
EXECUTE CALL meta.update(createdObjects, deletedObjects, removedVertexProperties, removedEdgeProperties, setVertexLabels, removedVertexLabels);

The stats_online procedure tracks the created, deleted or modified data after the trigger is added. If you want to return the metadata about the whole graph you need to run the procedure with the update_stats flag set to true, but only once. That flag will cause the procedure to traverse the whole graph to update the metadata. After that run, you can run the procedure with the update_stats flag set to false and the procedure will return the metadata in O(1) complexity.

Input:

  • update_stats: bool (default=false) ➡ If true, the procedure traverses the whole graph to update the metadata. Otherwise, it returns the stored metadata.

Output:

  • labelCount: int ➡ The number of unique labels in nodes.
  • relationshipTypeCount: int ➡ The number of unique relationship types (labels).
  • nodeCount: int ➡ The number of nodes in the graph.
  • relationshipCount: int ➡ The number of relationships in the graph.
  • labels: Map[string: int] ➡ A map with the following (key, value) pairs:
    • label : number_of_occurrences
  • relationshipTypes: Map[string: int] ➡ A map with the following (key, value) pairs:
    • (:label)-[:relationship_type]->() : number_of_occurrences
    • ()-[:relationship_type]->(:label) : number_of_occurrences
    • ()-[:relationship_type]->() : number_of_occurrences
  • relationshipTypesCount: Map[string: int] ➡ A map with the following (key, value) pairs:
    • relationship_type : number_of_occurrences
  • stats ➡ A map which contains all of the above.

Usage:

Create the following objects in the database:

MERGE (a:Node {id: 0}) MERGE (b:Node {id: 1}) CREATE (a)-[:Relation1]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 2}) CREATE (a)-[:Relation1]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 0}) CREATE (a)-[:Relation1]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 3}) CREATE (a)-[:Relation2]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 4}) CREATE (a)-[:Relation2]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 5}) CREATE (a)-[:Relation2]->(b);

Run stats using the following query:

CALL meta.stats_online() YIELD stats;
+-------------------------------------------------------+
|     stats                                             |
+-------------------------------------------------------+
|                                                       |
|{                                                      |
|   "labelCount": 1,                                    |
|   "labels": {                                         |
|      "Node": 6                                        |
|   },                                                  |
|   "nodeCount": 6,                                     |
|   "propertyKeyCount": 1,                              |
|   "relationshipCount": 6,                             |
|   "relationshipTypeCount": 2,                         |
|   "relationshipTypes": {                              |
|      "()-[:Relation1]->()": 3,                        |
|      "()-[:Relation1]->(:Node)": 3,                   |
|      "()-[:Relation2]->()": 3,                        |
|      "()-[:Relation2]->(:Node)": 3,                   |
|      "(:Node)-[:Relation1]->()": 3,                   |
|      "(:Node)-[:Relation2]->()": 3                    |
|   },                                                  |
|   "relationshipTypesCount": {                         |
|      "Relation1": 3,                                  |
|      "Relation2": 3                                   |
|   }                                                   |
|}                                                      |
|                                                       |
+-------------------------------------------------------+

stats_offline()

Retrieves graph metadata by traversing the whole graph. The stats_online procedure should be preferred because of the better complexity unless you don't want to use triggers.

Output:

  • labelCount: int ➡ The number of unique labels in nodes.
  • relationshipTypeCount: int ➡ The number of unique relationship types (labels).
  • nodeCount: int ➡ The number of nodes in the graph.
  • relationshipCount: int ➡ The number of relationships in the graph.
  • labels: Map[string: int] ➡ A map with the following (key, value) pairs:
    • label : number_of_occurrences
  • relationshipTypes: Map[string: int] ➡ A map with the following (key, value) pairs:
    • (:label)-[:relationship_type]->() : number_of_occurrences
    • ()-[:relationship_type]->(:label) : number_of_occurrences
    • ()-[:relationship_type]->() : number_of_occurrences
  • relationshipTypesCount: Map[string: int] ➡ A map with the following (key, value) pairs:
    • relationship_type : number_of_occurrences
  • stats ➡ A map which contains all of the above.

Usage:

Create the following objects in the database:

MERGE (a:Node {id: 0}) MERGE (b:Node {id: 1}) CREATE (a)-[:Relation1]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 2}) CREATE (a)-[:Relation1]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 0}) CREATE (a)-[:Relation1]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 3}) CREATE (a)-[:Relation2]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 4}) CREATE (a)-[:Relation2]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 5}) CREATE (a)-[:Relation2]->(b);

Run stats using the following query:

CALL meta.stats_offline() YIELD stats;
+-------------------------------------------------------+
|     stats                                             |
+-------------------------------------------------------+
|                                                       |
|{                                                      |
|   "labelCount": 1,                                    |
|   "labels": {                                         |
|      "Node": 6                                        |
|   },                                                  |
|   "nodeCount": 6,                                     |
|   "propertyKeyCount": 1,                              |
|   "relationshipCount": 6,                             |
|   "relationshipTypeCount": 2,                         |
|   "relationshipTypes": {                              |
|      "()-[:Relation1]->()": 3,                        |
|      "()-[:Relation1]->(:Node)": 3,                   |
|      "()-[:Relation2]->()": 3,                        |
|      "()-[:Relation2]->(:Node)": 3,                   |
|      "(:Node)-[:Relation1]->()": 3,                   |
|      "(:Node)-[:Relation2]->()": 3                    |
|   },                                                  |
|   "relationshipTypesCount": {                         |
|      "Relation1": 3,                                  |
|      "Relation2": 3                                   |
|   }                                                   |
|}                                                      |
|                                                       |
+-------------------------------------------------------+