views:

19

answers:

1
$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

A: 

This doesn't work for you?

SELECT * FROM t_table ORDER BY RAND() LIMIT 1
Kris
This was my first attempt, but the table got bigger and i had to replace it with the query on the question
arthurprs