I am making a simple sign up and login page in node js using sequelize(MySQL). I want to know how to implement sorting in the database on the username field during insertion operation and then use binary search to find a specific username in the database and return the index. I don't want actual code solution but any tutorial links or official docs that can help me. Thanks in advance.
Asked
Active
Viewed 264 times
1
-
4Why would you want to do this? The DBMS already implements searching algorithms and usually picks a good one to find a record. That's part of the point why one uses a DBMS. – sticky bit Jun 10 '19 at 15:19
-
2Well, index your columns instead of implementing your own. – nice_dev Jun 10 '19 at 15:21
-
1@stickybit So, if I run the query Sequelize.find on usernames in the table, it will automatically implement searching algorithms? That is binary search instead of linear search going from 1st index till last? – Dhruv Singh Jun 10 '19 at 15:36
-
1@vivek_23 I am sorry I don't understand what you mean. – Dhruv Singh Jun 10 '19 at 15:37
-
1@DhruvSingh: Sequelize should not search for itself, it asks the DBMS to find the record. And the DBMS has means implemented to find the record. To help the DBMS using fast searching algorithms you should create proper indexes on the tables. – sticky bit Jun 10 '19 at 15:42
-
1Proper indexes as in? My table has fields Id, username and password. – Dhruv Singh Jun 10 '19 at 15:44
-
1That depends on your search criteria. – sticky bit Jun 10 '19 at 15:45
-
1I want to search for a specific username in username column. – Dhruv Singh Jun 10 '19 at 15:48
-
1@DhruvSingh You can index your column in the database for fast search instead of implementing binary search on your own. See here https://stackoverflow.com/questions/2955459/what-is-an-index-in-sql – nice_dev Jun 10 '19 at 15:50
-
1@DhruvSingh: Then create an index on that column. For further info you should do a research on that topic. There are plenty of sources discussing indexing. That is to broad to handle that in the comments here. – sticky bit Jun 10 '19 at 15:51
-
1Alright, I will check that. Thanks – Dhruv Singh Jun 10 '19 at 16:08