Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iuIUR-0003nl-JZ for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jan 2020 16:04:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iuIUP-0003Ml-ND for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jan 2020 16:04:21 +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_SHA1:256) (Exim 4.89) (envelope-from <9erthalion6@gmail.com>) id 1iuIUP-0003Lb-Bb for pgsql-hackers@lists.postgresql.org; Wed, 22 Jan 2020 16:04:21 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1iuIUN-0000UX-6n for pgsql-hackers@postgresql.org; Wed, 22 Jan 2020 16:04:20 +0000 Received: by mail-wm1-x336.google.com with SMTP id p9so7376694wmc.2 for ; Wed, 22 Jan 2020 08:04:18 -0800 (PST) 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=kWd+Z+MsF18qgbZiQLBWMWpmPsmRIT4kw65JjXvGdqI=; b=ezOh/anLptkh/IE9sOK4r8jLyKdhu40rlfkhCphlI9pdASnLfAXPA/9euesR6H2bnN hY5oMrDEJQWQKKRgjTStlalKD2QwfawItCi8wrY/lvq0mWojHOQuFTBLrYa8jFvmTZAw E+ycyzp8iwKMBFJ+9Wd6QYCuCfQVr81uk3eoD9ss01WxIZXlSrN2+0nnFR2i3ASpn5nL SfOg4a0SWYtThX1hV7WAaAKobSip6tUryg2IBZWstcnJhqtBEJYHEFt1Kl7b3+RPBFXN yM7kvREjB5HKH3GBydqcjIW3Xvnul7YSu1HsI5PnWKRxIzsn0AiPPSuo0IQdcP9AwjnI q3Sg== 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=kWd+Z+MsF18qgbZiQLBWMWpmPsmRIT4kw65JjXvGdqI=; b=MuIHQ4X3zvz0ZgtS5MHT0tbf6e8hJwG7k8qtq65un4wEXUul4Jays3oHu0X8q5Zd3Q iGWTxrwhcG0GxUajHjNpjrEVY9wv1xYPd4Df0xft5HINAmNlGTKGcecy9ljBQy9H+ENG CJwYbDVEeei0rQ1shCeFwyEYnuLkuGN67TLOmWhCzXeHnFkVExGzBo/FuqN8CgB+1O+q LR3zocltc+peWscvJAl+XOshSkNUa5XKiHjGZQY3v4dTKK3q7ptM4zte9cubtkzTSYUo 3Eky55uOlxECgRgp/sjEd6tBiUJeRdzUhjq2xct+cyKi8NWEYhmJKcZ+lxWtLIabrsS1 d6bA== X-Gm-Message-State: APjAAAX7oyId5g5PJVANdOEOadFzGwiSO3fV92efjCWln4IqrwoWiDiP eHSS+sGdfqRsUHDULOCGjPY= X-Google-Smtp-Source: APXvYqxFqZaTbj7c5HYJQlJXAiTVKG/K74wYZnkVr5RD2TpVtYRlAERvwQ4MQFTfGWYlqe1886Advw== X-Received: by 2002:a05:600c:2406:: with SMTP id 6mr3741363wmp.30.1579709057219; Wed, 22 Jan 2020 08:04:17 -0800 (PST) Received: from localhost ([185.85.220.193]) by smtp.gmail.com with ESMTPSA id y22sm4471725wma.35.2020.01.22.08.04.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jan 2020 08:04:16 -0800 (PST) Date: Wed, 22 Jan 2020 17:04:41 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Floris Van Nee Cc: Peter Geoghegan , Jesper Pedersen , David Rowley , Tomas Vondra , Kyotaro Horiguchi , Alvaro Herrera , Thomas Munro , James Coleman , Rafia Sabih , Jeff Janes , Bhushan Uparkar , PostgreSQL-development , Alexander Korotkov Subject: Re: Index Skip Scan Message-ID: <20200122160441.ograupmzyytde2mi@localhost> References: <1e59d800b38141c5af2ad3a64cf9758e@opammb0562.comp.optiver.com> <802e46fa-dc2c-4c32-e55b-884e04aa7f12@redhat.com> <20200121160942.eu4bvbu46nt223ug@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 Wed, Jan 22, 2020 at 07:50:30AM +0000, Floris Van Nee wrote: > > Anyone please correct me if I'm wrong, but I think one case where the current patch relies on some data from the page it has locked before it in checking this hi/lo key. I think it's possible for the following sequence to happen. Suppose we have a very simple one leaf-page btree containing four elements: leaf page 1 = [2,4,6,8] > We do a backwards index skip scan on this and have just returned our first tuple (8). The buffer is left pinned but unlocked. Now, someone else comes in and inserts a tuple (value 5) into this page, but suppose the page happens to be full. So a page split occurs. As far as I know, a page split could happen at any random element in the page. One of the situations we could be left with is: > Leaf page 1 = [2,4] > Leaf page 2 = [5,6,8] > However, our scan is still pointing to leaf page 1. In case if we just returned a tuple, the next action would be either check the next page for another key or search down to the tree. Maybe I'm missing something in your scenario, but the latter will land us on a required page (we do not point to any leaf here), and before the former there is a check for high/low key. Is there anything else missing? > Now that I look at the patch again, I fear there currently may also be such a dependency in the "Advance forward but read backward"-case. It saves the offset number of a tuple in a variable, then does a _bt_search (releasing the lock and pin on the page). At this point, anything can happen to the tuples on this page - the page may be compacted by vacuum such that the offset number you have in your variable does not match the actual offset number of the tuple on the page anymore. Then, at the check for (nextOffset == startOffset) later, there's a possibility the offsets are different even though they relate to the same tuple. Interesting point. The original idea here was to check that we're not returned to the same position after jumping, so maybe instead of offsets we can check a tuple we found.