Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1bAk-0005iE-DL for pgsql-performance@arkaria.postgresql.org; Wed, 06 Mar 2019 18:21:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h1bAh-0005Ov-Ho for pgsql-performance@arkaria.postgresql.org; Wed, 06 Mar 2019 18:21:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1bAh-0005On-69 for pgsql-performance@lists.postgresql.org; Wed, 06 Mar 2019 18:21:39 +0000 Received: from mail2.code-sourcery.de ([138.201.66.53]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1bAe-00012u-0e for pgsql-performance@lists.postgresql.org; Wed, 06 Mar 2019 18:21:37 +0000 Received: from [192.168.2.5] (x4d037b22.dyn.telefonica.de [77.3.123.34]) by mail2.code-sourcery.de (Postfix) with ESMTPSA id D0D7D1FCA2 for ; Wed, 6 Mar 2019 19:21:33 +0100 (CET) Subject: Re: JIT performance question To: pgsql-performance@lists.postgresql.org References: <6191e1ee-d548-2a8c-d87d-dab63c05ad2e@code-sourcery.de> <20190306174258.f23avt6k3vtgqsqr@alap3.anarazel.de> From: Tobias Gierke Message-ID: Date: Wed, 6 Mar 2019 19:21:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <20190306174258.f23avt6k3vtgqsqr@alap3.anarazel.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: de-DE List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06.03.19 18:42, Andres Freund wrote: > > It's hard to know precisely without running a profile of the > workload. My suspicion is that the bottleneck in this query is the use > of numeric, which has fairly slow operations, including aggregation. And > they're too complicated to be inlined. > > Generally there's definitely advantage in JITing aggregation. > > There's a lot of further improvements on the table with better JIT code > generation, I just haven't gotten around implementing those :( Thanks for the quick response ! I think you're onto something with the numeric type. I replaced it with bigint and repeated my test and now I get a nice 40% speedup (I'm again intentionally ignoring the costs for JIT'ting here as I assume a future PostgreSQL version will have some kind of caching for the generated code): Without JIT:                                                         QUERY PLAN --------------------------------------------------------------------------------------------------------------------------  Aggregate  (cost=1395000.49..1395000.50 rows=1 width=6240) (actual time=6023.436..6023.436 rows=1 loops=1)    Buffers: shared hit=256 read=399744    I/O Timings: read=475.135    ->  Seq Scan on test  (cost=0.00..420000.00 rows=2000000 width=1560) (actual time=0.035..862.424 rows=2000000 loops=1)          Buffers: shared hit=256 read=399744          I/O Timings: read=475.135  Planning Time: 0.574 ms  Execution Time: 6024.298 ms (8 rows) With JIT:                                                         QUERY PLAN --------------------------------------------------------------------------------------------------------------------------  Aggregate  (cost=1395000.49..1395000.50 rows=1 width=6240) (actual time=4840.064..4840.064 rows=1 loops=1)    Buffers: shared hit=320 read=399680    I/O Timings: read=493.679    ->  Seq Scan on test  (cost=0.00..420000.00 rows=2000000 width=1560) (actual time=0.090..847.458 rows=2000000 loops=1)          Buffers: shared hit=320 read=399680          I/O Timings: read=493.679  Planning Time: 1.414 ms  JIT:    Functions: 3    Options: Inlining true, Optimization true, Expressions true, Deforming true    Timing: Generation 19.747 ms, Inlining 10.281 ms, Optimization 222.619 ms, Emission 362.862 ms, Total 615.509 ms  Execution Time: 4862.113 ms (12 rows) Cheers, Tobias