python - mysql table with many records and new index still slow -
i have following table little less 600,000 records:
create table `organization` ( `id` int(11) not null auto_increment, `company_name` varchar(255) default null, `uuid` varchar(255) default null, `created_at` varchar(255) default null, `updated_at` varchar(255) default null, primary key (`id`), key `org_company_name_7467253` (`company_name`) ) engine=innodb auto_increment=589816 default charset=utf8mb4; the table running slow created index on company_name:
create index `org_company_name_7467253` on `organization` (`company_name`); i doing several queries following taking around 30 seconds each:
for e in entity.objects.all(): #around 2000 records - select * entities if organization.objects.filter(company_name__icontains=e.name): #600,000 records - select * organizations company_name = entity.name print 'contains organization' is there can speed up?
doing same query 2000 time take time. 30000 ms isnt 15 ms query.
so either multithread send multiple request @ same time db, did here:
https://codereview.stackexchange.com/a/155263/95510
or join in db same result in single query.
dont know how work django, guess entity.objects.all represent table in db.
so like:
select e.*, o.* `entity.objects.all` e -- 2000 records make sure have index on name left join `organization` o -- 600,000 records on e.name = o.company_name o.company_name not null
Comments
Post a Comment