by amluto · 2w ago · 0 comments
I feel like I would probably execute three separate queries and merge the results myself. And the user query wouldn’t join against posts at all. Doing this would end up implicitly doing something like the optimization in the article.
The central query in the blog would likely be the type of query you'd use for the default top-level search box on StackOverflow, which is searching for posts and comments (e.g. questions and answers). The reason to include users in that query is two fold: 1) posts/comments from users who are relevant to your query should get a higher score, 2) you need the users to render the search results page anyway.
If you were doing only user search, then I agree: you probably would only search the users table.
> Getting that original, natural SQL query down to 100 ms on a single core (12x-50x faster than the 84-line UNION ALL rewrite, and within range of a fully denormalized dataset) required rethinking how joins and search indexes interact