Every flight has a flight plan. Every query has a query plan. You must have seen its text form, called EXPLAIN PLAN. Query optimizer is responsible for creating this query plan for every query, and it tries to create an optimal plan for every query. In Couchbase, the query optimizer has to choose the most optimal index for the query, decide on the predicates to push down to index scans, create appropriate spans (scan ranges) for each index, understand the sort (ORDER BY) and pagination (OFFSET, LIMIT) requirements, and create the plan accordingly. When you think there is a better plan, you can hint the optimizer with USE INDEX. This talk will teach you how the optimizer selects the indices, index scan methods, and joins. It will teach you the analysis of the optimizer behavior using EXPLAIN plan and how to change the choices optimizer makes.
Data-parallel — Query latency scales up with cores
Memory-bound
Data-parallel — Query latency scales up with cores
Memory-bound
Step 1. Scan brewery using index on brewery_state. Predicate brewery.state = ”California”
Step 2. Using the meta(brewery).id as the matching value, scan brewery_id to get the meta(beer).id
Step 3. If you do find the matching document, you have meta(beer).id, fetch the beer document to do the JOIN
Step 4. Do the JOIN and project necessary projections.
Step 5. Do the GROUP BY
Step 6. Do the aggregation & projection.