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 1k0VZk-0005EG-7B for pgsql-general@arkaria.postgresql.org; Tue, 28 Jul 2020 19:47:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k0VZj-0005j6-1H for pgsql-general@arkaria.postgresql.org; Tue, 28 Jul 2020 19:47:47 +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 1k0VZi-0005iz-Q3 for pgsql-general@lists.postgresql.org; Tue, 28 Jul 2020 19:47:46 +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 1k0VZg-0004uy-E1 for pgsql-general@lists.postgresql.org; Tue, 28 Jul 2020 19:47:46 +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 06SJlaPi1236774; Tue, 28 Jul 2020 15:47:38 -0400 From: Tom Lane To: Andres Freund cc: Alvaro Herrera , Scott Ribe , David Rowley , PostgreSQL General Subject: Re: bad JIT decision In-reply-to: <20200728171913.o5ok5h5c6kbjncob@alap3.anarazel.de> References: <690D93FA-4A30-422D-94C3-18A089B8AEFE@elevated-dev.com> <20200727230256.GA31992@alvherre.pgsql> <20200728171913.o5ok5h5c6kbjncob@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Tue, 28 Jul 2020 10:19:13 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1236772.1595965656.1@sss.pgh.pa.us> Date: Tue, 28 Jul 2020 15:47:36 -0400 Message-ID: <1236773.1595965656@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > On 2020-07-27 19:02:56 -0400, 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. > No, that's not what happens. The issue rather is that at execution time > there's simply nothing tying the partitioned parts of the query together > from the executor POV. Each table scan gets its own expressions to > evaluate quals etc. That's not a JIT specific thing, it's general. I think what Alvaro is imagining is caching the results of compiling tuple-deforming. You could hash on the basis of all the parts of the tupdesc that the deforming compiler cares about, and then share the compiled code across different relations with similar tupdescs. That could win for lots-o-partitions cases, and it could win across successive queries on the same relation, too. Maybe the same principle could be applied to compiled expressions, but it's less obvious that you'd get enough matches to win. regards, tom lane