From what I gather this is mostly because various different SQL queries might get transformed into the same "instructions", or execution plan, but also because SQL semantics doesn't leave much room for language-level optimizations.
As a sibling comment noted, an important decision is if you can replace a full table scan with an index lookup or index scan instead.
For example, if you need to do a full table scan, and do significant computation per row to determine if a row should be included in the result set, the optimizer might change the full table scan with a parallel table scan then merge the results from each parallel task.
When writing performant code for a compiler, you'll want to know how your compilers optimizer transforms the source code to machine instructions, so you prefer writing code the optimizer handles well and avoid writing code the optimizer outputs slower machine instructions for. After all the optimizer is programmed to detect certain patterns and transform them.
Same thing with a query optimizer and its execution plan. You'll have to learn which patterns the query optimizer in the database you're using can handle and generate efficient execution plans for.
A lot more can be done: choosing the join order, choosing the join strategies, pushing the filter predicates at the source, etc. That's the vast topic of SQL optimization.
Seems like jumping right into the code can be a bit overwhelming if you have no background on the topic.
[1] https://hdombrovskaya.wordpress.com/2024/01/11/the-optimizat...
https://use-the-index-luke.com/
Markus Winand (the website's author) has also written a book on the subject targeted at software developers which is decent for non-DBA level knowledge.