This is a rather complicated question, but I will try my best to describe it as well as possible.
I currently have 2 tables that are joined on an insta_id
.
The first table is called Soc_stat
and it contains a lot of entries of Instagram posts. The columns I use in my SQL query are insta_id
and main_tag
.
The other table is called tags
and includes an insta_id
and all the tag_names
that has been used with that insta_id
.
fThe tags
table looks like this.
My current SQL query looks like this
SELECT tag_names
FROM soc_stat
JOIN tags ON soc_stat.insta_id = tags.insta_id
WHERE main_tag = $hashtag
Now the issue is that currently I have 110000 rows in the tags
table, and the query above is taking such a long time that it often times out. But I think I might have found a solution: The main_tag
from the soc_stat
table is always represented under tag_names
in the tags
table.
So maybe I don't have to join the two tables? Wouldn't it be possible to just check the tags
table for all the insta_id
's that contains a tag_name
equal to $hashtag
and then fetch all the tag_names
that are linked to those insta_id
's?
Edit
I just used added an explain
to my Query on a hashtag I know there is problems with and the result is as follows:
And here I have done it on a much less used hashtag where it is still slow, but not nearly as slow