dotancohen / squeal

Database explorer with a focus on breadth, not depth.
2 stars 0 forks source link

Random row selector fails when primary keys are not sequential. #9

Open dotancohen opened 10 years ago

dotancohen commented 10 years ago

Consider the case where a table has a non-sequential primary key, such as if that primary key is a phone number:

   Some random records
   -------------------
+----+------+---------+------+-------+-----+---------+-------+--------+----------+-------------+-----------------+-
| id | name | address | city | state | zip | country | phone | source | campaign | search_term | search_location | 
+----+------+---------+------+-------+-----+---------+-------+--------+----------+-------------+-----------------+-
+----+------+---------+------+-------+-----+---------+-------+--------+----------+-------------+-----------------+-
Time: 110.1562

Instead, try comparing the primary key to a modulus, then use limit to get results deeper in the database:

mysql> select phone from phone_list where phone mod 3251 = 0 limit 233, 3;
+------------+
| phone      |
+------------+
| 7162040777 |
| 4804978000 |
| 4807269955 |
+------------+
3 rows in set (0.38 sec)