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 1k00GO-0007oR-ME for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Jul 2020 10:21:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k00GN-0000tE-IT for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Jul 2020 10:21:43 +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 <9erthalion6@gmail.com>) id 1k00GN-0000t6-93 for pgsql-hackers@lists.postgresql.org; Mon, 27 Jul 2020 10:21:43 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1k00GK-0003Tg-N0 for pgsql-hackers@postgresql.org; Mon, 27 Jul 2020 10:21:42 +0000 Received: by mail-ed1-x52e.google.com with SMTP id c2so5869441edx.8 for ; Mon, 27 Jul 2020 03:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pnl4xDQM9Zp3lTvBoy+2Naqn/6e2QXHF/xnve2evBvg=; b=a5vm9jTwbCEHmTVJ4d3Xjx7bb4gyIBjy5B6YPA9COGxLmCRqX1E4rmY7i3Nrd1rcNL f9GHdzpxGGCKZOkAtQBtpSwWjGG+mnbpVwpFS45CMOP0mHo5E3bdOq1kcpNhWjnBByMg 4uRbX2gGlMbOWZyWmmwnU894i6X2OpQUCZZSz1E2YKshAp3Dghud0AUfq1wrzsybFyYW GZdNP82CNOq7OSmYWNVKF/MLCIRRll7MI7ULwc96K/vy3vfMI5MkMzAbxoa/nmmxOjpi r4AvdfuLonCz+F6AesGMrLsE7bARJngupnCDtmqrpWRBA2ylV1xqF9aRy0VQvIM9qzKw Z8yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pnl4xDQM9Zp3lTvBoy+2Naqn/6e2QXHF/xnve2evBvg=; b=V6aQzdAFL1GTADPVT601gw2Le1yUQ368SjT7kB5+mYGb4O2Lk49Fqg8kn4Kqk5ET+0 z/HKQYaVrMCxUShrXEP8Dw9qVChapU6DvhcCvJvNk9em7if7Jb3Zjs6R8lt+8WoTL1Mx 647MvgXgaftEtOBhKgVK1EEETUrnWvwEwVNnEEd+EbdY6o6sx5MicjOfJ2qxUAmxKkNZ xx/bkm25JZjThSxQ+EPsL7ov5ot/2W3vNQ8nVu2epG79CJu8Wyv1JW4TJGXFOf7gB6Ti Uewbn7b7hMzknGFEHlbzzu1EHxYZ1HQQUfXfa9xw1Ec6c89mqGeGRNkD5htZliQ7Be3o +khQ== X-Gm-Message-State: AOAM533/k6jpSUWv0i1CmG4PWpcrfJ/yKi/Nj3wlQfBlzT7U1iYY0BOT UAnMcNuPFlwxTzxF9YrbwHs= X-Google-Smtp-Source: ABdhPJziiUSrBKHaxuSkbba8nTuarCeWYGW2y7ZUTvnNd5RqcjyKz24ABSs0UKuZ0RdsshPB4FM8Eg== X-Received: by 2002:a50:f19c:: with SMTP id x28mr18292659edl.295.1595845298418; Mon, 27 Jul 2020 03:21:38 -0700 (PDT) Received: from localhost (dslb-178-005-232-008.178.005.pools.vodafone-ip.de. [178.5.232.8]) by smtp.gmail.com with ESMTPSA id ah1sm6667515ejc.43.2020.07.27.03.21.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2020 03:21:37 -0700 (PDT) Date: Mon, 27 Jul 2020 12:24:31 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Peter Geoghegan Cc: PostgreSQL-development , Jesper Pedersen , David Rowley , Floris Van Nee , Kyotaro Horiguchi , Thomas Munro , Tomas Vondra , Andy Fan , Dilip Kumar Subject: Re: Index Skip Scan (new UniqueKeys) Message-ID: <20200727102431.mjspwec4yhzeyny2@localhost> References: <20200609102247.jdlatmfyeecg52fi@localhost> <20200711161258.5modwkdeszhf55ux@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Tue, Jul 21, 2020 at 04:35:55PM -0700, Peter Geoghegan wrote: > > > Well, it's obviously wrong, thanks for noticing. What is necessary is to > > compare two index tuples, the start and the next one, to test if they're > > the same (in which case if I'm not mistaken probably we can compare item > > pointers). I've got this question when I was about to post a new version > > with changes to address feedback from Andy, now I'll combine them and > > send a cumulative patch. > > This sounds like approximately the same problem as the one that > _bt_killitems() has to deal with as of Postgres 13. This is handled in > a way that is admittedly pretty tricky, even though the code does not > need to be 100% certain that it's "the same" tuple. Deduplication kind > of makes that a fuzzy concept. In principle there could be one big > index tuple instead of 5 tuples, even though the logical contents of > the page have not been changed between the time we recording heap TIDs > in local and the time _bt_killitems() tried to match on those heap > TIDs to kill_prior_tuple-kill some index tuples -- a concurrent > deduplication pass could do that. Your code needs to be prepared for > stuff like that. > > Ultimately posting list tuples are just a matter of understanding the > on-disk representation -- a "Small Matter of Programming". Even > without deduplication there are potential hazards from the physical > deletion of LP_DEAD-marked tuples in _bt_vacuum_one_page() (which is > not code that runs in VACUUM, despite the name). Make sure that you > hold a buffer pin on the leaf page throughout, because you need to do > that to make sure that VACUUM cannot concurrently recycle heap TIDs. > If VACUUM *is* able to concurrently recycle heap TIDs then it'll be > subtly broken. _bt_killitems() is safe because it either holds on to a > pin or gives up when the LSN changes at all. (ISTM that your only > choice is to hold on to a leaf page pin, since you cannot just decide > to give up in the way that _bt_killitems() sometimes can.) I see, thanks for clarification. You're right, in this part of implementation there is no way to give up if LSN changes like _bt_killitems does. As far as I can see the leaf page is already pinned all the time between reading relevant tuples and comparing them, I only need to handle posting list tuples.