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 1lZ2ML-00043f-N7 for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Apr 2021 02:12:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lZ2MK-00082F-Ks for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Apr 2021 02:12:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lZ2MK-000828-9K for pgsql-hackers@lists.postgresql.org; Wed, 21 Apr 2021 02:12:56 +0000 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lZ2MG-00040a-Sl for pgsql-hackers@postgresql.org; Wed, 21 Apr 2021 02:12:55 +0000 Received: by mail-ot1-x332.google.com with SMTP id 35-20020a9d05260000b029029c82502d7bso6245344otw.2 for ; Tue, 20 Apr 2021 19:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nw+1mbWJZuVtoUOgeAOEucHxbMGdg3D0YUebvCdCK2Q=; b=TUQOBXhnDXC8D9Yb0HGQj6cfeOHIFEGMfuJDCAhwtP4Wdx2cv1/hdI0xfrAH9YbLer LMPYeZFq1SskHEy++CTUgjfOBo47so/Yv3MI86IhY/O5hsjvyEf9nEydgAIjr2dX8c7V gyqBabWg/WgM//II9PniF7QMCWY8ZlcopTZ+pQSHRGUbvZueOYjmAN+YOS48ZoM89XDf stw+IB4dYWucJnustdwUVbVS/uL6pLR1wwznNhQomvs+mbZ649HmA5UP7eHpBx1QTcaL xmorEULeAApYui44V7aNi2Z1nLXQpVqWsV7z6xE9hDBZUXlrGKtWv5zTBwsQZ+7e6mo5 Vc4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=nw+1mbWJZuVtoUOgeAOEucHxbMGdg3D0YUebvCdCK2Q=; b=UKx9zB817qDoQBCileax8Osbl64xr5jUjixXTwnIW2+0jjhNiNUtT9nr/u0jKcAtGZ qeckWmTCnGBkFkQ3keYyu4yEaWiDXGIn3JqfZdxcf7afG+OSKPKwRRfXVrPGnirY2xlT O5iBKch84Z374dSnlGjt53Dw+s0kYg+oRJjYH+AJSqOgVW4Rk4RoOt1S2tmJf0AQzjeF kJvEgoEt2RxIWs7EWBeIfQT2RSEY53iaQwYK35KK5+i5CbSGmfclC6WOcWz+0Hl8wNnb Z+gzkLbBqUqQ7j6VOIsPhS93kJ7uIerAWQIdjWC/yWemMN6Mq47fv4fJi8t8S5Iphit5 mFWw== X-Gm-Message-State: AOAM530AejUUtgIryefUuOstLxRCQf8M3+oM0eEOJG8+nGwt8Lyh+vzs xoiD3lpkKfsn1uzyC7t2JcIkLw== X-Google-Smtp-Source: ABdhPJwdnb7kCnKipOTFxep0rC5AAk6mSXkuCSgmdqiLjYNOTwl7ci75OIW8zSNgESIizG9+A3CYZA== X-Received: by 2002:a9d:17e7:: with SMTP id j94mr21604751otj.41.1618971172071; Tue, 20 Apr 2021 19:12:52 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a134sm195624oii.29.2021.04.20.19.12.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Apr 2021 19:12:51 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 6FDDA800A3E; Tue, 20 Apr 2021 21:12:50 -0500 (CDT) Date: Tue, 20 Apr 2021 21:12:50 -0500 From: Justin Pryzby To: Andres Freund Cc: pgsql-hackers@postgresql.org, Tom Lane Subject: Re: terminate called after throwing an instance of 'std::bad_alloc' Message-ID: <20210421021250.GS7256@telsasoft.com> References: <20210417021755.xdcqaqqt4y46wzt7@alap3.anarazel.de> <20210417024854.GL3315@telsasoft.com> <20210417031837.GM3315@telsasoft.com> <20210418001324.GP3315@telsasoft.com> <20210419164130.byegpfrw46mzagcu@alap3.anarazel.de> <20210420053826.GM7256@telsasoft.com> <20210420055821.GA17201@telsasoft.com> <20210421002056.gjd6rpe6toumiqd6@alap3.anarazel.de> <20210421010313.GR7256@telsasoft.com> <20210421011628.nivvgehnwc2jefhf@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210421011628.nivvgehnwc2jefhf@alap3.anarazel.de> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Apr 20, 2021 at 06:16:28PM -0700, Andres Freund wrote: > On 2021-04-20 20:03:13 -0500, Justin Pryzby wrote: > > That's a query over a 2 day period (midnight to midnight+2), so it's not hard > > for me to believe it sometimes exceeds 100k cost units (jit_inline_above_cost), > > depending on where we are in that interval, and on planner statistics. It > > might've been different when I first reported the problem, too. > > > > I'm not sure what you mean about expensive enough to be jited ? > > I think our custom functions don't have a COST set. > > What get's JITed is queries. Unless your functions are fully inlinable > SQL functions that means that query executions in functions are > separately JITed. And need to separately pass the cost minimums. I think the queries our plpgsql functions make wouldn't be expensive - mostly lookups by primary key. And any functions called by the queries within the plpgsql function would not have COST set. What do you think of the test case I sent? | SELECT fn() FROM generate_series If the JIT contexts can't be reset for this query, I assume the same reason applies to our more complicated query. > Note that this isn't about how many plpsql functions or such are called, > but about how many JITed functions are generated. Typically there's one > function per expression, and one for each table accessed. Thanks for the explanations. Note that in our config I have set jit_tuple_deforming=off, so I think the table accesses don't use functions, right? Oh...that appears to be relevant somehow: $ PGOPTIONS='-c client_min_messages=debug -c log_executor_stats=on -c jit=on -c jit_above_cost=0 -c jit_inline_above_cost=0' psql ts -c "explain analyze SELECT fn() FROM generate_series(1,999)" ! 69872 kB max resident size $ PGOPTIONS='-c client_min_messages=debug -c log_executor_stats=on -c jit=on -c jit_above_cost=0 -c jit_inline_above_cost=0 -c jit_tuple_deforming=on' psql ts -c "explain analyze SELECT fn() FROM generate_series(1,999)" ! 36140 kB max resident size -- Justin