@@ -8,18 +8,18 @@ use super::{
88} ;
99use crate :: {
1010 db_metrics:: DB_METRICS ,
11- error:: { DatastoreError , IndexError , TableError } ,
11+ error:: { DatastoreError , IndexError , TableError , ViewError } ,
1212 execution_context:: ExecutionContext ,
1313 locking_tx_datastore:: { mut_tx:: ViewReadSets , state_view:: iter_st_column_for_table} ,
1414 system_tables:: {
1515 system_tables, StColumnRow , StConstraintData , StConstraintRow , StIndexRow , StSequenceRow , StTableFields ,
16- StTableRow , SystemTable , ST_CLIENT_ID , ST_CLIENT_IDX , ST_COLUMN_ID , ST_COLUMN_IDX , ST_COLUMN_NAME ,
16+ StTableRow , StViewRow , SystemTable , ST_CLIENT_ID , ST_CLIENT_IDX , ST_COLUMN_ID , ST_COLUMN_IDX , ST_COLUMN_NAME ,
1717 ST_CONSTRAINT_ID , ST_CONSTRAINT_IDX , ST_CONSTRAINT_NAME , ST_INDEX_ID , ST_INDEX_IDX , ST_INDEX_NAME ,
1818 ST_MODULE_ID , ST_MODULE_IDX , ST_ROW_LEVEL_SECURITY_ID , ST_ROW_LEVEL_SECURITY_IDX , ST_SCHEDULED_ID ,
1919 ST_SCHEDULED_IDX , ST_SEQUENCE_ID , ST_SEQUENCE_IDX , ST_SEQUENCE_NAME , ST_TABLE_ID , ST_TABLE_IDX , ST_VAR_ID ,
2020 ST_VAR_IDX , ST_VIEW_ARG_ID , ST_VIEW_ARG_IDX ,
2121 } ,
22- traits:: TxData ,
22+ traits:: { EphemeralTables , TxData } ,
2323} ;
2424use crate :: {
2525 locking_tx_datastore:: ViewCallInfo ,
@@ -80,6 +80,12 @@ pub struct CommittedState {
8080 /// Any overlap will trigger a re-evaluation of the affected view,
8181 /// and its read set will be updated accordingly.
8282 read_sets : ViewReadSets ,
83+
84+ /// Tables which do not need to be made persistent.
85+ /// These include:
86+ /// - system tables: `st_view_sub`, `st_view_arg`
87+ /// - Tables which back views.
88+ pub ( super ) ephemeral_tables : EphemeralTables ,
8389}
8490
8591impl CommittedState {
@@ -99,6 +105,7 @@ impl MemoryUsage for CommittedState {
99105 page_pool : _,
100106 table_dropped,
101107 read_sets,
108+ ephemeral_tables,
102109 } = self ;
103110 // NOTE(centril): We do not want to include the heap usage of `page_pool` as it's a shared resource.
104111 next_tx_offset. heap_usage ( )
@@ -107,6 +114,7 @@ impl MemoryUsage for CommittedState {
107114 + index_id_map. heap_usage ( )
108115 + table_dropped. heap_usage ( )
109116 + read_sets. heap_usage ( )
117+ + ephemeral_tables. heap_usage ( )
110118 }
111119}
112120
@@ -171,6 +179,7 @@ impl CommittedState {
171179 table_dropped : <_ >:: default ( ) ,
172180 read_sets : <_ >:: default ( ) ,
173181 page_pool,
182+ ephemeral_tables : <_ >:: default ( ) ,
174183 }
175184 }
176185
@@ -518,6 +527,32 @@ impl CommittedState {
518527 Ok ( ( ) )
519528 }
520529
530+ pub ( super ) fn collect_ephemeral_tables ( & mut self ) -> Result < ( ) > {
531+ self . ephemeral_tables = self . ephemeral_tables ( ) ?. into_iter ( ) . collect ( ) ;
532+ Ok ( ( ) )
533+ }
534+
535+ fn ephemeral_tables ( & self ) -> Result < Vec < TableId > > {
536+ let mut tables = vec ! [ ST_VIEW_SUB_ID , ST_VIEW_ARG_ID ] ;
537+
538+ let Some ( st_view) = self . tables . get ( & ST_VIEW_ID ) else {
539+ return Ok ( tables) ;
540+ } ;
541+ let backing_tables = st_view
542+ . scan_rows ( & self . blob_store )
543+ . map ( |row_ref| {
544+ let view_row = StViewRow :: try_from ( row_ref) ?;
545+ view_row
546+ . table_id
547+ . ok_or_else ( || DatastoreError :: View ( ViewError :: TableNotFound ( view_row. view_id ) ) )
548+ } )
549+ . collect :: < Result < Vec < _ > > > ( ) ?;
550+
551+ tables. extend ( backing_tables) ;
552+
553+ Ok ( tables)
554+ }
555+
521556 /// After replaying all old transactions,
522557 /// inserts and deletes into the system tables
523558 /// might not be reflected in the schemas of the built tables.
@@ -675,6 +710,8 @@ impl CommittedState {
675710 self . next_tx_offset += 1 ;
676711 }
677712
713+ tx_data. set_ephemeral_tables ( & self . ephemeral_tables ) ;
714+
678715 tx_data
679716 }
680717
@@ -847,17 +884,25 @@ impl CommittedState {
847884 }
848885 // A table was removed. Add it back.
849886 TableRemoved ( table_id, table) => {
887+ let is_view_table = table. schema . is_view ( ) ;
850888 // We don't need to deal with sub-components.
851889 // That is, we don't need to add back indices and such.
852890 // Instead, there will be separate pending schema changes like `IndexRemoved`.
853891 self . tables . insert ( table_id, table) ;
892+
893+ // Incase, the table was ephemeral, add it back to that set as well.
894+ if is_view_table {
895+ self . ephemeral_tables . insert ( table_id) ;
896+ }
854897 }
855898 // A table was added. Remove it.
856899 TableAdded ( table_id) => {
857900 // We don't need to deal with sub-components.
858901 // That is, we don't need to remove indices and such.
859902 // Instead, there will be separate pending schema changes like `IndexAdded`.
860903 self . tables . remove ( & table_id) ;
904+ // Incase, the table was ephemeral, remove it from that set as well.
905+ self . ephemeral_tables . remove ( & table_id) ;
861906 }
862907 // A table's access was changed. Change back to the old one.
863908 TableAlterAccess ( table_id, access) => {
0 commit comments