@@ -115,6 +115,13 @@ impl ProjectPlan {
115115 pub fn returns_view_table ( & self ) -> bool {
116116 self . return_table ( ) . is_some_and ( |schema| schema. is_view ( ) )
117117 }
118+
119+ /// Does this plan read from an (anonymous) view?
120+ pub fn reads_from_view ( & self , anonymous : bool ) -> bool {
121+ match self {
122+ Self :: None ( plan) | Self :: Name ( plan, ..) => plan. reads_from_view ( anonymous) ,
123+ }
124+ }
118125}
119126
120127/// Physical plans always terminate with a projection.
@@ -213,6 +220,15 @@ impl ProjectListPlan {
213220 pub fn returns_view_table ( & self ) -> bool {
214221 self . return_table ( ) . is_some_and ( |schema| schema. is_view ( ) )
215222 }
223+
224+ /// Does this plan read from an (anonymous) view?
225+ pub fn reads_from_view ( & self , anonymous : bool ) -> bool {
226+ match self {
227+ Self :: Limit ( plan, _) => plan. reads_from_view ( anonymous) ,
228+ Self :: Name ( plans) => plans. iter ( ) . any ( |plan| plan. reads_from_view ( anonymous) ) ,
229+ Self :: List ( plans, ..) | Self :: Agg ( plans, ..) => plans. iter ( ) . any ( |plan| plan. reads_from_view ( anonymous) ) ,
230+ }
231+ }
216232}
217233
218234/// Query operators return tuples of rows.
@@ -1124,6 +1140,19 @@ impl PhysicalPlan {
11241140 pub fn returns_view_table ( & self ) -> bool {
11251141 self . return_table ( ) . is_some_and ( |schema| schema. is_view ( ) )
11261142 }
1143+
1144+ /// Does this plan read from an (anonymous) view?
1145+ pub fn reads_from_view ( & self , anonymous : bool ) -> bool {
1146+ self . any ( & |plan| match plan {
1147+ Self :: TableScan ( scan, _) if anonymous => scan. schema . is_anonymous_view ( ) ,
1148+ Self :: TableScan ( scan, _) => scan. schema . is_view ( ) && !scan. schema . is_anonymous_view ( ) ,
1149+ Self :: IxScan ( scan, _) if anonymous => scan. schema . is_anonymous_view ( ) ,
1150+ Self :: IxScan ( scan, _) => scan. schema . is_view ( ) && !scan. schema . is_anonymous_view ( ) ,
1151+ Self :: IxJoin ( join, _) if anonymous => join. rhs . is_anonymous_view ( ) ,
1152+ Self :: IxJoin ( join, _) => join. rhs . is_view ( ) && !join. rhs . is_anonymous_view ( ) ,
1153+ _ => false ,
1154+ } )
1155+ }
11271156}
11281157
11291158/// Scan a table row by row, returning row ids
0 commit comments