About MySQL compound-statement SQL

Source: Internet
Author: User

In the MySQL compound-statement SQL background, sending multiple statements to MySQL can reduce the number of network interactions. In case of transactions, the lifetime of transactions on a single thread can be shortened. Writing business logic into a stored procedure is a form, but considering this, binding the business logic to the server is not the best choice. Some people mentioned the hope that MySQL can support compound-statement SQL similar to Oracle. In fact, MySQL is supported in MySQL 5.0. When the connection parameter of c api is added to mysql_real_connect, CLIENT_MULTI_STATEMENTS can be separated by semicolons and multiple SQL statements can be sent to the Server together. In fact, in the client that comes with mysql, this bit has been set for the connection parameter. Mysql_real_connect (& mysql, host, user, password, database, opt_mysql_port, opt_mysql_unix_port, connect_flag | CLIENT_MULTI_STATEMENTS) MySQL client usage, but even so, users enter multiple SQL statements differentiated by semicolons on the client, in fact, it is sent in order after the client is split. That is to say, a statement like this is mysql> insert into test123 values (1, 'A'); insert into test123 values (2, 'A'); in fact, the first insert is completed first, send the second response. The reason is that the mysql client uses ";" as the statement terminator when parsing user input. Redefines the statement Terminator. In fact, to implement the syntax of multiple statements, we used it when creating the stored procedure. Delimiter; begin; insert into test123 values (1, 'aaaaa'); insert into test123 values (1, 'aaaaa'); insert into test123 values (1, 'aaaaa'); commit; in this way, the second line is sent to the server. It indicates that the compound-statement method is about 20% higher than the single-thread performance under the stress of a Single-thread test in the preceding scenario, because the number of network interactions is reduced. Under the multi-thread pressure, whether or not the performance is improved depends on the mutex between the transactions of each thread. The benefit of performance improvement is that the transaction lifetime of a single thread is shortened.

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.