Tagged articles
7 articles
Page 1 of 1
Java Captain
Java Captain
Jul 17, 2021 · Databases

Optimizing Existence Checks: Use SELECT 1 LIMIT 1 Instead of SELECT count(*)

Developers often use SELECT count(*) to check record existence, but replacing it with SELECT 1 … LIMIT 1 improves performance by stopping after the first match, allowing simpler Java null checks and potentially reducing index usage, especially when only a binary presence test is needed.

Database OptimizationExistence CheckJava
0 likes · 3 min read
Optimizing Existence Checks: Use SELECT 1 LIMIT 1 Instead of SELECT count(*)