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 1itw5r-0003w0-K5 for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jan 2020 16:09:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1itw5o-0006Hb-K7 for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jan 2020 16:09:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from <9erthalion6@gmail.com>) id 1itw5o-0006HN-5k for pgsql-hackers@lists.postgresql.org; Tue, 21 Jan 2020 16:09:28 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1itw5h-0005nz-Er for pgsql-hackers@postgresql.org; Tue, 21 Jan 2020 16:09:27 +0000 Received: by mail-wm1-x332.google.com with SMTP id p17so3735758wma.1 for ; Tue, 21 Jan 2020 08:09:21 -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=7gr4dBmLzXFqqKpxrlvfH2czfgyxsRbFXYRmq5O29iQ=; b=Ex6eedb2ubn2eL0CLtqQibc9B/+4amYvmK1BEEhCS95w9wxxHNHzRxIEagWgmd9oXd YS0c0LLuMz29xE/RvQTD/mw3bK6HF4zho5dSAXjVPp08MgM5UPFpkxsJPab1CKDL6cJ/ KBDbinkBoO7d3WZf8Xmeod6HdgUoe56X6ozsDaeSJ45OT02wtSqPqZVQW6Z7RB8nSLjL EqF2y8WXDMeRsiD/R394zD9/DJ45dr3CKMGAkSR2bLUK1LlrtvKQOidFlhrlCaosCs9V X9Ltniu6QJs9jqebIHHzdRHiqFfDQ1NPKmAXEyq+Fhc7Zl+UMszNxd+OPSZGUTOXYLa3 HZBQ== 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=7gr4dBmLzXFqqKpxrlvfH2czfgyxsRbFXYRmq5O29iQ=; b=tY4+1z7dKkDayWHxpFcnPLrH6+NTLhTPGOBvHpBUyfdjCx8v4kxOCrHPrVVsIDslGL UZ8+cxJ82uFhZZT+hC17bjvG3d7Yry7av5nMYYlxIWTV2W6mIkEzprFEuqD7Rz0wmArD vUQsKUk6710OmaDVwYpvb/6RMLSvPnD/+/ZTwDZZaHkNVBZbrSdiXR3TQ0dGUpefyqoS 3h0cdd2iiWIZKmki8PAHMaUCZ+pcMjm9i21ycl54wOTSqpsQOMPF87lAAzSEFZivYXe0 BACSeiAYngusqwfNkm3Yhsa3WsR1cl1B7ntyIlnRUL2wFBjdJ0i3ZQrjHTHJnR4b4nIu 0OrA== X-Gm-Message-State: APjAAAXXOOzsg3pnnSi4pd4fBdtkQ2hvw6KRWrgdBiv7aH4DgSV1uqcE LnNwrf0dRNv2b0U2XoRGa3Q= X-Google-Smtp-Source: APXvYqw6SUU0ZXyEsFl9UXJvV/ddiQKTzpoiKxgy1w5j0BuLVewS7YmmhFoj4H9/QFJf42Qantoh3A== X-Received: by 2002:a1c:2dcd:: with SMTP id t196mr5007204wmt.22.1579622959172; Tue, 21 Jan 2020 08:09:19 -0800 (PST) Received: from localhost ([185.85.220.193]) by smtp.gmail.com with ESMTPSA id u84sm4726609wmg.10.2020.01.21.08.09.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jan 2020 08:09:18 -0800 (PST) Date: Tue, 21 Jan 2020 17:09:42 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Peter Geoghegan Cc: Jesper Pedersen , Floris Van Nee , 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: <20200121160942.eu4bvbu46nt223ug@localhost> References: <1e59d800b38141c5af2ad3a64cf9758e@opammb0562.comp.optiver.com> <802e46fa-dc2c-4c32-e55b-884e04aa7f12@redhat.com> 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 Mon, Jan 20, 2020 at 01:19:30PM -0800, Peter Geoghegan wrote: Thanks for the commentaries. I'm trying to clarify your conclusions for myself, so couple of questions. > > > - nbtsearch.c in general > > > Most of the code seems to rely quite heavily on the fact that xs_want_itup forces _bt_drop_lock_and_maybe_pin to never release the buffer pin. Have you considered that compacting of a page may still happen even if you hold the pin? [1] I've been trying to come up with cases in which this may break the patch, but I haven't able to produce such a scenario - so it may be fine. > > Try making _bt_findinsertloc() call _bt_vacuum_one_page() whenever the > page is P_HAS_GARBAGE(), regardless of whether or not the page is > about to split. That will still be correct, while having a much better > chance of breaking the patch during stress-testing. > > Relying on a buffer pin to prevent the B-Tree structure itself from > changing in any important way seems likely to be broken already. Even > if it isn't, it sounds fragile. Except for checking low/high key (which should be done with a lock), I believe the current implementation follows the same pattern I see quite often, namely * get a lock on a page of interest and test it's values (if we can find next distinct value right on the next one without goind down the tree). * if not, unlock the current page, search within the tree with _bt_search (which locks a resuling new page) and examine values on a new page, when necessary do _bt_steppage Is there an obvious problem with this approach, when it comes to the page structure modification? > A leaf page doesn't really have anything called a low key. It usually > has a current first "data item"/non-pivot tuple, which is an > inherently unstable thing. Would this inherent instability be resolved for this particular case by having a lock on a page while checking a first data item, or there is something else I need to take into account? > > There is a BT_READ lock in place when finding the correct leaf page, or > > searching within the leaf page itself. _bt_vacuum_one_page deletes only > > LP_DEAD tuples, but those are already ignored in _bt_readpage. Peter, do > > you have some feedback for this ? > > It sounds like the design of the patch relies on doing something other > than stopping a scan "between" pages, in the sense that is outlined in > the commit message of commit 09cb5c0e. If so, then that's a serious > flaw in its design. Could you please elaborate why does it sound like that? If I understand correctly, to stop a scan only "between" pages one need to use only _bt_readpage/_bt_steppage? Other than that there is no magic with scan position in the patch, so I'm not sure if I'm missing something here.