SQL optimization

PwC
ufchv

Go to company page PwC

ufchv
Oct 5, 2020 4 Comments

Hi can anyone give any advice on how to learn SQL code optimization? I know my basics and can do window functions/sub-queries etc and all but recently got feedback in an interview that my code was not optimized. Thank you!

comments

Want to comment? LOG IN or SIGN UP
TOP 4 Comments
  • GE
    n64gtfo

    Go to company page GE

    n64gtfo
    Optimization is more about understanding the code flow and requirements than the code itself.

    Sub-queries are almost always less optimal than joins.

    Focus on the indices. SQL is about trading off insert vs retrieval time. Creating or using appropriate indices is very important. For example, you may end up with sql that looks less optimal, but is actually much faster since it uses proper indices.
    Oct 5, 2020 0
  • High performance MySQL is a great resource.
    Oct 5, 2020 0
  • Amazon
    DHardwood

    Go to company page Amazon

    DHardwood
    "SQL Performance Explained" is a good primer. It's not just enough enough to know language semantics but how the engine uses the statement to generate a query plan and then how it is executed. After this book, you'll need to cover a more thorough book.
    Oct 5, 2020 0
  • Following
    Oct 5, 2020 0