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 1jyZdw-00035E-Pz for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Jul 2020 11:44:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jyZdv-0001EI-JB for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Jul 2020 11:44:07 +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 ) id 1jyZdv-0001EA-Bo for pgsql-hackers@lists.postgresql.org; Thu, 23 Jul 2020 11:44:07 +0000 Received: from smtp03.optiver.com ([195.246.114.70]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jyZds-0003Za-9i for pgsql-hackers@postgresql.org; Thu, 23 Jul 2020 11:44:06 +0000 Received: from pps.filterd (smtp03.optiver.com [127.0.0.1]) by smtp03.optiver.com (8.16.0.27/8.16.0.27) with SMTP id 06NBgTKc004500; Thu, 23 Jul 2020 13:43:57 +0200 Received: from opammb0561.comp.optiver.com (opammb0561.comp.optiver.com [10.131.160.1]) by smtp03.optiver.com with ESMTP id 32bpp4jjq3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 23 Jul 2020 13:43:56 +0200 Received: from opammb0561.comp.optiver.com (10.131.160.1) by opammb0561.comp.optiver.com (10.131.160.1) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 23 Jul 2020 13:43:56 +0200 Received: from opammb0561.comp.optiver.com ([fe80::78c7:ae96:9b5c:c00]) by opammb0561.comp.optiver.com ([fe80::78c7:ae96:9b5c:c00%17]) with mapi id 15.00.1497.006; Thu, 23 Jul 2020 13:43:56 +0200 From: Floris Van Nee To: Dmitry Dolgov <9erthalion6@gmail.com> CC: Andy Fan , PostgreSQL-development , Jesper Pedersen , David Rowley , Kyotaro Horiguchi , Peter Geoghegan , Thomas Munro , Tomas Vondra , "Dilip Kumar" Thread-Topic: Index Skip Scan (new UniqueKeys) [External] Thread-Index: AQHWPkejvFmf8VE85UaktavhwXWuBqjS8neAgByLE4CAEbyf4IABZkuAgAFvkyCAA0bPAIAAK8DAgA2NqYCAACIEEA== Date: Thu, 23 Jul 2020 11:43:56 +0000 Message-ID: <8a483a1889b24e888f6cf37bc5baea85@opammb0561.comp.optiver.com> References: <20200609102247.jdlatmfyeecg52fi@localhost> <20200629120709.52w2zi36mtzyliv2@localhost> <20200711162103.hiygat3k6wu2d25p@localhost> <20200714161852.s27ikts2dppvbm3h@localhost> <536657c24bcf49eb8215e84969f2b345@opammb0561.comp.optiver.com> <20200723095351.dbboo3fymuzwqmic@localhost> In-Reply-To: <20200723095351.dbboo3fymuzwqmic@localhost> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.131.160.182] x-tm-as-product-ver: SMEX-14.0.0.1158-8.6.1012-25558.006 x-tm-as-result: No-10--19.972100-8.000000 x-tmase-matchedrid: cxtZ8fwm3r/uo96mfIBuopzEHTUOuMX33dCmvEa6IiFJkYDIfDuRnyj5 3aEB5qDLYAO+QGS70TMk2oy24OAgMipv7EKjMQSgdPM8veyrICaMhbTsXysU3/yQXCBzKijhJeL xnuELHSiuvEVtJ+Mbfcc23EbFTAfH12qgs2XkJdtJUdgxNDUXWm2mQLk3s605GJYskYnAVDSksV VD6rDnVFYLdmb6QZh1tFfNhIkO4XV6hPyCGn1Pv7b55TietSt6TsTCHtXv0PpaS+dwPO2iW28d5 tamToAglJpVNDZMVXJqNoAd4och+2uhJ+H9aO0k6fUfELqFUH9QdXu/xf76ufAlhlr8vzcd6Zam opeZkvnYBxmFXm5d5lNR41fsCgiuc7eLMCSXxGEGLRKL2NexjZTb3PKAwoR/T7zqZowzdpJkVnj 7rBUGjEXp/YJegAVVYXf7R5V86KVYwMQSR3qB3QD9gX5aXd4feLycN/G5ABOGToisPp3j9bgZ+7 EzWJ94e3PLKWQxN5X5odUxplNHlkT9KnQ8PcbHfid4LSHtIAP3w54cD0H0R3ekRURO7ynxD+A3v N265hcObBGS8B/Z3l+24nCsUSFNt7DW3B48kkHdB/CxWTRRuyUIayx+Skid x-tm-as-user-approved-sender: Yes x-tm-as-user-blocked-sender: No x-tmase-result: 10--19.972100-8.000000 x-tmase-version: SMEX-14.0.0.1158-8.6.1012-25558.006 x-tm-snts-smtp: BE94169990853ECC5D1285BCE73B1F9EF105FFEB2BFC2530DF6EA63BADB95A592000:8 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: Index Skip Scan (new UniqueKeys) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-23_03:2020-07-23,2020-07-23 signatures=0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >=20 > One UniqueKey can have multiple corresponding expressions, which gives us > also possibility of having one unique key with (t1.a, t2.a) and it looks = now > similar to EquivalenceClass. >=20 I believe the current definition of a unique key with two expressions (t1.a= , t2.a) means that it's unique on the tuple (t1.a, t2.a) - this gives weake= r guarantees than uniqueness on (t1.a) and uniqueness on (t2.a). >=20 > The idea behind this query sounds questionable to me, more transparent > would be to do this without distinct, skipping will actually do exactly t= he same > stuff just under another name. But if allowing skipping on constants do n= ot > bring significant changes in the code probably it's fine. >=20 Yeah indeed, I didn't say it's a query that people should generally write. = :-) It's better to write as a regular SELECT with LIMIT 1 of course. Howeve= r, it's more to be consistent and predictable to the user: if a SELECT DIST= INCT ON (a) * FROM t1 runs fast, then it doesn't make sense to the user if = a SELECT DISTINCT ON (a) * FROM t1 WHERE a=3D2 runs slow. And to support it= also makes the implementation more consistent with little code changes. > > > > Yeah, there's definitely some double work there, but the actual impact = may > be limited - it doesn't actually allocate a new path key, but it looks it= up in > root->canon_pathkeys and returns that path key. > > I wrote it like this, because I couldn't find a way to identify from a = certain > PathKey the actual location in the index of that column. The constructed = path > keys list filters out all redundant path keys. An index on (a,a,b,a,b) be= comes > path keys (a,b). Now if we skip on (a,b) we actually need to use prefix= =3D3. But > how to get from PathKey=3Db to that number 3, I didn't find a solid way e= xcept > doing this. Maybe there is though? >=20 > I don't think there is a direct way, but why not modify build_index_paths= to > also provide this information, or compare index_pathkeys expressions with > indextlist without actually create those pathkeys again? >=20 I agree there could be other ways - I don't currently have a strong prefere= nce for either. I can have a look at this later. > And couple of words about this thread [1]. It looks to me like a strange = way > of interacting with the community. Are you going to duplicate there > everything, or what are your plans? At the very least you could try to in= clude > everyone involved in the recipients list, not exclude some of the authors= . >=20 When I wrote the first mail in the thread, I went to this thread [1] and in= cluded everyone from there, but I see now that I only included the to: and = cc: people and forgot the original thread author, you. I'm sorry about that= - I should've looked better to make sure I had everyone. In any case, my plan is to keep the patch at least applicable to master, as= I believe it can be helpful for discussions about both patches. [1] https://www.postgresql.org/message-id/20200609102247.jdlatmfyeecg52fi%4= 0localhost