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 1sRLvB-00EdNO-2z for pgsql-general@arkaria.postgresql.org; Wed, 10 Jul 2024 01:15:01 +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 1sRLv9-001CL5-Op for pgsql-general@arkaria.postgresql.org; Wed, 10 Jul 2024 01:14:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRLv9-001CKr-Dk for pgsql-general@lists.postgresql.org; Wed, 10 Jul 2024 01:14:59 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sRLv5-001I8S-5E for pgsql-general@lists.postgresql.org; Wed, 10 Jul 2024 01:14:58 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1fb3e9e32ffso25714755ad.0 for ; Tue, 09 Jul 2024 18:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720574094; x=1721178894; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4xOki12MUL1KjUBqcSFHYPrfJNkQzEyJ8zGNYn+Tk2o=; b=ZXva1s1ESj2xSrElN/EaNpbaA3er2QVNdVdsYhtQAUo3sz/DUZ3Wgm+bA4qtuCnzsr 1GGcWB3ypYLX16eNb5EVOAMl/wwF0mz6Ozu96GUmE7JgyWik7IqLP1uv5RZbhT138Zxf U2NpYDbd6XMx4hY4nD6N+Sp4IwPyjYY8A69Q+8BL2vnDWnT/h6uyrR8ubgfP997XycVo 04huv2SemWRKWOa6a3ARihAFENtorLSkQn+yB91URpitcU9PFJJCv4MtmFehYltXNs+C uEnV2p3PZdupBloz/3WVAIkk6a4dQTE1YH6qHky/+QWWMzjv0gUKL88Jh3Yz0O2smNoO v6Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720574094; x=1721178894; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4xOki12MUL1KjUBqcSFHYPrfJNkQzEyJ8zGNYn+Tk2o=; b=VLXIBtZySXLJtvRS4LvixbUUCICd+ANOZwwTSoREv/1hjFUiXgMAFyrYWED6HkpCyu +ORgbQVXDtyf/8gt/0QeP9bl9hmj8SZODCuie0hBZzpvhsep1IE+6+x9NVul9+FAeNvP 5pnk+ruHC5wJGT5sTQfZENQGuL5Bn2aoVtoiQQWMcLnnkHlgyIzhszliUAdLWg0EzORd jp6157+LCjohMjBAB/Bz2QkE0TQaylydIGe6NoDi4t9z5ow1VrbXvkojuGOpAqBFJf0o UAYf/BANVWsvfPi5enAaVU6NtYYWYSXXl3U0RmN8bbwxPxpw/Krqljr9D5/CB8gpXc4u gEWQ== X-Gm-Message-State: AOJu0Yy8a5JLaMnnFC85+0mXrbEVJFWXBfEfCIoNIKQpOR4lt7qgvjHE 7EhDJ5U4ZejjT/1gcUE6tCNlMiuO+EmVTIH5onqvyEEkF7YMikA4 X-Google-Smtp-Source: AGHT+IG94+uK/WVSJv2MQ1Fi6jMnuDw7lieBfE7RDMHXLbdklIfxojj0SBo4ZVmHruMdaaxNlD3BTw== X-Received: by 2002:a17:903:230e:b0:1fb:99f6:81d6 with SMTP id d9443c01a7336-1fbb6eb8514mr28711605ad.55.1720574094005; Tue, 09 Jul 2024 18:14:54 -0700 (PDT) Received: from smtpclient.apple ([2600:8801:8600:3d2::12]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6acf63fsm21978035ad.268.2024.07.09.18.14.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jul 2024 18:14:53 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: can stored procedures with computational sql queries improve API performance? From: Guyren Howe In-Reply-To: Date: Tue, 9 Jul 2024 18:14:42 -0700 Cc: "pgsql-general@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <04AE80B8-1F00-4758-A498-C1C7C1FC7A31@gmail.com> References: To: Krishnakant Mane X-Mailer: Apple Mail (2.3774.600.62) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Jul 9, 2024, at 17:58, Krishnakant Mane wrote: >=20 > Hello. >=20 > I have a straight forward question, but I am just trying to analyze = the specifics. >=20 > So I have a set of queries depending on each other in a sequence to = compute some results for generating financial report. >=20 > 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). >=20 > There are at least 6 queries in this sequence and apart from 4 input = parameters. these queries never change. >=20 > So will I get any performance benefit by having them in a stored = procedure rather than sending the queries from my Python based API? Almost certainly. Doing it all in a stored procedure or likely even better a single query = will remove all of the latency involved in going back and forth between = your app and the database. Insofar as the queries you are running separately access similar data, a = single query will be able to do that work once. There are other potential benefits (a smaller number of queries reduces = planning time, for example).=