How MySQL implements cross-pants query

Source: Internet
Author: User

Scenario one, field redundancy. In other words, a part of the information is repeated, such as Pay_log table in addition to the UserID field and User_name field, and so on. However, this is only suitable for a small number of fields, if the registration, login time, level and so on all fields are repeated, it is obviously unscientific.

Scenario Two, table replication and synchronization. In other words, the User_info table inside the main_db is copied to the log_db, and then the scheduled task is set to synchronize the two tables. This can be done in a library, and then can be a JOIN and other complex statement operations. But the contents of the two tables are repetitive, which is a bit of a waste of space.

Program three, link table. What is a linked table? Simply put, there is a user_info table in the log_db, but the table does not store data, but is linked directly to the User_info table in main_db. In this way, we can do this without having to synchronize regularly, or we can use joins in the same library.

Using the code of the Federated engine, Federated is turned off by default, and needs to modify the configuration to turn on the engine

CREATE TABLE ' user_info ' (  ' userid ' int (one) ' Not NULL auto_increment COMMENT ' user ID ',  ' username ' varchar ' not NUL L default ' COMMENT ' account ',  ' level ' int (one) NOT null default ' 1 ' COMMENT ' rank ',  ' log_dt ' timestamp NOT NULL default ' 2016-11-30 00:00:00 ' COMMENT ' last login time ',  ' Reg_dt ' timestamp not NULL DEFAULT current_timestamp COMMENT ' registration time ',  PRIMARY key (' userid '),  key ' idx_name ' (' username ')) engine=federated DEFAULT Charset=utf8 row_format=compact connection= ' Mysql://batsing:[email protected]:3306/main_db/user_info '  comment= ' user basic information table-Link table ';

  

Original: http://www.cnblogs.com/batsing/p/federated.html

How MySQL implements cross-pants query

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.