Mysql MERGE engine is used in a sub-table environment

Source: Internet
Author: User

Application scenario: When we are doing the sub-table, we usually split the data of a large table into several sub-tables, which is also the concept of the sub-table in database optimization. The problem with the sub-table is the multi-table query.

Now there are t1,t2 two data tables, need to meet the different query conditions at the same time from the two tables to query data, but also to achieve sorting, paging and other requirements.

[T1 table]

1 CREATE TABLE' T1 ' (2' ID 'int(Ten) unsigned not NULLAuto_increment,3' Name 'varchar(Ten) not NULL,4   PRIMARY KEY(' id '),5   UNIQUE KEY' name ' (' name ')6) ENGINE=MyISAM auto_increment=3 DEFAULTCHARSET=Utf8

[T2 Table]

1 CREATE TABLE' T2 ' (2' ID 'int(Ten) unsigned not NULLAuto_increment,3' Name 'varchar(Ten) not NULL,4   PRIMARY KEY(' id '),5   UNIQUE KEY' name ' (' name ')6) ENGINE=MyISAM auto_increment=4 DEFAULTCHARSET=Utf8

[t Table]

1 CREATE TABLE' t ' (2' ID 'int(Ten) unsigned not NULLAuto_increment,3' Name 'varchar(Ten) not NULL,4   PRIMARY KEY(' id '),5   UNIQUE KEY' name ' (' name ')6) ENGINE=Mrg_myisamDEFAULTCHARSET=UTF8 Insert_method=LastUNION=(' T1 ', ' T2 ')

Using SQL to see that the engine specifying the T table is the MERGE (Mrg_myisam also), the Insert_method meaning is how we handle the table t when we insert it

Engine (specify table engine)

Union (tables that need to be combined)

Syntax: UNION (' t1 ', ' T2 ', ' T3 ' ..., ' TN ')

Insert_method (insert mode)

    • 0 Insert not allowed
    • First inserts into the second table
    • Last inserted into the final table

Attention:

    • The MERGE Word table must be a Myisam engine
    • If the same primary key exists in a federated table, when the primary key is a query condition, the waiting query is stopped after the winner key in the first table.
    • Deleting a federated table directly causes the MERGE table to become corrupted, and it is a good practice to remove the union relationship first.

Mysql MERGE engine is used in a sub-table environment

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.