Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upCache prepared statements #98
Comments
This comment has been minimized.
|
Ok so I've started looking into this a little bit, and my first pass worked similarly to Rails, where I calculated the statement name from the hash of the SQL string. I actually started to wonder if this was even worth it, as to my knowledge PG will perform query planner caching automatically regardless. However, I've come to realize that due to how our query builder works, we can do much better than that. As long as an AST contains no We can also determine whether an AST contains a
pub trait QueryFragment {
fn is_preparable() -> bool;
fn to_sql(&self, out: &mut QueryBuilder) -> BuildQueryResult;
fn collect_bind_params(&self, out: &mut BindParamCollector) -> BuildQueryResult;
}
While |
This comment has been minimized.
|
This might not actually work for our case, since At the end of the day, if we do end up having to compute the hash of the SQL string, that's fine too. I'd still like to change our query builder to be 2 pass, as that will potentially be helpful for SQLite support, and will make this optimization easier in the future. |
sgrif commentedJan 15, 2016
Currently we're never caching a prepared statement (though we are preparing them). We should put these in an LRU cache automatically, with a configurable size. Beyond the ability to specify the size, this should be a completely opaque change.