Query Plan Caching in CockroachDB

Query Plan Caching in CockroachDB

We’ll start with an overview of the stages of the query planning process; then we’ll go over the methods clients can use to issue queries against CockroachDB, and finally we’ll discuss the caching work we have done to speed up query planning. This caching also speeds up the execution step of prepare-each, but this method is still relatively inefficient because of the prepare step (which runs for every query instance). Recall the benchmark that breaks down query planning time by phases:

If we use the prepare-once method and execute a previously prepared statement, we store the result of the Parse/OptBuild/Normalize stages with the prepared statement and on each execution we can proceed with the stages:

This is a significant (more than 50%) reduction in planning time.

Source: cockroa.ch