There is always a problem, basically, but I still want to figure it out. Mysql reads database storage.

Source: Internet
Author: User
There is always a problem, basically, but I still want to figure it out. Mysql reads database storage... This post was last edited by xianglei1130 from 2013-03-0414: 50: 06. This question has always occurred. I am so excited today that I will post a post to discuss it with you. I know that my technology is average, so don't try it out. it's basically a problem, but I still want to figure it out. Mysql reads database storage...
This post was edited at 14:50:06 on by xianglei1130. it has always been a problem. today, I am excited and I will post a post to discuss it with you.

I know that my technology is average, so don't try it out.

It is assumed that there is A total record in Table A, which contains various fields, sid title content link ....

Then there is A personal record Table B, field: id name sid (sid of Table A) to record the data in table A owned by this person.

Now the problem arises. if there are 10 records in table A in Table B "zhang san", I will combine the 10 sid with A single symbol to store the sid in Table B. Or are 10 records generated and saved to Table B?





The 1st method is to use explode to split the sid of Table B and then query table A to retrieve the data. The 2nd method is to find all records of the id and loop it out.

Which method is better? From all aspects of the database program. I don't know how to explain it next. I hope you can advise me... Database storage mysql
------ Solution --------------------
1. A combination of symbols (,) can be used to store the sid of Table B. find_in_set (A. sid, B. sid)
In this case, B. sid is large enough. if it is not 10 but 1000, what about 10000?
2. each sid can be saved to B. A. sid = B. sid during query.
It looks silly, but it works.
3. the above schemes assume that A. sid is public, that is, multiple users can have the same A. sid. For example: friends, follow
If A. sid is private to the user, such as posting
Then we should add A uid field in A to record the ownership.
------ Solution --------------------
The second is simple. if The explode is used, you have to perform many operations on your own.

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.