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 1qOsOL-009HDk-EJ for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 04:14:21 +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 1qOsOI-007nvH-Ch for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 04:14:18 +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 1qOsOH-007nv8-Vm for pgsql-hackers@lists.postgresql.org; Thu, 27 Jul 2023 04:14:18 +0000 Received: from mail-vk1-xa29.google.com ([2607:f8b0:4864:20::a29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qOsOE-001n6a-V5 for pgsql-hackers@lists.postgresql.org; Thu, 27 Jul 2023 04:14:16 +0000 Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-4864a9faf90so328015e0c.0 for ; Wed, 26 Jul 2023 21:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20221208.gappssmtp.com; s=20221208; t=1690431253; x=1691036053; 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=eCNzmlWPVAfZk1IUfOnvPHhbB5jEzn4EZANaM7RT1Dc=; b=lDTKTR/8zib7czbek5BQkCfCKjk9c0xLE43WtoD/h1JON+UFCshQnIgwCcG5VfFDVR /ez6XRpPyd1pLA7l1tji2VItuMz8GTvnvHdJfUwr/MTs0dW4ajoE9egTZasiwgmU+go6 dzT8TvFnPMeL0fqpF9wx1aROSjBrV5z56wss0KYnMWXKH//TK8qU8mGJs9HMnXbjHKO5 wGrKZdOP5vJISSduVtvog4ZQA1DNqRaR0u48J0CUrADMiIxdUoVlMcRmg4E2SDDboaYd xuGKYRU98x9+bqLoEg5xEEvBrTz7wI3gfWlWm4beDuDjWTM6+XDI0gEZRzJhdqVTofUW vXRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690431253; x=1691036053; 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=eCNzmlWPVAfZk1IUfOnvPHhbB5jEzn4EZANaM7RT1Dc=; b=dmUlWTDXyxnllBxdVFDtsJf4b7nY8VW0qG/SYMJq9PhQqCOtA7iCcxg7KlpZAamya2 EDOx6L8r1rdhWjnHUWe0K/zW7BQ3aFAu3/HgoudimuVyK0slYeO8rLsrczytyzNiFtro 4JhbJPEf7I0tuRCSTqpKY0SUdscD9+xMXZrf8CnfyM+whjx9nyEyv7KWVEIETOl2Nuvz aLTgGbs2JDhx0hNMCwZvDOqHAyjQTCDNCGlvjeBjY5llB/vXgXNioIbUV7NLBkeN/oHe cwmVzd6oOBw7K2KcoRij3Sx848yJpmTcxwwoUlgHjL0xWHNH9ZSdwAJexjX1e/x9auFI jaSA== X-Gm-Message-State: ABy/qLY/1y5FItJoAxl6a+QaP/iHIw4ZMKQWAzyhA+HWBDzehz7b+15u hJISoxymbvCKHsOj2I5qaAoVVq1NW77/I2G1CFAsAA== X-Google-Smtp-Source: APBJJlE1u4cQJW8CdmhDfeLPg3qnDbiGztsfwZIYCsHZdaH0w7gSGF94KqgAzOfX7F08UCMIK5tfsndN4olmZXaHmnM= X-Received: by 2002:a1f:bf0a:0:b0:481:4505:9fe1 with SMTP id p10-20020a1fbf0a000000b0048145059fe1mr306275vkf.5.1690431253451; Wed, 26 Jul 2023 21:14:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Geoghegan Date: Thu, 27 Jul 2023 00:13:47 -0400 Message-ID: Subject: Re: Optimizing nbtree ScalarArrayOp execution, allowing multi-column ordered scans, skip scan To: Matthias van de Meent 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, Jul 26, 2023 at 12:07=E2=80=AFPM Matthias van de Meent wrote: > We could cache the last accessed leaf page across amrescan operations > to reduce the number of index traversals needed when the join key of > the left side is highly (but not necessarily strictly) correllated. That sounds like block nested loop join. It's possible that that could reuse some infrastructure from this patch, but I'm not sure. In general, SAOP execution/MDAM performs "duplicate elimination before it reads the data" by sorting and deduplicating the arrays up front. While my patch sometimes elides a primitive index scan, primitive index scans are already disjuncts that are combined to create what can be considered one big index scan (that's how the planner and executor think of them). The patch takes that one step further by recognizing that it could quite literally be one big index scan in some cases (or fewer, larger scans, at least). It's a natural incremental improvement, as opposed to inventing a new kind of index scan. If anything the patch makes SAOP execution more similar to traditional index scans, especially when costing them. Like InnoDB style loose index scan (for DISTINCT and GROUP BY optimization), block nested loop join would require inventing a new type of index scan. Both of these other two optimizations involve the use of semantic information that spans multiple levels of abstraction. Loose scan requires duplicate elimination (that's the whole point), while IIUC block nested loop join needs to "simulate multiple inner index scans" by deliberately returning duplicates for each would-be inner index scan. These are specialized things. To be clear, I think that all of these ideas are reasonable. I just find it useful to classify these sorts of techniques according to whether or not the index AM API would have to change or not, and the general nature of any required changes. MDAM can do a lot of cool things without requiring any revisions to the index AM API, which should allow it to play nice with everything else (index path clause safety issues notwithstanding). --=20 Peter Geoghegan