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 1pL8ES-00027z-Cw for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Jan 2023 19:48:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pL8EQ-0002t1-W7 for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Jan 2023 19:48:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL8EQ-0002ss-LC for pgsql-hackers@lists.postgresql.org; Thu, 26 Jan 2023 19:48:22 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pL8EK-0005VU-34 for pgsql-hackers@postgresql.org; Thu, 26 Jan 2023 19:48:21 +0000 Received: by mail-pl1-x633.google.com with SMTP id p24so2797591plw.11 for ; Thu, 26 Jan 2023 11:48:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Z6yv56CZTt1bRoMQDK2wnjHyCiKmx2qtUR04H66rnP0=; b=RazHskxLAmFgSlLmVGWR0pCWHy9otCrBxwdreVBFHdbM3ulqcrxcBeXub+yyuYRZ6J VXQCIYJhjFZ00hnCmAuFSQGHobsTH3SYXfD5FQ/0h2Jr5tO3XeIBnK19vPeqKqMk4aBt dPKYb2RAQYF+0UQPeFU14NUKkm85N4aDtnNjtcQCKO8isFm4l1f05gW6eXiZo7ZFAoBH w3Ivpg5JRlVe8pFRYZaGKf05oZFnceJSYWSB14HdQKgu2m91nObllHbMwV8QNibgoDG6 FfnZPJbbXx4mD9IM/xbyQLBB1I/VCWQQK74c1gCDSbQdrlBrKf/QX+xF5xvBU4B0RUyx RRuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Z6yv56CZTt1bRoMQDK2wnjHyCiKmx2qtUR04H66rnP0=; b=0hbETDv8oF0FMexYDVrFiRFTQ/q4q7pInURQJFdDXczKs35W4NVOseTFtgMLuci26T PDe6Z4BEeFORgEClGIbQsr9t4STz4anE1SJuFk/Glat3cLZmnfoOPRg0AxcrbqKvS28o H6Wdl8kMYxhT5q5LgEnH0fGF5K23OEa0QYJT2SoGV6+27X+md8wvBqnMBCQx41iQtMG0 yhn8heHEZgvb8bI2TEI544N0RCkKgxucJNmkyeubqu5KsybNk1obPIAvPfOOpS9M4OY9 to54s21ZGs3UXojdHb9H1KHxJiNREwh7CfZz4rEtUF222jhytnnpYzExtDHEH+1713i3 WLDg== X-Gm-Message-State: AO0yUKUF+CVm22xgSyCipDbJh7/Hpz44Jm4Bnqc5RvWqU10Ar3d/5Din qWTZaAmuBchezQP5A7rsil8= X-Google-Smtp-Source: AK7set8r6aOBa8dzy/X/JOm6rNxelJTnjWmXBgum+qbemNBmtYZlMSf6nK2lUsLryPtXyefRMBcLyw== X-Received: by 2002:a17:903:32d2:b0:196:3ecd:c39a with SMTP id i18-20020a17090332d200b001963ecdc39amr4207835plr.43.1674762494769; Thu, 26 Jan 2023 11:48:14 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id s7-20020a170902b18700b0019492b949fbsm1311734plr.272.2023.01.26.11.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 11:48:14 -0800 (PST) Date: Thu, 26 Jan 2023 11:48:12 -0800 From: Nathan Bossart To: Tom Lane Cc: Thomas Munro , "Hayato Kuroda (Fujitsu)" , "pgsql-hackers@postgresql.org" Subject: Re: suppressing useless wakeups in logical/worker.c Message-ID: <20230126194812.GA1702315@nathanxps13> References: <20221205173523.GA2714833@nathanxps13> <20230109174217.GA1112698@nathanxps13> <2557815.1674603908@sss.pgh.pa.us> <20230125235004.GA1327755@nathanxps13> <20230126003319.GA1507251@nathanxps13> <2878152.1674700077@sss.pgh.pa.us> <2888102.1674705840@sss.pgh.pa.us> <3126727.1674759248@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3126727.1674759248@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 26, 2023 at 01:54:08PM -0500, Tom Lane wrote: > After looking closer, I see that TimestampDifferenceMilliseconds > already explicitly states that its output is intended for WaitLatch > and friends, which makes it perfectly sane for it to clamp the result > to [0, INT_MAX] rather than depending on the caller to not pass > out-of-range values. +1 > * This is typically used to calculate a wait timeout for WaitLatch() > * or a related function. The choice of "long" as the result type > - * is to harmonize with that. It is caller's responsibility that the > - * input timestamps not be so far apart as to risk overflow of "long" > - * (which'd happen at about 25 days on machines with 32-bit "long"). > + * is to harmonize with that; furthermore, we clamp the result to at most > + * INT_MAX milliseconds, because that's all that WaitLatch() allows. > * > - * Both inputs must be ordinary finite timestamps (in current usage, > - * they'll be results from GetCurrentTimestamp()). > + * At least one input must be an ordinary finite timestamp, else the "diff" > + * calculation might overflow. We do support stop_time == TIMESTAMP_INFINITY, > + * which will result in INT_MAX wait time. I wonder if we should explicitly reject negative timestamps to eliminate any chance of int64 overflow, too. Alternatively, we could detect that the operation will overflow and return either 0 or INT_MAX, but I assume there's minimal use of this function with negative timestamps. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com