Disadvantages of quoting integers in a Mysql query?

后端 未结 4 1267
天涯浪人
天涯浪人 2020-12-06 18:56

I am curious about the disadvantage of quoting integers in MYSQL queries

For example

SELECT col1,col2,col3 FROM table WHERE col1=\'3\';
4条回答
  •  青春惊慌失措
    2020-12-06 19:56

    The performance cost is that whenever mysql needs to do a type conversion from whatever you give it to datatype of the column. So with your query

    SELECT col1,col2,col3 FROM table WHERE col1='3';

    If col1 is not a string type, MySQL needs to convert '3' to that type. This type of query isn't really a big deal, as the performance overhead of that conversion is negligible.

    However, when you try to do the same thing when, say, joining 2 table that have several million rows each. If the columns in the ON clause are not the same datatype, then MySQL will have to convert several million rows every single time you run your query, and that is where the performance overhead comes in.

提交回复
热议问题