Another way for mysql to process big data merging

Source: Internet
Author: User

When I was working on a project, I encountered a scenario where there were two tables with a data volume of around million. Now I want to merge these two tables into one table in the production environment, I originally wanted to use the SQL statement insert into select for implementation. Later I found that this operation was slow because of the computing logic. The approximate table structure is as follows:

Table1

Id tel credits1

 

Table 2

Id tel credits2 points

 

The merged table is

Table

Id tel credits points

 

Credits = credits1 + credits2

 

The implementation method I used is as follows:

 

Step 1: Create a view first.

Name: table

The SQL statement is roughly as follows:

Select table2.id, table2.tel, table1.credits1 + table2.credits2 as credits, table2.points from table2 left join table1 on table1.tel = table2.tel

 

It takes about one day to go online. Find an idle period and close the project.

 

Step 2: export the data in the view.

Step 3. Rename the view name as table_copy.

Step 4: Create a table with the field id tel credits points

Step 5: import the data in the view to the table.

 

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.