DISTINCT was unnecessary here, and was causing sqlite to choose lousy
query plans.