Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pJjeX-0007EV-Gp for pgsql-hackers@arkaria.postgresql.org; Sun, 22 Jan 2023 23:21:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pJjeW-0001lF-2o for pgsql-hackers@arkaria.postgresql.org; Sun, 22 Jan 2023 23:21:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pJjeV-0001l5-On for pgsql-hackers@lists.postgresql.org; Sun, 22 Jan 2023 23:21:31 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pJjeO-0001np-FO for pgsql-hackers@lists.postgresql.org; Sun, 22 Jan 2023 23:21:30 +0000 Received: by mail-wr1-x432.google.com with SMTP id n7so9292262wrx.5 for ; Sun, 22 Jan 2023 15:21:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=m9Kqi1nUB72mKePV4A9YBqieIW5QU+qcWDNFNLw6/EU=; b=B5+uEfcVcTt+vyr91KQlOb2b3cBX8dhIjqfwA9wGkrM1a/kFFCEgISg5V976cF+g9T 9mcZIyiXy/PuGSpsnhAG5mjd4Ef1Ls4K42sT6D9FoBR+/ouaQ1FKCcNZeCcxY3OcgGXH wZ9QMkTB/yeFvr1D0ub1FnqVKJuhToDgys5z0lxBLdN5gyflGJ4C7lWegze/8MRfu6Gm xgVgrVRekfvLqxSpokwg4zIVKxldHXhjaB0JKI4mn7AI0rIIDAtUoozxVR6Jk1TGx83s D7K1L6frBj3BjAd2LjUoad1bXdDxSWx5qaBhKMSMiBFz3b/hKr9lRlNgv4TU6A6X/39x 4gnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=m9Kqi1nUB72mKePV4A9YBqieIW5QU+qcWDNFNLw6/EU=; b=sXaQ3FoNNCilIXeG/KExBBGkW2p6RxMlzz9wxFirknSgOzsWZcXEU8z6T4TDCiZhlI 1l+cIIzpSWZRhG+KcVEh5rTwUdOngC83Afr1LaXIW4wcvR0CONQ0hQZgNJ1plBChhvuL 9dtD+uzSkcGggGnLAjK/GfOVsCWVJZSrlQdUyBE5aLAS4p7JrB8pVFcCxVwqY5Vz/aac EQ0dby6GZb7B2p4/sTadNwcpy6qYQzx4cRn1Z5ObORwAcnAXaBU7GxmdtiZaTGBfGuSO YpGUHyI2YIBu+SgHKv5qhgUHIPJlmGAf+rg2RfvbQ4wLeA81O8C0TpYbiKjJEXhgutPR KfdA== X-Gm-Message-State: AFqh2kqmCG5yBNri/GFmzWZ6w0SZFpwZU4E3o9BGDxE7ZVlT/BYShIgY y4tu4vdD6Y075p+1bnbVpR+5E8dREPFxK6xzYdu225IHqPI8HGB3hFI1dFLmP3tYp92ckG0ebF0 jlYWxhWn1PU0Tcn1UVb7ATfSSUl25V3N8Ihh93zT0Ou5mv/Djukwcxx66w4/BCTFufB/u+wj/Hw MNAAdJ1+2NfwZzc58CGJ2qu5yBUk4Vyk8hHPNfraZIEk8keWeqGebtM6ZX9OYJ5EI1mAVq9YASL EJoTkFgG+n+A8Ops30hycC3p1rHivWTe+iKrywZCq91RK2vn3UCQYRurIdI X-Google-Smtp-Source: AMrXdXuZ+mXjOV3PBarvCSjErejiPR5lafG2sR6hvrXID2/KIFHq7QlHjD+VBSvd7NPxdD55qlzG7w== X-Received: by 2002:a5d:4ac4:0:b0:2bd:d6bd:57c7 with SMTP id y4-20020a5d4ac4000000b002bdd6bd57c7mr27862079wrs.12.1674429682842; Sun, 22 Jan 2023 15:21:22 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-228-162.bb.vodafone.cz. [86.49.228.162]) by smtp.gmail.com with ESMTPSA id n1-20020a5d67c1000000b002bc7f64efa3sm33380216wrw.29.2023.01.22.15.21.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Jan 2023 15:21:22 -0800 (PST) Message-ID: <7ae24b59-782a-a531-fae5-e498e4eaa0e7@enterprisedb.com> Date: Mon, 23 Jan 2023 00:21:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: pg_stats and range statistics To: Justin Pryzby Cc: Egor Rogov , Soumyadeep Chakraborty , pgsql-hackers@lists.postgresql.org References: <55c8ecd4-57d0-5c63-6fe3-1b81e8caea9d@enterprisedb.com> <20230122213310.GQ13860@telsasoft.com> Content-Language: en-US From: Tomas Vondra In-Reply-To: <20230122213310.GQ13860@telsasoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/22/23 22:33, Justin Pryzby wrote: > On Sun, Jan 22, 2023 at 07:19:41PM +0100, Tomas Vondra wrote: >> On 1/21/23 19:53, Egor Rogov wrote: >>> Hi Tomas, >>> On 21.01.2023 00:50, Tomas Vondra wrote: >>>> This simply adds two functions, accepting/producing anyarray - one for >>>> lower bounds, one for upper bounds. I don't think it can be done with a >>>> plain subquery (or at least I don't know how). >>> >>> Anyarray is an alien to SQL, so functions are well justified here. What >>> makes me a bit uneasy is two almost identical functions. Should we >>> consider other options like a function with an additional parameter or a >>> function returning an array of bounds arrays (which is somewhat >>> wasteful, but probably it doesn't matter much here)? >>> >> >> I thought about that, but I think the alternatives (e.g. a single >> function with a parameter determining which boundary to return). But I >> don't think it's better. > > What about a common function, maybe called like: > > ranges_upper_bounds(PG_FUNCTION_ARGS) > { > AnyArrayType *array = PG_GETARG_ANY_ARRAY_P(0); > Oid element_type = AARR_ELEMTYPE(array); > TypeCacheEntry *typentry; > > /* Get information about range type; note column might be a domain */ > typentry = range_get_typcache(fcinfo, getBaseType(element_type)); > > return ranges_bounds_common(typentry, array, false); > } > > That saves 40 LOC. > Thanks, that's better. But I'm still not sure it's a good idea to add function with anyarray argument, when we need it to be an array of ranges ... I wonder if we have other functions doing something similar, i.e. accepting a polymorphic type and then imposing additional restrictions on it. > Shouldn't this add some sql tests ? > Yeah, I guess we should have a couple tests calling these functions on different range arrays. This reminds me lower()/upper() have some extra rules about handling empty ranges / infinite boundaries etc. These functions should behave consistently (as if we called lower() in a loop) and I'm pretty sure that's not the current state. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company