3 ms·
Thanks for the detailed answer, but I don't think this is right. I will attempt to be as civil as you in my rebuttal :) The key point I think your perspective
by robertlagrant 4y ago
Thanks for the detailed answer, but I don't think this is right. I will attempt to be as civil as you in my rebuttal :)
The key point I think your perspective foregoes is that documents aren't like tables, and columns aren't like fields. A document holds one complete entity. A table holds a part of the information for all entities.
As an example, if I were a bookshop, and I chose to store books in an RDBMS, I might store their prices in a price table that just has id, book_id and price_in_cents in it (ignoring valid_from and valid_to niceties). If I store them in a document database, I would have a price field embedded in each Book document.
If we wanted to operate on all the prices, say to generate a histogram of all current book prices, I can query my RDBMS table for each price per book. The RDBMS knows exactly where to look in the data file(s) as it operates on fixed byte offsets defined in the table schema. The document database needs to jump into each document, pull out the price, find the next document and repeat. This is very far from fixed offsets, and likely involves loading far more data into memory in the first place.
I await a rebuttal with interest :)
- redwood 4y agoThis is what secondary indexes enable: if you have a sub-field of the document for price and you have a secondary index on that sub-field, you can do a covered query straight out of the index on an aggregate of that price field. Essentially in your example you could think of the price table that you described as effectively a secondary index style data structure in a user space table.. but why not just make it an index that the database engine manages consistently for you?
- robertlagrant 4y agoWell, I suppose because indexes can slow some things down (e.g. writes), and can also fail to speed other things up. They're not a magical answer to everything, or they'd be on by default on everything! But let's take your example of using an index to get all prices. How would that work?
- redwood 4y agoYou would do an aggregate query on the price field grouped by price