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 1kpxrW-0004CS-Tz for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Dec 2020 18:18:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kpxrT-00064U-Uk for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Dec 2020 18:18:47 +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 <9erthalion6@gmail.com>) id 1kpxrT-00064N-KB for pgsql-hackers@lists.postgresql.org; Thu, 17 Dec 2020 18:18:47 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kpxrQ-0008VP-1S for pgsql-hackers@postgresql.org; Thu, 17 Dec 2020 18:18:46 +0000 Received: by mail-ej1-x62c.google.com with SMTP id ce23so39272026ejb.8 for ; Thu, 17 Dec 2020 10:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=B4VP2t8pT3VOle49Jek/jxwRMFC8ZLVbMCJY3UZGWvg=; b=itB6ej/Bcr/kfYyAAfsqO84ATf8rHrmcL9oIrLbazTJOgk85It5WXnlQ1+0onmAOmj 2odvYfJOavY6ohap42Kuzi7MfHoPkcb/3k0VJ4VIH5PINe2zOBuITtFtjLEZSClAs0E/ 3oHKWavWiVKaMe3WtQkn30x//t89/Ez4GFn8tK3IuO/LBkIt+m2NbfKZrxvseAFfk3J5 DPHCdrmo32A9hb6RMWX7hi2PZiSNIH5UX53NZMtsoXXGGYRoHdVCzycqQEQiyJgmHOll OWbKV1n4l7FzC2Asy+H7vh6+QlT8/+plz/N2HEO/0Nq4kc3i7pNZImgnptr3hYJl/m0c Dz/w== 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=B4VP2t8pT3VOle49Jek/jxwRMFC8ZLVbMCJY3UZGWvg=; b=XjrexSATTxAKHmMzbVQYSihCWeNkqQ3ypVsdKXXIi708eu7XYHsJbd8poMB/pyHT0E hTCvTQhzviTk8zuqYbBWLVnwpQX4R83e5a4jdh0nLFtsDASoGVRbJ35olgTPdF5LIust kboqHwAwmD6LUfkdKzR9jgBh/3tMqV8hDkqPxtAY06UjWGlijxKQgA/ZRdLK31Ga+M8b MCAzkP0bMqoYI2ld/hbAMTlO61hvFlO+lHciOxG+xaOPIlNimfanYz7JPFybjj7D3BqP WhA62aduG0N0/XyENicqpb41osJReRWQdWRZxxG/x+Kg2wyx2Z/5NXaLEInbuNbRF1/g n7xg== X-Gm-Message-State: AOAM531UxiCliK6j5MFyZsaxZbsXy9IcThvm/Jpf/E7Kd85zIWdOlKQg spI578Y8cxpODEGAZU67Qh0= X-Google-Smtp-Source: ABdhPJyDW365BNkXSjePllUkL3ThsuEXcxmpMdoi94Uxlmf8IMckQfTi73M6g80D2z4UT85CmSzwHA== X-Received: by 2002:a17:906:7a18:: with SMTP id d24mr281250ejo.324.1608229122362; Thu, 17 Dec 2020 10:18:42 -0800 (PST) Received: from localhost (dslb-094-222-016-204.094.222.pools.vodafone-ip.de. [94.222.16.204]) by smtp.gmail.com with ESMTPSA id x17sm13102311edq.77.2020.12.17.10.18.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Dec 2020 10:18:41 -0800 (PST) Date: Thu, 17 Dec 2020 19:20:03 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Tom Lane Cc: Pavel Stehule , Andres Freund , Alexander Korotkov , Justin Pryzby , David Steele , Nikita Glukhov , Alvaro Herrera , David Fetter , Thomas Munro , Oleksandr Shulgin , Robert Haas , Michael Paquier , Oleg Bartunov , Peter Eisentraut , PostgreSQL Hackers Subject: Re: [HACKERS] [PATCH] Generic type subscripting Message-ID: <20201217182003.nrhxqqiutfwjesen@localhost> References: <20201209013003.hj4ealuvwmzvczs2@alap3.anarazel.de> <3459640.1607477907@sss.pgh.pa.us> <3544235.1607482944@sss.pgh.pa.us> <3635350.1607536188@sss.pgh.pa.us> <20201209183704.x5ue5rctdwmhmlmy@localhost> <3674425.1607540422@sss.pgh.pa.us> <3724341.1607551174@sss.pgh.pa.us> <20201211151957.wqlnxdqjwsd7azzd@localhost> <4110100.1607701087@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4110100.1607701087@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Fri, Dec 11, 2020 at 10:38:07AM -0500, Tom Lane wrote: > Dmitry Dolgov <9erthalion6@gmail.com> writes: > >> On Wed, Dec 09, 2020 at 04:59:34PM -0500, Tom Lane wrote: > >> 0001 adds the ability to attach a subscript handler to an existing > >> data type with ALTER TYPE. This is clearly going to be necessary > >> if we want extension types to be able to use this facility. The > >> only thing that I think might be controversial here is that I did > >> not add the ability to set pg_type.typelem. > > > I'm curious what could be the use case for setting pg_type.typelem for > > subscripting? I don't see this that much controversial, but maybe I'm > > missing something. > > If you want the result of subscripting to be "text" or some other built-in > type, then clearly there's no need to use typelem for that, you can just > refer to the standard OID macros. The potential use-case that I thought > of for setting typelem is where an extension defines types A and B and > would like subscripting of B to yield A. Installing A's OID as B.typelem > would save a catalog lookup during subscript parsing, and remove a bunch > of edge failure cases such as what happens if A gets renamed. However, > given the dependency behavior, this would also have the effect of "you > can't drop A without dropping B, and you can't modify A in any interesting > way either". That would be annoyingly restrictive if there weren't any > actual physical containment relationship. But on the other hand, maybe > it's acceptable and we just need to document it. > > The other issue is what about existing stored SubscriptingRef structs. > If our backs were to the wall I'd think about removing the refelemtype > field so there's no stored image of typelem that needs to be updated. > But that would incur an extra catalog lookup in array_exec_setup, so > I don't much like it. If we do add the ability to set typelem, I'd > prefer to just warn people to not change it once they've installed a > subscript handler. > > Anyway, between those two issues I'm about -0.1 on adding a way to alter > typelem. I won't fight hard if somebody wants it, but I'm inclined > to leave it out. Yes, makes sense. Thanks for the clarification. > On Wed, Dec 09, 2020 at 07:37:04PM +0100, Dmitry Dolgov wrote: > > On Wed, Dec 09, 2020 at 12:49:48PM -0500, Tom Lane wrote: > > > > The jsonb parts now have to be > > rebased onto this design, which I'm assuming Dmitry will tackle > > Yes, I'm already on it, just couldn't keep up with the changes in this > thread. While rebasing the jsonb patch I found out that the current subscripting assignment implementation in transformAssignmentIndirection always coerce the value to be assigned to the type which subscripting result suppose to have (refrestype). For arrays it's fine, since those two indeed must be the same, but for jsonb (and for hstore I guess too) the result of subscripting is always jsonb (well, text type) and the assigned value could be of some other type. This leads to assigning everything converted to text. Originally this coercion was done in the type specific code, so I hoped to put it into "transform" routine. Unfortunately "transform" is called before that (and could not be called later, because type information from sbsref is required) and all the other hooks are apparently too late. Probably the most straightforward solution here would be to add a new argument to transformAssignmentIndirection to signal if coercion needs to happen or not, and allow the type specific code to specify it via SubscriptingRef. Are there any better ideas?