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.89) (envelope-from ) id 1i7out-0008Ct-ME for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Sep 2019 22:47:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i7ous-0002lE-E4 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Sep 2019 22:47:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7our-0002es-SQ for pgsql-hackers@lists.postgresql.org; Tue, 10 Sep 2019 22:47:18 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i7oup-0001Vt-2o for pgsql-hackers@postgresql.org; Tue, 10 Sep 2019 22:47:17 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 73CA921C3FA0; Wed, 11 Sep 2019 01:47:14 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [10.100.236.30] (unknown [193.106.43.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 1552521C3F9F; Wed, 11 Sep 2019 01:47:14 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1568155634; bh=PnRMG5qkVZWr4gdijQD+XEPt0vvmOhPhZew0ax2LKB8=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=k1cioQEUagvwO7fHFeOp2nThdUke87IJhmwbofmRIEyfkAaZmtFUTpsZqg2GQz1IG ROSmjXvvZIbqtlOUmhGOry+LmHWayGbv0DRRcFmKIVNGJ0pM7qOPPRJmFRktyQXrUl nfzLpUo1z7m0H1XuPGkLilMVrb18+AECNHQkgcDI= Subject: Re: [PATCH] Opclass parameters To: Tomas Vondra , "pgsql-hackers@postgresql.org" Cc: Alvaro Herrera , Robert Haas , Tom Lane , Nikolay Shaplov , Oleg Bartunov References: <20190903220254.GA22389@alvherre.pgsql> <20190910220358.6tj37k4v6vyaqac7@development> From: Nikita Glukhov Organization: Postgres Professional Message-ID: <0807f67b-c1bd-3760-7fc5-89900ae65408@postgrespro.ru> Date: Wed, 11 Sep 2019 01:44:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190910220358.6tj37k4v6vyaqac7@development> Content-Type: multipart/alternative; boundary="------------056D4DABD5848D7AFBB1913C" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------056D4DABD5848D7AFBB1913C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 11.09.2019 1:03, Tomas Vondra wrote: > On Tue, Sep 10, 2019 at 04:30:41AM +0300, Nikita Glukhov wrote: > >> 2. New AM method amattoptions(). >> >>   amattoptions() is used to specify per-column AM-specific options. >>   The example is signature length for bloom indexes (patch #3). >> > > I'm somewhat confused how am I supposed to use this, considering the > patch > set only defines this for the contrib/bloom index AM. So let's say I want > to create a custom BRIN opclass with per-attribute options (like the two > BRIN opclasses I work on in the other thread). Clearly, I can't tweak the > IndexAmRoutine from the extension. ISTM the patch series should modify > all > existing index AMs to have a valid amattoptions() implementation, calling > the new amproc if defined. > > Or what is the correct way to define custom opclass for existing index AM > (e.g. BRIN) with attribute options? > Per-attribute opclass options are implemented independently from per-attribute AM options. amattoptions() is optional and needs to be defined only if AM has per-attribute options. amproc #0 is called regardless of whether amattoptions is defined or not. That was the main reason why uniform procnum 0 was picked. You should simply define function like that and use it as amproc #0: Datum brin_bloom_options(PG_FUNCTION_ARGS) { local_relopts *relopts = (local_relopts *) PG_GETARG_POINTER(0); BloomOptions *blopts = NULL; extend_local_reloptions(relopts, blopts, sizeof(*blopts)); add_local_real_reloption(relopts, "n_distinct_per_range", "desc", -0.1, -1.0, INT_MAX, &blopts->nDistinctPerRange); add_local_real_reloption(relopts, "false_positive_rate", "desc", 0.01, 0.001, 1.0, &blopts->falsePositiveRate); PG_RETURN_VOID(); } -- Nikita Glukhov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --------------056D4DABD5848D7AFBB1913C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

On 11.09.2019 1:03, Tomas Vondra wrote:

On Tue, Sep 10, 2019 at 04:30:41AM +0300, Nikita Glukhov wrote:

2. New AM method amattoptions().

  amattoptions() is used to specify per-column AM-specific options.
  The example is signature length for bloom indexes (patch #3).


I'm somewhat confused how am I supposed to use this, considering the patch
set only defines this for the contrib/bloom index AM. So let's say I want
to create a custom BRIN opclass with per-attribute options (like the two
BRIN opclasses I work on in the other thread). Clearly, I can't tweak the
IndexAmRoutine from the extension. ISTM the patch series should modify all
existing index AMs to have a valid amattoptions() implementation, calling
the new amproc if defined.

Or what is the correct way to define custom opclass for existing index AM
(e.g. BRIN) with attribute options?

Per-attribute opclass options are implemented independently from per-attribute 
AM options.  amattoptions() is optional and needs to be defined only if AM has 
per-attribute options.  amproc #0 is called regardless of whether amattoptions
is defined or not.  That was the main reason why uniform procnum 0 was picked.
You should simply define function like that and use it as amproc #0:
 
Datum
brin_bloom_options(PG_FUNCTION_ARGS)
{
    local_relopts *relopts = (local_relopts *) PG_GETARG_POINTER(0);
    BloomOptions *blopts = NULL;

    extend_local_reloptions(relopts, blopts, sizeof(*blopts));

    add_local_real_reloption(relopts, "n_distinct_per_range", "desc",
                             -0.1, -1.0, INT_MAX, &blopts->nDistinctPerRange);

    add_local_real_reloption(relopts, "false_positive_rate", "desc",
                             0.01, 0.001, 1.0, &blopts->falsePositiveRate);

    PG_RETURN_VOID();
}
--
Nikita Glukhov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--------------056D4DABD5848D7AFBB1913C--