>From now on I wont use "LIMIT 1" in these cases any more. Such queries will be more readable and surely not slower.
Thank you for explanation! Paul 5 February 2016, 14:21:35, by "Richard Hipp" <drh at sqlite.org>: > On 2/5/16, Paul 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