Re: GiST VACUUM
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Andrey Borodin <x4mmm@yandex-team.ru>
Cc: Michael Paquier <michael@paquier.xyz>, Thomas Munro <thomas.munro@enterprisedb.com>, Robert Haas <robertmhaas@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, Костя Кузнецов <chapaev28@ya.ru>
Date: 2019-03-11T15:03:54Z
Lists: pgsql-hackers
Attachments
- 0001-Add-block-set-data-structure.patch (text/x-patch)
On 10/03/2019 18:40, Andrey Borodin wrote: > Here's new version of the patch for actual page deletion. > Changes: > > 1. Fixed possible concurrency issue: > > We were locking child page while holding lock on internal page. Notes > in GiST README recommend locking child before parent. Thus now we > unlock internal page before locking children for deletion, and lock > it again, check that everything is still on it's place and delete > only then. Good catch. The implementation is a bit broken, though. This segfaults: create table gist_point_tbl(id int4, p point); create index gist_pointidx on gist_point_tbl using gist(p); insert into gist_point_tbl (id, p) select g, point((1+g) % 100, (1+g) % 100) from generate_series(1, 10000) g; insert into gist_point_tbl (id, p) select -g, point(1000, 1000) from generate_series(1, 10000) g; delete from gist_point_tbl where id >= 0; vacuum verbose gist_point_tbl; BTW, we don't seem to have test coverage for this in the regression tests. The tests that delete some rows, where you updated the comment, doesn't actually seem to produce any empty pages that could be deleted. > One thing still bothers me. Let's assume that we have internal page > with 2 deletable leaves. We lock these leaves in order of items on > internal page. Is it possible that 2nd page have follow-right link on > 1st and someone will lock 2nd page, try to lock 1st and deadlock with > VACUUM? Hmm. If the follow-right flag is set on a page, it means that its right sibling doesn't have a downlink in the parent yet. Nevertheless, I think I'd sleep better, if we acquired the locks in left-to-right order, to be safe. An easy cop-out would be to use LWLockConditionalAcquire, and bail out if we can't get the lock. But if it's not too complicated, it'd be nice to acquire the locks in the correct order to begin with. I did a round of cleanup and moving things around, before I bumped into the above issue. I'm including them here as separate patches, for easier review, but they should of course be squashed into yours. For convenience, I'm including your patches here as well, so that all the patches you need are in the same place, but they are identical to what you posted. - Heikki
Commits
-
Use full 64-bit XID for checking if a deleted GiST page is old enough.
- fb5344c969af 12.0 landed
- 6655a7299d83 13.0 landed
-
Refactor checks for deleted GiST pages.
- e2e992c93145 12.0 landed
- 9eb5607e6993 13.0 landed
-
Delete empty pages during GiST VACUUM.
- 7df159a620b7 12.0 landed
-
Scan GiST indexes in physical order during VACUUM.
- fe280694d0d4 12.0 landed
-
Prevent GIN deleted pages from being reclaimed too early
- 52ac6cd2d0cd 12.0 cited