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 1iVM0X-0000yk-DW for pgsql-performance@arkaria.postgresql.org; Thu, 14 Nov 2019 20:46:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVM0T-0001Bt-EY for pgsql-performance@arkaria.postgresql.org; Thu, 14 Nov 2019 20:46: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 1iVM0T-0001BW-4R for pgsql-performance@lists.postgresql.org; Thu, 14 Nov 2019 20:46:21 +0000 Received: from us-smtp-2.mimecast.com ([205.139.110.61] helo=us-smtp-delivery-1.mimecast.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVM0P-0007k6-8A for pgsql-performance@lists.postgresql.org; Thu, 14 Nov 2019 20:46:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573764374; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1DPnwMHQ7rCwJINRloaNqEy07hrhvjyijIyV1TXx9Fs=; b=I7vDzlU0gqCLoJPBcHey3aCIsc4l0m9l9HDj5ak2fG1zznZHyF2N1Ue3Z/4yX2sxEacJYN ET2mXt1LJIZ+KcE6Aosv5+FzyOb9qqbNOmKYQTKmUcfz2LftXNMckg2xCndD5uMv8ngD+C tdsyvX9Zww6fmQ93RqeLJyUpvJRM3ro= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-ikF6MySbOxWhO9n0kIj9IQ-1; Thu, 14 Nov 2019 15:46:12 -0500 Received: by mail-qv1-f70.google.com with SMTP id i11so5010084qvh.3 for ; Thu, 14 Nov 2019 12:46:12 -0800 (PST) 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:content-transfer-encoding; bh=rViisdmTLFXBwHFIpoasxDgIswyPJNs28SrLiTGKXl4=; b=BUVW7AIuL7h+c83YcUA5FbfK5W/ssZsiSU8AvwMYVIG7XvRdQJ25Gy98+lKuJxjvfU z+Oi7lxgLnbQYCA6Oy7MyFdN5qdMIzDFEalry/tzdl370GvJ/cW5tU1cWlFhnbtd1FXW 1lRaL9D8/bmBjAamFHrYnKf7w3wNOauF80mxno/O7m9V7sxXB+jzntS9qFmXOjBJFA3L vkArqTYTMf2+8RK7LFO0lj10m2FqIUw1FQcooIiYgrwZ3atxs5OR3CUpHhzl/02wbbAP bFdeOV5vfL06mPHDrTcwQeShVCgz1K/DrNjvdKVeY9WvkWaytoI7vXCT8y7esL+9fwUD G2iA== X-Gm-Message-State: APjAAAW+sDNfPV4T5U5efDVqA7No7n01jmhFVkp3VU43ik4hVSnZmO2K JJijISu7Z2FqXd59yis8T38ZL/kTE71rm6NVt19EdGS8AeHdj1tDdDnictR+9aEvZdit48Nnv9v OQdo8ua8oHU0m7uyaiByLxo6dqqJsOjBQEfcZCA== X-Received: by 2002:a37:dc44:: with SMTP id v65mr9007537qki.72.1573764371889; Thu, 14 Nov 2019 12:46:11 -0800 (PST) X-Google-Smtp-Source: APXvYqxKk6EYjBBT6yI/rBfA4cj5g6R5Gdo7nJdKWu/iRcx+30LWKOLpfVXAcCyCc24xt2AqoxOLBw== X-Received: by 2002:a37:dc44:: with SMTP id v65mr9007498qki.72.1573764371476; Thu, 14 Nov 2019 12:46:11 -0800 (PST) Received: from localhost.localdomain (c-24-61-8-151.hsd1.ma.comcast.net. [24.61.8.151]) by smtp.gmail.com with ESMTPSA id a3sm2992762qkf.76.2019.11.14.12.46.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Nov 2019 12:46:10 -0800 (PST) Reply-To: jesper.pedersen@redhat.com Subject: Re: JSON path To: Tom Lane Cc: pgsql-performance@lists.postgresql.org References: <71a1d71e-5263-2980-117c-066a37e481bc@redhat.com> <4339.1573754676@sss.pgh.pa.us> From: Jesper Pedersen Organization: Red Hat Message-ID: <17beac8b-e4e5-d37d-3412-3cbb2052090d@redhat.com> Date: Thu, 14 Nov 2019 15:46:08 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <4339.1573754676@sss.pgh.pa.us> Content-Language: en-US X-MC-Unique: ikF6MySbOxWhO9n0kIj9IQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 11/14/19 1:04 PM, Tom Lane wrote: > As of v12, that WITH will get flattened, so that you still end up > with three invocations of jsonb_path_query_first, as EXPLAIN VERBOSE > will show you. You could write "WITH foo AS MATERIALIZED ..." to > prevent that, but then you'll need to stick the WHERE clause inside > the WITH or you'll end up running jsonb_path_query_first for every > row of tbl. >=20 > With >=20 > explain verbose WITH foo AS materialized (select > id, > col1, > col2, > jsonb_path_query_first(data,'$.lvl1.lvl2.lvl3.lvl4.lvl5') as jsondata > from tbl where id =3D 1 ) > select > col1, > col2, > jsondata->'val1'->'text()' as val1, > jsondata->'val2'->'text()' as val2, > jsondata->'val3'->'text()' as val3 > from foo; >=20 Thanks Tom ! This works :) I owe you one. Best regards, Jesper