Timeline for Fetch the most recently updated records in a database across multiple tables in a performant manner
Current License: CC BY-SA 4.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 15, 2021 at 8:53 | comment | added | Ewan | "short cuts mean long delays" Gandalf | |
| Aug 14, 2021 at 21:08 | comment | added | Philipp Doerner | @joshp 1) Where is ordering + limiting ? - Fair point! I added a shortened version of a Django view I'm using for the serialization and pagination. The ordering happens there by defining the queryset with an order_by("-update_datetime") and limiting by taking a slice of the queryset. 2) UNION: That's a fair point, I adjusted the query accordingly. | |
| Aug 14, 2021 at 21:05 | history | edited | Philipp Doerner | CC BY-SA 4.0 | Expanded upon where ordering and limiting to n most recent articles occurs as requested by joshp |
| Aug 14, 2021 at 19:59 | comment | added | joshp | The UNION query approach is solid. As long as the update time is indexed in the underlying tables you can go far with this. However, for most RDBMS, you would be better off using "UNION ALL". UNION (a set operation) requires SQL to guarantee no duplicate rows in the result. This often results in an extra sort/remove duplicates operation. Your underlying queries already guarantee unique results, but the optimizer is unlikely to figure that out. This is a common mistake, easy to fix. UNION ALL means don't insure uniqueness, return all rows. As data grows the difference can be quite significant. | |
| Aug 14, 2021 at 19:46 | comment | added | joshp | Your original question was to find the most recent articles. Where does that ordering or limiting to n most recent occur in this code example? As I read it the code might retrieve all articles in an undefined order. The undefined order might happen to be the order you want, until you change something. | |
| Aug 14, 2021 at 17:49 | history | answered | Philipp Doerner | CC BY-SA 4.0 |