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 1kBJOr-0005kf-2Z for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Aug 2020 15:01:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kBJOo-0001tC-BA for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Aug 2020 15:01:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kBJOo-0001rn-4q for pgsql-bugs@lists.postgresql.org; Thu, 27 Aug 2020 15:01:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kBJOm-0007Dr-1I for pgsql-bugs@lists.postgresql.org; Thu, 27 Aug 2020 15:01:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 07RF148q3032573; Thu, 27 Aug 2020 11:01:04 -0400 From: Tom Lane To: jesse@falkon.ai cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16595: Reads fail with "lost saved point in index" error after writes In-reply-to: <16595-633118be8eef9ce2@postgresql.org> References: <16595-633118be8eef9ce2@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 27 Aug 2020 03:40:47 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3032571.1598540464.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 27 Aug 2020 11:01:04 -0400 Message-ID: <3032572.1598540464@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > The table in question has a JSONB column with a GIN index, defined as: > "index_name_idx" gin (jsonb_column_name jsonb_path_ops, integer_column, > timestamp_with_time_zone_column) > Under load (especially writes followed immediately by reads), we > occasionally see reads failing an internal exception (error code XX000) = with > the message "lost saved point in index". [ stares at that for awhile... ] Hm, I think this is just broken for multi-column GIN indexes. The code is expecting that it can re-find an index item that was there before, and that the item must either be where it was before in the index or somewhere to the right. Both of those assumptions seem valid, since ginvacuum never removes items; but insertions could push the item to the right. But this: if (gintuple_get_attrnum(btree->ginstate, itup) !=3D attnu= m) elog(ERROR, "lost saved point in index"); /* must n= ot happen !!! */ amounts to an assumption that things can't get pushed so far to the right that our pointer is now pointing at an item with lower attnum. There's no reason for that to be true --- AFAICS, the attnum is the first sort key for the items, but there's not physical segregation into different index pages or anything like that. We could throw an error if we reach a higher attnum, but since the whole thing is supposed to be can't-happen, I doubt it's worth expending code on. What we should do is just advance over any item that hasn't got the right attnum. regards, tom lane