Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKP6f-00055H-Kb for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Nov 2018 14:46:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gKP6e-00052r-0f for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Nov 2018 14:46:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKP6d-00052e-Qn for pgsql-bugs@lists.postgresql.org; Wed, 07 Nov 2018 14:46:55 +0000 Received: from mout.gmx.net ([212.227.17.21]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gKP6b-0008U7-35 for pgsql-bugs@lists.postgresql.org; Wed, 07 Nov 2018 14:46:55 +0000 Received: from scnat18.scnat.ch ([212.103.79.228]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0M2cDB-1fUmSL2MAH-00sLhQ; Wed, 07 Nov 2018 15:46:48 +0100 From: Tobias Bussmann Content-Type: multipart/mixed; boundary="Apple-Mail=_23297E96-9B58-4B3F-A5F0-2953CA7214CA" Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: segfault with expression index, btree_gist and HOT Update Message-Id: <77EC85F8-B515-4CD3-B68E-26D82CF48D58@gmx.net> Date: Wed, 7 Nov 2018 15:46:46 +0100 Cc: =?utf-8?Q?J=C3=BCrg_Senn?= To: pgsql-bugs@lists.postgresql.org X-Mailer: Apple Mail (2.3445.9.1) X-Provags-ID: V03:K1:gZ4Qkhu27tR4ZZF41RfFVt7ZsdJLr35PMimz8C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D2MvQQRUDx3g69MDWxida/Qlwp+eqvtUyQlnbycxB3F9mPVwO/j8z11V4qZkjDHxWs 2LQhGUKK7kLvGTSor9vQ36TbzJBGN7n+wm7ta85gw= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_23297E96-9B58-4B3F-A5F0-2953CA7214CA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello, my colleague J=C3=BCrg Senn recently found a backend crash in Postgres = 11 and trimmed it down to a reproducible test case. Testing revealed the = crash is still present in last week's master branch but not in 10. I = further simplified the test case to: CREATE EXTENSION btree_gist; CREATE TABLE segfault (i int); CREATE INDEX ON segfault USING gist ((i + 10)); INSERT INTO segfault VALUES (1); UPDATE segfault SET i =3D 2; Our tests were performed on macOS: PostgreSQL 12devel on = x86_64-apple-darwin17.7.0, compiled by Apple LLVM version 9.1.0 = (clang-902.0.39.2), 64-bit Apparently the segfault happens within the check for the possibility of = HOT Updates with expression / functional indexes which was added by = c203d6cf8 in 11. The backtrace on the segfault is:=20 * thread #1, queue =3D 'com.apple.main-thread', stop reason =3D = EXC_BAD_ACCESS (code=3D1, address=3D0xb) * frame #0: 0x00007fff51b06cc0 = libsystem_platform.dylib`_platform_memcmp + 288 frame #1: 0x0000000108b8b7e3 postgres`datumIsEqual(value1=3D11, = value2=3D12, typByVal=3Dfalse, typLen=3D8) at datum.c:249 frame #2: 0x000000010869ca52 = postgres`ProjIndexIsUnchanged(relation=3D0x000000010b292778, = oldtup=3D0x00007ffee75e28b8, newtup=3D0x00007f9f84007e70) at = heapam.c:4551 frame #3: 0x000000010869b60f = postgres`heap_update(relation=3D0x000000010b292778, = otid=3D0x00007ffee75e2bc8, newtup=3D0x00007f9f84007e70, cid=3D0, = crosscheck=3D0x0000000000000000, wait=3Dtrue, hufd=3D0x00007ffee75e2a98, = lockmode=3D0x00007ffee75e2a80) at heapam.c:4242 frame #4: 0x000000010892c381 = postgres`ExecUpdate(mtstate=3D0x00007f9f840066c0, = tupleid=3D0x00007ffee75e2bc8, oldtuple=3D0x0000000000000000, = slot=3D0x00007f9f84007708, planSlot=3D0x00007f9f84006bd8, = epqstate=3D0x00007f9f84006780, estate=3D0x00007f9f84006318, = canSetTag=3Dtrue) at nodeModifyTable.c:1208 frame #5: 0x000000010892a57e = postgres`ExecModifyTable(pstate=3D0x00007f9f840066c0) at = nodeModifyTable.c:2172 frame #6: 0x00000001088fbc12 = postgres`ExecProcNodeFirst(node=3D0x00007f9f840066c0) at = execProcnode.c:445 frame #7: 0x00000001088f5002 = postgres`ExecProcNode(node=3D0x00007f9f840066c0) at executor.h:237 frame #8: 0x00000001088f0a31 = postgres`ExecutePlan(estate=3D0x00007f9f84006318, = planstate=3D0x00007f9f840066c0, use_parallel_mode=3Dfalse, = operation=3DCMD_UPDATE, sendTuples=3Dfalse, numberTuples=3D0, = direction=3DForwardScanDirection, dest=3D0x00007f9f83005e40, = execute_once=3Dtrue) at execMain.c:1707 frame #9: 0x00000001088f08fc = postgres`standard_ExecutorRun(queryDesc=3D0x00007f9f83005b18, = direction=3DForwardScanDirection, count=3D0, execute_once=3Dtrue) at = execMain.c:364 frame #10: 0x00000001088f06c2 = postgres`ExecutorRun(queryDesc=3D0x00007f9f83005b18, = direction=3DForwardScanDirection, count=3D0, execute_once=3Dtrue) at = execMain.c:307 frame #11: 0x0000000108b2edfe = postgres`ProcessQuery(plan=3D0x00007f9f830015b0, sourceText=3D"UPDATE = segfault SET i =3D 2;", params=3D0x0000000000000000, = queryEnv=3D0x0000000000000000, dest=3D0x00007f9f83005e40, = completionTag=3D"") at pquery.c:161 frame #12: 0x0000000108b2de78 = postgres`PortalRunMulti(portal=3D0x00007f9f82842518, isTopLevel=3Dtrue, = setHoldSnapshot=3Dfalse, dest=3D0x00007f9f83005e40, = altdest=3D0x00007f9f83005e40, completionTag=3D"") at pquery.c:1286 frame #13: 0x0000000108b2d540 = postgres`PortalRun(portal=3D0x00007f9f82842518, = count=3D9223372036854775807, isTopLevel=3Dtrue, run_once=3Dtrue, = dest=3D0x00007f9f83005e40, altdest=3D0x00007f9f83005e40, = completionTag=3D"") at pquery.c:799 frame #14: 0x0000000108b28a21 = postgres`exec_simple_query(query_string=3D"UPDATE segfault SET i =3D = 2;") at postgres.c:1215 frame #15: 0x0000000108b27bb8 postgres`PostgresMain(argc=3D1, = argv=3D0x00007f9f82815138, dbname=3D"bussmann", username=3D"bussmann") = at postgres.c:4243 frame #16: 0x0000000108a655b4 = postgres`BackendRun(port=3D0x00007f9f80e00910) at postmaster.c:4377 frame #17: 0x0000000108a649b8 = postgres`BackendStartup(port=3D0x00007f9f80e00910) at postmaster.c:4068 frame #18: 0x0000000108a6385a postgres`ServerLoop at = postmaster.c:1700 frame #19: 0x0000000108a61158 postgres`PostmasterMain(argc=3D3, = argv=3D0x00007f9f81900580) at postmaster.c:1373 frame #20: 0x000000010896c219 postgres`main(argc=3D3, = argv=3D0x00007f9f81900580) at main.c:228 frame #21: 0x00007fff517f9015 libdyld.dylib`start + 1 Interestingly, the debugger has no issue accessing the memory in = question: (Datum) value1 =3D 11 (Datum) value2 =3D 12 (bool) typByVal =3D false (int) typLen =3D 8 (bool) res =3D false (Size) size1 =3D 8 (Size) size2 =3D 8 (char *) s1 =3D 0x000000000000000b "" (char *) s2 =3D 0x000000000000000c "" How can this be investigated further? The top of the stack trace is similar to the one in = https://www.postgresql.org/message-id/20181101140216.GA2954%40hermes.hilbe= rt.loc but I'm not sure these are actually related. I was unable to reproduce the segfault with other index types then GIST = nor w/o the opclasses provided by the btree_gist extension. However none = of that specifically appears in the stack frame. Further poking around the issue I came across the following: # ALTER INDEX segfault_expr_idx SET (RECHECK_ON_UPDATE =3D off); ERROR: unrecognized parameter "recheck_on_update" According to the commit referred to earlier, this option should work for = all index types, but apparently it does not for GIST. In reloptions.h:54 = we have=20 > RELOPT_KIND_INDEX =3D = RELOPT_KIND_BTREE|RELOPT_KIND_HASH|RELOPT_KIND_GIN|RELOPT_KIND_SPGIST which is missing RELOPT_KIND_GIST and RELOPT_KIND_BRIN. Adding these at = least fixes the possibility to set and use the parameter on the GIST = index. Trivial patch for that attached. Tobias --Apple-Mail=_23297E96-9B58-4B3F-A5F0-2953CA7214CA Content-Disposition: attachment; filename=recheck_on_update.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="recheck_on_update.patch" Content-Transfer-Encoding: 7bit diff --git a/src/include/access/reloptions.h b/src/include/access/reloptions.h index 4022c14a83..b4afb0a345 100644 --- a/src/include/access/reloptions.h +++ b/src/include/access/reloptions.h @@ -51,7 +51,12 @@ typedef enum relopt_kind RELOPT_KIND_PARTITIONED = (1 << 11), /* if you add a new kind, make sure you update "last_default" too */ RELOPT_KIND_LAST_DEFAULT = RELOPT_KIND_PARTITIONED, - RELOPT_KIND_INDEX = RELOPT_KIND_BTREE | RELOPT_KIND_HASH | RELOPT_KIND_GIN | RELOPT_KIND_SPGIST, + RELOPT_KIND_INDEX = RELOPT_KIND_BTREE + | RELOPT_KIND_HASH + | RELOPT_KIND_GIN + | RELOPT_KIND_GIST + | RELOPT_KIND_SPGIST + | RELOPT_KIND_BRIN, /* some compilers treat enums as signed ints, so we can't use 1 << 31 */ RELOPT_KIND_MAX = (1 << 30) } relopt_kind; --Apple-Mail=_23297E96-9B58-4B3F-A5F0-2953CA7214CA Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_23297E96-9B58-4B3F-A5F0-2953CA7214CA--