sql - Basic optimisation with an index for mysql -


I have a question about basic MySQL database optimization. I have 3 tables, articles, tags and tagging (which is a included table).

  Tag Tags Tag ID ID ID name article_id name tag_ id  

I

  SELECT *, COUNT (*) As a contact tag, retrieving articles that match exact tags as tags, such as a.id = tng.article_id tng T.id = tng.tag_id where TN .n. Type in ("red", "green") group a.id hashing c = 2  

This query is slow, so I did an expo and got the following results:

Now, I really can not understand what I am doing here, but I believe that "all types" are not good, I will add index (BTERR) for both articles and tags, and query again I will run Well, in my uneducated eyes, no one looks better, the same number of rows as the last one, and the type is still one of the two cases.

So someone can tell me where I am going wrong, please? Will this indexed issue not help me?

My tag table will be relatively short, so I thought the query should scan the tag table for the tag I specify, and then (through indexed) enable

[Edit] - For comments of J.

thanks

[edit] - For J. comments

thanks

> I've added 10k articles, 30k tagging and 6 tags, tagged on tag name and taggages. Tag_id, query still took a long time, 0.5-1 seconds, the bottom of the display is

because tags .name is the only column that actually reduces the number of rows in the result set, it is necessary

Update: Try running this query

  SELECT A. * Join tag as a tag in the form of tags as tng .id = tng.article_id t.id = tng.tag_id as the tag WHERE t.name IN ("Red", "Green") Group hosting a.id by COUNT (DISTINCT t.id) = 2  

Comments