Install
openclaw skills install graph-query-optimization-assistantAnalyze graph queries and suggest optimizations to improve performance, reduce execution time, and ensure efficient traversal in graph databases.
openclaw skills install graph-query-optimization-assistantAnalyze graph queries and recommend performance optimizations.
This skill helps developers improve the performance of graph database queries by identifying inefficiencies and suggesting optimized query patterns.
It evaluates queries written in languages such as Cypher or SPARQL and provides recommendations that reduce query cost, improve traversal efficiency, and minimize unnecessary graph scans.
Use this skill when a user wants to:
The optimization assistant analyzes queries and provides:
Efficient queries start from the most selective nodes to minimize graph traversal.
Patterns:
Example Inefficient:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
WHERE c.name = "Acme"
RETURN p
Example Optimized:
MATCH (c:Company {name: "Acme"})
MATCH (c)<-[:WORKS_AT]-(p:Person)
RETURN p
Strategic index creation dramatically improves query performance.
Patterns:
Recommendations:
-- Create single property index
CREATE INDEX ON :Company(name)
-- Create composite index
CREATE INDEX ON :Person(firstName, lastName)
-- Create full-text index for search
CREATE FULLTEXT INDEX person_search FOR (p:Person) ON EACH [p.name, p.email]
Optimize how relationships are traversed.
Patterns:
Example Inefficient:
MATCH (p:Person)-[*]->(target)
RETURN p, target
Example Optimized:
MATCH (p:Person)-[*1..3]->(target:Company)
RETURN p, target
Organize query clauses for maximum efficiency.
Patterns:
Example Inefficient:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN p, c
LIMIT 100
Example Optimized:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN p, c
LIMIT 100
Understand and estimate query costs.
Patterns:
Cost Analysis Formula:
Total Cost = Entry Point Cost + Traversal Cost + Filter Cost + Result Processing Cost
Optimization techniques specific to Cypher/Neo4j.
Patterns:
Optimization techniques for SPARQL/RDF.
Patterns:
When optimizing a graph query:
Execution Time: Time required to execute query
Memory Usage: Memory required during execution
Node Visits: Number of nodes examined during traversal
Relationship Traversals: Number of relationships examined
Index Usage: Whether indexes are utilized
Query Performance Comparison
═══════════════════════════════════════════════════════
Original Query:
Execution Time: 5,432 ms
Nodes Visited: 1,200,000
Memory: 256 MB
Cost Score: 8.5/10
Optimized Query:
Execution Time: 245 ms
Nodes Visited: 45,000
Memory: 64 MB
Cost Score: 2.1/10
Improvement:
Speed: 22.1x faster (5,187 ms saved)
Efficiency: 96.3% fewer nodes visited
Memory: 75% reduction
Original Query:
MATCH (customer:Customer)-[:PURCHASED]->(p1:Product)
MATCH (p1)<-[:PURCHASED]-(other:Customer)
MATCH (other)-[:PURCHASED]->(recommended:Product)
WHERE recommended.price < 100
RETURN recommended
LIMIT 10
Issues Identified:
Optimized Query:
MATCH (customer:Customer {id: $customerId})
MATCH (customer)-[:PURCHASED]->(p1:Product)
MATCH (p1)<-[:PURCHASED]-(other:Customer)
MATCH (other)-[:PURCHASED]->(recommended:Product {active: true})
WHERE recommended.price < 100
RETURN recommended
LIMIT 10
Recommendations:
CREATE INDEX ON :Product(price)CREATE INDEX ON :Customer(id)Performance Impact:
Original Query:
SELECT ?friend
WHERE {
?user foaf:knows ?connection .
?connection foaf:knows ?friend .
}
Issues Identified:
Optimized Query:
SELECT ?friend (COUNT(?connection) as ?mutual_friends)
WHERE {
?user foaf:knows ?connection .
?connection foaf:knows ?friend .
FILTER (?user != ?friend)
FILTER NOT EXISTS { ?user foaf:knows ?friend }
}
GROUP BY ?friend
ORDER BY DESC(?mutual_friends)
LIMIT 20
Recommendations:
Performance Impact:
Single Property Index:
Composite Index:
Full-Text Index:
-- Basic single property index
CREATE INDEX ON :Person(email)
-- Composite index for multiple properties
CREATE NAMED INDEX person_name_age FOR (p:Person) ON (p.firstName, p.lastName)
-- Full-text index for searching
CREATE FULLTEXT INDEX person_search FOR (p:Person) ON EACH [p.name, p.bio]
-- Unique constraint (also acts as index)
CREATE CONSTRAINT ON (u:User) ASSERT u.email IS UNIQUE
When optimizing graph queries:
[*1..3]This skill integrates with:
py2neo - Neo4j driver with performance metricsrdf-lib - RDF query optimization utilitiesgraphistry - Query visualization and optimizationnumba - JIT compilation for cost analysisThis skill improves the performance of graph database queries by analyzing query structure and suggesting optimized patterns.
It helps developers write faster, more efficient Cypher and SPARQL queries that scale effectively with large graph datasets through strategic index recommendations, intelligent query restructuring, and comprehensive performance analysis.
Status: Enterprise-Grade Query Optimization Tool
Comprehensive performance analysis, index optimization, and query acceleration for professional knowledge graph development.