fix rest of the failing tests

This commit is contained in:
jussisaurio
2024-11-23 17:46:54 +02:00
parent 9a557516b8
commit 7ecc252507
5 changed files with 15 additions and 63 deletions

View File

@@ -16,6 +16,7 @@ use super::expr::{
translate_aggregation, translate_aggregation_groupby, translate_condition_expr, translate_expr,
ConditionMetadata,
};
use super::optimizer::Optimizable;
use super::plan::{Aggregate, BTreeTableReference, Direction, Plan};
use super::plan::{ResultSetColumn, SourceOperator};
@@ -825,6 +826,19 @@ pub enum InnerLoopEmitTarget<'a> {
}
fn inner_loop_emit(program: &mut ProgramBuilder, plan: &mut Plan, m: &mut Metadata) -> Result<()> {
if let Some(wc) = &plan.where_clause {
for predicate in wc.iter() {
if predicate.is_always_false()? {
return Ok(());
} else if predicate.is_always_true()? {
// do nothing
} else {
unreachable!(
"all WHERE clause terms that are not trivially true or false should have been pushed down to the source"
);
}
}
}
// if we have a group by, we emit a record into the group by sorter.
if let Some(group_by) = &plan.group_by {
return inner_loop_source_emit(
@@ -886,7 +900,6 @@ fn inner_loop_source_emit(
group_by,
aggregates,
} => {
// TODO: DOESNT WORK YET
let sort_keys_count = group_by.len();
let aggregate_arguments_count =
aggregates.iter().map(|agg| agg.args.len()).sum::<usize>();

View File

@@ -20,21 +20,7 @@ pub fn optimize_plan(mut select_plan: Plan) -> Result<Plan> {
&mut select_plan.where_clause,
&select_plan.referenced_tables,
)?;
if eliminate_constants(&mut select_plan.source)?
== ConstantConditionEliminationResult::ImpossibleCondition
{
return Ok(Plan {
source: SourceOperator::Nothing,
aggregates: None,
result_columns: vec![],
where_clause: None,
group_by: None,
order_by: None,
limit: None,
referenced_tables: select_plan.referenced_tables,
available_indexes: select_plan.available_indexes,
});
}
eliminate_constants(&mut select_plan.source)?;
use_indexes(
&mut select_plan.source,
&select_plan.referenced_tables,

View File

@@ -130,48 +130,6 @@ pub enum Search {
}
impl SourceOperator {
pub fn column_count(&self, referenced_tables: &[BTreeTableReference]) -> usize {
match self {
SourceOperator::Join { left, right, .. } => {
left.column_count(referenced_tables) + right.column_count(referenced_tables)
}
SourceOperator::Scan {
table_reference, ..
} => table_reference.table.columns.len(),
SourceOperator::Search {
table_reference, ..
} => table_reference.table.columns.len(),
SourceOperator::Nothing => 0,
}
}
pub fn column_names(&self) -> Vec<String> {
match self {
SourceOperator::Join { left, right, .. } => {
let mut names = left.column_names();
names.extend(right.column_names());
names
}
SourceOperator::Scan {
table_reference, ..
} => table_reference
.table
.columns
.iter()
.map(|c| c.name.clone())
.collect(),
SourceOperator::Search {
table_reference, ..
} => table_reference
.table
.columns
.iter()
.map(|c| c.name.clone())
.collect(),
SourceOperator::Nothing => vec![],
}
}
pub fn id(&self) -> usize {
match self {
SourceOperator::Join { id, .. } => *id,

View File

@@ -18,6 +18,5 @@ pub fn translate_select(
) -> Result<Program> {
let select_plan = prepare_select_plan(schema, select)?;
let optimized_plan = optimize_plan(select_plan)?;
// println!("optimized_plan: {:?}", optimized_plan);
emit_program(database_header, optimized_plan, connection)
}

View File

@@ -361,10 +361,6 @@ impl ProgramBuilder {
.unwrap()
}
pub fn resolve_cursor_to_table(&self, cursor_id: CursorID) -> Option<Table> {
self.cursor_ref[cursor_id].1.clone()
}
pub fn resolve_deferred_labels(&mut self) {
for i in 0..self.deferred_label_resolutions.len() {
let (label, insn_reference) = self.deferred_label_resolutions[i];