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
coprocessor/dag:fix bug caused by use offset in expr #2064
Conversation
@@ -35,27 +35,23 @@ pub struct AggregationExecutor<'a> { | |||
cursor: usize, | |||
executed: bool, | |||
ctx: Rc<EvalContext>, | |||
cols: Vec<ColumnInfo>, | |||
cols: Rc<Vec<ColumnInfo>>, | |||
related_cols: Vec<usize>, // offset of related columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related_cols_offset or sth.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use name consistently.
name | represent |
---|---|
column/column_info/info | Column Info |
id/column_id | Column ID |
offset | Column Offset |
src/coprocessor/executor/mod.rs
Outdated
} | ||
|
||
pub fn visit(&mut self, expr: &Expr) -> Result<()> { | ||
if expr.get_tp() == ExprType::ColumnRef { | ||
self.col_ids.insert(box_try!(expr.get_val().decode_i64())); | ||
let offset = box_try!(expr.get_val().decode_i64()) as usize; | ||
if offset < self.cols_len { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return an error if offset invalid?
src/coprocessor/executor/mod.rs
Outdated
@@ -53,6 +68,10 @@ impl ExprColumnRefVisitor { | |||
} | |||
Ok(()) | |||
} | |||
|
|||
pub fn cols(self) -> Vec<usize> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/cols/column_offsets/
src/coprocessor/executor/topn.rs
Outdated
use super::super::table_scan::TableScanExecutor; | ||
use super::super::scanner::test::{TestStore, get_range, new_col_info}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
CI fails @AndreMouche |
Rest LGTM |
PTAL @hanfei1991 @XuHuaiyu @andelf |
LGTM |
ExprColumnRefVisitor { col_ids: HashSet::new() } | ||
pub fn new(cols_len: usize) -> ExprColumnRefVisitor { | ||
ExprColumnRefVisitor { | ||
cols_offset: HashSet::default(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use with_capacity
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No associated item named with_capacity
found for type std::collections::HashSet<_, std::hash::BuildHasherDefault<fnv::FnvHasher>>
in the current scope @BusyJay
src/coprocessor/executor/mod.rs
Outdated
} | ||
|
||
pub fn visit(&mut self, expr: &Expr) -> Result<()> { | ||
if expr.get_tp() == ExprType::ColumnRef { | ||
self.col_ids.insert(box_try!(expr.get_val().decode_i64())); | ||
let offset = box_try!(expr.get_val().decode_i64()) as usize; | ||
if offset > self.cols_len { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be >=
?
src/coprocessor/executor/mod.rs
Outdated
@@ -27,18 +36,28 @@ pub mod aggregation; | |||
|
|||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be removed?
src/coprocessor/executor/mod.rs
Outdated
self.col_ids.insert(box_try!(expr.get_val().decode_i64())); | ||
let offset = box_try!(expr.get_val().decode_i64()) as usize; | ||
if offset > self.cols_len { | ||
return Err(Error::Other(box_err!("offset {} overflow,should be less than {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space.
src: Box<Executor + 'a>) | ||
-> Result<AggregationExecutor<'a>> { | ||
// collect all cols used in aggregation | ||
let mut visitor = ExprColumnRefVisitor::new(); | ||
let mut visitor = ExprColumnRefVisitor::new(columns.len()); | ||
let group_by = meta.take_group_by().into_vec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think visitor.batch_visit(meta.get_group_by())
should be ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group_by
is not only been used in visitor
and would be taken later @BusyJay
src: Box<Executor + 'a>) | ||
-> Result<SelectionExecutor<'a>> { | ||
let conditions = meta.take_conditions().into_vec(); | ||
let mut visitor = ExprColumnRefVisitor::new(); | ||
let mut visitor = ExprColumnRefVisitor::new(columns_info.len()); | ||
for cond in &conditions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use batch_visit
?
@BusyJay @hhkbp2 @hanfei1991 PTAL |
tests/coprocessor/test_select.rs
Outdated
@@ -193,6 +197,13 @@ impl Table { | |||
c_info.set_pk_handle(col.id == self.handle_id); | |||
idx_info.mut_columns().push(c_info); | |||
} | |||
if let Some(col) = self.cols.get(&self.handle_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
let columns_info = index_info.take_columns(); | ||
scan.set_columns(columns_info.clone()); | ||
exec.set_idx_scan(scan); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many empty lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi,
This PR will fix bug caused by use column_id instead of column_offset in expression.
And its tests in test_select is not finished.
@hanfei1991 you can test it first.