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 1jJO8y-0003f5-39 for pgsql-general@arkaria.postgresql.org; Tue, 31 Mar 2020 21:09:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJO8x-0001Ww-1p for pgsql-general@arkaria.postgresql.org; Tue, 31 Mar 2020 21:09:55 +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 ) id 1jJO8w-0001Wn-HV for pgsql-general@lists.postgresql.org; Tue, 31 Mar 2020 21:09:54 +0000 Received: from mail-eopbgr120049.outbound.protection.outlook.com ([40.107.12.49] helo=FRA01-PR2-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJO8t-0005Nz-BL for pgsql-general@lists.postgresql.org; Tue, 31 Mar 2020 21:09:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JYa+lE2eWLtU3XBhRjHDokuRWvkvcIYq2OqHT1sX+woFSR1fX8xno6FOEczS9fDZ6/WtGq05JlkALCnbskUVaFO8HzVpoC4nKgRMPg6IrKfR40p9T0gmuy5QxhFA+RCcJGp2IcRBQsGnuvtAfPpWfbEh9yg2CukSADbfDk/OkJmFHqUlDtc3zdAP16RTXjR7FofvVcsRg9qR2v54FVLo3kfwMu+jJwruzDA7mKxAe2+ebVwZ0pdS8u/DLH7/RPxD4SSxERTE4JZEsRBPxybJ/mCJqJAKbN3SxrsMoVRVt4wo1QkoAy2Fkk9xDTbZd5UcQFO0nxsWnut6i4UbE8k1+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GvSayfOHYQNvaQbp0MngHcor6oKBRrM+s4HNwgiWKh4=; b=aW7kcBODj/W4UbwKdxRaGwwaxfRJRCxZVS14+GxTefutZf1ypqhrY8orQv6cI1sMkMX3oXLSbGDqcja8UJ//5GauYhlBv0WnfRZy73rKZCFgPVz4vMJ8wtDm+EM1cIuXcgBr8tjpmheQs9MHIaPadV5ApQVOVnkfCmxpsPgoQN3/yKrxmIdYO6dJKqQnoS5PD9Ho6C000mjF9soxiBEeLCU7fZ6e1c5BHC9aStCNZXrO4S/IiF1fjsiO2f0rjFpFTh8BN1qZgaDV6ppIbSI/MiZET+PuGNGuNr689nP9qdT5AYCRB5UdckoNiz/jL7WlTn1B+2H6ADNo+WIsFxRksA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=analyticsengines.com; dmarc=pass action=none header.from=analyticsengines.com; dkim=pass header.d=analyticsengines.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analyticsengines.onmicrosoft.com; s=selector2-analyticsengines-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GvSayfOHYQNvaQbp0MngHcor6oKBRrM+s4HNwgiWKh4=; b=BeSEfdrs1+v22blXNzcYIslDHsZb+X5zpYDLkF320jvF3J7r35MEqJBfVW7mgATKd9nqyztrTj7fzqRfEfk+H0yuePvHwAGJouWL4ePQddIErkgFgjIl0lGZEgymw5M6ZyGkJsG4bSIewT7pj2KMs6QEfkb00WOcS8ooXPX/9mI= Received: from PR1PR02MB5340.eurprd02.prod.outlook.com (2603:10a6:102:3::10) by PR1PR02MB4794.eurprd02.prod.outlook.com (2603:10a6:102:5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.20; Tue, 31 Mar 2020 21:09:48 +0000 Received: from PR1PR02MB5340.eurprd02.prod.outlook.com ([fe80::78a0:596:4c0a:93c3]) by PR1PR02MB5340.eurprd02.prod.outlook.com ([fe80::78a0:596:4c0a:93c3%7]) with mapi id 15.20.2856.019; Tue, 31 Mar 2020 21:09:47 +0000 From: Alastair McKinley To: Tom Lane CC: "pgsql-general@lists.postgresql.org" Subject: Re: Index selection issues with RLS using expressions Thread-Topic: Index selection issues with RLS using expressions Thread-Index: AQHWB42howKlPkgN7E2Mj3NqjfGdEqhjEy0AgAAbhL4= Date: Tue, 31 Mar 2020 21:09:47 +0000 Message-ID: References: ,<23829.1585682302@sss.pgh.pa.us> In-Reply-To: <23829.1585682302@sss.pgh.pa.us> Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=a.mckinley@analyticsengines.com; x-originating-ip: [86.135.78.64] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 66ef1f78-2588-4eb7-c5da-08d7d5b7d836 x-ms-traffictypediagnostic: PR1PR02MB4794: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 0359162B6D x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PR1PR02MB5340.eurprd02.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(396003)(39840400004)(136003)(376002)(366004)(346002)(5660300002)(316002)(33656002)(9686003)(52536014)(55016002)(8936002)(81166006)(6506007)(186003)(71200400001)(53546011)(7696005)(66446008)(81156014)(91956017)(76116006)(4326008)(508600001)(6916009)(86362001)(66476007)(66946007)(2906002)(8676002)(26005)(19627405001)(66556008)(64756008);DIR:OUT;SFP:1101; received-spf: None (protection.outlook.com: analyticsengines.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: QcAZz/2IBPVlsbb1mefsavfLqBr8Zgj5eRURzNda32Yam/ICv86cdMxQztddGGZDEQLnTI1xmy+DW7IJ5PPyIkAnh+LWPyXv+JHlQu/eRbYYjTfgTdavYQwh0lPiils1x3w8Kg9GSvR3uZkIWOVOjQTEG9njQ1n6rNC5r7uX4lgm9GxeHiHfsdexP6Ba1QwIBVJQ5Bv4o81+Yzr3P+F2frLS0eKILHdgwGobabWjbMokvWcWQl4RA6lA5ZUD7OCDB25+JiAw7DRDPi2oDbRDdAEQUmx21J3QftZ5O2hDWiZEXwJ61wQEf/FkV88Pb5uPC9Sl/KVK+MTAwMJEvO+nXhjK3BZ6beKqAt33Qf3hg+bbLzYEgewcPVLl9T6lJM44cSWTMWL2jnYCXnoVBdu1FF7yCb8uWtuv2XYOWXzywYBSvaYbWITUZerLjMoW4taT x-ms-exchange-antispam-messagedata: /0N1GUy+YtQpzUJmZ7FnQc3qWk7AWAp7zQwy/aI92gwufFUnJ43pH+FwBwamvuEZ1aR4pL7+Oo6JQU0FDyldR0F2cOgI5RCF0pHbP+BsTuKYST70h/ucaR4eNBqs2xHETZ/r2GMWbgBqDHw1FL1juw== x-ms-exchange-transport-forked: True Content-Type: multipart/alternative; boundary="_000_PR1PR02MB5340BE7BBCA6331BDC2AE6FCE3C80PR1PR02MB5340eurp_" MIME-Version: 1.0 X-OriginatorOrg: analyticsengines.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66ef1f78-2588-4eb7-c5da-08d7d5b7d836 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Mar 2020 21:09:47.8164 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 861f81d7-c1ff-445c-b861-5a0f983c5b47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +0+5eOeH107QcpRS84kkIR/WwcI7wzbg6XZee3GsGKRh4v0SzRFxiUKSbdPYtQ22RgKp2MlioC4F8nXTV04rkZQBRwMmeTBT7wOkMyofX2U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1PR02MB4794 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --_000_PR1PR02MB5340BE7BBCA6331BDC2AE6FCE3C80PR1PR02MB5340eurp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Tom, Thanks for looking at this! It seems like there are quite a few performanc= e gotchas around leaky operators and RLS, this is my second encounter with = this issue in the last few weeks. What would you recommend as a reasonable workaround? I have a large table with a gin index that I would like to use RLS on and u= se the @@ text search operator. My initial thought is to use a security de= finer set-returning function that implements the RLS policy explicitly. Wo= uld a security barrier view also potentially work? Best regards and thanks again, Alastair ________________________________ From: Tom Lane Sent: 31 March 2020 20:18 To: Alastair McKinley Cc: pgsql-general@lists.postgresql.org Subject: Re: Index selection issues with RLS using expressions Alastair McKinley writes: > I am running in to an issue with RLS and index selection in my queries. = I created a toy example to try to illustrate the issue below. Postgres ver= sion is PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, c= ompiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit. > Is there some subtle reason as to why the role "new_user" cannot seem to = generate a query plan that uses the gin index? The && operator is not marked leakproof, so it can't be applied till after the RLS filter, making an indexscan with it impossible when RLS is active. Perhaps arrayoverlap() itself could be proven leakproof, but the underlying type-specific equality operator might or might not be. We don't have enough infrastructure to handle indirect leakproofness requirements like that, so you lose :-( regards, tom lane --_000_PR1PR02MB5340BE7BBCA6331BDC2AE6FCE3C80PR1PR02MB5340eurp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hi Tom,

Thanks for looking at this!  It seems like there are quite a few perfo= rmance gotchas around leaky operators and RLS, this is my second encounter = with this issue in the last few weeks.

What would you recommend as a reasonable workaround? 

I have a large table with a gin index that I would like to use RLS on and u= se the @@ text search operator.  My initial thought is to use a securi= ty definer set-returning function that implements the RLS policy explicitly= .  Would a security barrier view also potentially work?

Best regards and thanks again,

Alastair



From: Tom Lane <tgl@sss.= pgh.pa.us>
Sent: 31 March 2020 20:18
To: Alastair McKinley <a.mckinley@analyticsengines.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postg= resql.org>
Subject: Re: Index selection issues with RLS using expressions
 
Alastair McKinley <a.mckinley@analyticsengines.= com> writes:
> I am running in to an issue with RLS and index selection in my queries= .  I created a toy example to try to illustrate the issue below. = Postgres version is PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_6= 4-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit.

> Is there some subtle reason as to why the role "new_user" ca= nnot seem to generate a query plan that uses the gin index?

The && operator is not marked leakproof, so it can't be applied til= l
after the RLS filter, making an indexscan with it impossible when
RLS is active.

Perhaps arrayoverlap() itself could be proven leakproof, but the
underlying type-specific equality operator might or might not be.
We don't have enough infrastructure to handle indirect leakproofness
requirements like that, so you lose :-(

            &nb= sp;           regards, to= m lane
--_000_PR1PR02MB5340BE7BBCA6331BDC2AE6FCE3C80PR1PR02MB5340eurp_--