4 ms·
It would be nice if they could go more into detail about how they decide whether a query is read or write. The casual mention of this makes it sound like they
by hamburglar 2y ago
It would be nice if they could go more into detail about how they decide whether a query is read or write. The casual mention of this makes it sound like they originally took a too-naive approach (looking at the first word) but even ignoring CTEs, you can still have an UPDATE within a SELECT subquery, which makes the problem very hard without parsing the whole query. Perhaps the C++ code extracted from pg handles this for them and returns some metadata that indicates whether there are any writes buried in the query?
- levkk 2y agoForgot to add that to the article, but yes, we parse the statement and route SelectStmt[1] to replicas. If there is an UPDATE in the SELECT, we don't handle that at the moment, but can be easily added. [1] https://docs.rs/pg_query/6.0.0/pg_query/protobuf/struct.SelectStmt.html https://docs.rs/pg_query/6.0.0/pg_query/protobuf/struct.Sele...
- hamburglar 2y agoDo you have to traverse the syntax tree to determine that?
- levkk 2y agoYup.