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 1i8Cn5-0006bo-NQ for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Sep 2019 00:16:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8Cn3-0006Hz-CJ for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Sep 2019 00:16:49 +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 1i8Cn2-0006G4-UQ for pgsql-hackers@lists.postgresql.org; Thu, 12 Sep 2019 00:16:49 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8Cmv-0006YO-6O for pgsql-hackers@postgresql.org; Thu, 12 Sep 2019 00:16:48 +0000 Received: by mail-wr1-x442.google.com with SMTP id l16so26389985wrv.12 for ; Wed, 11 Sep 2019 17:16:40 -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:content-transfer-encoding:in-reply-to :user-agent; bh=wbcSCy08qOwsYCUCdf1+f5z00Qf8veLL6GXmoJP0SGA=; b=nE2JkVrgXCUdVNGCuuGVc+jWnuEi/jtLtfeRhIW0o86KmvccYyBUcncU6Wv8G5DT0N uR3VnHgn4VB0TuQndLqcn03vCxNqQJuQdEx8pcz2Fgoov6xCQwkOk4LmKaGkYPgtjWix OfzSnQHzWZt8MrmSOYRgzjDSHR/SlPDQVNiMSWNbOd77rocGKZt1krYbS4kevFQckrRK TmrDpco8LfgCmXSKwwziFxV5smjt7kWRw+kIhbG5RkyY41GDJKivs3mFRQxQmeu2M8kF YFaRmPZ1xzzna9MAYQWPdRODLbdzT+npNBQb885E7TERlLqoxhPLCzlLS4+itJoHjrdN /rjg== 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:content-transfer-encoding :in-reply-to:user-agent; bh=wbcSCy08qOwsYCUCdf1+f5z00Qf8veLL6GXmoJP0SGA=; b=kwAiXa5rwPZeHslBstGLVrh5h75vE7gqafhRNyZ3NVtR15+vchas0vNYIXArKa+Pt0 T2yDLsYWoPlrzxPg95YOR6sEwX2uLPfYtpBezEsy1t69FuYrisYYUnr2AMIwnqIGUFpl RUPNjyye+kGCWlW7woQq/QnDR3ZMlkGgZvCRZboyONyTjF/2M0uVs4uG70mj3evbXZhC kUVDC51oJtBpOeeG5ofX1mXUcJBnOqqzIkad3Vl9pm/7Ew/KTHQg29gsyPyhDp9UdOM0 esMG9Y54u+4/p6HKbrBpOIvI3t5hfUo4fcvka2Ysu5hT8rDwDdz/0+7O42O5cLjqkvtK /AHg== X-Gm-Message-State: APjAAAXv7q0RLaEvKDoFIvOe/ribo8eNMTQ2I35ZtPD3CpT1tZdw/QUB q5rWqSgZFtxY5JbNdBOfSL2zlA== X-Google-Smtp-Source: APXvYqw514PpPg5sCwzishFyUSgGeE3HCueDFdINd7xqeg350nI+y81q5AUO5+N9c8SUPU0q7oRLfQ== X-Received: by 2002:a05:6000:a:: with SMTP id h10mr10297009wrx.226.1568247398115; Wed, 11 Sep 2019 17:16:38 -0700 (PDT) Received: from localhost ([88.157.94.57]) by smtp.gmail.com with ESMTPSA id t203sm7654775wmf.42.2019.09.11.17.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2019 17:16:37 -0700 (PDT) Date: Thu, 12 Sep 2019 02:16:34 +0200 From: Tomas Vondra To: Nikita Glukhov Cc: "pgsql-hackers@postgresql.org" , Alvaro Herrera , Robert Haas , Tom Lane , Nikolay Shaplov , Oleg Bartunov Subject: Re: [PATCH] Opclass parameters Message-ID: <20190912001634.oeteg5edzke47om4@development> References: <20190903220254.GA22389@alvherre.pgsql> <20190910220358.6tj37k4v6vyaqac7@development> <0807f67b-c1bd-3760-7fc5-89900ae65408@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0807f67b-c1bd-3760-7fc5-89900ae65408@postgrespro.ru> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Sep 11, 2019 at 01:44:28AM +0300, Nikita Glukhov wrote: >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. OK, thanks for the explanation - so the per-attribute opclass options will work even when the AM does not have amattoptions() defined. Is there any practical reason why not to just define everything as opclass options and get rid of the amattoptions() entirely? > amproc #0 is called regardless of whether amattoptions >is defined or not. That was the main reason why uniform procnum 0 was >picked. > I still think using procnum 0 and passing the data through fn_expr are not the right solution. Firstly, traditionally the amprocs are either required or optional, with required procs having low procnums and optional starting at 11 or so. The 0 breaks this, because it's optional but it contradicts the procnum rule. Also, what happens if we need to add another optional amproc defined for all AMs? Surely we won't use -1. IMHO we should keep AM-specific procnum and pass it somehow to the AM machinery. FWIW there seems to be a bug in identify_opfamily_groups() which does this: /* Ignore strategy numbers outside supported range */ if (oprform->amopstrategy > 0 && oprform->amopstrategy < 64) thisgroup->operatorset |= ((uint64) 1) << oprform->amopstrategy; but then identify_opfamily_groups() computes allfuncs without any such restriction, i.e. it includes procnum 0. And then it fails on this check if (thisgroup->functionset != allfuncs) {...} None of the built-in brin opclasses defines the new amproc, so the code does not hit this issue. I only noticed this with the opclasses added in the other thread. As for the fn_expr, I still think this seems like a misuse of a field which was intended for something else. I wonder if it might be breaking some exising code - either in code or in some extension. It seems quite possible. It just seems like we're inventing a new way to novel way to pass data into a function while we already have parameters for that purpose. Adding parameters may require care so as not to break existing opclasses, but it seems like the right approach. >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(); >} > OK, this did the trick. Thanks. I don't have a clear opinion on the API, but it certainly looks like an improvement. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services