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 1nZK8b-0005dP-SM for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Mar 2022 22:16:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nZK8a-0003mE-CN for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Mar 2022 22:16:28 +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 1nZK8Y-0003lg-Jq for pgsql-hackers@lists.postgresql.org; Tue, 29 Mar 2022 22:16:28 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZK8T-0002di-UQ for pgsql-hackers@lists.postgresql.org; Tue, 29 Mar 2022 22:16:25 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 658CF3200E89; Tue, 29 Mar 2022 18:16:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 29 Mar 2022 18:16:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; bh=0fTLmBpHqsIV3rVDaDc9HedB2n7nvc5noraP/1 /mvUU=; b=lY4O8AEmB8jbCyB7VIqCkhDOh5RZ5wIHonrJMMziakJ9emr3HFhHaF xsL8hN/PiYJtGs/g1uZf8O9zmBVcfRsjcTKc/xWJuXNK4WZ93ZlAQ9hm1oiKjy+o c21vFgcRQQfLRxBD4H/xMcAFfeCTAAxufDlGzAjvbXDOWS08PjEUCHQ0igCvHIVq A/jM36jIJfn7LHomeU3/8ty72t0wypIc97ccp/mGI69ko7LKKbPK0CDPzAn6SVYr oDY3PnS7LugrFikr4fpkBfqC5hltfFWaJddBmsVHn0MfL/nILcDuxbhDDnOQ7Svp HnIq6rps+vWiS4KXkwE11XnPpvkn9XIw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=0fTLmBpHqsIV3rVDa Dc9HedB2n7nvc5noraP/1/mvUU=; b=D6VqQMqrC+mmcxIUXD7c82nxHC0rSEDO4 PjyIk3XV+wLKWByVInF1wsMQrtGJDUOYIs9SLBtOht0CM74uNKODXz5npJkbZT8D gsTzk2HIX5erWq+/EBa5o6kCHeRV2ylRp6AQzH4QdplI8kOI3Stwfq4IoTcPYy+z 3K7Y4Glav2jYG8yceQMBZKM8mD/mMWWu4AOaYIgtYAB2BzTG+ZhcpcHj0eJggpEZ cVCjJZathfiYcKqep+EukxoofiMp/Xsa65eoc7RinfJpNIdlWjFlUNVFZc+296rY FOGLBvS0DFvj0+Nmizi8Mvlirz27lcL6Wyi9dZXCE++BjE/2I36qQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeiuddgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedukefhkeelueegveetheelffffjeegleeuudelfeefuedtleffueejfffh ueffudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 29 Mar 2022 18:16:16 -0400 (EDT) Date: Tue, 29 Mar 2022 15:16:15 -0700 From: Andres Freund To: David Rowley Cc: Andy Fan , Zhihong Yu , PostgreSQL Developers Subject: Re: Window Function "Run Conditions" Message-ID: <20220329221615.hule724qcaarhe3y@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: Archived-At: Precedence: bulk Hi, On 2022-03-29 15:11:52 +1300, David Rowley wrote: > One thing which I'm not sure about with the patch is how I'm handling > the evaluation of the runcondition in nodeWindowAgg.c. Instead of > having ExecQual() evaluate an OpExpr such as "row_number() over (...) > <= 10", I'm replacing the WindowFunc with the Var in the targetlist > that corresponds to the given WindowFunc. This saves having to double > evaluate the WindowFunc. Instead, the value of the Var can be taken > directly from the slot. I don't know of anywhere else we do things > quite like that. The runcondition is slightly similar to HAVING > clauses, but HAVING clauses don't work this way. Don't HAVING clauses actually work pretty similar? Yes, they don't have a Var, but for expression evaluation purposes an Aggref is nearly the same as a plain Var: EEO_CASE(EEOP_INNER_VAR) { int attnum = op->d.var.attnum; /* * Since we already extracted all referenced columns from the * tuple with a FETCHSOME step, we can just grab the value * directly out of the slot's decomposed-data arrays. But let's * have an Assert to check that that did happen. */ Assert(attnum >= 0 && attnum < innerslot->tts_nvalid); *op->resvalue = innerslot->tts_values[attnum]; *op->resnull = innerslot->tts_isnull[attnum]; EEO_NEXT(); } vs EEO_CASE(EEOP_AGGREF) { /* * Returns a Datum whose value is the precomputed aggregate value * found in the given expression context. */ int aggno = op->d.aggref.aggno; Assert(econtext->ecxt_aggvalues != NULL); *op->resvalue = econtext->ecxt_aggvalues[aggno]; *op->resnull = econtext->ecxt_aggnulls[aggno]; EEO_NEXT(); } specifically we don't re-evaluate expressions? This is afaics slightly cheaper than referencing a variable in a slot. Greetings, Andres Freund