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 1iPrBq-00005P-C5 for pgsql-general@arkaria.postgresql.org; Wed, 30 Oct 2019 16:51:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iPrBp-0001XJ-3N for pgsql-general@arkaria.postgresql.org; Wed, 30 Oct 2019 16:51:21 +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 1iPrBo-0001XB-O3 for pgsql-general@lists.postgresql.org; Wed, 30 Oct 2019 16:51:20 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iPrBk-0006q6-58 for pgsql-general@lists.postgresql.org; Wed, 30 Oct 2019 16:51:20 +0000 Received: by mail-wm1-x331.google.com with SMTP id p21so2867818wmg.2 for ; Wed, 30 Oct 2019 09:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ocado.com; s=google; h=reply-to:subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=mT1+U1UUec7mR9LZkw1/paBY+pP0Suo35+BXikdDZzw=; b=w2urslCsI5hhQZYCHt3A/av3CavShr86wcz0j+FBlcMKe1cD51AevNxG50IUaniQ1Q /NDsKFtGmwZwV9CRqeX4KUbBNs4eCPNHqNYYVOyXFc1xHdvOaS31g2AsJcENvZAHzhkV UtUcwvvDLYH6Ve8KqiFzUX9APcqzIVroxL5imO8aNSkoQW2HuxNwJ8WAmvv/f47/1Dsr 9wh9ltg45Io88mYuig/7XLvb0RpATTsLKX/7ZXoY5IyDN5lakjgILLYfHakiqctSDmlA fzSqcz75Q4spDHLkXydP0woYpAo06rfIKn0p2Xs6kMmqRJ8uY+FG7Z3f92uOIE7A7GX3 0gaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language; bh=mT1+U1UUec7mR9LZkw1/paBY+pP0Suo35+BXikdDZzw=; b=XjPdlHS1n1ITmNE/PGvwr9FsdrErSB5DRUnO6x28NUy/9Of3X2BfZBhrZg4jUY/2nx P+okuw2kisMvucUC/sjaDJ9HaGOnvrq8+YtfTxqSLPurkMpLgInOigTQKxICsooYIi2r nLS8xU+C/7bykyBzK0tY40UZUNEMymF8kzrci/Vfsny1Lbypohe8vS8kb0yYIrUPXxn9 RdDTdL/yIELGdf/VJLWtl5NLsDIQa0AAUgsFRBK6llfP8fNVvX9AEmApG8aoJbiGlLGK FrYkSmCoHHjUyjv8JgbpExUho+4LkrFIXl+A4E2E9Qi4DtJsK4wnuH4ZM7kUBJpFCyjT ydPQ== X-Gm-Message-State: APjAAAXM4aciaS+lGpqdlqBbCNsv71CH2yoihboChPebWh2d+ANqofbn 60qAE/+HcWzxGhRUemQg3IV/ebRypm9jGZvLEqu2ND3TtrB9QogMzpBrljvwsQhBdFjLYubHk62 KKrt9A067n65whUBCTM/mvwZi85vHQw== X-Google-Smtp-Source: APXvYqwrnmBxHMZM/pwV7pRyV9xnoV/yj8fQVAhVETvS2+DNiYuIVqf63PEIS6T2jvwLI3mQfmEr4A== X-Received: by 2002:a7b:c1da:: with SMTP id a26mr428206wmj.84.1572454274813; Wed, 30 Oct 2019 09:51:14 -0700 (PDT) Received: from [10.62.12.22] ([91.206.0.63]) by smtp.gmail.com with ESMTPSA id w22sm604503wmc.16.2019.10.30.09.51.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Oct 2019 09:51:14 -0700 (PDT) Reply-To: f.venchiarutti@ocado.com Subject: Re: Automatically parsing in-line composite types To: Mitar , Merlin Moncure Cc: Dave Cramer , "pgsql-generallists.postgresql.org" References: From: Fabio Ugo Venchiarutti Organization: Ocado Technology Message-ID: <25e4fa14-28c9-c2b3-404f-2574d111cdeb@ocado.com> Date: Wed, 30 Oct 2019 16:51:13 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 30/10/2019 16:15, Mitar wrote: > Hi! > > On Wed, Oct 30, 2019 at 8:37 AM Merlin Moncure wrote: >> Check out libpqtypes: https://github.com/pgagarinov/libpqtypes > > Interesting. I have looked at the code a bit but I do not find how it > determines the type for inline compound types, like the ones they > appear in my original SQL query example. Could you maybe point me to > the piece of code there handling that? Because to my > understanding/exploration that information is simply not exposed to > the client in any way. :-( > >> it does exactly what you want. It's a wrapper for libpq that provides >> client side parsing for the binary protocol with array and composite >> type parsing. > > It looks to me that it does parsing of composite types only if they > are registered composite types. But not for example ones you get if > you project a subset of fields from a table in a subquery. That has no > registered composite type? > > Also, how you are handling discovery of registered types, do you read > that on-demand from the database? They are not provided over the wire? > >> Virtually any >> non-C client application really ought to be using json rather than the >> custom binary structures libpqtyps would provide. > > I thought that initially, too, but then found out that JSON has some > heavy limitations because the implementation in PostgreSQL is standard > based. There is also no hook to do custom encoding of non-JSON values. > So binary blobs are converted in an ugly way (base64 would be better). > You also loose a lot of meta-information, because everything non-JSON > gets converted to strings automatically. Like knowing what is a date. > I think MongoDB with BSON made much more sense here. It looks like > perfect balance between simplicity of JSON structure and adding few > more useful data types. > > But yes, JSON is great also because clients often have optimized JSON > readers. Which can beat any other binary serialization format. In > node.js, it is simply the fastest there is to transfer data: > > https://mitar.tnode.com/post/in-nodejs-always-query-in-json-from-postgresql/ > > > Mitar > Then perhaps, as opposed to wedging this into the tabular paradigm, a transition to more targeted support for hierarchical result representation would be preferable, just done directly by the backend an rendered by libpq... (perhaps still encapsulated as a DataRow field not to break the traditional model. Or perhaps a special RowDescription-like message in the backend protocol? Not my place to strongly push proposals there). There's a lot of room for optimisation if done natively (think label deduplication at the source. Not sure if BSON works this way too). There's also the problem of independent implementations of the protocol...AFAIK the JDBC client is not a wrapper to libpq and they'd also have to break their result surfacing paradigms to make it work... Sounds like an enormous risk & undertaking for the hackers TBH, and I currently see another limiting factor to idea's popularity: as it stands, advanced SQL is daunting for the much of the industry, and IMHO the queries to generate arbitrarily structured & lightweight inline types/relations are relatively verbose and deeply nested (eg: last time I checked, stripping/renaming some attributes from a relation required subselecting them, and - prehaps due to PEBCAK - can't think of a way to create results as associative arrays indexed by attributes). For this to gain traction, a more streamlined syntax/functions/operators for precision work may be necessary, or the result would only satisfy a narrow set of users who are already intimate with the state of affairs. Can't help thinking that the current JSON-over-field pinhole may already be at the sweet spot between usefulness and inter-operability with existing systems. Just the SQL side of it could be less noisy and, yes, data type pidgeonhole problem could benefit from something like a GUC setting to electively break standard JSON compatibility, function arguments or else. -- Regards Fabio Ugo Venchiarutti OSPCFC Network Engineering Dpt. Ocado Technology -- Notice: This email is confidential and may contain copyright material of members of the Ocado Group. Opinions and views expressed in this message may not necessarily reflect the opinions and views of the members of the Ocado Group. If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses. References to the "Ocado Group" are to Ocado Group plc (registered in England and Wales with number 7098618) and its subsidiary undertakings (as that expression is defined in the Companies Act 2006) from time to time. The registered office of Ocado Group plc is Buildings One & Two, Trident Place, Mosquito Way, Hatfield, Hertfordshire, AL10 9UL.