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 1kaN93-00045G-59 for pgsql-performance@arkaria.postgresql.org; Wed, 04 Nov 2020 18:04:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kaN8y-0005cA-Tf for pgsql-performance@arkaria.postgresql.org; Wed, 04 Nov 2020 18:04:24 +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 1kaN8y-0005c1-MY for pgsql-performance@lists.postgresql.org; Wed, 04 Nov 2020 18:04:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaN8u-0004u7-Ux for pgsql-performance@lists.postgresql.org; Wed, 04 Nov 2020 18:04:23 +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 0A4I4IVu1234727; Wed, 4 Nov 2020 13:04:18 -0500 From: Tom Lane To: Eric Raskin cc: pgsql-performance@lists.postgresql.org Subject: Re: Adding nextval() to a select caused hang/very slow execution In-reply-to: References: Comments: In-reply-to Eric Raskin message dated "Wed, 04 Nov 2020 12:10:21 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1234725.1604513058.1@sss.pgh.pa.us> Date: Wed, 04 Nov 2020 13:04:18 -0500 Message-ID: <1234726.1604513058@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Eric Raskin writes: > I have a strange situation where a base query completes in about 30 seconds > but if I add a nextval() call to the select it never completes. There are > other processes running that are accessing the same sequence, but I thought > that concurrency was not an issue for sequences (other than skipped > values). Shouldn't be, probably ... but did you check to see if the query is blocked on a lock? (See pg_stat_activity or pg_locks views.) > The only change that > causes it to be extremely slow or hang (can't tell which) is that I changed > the select from: > select unnest(.... > to > select nextval('sbowner.idgen'), unnest(.... Without seeing the complete query it's hard to say much. But if this isn't the topmost select list, maybe what's happening is that the presence of a volatile function in a sub-select is defeating some key plan optimization. Did you compare plain EXPLAIN (w/out ANALYZE) output for the two cases, to see if the plan shape changes? regards, tom lane