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 1k1sXB-0001eD-Rc for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Aug 2020 14:30:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k1sX9-0004kA-H8 for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Aug 2020 14:30: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 1k1sX9-0004jD-77 for pgsql-hackers@lists.postgresql.org; Sat, 01 Aug 2020 14:30:47 +0000 Received: from mail-ej1-x641.google.com ([2a00:1450:4864:20::641]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1k1sX3-0008JH-1P for pgsql-hackers@postgresql.org; Sat, 01 Aug 2020 14:30:46 +0000 Received: by mail-ej1-x641.google.com with SMTP id c16so13836115ejx.12 for ; Sat, 01 Aug 2020 07:30:40 -0700 (PDT) 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=59vhAKFm5Ljw7wQH14UEGoFXeYGC8W7r6FrNfNkTY/c=; b=aqKIbT44yG6issjzKK5qAFzH+8UX3Y3tfPn318MEm4JMYogyNsJMEle3ya4egcb7VE zJQcH6H+EqwIbaC4ku+e2p4FCmzy7JCRoOUfQVKKvGOoHXDIEORO1ifNlSBbds0bB9jP qADsUnJF/q5IIDfJbFB4ms8QAkIP7NSIFvreuomRMWcQRykCW9GsjJcg0H7ZuyFFNcEl ehwldvx+8spjHWJ1vvXyNYE7J1HCRlvGhziIbxvlIB6FATHRaQnY1nnm4zgHuXT1mf6h z9/lL3UbSsX2qzw8eZoGxCYprbyzYJzDY82OwgJe/RsFTbkU0IqyZ4LA78E0L2lbe6IC dzUg== 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=59vhAKFm5Ljw7wQH14UEGoFXeYGC8W7r6FrNfNkTY/c=; b=Hq9K0dVbQ3jf94Su3EWLeVlwLj2nZFhti8RvMlip2yTxDiQXRsLdJiDW2tyJ6hYstz SwLNt0txc8mdm+ACpkCZi6CHKENQ0PUbOqqOAC37Ns1s9f0NOwW/j1Obrd/j9Ci/y/Yz zpnNYzh3aaMzEtTk1Xi9UteF64kdZXr4vHPKOdczqdCmn+qLfffB+7mG4K+Uz9+maON+ U6b7SCdRrLft+Ufr38VKf0mDNYDwqUC/JVU5RZ6qJzPBnkVi36Lz0491kGLUAZHrOXg3 i78loO1HGcmfKOwqviJEnbSHXMIvUV9QH+9/wc48+pQp0XAI51q3W/3JkXbe7P5ItJdN Ij1A== X-Gm-Message-State: AOAM533IBOv5At9f25z7AaI29b10XqltxC+V1qcqW7anpLwKgN0zh6wI Xrbs9brn0vORFOr3sTMJZjY= X-Google-Smtp-Source: ABdhPJxA/Yf/6DQidaAq+Lt/AUFGyqes3sgweLXnnrthWrr//I988v/VnUzuQV5IXXSgzroCpwXyvQ== X-Received: by 2002:a17:906:a142:: with SMTP id bu2mr9227295ejb.277.1596292238556; Sat, 01 Aug 2020 07:30:38 -0700 (PDT) Received: from localhost (dslb-178-005-232-008.178.005.pools.vodafone-ip.de. [178.5.232.8]) by smtp.gmail.com with ESMTPSA id t6sm11394348ejc.40.2020.08.01.07.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Aug 2020 07:30:37 -0700 (PDT) Date: Sat, 1 Aug 2020 16:33:34 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Tom Lane Cc: Justin Pryzby , Pavel Stehule , David Steele , Nikita Glukhov , Alvaro Herrera , David Fetter , Thomas Munro , Thomas Munro , Oleksandr Shulgin , Robert Haas , Andres Freund , Michael Paquier , Oleg Bartunov , Peter Eisentraut , pgsql-hackers@postgresql.org Subject: Re: [HACKERS] [PATCH] Generic type subscripting Message-ID: <20200801143334.d7d3tsb7gaezx6vq@localhost> References: <10957.1584899227@sss.pgh.pa.us> <23946.1584906094@sss.pgh.pa.us> <20200516122802.g4qbfxkr2zr7nlv2@localhost> <20200719191016.GW23581@telsasoft.com> <20200720160216.lav6vmyv6wbg7bfl@localhost> <20200728134308.qsstgwyyx3ngsfcw@localhost> <1808585.1596224122@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1808585.1596224122@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Fri, Jul 31, 2020 at 03:35:22PM -0400, Tom Lane wrote: > > I started to look through this again, and really found myself wondering > why we're going to all this work to invent what are fundamentally pretty > bogus "features". The thing that particularly sticks in my craw is the > 0005 patch, which tries to interpret a subscript of a JSON value as either > integer or text depending on, seemingly, the phase of the moon. I don't > think that will work. For example, with existing arrays you can do > something like arraycol['42'] and the unknown-type literal is properly > cast to an integer. The corresponding situation with a JSON subscript > would have no principled resolution. > > It doesn't help any that both coercion alternatives are attempted at > COERCION_ASSIGNMENT level, which makes it noticeably more likely that > they'll both succeed. But using ASSIGNMENT level is quite inappropriate > in any context where it's not 100% certain what the intended type is. > > The proposed commit message for 0005 claims that this is somehow improving > our standards compliance, but I see nothing in the SQL spec suggesting > that you can subscript a JSON value at all within the SQL language, so > I think that claim is just false. It's due to my lack of writing skills. As far as I can remember the discussion was about JSON path part of the standard, where one allowed to use float indexes with implementation-defined rounding or truncation. In this patch series I'm trying to think of JSON subscript as an equivalent for JSON path, hence this misleading description. Having said that, I guess the main motivation behind 0005 is performance improvements. Hopefully Nikita can provide more insights. Overall back when 0005 patch was suggested its implementation looked reasonable for me, but I'll review it again. > Maybe this could be salvaged by flushing 0005 in its current form and > having the jsonb subscript executor do something like "if the current > value-to-be-subscripted is a JSON array, then try to convert the textual > subscript value to an integer". Not sure about what the error handling > rules ought to be like, though. I'm fine with the idea of separating 0005 patch and potentially prusuing it as an independent item. Just need to rebase 0006, since Pavel mentioned that it's a reasonable change he would like to see in the final result.