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 1juI57-0005am-24 for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Jul 2020 16:10:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1juI56-0004vl-2U for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Jul 2020 16:10:28 +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 1juI55-0004vc-P6 for pgsql-hackers@lists.postgresql.org; Sat, 11 Jul 2020 16:10:27 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1juI4z-0005C2-B8 for pgsql-hackers@postgresql.org; Sat, 11 Jul 2020 16:10:26 +0000 Received: by mail-ed1-x544.google.com with SMTP id z17so7069151edr.9 for ; Sat, 11 Jul 2020 09:10:20 -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=3TiPo80pKewAQRIWWKDBxHmY/MOHPT5UCrR4Gw6kxw8=; b=J2gwWc58hg+HhnscZTufaD5nnkjaiuuluxUrPg4xVDOrgY9cE7GQxULnUb7tm9N1bJ nkmzjya5xPiFa+8JuTblvW3NIX5tyO0RNUInHWMN6ri4jE/ydJZGOxb3o5rrAlofkzB6 //m7Qn9X7YY27saV+6VrpQT5rE9EPmcCnThkZxbgUKEUfAzZvnhxlnjpuFA8gchdqkr4 AHPKH3OhM+702vmV+704Woxh71zDdAnnLPX0or9z8CV2BHuGr/xph0zWg7GmkU/uQ2Cc EIHQh/NC1tg1Adh3pLZzCREOB39eeMBOpBV94Nnrl/KsNFeHaGd/5TYUSN+buLB2Uv0L SKdg== 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=3TiPo80pKewAQRIWWKDBxHmY/MOHPT5UCrR4Gw6kxw8=; b=I6WNcgJWskyfOKkZVh7BvOxrxNX9SbXO9MLo5rXX40jmv8AV5dngsbVLU45ME8kZOB SnSw02LNQcog5QGV2YQPj4IsoKi61MnoDDdZvU0A4iERX3cNGrkC5yvLqUn+InJFwEcZ zv5WAtGTDIAbmNe0C8b0uEeCP8Sy8gaChI7XwF+7zS+08fYSQtKJn60KUKhgXGSEwsoy 1eVv4tPaeFi4gldTh+RkGcty6MX5dtENC76ZS/wKYX0J7iHBzbEL9AtrhLwmZG5hPWU4 gF0URng3Dq2a3uDfjfaTR2X/9O86tC0LZlPqF9ZY/fgHrk3YHOmpsv2vK4dEK98Yj25V juhw== X-Gm-Message-State: AOAM533tqex9XwgJ+G5xcEBzwJKDebHdjjWXzTfj8f0pXdgmgKs0HkNz t3tX3A5DO/oAVBFh2MzMoz8= X-Google-Smtp-Source: ABdhPJwanagy7UCXt58gawLYkCiyCavzbF8vSivvUtAw//PXcKXbX9516t4REc0CMp8V3/23Tu6n1g== X-Received: by 2002:a05:6402:1777:: with SMTP id da23mr81554911edb.260.1594483819050; Sat, 11 Jul 2020 09:10:19 -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 mj22sm5897627ejb.118.2020.07.11.09.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Jul 2020 09:10:18 -0700 (PDT) Date: Sat, 11 Jul 2020 18:12:58 +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: <20200711161258.5modwkdeszhf55ux@localhost> References: <20200609102247.jdlatmfyeecg52fi@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, Jul 08, 2020 at 03:44:26PM -0700, Peter Geoghegan wrote: > > On Tue, Jun 9, 2020 at 3:20 AM Dmitry Dolgov <9erthalion6@gmail.com> wrote: > > * Btree-implementation contains btree specific code to implement amskip, > > introduced in the previous patch. > > The way that you're dealing with B-Tree tuples here needs to account > for posting list tuples: > > > + currItem = &so->currPos.items[so->currPos.lastItem]; > > + itup = (IndexTuple) (so->currTuples + currItem->tupleOffset); > > + nextOffset = ItemPointerGetOffsetNumber(&itup->t_tid); Do you mean this last part with t_tid, which could also have a tid array in case of posting tuple format? > > + /* > > + * To check if we returned the same tuple, try to find a > > + * startItup on the current page. For that we need to update > > + * scankey to match the whole tuple and set nextkey to return > > + * an exact tuple, not the next one. If the nextOffset is the > > + * same as before, it means we are in the loop, return offnum > > + * to the original position and jump further > > + */ > > Why does it make sense to use the offset number like this? It isn't > stable or reliable. The patch goes on to do this: > > > + startOffset = _bt_binsrch(scan->indexRelation, > > + so->skipScanKey, > > + so->currPos.buf); > > + > > + page = BufferGetPage(so->currPos.buf); > > + maxoff = PageGetMaxOffsetNumber(page); > > + > > + if (nextOffset <= startOffset) > > + { > > Why compare a heap TID's offset number (an offset number for a heap > page) to another offset number for a B-Tree leaf page? They're > fundamentally different things. 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.