MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / query

Method query

src/pgwire/src/protocol.rs:1178–1229  ·  view source on GitHub ↗
(&mut self, sql: String, received: EpochMillis)

Source from the content-addressed store, hash-verified

1176 /// For implicit transaction handling, see "Multiple Statements in a Simple Query" in the above.
1177 #[instrument(level = "debug")]
1178 async fn query(&mut self, sql: String, received: EpochMillis) -> Result<State, io::Error> {
1179 // Parse first before doing any transaction checking.
1180 let stmts = match self.parse_sql(&sql) {
1181 Ok(stmts) => stmts,
1182 Err(err) => {
1183 self.send_error_and_get_state(err).await?;
1184 return self.ready().await;
1185 }
1186 };
1187
1188 let num_stmts = stmts.len();
1189
1190 // Compare with postgres' backend/tcop/postgres.c exec_simple_query.
1191 for StatementParseResult { ast: stmt, sql } in stmts {
1192 // In an aborted transaction, reject all commands except COMMIT/ROLLBACK.
1193 if self.is_aborted_txn() && !is_txn_exit_stmt(Some(&stmt)) {
1194 self.aborted_txn_error().await?;
1195 break;
1196 }
1197
1198 // Start an implicit transaction if we aren't in any transaction and there's
1199 // more than one statement. This mirrors the `use_implicit_block` variable in
1200 // postgres.
1201 //
1202 // This needs to be done in the loop instead of once at the top because
1203 // a COMMIT/ROLLBACK statement needs to start a new transaction on next
1204 // statement.
1205 self.ensure_transaction(num_stmts, "query").await?;
1206
1207 match self
1208 .one_query(stmt, sql.to_string(), LifecycleTimestamps { received })
1209 .await?
1210 {
1211 State::Ready => (),
1212 State::Drain => break,
1213 State::Done => return Ok(State::Done),
1214 }
1215 }
1216
1217 // Implicit transactions are closed at the end of a Query message.
1218 {
1219 if self.adapter_client.session().transaction().is_implicit() {
1220 self.commit_transaction().await?;
1221 }
1222 }
1223
1224 if num_stmts == 0 {
1225 self.send(BackendMessage::EmptyQueryResponse).await?;
1226 }
1227
1228 self.ready().await
1229 }
1230
1231 #[instrument(level = "debug")]
1232 async fn parse(

Callers 5

advance_readyMethod · 0.45
queryFunction · 0.45
query_preparedFunction · 0.45
pg_query_preparedFunction · 0.45
newMethod · 0.45

Calls 15

parse_sqlMethod · 0.80
is_aborted_txnMethod · 0.80
aborted_txn_errorMethod · 0.80
ensure_transactionMethod · 0.80
one_queryMethod · 0.80
is_txn_exit_stmtFunction · 0.70
readyMethod · 0.45
lenMethod · 0.45
to_stringMethod · 0.45
is_implicitMethod · 0.45
transactionMethod · 0.45

Tested by

no test coverage detected