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 1hfOe0-00082O-So for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2019 13:04:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfOdz-0006Iu-N4 for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2019 13:04:23 +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 ) id 1hfOdz-0006I1-EB for pgsql-hackers@lists.postgresql.org; Mon, 24 Jun 2019 13:04:23 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfOds-0007Ao-C1 for pgsql-hackers@postgresql.org; Mon, 24 Jun 2019 13:04:23 +0000 Received: by mail-wr1-x435.google.com with SMTP id n4so13783844wrw.13 for ; Mon, 24 Jun 2019 06:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/AdFfap/EnmQvo1OeO7e0UQCzCOuePOWfmRp1KIalPE=; b=hdsTA1OojqgOrk8JVKSoOG1FIu2cBO/8tfle9aA0RvgsUUd9kGoYloeUPjwMzRvkSR vgq+uFnm6GUjZH5pQJSEWeOiRMWQec+ytwKYch4p5X6cg0z+/7X0y8waqHOwjHSPdQyZ TuTCQG8878wgDpIuHO0AlyLl/wCM+22rcY3JrH9TEHlFWYIzbkKt79zhREoulRNjihNb O5caCO+yzgW4JUbu5Z6PXJAiazqWGKv02Ski4g0zF9CFf1ep/sJtc7AiLVhGU7xvcxok 0kQM4yCvipjDRTmDXJkRPtIVUjq3bg5cHVz/hHWDU7RYm2oFmVxn05ZTmatPEJwSr28l vRBQ== 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:user-agent; bh=/AdFfap/EnmQvo1OeO7e0UQCzCOuePOWfmRp1KIalPE=; b=t/W/X1BPyaA/w3vSS2ADROe5MB5v0Lihp5weXUbk6PArKhg6AMaSNY0zjL3UmlYGhF vvJC+DMJsj1DXbUMZVLm2pdFhChYMQ6o3+NT6TUtmsfqVedt0gaaifzC0vYu6aW3T4ip +x4AB82LHShiXkagEx5MrkWBIWOBaB3zM1ZjIVmsNqjWlz2W/zqOCEqPtnvO2MhLQh4k NNK2qHoay7bJhCXNACXwXokM46IdOzfvhqwRY07QCIHuTgt4P5Gm7rsW9OEnvLCS3++N SoE3hVcl+tSIUCHfJL1ghUe0rpWxlAp79Bt6eWcY7RgQUCb4PkosbB5rSvYhQncv2vVW V1iQ== X-Gm-Message-State: APjAAAUqsZ6wRncs1+Zev/6fPxooC1/NTbpm5z6FiXYDTEkzl/Kj8SzM P1LtsdU+oNt3moTx4Wl7E91AnA== X-Google-Smtp-Source: APXvYqwqLSLy0zyyPcbsjVP8XtYD3Wy3G0nTaBgMlVYO7OeMKVQ2ZNmfjEo7BmUHeNHvQKTiN49O1A== X-Received: by 2002:adf:fc45:: with SMTP id e5mr2683948wrs.240.1561381454912; Mon, 24 Jun 2019 06:04:14 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id g5sm9906362wrp.29.2019.06.24.06.04.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 06:04:13 -0700 (PDT) Date: Mon, 24 Jun 2019 15:04:10 +0200 From: Tomas Vondra To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: Floris Van Nee , David Rowley , Jesper Pedersen , Rafia Sabih , Jeff Janes , Thomas Munro , Alexander Kuzmenkov , Peter Geoghegan , Thomas Munro , Bhushan Uparkar , PostgreSQL-development , Alexander Korotkov , James Coleman Subject: Re: Index Skip Scan Message-ID: <20190624130410.rhor2lcffdvrh7ka@development> References: <988b7763-5c55-1be1-b7b6-f3a68eff0d40@redhat.com> <1559763453006.85615@Optiver.com> <1559763570329.85227@Optiver.com> <4d469bf2-49ff-bc3d-a428-6c7b5d87d526@redhat.com> <20190623131031.65zmz2m4waew6paa@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967-dirty List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Jun 24, 2019 at 01:44:14PM +0200, Dmitry Dolgov wrote: >> On Sun, Jun 23, 2019 at 1:04 PM Floris Van Nee wrote: >> >> However, _bt_readpage messes things up, because it only reads tuples that >> match all the provided keys (so where b=2) > >Right, the problem you've reported first had a similar origins. I'm starting to >think that probably using _bt_readpage just like that is not exactly right >thing to do, since the correct element is already found and there is no need to >check if tuples are matching after one step back. I'll try to avoid it in the >next version of patch. > >> I was wondering about something else: don't we also have another problem with >> updating this current index tuple by skipping before calling >> btgettuple/_bt_next? I see there's some code in btgettuple to kill dead tuples >> when scan->kill_prior_tuple is true. I'm not too familiar with the concept of >> killing dead tuples while doing index scans, but by looking at the code it >> seems to be possible that btgettuple returns a tuple, caller processes it and >> sets kill_prior_tuple to true in order to have it killed. However, then the >> skip scan kicks in, which sets the current tuple to a completely different >> tuple. Then, on the next call of btgettuple, the wrong tuple gets killed. Is my >> reasoning correct here or am I missing something? > >Need to check, but probably we can avoid that by setting kill_prior_tuple to >false in case of skip scan as in index_rescan. > >> On Sun, Jun 23, 2019 at 3:10 PM Tomas Vondra wrote: >> >> I've done some initial review on v20 - just reading through the code, no >> tests at this point. Here are my comments: > >Thank you! > >> 2) indices.sgml >> >> The new section is somewhat unclear and difficult to understand, I think >> it'd deserve a rewording. Also, I wonder if we really should link to the >> wiki page about FSM problems. We have a couple of wiki links in the sgml >> docs, but those seem more generic while this seems as a development page >> that might disapper. But more importantly, that wiki page does not say >> anything about "Loose Index scans" so is it even the right wiki page? > >Wow, indeed, looks like it's a totally wrong reference. I think Kyotaro already >mentioned it too, so probably I'm going to remove it (and instead describe the >idea in a few words in the documentation itself). > >> 6) nodeIndexScan.c >> >> I wonder why we even add and initialize the ioss_ fields for IndexScan >> nodes, when the skip scans require index-only scans? > >Skip scans required index-only scans until recently, when the patch was updated >to incorporate the same approach for index scans too. My apologies, looks like >documentation and some commentaries are still inconsistent about this topic. > Yes, if that's the case then various bits of docs and comments are rather misleading, ant fields in IndexScanState should be named 'iss_'. >> 7) pathnode.c >> >> I wonder how much was the costing discussed. It seems to me the logic is >> fairly similar to ideas discussed in the incremental sort patch, and >> we've been discussing some weak points there. I'm not sure how much we >> need to consider those issues here. > >Can you please elaborate in a few words, which issues do you mean? Is it about >non uniform distribution of distinct values? If so, I believe it's partially >addressed when we have to skip too often, by searching a next index page. >Although yeah, there is still an assumption about uniform distribution of >distinct groups at the planning time. > Right, it's mostly about what happens when the group sizes are not close to average size. The question is what happens in such cases - how much slower will the plan be, compared to "current" plan without a skip scan? I don't have a very good idea of the additional overhead associated with skip-scans - presumably it's a bit more expensive, right? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services