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

Method execute

src/adapter/src/client.rs:771–829  ·  view source on GitHub ↗
(
        &mut self,
        portal_name: String,
        cancel_future: impl Future<Output = std::io::Error> + Send,
        outer_ctx_extra: Option<ExecuteContextGuard>,
    )

Source from the content-addressed store, hash-verified

769 /// triggering the execution of the underlying query.
770 #[mz_ore::instrument(level = "debug")]
771 pub async fn execute(
772 &mut self,
773 portal_name: String,
774 cancel_future: impl Future<Output = std::io::Error> + Send,
775 outer_ctx_extra: Option<ExecuteContextGuard>,
776 ) -> Result<(ExecuteResponse, Instant), AdapterError> {
777 let execute_started = Instant::now();
778
779 let mut outer_ctx_extra = outer_ctx_extra;
780
781 // Unroll SQL `EXECUTE <prepared> (...)` so the inner statement
782 // flows through `try_frontend_peek` below, rather than being
783 // re-dispatched via `Command::Execute` from the coordinator's
784 // `Plan::Execute` handler. Without this, a prepared statement
785 // would route differently from the same statement issued
786 // directly.
787 //
788 // On a successful unroll, `unroll_sql_execute` also returns a
789 // catalog snapshot (threaded through to avoid taking a second
790 // one) and begins EXECUTE-level statement logging on the outer
791 // portal — so `mz_statement_execution_history` records
792 // `EXECUTE foo (...)`, not the inner SQL — installing the
793 // resulting `ExecuteContextGuard` into `outer_ctx_extra`.
794 let (portal_name, catalog) = self
795 .unroll_sql_execute(portal_name, &mut outer_ctx_extra)
796 .await?;
797
798 // Attempt peek sequencing in the session task.
799 // If unsupported, fall back to the Coordinator path.
800 // TODO(peek-seq): wire up cancel_future
801 let peek_result = self
802 .try_frontend_peek(&portal_name, catalog, &mut outer_ctx_extra)
803 .await?;
804 if let Some(resp) = peek_result {
805 debug!("frontend peek succeeded");
806 // Frontend peek handled the execution and retired outer_ctx_extra if it existed.
807 // No additional work needed here.
808 return Ok((resp, execute_started));
809 } else {
810 debug!("frontend peek did not happen, falling back to `Command::Execute`");
811 // If we bailed out, outer_ctx_extra is still present (if it was originally).
812 // `Command::Execute` will handle it.
813 // (This is not true if we bailed out _after_ the frontend peek sequencing has already
814 // begun its own statement logging. That case would be a bug.)
815 }
816
817 let response = self
818 .send_with_cancel(
819 |tx, session| Command::Execute {
820 portal_name,
821 session,
822 tx,
823 outer_ctx_extra,
824 },
825 cancel_future,
826 )
827 .await?;
828 Ok((response, execute_started))

Callers 15

trackSignupInHubspotFunction · 0.45
submitOnboardingSurveyFunction · 0.45
pg_execute_preparedFunction · 0.45
bootstrap_tablesMethod · 0.45
support_execute_oneMethod · 0.45
create_connectionFunction · 0.45
execute_stmtFunction · 0.45
test_subscribe_basicFunction · 0.45

Calls 4

nowFunction · 0.85
unroll_sql_executeMethod · 0.80
send_with_cancelMethod · 0.80
try_frontend_peekMethod · 0.45