Wiki: After analyzing 30,000 SQL queries, these are the top mistakes developers make
For agents: Markdown version · Wiki index · Explore
- Speaker: Tomer Shay Shimshi
- Event: Reversim Summit 2018
- Video: https://www.youtube.com/watch?v=65yjjYfUPVE
- Transcript: /transcripts/2018/46-65yjjYfUPVE.md
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: Databases, Architecture
Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.
Summary
The speaker shares insights from analyzing 30,000 SQL queries across thousands of companies to identify common performance mistakes. The main argument is that creating indexes is not enough; developers must also write queries in a way that allows the database to actually use those indexes. Through specific examples, the audience learns how practices like wrapping columns in functions, using OR operators, mixing sort directions, and comparing mismatched data types can hurt performance. Listeners leave with actionable strategies to optimize their queries and avoid common database bottlenecks.
Key points
- 0:11 The speaker introduces a study analyzing 30,000 SQL queries from 5,000 companies to find recurring optimization patterns.
- 1:16 The primary takeaway is that simply creating good indexes is insufficient; queries must be written to avoid preventing the database from using them.
- 2:22 Using functions on indexed columns prevents databases from utilizing the index, which can be solved with generated columns or alternative range checks.
- 2:22 The OR operator can hinder index usage, making it beneficial to split queries using UNION statements.
- 3:24 Combining ascending and descending sort directions prevents index usage for sorting, requiring descending indexes or virtual columns.
- 4:25 Comparing different data types in queries disables indexes, highlighting the importance of proper type matching.
- 4:25 ORM frameworks do not exempt developers from database performance challenges since the underlying database behavior remains the same.
Takeaways
- Avoid applying functions to indexed columns in your WHERE clauses.
- Be cautious with OR operators and consider using UNION to optimize index utilization.
- Ensure data types match in comparisons to prevent full table scans.
- Do not rely solely on ORMs to write optimized SQL queries.
Questions this talk answers
- Why does wrapping a column in a function prevent the database from using an index?
- How can I optimize queries that use mixed sort directions in the ORDER BY clause?
- Do ORMs protect developers from writing inefficient SQL queries?
Technologies
SQL, MySQL
Tags
backend development, database indexing, databases, query optimization, sql performance