Re: BUG #15672: PostgreSQL 11.1/11.2 crashed after dropping a partition table
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Amit Langote <amitlangote09@gmail.com>,
Michael Paquier <michael@paquier.xyz>, jianingy.yang@gmail.com,
PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>,
Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2019-04-24T23:27:10Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- avoid-bogus-index-reuse-HEAD.patch (text/x-diff) patch
- avoid-bogus-index-reuse-11.patch (text/x-diff) patch
Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> writes: > On 2019/04/24 7:03, Tom Lane wrote: >> ISTM we could work around the problem with the attached, which I think >> is a good change independently of anything else. > Agreed. After thinking about it more, it seems like a bad idea to put the check in CheckIndexCompatible; that could interfere with any other use of the function to match up potential child indexes. (I wonder why this test isn't the same as what DefineIndex uses to spot potential child indexes, BTW --- it uses a completely separate function CompareIndexInfo, which seems both wasteful and trouble waiting to happen.) So I think we should test the relkind in TryReuseIndex, instead. I think it would be a good idea to *also* do what you suggested upthread and have DefineIndex clear the field when cloning an IndexStmt to create a child; no good could possibly come of passing that down when we intend to create a new index. In short, I think the right short-term fix is as attached (plus a new regression test case based on the submitted example). Longer term, it's clearly bad that we fail to reuse child indexes in this scenario; the point about mangled comments is minor by comparison. I'm inclined to think that what we want to do is *not* recurse when creating the parent index, but to initially make it NOT VALID, and then do ALTER ATTACH PARTITION with each re-used child index. This would successfully reproduce the previous state in case only some of the partitions have attached indexes, which I don't think works correctly right now. BTW, I hadn't ever looked closely at what the index reuse code does, and now that I have, my heart just sinks. I think that logic needs to be nuked from orbit. RelationPreserveStorage was never meant to be abused in this way; I invite you to contemplate whether it's not a problem that it doesn't check the backend and nestLevel fields of PendingRelDelete entries before killing them. (In its originally-designed use for mapped rels at transaction end, that wasn't a problem, but I'm afraid that it may be one now.) The right way to do this IMO would be something closer to the heap-swap logic in cluster.c, where we exchange the relfilenodes of two live indexes, rather than what is happening now. Or for that matter, do we really need to delete the old indexes at all? None of that looks very practical for v12, let alone back-patching to v11, though. regards, tom lane
Commits
-
Apply stopgap fix for bug #15672.
- c01eb619a83a 12.0 landed
- 02c359eeda50 11.3 landed