pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Semanchuk <philip@americanefficient.com>
To: Sachin Kumar <sachinkumaras@gmail.com>
Cc: pgsql-sql@lists.postgresql.org
Subject: Re: how to make query
Date: Thu, 7 Jan 2021 12:05:29 -0500
Message-ID: <E25CD6BC-D5D2-488C-818C-7C37AE5ABD44@americanefficient.com> (raw)
In-Reply-To: <CALg-PKAjAt7aW3pWcN7BKPtjMiL5v4-cWJOuP_oxOGbhrjLhPQ@mail.gmail.com>
References: <CALg-PKBaGOBtLPD88JLuLkDFh6VarJraupdzOSCKxkAodyRT6w@mail.gmail.com>
	<B554173E-8FCB-480D-8684-8FB60F018B28@americanefficient.com>
	<CALg-PKAjAt7aW3pWcN7BKPtjMiL5v4-cWJOuP_oxOGbhrjLhPQ@mail.gmail.com>



> On Jan 7, 2021, at 9:25 AM, Sachin Kumar <sachinkumaras@gmail.com> wrote:
> 
> Hi Philip,
> 
> I am using Python Django and PostgreSQL to build our report app.
> 
> I am using below mention query to find some details. the query mention below is running fine in PostgreSQL command line and giving result in 2 sc for 2 million cards but when i i am try the same in Django application it is taking too much of time and the web page is expired while running this query.
> 
> can anyone help how to make query faster in Django? Or help me in correcting this query to be used in Django 


Sachin,
If your query runs well in Postgres, then your problem is with Django, not Postgres. You would be better off asking on a Django mailing list how to get Django to construct the query you want.




> 
> On Thu, Jan 7, 2021 at 7:28 PM Philip Semanchuk <philip@americanefficient.com> wrote:
> 
> 
> > On Jan 7, 2021, at 5:15 AM, Sachin Kumar <sachinkumaras@gmail.com> wrote:
> > 
> > Hi Team,
> > 
> > we are using Python Django and Postgresql. Our requirement is to search 10 Million Card data and bring specific records as a result after checking the record every time.
> > 
> > We have to find data from a 2nd table that is related to the first one which we are checking using the loop.
> > 
> > For Ex:- 
> > 10000 data - loop 10000 times 
> > to find data from the 2nd table. 
> > 
> > This makes our query too slower and it gets time out.
> 
> Hi Sachin,
> I’m not sure based on your description, but it sounds like you need to tell Django to select related objects all in one query rather than one at a time. If that’s the case, then your problem is a Django issue, not a Postgres one. Check out select_related() --
> 
> https://docs.djangoproject.com/en/3.1/ref/models/querysets/#django.db.models.query.QuerySet.select_r...
> 
> 
> Cheers
> Philip
> 
> 
> -- 
> 
> Best Regards, 
> Sachin Kumar






view thread (5+ messages)

Message-ID: <E25CD6BC-D5D2-488C-818C-7C37AE5ABD44@americanefficient.com>
Permalink:  ../E25CD6BC-D5D2-488C-818C-7C37AE5ABD44@americanefficient.com/
Also on:    postgresql.org/message-id/E25CD6BC-D5D2-488C-818C-7C37AE5ABD44@americanefficient.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: philip@americanefficient.com, sachinkumaras@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: Re: how to make query
  In-Reply-To: <E25CD6BC-D5D2-488C-818C-7C37AE5ABD44@americanefficient.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox