On 2/5/16, Paul <devgs at ukr.net> wrote: > > Does it have any advantage or worse, a downside to have "LIMIT 1" in a > queries with "... WHRE id = ?;" ? > For example: > > SELECT bar FROM foo WHERE id = ? LIMIT 1; > SELECT 1 FROM foo WHERE id = ? LIMIT 1; > ... etc >
When "id" is a UNIQUE column (or an INTEGER PRIMARY KEY), then there is only going to be a single row of output, regardless of whether or not the LIMIT 1 is used. So the answer is the same either way. As you conjecture, there is a small amount of overhead involved in processing the "LIMIT 1" clause. Further more, SQLite does not optimize-out the LIMIT 1 so there is a very small amount of run-time overhead associated with initializing and maintaining the counter. But in both cases the overhead is very small. I think you will have difficulty measuring any difference between what you have written above and the same query without LIMIT 1. -- D. Richard Hipp drh at sqlite.org