I have a DB table with 4.1 million unique rows of dword number blocks, indexed on start.
start end location
1259273696 1259273703 11532
1259273704 1259273704 4249
1259273705 1259273705 3487
1259273706 1259273711 4249
1259273712 1259273727 11532
1259273728 1259273791 117384
1259273792 1259273855 4053
1259273856 1259273983 117384
1259273984 1259274239 116001
etc....
$sql = "
SELECT location
FROM blocks
WHERE start<=" . $dword . "
AND end>=" . $dword . "
LIMIT 1";
$loc_code = $db->get_sql_field($sql,'location');
the query works, but with the DB size, the query is very slow. I also tried BETWEEN, also very slow.
any suggestions on how to improve the query?
perhaps using the row prior to the result row?
WHERE start>= $dword
if so, how can I select the row prior to the query result row?
thanks !
start end location
1259273696 1259273703 11532
1259273704 1259273704 4249
1259273705 1259273705 3487
1259273706 1259273711 4249
1259273712 1259273727 11532
1259273728 1259273791 117384
1259273792 1259273855 4053
1259273856 1259273983 117384
1259273984 1259274239 116001
etc....
$sql = "
SELECT location
FROM blocks
WHERE start<=" . $dword . "
AND end>=" . $dword . "
LIMIT 1";
$loc_code = $db->get_sql_field($sql,'location');
the query works, but with the DB size, the query is very slow. I also tried BETWEEN, also very slow.
any suggestions on how to improve the query?
perhaps using the row prior to the result row?
WHERE start>= $dword
if so, how can I select the row prior to the query result row?
thanks !