$offset = SELECT FLOOR(RAND() * COUNT(*)) FROM t_table
SELECT * FROM t_table WHERE LIMIT $offset,1
This works great in myisam but i would like to change this table to innodb (all other db tables are innodb) to take advantages of foreign-keys and avoid table level locking.
The primaryId field of this table is a VARCHAR(10)
I can't "force" a numeric autoinc Id, because records are deleted/added all the time and a RANDOM(MIN(Id), MAX(Id)) prediction would probably miss rows lots of times.
how can i optimize this query to innodb?
Thanks in advance!
Arthur