Given a table of N records, what would be considered the fastest way of getting a single random PK from that table(for later use in php)?
The two methods I'm wondering about are :
mysql : perform the random query directly and get a single ID as the query result.
php : get a list of IDs from mysql and use array_rand()
to fetch one at random
Also : Does scale matter for such a query? Would a table N=200
records be faster using mysql but a table of N=200,000
be faster with php?(or vice verca)
My intuition tells me that MySQL should be faster and use much less memory, as you must create an array of N
keys using the php method and store them at least temporarily.