Mirroring
Overview
ProxySQL's mirroring feature duplicates queries to multiple host groups for performance testing without impacting live traffic. Mirroring is enabled for the final query if the original was rewritten.
Configuration
Two columns were added to mysql_query_rules to enable mirroring:
mirror_flagOUT(INT UNSIGNED)mirror_hostgroup(INT UNSIGNED)
Implementation Logic
When either parameter is set during query processing:
- A new MySQL session is created with identical properties to the original
- The mirrored session inherits credentials, schema name, and default hostgroup
- If
mirror_hostgroupis specified, it becomes the new session's default hostgroup - Without
mirror_flagOUT, the original query executes againstmirror_hostgroup - With
mirror_flagOUT, the query matches rules starting from that flag value, enabling further modifications
Use Cases
Performance Testing — Mirror SELECT statements to test environments while preserving production traffic.
Query Rewrite Validation — Test regex patterns and rewrites without affecting live users by
setting mirror_flagOUT to route mirrored queries through separate rules.
Firewall Testing — Combine mirroring with error_msg to process queries without execution,
allowing verification of rewrites without server impact.
Metrics
Metrics are collected for both original and mirrored queries in stats_mysql_query_digest.
Limitations
Mirroring does not support prepared statements.