Improving query to use indexes better. Fixes #5101

As hinted at in the table, this fixes #5101 
enabled seems to only be toggled between 0 and 1, so if we check for everything greater than 1, we only have one value and then we can simply do a comparison. State equally seems to toggle between 0 and 1, although we don't seem to use it at all... This should be investigated further.