Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxYjB-0008Ta-Jg for pgsql-sql@arkaria.postgresql.org; Thu, 07 Jan 2021 17:05:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kxYjA-0003Bb-Hg for pgsql-sql@arkaria.postgresql.org; Thu, 07 Jan 2021 17:05:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxYjA-0003Ae-6C for pgsql-sql@lists.postgresql.org; Thu, 07 Jan 2021 17:05:36 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kxYj6-00048i-Dt for pgsql-sql@lists.postgresql.org; Thu, 07 Jan 2021 17:05:35 +0000 Received: by mail-io1-xd33.google.com with SMTP id n4so6778128iow.12 for ; Thu, 07 Jan 2021 09:05:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=americanefficient-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=zaKJRYzaqINvAA8J68AszhO1QUOocuBagKLJsuZK8aE=; b=RYxCMB8Ufz+ly2flsO4NLoQnGuDYUJgbGw0IOtpco99L0LNlnBHrRXu9GJueLPztCu 3/MAPLCnl21U5HQMkkvfphI2iU8HMSo3dyQgGy6QbW8zG4UXC6mFgDHL8qHX/O+7VUS6 k94tvPOGojJ+UwUodDUzYPhVul3QyvMDdbsNZR0Husn479zEGzKETY3yi+9nz9YblZs2 Rvv3DoB65+i9zIOI4pgqwvC1uNb29ZcgipqP/1e67xCp7HwL+y0s7B/GRtRdXkyvoc8J cu2NNtgoESoueDJbvQPGvgaHWJ01SlCE1ACJmQo8DZe+vnxtGUv5uAsCTVlLKYH6/0GD R9jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=zaKJRYzaqINvAA8J68AszhO1QUOocuBagKLJsuZK8aE=; b=Hzhp4UMFfs/RBiFOl3Mxexx9a44A9NyP4VA8pQDDnmCPukkdzLhT1OYZNIw0W7/0Y+ qrvhQ19scfbPxwbwxo4LLtfMxTQTLttVy1M2lEFBTOaJU2geqwzbhqQLQWyOnQoHKOsR jvvNLcl6rbG221/7bR6Fw7UdMtIpGUJnfHCLV/OHROOeDlhHM+GGh5dIluNeC9pgFr4X ZXPuufJEinyEoi4TS9fwuwGIaXTJ6DM2u1zOT6bn32RdVyHkPam/aZ0ZqYCcjv4mxNkH pBLKvWXug1s65Ipzfp1GU3qzw6sAzaHC+p0tkqi3duUA/wSvn/Pv05Bj8s1HmVqayd/H qSaQ== X-Gm-Message-State: AOAM531dLkXZvEwX41K7+FKKe0gMV1jNFuuzCoN+fXEl8ltFYOVElq/B DieT+kCsniPGDGuuPCbJSA71mg== X-Google-Smtp-Source: ABdhPJw5zQ1jmPFyfgLlJmLvJ5VMHRiw5/R0wFFNBVF8v8j4lXpK2HtQGZxd6ajY2G0BsZkhYzXDIw== X-Received: by 2002:a05:6638:1243:: with SMTP id o3mr8724944jas.129.1610039131641; Thu, 07 Jan 2021 09:05:31 -0800 (PST) Received: from [10.0.1.22] (user-10lff1p.cable.mindspring.com. [65.87.188.57]) by smtp.gmail.com with ESMTPSA id z10sm3351445ioi.47.2021.01.07.09.05.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jan 2021 09:05:30 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Subject: Re: how to make query From: Philip Semanchuk In-Reply-To: Date: Thu, 7 Jan 2021 12:05:29 -0500 Cc: pgsql-sql@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Sachin Kumar X-Mailer: Apple Mail (2.3654.40.0.2.32) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Jan 7, 2021, at 9:25 AM, Sachin Kumar = wrote: >=20 > Hi Philip, >=20 > I am using Python Django and PostgreSQL to build our report app. >=20 > 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. >=20 > can anyone help how to make query faster in Django? Or help me in = correcting this query to be used in Django=20 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. >=20 > On Thu, Jan 7, 2021 at 7:28 PM Philip Semanchuk = wrote: >=20 >=20 > > On Jan 7, 2021, at 5:15 AM, Sachin Kumar = wrote: > >=20 > > Hi Team, > >=20 > > 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. > >=20 > > We have to find data from a 2nd table that is related to the first = one which we are checking using the loop. > >=20 > > For Ex:-=20 > > 10000 data - loop 10000 times=20 > > to find data from the 2nd table.=20 > >=20 > > This makes our query too slower and it gets time out. >=20 > Hi Sachin, > I=E2=80=99m 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=E2=80=99s the case, then your problem is a = Django issue, not a Postgres one. Check out select_related() -- >=20 > = https://docs.djangoproject.com/en/3.1/ref/models/querysets/#django.db.mode= ls.query.QuerySet.select_related >=20 >=20 > Cheers > Philip >=20 >=20 > --=20 >=20 > Best Regards,=20 > Sachin Kumar