Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aYgJt-0001yK-A3 for pgsql-general@arkaria.postgresql.org; Wed, 24 Feb 2016 20:46:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aYgJs-0006HO-0N for pgsql-general@arkaria.postgresql.org; Wed, 24 Feb 2016 20:46:00 +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_SHA384:256) (Exim 4.84) (envelope-from ) id 1aYgJq-0006GR-Lg for pgsql-general@postgresql.org; Wed, 24 Feb 2016 20:45:58 +0000 Received: from tamriel.snowman.net ([2001:4830:167b::11]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aYgJn-00042Y-NZ for pgsql-general@postgresql.org; Wed, 24 Feb 2016 20:45:58 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id B84BD5F794; Wed, 24 Feb 2016 15:45:53 -0500 (EST) Date: Wed, 24 Feb 2016 15:45:53 -0500 From: Stephen Frost To: Adam Guthrie Cc: pgsql-general@postgresql.org Subject: Re: "plan should not reference subplan's variable" when using row level security Message-ID: <20160224204553.GK3127@tamriel.snowman.net> References: <20160224202751.GI3127@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="2WS97oupGEGbYNpW" Content-Disposition: inline In-Reply-To: X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/3.13.0-77-generic (x86_64) X-Uptime: 15:35:24 up 1 day, 17:28, 3 users, load average: 0.18, 0.13, 0.14 User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org --2WS97oupGEGbYNpW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Adam Guthrie (asguthrie@gmail.com) wrote: > On 24 February 2016 at 20:27, Stephen Frost wrote: > > Yeah, looks like a bug to me. My gut reaction is that we're pulling up > > a subquery in a way that isn't possible and that plan shouldn't be > > getting built/considered. >=20 > Thanks - shall I go ahead and submit a bug report? Sure. > > As a work-around, until we fix it, you could create an sql function to > > check for the existance of the id in 'a' and use that in the policy > > definition. >=20 > I've also discovered that using the following policy instead >=20 > CREATE POLICY a_select ON b FOR SELECT > USING ( a_id IN (SELECT id FROM a) ); >=20 > also seems to work around the issue. Yes, that also works, but it could get painful if 'a' gets large. An SQL function like: select exists (select * from a where a.id =3D $1); Would still use an indexed lookup against 'a'. Thanks! Stephen --2WS97oupGEGbYNpW Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJWzhaBAAoJEO1sijiDR2RVgQYP/3/DF0kq5f6zbjUsS9qddu4S fYvwDHNvZWjS2XMo5pfcsZ3hcLd8f8VO/EiMkDIKYQx/dP5KJ9ObG30Cr87lP2Lw Wc3eBREeTEc8a2OV8QWHDOBpVRmJpe6tlL/9+MktxqfN1M0Zduy6s5hvnw5jPI/S J/KqghIb00uk7thMjtvWX+6JXDmuL0G3FeuWM2tNd8hLo0vF2JxOah90bOLU+p/o JlRv632lDipp47UFgjPISyQjf5QptKQsrDlG/wGP5pxJ/Tq7zKEdtsyUpACPxkj+ eSwBH4BA3+z+PGNwmVahldeJBqQRBOvUFdmFDkdyducrMyXAyAS3jkzyx+28k2Um McGznLvXSQAEuNwk0IHFVNXrtPA6fPvQBfSHw0lUjFYzP6K7eJrsZ/wUNj/ka24v ffRAlhE2ymsCL5z9vP52BUvXvWD48HKnUxzgB946voImNRU+OWewEfmBTD8Xe1dK iIXNEZqyupolmcYcjXYxqodXYbwLIUEHLMzW6vMa+riIV3Sdk6fl74MqLpiDqAMS yqjzaCjCsZLc8IlStVzDMbBUZl23r2hQu5QXSJkCDHk6D1feYBM5ZgMjZekHPofN aR8FgXKZUUbbBHuI0Tt2Sus81dc7BaiOlg7EZGiBJEjHMnYTievsxKf/IAt361cm m7iOrAn0BVVTxXMT4D/u =VmKv -----END PGP SIGNATURE----- --2WS97oupGEGbYNpW--