Viewed
Explanation
OpenAI
GPT-5 mini
VS
Google
Gemini 2.5 Flash-Lite
Explain Database Indexing to a Junior Developer
You are a senior software engineer mentoring a junior developer who has been writing SQL queries for about six months but has never created or thought about database indexes. They just complained that their queries on a table with two million rows are running very slowly.
Write an explanation of database indexing for this audience. Your explanation should cover the following:
1. What a database index is and why it exists, using at least one concrete analogy that a beginner would find intuitive.
2. How a basic index (such as a B-tree index) speeds up query lookups, explained at a conceptual level without requiring knowledge of data structures coursework.
3. The trade-offs of adding indexes, including when indexes can hurt performance.
4. Practical guidance on how to decide which columns to index, with at least two realistic examples tied to common application scenarios (e.g., e-commerce, social media, content management).
5. A brief note on composite indexes and when they matter.
Your explanation should be clear enough that the junior developer could confidently decide whether and where to add an index to their own project after reading it. Avoid unnecessary jargon, but do not oversimplify to the point of inaccuracy.