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 1kGRNS-0003LV-6A for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Sep 2020 18:32:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kGRNQ-0002Wn-OB for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Sep 2020 18:32:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kGRNQ-0002Wg-D8 for pgsql-hackers@lists.postgresql.org; Thu, 10 Sep 2020 18:32:56 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kGRNN-00022c-8H for pgsql-hackers@postgresql.org; Thu, 10 Sep 2020 18:32:55 +0000 Received: by mail-lf1-x142.google.com with SMTP id u8so4152181lff.1 for ; Thu, 10 Sep 2020 11:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=1eqZj8/5U+cJT5CQZP8AysPPQs/tneN2B/ifXBZc1KE=; b=VjWahjL+1u23136lUirqBwMOQekfuqeRHIckhCA+E3iYd8Qoxj2dsgMhmba1mfkVHz hFET0kxMCT02lRAG/BTVKzHHRGniaF75JeUXfeQvla4VTr0Fc4/FYf4x0M39N+KcjBRd yDqLN9clrCvtay51XLWyhq6IiLMN395INU7BYAdZBNKPxw2kBbksmGXJvbzb50r6fRx8 FS15Kc9cF/nETVs/jS9JWDYj1Gb2Eg2ugVA4HKVg7F6XwUfmwydvv77kz2wDXf3GjQRy p+RcHj1pO3SGju1K4wFMKeuOrO2s71hDwLNbhakV8fgAPTNuQMw2y8CiFj5q7pXLG1AQ Lkzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=1eqZj8/5U+cJT5CQZP8AysPPQs/tneN2B/ifXBZc1KE=; b=XYvtFkY8VYuSN4OGXbjV2tOH69jNmGAa+Pg0lMvFIUM4sgPFiSJhOq76goTlS7CQZc 24OF+yEdXP24VDuHefjXegiqEqxXdrO+rJguPqsakTqtbhbN/kyqofmTKT1KY71HttgE lt+LVkgSRiQT6nIW06ewdZoU6b5SGu3Mm2aHfLtWDdX0Q0XTgamfyzDZ4RS/FQ2/OXl+ DTq9BI61+aVpi3EFNNDkyejfS3EOv2Wy80Uc7FJ5/d3uSwHznqVFFvVEJ01rtmb5FJtX whEGNiAC9csQM7DqUp15ltGNoiuLOUK65a+HZJuw+T0A30GJmeSUTxsibpTAW7Ik1ZRn Up6A== X-Gm-Message-State: AOAM533KccgDxDJOZ5MAN6lvqgBFxEISfBY6T9DfFI8dzbjc3NIympGp dnUuA2kkN0Z2FfanE3VhdtwsDmzYgAiRlSL0 X-Google-Smtp-Source: ABdhPJwu2RhkIg/gbJG9uKSaAle+w6wJtnTA1KpQ7M7t0J4e/JvObjxAuxbOj/44w06nMqHQwR6cmA== X-Received: by 2002:a19:4c8:: with SMTP id 191mr4637687lfe.197.1599762770639; Thu, 10 Sep 2020 11:32:50 -0700 (PDT) Received: from localhost (37-247-27-67.customers.ownit.se. [37.247.27.67]) by smtp.gmail.com with ESMTPSA id a16sm1791090ljj.108.2020.09.10.11.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 11:32:49 -0700 (PDT) Date: Thu, 10 Sep 2020 20:32:48 +0200 From: Tomas Vondra To: Alvaro Herrera Cc: John Naylor , pgsql-hackers Subject: Re: WIP: BRIN multi-range indexes Message-ID: <20200910183248.eajizgzuypntsjmh@development> References: <20200909193530.x57p5nzawryndxzj@development> <20200909195330.GA16854@alvherre.pgsql> <20200909202600.fup27xfr2m34jqg6@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200909202600.fup27xfr2m34jqg6@development> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Sep 09, 2020 at 10:26:00PM +0200, Tomas Vondra wrote: >On Wed, Sep 09, 2020 at 04:53:30PM -0300, Alvaro Herrera wrote: >>On 2020-Sep-09, Tomas Vondra wrote: >> >>>There are some minor optimizations possible - for example I noticed we >>>call minmax_multi_get_strategy_procinfo often because it happens in a >>>loop, and we could easily do it just once. But that saves only about 10% >>>or so, it's not a ground-breaking optimization. >> >>Well, I guess this kind of thing should be fixed regardless while we >>still know it's there, just to avoid an obvious inefficiency. >> > >Sure. I was just suggesting it's not something that'd make this very >close to plain minmax opclass. > >>>The main reason for the slowness is that we pass the values one by one >>>to brin_minmax_multi_add_value - and on each call we need to deserialize >>>(and then sometimes also serialize) the summary, which may be quite >>>expensive. The regular minmax does not have this issue, it just swaps >>>the Datum value and that's it. >> >>Ah, right, that's more interesting. The original dumb BRIN code >>separates BrinMemTuple from BrinTuple so that things can be operated >>efficiently in memory. Maybe something similar can be done in this >>case, which also sounds like your second suggestion: >> >>>Another option would be to teach add_value to keep the deserialized >>>summary somewhere, and then force serialization at the end of the BRIN >>>page range. The end result would be roughly the same, I think. >> > >Well, the patch already has Ranges (memory) and SerializedRanges (disk) >but it's not very clear to me where to stash the in-memory data and >where to make the conversion. > I've spent a bit of time experimenting with this. My idea was to allow keeping an "expanded" version of the summary somewhere. As the addValue function only receives BrinValues I guess one option would be to just add bv_mem_values field. Or do you have a better idea? Of course, more would need to be done: 1) We'd need to also pass the right memory context (bt_context seems like the right thing, but that's not something addValue sees now). 2) We'd also need to specify some sort of callback that serializes the in-memory value into bt_values. That's not something addValue can do, because it doesn't know whether it's the last value in the range etc. I guess one option would be to add yet another support proc, but I guess a simple callback would be enough. I've hacked together an experimental version of this to see how much would it help, and it reduces the duration from ~4.6s to ~3.3s. Which is nice, but plain minmax is ~1.1s. I suppose there's room for further improvements in compare_combine_ranges/reduce_combine_ranges and so on, but I still think there'll always be a gap compared to plain minmax. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services