Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7twv-007NUK-NS for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2023 09:00:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r7twt-003hcE-PN for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2023 09:00:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7twt-003hbc-Gh for pgsql-bugs@lists.postgresql.org; Tue, 28 Nov 2023 09:00:07 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r7twr-007k90-4P for pgsql-bugs@lists.postgresql.org; Tue, 28 Nov 2023 09:00:06 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50babce6ff6so3551996e87.3 for ; Tue, 28 Nov 2023 01:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701162003; x=1701766803; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=7PN4nECLVXhEB8qe/vWPlZ2fpIFCOcETDAOu4BYbFr8=; b=QJ9KWk6ky7KeGDU5g5B8tEowczPW3VjXw7GGnxJnlWIhrAD3/sOENHJpAfgqtgIke7 Zo0yvYemdmC8QuazZthBiCuf9l28s4Mpus2wsVA/0Z3XHTYAMyLGmdDEjJkr8c4K1BaA pv0Me385YMt+G4F+zeTFa3WkaQIpj6ypQZhJhA1yK0/ukWUmBeZScKGgoNueD/qY22sx 93d80FPDV3pIbVqkdx/cKKGtYxXktx0e10+e7yh8NuVhGP33YjY9T6E2voyh/MMHddkE rbHEHVztmn5mGxfSMbM11Leaz3irmfi0Llng6v5rnxyPFUVT0PVl4ITpOO9o21I3JtAr 71mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701162003; x=1701766803; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7PN4nECLVXhEB8qe/vWPlZ2fpIFCOcETDAOu4BYbFr8=; b=rfgOOb1o+guX3rB+GDx2ahzhoJA3pZ3kt3DpCSZVG2HyDVOsL9ku+tio6ddpPhO44s 5YBBB3ppBfN/EXiRO1ytcIc2YHQan3H9WDCiwR63ColwsKMp1OkTSOrMmcc09HtS1h7N mIUJysoQd5Jy+eVo5YUW5QRHR75R0+F1Soo09hnEj9yKMH1AmuGw4Gkjwx/hQkmjdBau Yk2oDp3qSYqvXzFcV8YAs5Ogwv3/B5910zL0hR6pmfXGwZHme+9GdPW5lMKzoGJG1xAz tt6/rLlhHn86wZFHTZB07YgQlyDfrxmkP55lCuO0ui05+KsjmllT3nMqRTSJcLjhIVeA aPmg== X-Gm-Message-State: AOJu0Yxhh9RnIMQQOT327d3XqrWJC6tZ6bRUD+xCJusfJD7QZ+kiX2yN xLnrkaCtEp097Q+JJLjO6CU= X-Google-Smtp-Source: AGHT+IE8UEGX3+iyHrfhCez1N5RNRW75su2WmAX/rt91NMrrsyFztsWyFvy66n7bkp/tJNZPPJnRgA== X-Received: by 2002:a05:6512:2242:b0:50b:a995:24e2 with SMTP id i2-20020a056512224200b0050ba99524e2mr8151196lfu.21.1701162003138; Tue, 28 Nov 2023 01:00:03 -0800 (PST) Received: from [1.0.0.7] ([178.155.24.255]) by smtp.gmail.com with ESMTPSA id q9-20020a0565123a8900b0050abbda2c52sm1791629lfu.157.2023.11.28.01.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Nov 2023 01:00:02 -0800 (PST) Message-ID: <8b695b41-a006-f4d2-545f-c99db7595ee2@gmail.com> Date: Tue, 28 Nov 2023 12:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #17893: Assert failed in heap_update()/_delete() when FK modiified by RI trigger in non-read-committed xact To: Heikki Linnakangas , pgsql-bugs@lists.postgresql.org, Andres Freund References: <17893-35847009eec517b5@postgresql.org> <1236e144-d772-7ff4-6e23-4ce91d0923ad@gmail.com> <0c6e10cd-9288-4dda-b35e-7a64684367d3@iki.fi> Content-Language: en-US From: Alexander Lakhin In-Reply-To: <0c6e10cd-9288-4dda-b35e-7a64684367d3@iki.fi> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Heikki, 27.11.2023 22:23, Heikki Linnakangas wrote: > I propose to attached slight variation, which moves the assertions before the crosscheck snapshot check. The > assertions are correct as they are, if you don't need to take the crosscheck into account. > Thank you for paying attention to this! I agree with your variation, it's more accurate. > I'm a little worried if the callers of tuple_update() might also get confused when tuple_update() returns TM_Updated > but xmax is invalid. As you said: > ... > I think you only get that error with REPEATABLE READ or SERIALIZABLE isolation level. I don't quite understand how > this works. In READ COMMITTED level, ISTM that ExecUpdate() or ExecDelete() will proceed with EvalPlanQualSlot() and > locking the row with table_tuple_lock(). Or do we never use the cross-check snapshot in READ COMMITTED mode? > I think so, as I see the following in ri_PerformCheck():     /*      * In READ COMMITTED mode, we just need to use an up-to-date regular      * snapshot, and we will see all rows that could be interesting. But in      * transaction-snapshot mode, we can't change the transaction snapshot. If      * the caller passes detectNewRows == false then it's okay to do the query      * with the transaction snapshot; otherwise we use a current snapshot, and      * tell the executor to error out if it finds any rows under the current      * snapshot that wouldn't be visible per the transaction snapshot.  Note      * that SPI_execute_snapshot will register the snapshots, so we don't need      * to bother here.      */     if (IsolationUsesXactSnapshot() && detectNewRows)     {         CommandCounterIncrement();  /* be sure all my own work is visible */         test_snapshot = GetLatestSnapshot();         crosscheck_snapshot = GetTransactionSnapshot();     } IIUC, that's the only place where crosscheck_snapshot (and then es_crosscheck_snapshot) may get a non-invalid value. Best regards, Alexander