@@ -252,6 +252,16 @@ impl TxData {
252252 self . ephemeral_tables . as_ref ( )
253253 }
254254
255+ /// Check if `table_id` is in the set of ephemeral tables for this transaction.
256+ ///
257+ /// Beware that ephemeral tables are known only after [Self::set_ephemeral_tables]
258+ /// has been called.
259+ pub fn is_ephemeral_table ( & self , table_id : & TableId ) -> bool {
260+ self . ephemeral_tables
261+ . as_ref ( )
262+ . is_some_and ( |etables| etables. contains ( table_id) )
263+ }
264+
255265 /// Obtain an iterator over the inserted rows per table.
256266 pub fn inserts ( & self ) -> impl Iterator < Item = ( & TableId , & Arc < [ ProductValue ] > ) > + ' _ {
257267 self . inserts . iter ( )
@@ -304,12 +314,20 @@ impl TxData {
304314 self . truncates . iter ( ) . copied ( )
305315 }
306316
307- /// Check if this [`TxData`] contains any `inserted | deleted` rows or `connect/disconnect` operations.
317+ /// Check if this [`TxData`] contains any `inserted | deleted` rows
318+ /// or `connect/disconnect` operations.
319+ ///
320+ /// Mutations of ephemeral tables are excluded, i.e. if the transaction
321+ /// modifies only ephemeral tables (and is not a connect/disconnect operation),
322+ /// the method returns `false`.
308323 ///
309324 /// This is used to determine if a transaction should be written to disk.
310325 pub fn has_rows_or_connect_disconnect ( & self , reducer_name : Option < & str > ) -> bool {
311- self . inserts ( ) . any ( |( _, inserted_rows) | !inserted_rows. is_empty ( ) )
312- || self . deletes ( ) . any ( |( .., deleted_rows) | !deleted_rows. is_empty ( ) )
326+ let is_non_ephemeral_mutation =
327+ |( table_id, rows) : ( _ , & Arc < [ _ ] > ) | !( self . is_ephemeral_table ( table_id) || rows. is_empty ( ) ) ;
328+
329+ self . inserts ( ) . any ( is_non_ephemeral_mutation)
330+ || self . deletes ( ) . any ( is_non_ephemeral_mutation)
313331 || matches ! (
314332 reducer_name. map( |rn| rn. strip_prefix( "__identity_" ) ) ,
315333 Some ( Some ( "connected__" | "disconnected__" ) )
0 commit comments