select count(snrdown)
from dsl_data,dslam_ports
where dslam_ports.dslam_id='$dslamid'
and dsl_data.port_id=dslam_ports.id
and dsl_data.snrdown > 399
How many rows of dslam_ports have dslam_id='$dslamid' ?
How many rows of dsl_data have snrdown > 399 ?
Assuming these exist:
INDEX(dslam_id)
INDEX(snrdown)
then the optimizer will start with whichever table has the smaller number of rows. But then it has to reach into the other table via port_id to filter on the other restriction. Not cheap. Not fast.
If dslam_id and snrdown were in the same table, that this index would make it run much faster:
INDEX(dslam_id, snrdown)
A summary table keyed by dslam_id and, say, snrdown DIV 100 might cover a bunch of queries (snrdown > 299, snrdown > 599, srndown < 400, etc; but not snrdown > 350)