use super::super::super::predicates::Projection;
use super::super::super::SqlSelectFact;
use super::super::{from, nested, shapes, stars, uses};
use super::Collector;
use crate::star_projection::WholeRowUses;
use sqlparser::ast::{OrderByExpr, Select};
impl<P: Projection> Collector<'_, '_, '_, P> {
pub(super) fn push_select(
&mut self,
select: &Select,
ctes: &[String],
in_insert_select: bool,
in_exists: bool,
order: &[OrderByExpr],
) {
let sql = self.sql;
let policy = self.policy;
let out = &mut self.out;
let tables = from::table_names(&select.from, ctes);
let mut exists_set_operations = Vec::new();
super::super::super::exists::collect_from_select_at(
sql,
select,
policy.positions,
&mut exists_set_operations,
);
if let Some(whole_rows) = WholeRowUses::for_derived(select, self.narrowed, order) {
from::collect_derived_queries(
sql,
&select.from,
ctes,
in_insert_select,
policy,
Some(&whole_rows),
out,
);
}
nested::collect_at(sql, select, ctes, in_insert_select, policy, out);
let relations = super::super::super::predicates::select_relations_projected(
sql,
select,
ctes,
policy.positions,
policy.projection,
);
let shapes = shapes::collect(select);
let line = super::super::line::select_line(select, &tables);
let star_projections = if in_exists {
Vec::new()
} else {
stars::collect(select, ctes, line, self.narrowed)
};
let column_uses = uses::collect(select, order, ctes, line, policy.positions);
if tables.is_empty()
&& exists_set_operations.is_empty()
&& relations.is_empty()
&& shapes.not_in_subqueries.is_empty()
&& shapes.count_existence_checks.is_empty()
&& star_projections.is_empty()
&& column_uses.is_empty()
{
return;
}
out.push(SqlSelectFact {
sql_position: (
select.select_token.0.span.start.line as usize,
select.select_token.0.span.start.column as usize,
),
line,
tables,
predicate_sql: from::predicate_text(select),
exists_set_operations,
relations,
in_insert_select,
not_in_subqueries: shapes.not_in_subqueries,
not_in_columns: shapes.not_in_columns,
count_existence_checks: shapes.count_existence_checks,
star_projections,
column_uses,
catalog_predicates: super::super::catalog_predicates::collect(select, ctes),
});
}
}