Test the index usage of parameter integer and string type errors in mysql Query

Source: Internet
Author: User
Tags numeric mysql query

Prepare Data:
Create table 'test _ idx '(
'I' int (10) NOT NULL,
'S 'varchar (10) not null,
KEY 'I' ('I '),
KEY's '('s ')
) ENGINE = InnoDB default charset = utf8;
 
Insert into test_idx (I, s) values (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9 ');

Test 1:

Explain select * from test_idx where I = 1;
Explain select * from test_idx where I = '1 ';

Result:

Numeric index. Indexes can still be used with quotation marks.
Test 2:
Explain select * from test_idx where s = 1;
Explain select * from test_idx where s = '1 ';

Result:

String index without quotation marks. The index is invalid.
Test 3:
Explain select * from test_idx where I in (1, 2 );
Explain select * from test_idx where I in (1, '2 ');

Result:

The compound query index is invalid in the numeric index.
Test 4:
Explain select * from test_idx where s in ('1', '2 ');
Explain select * from test_idx where s in (1, '2 ');

Result:

The compound query index is invalid in the string index.

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.