2 ms·
>one of the worst-performing SQL queries I've ever seen voter left join precinct left join party where filter(voter) would work just fine even if precinct and
by trhway 7y ago
>one of the worst-performing SQL queries I've ever seen
voter left join precinct left join party where filter(voter)
would work just fine even if precinct and party aren't primary indexed as the number of precincts is just too low (1700) to cause any issues - an optimizer like Oracle would drive the query from the voter while applying filter to it (indexes on the first/last name and/or address would speed the filtering obviously) and looking up precincts by index (in case of precincts not having the index it would just scan the precincts in case of a small filtered voter set or hash the precincts and do hash lookup in case of a larger filtered voter set). For party it is the same, just for 2 parties it doesn't matter - index, scan or hash, etc.
The main issue is as always at business logic and data quality level - it seems that there are supposedly voters without precincts, and precincts without parties :)