top | item 45629197

(no title)

Guillaume86 | 4 months ago

Only if your table is missing an unique index on that column, which it should have to enforce your assumption, so yeah LIMIT 1 is a code (or schema in the case) smell.

discuss

order

dotancohen|4 months ago

IDs are typically unique primary key. But in my experience, adding LIMIT 1 would on average halve the time taken to retrieve the record.

I'll test again, really the last time I tested that was two decades ago.

EvanAnderson|4 months ago

That seems like your RDBMS wasn't handling something right there or there wasn't a unique index on the column.

Do you recall what the database server was?

Guillaume86|4 months ago

You should use the DB explain or equivalent command to spit out the query plan, limit 1 shouldn't change anything in your case, if it's not the case you should file an issue, it's pretty much 101 of query optimization.

viraptor|4 months ago

That would be a reportable bug. Of a pretty high priority.

buckle8017|4 months ago

You are certainly doing something wrong if that's true.

I'm curious, can you demo this?