NAME

DBIx::Fast::Profile::MariaDB - MariaDB/MySQL profiling and diagnostics

SYNOPSIS

my $db = DBIx::Fast->new( dsn => 'mariadb://user:pass@host/app' );
my $mariadb = $db->profiler;                  # DBIx::Fast::Profile::MariaDB

my $plan  = $mariadb->explain_query('SELECT * FROM orders WHERE id = ?', 7);
my $table = $mariadb->get_table_stats('orders');
my $idx   = $mariadb->analyze_indexes('orders');
my $conns = $mariadb->get_current_connections;
$mariadb->print_stats;

DESCRIPTION

Provides MariaDB-native query profiling, index analysis, and connection monitoring using information_schema and performance_schema. Extends DBIx::Fast::Profile::Base.

METHODS

init

Enables MariaDB session profiling (SET profiling = 1) and configures history size and resource usage tracking.

get_slow_queries

Returns queries from information_schema.profiling whose total duration exceeds the slow_query threshold.

get_query_profile

my $profile = $mariadb->get_query_profile($query_id);

Returns detailed stage-by-stage profiling data for a specific query ID, including CPU, I/O, and memory metrics.

get_stats

Returns a hashref with global server status counters and session-level query statistics for the current connection.

Prints a formatted report of global and session query statistics.

explain_query

my $plan = $mariadb->explain_query($sql, @params);

Runs EXPLAIN EXTENDED on the given SQL and returns the execution plan. The SQL is validated before execution: it must begin with a DML keyword (SELECT, INSERT, UPDATE, DELETE, TABLE, WITH) and must not contain statement terminators or comment markers. Returns undef if the SQL fails validation.

Pass trusted SQL only. MariaDB's optimizer evaluates constant subqueries while building a plan, so EXPLAIN can run functions. Known stalling or data-leaking ones (SLEEP, BENCHMARK, GET_LOCK, MASTER_GTID_WAIT, MASTER_POS_WAIT, EXTRACTVALUE, UPDATEXML, ...) are rejected, and the statement runs under SET STATEMENT max_statement_time=N FOR so anything that slips past the deny-list is bounded. N is $DBIx::Fast::Profile::MariaDB::EXPLAIN_TIMEOUT (default 5 seconds). The mysql profile has no SET STATEMENT; it relies on the deny-list.

get_table_stats

my $stats = $mariadb->get_table_stats($table);

Returns table metadata from information_schema.tables including engine, row count, and data/index sizes.

get_index_stats

my $stats = $mariadb->get_index_stats($table);

Returns index column details and cardinality from information_schema.statistics.

analyze_indexes

my $analysis = $mariadb->analyze_indexes($table);

Performs a comprehensive index analysis combining schema metadata with performance_schema usage data. Returns indexes, detected problems, and optimization recommendations.

$mariadb->print_index_analysis($table);

Prints a formatted index analysis report for the given table, including usage stats, problems, and recommendations.

get_index_metrics

my $metrics = $mariadb->get_index_metrics($table);

Returns per-index I/O wait metrics (reads, writes, fetches, latency) from performance_schema.

monitor_connections

my $stats = $mariadb->monitor_connections();

Returns a comprehensive snapshot of current connections, processes, variables, status counters, per-user usage, and detected problems.

Prints a formatted connection monitoring report including active processes, settings, status, and any detected problems.

start_connection_monitor

$mariadb->start_connection_monitor($interval, $duration);

Runs a continuous connection monitor that refreshes every $interval seconds (default 60) for up to $duration seconds (default 3600).

SEE ALSO

DBIx::Fast::Profile::Base, DBIx::Fast::Profile::mysql, DBIx::Fast::Profiler, DBD::MariaDB

AUTHOR

SeHarrys

LICENSE

This is free software under the Artistic License 2.0.