Answer the question
In order to leave comments, you need to log in
How to implement binary search in Django database?
I wanted to make mini applications, prepared a database consisting of 10 million unique names (and another table for 9 million surnames, also unique). But when searching through these databases, one request is completed ~ 1.5 seconds. Which is long, but I make 2 requests (first and last name), as a result 3.
Clarification, the database is in a sorted state, by first and last name (from smallest to largest).
The questions I have are:
1. Will it affect, if so, how, transferring all data from sqlite3 to postqresql in django itself?
2. Is it possible to instantly get the value from the sqlite3 base by index? And if possible, then please show an example of how to do this in the django model.
At the moment I get the value like this:
try:
name_count = Names.objects.get(name=name).count
except ObjectDoesNotExist:
name_count = 1
Answer the question
In order to leave comments, you need to log in
1. I doubt it very much.
2. The request Names.objects.get(name=name).count uses the index perfectly, if you created it, of course . 14 million rows for an index, especially a unique one, is very small. And if you didn’t create it, then it’s fullscan and for a very long time
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question