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 1kkaXO-00089Z-1W for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:23:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkaXM-0005yK-4z for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:23:48 +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 1kkaXL-0005yD-Ta for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:23:47 +0000 Received: from ook.raf.org ([139.99.156.21]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkaXJ-00065x-8S for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:23:46 +0000 Received: from localhost (localhost [127.0.0.1]) by ook.raf.org (Postfix) with ESMTP id DBEA55DE1E for ; Thu, 3 Dec 2020 09:23:42 +1100 (AEDT) X-Virus-Scanned: Debian amavisd-new at ook.raf.org Received: from ook.raf.org ([127.0.0.1]) by localhost (ook.raf.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F13tfY8zUkjs for ; Thu, 3 Dec 2020 09:23:42 +1100 (AEDT) Received: by ook.raf.org (Postfix, from userid 1001) id 71D065E2C6; Thu, 3 Dec 2020 09:23:42 +1100 (AEDT) Date: Thu, 3 Dec 2020 09:23:42 +1100 From: raf To: pgsql-general@lists.postgresql.org Subject: Re: Is the Halloween problem an issue in Postgres Message-ID: <20201202222342.oc4ayyaxql24tquo@raf.org> References: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> <5f7e3d0e-52da-c5e4-72d6-edcff340d710@gmx.net> <869172f6-9114-e759-79ba-eb17f1c5082c@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <869172f6-9114-e759-79ba-eb17f1c5082c@aklaver.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Dec 02, 2020 at 02:08:41PM -0800, Adrian Klaver wrote: > On 12/2/20 2:02 PM, Thomas Kellerer wrote: > > guyren@icloud.com schrieb am 02.12.2020 um 21:27: > > > The Halloween problem is that it is a challenge for the database if > > > you’re updating a field that is also in the WHERE clause of the same > > > query. > > > > > > I just saw a presentation from someone about how in SQL Server he > > > recommended writing changes to a temp table and then writing them to > > > the table as being much more efficient. > > > > It sounds strange to me, that this _is_ actually a problem. > > > > Why exactly is that a problem in SQL Server? > > Yeah that was a new one to me. A quick search found: > > https://www.sqlshack.com/the-halloween-problem-in-sql-server-and-suggested-solutions/ > > > And what are the consequences if you do it nevertheless. It looks like the anser is no (unless I've misunderstood the problem): create table a (id serial not null primary key, a integer not null, b integer not null); create index a_a on a(a); insert into a (a, b) values (1, 2); insert into a (a, b) values (2, 3); insert into a (a, b) values (3, 4); insert into a (a, b) values (4, 5); insert into a (a, b) values (5, 6); insert into a (a, b) values (6, 7); update a set a = a + 1 where a < 4; select * from a order by id; drop table a cascade; results in: id | a | b ----+---+--- 1 | 2 | 2 2 | 3 | 3 3 | 4 | 4 4 | 4 | 5 5 | 5 | 6 6 | 6 | 7 It's the same with or without the index on a(a). cheers, raf