Questions about database Multi-table queries?

Source: Internet
Author: User
There are currently three tables
Topic topic Table ID Title
Tagsmap corresponding relationship table ID tagsid topicid
Tags tag table id tagsname

Now you need to query the first few topic records under a tag.

Select title from topic where ID in (select TopicID from Tagsmap where tagsid= "10000")

This query finds the query to be slow.

What's wrong with this notation? Ask how to optimize the query is better! I hope we can discuss it.

Reply content:

There are currently three tables
Topic topic Table ID Title
Tagsmap corresponding relationship table ID tagsid topicid
Tags tag table id tagsname

Now you need to query the first few topic records under a tag.

Select title from topic where ID in (select TopicID from Tagsmap where tagsid= "10000")

This query finds the query to be slow.

What's wrong with this notation? Ask how to optimize the query is better! I hope we can discuss it.

Just a general level of optimization:
select title from topic t left join tagsmap m on m.topicid = t.id where m.tagsid = "10000"
The amount of data in the tens of thousands of to hundreds of thousands of basically this performance is acceptable, of course, remember tagsmap inside the TAGSID plus index

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.