Yes, it’s most efficient to emit the data you need into the value during the map function, because getting the value from the
QueryRow doesn’t cause an extra database lookup.
QueryRow.document is implemented as
db.getDocument(row.documentID). That is, each query row stores the ID of the document that emitted it, but loading the document may take another database lookup.
Two exceptions to this:
- Don’t store more in the value than you need. The bigger the value the more overhead there is to reading the query row.
- The database does cache recently-used documents in memory, so if the row’s document is already cached, getting the document is extremely cheap.