Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewwIv-00073O-EF for pgsql-performance@arkaria.postgresql.org; Fri, 16 Mar 2018 20:50:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewwIu-0006ys-Ac for pgsql-performance@arkaria.postgresql.org; Fri, 16 Mar 2018 20:50:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewwIt-0006oJ-D7 for pgsql-performance@lists.postgresql.org; Fri, 16 Mar 2018 20:50:19 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewwIq-0003cW-56 for pgsql-performance@postgresql.org; Fri, 16 Mar 2018 20:50:18 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B914420ADC; Fri, 16 Mar 2018 16:50:14 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Fri, 16 Mar 2018 16:50:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=7JRKOOmTFsD/pOrt5farcYNK50ay111NJYe5VcVTW2c=; b=rKHjoQKf NQ9jsHnwUzvr7rdEgHtDIRy3H+4j3cr+RUVkrx7dxkc7U5w6uLLWQyQ3ZfD9gTsS 53HgsE8KT+ZXxzzaM656h1Bfd17Ah7b7yjlBAtKNLnxTKUY5TuXNw+wEOHp1ClXs GhAGYmD3PvYRqMP5F69wRpZkZjL9xWASc4tA79FEoYxaqFiIo2iL6OaPr8u9gKZz 6iaP/cgU7d2VQSF0AVbC/s59p+zjM9rSinKa86saVdgKbJkek9irAs2Z1o9Jb6yA E+9h0E7FIZ8/Ijz2mOGtxNgQmIJNOPaK6X3S9fIFGBsBe63xjwyb5uhyAxI8j6/F qvHq+SOoYxobSA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=7JRKOOmTFsD/pOrt5farcYNK50ay1 11NJYe5VcVTW2c=; b=bMiOL2wpoIBz7g1pdpZYdUUfI4xDDixzCiNjGIm/83SPZ s2WGHp8a0DBIYT5DJ3UyPV0rPhka2F4a0My7Jwz5tE22kvzdzxgXAaEM7/bFJBf0 1EMUxzyA/6YDD/dnbZ1vDhERBVnU62u3nC+OyWTejTosuVxm/Z+0SvMFw0v2EuR2 4lWAdPKBZmU0ISLTAf+W0HEk9lXSz836HurJFhUOq4v/Ckjj9ksmdSH+c6+8dVfm Nn18t/35TxRDgPbG9Pb4HQ7GeATdfsyZ9w0n73a1NadThKVHIE5jiac+5BjovkK9 s4pahvfTgzsGRycuk7E/bzYrrEWEV65z/GNBoEoLw== X-ME-Sender: Received: from intern.anarazel.de (unknown [136.24.76.189]) by mail.messagingengine.com (Postfix) with ESMTPA id 6B2A67E21D; Fri, 16 Mar 2018 16:50:14 -0400 (EDT) Date: Fri, 16 Mar 2018 13:50:13 -0700 From: Andres Freund To: Craig James Cc: "pgsql-performa." Subject: Re: Irrelevant columns cause massive performance change Message-ID: <20180316205013.sl7vrlr44ms3ptkg@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2018-03-16 13:37:05 -0700, Craig James wrote: > The timing of the second query is excellent, and is what I expected. I > don't understand why including a function-defined column in the view would > have such a dramatic effect on the planner's ability to choose the sdf_pkey > index for the join. > create or replace function gunzip(bytea) returns text as > $gunzip$ > use IO::Uncompress::Gunzip qw(gunzip $GunzipError); > my $compressed = decode_bytea($_[0]); > my $uncompressed; > if (!gunzip(\$compressed, \$uncompressed)) { > return $GunzipError; > } > return $uncompressed; > $gunzip$ > language plperlu; I suspect at least part of the problem here is that the function is declared volatile (the default). That means it can have arbitrary sideeffects, which in turn means there's several places in the planner that forgo optimizations if volatile functions are involved. If you declare the function as immutable, does the problem persist? Greetings, Andres Freund