Company
Date Published
Author
Bingjie Miao, Principal Software Engineer Couchbase
Word count
2739
Language
English
Hacker News points
None

Summary

Couchbase Server 7.0 Enterprise Edition introduces a Cost-Based Optimizer (CBO) to replace the previous Rule-Based Optimizer (RBO), aligning with the evolution seen in other major relational databases. The CBO relies on optimizer statistics gathered through new SQL++ (N1QL) statements, UPDATE STATISTICS or ANALYZE, which are issued manually to compute statistics on keyspaces, collections, indexes, and term distributions. These statistics are stored in a newly created N1QL_SYSTEM_BUCKET and are available across multiple query nodes, but if the bucket is dropped, the system reverts to RBO until statistics are re-analyzed. The CBO setup also includes options for customizing statistics collection, such as resolution, sample size, and batch size, to optimize resource use and analysis time. Additionally, users can specify which fields or expressions require statistics, including those in WHERE, ON, GROUP BY, and ORDER BY clauses, as well as array index expressions. The system introduces new system keyspaces for managing these statistics, and the EXPLAIN output now includes optimizer estimates, signifying the use of CBO in query planning. However, the process is manual, necessitating regular updates, potentially via automated jobs like cron, to maintain optimal performance.