Hacker News new | ask | show | jobs
by johncs 2284 days ago
> This pattern of access is simple and intuitive but causes huge problems in even small projects. Retrieving whole rows is hugely wasteful when only part of the row is required to resolve a user request.

Retrieving a whole row rather than just a single column from a database that's likely on a local network definitely doesn't seem "hugely wasteful", especially for smaller projects.

2 comments

Author here - I'm afraid it is hugely wasteful. The network is really nothing to do with it but instead the fact that you have to make a table read instead of an index read. This seems like a small thing but as I describe it changes the complexity class of the algorithm you have effectively written.
How does it change the complexity class of an algorithm?

Database performing a table read because additional columns were requested shouldn't change the complexity class if the query was otherwise successfully satisfied using the index.

I searched the article for "complexity class" and, while I found the phrase, it didn't explain much.

Sorry, yes, you're right. It doesn't change the complexity class just because you have to go to the heap. It is however a lot slower for the usual reasons: the heap is less dense in memory, it's a second thing you have to do, you have to serialise/deserialise more, etc etc.

But yes, you're right: just going to the heap is not a change in complexity class.

It is when you're retrieving thousands of rows/objects.