-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
When using ProxySQL in PostgreSQL mode, the internal digest normalization replaces table names and column names with ? if the query uses quoted identifiers (e.g., "TableName", "ColumnName").
This results in unrelated queries producing the same digest, making query statistics, monitoring, and rule matching unreliable.
Problem Description
ProxySQL aggressively normalizes PostgreSQL queries. When queries use quoted identifiers, table names and column names are replaced with ? in the digest.
This is problematic because:
Many unrelated queries collapse into the same digest.
Digest statistics (stats_pgsql_query_digest) are merged incorrectly.
Query rewrite rules (pgsql_query_rules) cannot reliably match queries.
SELECT * FROM "Attributes" WHERE "InventoryId"=123 AND "IsDeleted"=false;
SELECT * FROM "Inventory" WHERE "TenantId"=1 AND "IsDeleted"=false;
SELECT * FROM "Users" WHERE "UserId"=44 AND "Active"=false;
SELECT * FROM "Orders" WHERE "OrderId"=999 AND "Deleted"=false;
All produce the same digest:
select * from ? where ?=? and ?=false
Actual Result
Table names and column names replaced with ?
Digest statistics (count_star, sum_rows_sent, etc.) are aggregated across unrelated queries
Example digest record:
digest: 0x91f7ed1c43819467
digest_text: select * from ? where ?=? and ?=false
count_star: 3
sum_rows_sent: 171Expected Result
Digest should preserve table and column names from quoted identifiers.
Only literals (numbers, strings) should be replaced with ?.
Each query shape should produce a unique digest, even if identifiers use uppercase letters via quoted names.
Impact
Query digests are misleading
Query rewrite rules cannot reliably match queries
Statistics (count_star, sum_time, sum_rows_sent) are aggregated incorrectly
Steps to Reproduce
Configure ProxySQL with a PostgreSQL backend.
Run queries using quoted identifiers (uppercase table/column names).
Inspect stats_pgsql_query_digest:
SELECT digest_text, count_star FROM stats_pgsql_query_digest;Observe unrelated queries share the same digest.
Additional Notes
This only happens when using quoted identifiers, which are commonly used to preserve uppercase letters in table/column names.