Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j9cTj-0001IY-8o for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2020 22:26:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9cTh-0004j1-Qh for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2020 22:26:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j9cTh-0004iu-8z for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2020 22:26:57 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j9cTe-0000I7-I2 for pgsql-hackers@postgresql.org; Wed, 04 Mar 2020 22:26:56 +0000 Received: by mail-pg1-x529.google.com with SMTP id t24so1682982pgj.7 for ; Wed, 04 Mar 2020 14:26:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=J80XLELEmlZkoIgXejK4bBLxdWWH2Kho3JZUqcJDyw0=; b=kfar5NiOjX7dFc0CctDYjxSa6jmsYwcwZkUkLip3MZ7UFYa3x/keadsGUETe1YORif M9NpUFGz0tDzogoTL0KCqAzs9LTHyoWO8eMyFP1gF1NcmJYEo7tzXhpWcAQpfCf8H0rx Tdc0qWzdKVhet07jP99VpaZBfrDdZGBCCynII6netF9Ngl3iJl6HjlgjEVzdUBstVFbf 5w+GHgrOxVp1Vpvhf32hVVUd4/f15G8mtIADtAldQOAJCvTxhxefXP/o62BSdoUWYIxw z9ce+YUrtNIC+JfsJKMR0baQ2ItGzSg6VxxaUrI4GGtSOacyN6SHpaeZhi4XWWZAhOVt mJUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=J80XLELEmlZkoIgXejK4bBLxdWWH2Kho3JZUqcJDyw0=; b=J/mBN1YAVLeKfZJEC5PtE7acB6m44Qb5c3z0IIUmlAmvaNFEEEN0uNRxTkSJ4gLcve nEnxCa8A4Y49GFyV/s1brXTmpP0lrH/l8Wxv5KMR9YIxbu8R5jp1QE8JdIsM6vhN0AwM W6jC5Sz/HaLAd1yqKlmJRybREHlNjHKQOWXtTJ8sMnLsqrRjbkldx23o5fLhL4h1HkkX epQs3EIZ+SMdYXRvUGJPerzF2vBQQSADf3MbcrFvEJPwRhGghQV1BijfA3z2YWZ45aWY Axc3JWxwmbGCxbyyOxT9ZUcRfEafRcbalqxP9gMg2KmDYzxYNahF5CL4RD/SgH2+oyFO uEwQ== X-Gm-Message-State: ANhLgQ1Zhb7BS4L2EYw4czLwSsEwemQApwzBMswklcrC/IVHGptIUni3 QjdSqV+95RsEr0EV0R/w14c9Y57LEu8= X-Google-Smtp-Source: ADFU+vuh+xCdLImYIGQhjIMQxFN44/WBTd8O9Hqou2WToRHAclIwX7ceQnVmwsql3DLV/AnB1MIWUQ== X-Received: by 2002:a63:1054:: with SMTP id 20mr3679170pgq.431.1583360812982; Wed, 04 Mar 2020 14:26:52 -0800 (PST) Received: from [192.168.2.101] (static-50-53-109-254.bvtn.or.frontiernet.net. [50.53.109.254]) by smtp.googlemail.com with ESMTPSA id b133sm29134077pga.43.2020.03.04.14.26.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Mar 2020 14:26:52 -0800 (PST) Subject: Re: range_agg To: Alvaro Herrera Cc: Tom Lane , Pavel Stehule , Jeff Davis , Pgsql Hackers References: <20200304213321.GA23016@alvherre.pgsql> From: Paul Jungwirth Message-ID: <0b0de089-4987-0ae9-615d-a07b4f8ee5aa@illuminatedcomputing.com> Date: Wed, 4 Mar 2020 14:26:50 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200304213321.GA23016@alvherre.pgsql> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thanks for looking at this again! On 3/4/20 1:33 PM, Alvaro Herrera wrote: > I came across an interesting thing, namely multirange_canonicalize()'s > use of qsort_arg with a callback of range_compare(). range_compare() > calls range_deserialize() (non-trivial parsing) for each input range; > multirange_canonicalize() later does a few extra deserialize calls of > its own. Call me a premature optimization guy if you will, but I think > it makes sense to have a different struct (let's call it > "InMemoryRange") which stores the parsed representation of each range; > then we can deserialize all ranges up front, and use that as many times > as needed, without having to deserialize each range every time. I don't know, this sounds like a drastic change. I agree that multirange_deserialize and range_deserialize do a lot of copying (not really any parsing though, and they both assume their inputs are already de-TOASTED). But they are used very extensively, so if you wanted to remove them you'd have to rewrite a lot. I interpreted the intention of range_deserialize to be a way to keep the range struct fairly "private" and give a standard interface to extracting its attributes. Its motive seems akin to deconstruct_array. So I wrote multirange_deserialize to follow that principle. Both functions also handle memory alignment issues for you. With multirange_deserialize, there isn't actually much structure (just the list of ranges), so perhaps you could more easily omit it and give callers direct access into the multirange contents. That still seems risky though, and less well encapsulated. My preference would be to see if these functions are really a performance problem first, and only redo the in-memory structures if they are. Also that seems like something you could do as a separate project. (I wouldn't mind working on it myself, although I'd prefer to do actual temporal database features first.) There are no backwards-compatibility concerns to changing the in-memory structure, right? (Even if there are, it's too late to avoid them for ranges.) > While I'm at this, why not name the new file simply multiranges.c > instead of multirangetypes.c? As someone who doesn't do a lot of Postgres hacking, I tried to follow the approach in rangetypes.c as closely as I could, especially for naming things. So I named the file multirangetypes.c because there was already rangetypes.c. But also I can see how the "types" emphasizes that ranges and multiranges are not concrete types themselves, but more like abstract data types or generics (like arrays). Yours, -- Paul ~{:-) pj@illuminatedcomputing.com