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 1tuCIz-004za9-MN for pgsql-performance@arkaria.postgresql.org; Mon, 17 Mar 2025 15:23:05 +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 1tuCIy-00EZRY-3K for pgsql-performance@arkaria.postgresql.org; Mon, 17 Mar 2025 15:23:04 +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 1tuCIx-00EZRP-Of for pgsql-performance@lists.postgresql.org; Mon, 17 Mar 2025 15:23:03 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tuCIt-003OOv-26 for pgsql-performance@postgresql.org; Mon, 17 Mar 2025 15:23:03 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 52HFMvb74008328; Mon, 17 Mar 2025 11:22:57 -0400 From: Tom Lane To: kimaidou cc: postgres performance list Subject: Re: Bad perf when using DECLARE CURSOR on big table In-reply-to: References: Comments: In-reply-to kimaidou message dated "Mon, 17 Mar 2025 15:41:07 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4008326.1742224977.1@sss.pgh.pa.us> Date: Mon, 17 Mar 2025 11:22:57 -0400 Message-ID: <4008327.1742224977@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk kimaidou writes: > I have seen that this DECLARE has bad perf compared to a simple SQL query : > Simple SQL query > ===== > https://explain.dalibo.com/plan/042bc4dc2449adfe > 96ms > DECLARE CURSOR for the same query > ===== > https://explain.dalibo.com/plan/bh83fc0db500a79g# > 171 031 ms !! Raising cursor_tuple_fraction would probably help this case. regards, tom lane