@@ -10,8 +10,9 @@ use spacetimedb_client_api_messages::websocket::v1::{self as ws_v1};
1010use spacetimedb_datastore:: {
1111 db_metrics:: DB_METRICS , execution_context:: WorkloadType , locking_tx_datastore:: datastore:: MetricsRecorder ,
1212} ;
13- use spacetimedb_execution:: { pipelined:: PipelinedProject , Datastore , DeltaStore , Row } ;
13+ use spacetimedb_execution:: { pipelined:: PipelinedProject , Datastore , DeltaStore , ExecutionParams , Row } ;
1414use spacetimedb_lib:: { metrics:: ExecutionMetrics , Identity } ;
15+ use spacetimedb_physical_plan:: plan:: ParamResolver ;
1516use spacetimedb_primitives:: { ColList , TableId } ;
1617use spacetimedb_sats:: bsatn:: ToBsatn ;
1718use spacetimedb_sats:: Serialize ;
@@ -104,13 +105,35 @@ pub fn execute_plan_for_view<'p, F>(
104105 tx : & ( impl Datastore + DeltaStore ) ,
105106 rlb_pool : & impl RowListBuilderSource < F > ,
106107) -> Result < ( F :: List , u64 , ExecutionMetrics ) >
108+ where
109+ F : BuildableWebsocketFormat ,
110+ {
111+ execute_plan_for_view_with_params (
112+ plan_fragments,
113+ num_cols,
114+ num_private_cols,
115+ tx,
116+ & ExecutionParams :: empty ( ) ,
117+ rlb_pool,
118+ )
119+ }
120+
121+ /// Execute subscription query fragments over a view with runtime parameters.
122+ pub fn execute_plan_for_view_with_params < ' p , F > (
123+ plan_fragments : impl IntoIterator < Item = & ' p PipelinedProject > ,
124+ num_cols : usize ,
125+ num_private_cols : usize ,
126+ tx : & ( impl Datastore + DeltaStore ) ,
127+ params : & impl ParamResolver ,
128+ rlb_pool : & impl RowListBuilderSource < F > ,
129+ ) -> Result < ( F :: List , u64 , ExecutionMetrics ) >
107130where
108131 F : BuildableWebsocketFormat ,
109132{
110133 build_list_with_executor ( rlb_pool, |metrics, add| {
111134 let col_list = ColList :: from_iter ( num_private_cols..num_cols) ;
112135 for fragment in plan_fragments {
113- fragment. execute ( tx, metrics, & mut |row| match row {
136+ fragment. execute_with_params ( tx, params , metrics, & mut |row| match row {
114137 Row :: Ptr ( ptr) => add ( ptr. project_product ( & col_list) ?) ,
115138 Row :: Ref ( val) => add ( val. project_product ( & col_list) ?) ,
116139 } ) ?;
@@ -125,12 +148,25 @@ pub fn execute_plan<'p, F>(
125148 tx : & ( impl Datastore + DeltaStore ) ,
126149 rlb_pool : & impl RowListBuilderSource < F > ,
127150) -> Result < ( F :: List , u64 , ExecutionMetrics ) >
151+ where
152+ F : BuildableWebsocketFormat ,
153+ {
154+ execute_plan_with_params ( plan_fragments, tx, & ExecutionParams :: empty ( ) , rlb_pool)
155+ }
156+
157+ /// Execute a subscription query with runtime parameters.
158+ pub fn execute_plan_with_params < ' p , F > (
159+ plan_fragments : impl IntoIterator < Item = & ' p PipelinedProject > ,
160+ tx : & ( impl Datastore + DeltaStore ) ,
161+ params : & impl ParamResolver ,
162+ rlb_pool : & impl RowListBuilderSource < F > ,
163+ ) -> Result < ( F :: List , u64 , ExecutionMetrics ) >
128164where
129165 F : BuildableWebsocketFormat ,
130166{
131167 build_list_with_executor ( rlb_pool, |metrics, add| {
132168 for fragment in plan_fragments {
133- fragment. execute ( tx, metrics, add) ?;
169+ fragment. execute_with_params ( tx, params , metrics, add) ?;
134170 }
135171 Ok ( ( ) )
136172 } )
@@ -208,14 +244,15 @@ pub fn collect_table_update_for_view<'p, Tx, F>(
208244 table_id : TableId ,
209245 table_name : TableName ,
210246 tx : & Tx ,
247+ params : & impl ParamResolver ,
211248 update_type : TableUpdateType ,
212249 rlb_pool : & impl RowListBuilderSource < F > ,
213250) -> Result < ( ws_v1:: TableUpdate < F > , ExecutionMetrics ) >
214251where
215252 Tx : Datastore + DeltaStore ,
216253 F : BuildableWebsocketFormat ,
217254{
218- execute_plan_for_view :: < F > ( plan_fragments, num_cols, num_private_cols, tx, rlb_pool) . map (
255+ execute_plan_for_view_with_params :: < F > ( plan_fragments, num_cols, num_private_cols, tx, params , rlb_pool) . map (
219256 |( rows, num_rows, metrics) | table_update_from_rows ( rows, num_rows, metrics, table_id, table_name, update_type) ,
220257 )
221258}
@@ -226,13 +263,14 @@ pub fn collect_table_update<'p, F>(
226263 table_id : TableId ,
227264 table_name : TableName ,
228265 tx : & ( impl Datastore + DeltaStore ) ,
266+ params : & impl ParamResolver ,
229267 update_type : TableUpdateType ,
230268 rlb_pool : & impl RowListBuilderSource < F > ,
231269) -> Result < ( ws_v1:: TableUpdate < F > , ExecutionMetrics ) >
232270where
233271 F : BuildableWebsocketFormat ,
234272{
235- execute_plan :: < F > ( plan_fragments, tx, rlb_pool) . map ( |( rows, num_rows, metrics) | {
273+ execute_plan_with_params :: < F > ( plan_fragments, tx, params , rlb_pool) . map ( |( rows, num_rows, metrics) | {
236274 table_update_from_rows ( rows, num_rows, metrics, table_id, table_name, update_type)
237275 } )
238276}
@@ -265,6 +303,7 @@ pub fn execute_plans<F: BuildableWebsocketFormat>(
265303 table_id,
266304 table_name. clone ( ) ,
267305 tx,
306+ plan. params ( ) ,
268307 update_type,
269308 rlb_pool,
270309 ) ?
@@ -274,6 +313,7 @@ pub fn execute_plans<F: BuildableWebsocketFormat>(
274313 table_id,
275314 table_name. clone ( ) ,
276315 tx,
316+ plan. params ( ) ,
277317 update_type,
278318 rlb_pool,
279319 ) ?
0 commit comments