For parallel insert problems that display the specified lock tables (from other tables)

Source: Internet
Author: User

Document:

If you acquire a table lock explicitly with lock TABLES, you can request a READ LOCAL lock rather
than a READ lock to enable other sessions to perform concurrent inserts while you have the table
Locked.
To perform many INSERT and SELECT operations on a table real_table when concurrent inserts
is not possible, you can insert rows into a temporary table temp_table and update the real table
With the rows from the temporary table periodically. This can is done with the following code:


mysql> lock table T1;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1
mysql> lock table T1 write;
Query OK, 0 rows Affected (0.00 sec)

mysql> INSERT INTO T1 select * from T2;
ERROR 1100 (HY000): Table ' T2 ' is not locked with LOCK TABLES
mysql> Lock table T2;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1
mysql> lock table T2 write;
Query OK, 0 rows Affected (0.00 sec)

mysql> INSERT INTO T1 select * from T2;
ERROR 1100 (HY000): Table ' T1 ' is not locked with LOCK TABLES
mysql> Lock table T1 WRITE,T2 write;
Query OK, 0 rows Affected (0.00 sec)

mysql> INSERT INTO T1 select * from T2;
Query OK, 869 rows affected (0.01 sec)
records:869 duplicates:0 warnings:0

Mysql> unlocks;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near ' unlocks ' on line 1
mysql> unlock tables;
Query OK, 0 rows Affected (0.00 sec)


You can see that you can put the content that you want to insert into the T1 table on a temporary table T2 (temporary table), so that you can avoid locking the table behind select to ensure that you insert it into the table T1;

For parallel insert problems that display the specified lock tables (from other tables)

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.