Not the answer you need?
Register and ask your own question!

why coerce the column instead of a constant?

takeshi14121990takeshi14121990 EntrantCurrent User Role Beginner
So if I have a table


CREATE TABLE examples ( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, external_id CHAR(12) NOT NULL, data INT(11), INDEX (external_id)) Engine=InnoDB;


and I query it like so:


SELECT * FROM examples WHERE external_id = 1


I can't use the index, because MySQL thinks it must coerce the external_id column to an INT in order to evaluate the where clause. Is there any good reason why it just doesn't coerce the constant into a CHAR(12)?

Just curious.
Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.