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 1jY6YZ-0000qV-O3 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2020 11:25:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jY6YY-00005d-C2 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2020 11:25:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1jY6YY-00005W-3m for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2020 11:25:10 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1jY6YW-0002mf-7H for pgsql-hackers@postgresql.org; Mon, 11 May 2020 11:25:09 +0000 Received: by mail-wm1-x341.google.com with SMTP id m24so8050173wml.2 for ; Mon, 11 May 2020 04:25:07 -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=zZbMBOewozVPA1JAFRvNa/pYyLK6IEmqTYAKoEO9q54=; b=HvLA52eMRz7rYBsyW2ikf5n0D1xSZpBm5Wqc1oo8HUaXbMdOS/ga1tWAF9n0Q9pyv1 JinZ1Ux1tg2HQ0OqEN//NvIIjaGpNIUYoETyhisCi+inJfYY9FgRRcrSTplEA56jytZf VXVFHFfrPMTUTetEQhCVYWlMCtrshUZHc8v+D/Cxqs4XVrEaZRCAlU/2jnVctUWpVqyF cvbBsSk4aLxySHZJupR4vZwyqjRz3GLrXrHT72nPVqOHaA2aBPPP+Lks20V7zyfj2H6G 3qwyHEgHFJG+GaNhg3gVetiHgoSWoEaKUgN8RBfkJBz6NSDAsjpGUCljh7aIe20kF+/t dBNg== 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=zZbMBOewozVPA1JAFRvNa/pYyLK6IEmqTYAKoEO9q54=; b=HPinALWI05xZX/nlty1CNL9boGbiHE5KyopL9a2TzRxHF/Mch7gG8LgA5p/JByTILg aQkyDh+SFXNgJhWWkNUYAMStm+PV8Wa4WLXBRAnTVIne9LnJFq06bGj0dU/qgMh+MkDa ceTAecT/oo+TKbj+4f9znDKkWvLf/K/1DqyHt+Z+Je+p1I+ngamqnc1yFn8q7yaLphHh HGKCSFc3ZtVJHFK169AOD4AsKUP6vRascHS+itXAZPLsyfLzACpAZX9jud951zUAkccb /f/gP3OXHC6fpcMj7gzX6TrJYYn8X71icxJfy43GVoOiaa6/qEBR7RXeegjtFbBC5TxM 6g6w== X-Gm-Message-State: AGi0PuZriG9JnMK1phy5Pz5/sJ6+6XY6SnRlHJiJ0j24a3/06eR9b9TT ypqmeJCLpgKYACsXmkRKYOw= X-Google-Smtp-Source: APiQypLjfP/lPgdwbi7CrHgBEbgscCnmPdpTaa9UK1Lw5iy6M8J7qjUBkqW4yr2z9QEK6rx2out4Pg== X-Received: by 2002:a7b:c250:: with SMTP id b16mr32521910wmj.100.1589196306710; Mon, 11 May 2020 04:25:06 -0700 (PDT) Received: from localhost (dslb-094-222-004-201.094.222.pools.vodafone-ip.de. [94.222.4.201]) by smtp.gmail.com with ESMTPSA id u16sm17208571wrq.17.2020.05.11.04.25.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2020 04:25:06 -0700 (PDT) Date: Mon, 11 May 2020 13:26:55 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Dilip Kumar Cc: Floris Van Nee , David Rowley , Kyotaro Horiguchi , Tomas Vondra , Peter Geoghegan , Jesper Pedersen , Alvaro Herrera , Thomas Munro , James Coleman , Rafia Sabih , Jeff Janes , "bhushan.uparkar@gmail.com" , PostgreSQL-development , Alexander Korotkov Subject: Re: Index Skip Scan Message-ID: <20200511112655.ijz2sjltzdpif3cn@localhost> References: <20200405161029.fpqqll7xbgfqy5na@localhost> <80ef5f0744f542b18e508fb589a6425a@opammb0562.comp.optiver.com> <20200406163941.rh3okji2rhbnptyt@localhost> <8abe43ac82714c2f9044fb8bac0ebfd0@opammb0562.comp.optiver.com> <20200407194220.edf4nbi7l4cpxk4v@localhost> <20200510174935.teqyazdw6jj6vh47@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 Mon, May 11, 2020 at 04:04:00PM +0530, Dilip Kumar wrote: > > > > +static inline bool > > > +_bt_scankey_within_page(IndexScanDesc scan, BTScanInsert key, > > > + Buffer buf, ScanDirection dir) > > > +{ > > > + OffsetNumber low, high; > > > + Page page = BufferGetPage(buf); > > > + BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page); > > > + > > > + low = P_FIRSTDATAKEY(opaque); > > > + high = PageGetMaxOffsetNumber(page); > > > + > > > + if (unlikely(high < low)) > > > + return false; > > > + > > > + return (_bt_compare(scan->indexRelation, key, page, low) > 0 && > > > + _bt_compare(scan->indexRelation, key, page, high) < 1); > > > +} > > > > > > I think the high key condition should be changed to > > > _bt_compare(scan->indexRelation, key, page, high) < 0 ? Because if > > > prefix qual is equal to the high key then also there is no point in > > > searching on the current page so we can directly skip. > > > > From nbtree/README and comments to functions like _bt_split I've got an > > impression that the high key could be equal to the last item on the leaf > > page, so there is a point in searching. Is that incorrect? > > But IIUC, here we want to decide whether we will get the next key in > the current page or not? In general this function does what it says, it checks wether or not the provided scankey could be found within the page. All the logic about finding a proper next key to fetch is implemented on the call site, and within this function we want to test whatever was passed in. Does it answer the question?