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