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 1qOzeY-009fQn-0c for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 11:59:33 +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 1qOzeV-009o4U-1z for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 11:59:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qOzeU-009o4M-ME for pgsql-hackers@lists.postgresql.org; Thu, 27 Jul 2023 11:59:30 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qOzeR-000gkj-PK for pgsql-hackers@lists.postgresql.org; Thu, 27 Jul 2023 11:59:30 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-267f870e6ffso519268a91.0 for ; Thu, 27 Jul 2023 04:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690459165; x=1691063965; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0XkNR5c84Ie5vp9fNHy64h/0//YXgkhCHZEDcQUThAg=; b=JK/FSIy2RCwpP+ko875kbeY+KrltKuOdiq3LiCxmJkupHfu7KTc/tmrakgcQi+c0SV 4yTIcXTvOBneGRYZxF9ovh7C5SuQEC8K0CBqtBVwf8x4PAa7mIX/KEqi3cahc6agrccu sPI+DbJ63FoA6HvjYZ7Is2NKlAdWCNhF4ObCRp6VYL51tREsXKjFJafQwSr9+3yRsn94 bG8ExNi0u4TKnGlp+sAo0qBgbRKQ+SAZVPcyd/mKdTb9WSffPlNCNRdcOgmFifTHOi+/ NwZyCivE1HhyL66rzneorkAbDUBCidBbDhkREkoqRS80RGPtWu1jaPy0M133lpcsZsw0 8YwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690459165; x=1691063965; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0XkNR5c84Ie5vp9fNHy64h/0//YXgkhCHZEDcQUThAg=; b=Q3y/4yo2eIGCTFLDBNiAsK4flfcfK3OSyz3IqiEyNpC9e1xI87hEcPsbARqm0DIhEv e7zESvaaP+WsabsWKHtqfpBvpr8HHXXXId/ZOJ2nwy31y+u6GdXr6BxqeC23Yied/Xdg Z/gjcBmYmzIkR6Kx3bILCw1oWe/iMQ6VOheiv5Idg05QtkbQIXtP3+x+h8l1PSSYmi51 Faj8/EZZxhx7A0lvV9uqPcVtJEnNJWKCu856lt+4MfxjsLhqp1hYA5OQKk7QZ9yB1smX wPm55r+2D/niV8l5saOzIQlrp92ubtqLdH8/2A4fyoqZOblkMqIU2RwIK69jAoIy8sP5 UFuw== X-Gm-Message-State: ABy/qLYYfWYZ2IjLnwfVZCmRQuUE9F8YWXy1r/AJdpkyNJIukJ2onwZj wqcjgNSyfYmjjIKG6VnIsKOb74TYV3SDB1cboOk= X-Google-Smtp-Source: APBJJlHPR6B30IIKrxFzTdRs7O8X0rHkpZ1kn7Q1U04+Gk/tBbqVum1yyKs7YS9zWmHoQfHHpODDBt45ioAHIhZAjTw= X-Received: by 2002:a17:90a:c9:b0:268:ee6:6bdf with SMTP id v9-20020a17090a00c900b002680ee66bdfmr3883873pjd.47.1690459165097; Thu, 27 Jul 2023 04:59:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Matthias van de Meent Date: Thu, 27 Jul 2023 13:59:13 +0200 Message-ID: Subject: Re: Optimizing nbtree ScalarArrayOp execution, allowing multi-column ordered scans, skip scan To: Peter Geoghegan Cc: PostgreSQL Hackers , Tom Lane , Tomas Vondra , Jeff Davis , benoit Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 26 Jul 2023 at 15:42, Peter Geoghegan wrote: > > On Wed, Jul 26, 2023 at 5:29=E2=80=AFAM Matthias van de Meent > > I'm not sure I understand. MDAM seems to work on an index level to > > return full ranges of values, while "skip scan" seems to try to allow > > systems to signal to the index to skip to some other index condition > > based on arbitrary cutoffs. This would usually be those of which the > > information is not stored in the index, such as "SELECT user_id FROM > > orders GROUP BY user_id HAVING COUNT(*) > 10", where the scan would go > > though the user_id index and skip to the next user_id value when it > > gets enough rows of a matching result (where "enough" is determined > > above the index AM's plan node, or otherwise is impossible to > > determine with only the scan key info in the index AM). I'm not sure > > how this could work without specifically adding skip scan-related > > index AM functionality, and I don't see how it fits in with this > > MDAM/SAOP system. > > I think of that as being quite a different thing. > > Basically, the patch that added that feature had to revise the index > AM API, in order to support a mode of operation where scans return > groupings rather than tuples. Whereas this patch requires none of > that. It makes affected index scans as similar as possible to > conventional index scans. Hmm, yes. I see now where my confusion started. You called it out in your first paragraph of the original mail, too, but that didn't help me then: The wiki does not distinguish "Index Skip Scans" and "Loose Index Scans", but these are not the same. In the one page on "Loose indexscan", it refers to MySQL's "loose index scan" documentation, which does handle groupings, and this was targeted with the previous, mislabeled, "Index skipscan" patchset. However, crucially, it also refers to other databases' Index Skip Scan documentation, which document and implement this approach of 'skipping to the next potential key range to get efficient non-prefix qual results', giving me a false impression that those two features are one and the same when they are not. It seems like I'll have to wait a bit longer for the functionality of Loose Index Scans. > > > [...] > > > > > > Thoughts? > > > > MDAM seems to require exponential storage for "scan key operations" > > for conditions on N columns (to be precise, the product of the number > > of distinct conditions on each column); e.g. an index on mytable > > (a,b,c,d,e,f,g,h) with conditions "a IN (1, 2) AND b IN (1, 2) AND ... > > AND h IN (1, 2)" would require 2^8 entries. > > Note that I haven't actually changed anything about the way that the > state machine generates new sets of single value predicates -- it's > still just cycling through each distinct set of array keys in the > patch. > > What you describe is a problem in theory, but I doubt that it's a > problem in practice. You don't actually have to materialize the > predicates up-front, or at all. Yes, that's why I asked: The MDAM paper's examples seem to materialize the full predicate up-front, which would require a product of all indexed columns' quals in size, so that materialization has a good chance to get really, really large. But if we're not doing that materialization upfront, then there is no issue with resource consumption (except CPU time, which can likely be improved with other methods) Kind regards, Matthias van de Meent Neon (https://neon.tech/)