Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-06 Thread Web Architect
Hi Furbee, Thanks for the suggestion. Would look into it. Thanks. On Sunday, February 4, 2018 at 10:32:20 AM UTC+5:30, Furbee wrote: > > You can set up an index on multiple field, as well, so if you’re searching > for As without a reference from B or C, using the index_together operative > i

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-03 Thread Furbee
You can set up an index on multiple field, as well, so if you’re searching for As without a reference from B or C, using the index_together operative in the class Meta for that model. I’m not completely sure, but I think this may speed up you query time. Thanks, Furbee On Saturday, February 3, 2

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-03 Thread Vijay Khemlani
Well, you should've said that in the first post. First I would try with a saner DB (Postgres) Also I don't think 300 ms is particularly bad, but in that case start looking into caching alternatives (e.g. memcached) or a search index (e.g. ElasticSearch) On Sat, Feb 3, 2018 at 3:14 AM, Web Archit

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi Furbee, Thanks for your response. With my experience I have always noticed that a query within query kills the mysql and Mysqld CPU usage hits the ceiling. I would still check your alternate. I have mentioned the size of A and B in response to Vijay's reply. On Saturday, February 3, 201

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi Vijay, Thanks for your response. In my scenario, there is also another model with manytomany relation with A: class C(models.Model): a = manytomany('A', related_name='cs', through='D') so, for around 25K records in A, 45K records in D and 18K records in B, following query takes more tha

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Furbee
There are a couple options you could try to see which is the best fit for your data. With DEBUG=True in settings.py you can check the actual queries and process time. It depends on the sizes of A and B. Another query you can run is: A.objects.exclude(id__in=B.objects.all().values_list('a_id', flat

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Vijay Khemlani
"with large of records in A and B, the above takes lot of time" How long? At first glance it doesn't look like a complex query or something particularly inefficient for a DB. On Fri, Feb 2, 2018 at 11:31 AM, Andy wrote: > not that i know of > > > Am Freitag, 2. Februar 2018 15:28:26 UTC+1 schri

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Andy
not that i know of Am Freitag, 2. Februar 2018 15:28:26 UTC+1 schrieb Web Architect: > > Hi Andy, > > Thanks for your response. I was pondering on option a before posting this > query thinking there could be better ways in django/SQL to handle this. But > now I would probably go with a. > > Than

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi Andy, Thanks for your response. I was pondering on option a before posting this query thinking there could be better ways in django/SQL to handle this. But now I would probably go with a. Thanks. On Friday, February 2, 2018 at 7:50:53 PM UTC+5:30, Andy wrote: > > a) Maybe its an option to p

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Andy
a) Maybe its an option to put the foreign key to the other model? This way you dont need to make a join to find out if there is a relation. b) Save the existing ralation status to model A c) cache the A.objects.filter(bs__isnull=False) query But apart from that i fear you cannot do much more, s

Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi, I am trying to optimise Django queries on my ecommerce website. One of the fundamental query is where I have no clue how to make efficient. It could be trivial and probably been known long time back. But I am new to Django and would appreciate any help. This is primarily for one to many or