-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Migrate from UUID v4 (stored as VARCHAR(255)) to UUID v7 (stored as BINARY(16) or native UUID type) for all primary key columns to improve database performance.
Motivation
Current Implementation
id VARCHAR(255) NOT NULL PRIMARY KEY- UUID v4: Completely random, no time-based ordering
- VARCHAR(255): 36 bytes + length prefix, string comparisons
Problems with UUID v4 + VARCHAR
-
Poor B-Tree Index Performance
- Random UUIDs scatter inserts across the entire B-Tree
- Causes frequent page splits and index fragmentation
- More disk I/O, worse cache utilization
-
Storage Overhead
- VARCHAR stores 36 characters (+ overhead) vs. 16 bytes for binary
- String comparisons are slower than binary comparisons
- Larger index size = more memory needed
-
No Natural Ordering
- UUID v4 has no relationship to creation time
- Requires separate
created_atcolumn and index for time-based queries
Proposed Solution
UUID v7 (RFC 9562) provides:
- Time-ordered: Contains millisecond-precision Unix timestamp
- Monotonically increasing: New IDs are always "greater" than older ones
- Sequential inserts: Append-only behavior in B-Tree indexes
Expected Performance Gains
| Metric | Improvement |
|---|---|
| Insert throughput | 20-40% faster |
| Index size | ~50% smaller |
| Primary key lookups | 10-20% faster |
| Storage space | ~50% less for ID columns |
Alternatives Considered
UUID v7 with VARCHAR storage (no schema change)
Pros:
- No breaking change
- Still improves insert performance (sequential ordering)
Cons:
- Misses storage and comparison performance gains
- Half-measure
Verdict: Could be done in v1.x as a quick win, but full migration should happen in v2.0.
| Storage space | ~50% less for ID columns |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request