Pre-Deployment Audit
Select your database and inspect your query structure before opening a PR.
Review Checklist
Optimization Strategies and Common Mistakes
Database engines are incredibly smart, but they still rely on developers to write clear, precise queries. Inefficient queries can cause locking, crash production databases, or silently consume unnecessary I/O. As a junior developer or data analyst, it helps to build a reliable mental model before submitting your code for review. Here are some fundamental rules to check.
The Danger of "SELECT *"
Using SELECT * in production queries is a common antipattern. It forces the database to read every column from the disk, even if your application only needs one or two fields. If a teammate adds a large text or binary column to the table later, your query will instantly become slower without the code ever changing. Always specify exact column names.
Sargability and Function Usage
Sargable stands for "Search Argument Able." If you wrap a column in a function inside a WHERE clause (for example, WHERE YEAR(created_at) = 2026), the database cannot use standard indexes on that column. Instead, it must run that function against every row in the table, resulting in a full table scan. Rewrite the logic to keep the column bare: WHERE created_at >= '2026-01-01' AND created_at < '2027-01-01'.
Implicit Operations
Implicit casting happens when you compare a column of one data type to a value of a different data type. If your user_id is a string, but you query WHERE user_id = 12345, the database has to convert the column to an integer for every row before comparing. Keep your data types strictly aligned.
Reading Explain Plans
This checklist catches structural issues, but your final step should always be running an EXPLAIN or EXPLAIN ANALYZE statement on your database. Keep an eye out for "Seq Scan" (sequential scans) on large tables, nested loops that examine millions of rows, or heavy temporary file usage during large sorts.
Assumptions: This auditor assumes you possess basic permissions to view table schemas in your database and that you understand the indexes currently available on your target tables. QueryGuard does not connect to your server to verify index existence. You must verify indexes manually using tools like pg_stat_statements or your DBA's documentation.