Military rule applications developed by MySQL database (1)

Source: Internet
Author: User

Slides address: http://www.slideshare.net/mysqlops/mysql-9838563
Comparison of column values of the same data type
Principle: Number-to-number, character-to-Character
Comparison between value columns and Character Types
• Conversion to precision at the same time
• Comparison
Character column and numeric type comparison
• The entire character column is converted to a value of www.2cto.com.
• Index query is not used
The instance displayed on page 43 of slides is a comparison between character columns and numeric values. Compared with the same type, the former consumes about 28 times the latter.
The test results are as follows:
Mysql> select sum (capital) FROM lend_inoutdetail WHERE rec_type = '1' AND user_id =
319;
+ -------------- +
| SUM (capital) |
+ -------------- +
| 1, 11942.5300 |
+ -------------- +
1 row in set (1.08 sec)

Mysql> select sum (capital) FROM lend_inoutdetail WHERE rec_type = 1 AND user_id = 31
9;
+ -------------- +
| SUM (capital) |
+ -------------- +
| 1, 11942.5300 |
+ -------------- +
1 row in set (5.30 sec)

Mysql>
The time difference is about 4 times. The data volume in my database is relatively small. The larger the data volume, the larger the time difference.
I looked back at the project code and found that many character columns are compared with numbers. I need to correct the code and keep this rule in mind in future code.

Excerpt

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.