On 2013-11-04 16:10, Caio Casimiro
wrote:
Yes, because that part of the query is kicking back so many rows, many of which are totally unnecessary anyway - you're first getting all the tweets in a particular time range, then limiting them down to just users that are followed. Here's clarification on the approach I mentioned earlier. All you should really need are basic (btree) indexes on your different keys (tweet_topic.tweet_id, tweet.id, tweet.user_id, relationship.follower_id, relationship.followed_id). I also changed the left join to an inner join as somebody pointed out that your logic amounted to reducing the match to an inner join anyway. SELECT tt.tweet_id, tt.topic, tt.topic_value FROM tweet_topic AS tt JOIN tweet AS t ON tt.tweet_id = t.id join relationship on t.user_id = relationship.followed_id WHERE creation_time BETWEEN 'D1' AND 'D2' AND relationship.follower_id = N ORDER BY tt.tweet_id ; |