Skip to main content

QueryAnalyzer

Struct QueryAnalyzer 

Source
pub struct QueryAnalyzer { /* private fields */ }
Expand description

Analyzer for SQL queries found in PostgreSQL logs

Implementations§

Source§

impl QueryAnalyzer

Source

pub fn new() -> Self

Create a new query analyzer with default settings

Source

pub fn with_settings( slow_query_threshold: f64, max_slow_queries: usize, max_frequent_queries: usize, ) -> Self

Create a new query analyzer with custom settings

Source

pub fn slow_query_threshold(&self) -> f64

Get the slow query threshold (public for testing)

Source

pub fn max_slow_queries(&self) -> usize

Get the maximum number of slow queries to track (public for testing)

Source

pub fn max_frequent_queries(&self) -> usize

Get the maximum number of frequent queries to track (public for testing)

Source

pub fn analyze(&self, entries: &[LogEntry]) -> Result<AnalysisResult>

Analyze queries from log entries

Source

pub fn analyze_events( &self, events: &[NormalizedEvent], ) -> Result<AnalysisResult>

Analyze queries from normalized events.

Source

pub fn normalize_query(&self, sql: &str) -> String

Normalize SQL query by replacing literals with placeholders

Source

pub fn classify_query(&self, sql: &str) -> QueryType

Classify query type based on SQL content

Source

pub fn calculate_metrics(&self, durations: &[f64]) -> QueryMetrics

Calculate performance metrics from durations (public for testing)

Source

pub fn find_slow_queries( &self, entries: &[LogEntry], threshold_ms: f64, ) -> Result<Vec<LogEntry>>

Find slow queries above a threshold

Source

pub fn get_query_type_distribution( &self, entries: &[LogEntry], ) -> HashMap<QueryType, u64>

Get query type distribution

Source

pub fn get_query_type_distribution_for_events( &self, events: &[NormalizedEvent], ) -> HashMap<QueryType, u64>

Source

pub fn calculate_error_rate(&self, entries: &[LogEntry]) -> f64

Calculate error rate

Source

pub fn calculate_error_rate_for_events(&self, events: &[NormalizedEvent]) -> f64

Trait Implementations§

Source§

impl Default for QueryAnalyzer

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.