News for hackers. Stuff that matters.
Re:Medium-hard SQL interview questions by barbegal on Saturday May 02, 2020 @04:39PM (#23054724)
DISTINCT generally requires the results to be sorted which has O(n^2) worst performance so it can have a big performance hit on a query. It is best to make your database structure such that queries only return distinct data. E.g. by disallowing duplicates
Re:Medium-hard SQL interview questions by namibj on Saturday May 02, 2020 @10:11PM (#23056345)
If your sorting algorithm degrades to anywhere near O(n^2) in pathological cases, you're doing something wrong. And even if it's just a kind of timeout/operations-limit to detect pathological cases and just run an in-place mergesort instead. Tail latency/containing pathological data is quite important if there's any interactivity.