Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dN3QU-0003G2-1Z for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Jun 2017 20:37:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dN3QT-0005LK-8S for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Jun 2017 20:37:33 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dN3QS-0005KM-DV; Mon, 19 Jun 2017 20:37:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dN3QP-0003HW-SN; Mon, 19 Jun 2017 20:37:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v5JKbRCW009072; Mon, 19 Jun 2017 16:37:27 -0400 From: Tom Lane To: J Chapman Flack cc: Dilip Kumar , Artus de benque , pgsql-bugs@postgresql.org, pgsql-hackers Subject: Re: [HACKERS] Re: Postgresql bug report - unexpected behavior of suppress_redundant_updates_trigger In-reply-to: <3b45ea7f-3434-8d97-9177-f1174131fc9a@math.purdue.edu> References: <3b45ea7f-3434-8d97-9177-f1174131fc9a@math.purdue.edu> Comments: In-reply-to J Chapman Flack message dated "Mon, 19 Jun 2017 14:18:50 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9070.1497904647.1@sss.pgh.pa.us> Date: Mon, 19 Jun 2017 16:37:27 -0400 Message-ID: <9071.1497904647@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org J Chapman Flack writes: > On 06/19/2017 11:40 AM, Dilip Kumar wrote: >> ... Artus de benque ... wrote: >>> ...=# UPDATE test_table SET field = rpad('', 2001, 'a') WHERE id = 1; >> Seems like in "suppress_redundant_updates_trigger" we are comparing >> toasted tuple with the new tuple and that is the cause of the bug. > Something still puzzles me about this, though, maybe only because > I don't know enough about TOAST. > The size of 'field' ends up 2001, or just over the threshold where > TOASTing will be attempted at all. The report doesn't mention changing > the strategy from the default EXTENDED, so won't the first thing > attempted be compression? Won't that succeed spectacularly, since the > test string is a single character 2001 times, probably producing > a compressed string a handful of bytes long, well under the threshold, > obviating any need to go further with TOAST pointers? Right, given the facts at hand, the stored old tuple has probably got a compressed-in-line version of "field". However, the *new* tuple is a transient tuple containing the uncompressed result of rpad(). We don't bother to try to compress fields or shove them out-of-line until after all the BEFORE ROW triggers are done --- if we did, the effort might just be wasted, if the triggers change those fields or cancel the update altogether. So the trigger is seeing a compressed vs. an uncompressed version of the field value, and since it's just doing a dumb bitwise compare, they don't look equal. As I mentioned upthread, it'd certainly be possible for the trigger to iterate through the fields in a datatype-aware fashion and undo compression or out-of-lineing before the comparison. But that would eat a lot more cycles than the current implementation, and it seems dubious that it's worth it. If the trigger is succeeding (ie, detecting a no-op update) often enough that it would be worth that, you've really got an application-stupidity problem to fix. > Is the compression algorithm nondeterministic? I don't think so. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs