count vs findOne ? Which one is efficient #14340
Unanswered
uzair004
asked this question in
Help & Questions
Replies: 3 comments 2 replies
-
The fastest solution is probably this: User.findOne({
attributes: ['id'], // reduce how much data is loaded
raw: true, // don't build a model instance, return the raw data
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
Found this issue that might interest you #10187 |
Beta Was this translation helpful? Give feedback.
0 replies
-
After doing some tests directly with MySQL, I found that a query with a LIMIT 1 is up to 10 times faster than a count on the table without a WHERE clause. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Most of the time we want to check if something exist in database or not.
There are 3 main approaches in SQL in general
Among first two which one should be used?
Don't you think there should be
exists()
method in sequelize?Beta Was this translation helpful? Give feedback.
All reactions