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 1lR0Ew-000770-9u for pgsql-general@arkaria.postgresql.org; Mon, 29 Mar 2021 22:20:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lR0Ev-0006V7-3c for pgsql-general@arkaria.postgresql.org; Mon, 29 Mar 2021 22:20:05 +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 1lR0Et-0006Uz-NV for pgsql-general@lists.postgresql.org; Mon, 29 Mar 2021 22:20:04 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lR0Ep-0005bE-78 for pgsql-general@lists.postgresql.org; Mon, 29 Mar 2021 22:20:02 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 0DB025C01BB for ; Mon, 29 Mar 2021 18:19:58 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 29 Mar 2021 18:19:58 -0400 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=fm2; bh=t u8RhtKusBM4jPRMcq677GuIzSrcZt0J79Ncncr94Jg=; b=xGkMwSag7QoekWPuw 9/hMkZWsdWIH5K+kKv34Z6BhXZfxKs4FbHKK0R0z/t7RQO1ZfPOYo8yClphw8hZh U3am/zyjokj6hPbn3yO8L1aW6IRdVUIV8LFTLVjZg8PlDZnC9bWLOEyM/AfQgYad ghXH22ASn6o53wbnJ7e5LMPypDIOqQqUe5fMMaF/Y5Di3uFOeOTM8PF6iMdbrXCW tiRM63/6wIwOr3QSJDJ2XOBrYWZ7xdwgNvWFWC6SCCJ5e+q8FIpMxHMPuytbIDkA pRgb9UC7n2CVWz1KrxRtnFOAKVeY9iDK2VU9Q+9O2h4c9GiRE8MExC2d/WV/HLwZ SeZ+g== 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=fm2; bh=tu8RhtKusBM4jPRMcq677GuIzSrcZt0J79Ncncr94 Jg=; b=qrEcLrG4ylgMfPLmIZuQbZF1z8oE5mGjE1LX7tVM5VuSHukvevA/PnR8L YnOjTGmu09SbisiO8StVJvgCpSLJknJLGVKkNizpoBhAtRB+4lPn7lSB1YAru/He LjFM46r02LmkP8GmFMIsCG2O4iepiBdLvmHnOokY6F6K9zJDfDzsZ7fICaYSD2lN 5oInUvImqP09jvo+jvqWFl9Z01+Hsf0JBRQLyFxUNVHtNi2pkcVFyLHyKMc8odMI gKjetKjQd6LkYV9dF8M6B/DXVjWMJ7Ou7zr7PCHPgr7v0jy9PI7B7YHxlMpuIfDW 3Km6AiQJHZcTaFQbFZA0qchJMEINw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudehledgtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepgfekfedtfe euteeifeeigeefudfhhedvgfevvedvheeujeevffeltdduuefggeefnecuffhomhgrihhn pehgihhthhhusgdrtghomhdpphhoshhtghhrvghsqhhlrdhorhhgpdhsvghilhgvrhdruh hsnecukfhppeehtddrudeljedrkedtrddvnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomh X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 1E9771080063 for ; Mon, 29 Mar 2021 18:19:57 -0400 (EDT) Subject: Re: Dangerous Naming Confusion To: pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Mon, 29 Mar 2021 15:19:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: 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: Archived-At: Precedence: bulk On 3/29/21 3:00 PM, Don Seiler wrote: > Good evening, > > Please see my gist at > https://gist.github.com/dtseiler/9ef0a5e2b1e0efc6a13d5661436d4056 > for > a complete test case. > > I tested this on PG 12.6 and 13.2 and observed the same on both. > > We were expecting the queries that use dts_temp to only return 3 rows. > However the subquery starting at line 36 returns ALL 250,000 rows from > dts_orders. Note that the "order_id" field doesn't exist in the dts_temp > table, so I'm assuming PG is using the "order_id" field from the > dts_orders table. If I use explicit table references like in the query > at line 48, then I get the error I would expect that the "order_id" > column doesn't exist in dts_temp. > > When I use the actual column name "a" for dts_temp, then I get the 3 > rows back as expected. > > I'm wondering if this is expected behavior that PG uses the > dts_orders.order_id value in the subquery "select order_id from > dts_temp" when dts_temp doesn't have its own order_id column. I would > have expected an error that the column doesn't exist. Seems very > counter-intuitive to think PG would use a column from a different table. See: https://www.postgresql.org/message-id/Pine.LNX.4.56.0308011345320.881@krusty.credativ.de > > This issue was discovered today when this logic was used in an UPDATE > and ended up locking all rows in a 5M row table and brought many apps to > a grinding halt. Thankfully it was caught and killed before it actually > updated anything. > > Thanks, > Don. > -- > Don Seiler > www.seiler.us -- Adrian Klaver adrian.klaver@aklaver.com