Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6FB8-0009Wl-Bi for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Nov 2023 19:15:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r6FB5-003euh-3T for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Nov 2023 19:15:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6FB4-003euY-Qi for pgsql-hackers@lists.postgresql.org; Thu, 23 Nov 2023 19:15:54 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6FB2-0071Su-Fr for pgsql-hackers@lists.postgresql.org; Thu, 23 Nov 2023 19:15:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3ANJFogL3167406; Thu, 23 Nov 2023 14:15:50 -0500 From: Tom Lane To: Peter Geoghegan cc: Matthias van de Meent , PostgreSQL Hackers Subject: Re: Questions regarding Index AMs and natural ordering In-reply-to: References: Comments: In-reply-to Peter Geoghegan message dated "Thu, 23 Nov 2023 10:51:51 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3167404.1700766950.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 23 Nov 2023 14:15:50 -0500 Message-ID: <3167405.1700766950@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Geoghegan writes: > On Thu, Nov 23, 2023 at 9:16 AM Matthias van de Meent > wrote: >> Is returning index scan results in (reverse) natural order not >> optional but required with amcanorder? If it is required, why is the >> am indicator called 'canorder' instead of 'willorder', 'doesorder' or >> 'isordered'? > I don't know. I have a hard time imagining an index AM that is > amcanorder=true that isn't either nbtree, or something very similar > (so similar that it seems unlikely that anybody would actually go to > the trouble of implementing it from scratch). Agreed on that, but I don't have that hard a time imagining cases where it might be useful for btree not to guarantee ordered output. IIRC, it currently has to do extra pushups to ensure that behavior in ScalarArrayOp cases. We've not bothered to expand the planner infrastructure to distinguish "could, but doesn't" paths for btree scans, but that's more about it not being a priority than because it wouldn't make sense. If we did put work into that, we'd probably generate multiple indexscan Paths for the same index and same index conditions, some of which are marked with sort ordering PathKeys and some of which aren't (and have a flag that would eventually tell the index AM not to bother with sorting at runtime). > The general notion of a data type's sort order comes from its default > btree operator class, so the whole idea of a generic sort order is > deeply tied to the nbtree AM. Right. There hasn't been a reason to decouple that, just as our notions of hashing are tied to the hash AM. This doesn't entirely foreclose other AMs that handle sorted output, but it constrains them to use btree's opclasses to represent the ordering. regards, tom lane