MySQL Vertical sub-table technology, the actual combat drill, there are actual code.

Source: Internet
Author: User

Vertical Sub-table technology

Vertical segmentation refers to: The table is not a lot of records, but the field is very long, the table occupies a large amount of space, when retrieving the table need to execute a large number of IO, severely reduce performance. You need to split the large field into another table, and the table is a one-to-a-kind relationship with the original table.

1, vertical table technology first of all to pay attention to the design of the database, some fields larger data exist in another table. For example: article content. The IDs of the two tables correspond to one by one, and the first part of their table name is the same, and the end of the table is followed by a ' _data '. Convenient data manipulation at the back.

2, after the data table design is the data storage, here is noted that the ID of the two tables is one by one corresponding . Nonsense not much to say, the direct code:

1 /*2 This example is the use of phpcms, not familiar with this framework of friends also do not matter, may instantiate the model is in Phpcms way, others are native PHP knowledge3 */4 5 /*Storage of Data*/6 $this- Case= Pc_base::load_model (' Case_model ');//instantiate a case model, such as THINKPHP5: $case =new cases ();7 $info=Array();//for storing normal data8 $content=Array();//for storing Big data9 $info[' Name ']=$_post[' Name '];Ten $info[' Phone ']=$_post[' Phone ']; One $info[' Email ']=$_post[' Email ']; A  - $id=$this- Case->insert ($info);//The data of the small section is stored in the main table, and the ID is returned; -  the $this- Case->table_name=$this- Case->table_name. ' _data ';//set the data table as a schedule and go to the schedule to inquire about the relevant contents; - $content[' Content ']=$_post[' Content ']; - $content[' ID ']=$id; - $this- Case->insert ($content);

3, the reading of the data, the key to reading data is to use the Array_merger () method to merge two of data :

Definition and usage
The Array_merge () function merges one or more arrays into an array.
Tip: You can enter one or more arrays into the function.
Note: If two or more array elements have the same key name, the last element overrides the other element.
Note: If you enter an array only to the Array_merge () function, and the key name is an integer, the function returns a new array with an integer key name, with the key name re-indexed starting at 0.

1 /*reading of data*/2 $userid=$_get[' UserID '];//get article ID3 $data=$this- Case->get_one (Array(' id ' = =$id));//data, such as Think5:case::get ([' id ' = $id]);4 $this- Case->table_name=$this- Case->table_name. ' _data ';//set the data table as a schedule and go to the schedule to inquire about the relevant contents;5 $datas=$this- Case->get_one (Array(' id ' = =$id));//A field that is queried to a schedule; Content and the like. 6 $data=Array_merge($data,$datas);//By merging two data, you get the final data you want .

MySQL Vertical sub-table technology, the actual combat drill, there are actual code.

Related Article

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.