Building Type-Safe APIs with Nuxt 3 and Prisma
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Move beyond basic B-tree indexes. Learn when to use partial indexes, covering indexes, and GIN indexes for real performance gains.
Mbeah Essilfie
July 13, 2026 at 06:02 AM
Every index speeds up reads but slows down writes. The goal isn't "index everything" — it's indexing strategically based on your query patterns.
-- Always start with EXPLAIN ANALYZE
EXPLAIN ANALYZE
SELECT * FROM posts
WHERE status = 'published' AND published_at > NOW() - INTERVAL '30 days'
ORDER BY published_at DESC
LIMIT 20;
Look for Seq Scan — that's a full table scan you probably want to eliminate.
Perfect for equality and range queries:
CREATE INDEX idx_posts_published_at ON posts (published_at DESC);
CREATE INDEX idx_posts_status ON posts (status);
Order matters — put the most selective column first:
-- Matches: WHERE status = 'published' AND published_at > ...
-- Also matches: WHERE status = 'published'
-- Does NOT efficiently match: WHERE published_at > ...
CREATE INDEX idx_posts_status_date ON posts (status, published_at DESC);
Index only the rows you actually query:
-- Only index published posts (maybe 30% of all posts)
CREATE INDEX idx_published_posts ON posts (published_at DESC)
WHERE status = 'published';
-- Add a tsvector column
ALTER TABLE posts ADD COLUMN search_vector tsvector;
-- Create a GIN index
CREATE INDEX idx_posts_search ON posts USING GIN (search_vector);
-- Update it with a trigger
CREATE FUNCTION update_search_vector() RETURNS trigger AS $$
BEGIN
NEW.search_vector := to_tsvector('english', NEW.title || ' ' || NEW.content);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
model Post {
id String @id @default(uuid())
status String
publishedAt DateTime?
@@index([status, publishedAt(sort: Desc)])
}
Monitor with pg_stat_user_indexes to find unused indexes consuming write overhead.
Fullstack Software Developer
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Go beyond basic utility classes and learn how to build cohesive, maintainable design systems with Tailwind CSS.
Understand the power of Vue 3's Composition API through practical, real-world composable patterns that you can use today.
