From guyren@icloud.com Wed Dec 2 20:27:16 2020 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 1kkZ20-0004d3-0i for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 20:47:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkZ1y-0002p5-CU for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 20:47:18 +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 1kkYip-0006NW-SB for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 20:27:31 +0000 Received: from mr85p00im-hyfv06011401.me.com ([17.58.23.191]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkYin-0004xL-4d for pgsql-general@postgresql.org; Wed, 02 Dec 2020 20:27:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1606940847; bh=5QjRw8N5v51QnlQyeBK0sOX1WEZtaOsFrLo9gX29tOc=; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type; b=zMypZ9WDWIzHgP9St+W3zT1/QItQEQmezpup8N3rCpLe70TAVSxjUNC8aHNe0zM7W w21wRP/ybLHQFIPIYhivB052NLiwuCbuS8WJWMUL0kmLFxnBUgnYYTULGSTpgpIKQq 41eFDcWACXrVWF4+8+eOkjOhwkLuky6qvnb0YbFdXhfN7nevO2w+ucSUCeHcZxUlnB 0bAhetmQAojQf6eX3GaP8nzLRbOB9UMbjQZtSeFJkRE+tQNwsuKTJW8AuwD6/1VUUe jgjlu2PHq5MgSzafZIPjwYNzS/1hqxr2n0Mkw21vyTLExW469Tmk19CBJlkbgIxP3G VgOHs2qwtz+PQ== Received: from [192.168.1.35] (ip68-107-18-54.sd.sd.cox.net [68.107.18.54]) by mr85p00im-hyfv06011401.me.com (Postfix) with ESMTPSA id 63A42D2040E for ; Wed, 2 Dec 2020 20:27:27 +0000 (UTC) Date: Wed, 2 Dec 2020 12:27:16 -0800 From: guyren@icloud.com To: PG-General Mailing List Message-ID: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> References: Subject: Is the Halloween problem an issue in Postgres X-Readdle-Message-ID: 756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="5fc7f8ad_19495cff_c23" X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-12-02_12:2020-11-30,2020-12-02 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=6 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 mlxscore=0 mlxlogscore=464 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2006250000 definitions=main-2012020122 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --5fc7f8ad_19495cff_c23 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The Halloween problem is that it is a challenge for the database if you=E2= =80=99re updating a field that is also in the WHERE clause of the same qu= ery. I just saw a presentation from someone about how in SQL Server he recomme= nded writing changes to a temp table and then writing them to the table a= s being much more efficient. Does Postgres handle this problem efficiently, or should we follow a simi= lar strategy=3F --5fc7f8ad_19495cff_c23 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
The Halloween problem is that it is a challenge for= the database if you=E2=80=99re updating a field that is also in the WHER= E clause of the same query.

I just saw a presentation from someone about how in SQL Server he recomme= nded writing changes to a temp table and then writing them to the table a= s being much more efficient.

Does Postgres handle this problem efficiently, or should we follow a simi= lar strategy=3F
--5fc7f8ad_19495cff_c23-- From tgl@sss.pgh.pa.us Wed Dec 2 20:48:05 2020 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 1kkZ2r-0004fb-Ip for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 20:48:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkZ2q-00039e-H7 for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 20:48:12 +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 1kkZ2q-00039V-8e for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 20:48:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkZ2o-00057R-3m for pgsql-general@postgresql.org; Wed, 02 Dec 2020 20:48:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0B2Km59C1673520; Wed, 2 Dec 2020 15:48:05 -0500 From: Tom Lane To: guyren@icloud.com cc: PG-General Mailing List Subject: Re: Is the Halloween problem an issue in Postgres In-reply-to: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> References: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> Comments: In-reply-to guyren@icloud.com message dated "Wed, 02 Dec 2020 12:27:16 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1673518.1606942085.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2020 15:48:05 -0500 Message-ID: <1673519.1606942085@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk guyren@icloud.com writes: > The Halloween problem is that it is a challenge for the database if you=E2= =80=99re updating a field that is also in the WHERE clause of the same que= ry. > I just saw a presentation from someone about how in SQL Server he recomm= ended writing changes to a temp table and then writing them to the table a= s being much more efficient. That's nonsense as far as Postgres is concerned. regards, tom lane From shammat@gmx.net Wed Dec 2 22:02:07 2020 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 1kkaCV-0007Q4-LB for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:02:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkaCU-0004RH-Hd for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:02:14 +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 1kkaCU-0004R9-8Q for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:02:14 +0000 Received: from mout.gmx.net ([212.227.17.22]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkaCR-0005w9-PW for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:02:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606946528; bh=ffDNBYL3MSxnrMCQbwRJwGv/6+wWGX4aepvhJal3+pI=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=Xt+unJGJ/Vsf93vR8aTClpY1eHcMa6gKmpJXTGyDmbVOsZtarbtvwVc13+NXmOpW/ lsEEpndpnPjT/UpGnEFaBae1rHKdq8UPOSGyiyFW+b1VOTu/bnjpg+OUVUUJFJOYhZ A0gOrKFXgLgstVtTLdFNDUDfmplUY7uY0qGAaidQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.20] ([83.171.175.173]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MzhnN-1jygVt1Od7-00vcrq for ; Wed, 02 Dec 2020 23:02:08 +0100 Subject: Re: Is the Halloween problem an issue in Postgres To: pgsql-general@lists.postgresql.org References: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> From: Thomas Kellerer Message-ID: <5f7e3d0e-52da-c5e4-72d6-edcff340d710@gmx.net> Date: Wed, 2 Dec 2020 23:02:07 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:MO9x9HWjOskwnPdjD/xysAY6h0WnZ1rGPs0xV2aBnQ1PD0dsp1S g+rzlCBgga+P+M33cVRlPD8s7mx4+dXe0Uqu7x3dvI8Utm3MTE3j475yOePLm166WI7/mFB SZ6LVVhVntqbIu/G7EeYkm86U03zB2EB8rDygmQxI2ng2vZhLRXuzmZdSjy+CkdoPTM690x YqnAYqFCrBeoXuOSpz5pQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fT5gu1WaVyw=:rV5jvMr+178KBCd7yO4JJE kZOj0mc4aVNcp8JC7p4KKO0mCbzDPpntFr48mbqnLJvYC8uPr25YYAc077TVwkCUkUMx2Ivhm uIcGRNA2tK9GKJqE6iIcA/xXlTKjUfmDMnV5RML3SeZkkpQ/Gq9vasL/2WKqqJuiuCB0uEp7N 6vbSoOPszY2sHPiFisJ7/PfyAoG5gQfnyILcttJ5ldGnu7u2sUCUmQW6VHjNqnQGFnkD7U7Sk CqHl3fWPz4PwdMPi9torN86lEORV0DKCBDiL+HArU3ubENN2cXnLe1dmUfASAKIqdy8Yk7NA0 +Pkk8Qx4h/bORAcu4hpT61a9xiFVDPs1dU/EGy70v0lK0Byq2LQGs+ADtaEYJ6hs8TQgTI4TW agzBgJ1LYtT+Kn3WyNo797zIx8zk1WbNzYm0VfBZnSb3DfOuNROJuHsqLHyqD4mlqF4jVAhe5 kzp8CQ2/hnVKzB4aOP480MpgzSW2dofIV9mzUB9caaN+imY1TTQ/d+a7JJ3fdlLAfi7XyD5Tb RUYQEGtFH7vn4aIHUh4QUN8ybavNMIAuiDngLbcbGs8GO3EUnbzFW3cBJ3+D+OsMZZBbJOP1P hi4SWqdOyk0rdyvk9/VF39S4er89zV0vBk7alOKwzDxqU2MFTIebBnheEKwE+iMTLNrNCa9Gg cU3/XXsJKfySxhpO8LINLf0OU9vDAAOJIy0vDai6zJ0x5IL8thh9j28n/dJJ2wxvQRmBML649 3m2Qsq7zi6ZiOyKeOX0HLt/hHUZhSlBqGsD5VEo1AUXlPLmOeB0AFyCQQ6MPmfmvhgrih/SIS Jz7+wFuEJJze04bNUv9UB72T63g/8AT/TZJr9VrCZozBQ58hTmsw2m0uUiu5wtdQHRSyacJPg GuHnbwgResV97fAxKGoQ== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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=E2=80=99re 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? And what are the consequences if you do it nevertheless. From adrian.klaver@aklaver.com Wed Dec 2 22:08:41 2020 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 1kkaIx-0007fX-GP for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:08:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkaIw-0000ss-6M for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:08:54 +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 1kkaIu-0000s9-Qj for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:08:53 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkaIq-0007Ai-OQ for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:08:52 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 4FC125C0190; Wed, 2 Dec 2020 17:08:46 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 02 Dec 2020 17:08:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=r ovfm87Wz4S/9/whvZLjrAa3DD6NR6XwmSUFa8+eiZQ=; b=E1RtOUSroI1LLmxqF hft57RRwTDn2472u7qdB8Bl+AxiW+BM1GrOGz0Fm2Wktq1HjNbKAr9LQ9UB6J0/m AT7cFPwSynJTaTdO/gdkjhHxYQfCpYQJHKRJaI7B+6JgJGyShWjSaOWHXBATW4Zl Mi1XGBAGVHJLB1TqVbiAKU8VicBcvPWVW7SM97S2MOt6H3AbaNegAXdKKrds254S m3jibQGvdVq5AKEUJE2xhgbWqotINJC/+HxUzLgGIcx7hvSuzQukLnEKbthr/TFZ 6w3SkkzAh51b0V6qadTMG/aFj2uMXUkeAu/Phi5yb2ktVJ/zlA2C9lhGSQauG6zj E3qmg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=rovfm87Wz4S/9/whvZLjrAa3DD6NR6XwmSUFa8+ei ZQ=; b=JZ1FpFxK8Nd8HJ83B+D48g/cxklSBNmFGlgW3FuKapBY3Tf37ZyLM3mio fnbTsupQcbZzYhDEg+TQhH2U/oErmenYGvFsERUGkWN+4C9fppRA6BSz6oemb1E3 UT6qXD7OfX84cJXQ+qlnjewvgIa7F9Tw5cfSz1EUFT0N9CGgMYJaGXeXcy8LthwN NzIdZrlhYUtk86TKYVvPncOuMrQDfIQJLT13Nl0Ms4Cv5f22LygMH6x8qIY74VXT MMHKQBKADVcUFF4HyQ8w2CMo/Cq0L/I3My3EW3NqEwiSfkK4yrbusIBYPXP+/ayu vwjPuRD8d4dxpv1vxputJ/vCGdSeQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeigedgudehkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeelffekie eitdehveejkeekteffjeelffefhfeiffeugeehgedtfeduteelheehveenucffohhmrghi nhepshhqlhhshhgrtghkrdgtohhmnecukfhppedujedvrdehkedrvddvrddvtdehnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghn rdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from ranger.suse (unknown [172.58.22.205]) by mail.messagingengine.com (Postfix) with ESMTPA id 3731A24005C; Wed, 2 Dec 2020 17:08:45 -0500 (EST) Subject: Re: Is the Halloween problem an issue in Postgres To: Thomas Kellerer , pgsql-general@lists.postgresql.org References: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> <5f7e3d0e-52da-c5e4-72d6-edcff340d710@gmx.net> From: Adrian Klaver Message-ID: <869172f6-9114-e759-79ba-eb17f1c5082c@aklaver.com> Date: Wed, 2 Dec 2020 14:08:41 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <5f7e3d0e-52da-c5e4-72d6-edcff340d710@gmx.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. > > > -- Adrian Klaver adrian.klaver@aklaver.com From raf@raf.org Wed Dec 2 22:11:36 2020 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 1kkaLi-0007l7-4M for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:11:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkaLh-0004Mu-3W for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:11:45 +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 1kkaLg-0004Mn-Rr for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:11:44 +0000 Received: from ook.raf.org ([2402:1f00:8100:400::31]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkaLe-0007Bn-DH for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:11:44 +0000 Received: from localhost (localhost [127.0.0.1]) by ook.raf.org (Postfix) with ESMTP id B1B0E5DE1E for ; Thu, 3 Dec 2020 09:11:36 +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 930JgY3yC-vy for ; Thu, 3 Dec 2020 09:11:36 +1100 (AEDT) Received: by ook.raf.org (Postfix, from userid 1001) id 500F45E2C6; Thu, 3 Dec 2020 09:11:36 +1100 (AEDT) Date: Thu, 3 Dec 2020 09:11:36 +1100 From: raf To: pgsql-general@lists.postgresql.org Subject: Re: Is the Halloween problem an issue in Postgres Message-ID: <20201202221136.troad5g7gkddpnuk@raf.org> References: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> <5f7e3d0e-52da-c5e4-72d6-edcff340d710@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5f7e3d0e-52da-c5e4-72d6-edcff340d710@gmx.net> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Dec 02, 2020 at 11:02:07PM +0100, 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? > And what are the consequences if you do it nevertheless. According to wikipedia, this problem was discovered on Halloween day, 1976. I find it hard to believe that any database would still exhibit that behaviour 44 years later. cheers, raf From raf@raf.org Wed Dec 2 22:23:42 2020 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 From ronljohnsonjr@gmail.com Wed Dec 2 22:35:05 2020 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 1kkaiN-000088-L3 for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:35:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkaiM-0004NJ-K3 for pgsql-general@arkaria.postgresql.org; Wed, 02 Dec 2020 22:35:10 +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 1kkaiM-0004NC-8t for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:35:10 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kkaiK-0006B5-1I for pgsql-general@lists.postgresql.org; Wed, 02 Dec 2020 22:35:09 +0000 Received: by mail-ot1-x333.google.com with SMTP id z24so3215837oto.6 for ; Wed, 02 Dec 2020 14:35:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=Q0IexLYRIedJbnLZUrukcv2eDJiVR1rIe78krElkAPQ=; b=Q8U7NIKf7WnefwuBK+4Wc4+f63K6wwcEs6y1UNUcyxHmcStttM8qhvBjL0yXMfHYWc khkYHIw4zMvMkhaaNreLFyJ7TIgLyzZcr4y1G6gmSDeOshHtTpfs2JkOLQKcle+fwa7K pkneC6TKOMcjfk/kygUY/z+M8ifTH4Nxn9V3+3+oC3XSyoBZSBPkuS5H2BQpZf6cePEQ 7bxrSRJhipd1hGuFEgQI0ZmhTs1YOJqwjuj6Ubt1AQQdYtskKLZ/C6d2xIVP/uBsjoDZ GdbIGM2U2yyYh+O9SIWJSwshwQ/Yu+vGC9c0UEMM3JEj6Lwak5ev+xDGIUfmz5cQ6jK1 ioag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Q0IexLYRIedJbnLZUrukcv2eDJiVR1rIe78krElkAPQ=; b=iRTajdbqWfogqHE5fsMxk4d0+/P+YpC9GjnswvnyqU4zdvescGrFhLuCOUoO0o3So6 oR2oHDdS+kk8xMWqj+gGCZ8lYFFw7vDP/NTUxxMphoCbpo5KYH0TGiovqqX/Po5wLzEr 4BDrv8cgC+QLjuGC1nGehDRD18Vu1B3gCoY9qBpbaSkOrWelIS/Xy+0E09Vus0r4tiac 6MWQVnEuSmAxkH4mkBoTrKZhkpHlxx+IOBhPhTawRpQQNmbDrLpA8xa4oc+woRAwbRg8 c1y7Jlrmi6eQa9fVaBK2d/NRWyTYxbwg5OUv6txN3Pr4JMszHapZ0QxaWAov44jrGmOk YbYg== X-Gm-Message-State: AOAM53194vTwkh4tBSgvbQ3WLG4LiNOK03qp3sD/QRgP/bUBScVtjvlc ewRO5lgCjOUIOTZEM4SjvGkU1W/ckR/mcw== X-Google-Smtp-Source: ABdhPJxBt16YVIvc1te4pyCmgGVi57pKVSf8OToSCldGf38fLGzmUMxho2rSpkMEaM92JEiIug7A4g== X-Received: by 2002:a05:6830:15d9:: with SMTP id j25mr39736otr.259.1606948506912; Wed, 02 Dec 2020 14:35:06 -0800 (PST) Received: from [192.168.1.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id v207sm705581oif.58.2020.12.02.14.35.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2020 14:35:06 -0800 (PST) Subject: Re: Is the Halloween problem an issue in Postgres To: pgsql-general@lists.postgresql.org References: <756bd845-ebe1-4c45-88e8-0ab44bbc02b7@Spark> <5f7e3d0e-52da-c5e4-72d6-edcff340d710@gmx.net> <869172f6-9114-e759-79ba-eb17f1c5082c@aklaver.com> <20201202222342.oc4ayyaxql24tquo@raf.org> From: Ron Message-ID: <4fcb3891-5496-3b14-7cc1-f42f08a3c09a@gmail.com> Date: Wed, 2 Dec 2020 16:35:05 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201202222342.oc4ayyaxql24tquo@raf.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/2/20 4:23 PM, raf wrote: > 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). The Halloween Problem does not seem to cause the statement to fail, but to run slowly. -- Angular momentum makes the world go 'round.