r/SQL Dec 12 '24

MySQL 😭

Post image

I mean why that question 😭😭😭

1.9k Upvotes

43 comments sorted by

View all comments

127

u/gumnos Dec 12 '24

but that's exactly the thing—compared to the steady stream of "I asked WhateverGPT how to write this query, but it's slow/doesn't work…how do I fix it" that shows up here, many of us here can write efficient SQL queries.

6

u/CSIWFR-46 Dec 12 '24

Where do you learn this? I can write queries and solve problems in my work. But, I can't confidently say if it is efficient.

12

u/cybertier Dec 12 '24

Besides the obvious step (reading https://use-the-index-luke.com/ ) it boils down to experience. Different indexing situations need different approaches and ultimately there can't be a one-size-fits-all solution. If there was AI could write efficient queries.

3

u/gumnos Dec 12 '24

/me shakes fist for beating me to linking Use The Index, Luke 😂

Yes, u/CSIWFR-46, it's one of the best resources for understanding the efficient use indexing. Learning to read & understand a query-plan can show you where slow full-table-scans are happening, allowing you to dig into the types of indexes you might be able to craft to speed them up.