Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy fix #134

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion xngin-expr/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ impl TypeFix for ExprKind {
_ => return inferer.confirm(self).ok_or(Error::UnknownColumnType),
},
ExprKind::Func { kind, args } => fix_func(*kind, args.as_mut(), inferer)?,
ExprKind::Pred(..) => PreciseType::bool(),
ExprKind::Pred(pred) => {
fix_pred(pred, inferer)?;
PreciseType::bool()
}
_ => todo!(),
};
Ok(ty)
Expand Down
6 changes: 3 additions & 3 deletions xngin-plan/src/lgc/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ impl<'c, C: Catalog> LgcBuilder<'c, C> {
///
/// if correlated is set to true, column can refer to sources in outer scopes.
#[inline]
fn setup_with<'a>(
fn setup_with(
&mut self,
with: &With<'a>,
with: &With<'_>,
allow_unknown_ident: bool,
colgen: &mut ColGen,
) -> Result<()> {
Expand Down Expand Up @@ -913,7 +913,7 @@ impl<'c, C: Catalog> LgcBuilder<'c, C> {
let (qry_id, subquery) = self.qs.insert_empty();
let mut proj_cols = Vec::with_capacity(all_cols.len());
for c in all_cols {
let idx = ColIndex::from(c.idx as u32);
let idx = ColIndex::from(c.idx);
let col = colgen.gen_tbl_col(qry_id, table_id, idx, c.pty, c.name.clone());
proj_cols.push(ProjCol::implicit_alias(col, c.name))
}
Expand Down
9 changes: 2 additions & 7 deletions xngin-plan/src/lgc/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,14 @@ pub enum Location {
Virtual,
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum QryIDs {
#[default]
Empty,
Single(QueryID),
Multi(HashSet<QueryID>),
}

impl Default for QryIDs {
fn default() -> Self {
QryIDs::Empty
}
}

/// QuerySet stores all sub-subqeries and provide lookup and update methods.
#[derive(Debug, Default)]
pub struct QuerySet(Vec<Subquery>);
Expand Down
47 changes: 24 additions & 23 deletions xngin-plan/src/phy/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,29 @@ impl<'a> PhyBuilder<'a> {
// Table scan supports Proj and Table operators.
#[inline]
fn build_disk_scan(&mut self, mut root: &Op) -> Result<NodeIndex> {
let mut proj = None;
let table_id;
loop {
match root {
// Op::Proj { cols, input } => {
// let eval_plan = TableEvalPlan::new(cols.iter().map(|c| &c.expr))?;
// proj = Some(eval_plan);
// root = &**input;
// }
// Op::Table(_, tid) => {
// table_id = Some(*tid);
// break;
// }
_ => return Err(Error::UnsupportedPhyTableScan),
}
}
let (evals, table_id) = proj.zip(table_id).ok_or(Error::UnsupportedPhyTableScan)?;
let node = Phy {
kind: PhyKind::TableScan(PhyTableScan { evals, table_id }),
};
let idx = self.graph.add_node(node);
self.start.push(idx);
Ok(idx)
// let mut proj = None;
// let table_id;
// loop {
// match &root.kind {
// // Op::Proj { cols, input } => {
// // let eval_plan = TableEvalPlan::new(cols.iter().map(|c| &c.expr))?;
// // proj = Some(eval_plan);
// // root = &**input;
// // }
// OpKind::Table(_, tid) => {
// table_id = Some(*tid);
// break;
// }
// _ => return Err(Error::UnsupportedPhyTableScan),
// }
// }
// let (evals, table_id) = proj.zip(table_id).ok_or(Error::UnsupportedPhyTableScan)?;
// let node = Phy {
// kind: PhyKind::TableScan(PhyTableScan { evals, table_id }),
// };
// let idx = self.graph.add_node(node);
// self.start.push(idx);
// Ok(idx)
todo!()
}
}
6 changes: 3 additions & 3 deletions xngin-plan/src/rule/col_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn prune_col(
if let Some(subq) = qry_set.get_mut(&qry_id) {
if subq.location != Location::Intermediate {
// skip other types of queries
return Ok(RuleEffect::NONE);
return Ok(RuleEffect::empty());
}
let mut c = Collect(use_set);
let _ = subq.root.walk(&mut c);
Expand Down Expand Up @@ -101,7 +101,7 @@ impl OpMutVisitor for Modify<'_> {
prune_col(self.qry_set, *qry_id, self.use_set).branch()
}
_ => {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
for e in op.kind.exprs_mut() {
eff |= e.walk_mut(self)?;
}
Expand All @@ -116,7 +116,7 @@ impl ExprMutVisitor for Modify<'_> {
type Break = Error;
#[inline]
fn enter(&mut self, e: &mut ExprKind) -> ControlFlow<Error, RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
match e {
ExprKind::Col(Col {
kind: ColKind::Query(qry_id),
Expand Down
18 changes: 9 additions & 9 deletions xngin-plan/src/rule/derived_unfold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn unfold_derived(
let mut u = Unfold::new(qry_set, mapping, mode);
op.walk_mut(&mut u).unbranch()
} else {
Ok(RuleEffect::NONE)
Ok(RuleEffect::empty())
}
})?
}
Expand Down Expand Up @@ -85,7 +85,7 @@ impl OpMutVisitor for Unfold<'_> {
unfold_derived(self.qry_set, *qry_id, &mut mapping, Mode::Full).branch()
}
OpKind::Join(join) => match join.as_mut() {
Join::Cross(_) => ControlFlow::Continue(RuleEffect::NONE),
Join::Cross(_) => ControlFlow::Continue(RuleEffect::empty()),
Join::Qualified(QualifiedJoin {
kind: JoinKind::Left,
right,
Expand Down Expand Up @@ -115,11 +115,11 @@ impl OpMutVisitor for Unfold<'_> {
self.stack.push(left.into());
ControlFlow::Continue(eff)
}
_ => ControlFlow::Continue(RuleEffect::NONE), // other joins is fine to bypass
_ => ControlFlow::Continue(RuleEffect::empty()), // other joins is fine to bypass
},
OpKind::Setop(so) => {
// setop does not support unfolding into current query
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
let Setop { left, right, .. } = so.as_mut();
let right = mem::take(right);
if let OpKind::Query(qry_id) = &right.kind {
Expand All @@ -145,8 +145,8 @@ impl OpMutVisitor for Unfold<'_> {
| OpKind::Aggr(_)
| OpKind::Sort { .. }
| OpKind::Limit { .. }
| OpKind::Attach(..) => ControlFlow::Continue(RuleEffect::NONE), // fine to bypass
OpKind::Empty => ControlFlow::Continue(RuleEffect::NONE), // as join op is set to empty, it's safe to bypass
| OpKind::Attach(..) => ControlFlow::Continue(RuleEffect::empty()), // fine to bypass
OpKind::Empty => ControlFlow::Continue(RuleEffect::empty()), // as join op is set to empty, it's safe to bypass
OpKind::Table(..) | OpKind::Row(_) => unreachable!(),
}
}
Expand All @@ -168,7 +168,7 @@ impl OpMutVisitor for Unfold<'_> {
*op = new_op;
ControlFlow::Continue(RuleEffect::OPEXPR)
}
None => ControlFlow::Continue(RuleEffect::NONE),
None => ControlFlow::Continue(RuleEffect::empty()),
}
}
None => ControlFlow::Break(Error::QueryNotFound(*qry_id)),
Expand Down Expand Up @@ -347,10 +347,10 @@ fn rewrite_exprs(op: &mut Op, mapping: &HashMap<QueryCol, ExprKind>) -> RuleEffe
return ControlFlow::Continue(RuleEffect::EXPR);
}
}
ControlFlow::Continue(RuleEffect::NONE)
ControlFlow::Continue(RuleEffect::empty())
}
}
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
if mapping.is_empty() {
return eff;
}
Expand Down
16 changes: 8 additions & 8 deletions xngin-plan/src/rule/expr_simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl OpMutVisitor for ExprSimplify<'_> {
match &mut op.kind {
OpKind::Query(qry_id) => simplify_expr(self.qry_set, *qry_id).branch(),
OpKind::Filt { pred, .. } => {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
for p in pred.iter_mut() {
eff |= simplify_nested(p, NullCoalesce::False).branch()?;
normalize_single(p);
Expand All @@ -74,9 +74,9 @@ impl OpMutVisitor for ExprSimplify<'_> {
ControlFlow::Continue(eff)
}
OpKind::Join(join) => match join.as_mut() {
Join::Cross(_) => ControlFlow::Continue(RuleEffect::NONE),
Join::Cross(_) => ControlFlow::Continue(RuleEffect::empty()),
Join::Qualified(QualifiedJoin { cond, filt, .. }) => {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
for c in cond.iter_mut() {
eff |= simplify_nested(c, NullCoalesce::False).branch()?;
normalize_single(c);
Expand All @@ -93,7 +93,7 @@ impl OpMutVisitor for ExprSimplify<'_> {
}
},
_ => {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
for e in op.kind.exprs_mut() {
eff |= simplify_nested(e, NullCoalesce::Null).branch()?;
normalize_single(e);
Expand Down Expand Up @@ -124,7 +124,7 @@ pub(crate) fn update_simplify_nested<F: FnMut(&mut ExprKind) -> Result<()>>(
if let ExprKind::Pred(Pred::Not(_)) = e {
self.1.flip();
}
ControlFlow::Continue(RuleEffect::NONE)
ControlFlow::Continue(RuleEffect::empty())
}

#[inline]
Expand Down Expand Up @@ -672,7 +672,7 @@ pub(crate) fn simplify_conj(
es: &mut Vec<ExprKind>,
null_coalesce: NullCoalesce,
) -> Result<RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
if let Some(e) = simplify_conj_short_circuit(es, null_coalesce, &mut eff) {
es.clear();
es.push(e);
Expand All @@ -688,7 +688,7 @@ fn update_simplify_single<F: FnMut(&mut ExprKind) -> Result<()>>(
null_coalesce: NullCoalesce,
mut f: F,
) -> Result<RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
// we don't count the replacement as expression change
f(e)?;
match e {
Expand Down Expand Up @@ -1464,7 +1464,7 @@ fn simplify_pred(p: &mut Pred, null_coalesce: NullCoalesce) -> Result<Option<Exp
}
Pred::Conj(es) => {
let eff = simplify_conj(es, null_coalesce)?;
if eff == RuleEffect::NONE {
if eff.is_empty() {
None
} else if es.len() == 1 {
Some(es.pop().unwrap())
Expand Down
8 changes: 4 additions & 4 deletions xngin-plan/src/rule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use pred_pushdown::pred_pushdown;

bitflags! {
pub struct RuleEffect: u8 {
const NONE = 0x00;
// const NONE = 0x00;
const OP = 0x01;
const EXPR = 0x02;
const OPEXPR = Self::OP.bits | Self::EXPR.bits;
Expand All @@ -39,7 +39,7 @@ bitflags! {
impl Default for RuleEffect {
#[inline]
fn default() -> Self {
RuleEffect::NONE
RuleEffect::empty()
}
}

Expand Down Expand Up @@ -77,15 +77,15 @@ pub fn rule_optimize_each(qry_set: &mut QuerySet, qry_id: QueryID) -> Result<()>
}
_ => break,
}
eff = RuleEffect::NONE;
eff = RuleEffect::empty();
}
final_rule_optimize(qry_set, qry_id)?;
Ok(())
}

#[inline]
pub fn init_rule_optimize(qry_set: &mut QuerySet, qry_id: QueryID) -> Result<RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
// Run column pruning as first step, to remove unused columns in operator tree.
// this will largely reduce effort of other rules.
eff |= col_prune(qry_set, qry_id)?; // onetime
Expand Down
6 changes: 3 additions & 3 deletions xngin-plan/src/rule/op_eliminate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'a> EliminateOp<'a> {

#[inline]
fn bottom_up(&mut self, op: &mut Op) -> ControlFlow<Error, RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
match &mut op.kind {
OpKind::Join(j) => match j.as_mut() {
Join::Cross(tbls) => {
Expand Down Expand Up @@ -213,7 +213,7 @@ impl OpMutVisitor for EliminateOp<'_> {
type Break = Error;
#[inline]
fn enter(&mut self, op: &mut Op) -> ControlFlow<Error, RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
match &mut op.kind {
OpKind::Filt { pred, input } => {
if pred.is_empty() {
Expand Down Expand Up @@ -300,7 +300,7 @@ impl OpMutVisitor for EliminateOp<'_> {

#[inline]
fn leave(&mut self, op: &mut Op) -> ControlFlow<Error, RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
match &mut op.kind {
OpKind::Query(qry_id) => {
if let Some(subq) = self.qry_set.get(qry_id) {
Expand Down
4 changes: 2 additions & 2 deletions xngin-plan/src/rule/outerjoin_reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn reduce_outerjoin(
) -> Result<RuleEffect> {
qry_set.transform_op(qry_id, |qry_set, loc, op| {
if loc != Location::Intermediate {
return Ok(RuleEffect::NONE);
return Ok(RuleEffect::empty());
}
// as entering a new query, original reject-null exprs should be translated in current scope
// and check whether it still rejects null, and initialize new rn_map.
Expand Down Expand Up @@ -55,7 +55,7 @@ impl OpMutVisitor for Reduce<'_> {
type Break = Error;
#[inline]
fn enter(&mut self, op: &mut Op) -> ControlFlow<Error, RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
match &mut op.kind {
OpKind::Filt { pred, .. } => analyze_conj_preds(pred, self.rn_map).branch()?,
OpKind::Aggr(aggr) => analyze_conj_preds(&aggr.filt, self.rn_map).branch()?,
Expand Down
4 changes: 2 additions & 2 deletions xngin-plan/src/rule/pred_pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl OpMutVisitor for PredPushdown<'_> {
type Break = Error;
#[inline]
fn enter(&mut self, op: &mut Op) -> ControlFlow<Error, RuleEffect> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
match &mut op.kind {
OpKind::Filt { pred, input } => {
let mut fallback = vec![];
Expand Down Expand Up @@ -212,7 +212,7 @@ fn push_single(
op: &mut Op,
mut p: ExprItem,
) -> Result<(RuleEffect, Option<ExprItem>)> {
let mut eff = RuleEffect::NONE;
let mut eff = RuleEffect::empty();
let res = match &mut op.kind {
OpKind::Query(qry_id) => {
if let Some(subq) = qry_set.get(qry_id) {
Expand Down
2 changes: 1 addition & 1 deletion xngin-protocol/src/mysql/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ impl<'a> PacketParser<'a> {
};
}
let data = *b;
b.advance(b.len() as usize);
b.advance(b.len());
self.b = *b;
Packet {
kind: PacketKind::PartialPayload,
Expand Down
2 changes: 1 addition & 1 deletion xngin-protocol/src/mysql/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TryFrom<LenEncInt> for u64 {
LenEncInt::Len1(n) => Ok(n as u64),
LenEncInt::Len3(n) => Ok(n as u64),
LenEncInt::Len4(n) => Ok(n as u64),
LenEncInt::Len9(n) => Ok(n as u64),
LenEncInt::Len9(n) => Ok(n),
_ => Err(Error::InvalidLengthEncoding()),
}
}
Expand Down
Loading
Loading