Removes unused relation inputs
(
mut pipeline: Vec<SqlTransform>,
ctx: &mut Context,
)
| 57 | |
| 58 | /// Removes unused relation inputs |
| 59 | pub(in crate::sql) fn prune_inputs( |
| 60 | mut pipeline: Vec<SqlTransform>, |
| 61 | ctx: &mut Context, |
| 62 | ) -> Result<Vec<SqlTransform>> { |
| 63 | use SqlTransform::Super; |
| 64 | |
| 65 | let mut used_cids = HashSet::new(); |
| 66 | |
| 67 | let mut res = Vec::new(); |
| 68 | while let Some(mut transform) = pipeline.pop() { |
| 69 | // collect cids (special case for Join & From) |
| 70 | match transform { |
| 71 | SqlTransform::Join { ref filter, .. } => { |
| 72 | used_cids.extend(CidCollector::collect(filter.clone())); |
| 73 | } |
| 74 | SqlTransform::From(_) => {} |
| 75 | Super(t) => { |
| 76 | let (t, cids) = CidCollector::collect_t(t); |
| 77 | used_cids.extend(cids); |
| 78 | transform = Super(t); |
| 79 | } |
| 80 | _ => unreachable!(), |
| 81 | } |
| 82 | |
| 83 | // prune unused inputs |
| 84 | if let SqlTransform::From(with) | SqlTransform::Join { with, .. } = &mut transform { |
| 85 | let relation = ctx.anchor.relation_instances.get_mut(with).unwrap(); |
| 86 | (relation.table_ref.columns).retain(|(_, cid)| used_cids.contains(cid)); |
| 87 | } |
| 88 | |
| 89 | res.push(transform); |
| 90 | } |
| 91 | |
| 92 | res.reverse(); |
| 93 | Ok(res) |
| 94 | } |
| 95 | |
| 96 | pub(in crate::sql) fn wrap(pipe: Vec<Transform>, ctx: &mut Context) -> Result<Vec<SqlTransform>> { |
| 97 | // We map From and Join into SqlTransforms, because we need to change their RIIds. |
no test coverage detected