Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRe3y-00HMr4-Nq for pgsql-general@arkaria.postgresql.org; Wed, 10 Jul 2024 20:37:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sRe3x-008q9m-9E for pgsql-general@arkaria.postgresql.org; Wed, 10 Jul 2024 20:37:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRe3w-008q9e-Un for pgsql-general@lists.postgresql.org; Wed, 10 Jul 2024 20:37:16 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sRe3u-001Rob-M9 for pgsql-general@postgresql.org; Wed, 10 Jul 2024 20:37:16 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3d9da46ca13so112123b6e.2 for ; Wed, 10 Jul 2024 13:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720643833; x=1721248633; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eOzGklCwekGANxbwLCUJRByIE8PUWvm6RkU9zKe8/TM=; b=FvxNhpx1/noT80X7iGMWqACdANILJ1ywUI6/pspzaPrsPgwBJgYlt/6Xa/H/Mn46IC cRVeTvS5Gdy3XjrRIs2SRHKRpKgw2Bd1pEeaAQWGHsxSxSa/Ol+Fb7BR1x+kl7FWbVVI mIaLS7x5FWWP5SAzvJY6h7IBAaGI7O4qnt+EBPmsoDPRPELbRNafGd3HpiftecfzbLy1 sQ2p7qvaKhf1XfkavnUemn7s99ZTBFHPNG9S/lmZfpcnHM751FlvOyg5CMS1ciITngXa nhcHOE0UMLQ0y8DF3YoDiDJ9x49ezuJ0CiW6UupcIjmQm6lHjCIJe/QIeKdPgyCfv46X NK8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720643833; x=1721248633; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eOzGklCwekGANxbwLCUJRByIE8PUWvm6RkU9zKe8/TM=; b=aL5pUHYpL/+uZuOkKI6tLmJUeVvMkvBQ625aibk3qMEuUj7k/5M1SosbQonbElf0rm WfIGX5wJq5fPBhWG6DPohGbcK9M12kX/ZXwmXpxjdXZU4urOfrEqamQ5XgeJkXcz7aPf gkaEv8mFw399A174jMo79KepyrkcO4HUrrMp9W7OQ08DOg13+2+OeTlFXunO9uo2Dlpc XuPsM6iQZtkWWYfzVE4Atb2hVfXgruEJUjawqTZKTojcBoxp5Od04va8qI2L9gybNbj4 fM0Ilo+glwnmqZaYR0qbZYJkbuE5UDeRAZU60ThVhGVWi2zPfNONS+tFXjG4dhOkloK3 iYFQ== X-Gm-Message-State: AOJu0YwD92kbtC77GTfh0B40bneNr04n0kBlMPjDtLCpXFw+eBUcxkDl DKJfy8eFuOVvpdHl6bV3vOiugs4gLlgDQNQFnT0ShS3ncCa/oHWmEhdDYTZyUYLdZeUVG5qJj0m XXadwBXAaHmNy+nZ3sN876M4sYw== X-Google-Smtp-Source: AGHT+IGvBgOjef7KOx2Tmwr8gQWfF5/ue/Oq678nQJjRqWStLyQEjGn72tpEuirxtJ5w8IjbVVWeBEAkqd/1JA9NENY= X-Received: by 2002:a05:6808:2009:b0:3d9:df9d:8424 with SMTP id 5614622812f47-3d9df9d9178mr2902409b6e.33.1720643832728; Wed, 10 Jul 2024 13:37:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Juan Rodrigo Alejandro Burgos Mella Date: Wed, 10 Jul 2024 16:37:01 -0400 Message-ID: Subject: Re: can stored procedures with computational sql queries improve API performance? To: Ron Johnson Cc: pgsql-general Content-Type: multipart/alternative; boundary="0000000000006f549b061cea9c66" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006f549b061cea9c66 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Great tip!!! Thx El mi=C3=A9, 10 de jul de 2024, 16:17, Ron Johnson escribi=C3=B3: > On Tue, Jul 9, 2024 at 8:58=E2=80=AFPM Krishnakant Mane > wrote: > >> Hello. >> >> I have a straight forward question, but I am just trying to analyze the >> specifics. >> >> So I have a set of queries depending on each other in a sequence to >> compute some results for generating financial report. >> >> It involves summing up some amounts from tuns or of rows and also on >> certain conditions it categorizes the amounts into types (aka Debit >> Balance, Credit balance etc). >> >> There are at least 6 queries in this sequence and apart from 4 input >> parameters. these queries never change. >> >> So will I get any performance benefit by having them in a stored >> procedure rather than sending the queries from my Python based API? > > > One problem is that the query planner reverts to a generic query plan if > you execute the same query over and over in a loop in the SP. > > That bit us once. A big SP that had been running "normally" for months > suddenly went from about 20 minutes to six hours. The solution (given by > someone on this list a couple of years ago) was to add "set plan_cache_mo= de > =3D force_custom_plan;" above the call. > > That way, the query plan was updated every time. Performance dropped to > about 8 minutes IIRC. > > --0000000000006f549b061cea9c66 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Great tip!!! Thx


El mi= =C3=A9, 10 de jul de 2024, 16:17, Ron Johnson <ronljohnsonjr@gmail.com> escribi=C3=B3:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">
On Tue, Jul= 9, 2024 at 8:58=E2=80=AFPM Krishnakant Mane <kkproghub@gmail.com&g= t; wrote:
Hello.

I have a straight forward question, but I am just trying to analyze the specifics.

So I have a set of queries depending on each other in a sequence to
compute some results for generating financial report.

It involves summing up some amounts from tuns or of rows and also on
certain conditions it categorizes the amounts into types (aka Debit
Balance, Credit balance etc).

There are at least 6 queries in this sequence and apart from 4 input
parameters. these queries never change.

So will I get any performance benefit by having them in a stored
procedure rather than sending the queries from my Python based API?

One problem is that the query planner reverts to a= generic query plan if you execute the same query over and over in a loop i= n the SP.

That bit us once.=C2=A0 A big SP that ha= d been running "normally" for months suddenly went from about 20 = minutes to six hours.=C2=A0 The solution (given by someone on this list a c= ouple of years ago) was to add "set plan_cache_mode =3D force_custom_p= lan;" above the call.

That way, the query pla= n was updated every time.=C2=A0 Performance dropped to about 8 minutes IIRC= .

--0000000000006f549b061cea9c66--