News for hackers. Stuff that matters.
Re:MySQL is a Better NoSQL by aidos on Wednesday December 09, 2015 @07:32PM (#10708016)
Quick question - I'm confused about the comment "The nested query syntax ensures that we are doing only one round-trip to the database to run both SQL queries". Why is the nested syntax better than a regular join in this case?

Seems like a join would allow the query planner to decide how to carry out the query.

Re:MySQL is a Better NoSQL by meritt on Wednesday December 09, 2015 @08:15PM (#10708196)
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.

Re:MySQL is a Better NoSQL by oysteing on Thursday December 10, 2015 @04:29AM (#10709732)
You 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.
Re:MySQL is a Better NoSQL by jfrisby on Thursday December 10, 2015 @02:43PM (#10712885)
Only 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.
Re:MySQL is a Better NoSQL by yoava on Thursday December 10, 2015 @04:48PM (#10713740)
Your question is valid, assuming you trust the query planner to make the right decision. However, the query planner in most databases is not perfect and can miss.

We have tried a few different alternatives, including the join, and found that this sub-query option actually works better.

A sub query forces the database to execute the first query on routes using the index, then use the result for the second query on sites. It leave nothing for the interpretation of the optimizer which may decide to so some silly thing like full scan on the sites table before performing the join.

Re:MySQL is a Better NoSQL by aidos on Thursday December 10, 2015 @08:54PM (#10715035)
Thanks for replying. I remember having to use those sort of tricks to get more performance out of mysql queries in the past.

I use postgres these days and my system characteristics are such that I don't have to worry about query performance so much. Though I have found that I've needed similar tactics sometimes with postgres too.

Re:MySQL is a Better NoSQL by timhon on Thursday December 10, 2015 @03:49AM (#10709641)
@yoava - can you comment on this?