MySQL Optimization (vii)

Source: Internet
Author: User

31. Examples of Business

How the Myiasm table handles transactions:

mysql> LOCK TABLES Trans READ, customer WRITE;

Mysql> select sum (value) from trans where customer_id=some_id;

Mysql> Update Customer Set Total_value=sum_from_previous_statement

where customer_id=some_id;

Mysql> UNLOCK TABLES;

BdB How the table is transacted:

Mysql> BEGIN WORK;

Mysql> select sum (value) from trans where customer_id=some_id;

Mysql> Update Customer Set Total_value=sum_from_previous_statement

where customer_id=some_id;

Mysql> COMMIT;

Note that you can bypass the transaction with the following statement:

UPDATE customer SET value=value+new_value WHERE customer_id=some_id;

32, use the example of replace

Replace functions like inserts, except that if an old record has the same value as the record on a unique index, the old record is deleted before the new record is inserted. Do not use SELECT 1 from T1 WHERE key=#

IF Found-row

LOCK TABLES T1

DELETE from T1 WHERE key1=#

INSERT into T1 VALUES (...)

UNLOCK TABLES T1;

ENDIF

And with

REPLACE into T1 VALUES (...)

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.