You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Find all references to a symbol (who calls this?)SELECT*FROM find_references(
target_symbol_id :='symbol-id-here',
edge_kind_filter :='Calls'
);
-- Find all dependencies of a symbol (what does this call?)SELECT*FROM find_dependencies(
source_symbol_id :='symbol-id-here',
edge_kind_filter :='Calls'
);
-- Find call chain (recursive)SELECT*FROM find_call_chain(
start_symbol_id :='symbol-id-here',
max_depth :=5
);
Statistics & Analytics
Repository Stats
-- View repository statisticsSELECT*FROM repo_stats;
-- Specific repositorySELECT*FROM repo_stats WHERE repo_name ='my-repo';
Branch Stats
-- View branch statisticsSELECT*FROM branch_stats;
-- Specific branchSELECT*FROM branch_stats
WHERE repo_name ='my-repo'AND branch_name ='main';
-- Branches by index stateSELECT*FROM branch_stats WHERE index_state ='Completed';
Language Distribution
-- Language stats per repositorySELECT*FROM language_stats WHERE repo_name ='my-repo';
-- Top languages by file countSELECT language, SUM(file_count) as total_files
FROM language_stats
GROUP BY language
ORDER BY total_files DESC;
Symbol Kind Distribution
-- Symbol kinds per repositorySELECT*FROM symbol_kind_stats WHERE repo_name ='my-repo';
-- Most common symbol kindsSELECT symbol_kind, SUM(symbol_count) as total
FROM symbol_kind_stats
GROUP BY symbol_kind
ORDER BY total DESC;
Hot Symbols (Most Referenced)
-- Most referenced symbolsSELECT*FROM hot_symbols
ORDER BY reference_count DESCLIMIT20;
-- Most called functionsSELECT*FROM hot_symbols
WHERE symbol_kind IN ('Method', 'Function')
ORDER BY call_count DESCLIMIT20;
Recent Activity
-- Recent commitsSELECT*FROM recent_activity
ORDER BY committed_at DESCLIMIT20;
-- Recent commits in a repositorySELECT*FROM recent_activity
WHERE repo_name ='my-repo'ORDER BY committed_at DESC;
Indexing Progress
-- Overall indexing progressSELECT*FROM indexing_progress;
-- Specific repositorySELECT*FROM indexing_progress WHERE repo_name ='my-repo';
Maintenance
Refresh Materialized Views
-- Refresh all viewsSELECT refresh_all_stats();
-- Refresh specific viewSELECT refresh_stats('repo_stats');
SELECT refresh_stats('branch_stats');
SELECT refresh_stats('hot_symbols');
Vacuum and Analyze
-- Vacuum all tables
VACUUM ANALYZE;
-- Vacuum specific tables
VACUUM ANALYZE embeddings;
VACUUM ANALYZE code_chunks;
VACUUM ANALYZE symbols;
Reindex
-- Reindex all indexes
REINDEX DATABASE lancer;
-- Reindex specific index
REINDEX INDEX idx_embeddings_vector_hnsw;
REINDEX INDEX idx_chunks_content_fts;
Monitor Performance
-- Check index usageSELECT
schemaname,
tablename,
indexname,
idx_scan,
idx_tup_read,
idx_tup_fetch
FROM pg_stat_user_indexes
ORDER BY idx_scan DESC;
-- Check table sizesSELECT
schemaname,
tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables
WHERE schemaname ='public'ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
-- Check slow queries (requires pg_stat_statements)SELECT
query,
calls,
total_exec_time,
mean_exec_time,
max_exec_time
FROM pg_stat_statements
ORDER BY total_exec_time DESCLIMIT10;
Direct Table Queries
Repositories
-- List all repositoriesSELECT*FROM repos;
-- Get repository by nameSELECT*FROM repos WHERE name ='my-repo';
Branches
-- List all branchesSELECT*FROM branches;
-- Branches for a repositorySELECT*FROM branches WHERE repo_id ='repo-id';
-- Branches by stateSELECT*FROM branches WHERE index_state ='Completed';
Commits
-- Recent commitsSELECT*FROM commits ORDER BY committed_at DESCLIMIT20;
-- Commits by authorSELECT*FROM commits WHERE author_email ='user@example.com';
Files
-- Files in a repositorySELECT*FROM files WHERE repo_id ='repo-id';
-- Files by languageSELECT*FROM files WHERE language ='CSharp';
-- Largest filesSELECT file_path, size_bytes
FROM files
ORDER BY size_bytes DESCLIMIT20;
Symbols
-- All symbols in a fileSELECT*FROM symbols WHERE file_path ='path/to/file.cs';
-- Symbols by kindSELECT*FROM symbols WHERE kind ='Class';
-- Top-level symbols (no parent)SELECT*FROM symbols WHERE parent_symbol_id IS NULL;
-- Child symbols of a parentSELECT*FROM symbols WHERE parent_symbol_id ='parent-id';
Edges
-- All edges from a symbolSELECT*FROM edges WHERE source_symbol_id ='symbol-id';
-- All edges to a symbolSELECT*FROM edges WHERE target_symbol_id ='symbol-id';
-- Edges by kindSELECT*FROM edges WHERE kind ='Calls';
Code Chunks
-- Chunks in a fileSELECT*FROM code_chunks WHERE file_path ='path/to/file.cs';
-- Chunks by languageSELECT*FROM code_chunks WHERE language ='CSharp';
-- Chunks with embeddingsSELECT c.*FROM code_chunks c
JOIN embeddings e ONc.id=e.chunk_id;
Embeddings
-- Count embeddingsSELECTCOUNT(*) FROM embeddings;
-- Embeddings by modelSELECT model, COUNT(*)
FROM embeddings
GROUP BY model;
-- Recent embeddingsSELECT*FROM embeddings ORDER BY generated_at DESCLIMIT20;
Performance Tips
HNSW Query Performance
-- Increase ef_search for better recall (slower)SEThnsw.ef_search=200;
-- Decrease ef_search for faster queries (lower recall)SEThnsw.ef_search=40;
Full-Text Search Performance
-- Use phrase search for exact matchesSELECT*FROM code_chunks
WHERE to_tsvector('english', content) @@ phraseto_tsquery('english', 'user authentication');
-- Use prefix search for autocompleteSELECT*FROM code_chunks
WHERE to_tsvector('english', content) @@ to_tsquery('english', 'auth:*');
Batch Operations
-- Insert multiple rows efficientlyINSERT INTO code_chunks (id, repo_id, branch_name, ...)
VALUES
('id1', 'repo1', 'main', ...),
('id2', 'repo1', 'main', ...),
('id3', 'repo1', 'main', ...)
ON CONFLICT (id) DO UPDATESET ...;
-- Use COPY for bulk inserts
COPY code_chunks FROM'/path/to/data.csv' WITH (FORMAT csv, HEADER true);
Useful Psql Commands
# Connect to database
psql -h localhost -U postgres -d lancer
# List tables\dt
# List materialized views\dm
# List functions\df
# Describe table\d repos
\d+ repos # with more details# List indexes\di
# Show table sizes\dt+
# Execute SQL file\i /path/to/file.sql
# Export query results to CSV\copy (SELECT * FROM repos) TO '/tmp/repos.csv' WITH CSV HEADER;# Timing queries\timing on
SELECT * FROM search_chunks_fulltext('test');