It depends on how many thousands of thousands means and how big the array gets into memory. If you can handle this in PHP, you have to do it because using mysql creates a little overhead here.
memory_limit php.ini , MySQL.
, Memcached Redis, (Redis promises O (1))