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 1iRIz1-0000T6-Kw for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Nov 2019 16:44:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iRIyy-0006my-7K for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Nov 2019 16:44:04 +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 1iRIyx-0006mq-PY for pgsql-hackers@lists.postgresql.org; Sun, 03 Nov 2019 16:44:04 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1iRIyq-0005aI-QZ for pgsql-hackers@postgresql.org; Sun, 03 Nov 2019 16:44:02 +0000 Received: by mail-wr1-x441.google.com with SMTP id p4so14396579wrm.8 for ; Sun, 03 Nov 2019 08:43:56 -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=y2Cl8C5+TWDg5IQlSpQEmagrThiXQgyEujez+TeJicI=; b=ZfhftkAMEjbYaBdYoQiTpn2m6GsWLd0EIMlYFs4ULV/EfiO+4Wye8TTLd9Dm/ZU5En 0Mz1qJJMy2rmK5LHyz/uQhe0e3D6J91VlTN/TzpvtSH3VJENAtxkEuPEwabW9wWsCauv oF7rV9xiAfZAt1Ls6YraSYCLgF2Bd/6e1HtPs9eoNZ3y+7EmM2/exOGpFZy7+2muuCXY +P0s+tF4L81BTY2GivbQdCAZQhy/zSC4vN/sC1fxQMdVIzyjoJvJE525U6Mp0xxA5cQP mWFQgmVqSIZIat9zq5g9JVJ2f8AM1quX+uOTIE1CpCA4GwZ1Vd8oKF36d+BKDVBsaoRb CHkw== 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=y2Cl8C5+TWDg5IQlSpQEmagrThiXQgyEujez+TeJicI=; b=QNYuN+TkavniaGaw9cj5cdOogl8OBdNTb+xAHcOnkOxEkcun9t+sWkS4kDq+FYO3k8 vgtjN3zadsoTjVfxZK40fgBT1LNOp1KegUu7zDGOYoRYpXYljzBNMboc4O9l80QstFPb PibDW3AQXGCH/EoeRfBpM6a2ZSmuoL4t7PTYWKJY92twZm4RhxFOM7pG7zhcGM9+Jarn 3jEiWzBsC7Ddr/0S08K8G3lkSCyp5OaC/5ztFprxsohnAKE6mR2TRY8XjR1+xol9nMJI P+f6Ko7v4xGy7anwzSNkf489E4NLqbLYGKFvrvv2hyPqovrc7Dt5NPbZaR3hgjEisIwN uA8g== X-Gm-Message-State: APjAAAWkK7JnFCkrthNPsXWaVLZ02Ksdis8AimbnS6Tk/UjQGSbiN4Gl i2TyCqyoTrmE+uGwULNPKKE= X-Google-Smtp-Source: APXvYqw40Ric2chvZKc6h0TUTE5GM248pgdF9VHRILRcwbnHHPPYc4bINF3nsYUjzcn/A6P4lYo8qQ== X-Received: by 2002:adf:dc06:: with SMTP id t6mr2201609wri.378.1572799435162; Sun, 03 Nov 2019 08:43:55 -0800 (PST) Received: from localhost (dslb-188-103-189-084.188.103.pools.vodafone-ip.de. [188.103.189.84]) by smtp.gmail.com with ESMTPSA id j19sm18609433wre.0.2019.11.03.08.43.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Nov 2019 08:43:54 -0800 (PST) Date: Sun, 3 Nov 2019 17:45:47 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Peter Geoghegan Cc: Kyotaro Horiguchi , Alvaro Herrera , Floris Van Nee , Jesper Pedersen , David Rowley , Thomas Munro , James Coleman , Rafia Sabih , Jeff Janes , Tomas Vondra , Bhushan Uparkar , PostgreSQL-development , Alexander Korotkov Subject: Re: Index Skip Scan Message-ID: <20191103164547.oqcvno6467eikizg@localhost> References: <20190924.174146.159197618.horikyota.ntt@gmail.com> <20190924120627.GA12454@alvherre.pgsql> <20190925.100301.198068449.horikyota.ntt@gmail.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 Wed, Sep 25, 2019 at 2:33 AM Dmitry Dolgov <9erthalion6@gmail.com> wrote: > v27-0001-Index-skip-scan.patch > > Some random thoughts on this: Thanks a lot for the commentaries! > * Is _bt_scankey_within_page() really doing the right thing within empty pages? > > It looks like you're accidentally using the high key when the leaf > page is empty with forward scans (assuming that the leaf page isn't > rightmost). You'll need to think about empty pages for both forward > and backward direction scans there. Yes, you're right, that's an issue I need to fix. > Actually, using the high key in some cases may be desirable, once the > details are worked out -- the high key is actually very helpful with > low cardinality indexes. If you populate an index with retail > insertions (i.e. don't just do a CREATE INDEX after the table is > populated), and use low cardinality data in the indexed columns then > you'll see this effect. Can you please elaborate a bit more? I see that using high key will help a forward index scans to access the minimum number of leaf pages, but I'm not following how is it connected to the _bt_scankey_within_page? Or is this commentary related in general to the whole implementation? > * The extra scankeys that you are using in most of the new nbtsearch.c > code is an insertion scankey -- not a search style scankey. I think > that you should try to be a bit clearer on that distinction in > comments. It is already confusing now, but at least there is only zero > or one insertion scankeys per scan (for the initial positioning). > > * There are two _bt_skip() prototypes in nbtree.h (actually, there is > a btskip() and a _bt_skip()). I understand that the former is a public > wrapper of the latter, but I find the naming a little bit confusing. > Maybe rename _bt_skip() to something that is a little bit more > suggestive of its purpose. > > * Suggest running pgindent on the patch. Sure, I'll incorporate mentioned improvements into the next patch version (hopefully soon). > And now some more: > > * I'm confused about this code in _bt_skip(): > Yeah, it shouldn't be there, but rather before _bt_next, that expects unlocked buffer. Will fix. > * It also seems a bit odd that you assume that the scan is > "scan->xs_want_itup", but then check that condition many times. Why > bother? > > * Similarly, why bother using _bt_drop_lock_and_maybe_pin() at all, > rather than just unlocking the buffer directly? We'll only drop the > pin for a scan that is "!scan->xs_want_itup", which is never the case > within _bt_skip(). > > I think that the macros and stuff that manage pins and buffer locks in > nbtsearch.c is kind of a disaster anyway [1]. Maybe there is some > value in trying to be consistent with existing nbtsearch.c code in > ways that aren't strictly necessary. Yep, I've seen this thread, but tried to be consistent with the surrounding core style. Probably it indeed doesn't make sense. > * Not sure why you need this code after throwing an error: > > > else > > { > > elog(ERROR, "Could not read closest index tuples: %d", offnum); > > pfree(so->skipScanKey); > > so->skipScanKey = NULL; > > return false; > > } Unfortunately this is just a leftover from a previous version. Sorry for that, will get rid of it.