Skip to main content

QueryOptimizer

Struct QueryOptimizer 

Source
pub struct QueryOptimizer {
    pub check_select_star: bool,
    pub check_missing_limit: bool,
    pub check_missing_where: bool,
    pub default_limit: usize,
    pub join_weight: u32,
    pub subquery_weight: u32,
    pub where_weight: u32,
}
Expand description

SQL 查询优化分析器

基于规则分析 SQL 查询,生成优化建议。 不依赖外部 LLM API,纯规则匹配,适用于离线场景。

Fields§

§check_select_star: bool

是否检测 SELECT *

§check_missing_limit: bool

是否检测缺失的 LIMIT

§check_missing_where: bool

是否检测缺失的 WHERE

§default_limit: usize

LIMIT 建议的默认行数

§join_weight: u32

复杂度评分中 JOIN 的权重

§subquery_weight: u32

复杂度评分中子查询的权重

§where_weight: u32

复杂度评分中 WHERE 条件的权重

Implementations§

Source§

impl QueryOptimizer

Source

pub fn new() -> Self

创建新的查询优化分析器

Source

pub fn with_default_limit(self, limit: usize) -> Self

设置默认 LIMIT 行数

Source

pub fn disable_select_star_check(self) -> Self

禁用 SELECT * 检测

Source

pub fn disable_missing_limit_check(self) -> Self

禁用缺失 LIMIT 检测

Source

pub fn disable_missing_where_check(self) -> Self

禁用缺失 WHERE 检测

Source

pub fn analyze(&self, sql: &str, schema: &SchemaContext) -> QueryAnalysis

分析 SQL 查询并生成优化建议

§参数
  • sql: 要分析的 SQL 查询语句
  • schema: 数据库 schema 上下文(用于检测表名和索引)
Source

pub fn format_report(analysis: &QueryAnalysis) -> String

生成优化报告文本

Trait Implementations§

Source§

impl Default for QueryOptimizer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.