Why are certain types of prepared queries using PDO in PHP with MySQL slow?

后端 未结 3 937
庸人自扰
庸人自扰 2020-12-04 20:10

When using SELECT * FROM table WHERE Id IN ( .. ) queries with more than 10000 keys using PDO with prepare()/execute(), the performance degrades ~10X more than

3条回答
  •  生来不讨喜
    2020-12-04 20:45

    Make sure you're telling PDO that the value is an integer not a string; if PDO puts it as a string, then MySQL will have to typecast the values for comparison. Depending on how it goes about this, it could cause major slowdowns by causing MySQL to avoid using an index.

    I'm not completely sure about the behaviour here, but I have had this problem with Postgres a few years back...

提交回复
热议问题