The query is inaccurate because the decimal field of apsaradb for MySQL is too large

Causes

The decimal field size of apsaradb RDS for MySQL is too large and the query cannot be accurate, which is caused by a BUG in the MySQL database.

Fixes

You can solve the problem by adding an index. The SQL statement for optimization is as follows:

  1. create table mlgtestdecimal(`campaign_id` decimal(24, 0) NOT NULL, name VARCHAR(50));
  2. insert into mlgtestdecimal(campaign_id, name)
  3. VALUES('XXXXXXX','XXXXXX');
  4. insert into mlgtestdecimal(campaign_id, name)
  5. VALUES('XXXXXXX','XXXXXX');
  6. SELECT *
  7. from mlgtestdecimal
  8. where campaign_id='XXXXXXX'
  9. and name='XXXXXX'
  10. alter table mlgtestdecimal add index ind_decimal (`campaign_id`);

Application scope

ApsaraDB RDS for MySQL