database-analyzer
npx machina-cli add skill netresearch/composer-agent-skill-plugin/database-analyzer-skill --openclawDatabase Analyzer Skill
This skill helps you analyze database schemas, identify optimization opportunities, and understand table relationships.
Instructions
- Identify the target: Determine which table or schema to analyze
- Gather context: Understand the current usage patterns and performance concerns
- Analyze structure: Examine table definitions, indexes, and relationships
- Identify issues: Look for missing indexes, improper data types, or inefficient structures
- Suggest improvements: Provide specific, actionable recommendations
Examples
Example 1: Basic Table Analysis
User request: "Analyze the users table for optimization opportunities"
Approach:
- Check table structure and data types
- Verify indexes on frequently queried columns
- Look for redundant or missing indexes
- Suggest appropriate data types for columns
Analysis Steps:
-- 1. Get table structure
DESCRIBE users;
-- 2. Check existing indexes
SHOW INDEX FROM users;
-- 3. Analyze table statistics
ANALYZE TABLE users;
Common Issues to Check:
- Missing indexes on foreign keys
- Text columns that should be ENUM or SET
- Missing or excessive indexes
- Improper data types (e.g., VARCHAR when INT would suffice)
Example 2: Performance Investigation
User request: "Why are queries on the orders table slow?"
Approach:
- Identify frequently executed queries
- Check for missing indexes on WHERE/JOIN columns
- Analyze table size and growth patterns
- Suggest partitioning if appropriate
Investigation Steps:
-- 1. Check table size
SELECT
table_name,
round(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)'
FROM information_schema.TABLES
WHERE table_name = 'orders';
-- 2. Identify slow queries
SHOW PROCESSLIST;
-- 3. Check query execution plan
EXPLAIN SELECT * FROM orders WHERE customer_id = 123;
Optimization Recommendations:
- Add composite indexes for common query patterns
- Consider partitioning by date for large historical tables
- Archive old data to separate tables
- Optimize data types to reduce row size
Example 3: Index Optimization
User request: "Review indexes on the products table"
Approach:
- List all current indexes
- Identify unused or redundant indexes
- Check for missing indexes on query patterns
- Calculate index selectivity
Review Process:
-- 1. Show all indexes
SHOW INDEX FROM products;
-- 2. Check index usage (MySQL 5.6+)
SELECT * FROM sys.schema_unused_indexes
WHERE object_schema = 'your_database'
AND object_name = 'products';
-- 3. Analyze query patterns
SELECT DISTINCT column_name
FROM information_schema.statistics
WHERE table_name = 'products';
Requirements
- Access to database schema information
- Understanding of SQL and database design principles
- Ability to read EXPLAIN query plans (if available)
- Knowledge of the application's query patterns
Best Practices
- Always explain the reasoning behind suggestions
- Consider both read and write performance impacts
- Account for data volume and growth patterns
- Suggest incremental improvements when possible
- Document assumptions made during analysis
- Provide migration scripts for proposed changes
- Test recommendations in a non-production environment first
Common Patterns
Pattern 1: E-commerce Database
- Heavy read operations on product catalog
- Frequent JOIN operations between products, categories, and prices
- Date-based queries for orders
- Key optimizations: Composite indexes, query caching, read replicas
Pattern 2: User Management System
- Frequent lookups by email or username
- Session management with expiration
- Role-based access control queries
- Key optimizations: Unique indexes, covering indexes, denormalization
Pattern 3: Analytics Database
- Large aggregation queries
- Time-series data
- Reporting queries with multiple JOINs
- Key optimizations: Partitioning, summary tables, columnstore indexes
Troubleshooting
No Slow Queries Detected
- Check slow query log settings
- Verify logging is enabled
- Look for queries with high execution count (not just slow time)
Index Not Being Used
- Check index selectivity (should be high)
- Verify query uses indexed columns in WHERE clause
- Consider forcing index with USE INDEX hint for testing
- Check for implicit type conversions preventing index use
Table Lock Contention
- Identify long-running transactions
- Consider using InnoDB over MyISAM for row-level locking
- Optimize batch operations to reduce lock time
Resources
Bundled resources in this skill package:
references/schema-patterns.sql- Common schema patternsscripts/analyze-table.php- Automated analysis scriptassets/optimization-checklist.md- Comprehensive checklist
Use base directory from composer read-skill output to locate these files.
Notes
- Always backup before making schema changes
- Test in development environment first
- Monitor performance before and after changes
- Document all modifications for team awareness
Source
git clone https://github.com/netresearch/composer-agent-skill-plugin/blob/main/examples/database-analyzer-skill/SKILL.mdView on GitHub Overview
The database-analyzer helps you inspect schemas, identify optimization opportunities, and understand relationships between tables. It targets performance issues, missing or redundant indexes, and data-type appropriateness, providing actionable improvements.
How This Skill Works
To use it, identify the target table or schema, gather context on usage and concerns, then analyze structure, indexes, and relationships to surface issues. It then suggests concrete, actionable improvements and migration steps.
When to Use It
- When optimizing database structure and table relationships
- When reviewing indexes and index usage to speed queries
- When investigating slow or expensive queries on key tables
- When assessing data types and column definitions for efficiency
- When planning incremental optimizations or migrations for large tables
Quick Start
- Step 1: Identify the target table or schema to analyze
- Step 2: Gather usage context and performance concerns
- Step 3: Analyze structure, indexes, and relationships; propose improvements
Best Practices
- Explain the reasoning behind each suggestion
- Consider both read and write performance impacts
- Account for data volume and growth patterns
- Provide migration scripts for proposed changes
- Test recommendations in a non-production environment first
Example Use Cases
- Analyze the users table for optimization opportunities
- Investigate slow queries on the orders table
- Review indexes on the products table
- Check table structure and data types with DESCRIBE and optimize accordingly
- Assess table size and index usage to identify partitioning needs