Open chenzl25 opened 12 months ago
> * When expressions not actually be rewritten, `rewrite_exprs` should be able to directly return itself without cloning. This can be achieved with `Cow`.
I guess we can achieve it with passing the Arc
use std::rc::Rc;
pub trait ExprRewritable {
fn rewrite_exprs(self: Rc<Self>) -> Rc<dyn ExprRewritable>;
}
struct Proj {
a: i32
}
impl ExprRewritable for Proj {
fn rewrite_exprs(self: Rc<Self>) -> Rc<dyn ExprRewritable> {
if self.a == 1 {
return Rc::new(Proj{ a: 2});
} else {
return self
}
}
}
Originally posted by @st1page in https://github.com/risingwavelabs/risingwave/issues/13609#issuecomment-1823921930
This issue has been open for 60 days with no activity.
If you think it is still relevant today, and needs to be done in the near future, you can comment to update the status, or just manually remove the no-issue-activity
label.
You can also confidently close this issue as not planned to keep our backlog clean. Don't worry if you think the issue is still valuable to continue in the future. It's searchable and can be reopened when it's time. 😄
I'm considering whether it's possible to reduce the overhead of
rewrite
...We already have
has_rewritable_expr
to reduce the calls. https://github.com/risingwavelabs/risingwave/blob/d37b87bf641655d775f72997a268d6e881541e6d/src/frontend/src/optimizer/plan_node/expr_rewritable.rs#L26-L28 Is it possible to make it specific to different rewriters? This will somehow be similar to https://doc.rust-lang.org/stable/std/error/struct.Request.html#method.would_be_satisfied_by_ref_of.When expressions not actually be rewritten,
rewrite_exprs
should be able to directly return itself without cloning. This can be achieved withCow
. https://github.com/risingwavelabs/risingwave/blob/d37b87bf641655d775f72997a268d6e881541e6d/src/frontend/src/optimizer/plan_node/logical_project.rs#L172-L180Similarly when inputs not changed,
clone_with_inputs
should be able to directly return itself without cloning. This can be achieved withRc::ptr_eq
. https://github.com/risingwavelabs/risingwave/blob/d37b87bf641655d775f72997a268d6e881541e6d/src/frontend/src/optimizer/plan_node/mod.rs#L300There is no need to allocate a
Vec<ExprImpl>
or clone the expression when rewriting them. https://github.com/risingwavelabs/risingwave/blob/d37b87bf641655d775f72997a268d6e881541e6d/src/frontend/src/optimizer/plan_node/generic/project.rs#L55-L63Take this for an example, a more efficient version should be...
where no allocation will be done if there's no actual rewriting.
Originally posted by @BugenZhao in https://github.com/risingwavelabs/risingwave/issues/13609#issuecomment-1823899699