optimized_joinJoin operation completed efficiently
Join operation used indexes efficiently, avoiding cross-product scans.
What makes a join optimized
typescript
// An optimized join uses indexes on both sides of the join condition.
// Without indexes, the database does a nested loop full scan.
// PostgreSQL — ensure foreign key columns are indexed
// CREATE INDEX idx_posts_user_id ON posts(user_id);
// CREATE INDEX idx_comments_post_id ON comments(post_id);
// Prisma — index foreign keys in schema
// model Post {
// userId String
// user User @relation(fields: [userId], references: [id])
// @@index([userId])
// }
// Mongoose — index reference fields
const PostSchema = new Schema({
authorId: { type: ObjectId, ref: 'User', index: true }, // ← index here
});