Will DB.model.first(id)
always be more performant than a DB.model.first("field = ?", value)
, even if there is an index on field?
If there is an index
on field
then the two queries will be comparable. The lookup by id
may be slightly faster in theory, but the difference will probably be negligible.
Therefore, assuming an index
on the name
field
, the following two queries should be equally performant …
var id = "UUID";
var someone = DB.person.first(id);
var name = "Some Name";
var someoneElse = DB.person.first("name = ?", name);
1 Like