Say I have two lists with values that are returned from a mysql query:
List<String> databaseResultsA List<String> databaseResultsB databaseResultsA is ordered using MySQL ORDER BY ASC, whereas databaseResultsB is not ordered.
I need the two lists combined and ordered ascending, so I do this in the code after:
List<String> combinedResults = Stream.concat(databaseResultsA.stream(), databaseResultsB.stream()).sorted().distinct().collect(Collectors.toList()); My reasoning for sorting databaseResultsA is that I am expecting databaseResultsA to need to return results more frequently than databaseResultsB; therefore, if databaseResultsB is empty, then there would be less sorting in the code (databaseResultsA could be empty and databaseResultsB could have results, but I am not expecting that to happen as frequently as the other way around).
My question is, does my logic sound reasonable? Or would it be better to sort both lists in MySQL and then sort in code? I'm guessing this is something one should judge on a case by case basis, but just wondering if there is a rule of thumb for this.
https://stackoverflow.com/questions/66717279/order-two-lists-in-mysql-before-combining-or-after-in-code March 20, 2021 at 08:54AM
没有评论:
发表评论