php - MySQL Performance - "IN" Clause vs. Equals (=) for a Single Value -
this pretty simple question , i'm assuming answer "it doesn't matter" have ask anyway...
i have generic sql statement built in php:
$sql = 'select * `users` `id` in(' . implode(', ', $object_ids) . ')'; assuming prior validity checks ($object_ids array @ least 1 item , numeric values), should following instead?
if(count($object_ids) == 1) { $sql = 'select * `users` `id` = ' . array_shift($object_ids); } else { $sql = 'select * `users` `id` in(' . implode(', ', $object_ids) . ')'; } or overhead of checking count($object_ids) not worth saved in actual sql statement (if @ all)?
neither of them matter in big scope of things. network latency in communicating database far outweigh either count($object_ids) overhead or = vs in overhead. call case of premature optimization.
you should profile , load-test application learn real bottlenecks are.
Comments
Post a Comment