问题
I'm working on Django 2.1.5 and MySQL 14.14.
I'm trying to query using a wildcard search as below for single character replacement.
98765?321- returns all the numbers in the database column with a single replacement for?- at most10numbers will be returned.98?65?321- returns all the numbers with single replacement for both?s - at most100numbers will be returned.98?65?32?- returns all the numbers with single replacement for first?and all the numbers ending with that for second?- any number of numbers could be returned.98?65?3?1- returns all the numbers with single replacement for all three?s - at most1000numbers will be returned.987?should return all the numbers starting with987- could return any number of numbers.
I was able to do this with Model.objects.filter(column_regex=regex).
But as the DB contains 50 millions of rows, this is impacting performance.
How can I do the same thing with column__contains or column__icontains etc.
Sample DB column values:
9875156245
7657676372
3765277678
7765725757
来源:https://stackoverflow.com/questions/57004942/django-orms-contains-vs-sqls-like