Chris Biscardi: On the left, we have an FQL query. We match on the index of all customers. We paginate that match. We map over the result set. We're getting each of the refs. If we run this query, we can see that we actually get a full list of all the documents, including all of the fields.
If we take a look at the headers for the request that we just sent to the database in the Chrome pane, we can see that one of the headers is X-Read-Ops. X-Read-Ops tells us how many read ops our query made. In this case, we made four. Since we only have three records, that's not a huge deal.
Let's say we had many, many, many records. To reduce the number of read ops, we can use an index. Here in our list of indexes, we can see that we have all customers and a couple of other indexes. We'll create a new index.
Since we're querying all customers, we'll put it on the customers collection. We'll name our index, and we'll leave terms empty.
For values, we'll include the firstName, lastName, and telephone. Note that for each field, our value was auto-completed to data.firstname. We can see that our index, all_customers_with_fields, includes all of our documents -- the firstName, the lastName, and the telephone.
Let's go back to our Shell. Remember that our last query required a read op for every Get, and a read op for the index. If we just run the Paginate on the Match, we can see that we get a number of Refs. If we switch the index to use our new index, all_customers_with_fields, we can see that we got all of the data that we looked for in the index, including the first name, the last name, and the telephone number.
If we check the headers on our request, we can see that our read ops are now one. We have successfully reduced the number of read ops our query is using by taking advantage of an index.