3 ms·
Author seems to be confused on how databases operate (especially since they really should just be using a KV store like Redis), because you're exactly right, th
by meritt 11y ago
Author seems to be confused on how databases operate (especially since they really should just be using a KV store like Redis), because you're exactly right, the query would be the same as:
select sites.* from sites join routes using (site_id) where route_id = ?
Assuming sites.site_id and routes.route_id are both primary keys, this query is going to perform identically using either syntax. It'll read 1 row from each table.
They could see a further performance gain by placing an index on routes (route_id, site_id) since the site_id could be retrieved from the b-tree and avoid a table hit entirely. But regardless, query syntax will not affect performance here.
- oysteing 11y agoYou are right that this join query should be equivalent. However, with InnoDB there will not be much benefit from your suggested index. In InnoDB primary indexes are clustered. Hence, any column may be retrieved from the B-tree of the primary index.
- deleted 11y ago[deleted]
- jfrisby 11y agoOnly if the columns are stored on-page with the index, which is not guaranteed -- it depends on what other columns exist in the table, etc.