# SQL Analysis Examples

## Example 1: Query Optimization

**Input:**
```sql
SELECT * FROM users u
WHERE YEAR(u.created_at) = 2025
AND u.id IN (SELECT user_id FROM orders);
```

**Expected Output:**
Issues identified: SELECT *, function in WHERE (index not used), IN with subquery. Optimized query with specific columns, date range, EXISTS clause.

## Example 2: Index Design

**Input:**
```
Design indexes for a users table frequently queried by email and created_at, with JOIN on orders table.
```

**Expected Output:**
Index recommendations: UNIQUE index on email, B-tree index on created_at, index on orders.user_id (foreign key), composite index considerations.

## Example 3: N+1 Problem

**Input:**
```
Application loads users then queries orders for each user in a loop. How to optimize?
```

**Expected Output:**
N+1 problem explained, single JOIN query solution, ORM eager loading, performance impact comparison.

## Common Use Cases

- Query optimization
- Index design
- Schema design review
- Performance troubleshooting
- SQL injection prevention
