|
| 1 | +# Performance Indexes for GoGraph |
| 2 | + |
| 3 | +## Required Indexes for Optimal Query Performance |
| 4 | + |
| 5 | +The following indexes should be created in Neo4j to optimize query performance, especially for case-insensitive searches using `toLower()`: |
| 6 | + |
| 7 | +### Full-Text Indexes |
| 8 | + |
| 9 | +Create full-text indexes for text search operations: |
| 10 | + |
| 11 | +```cypher |
| 12 | +-- Function name and package search |
| 13 | +CALL db.index.fulltext.createNodeIndex( |
| 14 | + "functionSearch", |
| 15 | + ["Function"], |
| 16 | + ["name", "package"], |
| 17 | + {analyzer: "standard-no-stop-words"} |
| 18 | +); |
| 19 | +
|
| 20 | +-- Struct name and package search |
| 21 | +CALL db.index.fulltext.createNodeIndex( |
| 22 | + "structSearch", |
| 23 | + ["Struct"], |
| 24 | + ["name", "package"], |
| 25 | + {analyzer: "standard-no-stop-words"} |
| 26 | +); |
| 27 | +
|
| 28 | +-- Interface name and package search |
| 29 | +CALL db.index.fulltext.createNodeIndex( |
| 30 | + "interfaceSearch", |
| 31 | + ["Interface"], |
| 32 | + ["name", "package"], |
| 33 | + {analyzer: "standard-no-stop-words"} |
| 34 | +); |
| 35 | +
|
| 36 | +-- File path search |
| 37 | +CALL db.index.fulltext.createNodeIndex( |
| 38 | + "fileSearch", |
| 39 | + ["File"], |
| 40 | + ["path", "name"], |
| 41 | + {analyzer: "standard-no-stop-words"} |
| 42 | +); |
| 43 | +
|
| 44 | +-- Package search |
| 45 | +CALL db.index.fulltext.createNodeIndex( |
| 46 | + "packageSearch", |
| 47 | + ["Package"], |
| 48 | + ["name", "path"], |
| 49 | + {analyzer: "standard-no-stop-words"} |
| 50 | +); |
| 51 | +``` |
| 52 | + |
| 53 | +### Composite Indexes |
| 54 | + |
| 55 | +Create composite indexes for common query patterns: |
| 56 | + |
| 57 | +```cypher |
| 58 | +-- Function lookups by project and name |
| 59 | +CREATE INDEX function_project_name FOR (n:Function) ON (n.project_id, n.name); |
| 60 | +
|
| 61 | +-- Struct lookups by project and name |
| 62 | +CREATE INDEX struct_project_name FOR (n:Struct) ON (n.project_id, n.name); |
| 63 | +
|
| 64 | +-- Interface lookups by project and name |
| 65 | +CREATE INDEX interface_project_name FOR (n:Interface) ON (n.project_id, n.name); |
| 66 | +
|
| 67 | +-- File lookups by project and path |
| 68 | +CREATE INDEX file_project_path FOR (n:File) ON (n.project_id, n.path); |
| 69 | +
|
| 70 | +-- Package lookups by project and name |
| 71 | +CREATE INDEX package_project_name FOR (n:Package) ON (n.project_id, n.name); |
| 72 | +``` |
| 73 | + |
| 74 | +### Property Indexes |
| 75 | + |
| 76 | +Create property indexes for frequently queried fields: |
| 77 | + |
| 78 | +```cypher |
| 79 | +-- Basic property indexes |
| 80 | +CREATE INDEX ON :Function(name); |
| 81 | +CREATE INDEX ON :Function(package); |
| 82 | +CREATE INDEX ON :Function(is_exported); |
| 83 | +CREATE INDEX ON :Struct(name); |
| 84 | +CREATE INDEX ON :Struct(package); |
| 85 | +CREATE INDEX ON :Interface(name); |
| 86 | +CREATE INDEX ON :Interface(package); |
| 87 | +CREATE INDEX ON :File(path); |
| 88 | +CREATE INDEX ON :Package(name); |
| 89 | +``` |
| 90 | + |
| 91 | +## Query Optimization Tips |
| 92 | + |
| 93 | +### Using Full-Text Indexes |
| 94 | + |
| 95 | +Instead of using `toLower()` for case-insensitive searches, use full-text queries: |
| 96 | + |
| 97 | +```cypher |
| 98 | +-- Before (slow) |
| 99 | +MATCH (f:Function {project_id: $project_id}) |
| 100 | +WHERE toLower(f.name) CONTAINS toLower($search_term) |
| 101 | +RETURN f |
| 102 | +
|
| 103 | +-- After (fast) |
| 104 | +CALL db.index.fulltext.queryNodes("functionSearch", $search_term + "*") |
| 105 | +YIELD node as f |
| 106 | +WHERE f.project_id = $project_id |
| 107 | +RETURN f |
| 108 | +``` |
| 109 | + |
| 110 | +### Monitoring Index Usage |
| 111 | + |
| 112 | +Check if indexes are being used: |
| 113 | + |
| 114 | +```cypher |
| 115 | +EXPLAIN MATCH (f:Function {project_id: "test"}) |
| 116 | +WHERE f.name = "HandleRequest" |
| 117 | +RETURN f |
| 118 | +``` |
| 119 | + |
| 120 | +### Index Maintenance |
| 121 | + |
| 122 | +Regularly update index statistics: |
| 123 | + |
| 124 | +```cypher |
| 125 | +CALL db.stats.retrieve("INDEXES"); |
| 126 | +``` |
| 127 | + |
| 128 | +## Implementation Notes |
| 129 | + |
| 130 | +1. These indexes should be created after initial data import for best performance |
| 131 | +2. Monitor query performance using Neo4j's query log |
| 132 | +3. Consider adding more specialized indexes based on actual query patterns |
| 133 | +4. For very large datasets, consider partitioning strategies |
| 134 | + |
| 135 | +## Future Optimizations |
| 136 | + |
| 137 | +1. Implement caching layer for frequently accessed queries |
| 138 | +2. Consider using materialized views for complex aggregations |
| 139 | +3. Implement query result pagination for large result sets |
| 140 | +4. Add connection pooling configuration for concurrent access |
0 commit comments