samedi 16 mai 2015

MySQL RAND() optimization with LIMIT option

I have 50,000 rows in table and i am running following query but i heard it is a bad idea but how do i make it work better way?

mysql> SELECT t_dnis,account_id FROM mytable WHERE o_dnis = '15623157085' AND enabled = 1 ORDER BY RAND() LIMIT 1;
+------------+------------+
| t_dnis     | account_id |
+------------+------------+
| 5623157085 | 1127       |
+------------+------------+

Any other way i can make is query faster or user other options?

I am not DBA so sorry if this question asked before :(




Aucun commentaire:

Enregistrer un commentaire