• Not enough information here, but I can guess that this query would benefit from a filter by date on table B. (At the least).

    ----------------------------------------------------