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 1hYIQu-0004CY-7r for pgsql-performance@arkaria.postgresql.org; Tue, 04 Jun 2019 23:01:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hYIQt-0005K5-1K for pgsql-performance@arkaria.postgresql.org; Tue, 04 Jun 2019 23:01:31 +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 1hYIQs-0004wS-Gj for pgsql-performance@lists.postgresql.org; Tue, 04 Jun 2019 23:01:30 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYIQk-0004XK-W1 for pgsql-performance@postgresql.org; Tue, 04 Jun 2019 23:01:29 +0000 Received: by mail-wm1-x342.google.com with SMTP id v19so472885wmh.0 for ; Tue, 04 Jun 2019 16:01:22 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qpVq1UbTtR4f/tW06o9NjMwXIzSPK0WnaAd43RjBP/o=; b=1kgCw2SfeQ9SKgxY9OPuEZMnRXvktyRLew+yiYGbtDQyb81Tx17EFv32CBqI6jDXxg Mxe7dUjUfnCfO/j1Ms4Gf/QV2D1/kBGKAVazGp8hGIlNy8t3FkS4Q5MOaNJV7O0gJLwq MweuAbDn05JGGJmvIRB+g+v1bDv3wzxGl44ROGcIqu3aOdJfPhRg9OzJpcXjjR5ashQE R24hnqrWujXSkBk83KmZnLL7LyCOxHYHRb8zwZQj/iE+/HxdbzeZb+/qFq7nncsxLJw4 P1BWD04csRQRvz+Ibgb5ssz0/FpdfSSiuifIc3qov0Zm4dWOo99jM0jgZ0f3ycv2kp9T 7T8w== 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=qpVq1UbTtR4f/tW06o9NjMwXIzSPK0WnaAd43RjBP/o=; b=RCSIbI4it8L5xuK3o/Kmy1O/5rbVnUFcGbe5JbzZKVsVykFtPMFp+yTukbKTSaEloq 4hHshotiVoNvngWZ5X/BA7ENWYx61gWppfVXN5k/mbMPDV4oQomMfWN0CQUSicgAFc8c ipAf/dLJGM0ozCsEOZI/fHJX0BjJHKTbNScV1V1947XhhBGJ9GCyviB/bohfkzyp8PBd awsOXwxG0bdKZ4F34qi0Nyfw8SoNvD/t4vN832cStMX9Hj7p3q3YNcv8rNoc8clPyAIy Eutyv+B9VEwXBzlR2yHkL1YsABCt7X20Gy93zjKa9qlyAimCbCx0/6QMrirdEZ0k3ZxL GQ3g== X-Gm-Message-State: APjAAAXm3zf9ddLJdcvFDfpZniywI32xjj6EsFbb92YaBu2aPUW1amJx w9l3umaNdDketVlmKHEODdf4dQ== X-Google-Smtp-Source: APXvYqzol9qzm0LXD/rVDROIWKHXsmAmY6gh433/2Hr6Xw+0zqzq5HVSprYe4kZwvJLIGOHmliVg3Q== X-Received: by 2002:a1c:a002:: with SMTP id j2mr19612975wme.131.1559689281193; Tue, 04 Jun 2019 16:01:21 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id k2sm31782217wrg.41.2019.06.04.16.01.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 04 Jun 2019 16:01:20 -0700 (PDT) Date: Wed, 5 Jun 2019 01:01:18 +0200 From: Tomas Vondra To: Vasilis Ventirozos Cc: pgsql-performance@postgresql.org Subject: Re: Strange query behaviour between 9.4 and 12beta1 Message-ID: <20190604230118.obhk44tautptakmb@development> References: <32F9F8AD-2BBE-48D7-9A05-F33D3A90A9FA@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <32F9F8AD-2BBE-48D7-9A05-F33D3A90A9FA@gmail.com> User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Jun 04, 2019 at 05:34:07PM +0300, Vasilis Ventirozos wrote: >Hello everyone, >I started comparing performance between postgres 9.4 and 12beta1 more specifically comparing the new (materialized) CTE. Are you saying the CTE is specified as MATERIALIZED in the query on 12? Because I don't see it in the explain plan (it's mentioned in the 9.4 plan, though). >The statements i use are application statements that i have little control over, >Hardware is identical as both clusters are running on the same server, on the same disks, with the same data. >Also, cluster settings are almost identical and both clusters have been analyzed. >In all my tests 12 is faster , sometimes much faster, apart from one single query that takes ~12 seconds on 9.4 and nearly 300 seconds on 12. > >Plans for both : >Plan for 12 >plan for 9.4 > >The plans are obfuscated , apologies for that but what stands out is the following : > Meh. > >Hash Left Join (cost=200,673.150..203,301.940 rows=153,121 width=64) (actual time=1,485.883..284,536.440 rows=467,123 loops=1) >Hash Cond: (lima_sierra(six_lima_november2.victor_romeo, 1) = foxtrot_hotel.victor_romeo) >Join Filter: (whiskey_uniform1.six_sierra = foxtrot_hotel.uniform_juliet) >Rows Removed by Join Filter: 4549925366 > You have two equality conditions for the join. The first one is used to match rows by the hash join itself - it's used to compute the hash value and lookups. But there may be multiple rows that match on either side, generating additional "virtual rows". Those are then removed by the second condition. Consider for example simple cross-join on this table: a | b ------------- 1 | a 1 | b 2 | a 2 | b and the query is SELECT * FROM t t1 JOIN t t2 ON (t1.a = t2.a AND t1.b = t2.b) Now, in the first phase, the hash join might only do (t1.a = t2.a), which will generate 8 rows a | t1.b | t2.b ---------------- 1 | a | a 1 | a | b 1 | b | a 1 | b | b 2 | a | a 2 | a | b 2 | b | a 2 | b | b And then it will apply the second condition (t1.b = t2.b) as a "filter" which will remove some of the rows. In your case the first step generates 4.5B rows the second step discards. I'm not sure why we don't use both conditions as a hash condition. Perhaps it's a data type that does not support hashing, and on 9.4 that does not matter because we end up using merge join. > >I really can't understand what these 4.5bil rows have been removed from, there is nothing suggesting that this dataset was ever created (eg. temp) >and these numbers definitely don't match what i was expecting, which is more or less what i'm seeing in 9.4 plan. > >Obviously i've tested this more than once and this behaviour consists. > > >Best Regards, >Vasilis Ventirozos > regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services