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 1suZhs-007pYf-Uh for pgsql-general@arkaria.postgresql.org; Sat, 28 Sep 2024 15:50:05 +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 1suZhs-009rhB-5V for pgsql-general@arkaria.postgresql.org; Sat, 28 Sep 2024 15:50:04 +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 1suZhr-009rh3-MS for pgsql-general@lists.postgresql.org; Sat, 28 Sep 2024 15:50:03 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1suZhn-001XhE-5p for pgsql-general@postgresql.org; Sat, 28 Sep 2024 15:50:03 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5c5bca59416so3476684a12.1 for ; Sat, 28 Sep 2024 08:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adriangb-com.20230601.gappssmtp.com; s=20230601; t=1727538599; x=1728143399; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=h0SKMKMI45dY7Yo4FbT9sHeANHccvG4fNyyhJ9RkUbo=; b=as7J1i6kIfdjm0PXZG+ieHGA4Y7rJzx4ULlI/Ul2A8Vvt8YPqS896JkJl290nZV47d y8zqaLsFXZqDGCs5mp5QjYq3gANbXiROy1DoEqrw3vKFTuuu2Q3Td8E5GS3DQl1Rqstq l87cvwBe45Y8wKxzeUsqvYnoqyoM+qcgK7ltAIDjIyw9fDhy1gK7VfoAT2pZU/bjAWd4 L4rol8deNj1aXCX5twyyxVSQaTAd2LCOFLIZ62w5xAFG48KoReoCDSK+tPrG8iqKDbX6 hriOCCK1mgANkB77CzbYp1rPjVd/+59m6Pf6jOmlXwspUdueRUjitQ4FOWzv6qgQXQgY j30A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727538599; x=1728143399; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h0SKMKMI45dY7Yo4FbT9sHeANHccvG4fNyyhJ9RkUbo=; b=kRXEj0CebgD7RtcN+gfv2eXEzvsn27L3MG4U26GPM35HpndNZ9xorXwr5Tkwg7qg1N y4JQZzrsI+F1FA/vvxwVIlkpjJyD+L5t4LZfBnpdKKtvbuTGjYg81UMQKiAHHmPny84b irlVl5dR7E4egy1jjcZRKm7O+uAcaNP9raPSYb40k+ibKmh1lBHVdI/257+GNMB3reJI xcRZAofwnWPVvggfwEiBmRFjB02f55fOFPBRndZpyuH2I5trEoB5JRr5m31Ppi/n6XuB /wJKsaCepTNuDYRyX34w2MKclYE9jgBDih39svH5+kVC6iyxx6KZiU569p9rNnXOLswL jKoA== X-Gm-Message-State: AOJu0Yy/l25grUbh4Z3MD/AxOVL8bFDrj9bHdzjt9tiVrIw0I5TPDHaM Mrxmh1RFIpGbfyAbc1/4XtAZLQNbEtAP1583s3cB8mNviUCcIHbuu9PvOxY1dXIHRC4wfLmJaLl 9gdH4emo1vmdFeTuheXrdARxLjF0woxnTKFx9qqCJMctXUbPcAv4= X-Google-Smtp-Source: AGHT+IH12AnUd9XssC60Yzn9wY1cmtM27SVldvnX9dGozUoMcMUYtDkqTCMXGreyVx6/+3ceynDD70o+Ig336GXhaMo= X-Received: by 2002:a05:6402:2803:b0:5c7:2279:bccf with SMTP id 4fb4d7f45d1cf-5c8824d6433mr5019516a12.13.1727538598931; Sat, 28 Sep 2024 08:49:58 -0700 (PDT) MIME-Version: 1.0 From: Adrian Garcia Badaracco Date: Sat, 28 Sep 2024 10:49:47 -0500 Message-ID: Subject: Faster `&&` intersection for sorted arrays To: pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="000000000000868ceb06232feca7" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000868ceb06232feca7 Content-Type: text/plain; charset="UTF-8" I was wondering if I could do better than `&&` for sorted arrays by doing binary search and came up with some really interesting results. I only did a quick spin of this, an LLM generated most of the code after I gave it the algorithm and I don't plan on using it in production (I'm going to normalize my schema instead) but I wanted to share this in case it's useful to anyone. https://gist.github.com/adriangb/1b68bb2e408423ddcb90fb0136a00ba8 --000000000000868ceb06232feca7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I was wondering if I could do better than `&&` for= sorted arrays by doing binary search and came up with some really interest= ing results.
I only did a quick spin of this, an LLM generated most of t= he code after I gave it the algorithm and I don't plan on using it in p= roduction (I'm going to normalize my schema instead) but I wanted to sh= are this in case it's useful to anyone.

https://gist.github.c= om/adriangb/1b68bb2e408423ddcb90fb0136a00ba8
--000000000000868ceb06232feca7--