1个不稳定版本
0.1.0 | 2023年4月8日 |
---|
#2814 在 数据库接口
8KB
124 行
sql-redactor
规范化并遮蔽SQL查询。支持多种方言,如mysql、postgres、clickhouse或hive。
这对于添加数据库的可观察性很有用。
当查询参数化时,很难找到QPS最高的查询
SELECT * FROM users where user_id = 1000
QPS 5SELECT * FROM users where user_id = 1001
QPS 3SELECT * FROM users where user_id = 1002
QPS 8- ..
SELECT * FROM articles where article_id = 2000
QPS 2SELECT * FROM articles where article_id = 2001
QPS 50SELECT * FROM articles where article_id = 2002
QPS 3
参数可以模糊化以提供更好的洞察
SELECT * FROM users where user_id = ?
QPS 3,000SELECT * FROM articles where article_id = ?
QPS 2,000
用法
cargo add sql-redactor
use sql_redactor::redact;
use sql_redactor::dialect::MySqlDialect;
let sql = "SELECT * FROM users
WHERE age > 18
AND city = 'New York'
ORDER BY last_name ASC;";
let redacted = "SELECT * FROM users WHERE age > ? AND city = ? ORDER BY last_name ASC;";
assert_eq!(redact(&MySqlDialect {}, sql).unwrap(), redacted);
基准测试
与典型的数据库延迟相比,遮蔽速度快。
AMD Ryzen 9 3900X
30us
SELECT * FROM foo WHERE bar = 1
60~70 us
SELECT * FROM users
WHERE age > 18
AND city = 'New York'
ORDER BY last_name ASC;
依赖
~2.5MB
~63K SLoC