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 1i7oKt-00074m-Tn for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Sep 2019 22:10:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i7oKs-0004wV-JS for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Sep 2019 22:10:06 +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 1i7oKs-0004qZ-3J for pgsql-hackers@lists.postgresql.org; Tue, 10 Sep 2019 22:10:06 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7oKk-0001BH-Mn for pgsql-hackers@postgresql.org; Tue, 10 Sep 2019 22:10:05 +0000 Received: by mail-wm1-x344.google.com with SMTP id n10so1210264wmj.0 for ; Tue, 10 Sep 2019 15:09:58 -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; bh=HEI516mat8zLB+euYY2Op1kIQH9X8MypegZBybw7GbY=; b=fWNZm0rOtkknIj69CIUaJZEXcfhH3IyLqzODToeqjXmHlUB/GYtQYluBmFnFwV+CPr zZwLX56sF7nDxmQySTzBGWGl3vmb1PpcR0w+QYb54tu1MHF54z0sywOY1iTYGDh2aR04 +dxja+K43hCYzawtJHwmrArPl5BJhLMnsL02tt/0CgojOy5xq/us5OIdjQY5rwY4YI1n i2iqVAkEqWrMSJOJAbFz6P61qqqvKd2MxCjoNg3V16qJ4jpt7eW6akmbqNuO6SabPi9P WdnPJDTC1Un5k5BFz3uq8lxr9KCP04aWBYLhYFZJ6J0W9FXU0CSBK2mg9iH6sVRaBl9a 9Peg== 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; bh=HEI516mat8zLB+euYY2Op1kIQH9X8MypegZBybw7GbY=; b=kAmlTH+8X3Q9kZQg8OXbfIY+a+hPWzz8GuZ3VBywXpU3wbOFo0WNgBDc/g0I8rQTAa tXOZpry0uCwfee+0yrIZMCgATE4Es/dbXo/qBKYsW4eXvt0meE0Tms/OZcjVJ2oPe9TE opBIIvomZlK4YWcUrMyXMSUocMqdOPBTHrwQ0JkxHcE1hjBF34AjRT6S4piylu4Tsy8v /LiRFw30PB6enXXkyMaRLOt2j/ESs+r6yRAHlGlRIOXaMMjh1KxpZruev/JIkcwuip5o dVoNjaGWggQXprBXQh/5jIe3yfXziO7nkHNMiwaSkOFW2Em7loK0ygDgNQIp1bfcqbeN 7I1Q== X-Gm-Message-State: APjAAAVf6jQLYItPSOS2tjPIHBBK7SfQJusus6swaazMoP/HMOryIHeK mYc7/awkIiNvhwqxNF+LP7j3og== X-Google-Smtp-Source: APXvYqyoZINbQscjYdUVzsYJ7qEBizjZqYmySM9qCbUNW8NcxgCosdmlFy1S/oaTSIkhLYWF+hhCQg== X-Received: by 2002:a05:600c:25a:: with SMTP id 26mr1145649wmj.60.1568153043594; Tue, 10 Sep 2019 15:04:03 -0700 (PDT) Received: from localhost ([88.157.94.57]) by smtp.gmail.com with ESMTPSA id n8sm1823553wma.7.2019.09.10.15.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 15:04:02 -0700 (PDT) Date: Wed, 11 Sep 2019 00:03:58 +0200 From: Tomas Vondra To: Nikita Glukhov Cc: Alvaro Herrera , "pgsql-hackers@postgresql.org" , Robert Haas , Tom Lane , Nikolay Shaplov , Oleg Bartunov Subject: Re: [PATCH] Opclass parameters Message-ID: <20190910220358.6tj37k4v6vyaqac7@development> References: <20190903220254.GA22389@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Sep 10, 2019 at 04:30:41AM +0300, Nikita Glukhov wrote: >On 04.09.2019 1:02, Alvaro Herrera wrote: > >>On 2019-Jun-11, Tomas Vondra wrote: >> >>>1) We need a better infrastructure to parse opclass parameters. For >>>example the gtsvector_options does this: >>I think this is part of what Nikolay's patch series was supposed to >>address. But that one has been going way too slow. I agree we need >>something better. > >API was simplified in the new version of the patches (see below). > >>>2) The 0001 part does this in index_opclass_options_generic: >>> >>> get_opclass_name(opclass, InvalidOid, &str); >>> >>> ereport(ERROR, >>> (errcode(ERRCODE_INVALID_PARAMETER_VALUE), >>> errmsg("operator class \"%s\" has no options", >>> opclassname.data))); >>> >>>But that's a bit broken, because get_opclass_name() appends the opclass >>>name to 'str', but with a space at the beginning. >>Yeah, I think just exporting get_opclass_name from ruleutils.c is a bad >>idea. Sounds like we need a (very small) new function in lsyscache.c >>that does the job of extracting the opclass name, and then the ruleutils >>function can call that one to avoid duplicated code. > >I decided to add new function generate_opclass_name() like existing >generate_collation_name(), and to reuse static get_opclass_name(). > >>Anyway, this patchset doesn't apply anymore. Somebody (maybe its >>author this time?) please rebase. > >New version of rebased patches is attached: > >1. Opclass parameters infrastructure. > > API was completely refactored since the previous version: > > - API was generalized for all AMs. Previously, each AM should implement > opclass options parsing/passing in its own way using its own support >  function numbers. > Now each AMs uses 0th support function (discussable). Binary bytea values > of parsed options are passed to support functions using special expression > node initialized in FmgrInfo.fn_expr (see macro PG_GET_OPCLASS_OPTIONS(), > get_fn_opclass_options(), set_fn_opclass_options). > I very much doubt these changes are in the right direction. Firstly, using 0 as procnum is weird - AFAICS you picked 0 because after moving it from individual AMs to pg_amproc.h it's hard to guarantee the procnum does not clash with other am procs. But ISTM that's more a hint that the move to pg_amproc.h itself was a bad idea. I suggest we undo that move, instead of trying to fix the symptoms. That is, each AM should have a custom procnum. Also, looking at fn_expr definition in FmgrInfo, I see this fmNodePtr fn_expr; /* expression parse tree for call, or NULL */ it seems like a rather bad idea to reuse that to pass options when it's clearly not meant for that purpose. > - Introduced new structure local_relopts (needs a better name, of course) > with a set of functions for opclass/AM options definition. The parsing > was moved into index_opclass_option(). That was necessary for mixing of >  AM- and opclass-specific options. Opclasses now extend the structure with > AM's options adding their own options. See patch #4 for an example. > OK. No opinion on this change yet. >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? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services