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.96) (envelope-from ) id 1vuy8x-00F3Nh-07 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Feb 2026 19:32:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vuy8v-003ABZ-2X for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Feb 2026 19:32:25 +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.96) (envelope-from ) id 1vuy8v-003ABR-1a for pgsql-hackers@lists.postgresql.org; Tue, 24 Feb 2026 19:32:25 +0000 Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vuy8s-000000016R0-0CGU for pgsql-hackers@lists.postgresql.org; Tue, 24 Feb 2026 19:32:24 +0000 Received: by mail-ua1-x934.google.com with SMTP id a1e0cc1a2514c-94dd2d71231so400505241.0 for ; Tue, 24 Feb 2026 11:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771961540; x=1772566340; darn=lists.postgresql.org; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ETrkzW4+hkYtFScqC87jNXOPD/ZmBVfuUT2OsT0NMgY=; b=ZgmJGDvKQ6o2tazDtWYRdnfCLhCsbZbFe8PpHpj3HB7JzLaQfffdbx2EXvGj+3AIt7 LAuWbxa1K8ysSQ4J1HuKJrFxfjJHiy7tBB+NeA9LW+2swLUdW/3AIZ+OvaC19lBO2/D8 NgwH4M+Wckv319QuRoY1XPxS0EUzX7rj9neP37Oc1JlPKImrkyZtSwwkHCrF745dRu4u YZfm6Z9vLhrO7+bd+rF6Z+HFnuWYs+dStvwz6TkGU7hUPQTPebutJWRN0+bD5c5vFL9R d4qWpZQu6U1svwY/A5P7J1RcLSaW8ZLaRqCp55voKzi27NMfd8IHFT+lYBoDhbAa0uMO STKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771961540; x=1772566340; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ETrkzW4+hkYtFScqC87jNXOPD/ZmBVfuUT2OsT0NMgY=; b=KW28jhvw1SwwGf8yVgDdNki7s+1r/Q3W+aa0freLYDdDy6cH4jbIdF4CnzLBbULWjV v2ojO9k4Fd4kUyFYtd8LphPoed6fGFYTCNDd4SNEz519Kj5am+9W/AYR7gyHe+56rKvk x6yxQQii/q6NY7AN0pF45rcq+CNBPM2gnSNwVXB8dA6lPkqa7idWQ5iMbhLsCyP+E/s5 xIwB7b1M9AiY9fA1S0dnFgnpIZXXKsKex1YiAM1ICmDqdNV2PSMrVzjyM5QXe9S9SOSt djTvrcqk0dMHNfZBPFIhslKM2sQUxYen5+6VC30Mq9GZ55mQZA3jAQLgbUJUEL4TPY2o 9c2g== X-Forwarded-Encrypted: i=1; AJvYcCUETX9G/4pKbLQdiw65i9wMn49VMiozzmyYiCwI9FvBqURZ082/3dUYZjebE04FcLzGsnRWyTJSY4XM68n1@lists.postgresql.org X-Gm-Message-State: AOJu0YwDOrXfCFm9A3sCRP1O+B1zLSalxDM5hq/d9AjIM1yCY1++kHOz 57JzsvZrSd7hsrw3g4WUQLWlw74LkD+lFgVYcI5pOmrjvczfRfM8582G X-Gm-Gg: ATEYQzw/QIcY3T+grBRsipJcsMT7yqsH7h270E8gSazKFm9FJSrxixyhW4glljXl2xE FQ89CIDiq7/rf9VuCCrQ/Bu3hAI6K2b9gbm/1SV2yGhd8IPibjYkplj5+jI8Xgqzf2Vk1pk/Rca 09kj8yRC9RrXY0aP3She7qehROkphdR4owVxsE7UIjYmGDJ3bgc1O1rCXKMvHEy/cIsJXFoKjiV m3L5B+n7p7fe5+amEGxQRfQdVeXUEbVfhiUiowSGKzIy/7YegILTzL/bVR6TsPduJmybdBredkh d71d4XRgHrG6tfTUK92KWdjXTwH+Rh9nJWJVTNyYNkPqWXwdOVmN2OLtiE81uxOTlyEnO6lgNa8 JNyQ3cEkIywe1D6E2oKWKeLb//uYS+1hF5tzdqHJVoyrH6In1GI8WccuXoV2U1WIPgx9Zt+cRjV /bGat08Vfvw8v6gTU+o78/43uhFlEk1AYyHutiUqiQaruqjg== X-Received: by 2002:a05:6102:e0e:b0:5f5:2a8e:f4b3 with SMTP id ada2fe7eead31-5feb310b930mr4525844137.37.1771961540116; Tue, 24 Feb 2026 11:32:20 -0800 (PST) Received: from localhost ([2804:14d:328a:a59c:6139:1fdb:e068:cabe]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-94da89e129esm10750969241.5.2026.02.24.11.32.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Feb 2026 11:32:19 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 24 Feb 2026 16:32:15 -0300 Message-Id: From: "Matheus Alcantara" To: "Ilia Evdokimov" , "Tatsuya Kawata" , "David Geier" Cc: "Chengpeng Yan" , "pgsql-hackers@lists.postgresql.org" Subject: Re: Hash-based MCV matching for large IN-lists X-Mailer: aerc 0.21.0 References: <7db341e0-fbc6-4ec5-922c-11fdafe7be12@tantorlabs.com> <988e3168-6096-488a-bb42-787e1e8c21a4@tantorlabs.com> <21FF6A0B-886F-4132-B6A6-0F4E934B4CEE@Outlook.com> <8ee9d903-bb13-434c-8145-b3769bf2b3cb@tantorlabs.com> <9e3054ae-1c5d-46dd-9b6a-7fb67764b076@tantorlabs.com> In-Reply-To: <9e3054ae-1c5d-46dd-9b6a-7fb67764b076@tantorlabs.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, thanks for working on this! On Wed Feb 18, 2026 at 9:48 AM -03, Ilia Evdokimov wrote: > I've fixed all the comments raised above and updated the v5 patch. > Here are some comments regarding v5 patch: On scalararraysel() we have: + ReleaseVariableStats(vardata); + + if (s1 >=3D 0.0) + return s1; I'm wondering if we also should call ReleaseVariableStats() on the early return? + if (!useOr && elem_nulls[i]) + { + pfree(elem_values); + pfree(elem_nulls); + pfree(elem_const); + + return (Selectivity) 0.0; + } ------------------ On scalararray_mcv_hash_match() free_attstatsslot() is called only on if (have_mcvs && OidIsValid(hashLeft) && OidIsValid(hashRight)), perhaps it should be moved outside the if condition? + if (have_mcvs && OidIsValid(hashLeft) && OidIsValid(hashRight)) + { + ... + MCVHashTable_destroy(hashTable); + free_attstatsslot(&sslot); + } + + return selec; ------------------ typo: "all elements are const" + * array is NULL if all elemnets is const. ------------------ It's worth adding on scalararray_mcv_hash_match() an early return when num_elems =3D=3D 0? I imagine that this can happens, e.g "WHERE a =3D ANY(array[]::int[]);". In this case the function should still execute completely? -- Matheus Alcantara EDB: https://www.enterprisedb.com