> What's neat is that no matter how complicated I is, you can still write \\(Q^I\\) using SELECT, FROM, WHERE, and the SQL query optimizer takes care of finding a way to quickly execute the query.

This is a bit optimistic.

There are many ways a database query can be suboptimal and the optimizer can't always improve performance.

For instance, PSQL does not automatically optimize subqueries into joins even when they are equivalent. Here is a [quora discussion](https://www.quora.com/Which-is-faster-joins-or-subqueries) about this.

It is important not to rely on the query optimizer and routinely check out the query planner.

There are many gotchas in SQL queries. You sometimes have to manually make indexes to improve performance. Even if you have an index, it is easy to write a SQL query that accidentally does not use it. Here is a [datadog blog post](https://www.datadoghq.com/blog/100x-faster-postgres-performance-by-changing-1-line/) where they go over this an example of this exercise, where a one line change gave a 100x performance improvement.