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 1im48v-0004GX-0V for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Dec 2019 23:08:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1im48t-0007ha-Lh for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Dec 2019 23:08:07 +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 1im48t-0007hT-6x for pgsql-hackers@lists.postgresql.org; Mon, 30 Dec 2019 23:08:07 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1im48l-0004IS-VZ for pgsql-hackers@postgresql.org; Mon, 30 Dec 2019 23:08:06 +0000 Received: by mail-wm1-x341.google.com with SMTP id p17so728629wmb.0 for ; Mon, 30 Dec 2019 15:07:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=H7ffzKmVQKIr0TGWYkMCXwKSe4qkbdAUZRblEif/XXQ=; b=lH0ByjFuAil7GliRl5QMYlGyrnin8w0LxtPQgnZl4lQHtOwC616YoDbNb4BqTz55oM D0mxJbyKt5Y2G//ImXaMVk6/3mDl60J/ZmN5ec6ADk5iiVi8QS+3lVhnifvqzyoJYFo9 hbTDKOizoVTWJ3vp883f90Q3lsH3+9Aud3TYF+w+tknKnZ/zAKWh96YqHhoQo7vv5A5j NL2LqwCTy37A14OFreiuoORie1qztTyivWBt/nLaEyZrLWKLcB0ei6/6C6Pa1QKRysD5 RJVPwGpl1zUPJ9TmNaTJ2jWfrKleES0h5gkhBjL/yNIUq/oLVOOWipACezAu9FoNKKUe BgPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=H7ffzKmVQKIr0TGWYkMCXwKSe4qkbdAUZRblEif/XXQ=; b=eBlXV511KIH//kmCN3Nu4KdXNXlIgEAK3ZYo38qXK3HTQ/Nz9r7mKQYf89H+zsSztj K/vTFz+yyQrDeqDZmyElZPHovtNug1R10l8sdFmlpmdB1di7b+gRtGJh02dG9daxQsNq wphqNHWCt4xYAVrwA2T8/o3pjc4s8pcJVA7CmvqEaLt+6j4JH/vqSMJYBwtClnOyiYWF j8N8AL6z7AyUe2BR8N2AHU7XCQ7Q971kP+YH8gdg7mw2tZrv59FBTPKGx0RtZ3k/r94z RVH3SdYQKu5OcDxB0Uu9WzFwrDjlNRI3ey1hAF04xbB8cJ760xiZFdkiT8uqXsm7e0Vd xMWg== X-Gm-Message-State: APjAAAX+BkXWfXN5rXOzB1iFErf1wnhBT5S9J+xuXYwoZsanNtXNjl8/ Awydbt0OHNMSmjSkikOyZlNSJeBQefxOwMrgGE/mXEzNnXy9X0NUszI0eOAIWKSekhV1jOn8YcC t25zs+42tk8UiGPG/MeUvAzhVa85JH4fzXxVVPk42p+VPE9KXCQjDzYB/Va/zfo/zOYwtn2pvt0 ndL/Rgu4VjElFe X-Google-Smtp-Source: APXvYqxz0tKwLozgo/Md97bGmeBGJe61uNdYg206CoUWtuW/EKHl5zfEbHJGa9iln/oqfeWOK/wJjw== X-Received: by 2002:a7b:cc14:: with SMTP id f20mr1099010wmh.58.1577747278706; Mon, 30 Dec 2019 15:07:58 -0800 (PST) Received: from [10.8.8.7] ([185.94.189.189]) by smtp.gmail.com with ESMTPSA id i8sm47351169wro.47.2019.12.30.15.07.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Dec 2019 15:07:58 -0800 (PST) Subject: Re: Allow an alias to be attached directly to a JOIN ... USING To: Peter Eisentraut , Fabien COELHO , Alvaro Herrera Cc: Thomas Munro , pgsql-hackers References: <20190917173742.GA8735@alvherre.pgsql> <9a5c9ed2-1dd7-8c2a-6b90-0de54f4c13a1@2ndquadrant.com> From: Vik Fearing Message-ID: <8568b66d-405d-5d83-ac8c-e107f1b9f113@2ndquadrant.com> Date: Tue, 31 Dec 2019 00:07:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <9a5c9ed2-1dd7-8c2a-6b90-0de54f4c13a1@2ndquadrant.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 30/12/2019 22:25, Peter Eisentraut wrote: > On 2019-12-24 19:13, Fabien COELHO wrote: >>>> Indeed, that seems like a problem, and it's a good question.  You can >>>> see this on unpatched master with SELECT x.filler FROM >>>> (pgbench_tellers AS t JOIN b USING (bid)) AS x. >>> >>> I'm not sure I understand why that problem is a blocker for this patch. >> >> As discussed on another thread, >> >>       >> https://www.postgresql.org/message-id/flat/2aa57950-b1d7-e9b6-0770-fa592d565dda@2ndquadrant.com >> >> the patch does not conform to spec >> >>     SQL:2016 Part 2 Foundation Section 7.10 >> >> Basically "x" is expected to include *ONLY* joined attributes with >> USING, >> i.e. above only x.bid should exists, and per-table aliases are >> expected to >> still work for other attributes. > > I took another crack at this.  Attached is a new patch that addresses > the semantic comments from this and the other thread.  It's all a bit > tricky, comments welcome. Excellent!  Thank you for working on this, Peter. One thing I notice is that the joined columns are still accessible from their respective table names when they should not be per spec.  That might be one of those "silly restrictions" that we choose to ignore, but it should probably be noted somewhere, at the very least in a code comment if not in user documentation. (This is my reading of SQL:2016 SR 11.a.i) -- Vik Fearing