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 1kxVoj-0002t6-VG for pgsql-sql@arkaria.postgresql.org; Thu, 07 Jan 2021 13:59:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kxVoh-0005Jg-Ri for pgsql-sql@arkaria.postgresql.org; Thu, 07 Jan 2021 13:59:07 +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 1kxVoh-0005JY-H4 for pgsql-sql@lists.postgresql.org; Thu, 07 Jan 2021 13:59:07 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kxVoa-0002fZ-79 for pgsql-sql@lists.postgresql.org; Thu, 07 Jan 2021 13:59:06 +0000 Received: by mail-io1-xd31.google.com with SMTP id z5so6163203iob.11 for ; Thu, 07 Jan 2021 05:58:59 -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=ktHp9h0dzuxINepuPMgUJsSySn2xNJQ+S03iqnhsqDc=; b=zWMAH5vfqtqCb/jIVWrmMLkPtRF7dexmhusX9oPEkGV6vANUEJCBgrSXE0FKumh9wJ j9lKyXbg/F0ZL6UGMgP7GryQ71776S60oz9McRWeNjfGLCxZ1ri6BaTHT3c7sjmjErdA WjQwdP+wmWiy5OOK4jTWyEomu9kPe9nh/ZwKwqEqYnL4ptoxzpmiZPxDG8qFl7Y0cv75 8tNNpludL3oufdkkkDYx4L0tJcUwe9sxIvhBXfxz+uhXBbYKfj808kOmfFTSGqvupdnt XA7ZFOk82f66wD6/RGMhFJKVuW0Zx82DrLkThOYzCXdzIcT/2Di6dzwz/FWI1fEjdR35 x2CQ== 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=ktHp9h0dzuxINepuPMgUJsSySn2xNJQ+S03iqnhsqDc=; b=IALF4AYqAQcyjlDJMfhIKpkEU5fGsWg68Dbv3QqbLoIPK35R2PTzHsBv4e/2gKDZTM ypd73WXwnWiYxG6tbB/ZSKGWda4tJlST8nJR7PofwRcYlQ8/0Z+qGCpGeIKxAZNZ/fUy wKLbevfO+HDXkFmZSVm+rKM5P45qrkZbndiwa182xAEDGF9Yj698q9vdPErVnb9b2Fs8 i4tUyARXrKmSSArZzhGjVBYR98Z+yurS/AtPnP7zJS9V0YG0jYKx8kBgPFY/pkg3IfhV IjdxJuQsBkHQKKEffJ8HmjffZ52VvuH+i+6Nre+UbBLqOXr5iz+upP2icyqKiiUpqDzV 1Qjw== X-Gm-Message-State: AOAM533QEXlYUXRip2WVnBCizqmgbADgbGekSXCmjg7FKvsKtPCc0KTF 2sGjfuFS+Cre/GKe1ic2DBXJRA== X-Google-Smtp-Source: ABdhPJwYuopUS8DW1y9ong9WUJ2032dsEorLRL5L3H6pd257SavpBkX2a6ybUlMSDAF4pFExwH9mvg== X-Received: by 2002:a02:ccdc:: with SMTP id k28mr7925948jaq.137.1610027938892; Thu, 07 Jan 2021 05:58:58 -0800 (PST) Received: from [10.0.1.22] (user-10lff1p.cable.mindspring.com. [65.87.188.57]) by smtp.gmail.com with ESMTPSA id x3sm3353149ila.29.2021.01.07.05.58.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jan 2021 05:58:58 -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 08:58:56 -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 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. 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() -- = https://docs.djangoproject.com/en/3.1/ref/models/querysets/#django.db.mode= ls.query.QuerySet.select_related Cheers Philip=