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 1oeW0Y-00033i-7r for pgsql-general@arkaria.postgresql.org; Sat, 01 Oct 2022 06:29:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oeW0X-0006Jy-3d for pgsql-general@arkaria.postgresql.org; Sat, 01 Oct 2022 06:29:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oeW0W-0006HU-OO for pgsql-general@lists.postgresql.org; Sat, 01 Oct 2022 06:29:52 +0000 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oeW0U-0007z1-B2 for pgsql-general@lists.postgresql.org; Sat, 01 Oct 2022 06:29:52 +0000 Received: by mail-oo1-xc2f.google.com with SMTP id c13-20020a4ac30d000000b0047663e3e16bso3619105ooq.6 for ; Fri, 30 Sep 2022 23:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:from:to:cc:subject:date; bh=q3HtuCD6XIrcyUbLPZOUEZMV/rTL8y3mr1p+NNz/024=; b=khptZQ+hKIJJUW1WAnFRuSETRXEmNBezEHuEgswdKiN6NYWCWKLmfzcpq+Ec7gwMan T3oZIjc7K7lYYSBzwRUCkIc+yWTEoCjMnbkP8L71xFrX685wc8DS9aidXt7ALYG5wgJo VU63QG8V4AAH2+RUyi7Ck1Tcd799VfLnC7NtDEpTs+iTlkNlRlQh1975h96xMVorT8Yx jsxCfvWn0fXcZfGthLVEFwcNtXzOwsW7TGyjAlwY5NEdCadqDLV/iKFywQJ+yUji5rBa /Cs4SWI6Gf+WwxgZdiff7mdolRbPAFooKVCE+0KmxiuNo+XCokPi4NrYyf9Kn5GH2w7m C3/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=q3HtuCD6XIrcyUbLPZOUEZMV/rTL8y3mr1p+NNz/024=; b=VVtg3/4HUFUFNvWIhPTYDRBNzWgpzvWCcUpeUM199YnrxjQ8yG3pvGP9DLvdnbJJ1D zxFPp1DLAK8v3fvkBSIg2Wkf2rIM2i/i1jtXQl4fE91T9033aCPTdY6FD8w+2gdceHEW KudaH27A4rA52S0r1Wr0Q7Sq0OeqDh9mX1Gy4M7HYzcQSFVX1NYsh0gxKwPJPy2DTICz r1uyGVhbsVvu4H3/gGbiEAoLas+HYJdAjq/jOTB+etOowXyofvi/BNZJnq4dn51IoqI6 HMMiC8ko6gAIMqx03J8IukKw13hxCoo7RFhzXlyj37pKW/QR98hj7+e3WUJAvYxQ6jEY 1huA== X-Gm-Message-State: ACrzQf2cQsgi8tSptkseNE0YXvyhIjxHzjmqCzznTNmAxTu3xup37n/I 309lMw6eNEr+0nKAhSSyyFNlGReU5fE= X-Google-Smtp-Source: AMsMyM7irOotsE5RpjW/7CYhpDrS1d4/431hfeQ00ybt+iXcFhgSPT5ONWhH8H3vavakWjizs/UdLg== X-Received: by 2002:a05:6830:1f4c:b0:655:cd18:a195 with SMTP id u12-20020a0568301f4c00b00655cd18a195mr4782839oth.310.1664605788592; Fri, 30 Sep 2022 23:29:48 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id r17-20020a4ae5d1000000b00476989d42ebsm873880oov.8.2022.09.30.23.29.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Sep 2022 23:29:48 -0700 (PDT) Message-ID: Date: Sat, 1 Oct 2022 01:29:46 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 To: pgsql-general list Content-Language: en-US From: Ron Subject: Singleton SELECT inside cursor loop Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk AWS RDS Postgresql 12.11 It runs quickly, no matter what the fetched cursor values are, as long as the cursor returns less than 8 rows.  After that, the singleton SELECT's performance tanks. We've got plenty of other procedures which have a similar "Singleton SELECT inside a cursor" design (many even query the same table that the problematic query does), but only this procedure's singleton SELECT tanks if the cursor returns more than 8 rows. It only runs once a month, so we've only just noticed the problem. Why would that be?  (We recently updated from 12.10 to 12.11, if that's relevant.) -- Angular momentum makes the world go 'round.