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 1k0C9D-0001iV-16 for pgsql-general@arkaria.postgresql.org; Mon, 27 Jul 2020 23:03:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k0C9C-00018O-0w for pgsql-general@arkaria.postgresql.org; Mon, 27 Jul 2020 23:03:06 +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 1k0C9B-00018H-La for pgsql-general@lists.postgresql.org; Mon, 27 Jul 2020 23:03:05 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k0C97-0001mc-8C for pgsql-general@lists.postgresql.org; Mon, 27 Jul 2020 23:03:05 +0000 Received: by mail-qk1-x743.google.com with SMTP id h7so16970751qkk.7 for ; Mon, 27 Jul 2020 16:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=OEgmZ+/LoZHnKPQZyv+vvp4jy//XB2E1tNa0dg4YHAQ=; b=tfXIkFE4zkpTqGCe2eTxNTOQwkazyZr0CuOtrUbkCka2l+LL1bCnyHkVpAmm3sg/X3 AW/+4z82ulVj8HwFsOc9u4Gbx4Z/pXOSYqsV4tcnmoaWlLJ1Sf86QPnwVPu/XoTVwbMb y5Z/FSOjMgc/nMch/NRX8cwfbOk+X3zNFzDOHFYDshhbrLik1SV460nfwRQoNxgrbuTS pMw2elFHHYxKXZMW0pHYlMvAs2GRYvoSGMw8Zg7ZQ/0aPoxsSdgBarybhfLfphj+ngav 9tZGyUcdEu0WVRh6E3ht29WAKifvsBWfcFy8sGnWFwLzCMcfvHArg87R7Qn9J8YDYLZI xJwA== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=OEgmZ+/LoZHnKPQZyv+vvp4jy//XB2E1tNa0dg4YHAQ=; b=oJHelEvmuQnBA/rt7huPyg2P0f4DKQSi3ZujhNixm7qniNV0zKGY7Z6c8VQYUYueAM E+4G9wW49o2ShXzaMN74/Y/PmopQcpWlMPft3O83nfprooIgSXLpgI9n4PMB78My0yV/ 6XvS6QhnufBLTdXVILfI6YuuI0STK875jAmfJ854frNYj2a2+uARuHgR+GaKlUapuChl 2Z7+p+l97YEd8n5nxv9xXyqpPe4cJlVUD7Qii7a72mItMlWf6VAwNxo7a7J9PbXnpCvL moGcIYjmiWzAbRr7vUwOGEibG71Sc1Isi9fm64+EIo6zdUonZ1HuNN26Y6dQhgxzUDOK W18g== X-Gm-Message-State: AOAM531vK/va4pz8JWZGPYsLd1ZIW1zPvrFKo4U6B+YPdrmboSk07gY3 QhmemALbHo4Oeq8Lr5/tDS4CDw== X-Google-Smtp-Source: ABdhPJyqGt31NNQ1Pa46xbBER+7WBpIj6TWX9y7/JP1l1UwILXVuovnJd0c30JCC2FXYTm07kMaviQ== X-Received: by 2002:a37:4c06:: with SMTP id z6mr24157501qka.481.1595890979070; Mon, 27 Jul 2020 16:02:59 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.19.47]) by smtp.gmail.com with ESMTPSA id o21sm4878302qkk.94.2020.07.27.16.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 16:02:58 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 5BB912A1E6E; Mon, 27 Jul 2020 19:02:56 -0400 (-04) Date: Mon, 27 Jul 2020 19:02:56 -0400 From: Alvaro Herrera To: Scott Ribe Cc: Andres Freund , Tom Lane , David Rowley , PostgreSQL General Subject: Re: bad JIT decision Message-ID: <20200727230256.GA31992@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <690D93FA-4A30-422D-94C3-18A089B8AEFE@elevated-dev.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Jul-27, Scott Ribe wrote: > > On Jul 27, 2020, at 4:00 PM, Alvaro Herrera wrote: > > > > I don't quite understand why is it that a table with 1000 partitions > > means that JIT compiles the thing 1000 times. Sure, it is possible that > > some partitions have a different column layout, but it seems an easy bet > > that most cases are going to have identical column layout, and so tuple > > deforming can be shared. (I'm less sure about sharing a compile of an > > expression, since the varno would vary. But presumably there's a way to > > take the varno as an input value for the compiled expr too?) Now I > > don't actually know how this works so please correct if I misunderstand > > it. > > I'm guessing it's because of inlining. You could optimize a function > that takes parameters, no problem. But what's happening is inlining, > with parameters, then optimizing. Are you saying that if you crank jit_inline_above_cost beyond this query's total cost, the problem goes away? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services