Other Query Optimization Techniques
So far, we have seen the internal workings of queries and how indexes help limit the number of documents to be scanned. We have also explored various types of indexes and their properties and learned how we can use the correct index and correct index properties in specific use cases. Creating the right index can improve query performance, but there are a few more techniques that are required to fine-tune the query performance. We will cover those techniques in this section.
Fetch Only What You Need
The performance of a query is also affected by the amount of data it returns. The database server and client communicate over a network. If a query produces a large amount of data, it will take longer to transfer it over a network. Moreover, to transfer the data over the network, it needs to be transformed and serialized by the server and deserialized by the receiving client. This means that the database client will have to wait longer to get the...