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 1q8yxR-00034S-8c for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Jun 2023 08:00:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q8yxP-0003Fw-5B for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Jun 2023 08:00:51 +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 1q8yxO-0003Fn-Sw for pgsql-bugs@lists.postgresql.org; Tue, 13 Jun 2023 08:00:50 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q8yxJ-001wAZ-AN for pgsql-bugs@lists.postgresql.org; Tue, 13 Jun 2023 08:00:49 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-51878f8e541so423004a12.3 for ; Tue, 13 Jun 2023 01:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686643244; x=1689235244; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=J9899/V968iiNGXxhoaZXjZz1AcZol3ns+5oe/4IKqo=; b=rboDcN2e5ARSDWXDz06MccV559+6r6+Tw/jHbv6GInFegQtRBMlFGv6Dud2MYWlKJW utniicvQOZbBM+nDjCL+IAjGgc8iKX10Ph1ha6rLyv5v6dTNaDACcgmLJPrZSGVJjVB5 zOKMAd0SGps4Sn7PzTKbUQH3iVsvlZxVPSULs9lNbH9LoGBsmvIeyqplMqwvHKkf2gMd vK4yyoA7cfS5YrepQ4vnUGuapsq5pym/2k5o8sF4UPA2ZwY9vj4yCOF4ftx+lWsVpJlG dxlH7zmr/Gk4ADiynNVd9NENq+sjXow81t9CLoHTZncO09KkWQr/5awwPpUviLmK4AMA TEww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686643244; x=1689235244; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J9899/V968iiNGXxhoaZXjZz1AcZol3ns+5oe/4IKqo=; b=YXDAiIhHveZZVTu4L4qTW9tVUUMnSk1pXlU7ymc0SgV/pWuwzvq2yLSXZzWg/7NzDH xVQEsD0OT/839nWgc4leOfaafKR3sN4/HE0p+/F2tlD/3JSKjltJ7gwHVj6dX+HC/MWq z/I0vyInHSap3/kuWc8fVSPoX/iJlXo0s++bSfhzzjY8Acf02q79o4rqHd+0UD5/TwMH xCJYrmrMj4M0FEWswwGsg7RoE1TWJebKzodo8oSW6mcNd/noJuLsgzOLVyMLDVvOmakI BbNEDuAILFAeBhSiH5Hjiegm8et3yHTOOla8opan71NyjNJ57cEjFL+aKEU/ZLcmkGEN Bu4g== X-Gm-Message-State: AC+VfDxjeuM3p9MLx7gMv/sBpgSdbD4jPdHxq6rbQ7EQdsGCMfaY6QUO V+TSNVRvRMbUTkmsUvQdozM= X-Google-Smtp-Source: ACHHUZ4E5VUQ8D8lrkWXkf5vLw14yKgcRvP6LTKQniqce5A4K56e1bbBZvr5Q5SPglvAdiQPUO6IgQ== X-Received: by 2002:a17:907:9403:b0:982:3db3:8d25 with SMTP id dk3-20020a170907940300b009823db38d25mr1025225ejc.60.1686643243632; Tue, 13 Jun 2023 01:00:43 -0700 (PDT) Received: from [192.168.10.157] (31-5-22.netrun.cytanet.com.cy. [31.153.5.22]) by smtp.gmail.com with ESMTPSA id i8-20020a17090671c800b009659fa6eeddsm6245023ejk.196.2023.06.13.01.00.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Jun 2023 01:00:43 -0700 (PDT) Message-ID: Date: Tue, 13 Jun 2023 11:00:41 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: BUG #17949: Adding an index introduces serialisation anomalies. Content-Language: en-US To: Thomas Munro , pgsql-bugs@lists.postgresql.org References: <17949-a0f17035294a55e2@postgresql.org> From: Artem Anisimov In-Reply-To: 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 Hi Thomas, thank you for the confirmation and analysis. Did you have a chance to take a more detailed look at the problem? Best regards, Artem. On 30/05/2023 04:29, Thomas Munro wrote: > Hi, > > Reproduced here. Thanks for the reproducer. I agree that something > is wrong here, but I haven't had time to figure out what, yet, but let > me share what I noticed so far... I modified your test to add a pid > column to the locks table and to insert insert pg_backend_pid() into > it, and got: > > postgres=# select xmin, * from locks; > > ┌───────┬──────┬───────┐ > │ xmin │ path │ pid │ > ├───────┼──────┼───────┤ > │ 17634 │ xyz │ 32932 │ > │ 17639 │ xyz │ 32957 │ > └───────┴──────┴───────┘ > > Then I filtered the logs (having turned the logging up to capture all > queries) so I could see just those PIDs and saw this sequence: > > 2023-05-29 00:15:43.933 EDT [32932] LOG: duration: 0.182 ms > statement: BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE > 2023-05-29 00:15:43.934 EDT [32957] LOG: duration: 0.276 ms > statement: BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE > 2023-05-29 00:15:43.935 EDT [32932] LOG: duration: 1.563 ms > statement: SELECT * FROM locks WHERE path = 'xyz' > 2023-05-29 00:15:43.936 EDT [32932] LOG: duration: 0.126 ms > statement: INSERT INTO locks(path, pid) VALUES('xyz', > pg_backend_pid()) > 2023-05-29 00:15:43.937 EDT [32957] LOG: duration: 2.191 ms > statement: SELECT * FROM locks WHERE path = 'xyz' > 2023-05-29 00:15:43.937 EDT [32957] LOG: duration: 0.261 ms > statement: INSERT INTO locks(path, pid) VALUES('xyz', > pg_backend_pid()) > 2023-05-29 00:15:43.937 EDT [32932] LOG: duration: 0.222 ms statement: COMMIT > 2023-05-29 00:15:43.939 EDT [32957] LOG: duration: 1.775 ms statement: COMMIT > > That sequence if run (without overlap) in the logged order is normally > rejected. The query plan being used (at least when I run the query > myself) looks like this: > > Query Text: SELECT * FROM locks WHERE path = 'xyz' > Bitmap Heap Scan on locks (cost=4.20..13.67 rows=6 width=36) > Recheck Cond: (path = 'xyz'::text) > -> Bitmap Index Scan on locks_path_idx (cost=0.00..4.20 rows=6 width=0) > Index Cond: (path = 'xyz'::text)