You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ma...@apache.org on 2025/02/21 09:45:36 UTC
(cloudberry) 21/30: Enable ORCA to generate plans with row level security enabled (#16869)
This is an automated email from the ASF dual-hosted git repository.
maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 80a26c835b22ff5e1708de57c1a545f40dc0b7d8
Author: Dev Swaroop Chattopadhyay <10...@users.noreply.github.com>
AuthorDate: Wed Jan 31 17:40:20 2024 +0530
Enable ORCA to generate plans with row level security enabled (#16869)
By default the tables do not have any policies defined, allowing any user with
table access privileges to query them. Row level security[1], when activated on a
table, permits the restriction of queried rows on a per-user basis. The table
owner exclusively holds the privilege to enable or disable row security and add
policies. To determine visible or modifiable rows based on a policy, an
expression yielding a Boolean result is necessary. This expression (security
quals) evaluates for each row before any conditions or functions from the
user's query are evaluated. Presently, ORCA fallbacks to the planner when
querying a table with row security. This pull request enhances ORCA to generate
plans with row level security enabled.
Implementation
The security quals are added to SeqScan/DynSeqScan during DXL to Planned
Statement translation. The security quals are placed before any quals from the
user's query. ORCA will fallback to planner if the security quals contains
sublinks.
Features Not Supported by this PR
Foreign Tables with RLS : The postgres_fdw wrapper does not support row level
security. We can't run a query like alter foreign table foo enable row level
security. It was discussed on hackers[2].
All type of Index Scans : The logic used in this PR is to add the security
quals as a filter while translating DXL to Planned statement. So in the case of
a index plan we will already have a DXL index plan before adding the security
quals as filter. It may happen that we generate a plan where the index
condition contains non-leakproof expressions. This can lead to data leak as we
always want our security quals to be executed first.
INSERT AND UPDATE : Insert and update queries also have WITHCHECKOPTIONS in the
rewritten parse tree which is not supported by ORCA. In this case ORCA will
fallback to planner.
[1] https://www.postgresql.org/docs/12/ddl-rowsecurity.html
[2] https://www.postgresql.org/message-id/flat/2518.1478214978@sss.pgh.pa.us#66fdfa406eccd80f8486e18429ba10ce
---
src/backend/gpopt/gpdbwrappers.cpp | 11 +
.../gpopt/translate/CTranslatorDXLToPlStmt.cpp | 238 +++-
.../gpopt/translate/CTranslatorQueryToDXL.cpp | 89 +-
.../include/gpopt/operators/CLogicalDynamicGet.h | 16 +-
.../libgpopt/include/gpopt/operators/CLogicalGet.h | 14 +-
.../src/operators/CExpressionPreprocessor.cpp | 2 +-
.../libgpopt/src/operators/CLogicalDynamicGet.cpp | 26 +-
.../gporca/libgpopt/src/operators/CLogicalGet.cpp | 19 +-
.../src/translate/CTranslatorDXLToExpr.cpp | 11 +-
...CXformExpandDynamicGetWithForeignPartitions.cpp | 4 +-
.../src/xforms/CXformJoin2IndexApplyGeneric.cpp | 22 +
.../libgpopt/src/xforms/CXformLimit2IndexGet.cpp | 12 +
.../libgpopt/src/xforms/CXformMinMax2IndexGet.cpp | 11 +
.../src/xforms/CXformSelect2BitmapBoolOp.cpp | 14 +
.../src/xforms/CXformSelect2DynamicIndexGet.cpp | 11 +
.../xforms/CXformSelect2DynamicIndexOnlyGet.cpp | 11 +
.../libgpopt/src/xforms/CXformSelect2IndexGet.cpp | 11 +
.../src/xforms/CXformSelect2IndexOnlyGet.cpp | 11 +
.../gporca/libgpopt/src/xforms/CXformUtils.cpp | 2 +-
.../xforms/CxformSelect2DynamicBitmapBoolOp.cpp | 12 +
.../naucrates/dxl/operators/CDXLLogicalGet.h | 8 +-
.../naucrates/dxl/parser/CParseHandlerLogicalGet.h | 4 +-
.../include/naucrates/dxl/xml/dxltokens.h | 3 +
.../libnaucrates/src/operators/CDXLLogicalGet.cpp | 17 +-
.../src/parser/CParseHandlerLogicalForeignGet.cpp | 6 +-
.../src/parser/CParseHandlerLogicalGet.cpp | 16 +-
.../gporca/libnaucrates/src/xml/dxltokens.cpp | 2 +
src/include/gpopt/gpdbwrappers.h | 3 +
.../gpopt/translate/CTranslatorDXLToPlStmt.h | 28 +
.../gpopt/translate/CTranslatorQueryToDXL.h | 3 +
src/test/regress/expected/equivclass_optimizer.out | 16 +-
src/test/regress/expected/qp_rowsecurity.out | 986 ++++++++++++++++
.../regress/expected/qp_rowsecurity_optimizer.out | 920 +++++++++++++++
src/test/regress/expected/rowsecurity.out | 2 +
.../{rowsecurity.out => rowsecurity_optimizer.out} | 1175 +++++++++++++++-----
src/test/regress/greenplum_schedule | 2 +-
src/test/regress/sql/qp_rowsecurity.sql | 466 ++++++++
src/test/regress/sql/rowsecurity.sql | 2 +
38 files changed, 3848 insertions(+), 358 deletions(-)
diff --git a/src/backend/gpopt/gpdbwrappers.cpp b/src/backend/gpopt/gpdbwrappers.cpp
index 8343d36ba8..74d2ca1bc7 100644
--- a/src/backend/gpopt/gpdbwrappers.cpp
+++ b/src/backend/gpopt/gpdbwrappers.cpp
@@ -418,6 +418,17 @@ gpdb::WalkExpressionTree(Node *node, bool (*walker)(Node *, void *), void *conte
return false;
}
+gpos::BOOL
+gpdb::WalkQueryTree(Query *query, bool (*walker)(), void *context, int flags)
+{
+ GP_WRAP_START;
+ {
+ return query_tree_walker(query, walker, context, flags);
+ }
+ GP_WRAP_END;
+ return false;
+}
+
Oid
gpdb::ExprType(Node *expr)
{
diff --git a/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp b/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp
index bf3c79a4ce..62c516bf03 100644
--- a/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp
+++ b/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp
@@ -105,6 +105,8 @@ extern "C" {
#include "naucrates/md/IMDTypeInt4.h"
#include "naucrates/traceflags/traceflags.h"
+#include "nodes/nodeFuncs.h"
+
using namespace gpdxl;
using namespace gpos;
using namespace gpopt;
@@ -627,9 +629,9 @@ CTranslatorDXLToPlStmt::TranslateDXLTblScan(
// Lock any table we are to scan, since it may not have been properly locked
// by the parser (e.g in case of generated scans for partitioned tables)
- CMDIdGPDB *mdid = CMDIdGPDB::CastMdid(md_rel->MDId());
+ OID oidRel = CMDIdGPDB::CastMdid(md_rel->MDId())->Oid();
GPOS_ASSERT(dxl_table_descr->LockMode() != -1);
- gpdb::GPDBLockRelationOid(mdid->Oid(), dxl_table_descr->LockMode());
+ gpdb::GPDBLockRelationOid(oidRel, dxl_table_descr->LockMode());
Index index = ProcessDXLTblDescr(dxl_table_descr, &base_table_context);
@@ -641,24 +643,27 @@ CTranslatorDXLToPlStmt::TranslateDXLTblScan(
CDXLNode *filter_dxlnode = (*tbl_scan_dxlnode)[EdxltsIndexFilter];
List *targetlist = NIL;
- List *qual = NIL;
+
+ // List to hold the quals after translating filter_dxlnode node.
+ List *query_quals = NIL;
TranslateProjListAndFilter(
project_list_dxlnode, filter_dxlnode,
&base_table_context, // translate context for the base table
nullptr, // translate_ctxt_left and pdxltrctxRight,
- &targetlist, &qual, output_context);
+ &targetlist, &query_quals, output_context);
Plan *plan = nullptr;
Plan *plan_return = nullptr;
if (IMDRelation::ErelstorageForeign == md_rel->RetrieveRelStorageType())
{
- OID oidRel = CMDIdGPDB::CastMdid(md_rel->MDId())->Oid();
RangeTblEntry *rte = m_dxl_to_plstmt_context->GetRTEByIndex(index);
+ // The postgres_fdw wrapper does not support row level security. So
+ // passing only the query_quals while creating the foreign scan node.
ForeignScan *foreign_scan =
- gpdb::CreateForeignScan(oidRel, index, qual, targetlist,
+ gpdb::CreateForeignScan(oidRel, index, query_quals, targetlist,
m_dxl_to_plstmt_context->m_orig_query, rte);
foreign_scan->scan.scanrelid = index;
plan = &(foreign_scan->scan.plan);
@@ -672,7 +677,22 @@ CTranslatorDXLToPlStmt::TranslateDXLTblScan(
plan_return = (Plan *) seq_scan;
plan->targetlist = targetlist;
- plan->qual = qual;
+
+ // List to hold the quals which contain both security quals and query
+ // quals.
+ List *security_query_quals = NIL;
+
+ // Fetching the RTE of the relation from the rewritten parse tree
+ // based on the oidRel and adding the security quals of the RTE in
+ // the security_query_quals list.
+ AddSecurityQuals(oidRel, &security_query_quals, &index);
+
+ // The security quals should always be executed first when
+ // compared to other quals. So appending query quals to the
+ // security_query_quals list after the security quals.
+ security_query_quals =
+ gpdb::ListConcat(security_query_quals, query_quals);
+ plan->qual = security_query_quals;
}
if (md_rel->IsAORowOrColTable())
@@ -4267,6 +4287,11 @@ CTranslatorDXLToPlStmt::TranslateDXLDynTblScan(
CMDIdGPDB::CastMdid(m_md_accessor->PtMDType<IMDTypeInt4>()->MDId())
->Oid();
+ const IMDRelation *md_rel =
+ m_md_accessor->RetrieveRel(dxl_table_descr->MDId());
+
+ OID oidRel = CMDIdGPDB::CastMdid(md_rel->MDId())->Oid();
+
dyn_seq_scan->join_prune_paramids =
TranslateJoinPruneParamids(dyn_tbl_scan_dxlop->GetSelectorIds(),
oid_type, m_dxl_to_plstmt_context);
@@ -4285,11 +4310,29 @@ CTranslatorDXLToPlStmt::TranslateDXLDynTblScan(
(*dyn_tbl_scan_dxlnode)[EdxltsIndexProjList];
CDXLNode *filter_dxlnode = (*dyn_tbl_scan_dxlnode)[EdxltsIndexFilter];
+ // List to hold the quals which contain both security quals and query
+ // quals.
+ List *security_query_quals = NIL;
+
+ // List to hold the quals after translating filter_dxlnode node.
+ List *query_quals = NIL;
+
+ // Fetching the RTE of the relation from the rewritten parse tree
+ // based on the oidRel and adding the security quals of the RTE in
+ // the security_query_quals list.
+ AddSecurityQuals(oidRel, &security_query_quals, &index);
+
TranslateProjListAndFilter(
project_list_dxlnode, filter_dxlnode,
&base_table_context, // translate context for the base table
nullptr, // translate_ctxt_left and pdxltrctxRight,
- &plan->targetlist, &plan->qual, output_context);
+ &plan->targetlist, &query_quals, output_context);
+
+ // The security quals should always be executed first when compared to
+ // other quals. So appending query quals to the security_query_quals
+ // list after the security quals.
+ security_query_quals = gpdb::ListConcat(security_query_quals, query_quals);
+ plan->qual = security_query_quals;
SetParamIds(plan);
@@ -5743,6 +5786,185 @@ CTranslatorDXLToPlStmt::TranslateProjListAndFilter(
child_contexts, output_context);
}
+//-----------------------------------------------------------------------------
+// @function:
+// CTranslatorDXLToPlStmt::AddSecurityQuals
+//
+// @doc:
+// This method is used to fetch the range table entry from the rewritten
+// parse tree based on the relId and add it's security quals in the quals
+// list. It also modifies the varno of the VAR node present in the
+// security quals and assigns it the value of the index i.e. the
+// position of this rte at m_dxl_to_plstmt_context->m_rtable_entries_list
+// (shortened as "rte_list")
+//
+//---------------------------------------------------------------------------
+void
+CTranslatorDXLToPlStmt::AddSecurityQuals(OID relId, List **qual, Index *index)
+{
+ SContextSecurityQuals ctxt_security_quals(relId);
+
+ // Find the RTE in the parse tree based on the relId and add the security
+ // quals of that RTE to the m_security_quals list present in
+ // ctxt_security_quals struct.
+ FetchSecurityQuals(m_dxl_to_plstmt_context->m_orig_query,
+ &ctxt_security_quals);
+
+ // The varno of the columns related to a particular table is different in
+ // the rewritten parse tree and the planned statement tree. In planned
+ // statement the varno of the columns is based on the index of the RTE
+ // at m_dxl_to_plstmt_context->m_rtable_entries_list. Since we are adding
+ // the security quals from the rewritten parse tree to planned statement
+ // tree we need to modify the varno of all the VAR nodes present in the
+ // security quals and assign it equal to index of the RTE in the rte_list.
+ SetSecurityQualsVarnoWalker((Node *) ctxt_security_quals.m_security_quals,
+ index);
+
+ // Adding the security quals from m_security_quals list to the qual list
+ *qual = gpdb::ListConcat(*qual, ctxt_security_quals.m_security_quals);
+}
+
+//---------------------------------------------------------------------------
+// @function:
+// CTranslatorDXLToPlStmt::FetchSecurityQuals
+//
+// @doc:
+// This method is used to walk the entire rewritten parse tree and
+// search for a range table entry whose relid is equal to the m_relId
+// field of ctxt_security_quals struct. On finding the RTE this method
+// will also add the security quals present in it to the
+// m_security_quals list of ctxt_security_quals struct.
+//
+//---------------------------------------------------------------------------
+BOOL
+CTranslatorDXLToPlStmt::FetchSecurityQuals(
+ Query *parsetree, SContextSecurityQuals *ctxt_security_quals)
+{
+ ListCell *lc;
+
+ // Iterate through all the range table entries present in the the rtable
+ // of the parsetree and search for a range table entry whose relid is
+ // equal to ctxt_security_quals->m_relId. If found then add the security
+ // quals of that RTE in the ctxt_security_quals->m_security_quals list.
+ // If the range table entry contains a subquery then recurse through that
+ // subquery and continue the search.
+ foreach (lc, parsetree->rtable)
+ {
+ RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
+ if (RTE_RELATION == rte->rtekind &&
+ rte->relid == ctxt_security_quals->m_relId)
+ {
+ ctxt_security_quals->m_security_quals = gpdb::ListConcat(
+ ctxt_security_quals->m_security_quals, rte->securityQuals);
+ return true;
+ }
+
+ if ((RTE_SUBQUERY == rte->rtekind ||
+ RTE_TABLEFUNCTION == rte->rtekind) &&
+ FetchSecurityQuals(rte->subquery, ctxt_security_quals))
+ {
+ return true;
+ }
+ }
+
+ // Recurse into ctelist
+ foreach (lc, parsetree->cteList)
+ {
+ CommonTableExpr *cte = lfirst_node(CommonTableExpr, lc);
+
+ if (FetchSecurityQuals(castNode(Query, cte->ctequery),
+ ctxt_security_quals))
+ {
+ return true;
+ }
+ }
+
+ // Recurse into sublink subqueries. We have already recursed the sublink
+ // subqueries present in the rtable and ctelist. QTW_IGNORE_RC_SUBQUERIES
+ // flag indicates to avoid recursing subqueries present in rtable and
+ // ctelist
+ if (parsetree->hasSubLinks)
+ {
+ return gpdb::WalkQueryTree(
+ parsetree,
+ (BOOL(*)()) CTranslatorDXLToPlStmt::FetchSecurityQualsWalker,
+ ctxt_security_quals, QTW_IGNORE_RC_SUBQUERIES);
+ }
+
+ return false;
+}
+
+//---------------------------------------------------------------------------
+// @function:
+// CTranslatorDXLToPlStmt::FetchSecurityQualsWalker
+//
+// @doc:
+// This method is a walker to recurse into SUBLINK nodes and search for
+// an RTE having relid equal to m_relId field of ctxt_security_quals struct
+//
+//---------------------------------------------------------------------------
+BOOL
+CTranslatorDXLToPlStmt::FetchSecurityQualsWalker(
+ Node *node, SContextSecurityQuals *ctxt_security_quals)
+{
+ if (nullptr == node)
+ {
+ return false;
+ }
+
+ // If the node is a SUBLINK, fetch its subselect node and start the
+ // search again for the RTE based on the m_relId field of
+ // ctxt_security_quals struct. If we found the RTE then the flag
+ // m_found_rte would have been set to true. In that case returning true
+ // which indicates to abort the walk immediately.
+ if (IsA(node, SubLink))
+ {
+ SubLink *sub = (SubLink *) node;
+
+ if (FetchSecurityQuals(castNode(Query, sub->subselect),
+ ctxt_security_quals))
+ {
+ return true;
+ }
+ }
+
+ return gpdb::WalkExpressionTree(
+ node, (BOOL(*)()) CTranslatorDXLToPlStmt::FetchSecurityQualsWalker,
+ ctxt_security_quals);
+}
+
+//-----------------------------------------------------------------------------
+// @function:
+// CTranslatorDXLToPlStmt::SetSecurityQualsVarnoWalker
+//
+// @doc:
+// The varno of the columns related to a particular table is different in
+// the rewritten parse tree and the planned statement tree. In planned
+// statement the varno of the columns is based on the index of the RTE at
+// m_dxl_to_plstmt_context->m_rtable_entries_list. Since we are adding
+// the security quals from the rewritten parse tree to planned statement
+// tree we need to modify the varno of all the VAR nodes present in the
+// security quals and assign it equal to index of the RTE in the rte_list.
+//
+//---------------------------------------------------------------------------
+BOOL
+CTranslatorDXLToPlStmt::SetSecurityQualsVarnoWalker(Node *node, Index *index)
+{
+ if (nullptr == node)
+ {
+ return false;
+ }
+
+ if (IsA(node, Var))
+ {
+ ((Var *) node)->varno = *index;
+ return false;
+ }
+
+ return gpdb::WalkExpressionTree(
+ node, (BOOL(*)()) CTranslatorDXLToPlStmt::SetSecurityQualsVarnoWalker,
+ index);
+}
//---------------------------------------------------------------------------
// @function:
diff --git a/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp b/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp
index 48e34a3119..85351167ed 100644
--- a/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp
+++ b/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp
@@ -468,13 +468,62 @@ CTranslatorQueryToDXL::CheckRangeTable(Query *query)
{
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
- if (rte->security_barrier || rte->securityQuals)
+ if (rte->security_barrier)
{
GPOS_ASSERT_FIXME(RTE_SUBQUERY == rte->rtekind);
// otherwise ORCA most likely pushes potentially leaky filters down
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
GPOS_WSZ_LIT("views with security_barrier ON"));
}
+
+ // In a rewritten parse tree
+ //
+ // [1] When hasRowSecurity=false and security_quals are not
+ // present in an rte, means that the relations present in a
+ // query don't have row level security enabled.
+ //
+ // [2] When hasRowSecurity=true and security_quals are present
+ // in an rte, means that the relations present in a query have
+ // row level security enabled.
+ //
+ // [3] When hasRowSecurity=true and security_quals are not
+ // present in an rte, means that the relations present in
+ // a query have row level security enabled but the query is
+ // executed by the owner of the relation.
+ //
+ // [4] When hasRowSecurity=false and security_quals are
+ // present in an rte example: A view with security barrier
+ // enabled and the view contains a relation with rules.
+ // Example query is below
+ //
+ // ```SQL
+ // CREATE TABLE foo(id int PRIMARY KEY, data text, deleted boolean);
+ // CREATE RULE foo_del_rule AS ON DELETE TO foo DO INSTEAD UPDATE foo SET deleted = true WHERE id = old.id;
+ // CREATE VIEW rw_view1 WITH (security_barrier=true) AS SELECT id, data FROM foo WHERE NOT deleted;
+ // DELETE FROM rw_view1 WHERE id = 1;
+ // ```
+ // ORCA will fallback to planner for this case [4].
+ if (!query->hasRowSecurity && nullptr != rte->securityQuals)
+ {
+ GPOS_RAISE(
+ gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
+ GPOS_WSZ_LIT(
+ "Security quals present in RTE without row level security enabled"));
+ }
+
+ // ORCA will fallback to planner if row level security is
+ // enabled for a relation and the security quals contain
+ // sublinks.
+ if (query->hasRowSecurity && query->hasSubLinks &&
+ 0 < gpdb::ListLength(rte->securityQuals) &&
+ CheckSublinkInSecurityQuals((Node *) rte->securityQuals, nullptr))
+ {
+ GPOS_RAISE(
+ gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
+ GPOS_WSZ_LIT(
+ "Query has row level security enabled and security quals contain sublinks"));
+ }
+
if (rte->tablesample)
{
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
@@ -483,6 +532,38 @@ CTranslatorQueryToDXL::CheckRangeTable(Query *query)
}
}
+//---------------------------------------------------------------------------
+// @function:
+// CTranslatorQueryToDXL::CheckSublinkInSecurityQuals
+//
+// @doc:
+// When row level security is enabled we add the security quals
+// while translating the table scans from DXL To Planned Statement.
+// If the security quals consists of SUBLINKS then those queries
+// will not have been planned as we add them at the end during
+// translation. So falling back to planner for such cases. This walker
+// is used to find if we have any sublinks present in the security quals.
+//
+//---------------------------------------------------------------------------
+
+BOOL
+CTranslatorQueryToDXL::CheckSublinkInSecurityQuals(Node *node, void *context)
+{
+ if (nullptr == node)
+ {
+ return false;
+ }
+
+ if (IsA(node, SubLink))
+ {
+ return true;
+ }
+
+ return gpdb::WalkExpressionTree(
+ node, (BOOL(*)()) CTranslatorQueryToDXL::CheckSublinkInSecurityQuals,
+ context);
+}
+
//---------------------------------------------------------------------------
// @function:
// CTranslatorQueryToDXL::GetQueryOutputCols
@@ -3402,6 +3483,9 @@ CTranslatorQueryToDXL::TranslateRTEToDXLLogicalGet(const RangeTblEntry *rte,
GPOS_WSZ_LIT("ONLY in the FROM clause"));
}
+
+ BOOL rteHasSecurityQuals = gpdb::ListLength(rte->securityQuals) > 0;
+
// query_id_for_target_rel is used to tag table descriptors assigned to target
// (result) relations one. In case of possible nested DML subqueries it's
// field points to target relation of corresponding Query structure of subquery.
@@ -3426,7 +3510,8 @@ CTranslatorQueryToDXL::TranslateRTEToDXLLogicalGet(const RangeTblEntry *rte,
}
else
{
- dxl_op = GPOS_NEW(m_mp) CDXLLogicalGet(m_mp, dxl_table_descr);
+ dxl_op = GPOS_NEW(m_mp)
+ CDXLLogicalGet(m_mp, dxl_table_descr, rteHasSecurityQuals);
}
CDXLNode *dxl_node = GPOS_NEW(m_mp) CDXLNode(m_mp, dxl_op);
diff --git a/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalDynamicGet.h b/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalDynamicGet.h
index 516087b429..9850879b80 100644
--- a/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalDynamicGet.h
+++ b/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalDynamicGet.h
@@ -42,6 +42,9 @@ protected:
// Indexes correspond to partitions
IMdIdArray *m_foreign_server_mdids{nullptr};
+ // relation has row level security enabled and has security quals
+ BOOL m_has_security_quals{false};
+
public:
CLogicalDynamicGet(const CLogicalDynamicGet &) = delete;
@@ -54,11 +57,14 @@ public:
CColRef2dArray *pdrgpdrgpcrPart,
IMdIdArray *partition_mdids,
CConstraint *partition_cnstrs_disj, BOOL static_pruned,
- IMdIdArray *foreign_server_mdids);
+ IMdIdArray *foreign_server_mdids,
+ BOOL hasSecurityQuals = false);
+
CLogicalDynamicGet(CMemoryPool *mp, const CName *pnameAlias,
CTableDescriptor *ptabdesc, ULONG ulPartIndex,
IMdIdArray *partition_mdids,
- IMdIdArray *foreign_server_mdids);
+ IMdIdArray *foreign_server_mdids,
+ BOOL hasSecurityQuals = false);
// dtor
~CLogicalDynamicGet() override;
@@ -91,6 +97,12 @@ public:
return m_static_pruned;
}
+ BOOL
+ HasSecurityQuals() const
+ {
+ return m_has_security_quals;
+ }
+
// operator specific hash function
ULONG HashValue() const override;
diff --git a/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalGet.h b/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalGet.h
index 5ce4a328b4..d9c5986890 100644
--- a/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalGet.h
+++ b/src/backend/gporca/libgpopt/include/gpopt/operators/CLogicalGet.h
@@ -48,6 +48,9 @@ private:
// distribution columns (empty for master only tables)
CColRefSet *m_pcrsDist;
+ // relation has row level security enabled and has security quals
+ BOOL m_has_security_quals{false};
+
void CreatePartCols(CMemoryPool *mp, const ULongPtrArray *pdrgpulPart);
// private copy ctor
@@ -58,10 +61,11 @@ public:
explicit CLogicalGet(CMemoryPool *mp);
CLogicalGet(CMemoryPool *mp, const CName *pnameAlias,
- CTableDescriptor *ptabdesc);
+ CTableDescriptor *ptabdesc, BOOL hasSecurityQuals = false);
CLogicalGet(CMemoryPool *mp, const CName *pnameAlias,
- CTableDescriptor *ptabdesc, CColRefArray *pdrgpcrOutput);
+ CTableDescriptor *ptabdesc, CColRefArray *pdrgpcrOutput,
+ BOOL hasSecurityQuals = false);
// dtor
~CLogicalGet() override;
@@ -115,6 +119,12 @@ public:
return m_pdrgpdrgpcrPart;
}
+ BOOL
+ HasSecurityQuals() const
+ {
+ return m_has_security_quals;
+ }
+
// operator specific hash function
ULONG HashValue() const override;
diff --git a/src/backend/gporca/libgpopt/src/operators/CExpressionPreprocessor.cpp b/src/backend/gporca/libgpopt/src/operators/CExpressionPreprocessor.cpp
index f2f47d86c1..c939fa3805 100644
--- a/src/backend/gporca/libgpopt/src/operators/CExpressionPreprocessor.cpp
+++ b/src/backend/gporca/libgpopt/src/operators/CExpressionPreprocessor.cpp
@@ -2921,7 +2921,7 @@ CExpressionPreprocessor::PrunePartitions(CMemoryPool *mp, CExpression *expr)
mp, new_alias, dyn_get->Ptabdesc(), dyn_get->ScanId(),
dyn_get->PdrgpcrOutput(), dyn_get->PdrgpdrgpcrPart(),
selected_partition_mdids, selected_part_cnstr_disj, true,
- foreign_server_mdids);
+ foreign_server_mdids, dyn_get->HasSecurityQuals());
CExpressionArray *select_children = GPOS_NEW(mp) CExpressionArray(mp);
select_children->Append(GPOS_NEW(mp) CExpression(mp, new_dyn_get));
diff --git a/src/backend/gporca/libgpopt/src/operators/CLogicalDynamicGet.cpp b/src/backend/gporca/libgpopt/src/operators/CLogicalDynamicGet.cpp
index 125875a894..9aa9045cc7 100644
--- a/src/backend/gporca/libgpopt/src/operators/CLogicalDynamicGet.cpp
+++ b/src/backend/gporca/libgpopt/src/operators/CLogicalDynamicGet.cpp
@@ -60,12 +60,13 @@ CLogicalDynamicGet::CLogicalDynamicGet(
ULONG ulPartIndex, CColRefArray *pdrgpcrOutput,
CColRef2dArray *pdrgpdrgpcrPart, IMdIdArray *partition_mdids,
CConstraint *partition_cnstrs_disj, BOOL static_pruned,
- IMdIdArray *foreign_server_mdids)
+ IMdIdArray *foreign_server_mdids, BOOL hasSecurityQuals)
: CLogicalDynamicGetBase(mp, pnameAlias, ptabdesc, ulPartIndex,
pdrgpcrOutput, pdrgpdrgpcrPart, partition_mdids),
m_partition_cnstrs_disj(partition_cnstrs_disj),
m_static_pruned(static_pruned),
- m_foreign_server_mdids(foreign_server_mdids)
+ m_foreign_server_mdids(foreign_server_mdids),
+ m_has_security_quals(hasSecurityQuals)
{
GPOS_ASSERT(static_pruned || (nullptr == partition_cnstrs_disj));
GPOS_ASSERT(nullptr != foreign_server_mdids);
@@ -84,10 +85,12 @@ CLogicalDynamicGet::CLogicalDynamicGet(CMemoryPool *mp, const CName *pnameAlias,
CTableDescriptor *ptabdesc,
ULONG ulPartIndex,
IMdIdArray *partition_mdids,
- IMdIdArray *foreign_server_mdids)
+ IMdIdArray *foreign_server_mdids,
+ BOOL hasSecurityQuals)
: CLogicalDynamicGetBase(mp, pnameAlias, ptabdesc, ulPartIndex,
partition_mdids),
- m_foreign_server_mdids(foreign_server_mdids)
+ m_foreign_server_mdids(foreign_server_mdids),
+ m_has_security_quals(hasSecurityQuals)
{
GPOS_ASSERT(nullptr != foreign_server_mdids);
}
@@ -122,6 +125,9 @@ CLogicalDynamicGet::HashValue() const
ulHash =
gpos::CombineHashes(ulHash, CUtils::UlHashColArray(m_pdrgpcrOutput));
+ ulHash = gpos::CombineHashes(ulHash,
+ gpos::HashValue<BOOL>(&m_has_security_quals));
+
return ulHash;
}
@@ -137,7 +143,15 @@ CLogicalDynamicGet::HashValue() const
BOOL
CLogicalDynamicGet::Matches(COperator *pop) const
{
- return CUtils::FMatchDynamicScan(this, pop);
+ if (this->Eopid() != pop->Eopid())
+ {
+ return false;
+ }
+
+ CLogicalDynamicGet *popGet = CLogicalDynamicGet::PopConvert(pop);
+
+ return CUtils::FMatchDynamicScan(this, pop) &&
+ this->HasSecurityQuals() == popGet->HasSecurityQuals();
}
//---------------------------------------------------------------------------
@@ -187,7 +201,7 @@ CLogicalDynamicGet::PopCopyWithRemappedColumns(CMemoryPool *mp,
return GPOS_NEW(mp) CLogicalDynamicGet(
mp, pnameAlias, Ptabdesc(), m_scan_id, pdrgpcrOutput, pdrgpdrgpcrPart,
m_partition_mdids, partition_cnstrs_disj, m_static_pruned,
- m_foreign_server_mdids);
+ m_foreign_server_mdids, m_has_security_quals);
}
//---------------------------------------------------------------------------
diff --git a/src/backend/gporca/libgpopt/src/operators/CLogicalGet.cpp b/src/backend/gporca/libgpopt/src/operators/CLogicalGet.cpp
index 39524647e9..c430e21652 100644
--- a/src/backend/gporca/libgpopt/src/operators/CLogicalGet.cpp
+++ b/src/backend/gporca/libgpopt/src/operators/CLogicalGet.cpp
@@ -57,13 +57,14 @@ CLogicalGet::CLogicalGet(CMemoryPool *mp)
//
//---------------------------------------------------------------------------
CLogicalGet::CLogicalGet(CMemoryPool *mp, const CName *pnameAlias,
- CTableDescriptor *ptabdesc)
+ CTableDescriptor *ptabdesc, BOOL hasSecurityQuals)
: CLogical(mp),
m_pnameAlias(pnameAlias),
m_ptabdesc(GPOS_NEW(mp) CTableDescriptorHashSet(mp)),
m_pdrgpcrOutput(nullptr),
m_pdrgpdrgpcrPart(nullptr),
- m_pcrsDist(nullptr)
+ m_pcrsDist(nullptr),
+ m_has_security_quals(hasSecurityQuals)
{
GPOS_ASSERT(nullptr != ptabdesc);
GPOS_ASSERT(nullptr != pnameAlias);
@@ -93,12 +94,13 @@ CLogicalGet::CLogicalGet(CMemoryPool *mp, const CName *pnameAlias,
//---------------------------------------------------------------------------
CLogicalGet::CLogicalGet(CMemoryPool *mp, const CName *pnameAlias,
CTableDescriptor *ptabdesc,
- CColRefArray *pdrgpcrOutput)
+ CColRefArray *pdrgpcrOutput, BOOL hasSecurityQuals)
: CLogical(mp),
m_pnameAlias(pnameAlias),
m_ptabdesc(GPOS_NEW(mp) CTableDescriptorHashSet(mp)),
m_pdrgpcrOutput(pdrgpcrOutput),
- m_pdrgpdrgpcrPart(nullptr)
+ m_pdrgpdrgpcrPart(nullptr),
+ m_has_security_quals(hasSecurityQuals)
{
GPOS_ASSERT(nullptr != ptabdesc);
GPOS_ASSERT(nullptr != pnameAlias);
@@ -149,6 +151,9 @@ CLogicalGet::HashValue() const
ulHash =
gpos::CombineHashes(ulHash, CUtils::UlHashColArray(m_pdrgpcrOutput));
+ ulHash = gpos::CombineHashes(ulHash,
+ gpos::HashValue<BOOL>(&m_has_security_quals));
+
return ulHash;
}
@@ -171,7 +176,8 @@ CLogicalGet::Matches(COperator *pop) const
CLogicalGet *popGet = CLogicalGet::PopConvert(pop);
return Ptabdesc()->MDId()->Equals(popGet->Ptabdesc()->MDId()) &&
- m_pdrgpcrOutput->Equals(popGet->PdrgpcrOutput());
+ m_pdrgpcrOutput->Equals(popGet->PdrgpcrOutput()) &&
+ m_has_security_quals == popGet->HasSecurityQuals();
}
//---------------------------------------------------------------------------
@@ -201,7 +207,8 @@ CLogicalGet::PopCopyWithRemappedColumns(CMemoryPool *mp,
CName *pnameAlias = GPOS_NEW(mp) CName(mp, *m_pnameAlias);
Ptabdesc()->AddRef();
- return GPOS_NEW(mp) CLogicalGet(mp, pnameAlias, Ptabdesc(), pdrgpcrOutput);
+ return GPOS_NEW(mp) CLogicalGet(mp, pnameAlias, Ptabdesc(), pdrgpcrOutput,
+ m_has_security_quals);
}
//---------------------------------------------------------------------------
diff --git a/src/backend/gporca/libgpopt/src/translate/CTranslatorDXLToExpr.cpp b/src/backend/gporca/libgpopt/src/translate/CTranslatorDXLToExpr.cpp
index 22d8bb3eba..671b9b143a 100644
--- a/src/backend/gporca/libgpopt/src/translate/CTranslatorDXLToExpr.cpp
+++ b/src/backend/gporca/libgpopt/src/translate/CTranslatorDXLToExpr.cpp
@@ -579,6 +579,8 @@ CTranslatorDXLToExpr::PexprLogicalGet(const CDXLNode *dxlnode)
CDXLTableDescr *table_descr =
CDXLLogicalGet::Cast(dxl_op)->GetDXLTableDescr();
+ BOOL hasSecurityQuals = CDXLLogicalGet::Cast(dxl_op)->HasSecurityQuals();
+
GPOS_ASSERT(nullptr != table_descr);
GPOS_ASSERT(nullptr != table_descr->MdName()->GetMDName());
@@ -632,9 +634,9 @@ CTranslatorDXLToExpr::PexprLogicalGet(const CDXLNode *dxlnode)
// generate a part index id
ULONG part_idx_id = COptCtxt::PoctxtFromTLS()->UlPartIndexNextVal();
partition_mdids->AddRef();
- popGet = GPOS_NEW(m_mp)
- CLogicalDynamicGet(m_mp, pname, ptabdesc, part_idx_id,
- partition_mdids, foreign_server_mdids);
+ popGet = GPOS_NEW(m_mp) CLogicalDynamicGet(
+ m_mp, pname, ptabdesc, part_idx_id, partition_mdids,
+ foreign_server_mdids, hasSecurityQuals);
CLogicalDynamicGet *popDynamicGet =
CLogicalDynamicGet::PopConvert(popGet);
@@ -645,7 +647,8 @@ CTranslatorDXLToExpr::PexprLogicalGet(const CDXLNode *dxlnode)
{
if (EdxlopLogicalGet == edxlopid)
{
- popGet = GPOS_NEW(m_mp) CLogicalGet(m_mp, pname, ptabdesc);
+ popGet = GPOS_NEW(m_mp)
+ CLogicalGet(m_mp, pname, ptabdesc, hasSecurityQuals);
}
else
{
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformExpandDynamicGetWithForeignPartitions.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformExpandDynamicGetWithForeignPartitions.cpp
index 7b867783e3..ce7636588a 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformExpandDynamicGetWithForeignPartitions.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformExpandDynamicGetWithForeignPartitions.cpp
@@ -85,6 +85,7 @@ CXformExpandDynamicGetWithForeignPartitions::Transform(CXformContext *pxfctxt,
IMdIdArray *foreign_server_mdids = popGet->ForeignServerMdIds();
IMdIdArray *all_part_mdids = popGet->GetPartitionMdids();
+ BOOL hasSecurityQuals = popGet->HasSecurityQuals();
IMdIdArray *non_foreign_parts = GPOS_NEW(mp) IMdIdArray(mp);
// create map from server-> (array of part mdids)
@@ -165,7 +166,8 @@ CXformExpandDynamicGetWithForeignPartitions::Transform(CXformContext *pxfctxt,
mp, new_alias, popGet->Ptabdesc(), popGet->ScanId(), pdrgpcrNew,
popGet->PdrgpdrgpcrPart(), non_foreign_parts,
popGet->GetPartitionConstraintsDisj(), popGet->FStaticPruned(),
- GPOS_NEW(mp) IMdIdArray(mp) /* foreign_server_mdids */);
+ GPOS_NEW(mp) IMdIdArray(mp) /* foreign_server_mdids */,
+ hasSecurityQuals);
CExpression *pexprNonForeignDynamicGet =
GPOS_NEW(mp) CExpression(mp, nonForeignDynamicGet);
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformJoin2IndexApplyGeneric.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformJoin2IndexApplyGeneric.cpp
index 331ed04df6..afc309a676 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformJoin2IndexApplyGeneric.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformJoin2IndexApplyGeneric.cpp
@@ -268,6 +268,17 @@ CXformJoin2IndexApplyGeneric::Transform(CXformContext *pxfctxt,
distributionCols = popGet->PcrsDist();
pexprGet = pexprCurrInnerChild;
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
if (nullptr != groupingColsToCheck.Value() &&
(!groupingColsToCheck->ContainsAll(distributionCols) ||
ptabdescInner->GetRelDistribution() ==
@@ -296,6 +307,17 @@ CXformJoin2IndexApplyGeneric::Transform(CXformContext *pxfctxt,
}
pexprGet = pexprCurrInnerChild;
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popDynamicGet->HasSecurityQuals())
+ {
+ return;
+ }
+
if (nullptr != groupingColsToCheck.Value() &&
(!groupingColsToCheck->ContainsAll(distributionCols) ||
ptabdescInner->GetRelDistribution() ==
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformLimit2IndexGet.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformLimit2IndexGet.cpp
index a9eab74007..d8b19c03f1 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformLimit2IndexGet.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformLimit2IndexGet.cpp
@@ -94,6 +94,18 @@ CXformLimit2IndexGet::Transform(CXformContext *pxfctxt, CXformResult *pxfres,
CExpression *pexprScalarRows = (*pexpr)[2];
CLogicalGet *popGet = CLogicalGet::PopConvert(pexprRelational->Pop());
+
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
// get the indices count of this relation
const ULONG ulIndices = popGet->Ptabdesc()->IndexCount();
// Ignore xform if relation doesn't have any indices
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformMinMax2IndexGet.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformMinMax2IndexGet.cpp
index b09e4223a5..5367b6ef46 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformMinMax2IndexGet.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformMinMax2IndexGet.cpp
@@ -106,6 +106,17 @@ CXformMinMax2IndexGet::Transform(CXformContext *pxfctxt, CXformResult *pxfres,
return;
}
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
CExpression *pexprPrjEl = (*pexprScalarPrjList)[0];
CExpression *pexprAggFunc = (*pexprPrjEl)[0];
CScalarAggFunc *popScAggFunc =
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2BitmapBoolOp.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2BitmapBoolOp.cpp
index a2549992cb..ca9f515b6c 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2BitmapBoolOp.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2BitmapBoolOp.cpp
@@ -75,6 +75,20 @@ CXformSelect2BitmapBoolOp::Transform(CXformContext *pxfctxt,
GPOS_ASSERT(FPromising(pxfctxt->Pmp(), this, pexpr));
GPOS_ASSERT(FCheckPattern(pexpr));
+ CExpression *pexprRelational = (*pexpr)[0];
+ CLogicalGet *popGet = CLogicalGet::PopConvert(pexprRelational->Pop());
+
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
CExpression *pexprResult =
CXformUtils::PexprSelect2BitmapBoolOp(pxfctxt->Pmp(), pexpr);
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexGet.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexGet.cpp
index c354e67f36..75bacfade3 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexGet.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexGet.cpp
@@ -91,6 +91,17 @@ CXformSelect2DynamicIndexGet::Transform(CXformContext *pxfctxt,
return;
}
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
CMemoryPool *mp = pxfctxt->Pmp();
// extract components
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexOnlyGet.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexOnlyGet.cpp
index 0f251fcfbc..efbae1c06c 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexOnlyGet.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2DynamicIndexOnlyGet.cpp
@@ -86,6 +86,17 @@ CXformSelect2DynamicIndexOnlyGet::Transform(CXformContext *pxfctxt,
return;
}
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
CMemoryPool *mp = pxfctxt->Pmp();
// extract components
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexGet.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexGet.cpp
index 5940a6b7ac..2385d0c1cf 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexGet.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexGet.cpp
@@ -92,6 +92,17 @@ CXformSelect2IndexGet::Transform(CXformContext *pxfctxt, CXformResult *pxfres,
return;
}
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
// array of expressions in the scalar expression
CExpressionArray *pdrgpexpr =
CPredicateUtils::PdrgpexprConjuncts(mp, pexprScalar);
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexOnlyGet.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexOnlyGet.cpp
index 5ef0f03174..35c6fe7694 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexOnlyGet.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformSelect2IndexOnlyGet.cpp
@@ -78,6 +78,17 @@ CXformSelect2IndexOnlyGet::Transform(CXformContext *pxfctxt,
return;
}
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
// array of expressions in the scalar expression
CExpressionArray *pdrgpexpr =
CPredicateUtils::PdrgpexprConjuncts(mp, pexprScalar);
diff --git a/src/backend/gporca/libgpopt/src/xforms/CXformUtils.cpp b/src/backend/gporca/libgpopt/src/xforms/CXformUtils.cpp
index 1c24fcc223..1cdfb4cae7 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CXformUtils.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CXformUtils.cpp
@@ -2507,7 +2507,7 @@ CXformUtils::PexprBuildBtreeIndexPlan(CMemoryPool *mp, CMDAccessor *md_accessor,
//
// (2) is valid only for Join2IndexApply xform wherein the index-get
// expression must include outer references for it to be an alternative
- // worth considering. Otherwise it has the same effect as a regular NLJ
+ // worth considering. Otherwise, it has the same effect as a regular NLJ
// with an index lookup.
//
// Both (1) and (2) doesn't apply if index is used for ORDER BY. Because
diff --git a/src/backend/gporca/libgpopt/src/xforms/CxformSelect2DynamicBitmapBoolOp.cpp b/src/backend/gporca/libgpopt/src/xforms/CxformSelect2DynamicBitmapBoolOp.cpp
index feec234944..1471254704 100644
--- a/src/backend/gporca/libgpopt/src/xforms/CxformSelect2DynamicBitmapBoolOp.cpp
+++ b/src/backend/gporca/libgpopt/src/xforms/CxformSelect2DynamicBitmapBoolOp.cpp
@@ -83,6 +83,18 @@ CXformSelect2DynamicBitmapBoolOp::Transform(CXformContext *pxfctxt,
{
return;
}
+
+ // We need to early exit when the relation contains security quals
+ // because we are adding the security quals when translating from DXL to
+ // Planned Statement as a filter. If we don't early exit then it may happen
+ // that we generate a plan where the index condition contains non-leakproof
+ // expressions. This can lead to data leak as we always want our security
+ // quals to be executed first.
+ if (popGet->HasSecurityQuals())
+ {
+ return;
+ }
+
CMemoryPool *mp = pxfctxt->Pmp();
CExpression *pexprResult = CXformUtils::PexprSelect2BitmapBoolOp(mp, pexpr);
diff --git a/src/backend/gporca/libnaucrates/include/naucrates/dxl/operators/CDXLLogicalGet.h b/src/backend/gporca/libnaucrates/include/naucrates/dxl/operators/CDXLLogicalGet.h
index e2f894da72..202142b4eb 100644
--- a/src/backend/gporca/libnaucrates/include/naucrates/dxl/operators/CDXLLogicalGet.h
+++ b/src/backend/gporca/libnaucrates/include/naucrates/dxl/operators/CDXLLogicalGet.h
@@ -35,11 +35,15 @@ private:
// table descriptor for the scanned table
CDXLTableDescr *m_dxl_table_descr;
+ // the table has row level security enabled and contains security quals
+ BOOL m_has_security_quals{false};
+
public:
CDXLLogicalGet(CDXLLogicalGet &) = delete;
// ctor
- CDXLLogicalGet(CMemoryPool *mp, CDXLTableDescr *table_descr);
+ CDXLLogicalGet(CMemoryPool *mp, CDXLTableDescr *table_descr,
+ BOOL hasSecurityQuals = false);
// dtor
~CDXLLogicalGet() override;
@@ -67,6 +71,8 @@ public:
return dynamic_cast<CDXLLogicalGet *>(dxl_op);
}
+ BOOL HasSecurityQuals() const;
+
#ifdef GPOS_DEBUG
// checks whether the operator has valid structure, i.e. number and
// types of child nodes
diff --git a/src/backend/gporca/libnaucrates/include/naucrates/dxl/parser/CParseHandlerLogicalGet.h b/src/backend/gporca/libnaucrates/include/naucrates/dxl/parser/CParseHandlerLogicalGet.h
index 7227e3788d..5683da061c 100644
--- a/src/backend/gporca/libnaucrates/include/naucrates/dxl/parser/CParseHandlerLogicalGet.h
+++ b/src/backend/gporca/libnaucrates/include/naucrates/dxl/parser/CParseHandlerLogicalGet.h
@@ -36,6 +36,8 @@ XERCES_CPP_NAMESPACE_USE
class CParseHandlerLogicalGet : public CParseHandlerLogicalOp
{
private:
+ BOOL m_has_security_quals{false};
+
// process the start of an element
void StartElement(
const XMLCh *const element_uri, // URI of element's namespace
@@ -54,7 +56,7 @@ private:
protected:
// start element helper function
void StartElement(const XMLCh *const element_local_name,
- Edxltoken token_type);
+ Edxltoken token_type, const Attributes &attr);
// end element helper function
void EndElement(const XMLCh *const element_local_name,
diff --git a/src/backend/gporca/libnaucrates/include/naucrates/dxl/xml/dxltokens.h b/src/backend/gporca/libnaucrates/include/naucrates/dxl/xml/dxltokens.h
index 25e1a2bfac..ac2d4c6f45 100644
--- a/src/backend/gporca/libnaucrates/include/naucrates/dxl/xml/dxltokens.h
+++ b/src/backend/gporca/libnaucrates/include/naucrates/dxl/xml/dxltokens.h
@@ -367,6 +367,9 @@ enum Edxltoken
EdxltokenGpSegmentIdColName,
EdxltokenGpForeignServerColName,
+ // For Logical Select
+ EdxltokenSecurityQuals,
+
EdxltokenActionColId,
EdxltokenCtidColId,
EdxltokenGpSegmentIdColId,
diff --git a/src/backend/gporca/libnaucrates/src/operators/CDXLLogicalGet.cpp b/src/backend/gporca/libnaucrates/src/operators/CDXLLogicalGet.cpp
index bd7c6a5aa6..183c9e0c09 100644
--- a/src/backend/gporca/libnaucrates/src/operators/CDXLLogicalGet.cpp
+++ b/src/backend/gporca/libnaucrates/src/operators/CDXLLogicalGet.cpp
@@ -27,8 +27,11 @@ using namespace gpdxl;
// Construct a logical get operator node given its table descriptor rtable entry
//
//---------------------------------------------------------------------------
-CDXLLogicalGet::CDXLLogicalGet(CMemoryPool *mp, CDXLTableDescr *table_descr)
- : CDXLLogical(mp), m_dxl_table_descr(table_descr)
+CDXLLogicalGet::CDXLLogicalGet(CMemoryPool *mp, CDXLTableDescr *table_descr,
+ BOOL hasSecurityQuals)
+ : CDXLLogical(mp),
+ m_dxl_table_descr(table_descr),
+ m_has_security_quals(hasSecurityQuals)
{
}
@@ -106,6 +109,10 @@ CDXLLogicalGet::SerializeToDXL(CXMLSerializer *xml_serializer,
xml_serializer->OpenElement(
CDXLTokens::GetDXLTokenStr(EdxltokenNamespacePrefix), element_name);
+ xml_serializer->AddAttribute(
+ CDXLTokens::GetDXLTokenStr(EdxltokenSecurityQuals),
+ m_has_security_quals);
+
// serialize table descriptor
m_dxl_table_descr->SerializeToDXL(xml_serializer);
@@ -137,6 +144,12 @@ CDXLLogicalGet::IsColDefined(ULONG colid) const
return false;
}
+BOOL
+CDXLLogicalGet::HasSecurityQuals() const
+{
+ return m_has_security_quals;
+}
+
#ifdef GPOS_DEBUG
//---------------------------------------------------------------------------
// @function:
diff --git a/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalForeignGet.cpp b/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalForeignGet.cpp
index ed75d2e270..4f75587b06 100644
--- a/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalForeignGet.cpp
+++ b/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalForeignGet.cpp
@@ -45,12 +45,12 @@ void
CParseHandlerLogicalForeignGet::StartElement(
const XMLCh *const, // element_uri,
const XMLCh *const element_local_name,
- const XMLCh *const, // element_qname
- const Attributes & //attrs
+ const XMLCh *const, // element_qname
+ const Attributes &attr //attrs
)
{
CParseHandlerLogicalGet::StartElement(element_local_name,
- EdxltokenLogicalForeignGet);
+ EdxltokenLogicalForeignGet, attr);
}
//---------------------------------------------------------------------------
diff --git a/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalGet.cpp b/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalGet.cpp
index e5300a92b0..e17eacd0d2 100644
--- a/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalGet.cpp
+++ b/src/backend/gporca/libnaucrates/src/parser/CParseHandlerLogicalGet.cpp
@@ -47,7 +47,8 @@ CParseHandlerLogicalGet::CParseHandlerLogicalGet(
//---------------------------------------------------------------------------
void
CParseHandlerLogicalGet::StartElement(const XMLCh *const element_local_name,
- Edxltoken token_type)
+ Edxltoken token_type,
+ const Attributes &attr)
{
if (0 != XMLString::compareString(CDXLTokens::XmlstrToken(token_type),
element_local_name))
@@ -58,6 +59,10 @@ CParseHandlerLogicalGet::StartElement(const XMLCh *const element_local_name,
str->GetBuffer());
}
+ m_has_security_quals = CDXLOperatorFactory::ExtractConvertAttrValueToBool(
+ m_parse_handler_mgr->GetDXLMemoryManager(), attr,
+ EdxltokenSecurityQuals, token_type, true, false);
+
// create child node parsers
// parse handler for table descriptor
@@ -82,11 +87,11 @@ CParseHandlerLogicalGet::StartElement(const XMLCh *const element_local_name,
void
CParseHandlerLogicalGet::StartElement(const XMLCh *const, // element_uri,
const XMLCh *const element_local_name,
- const XMLCh *const, // element_qname
- const Attributes & //attrs
+ const XMLCh *const, // element_qname
+ const Attributes &attr //attrs
)
{
- StartElement(element_local_name, EdxltokenLogicalGet);
+ StartElement(element_local_name, EdxltokenLogicalGet, attr);
}
//---------------------------------------------------------------------------
@@ -121,7 +126,8 @@ CParseHandlerLogicalGet::EndElement(const XMLCh *const element_local_name,
if (EdxltokenLogicalGet == token_type)
{
m_dxl_node = GPOS_NEW(m_mp)
- CDXLNode(m_mp, GPOS_NEW(m_mp) CDXLLogicalGet(m_mp, table_descr));
+ CDXLNode(m_mp, GPOS_NEW(m_mp) CDXLLogicalGet(m_mp, table_descr,
+ m_has_security_quals));
}
else
{
diff --git a/src/backend/gporca/libnaucrates/src/xml/dxltokens.cpp b/src/backend/gporca/libnaucrates/src/xml/dxltokens.cpp
index af2b1a20df..83cd2234d2 100644
--- a/src/backend/gporca/libnaucrates/src/xml/dxltokens.cpp
+++ b/src/backend/gporca/libnaucrates/src/xml/dxltokens.cpp
@@ -417,6 +417,8 @@ CDXLTokens::Init(CMemoryPool *mp)
{EdxltokenGpSegmentIdColName, GPOS_WSZ_LIT("gp_segment_id")},
{EdxltokenGpForeignServerColName, GPOS_WSZ_LIT("gp_foreign_server")},
+ {EdxltokenSecurityQuals, GPOS_WSZ_LIT("HasSecurityQuals")},
+
{EdxltokenActionColId, GPOS_WSZ_LIT("ActionCol")},
{EdxltokenCtidColId, GPOS_WSZ_LIT("CtidCol")},
{EdxltokenGpSegmentIdColId, GPOS_WSZ_LIT("SegmentIdCol")},
diff --git a/src/include/gpopt/gpdbwrappers.h b/src/include/gpopt/gpdbwrappers.h
index 6105174b50..caec2d340b 100644
--- a/src/include/gpopt/gpdbwrappers.h
+++ b/src/include/gpopt/gpdbwrappers.h
@@ -684,6 +684,9 @@ IndexAmRoutine *GetIndexAmRoutineFromAmHandler(Oid am_handler);
bool TestexprIsHashable(Node *testexpr, List *param_ids);
+gpos::BOOL WalkQueryTree(Query *query, bool (*walker)(), void *context,
+ int flags);
+
} //namespace gpdb
#define ForEach(cell, l) \
diff --git a/src/include/gpopt/translate/CTranslatorDXLToPlStmt.h b/src/include/gpopt/translate/CTranslatorDXLToPlStmt.h
index de4c0d0edc..c377aa9ba0 100644
--- a/src/include/gpopt/translate/CTranslatorDXLToPlStmt.h
+++ b/src/include/gpopt/translate/CTranslatorDXLToPlStmt.h
@@ -106,6 +106,21 @@ private:
}
}; // SContextIndexVarAttno
+ // context for finding security quals in an RTE
+ struct SContextSecurityQuals
+ {
+ // relid of the RTE to search in the rewritten parse tree
+ const OID m_relId;
+
+ // List to hold the security quals present in an RTE
+ List *m_security_quals{NIL};
+
+ // ctor
+ SContextSecurityQuals(const OID relId) : m_relId(relId)
+ {
+ }
+ }; // SContextSecurityQuals
+
// memory pool
CMemoryPool *m_mp;
@@ -139,6 +154,17 @@ private:
static BOOL SetIndexVarAttnoWalker(
Node *node, SContextIndexVarAttno *ctxt_index_var_attno_walker);
+ // walker to set inner var to outer
+ static BOOL SetHashKeysVarnoWalker(Node *node, void *context);
+
+ static BOOL FetchSecurityQualsWalker(
+ Node *node, SContextSecurityQuals *ctxt_security_quals);
+
+ static BOOL FetchSecurityQuals(Query *parsetree,
+ SContextSecurityQuals *ctxt_security_quals);
+
+ static BOOL SetSecurityQualsVarnoWalker(Node *node, Index *index);
+
public:
// ctor
CTranslatorDXLToPlStmt(CMemoryPool *mp, CMDAccessor *md_accessor,
@@ -492,6 +518,8 @@ private:
CDXLTranslationContextArray *child_contexts, List **targetlist_out,
List **qual_out, CDXLTranslateContext *output_context);
+ void AddSecurityQuals(OID relId, List **qual, Index *index);
+
// translate the hash expr list of a redistribute motion node
void TranslateHashExprList(const CDXLNode *hash_expr_list_dxlnode,
const CDXLTranslateContext *child_context,
diff --git a/src/include/gpopt/translate/CTranslatorQueryToDXL.h b/src/include/gpopt/translate/CTranslatorQueryToDXL.h
index 4a7405dee7..b9e02a9b97 100644
--- a/src/include/gpopt/translate/CTranslatorQueryToDXL.h
+++ b/src/include/gpopt/translate/CTranslatorQueryToDXL.h
@@ -147,6 +147,9 @@ private:
// node is found
static void CheckUnsupportedNodeTypes(Query *query);
+ // walker to check if SUBLINK node is present in the security quals
+ static BOOL CheckSublinkInSecurityQuals(Node *node, void *context);
+
// check for SIRV functions in the targetlist without a FROM clause and
// throw an exception when found
void CheckSirvFuncsWithoutFromClause(Query *query);
diff --git a/src/test/regress/expected/equivclass_optimizer.out b/src/test/regress/expected/equivclass_optimizer.out
index 903441b8a4..a10953c8d4 100644
--- a/src/test/regress/expected/equivclass_optimizer.out
+++ b/src/test/regress/expected/equivclass_optimizer.out
@@ -459,16 +459,16 @@ set session authorization regress_user_ectest;
explain (costs off)
select * from ec0 a, ec1 b
where a.ff = b.ff and a.ff = 43::bigint::int8alias1;
- QUERY PLAN
-----------------------------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
- -> Index Scan using ec0_pkey on ec0 a
- Index Cond: (ff = '43'::int8alias1)
- -> Index Scan using ec1_pkey on ec1 b
- Index Cond: (ff = a.ff)
- Filter: ((f1 < '5'::int8alias1) AND (ff = '43'::int8alias1))
- Optimizer: Postgres query optimizer
+ Join Filter: true
+ -> Seq Scan on ec1
+ Filter: (f1 < '5'::int8alias1)
+ -> Index Scan using ec0_pkey on ec0
+ Index Cond: ((ff = ec1.ff) AND (ff = '43'::int8alias1))
+ Optimizer: GPORCA
(8 rows)
reset session authorization;
diff --git a/src/test/regress/expected/qp_rowsecurity.out b/src/test/regress/expected/qp_rowsecurity.out
new file mode 100644
index 0000000000..c809c76d32
--- /dev/null
+++ b/src/test/regress/expected/qp_rowsecurity.out
@@ -0,0 +1,986 @@
+--------------------------------------------------------------------------------
+-- Current implementation only supports SELECT and DELETE queries.
+-- Foreign Scan / Dynamic Foreign Scan with row level security is not supported.
+-- Any sort of index plans will not be generated by ORCA
+-- for a relation having RLS enabled.
+-- If the security quals contains sublinks then ORCA will fall back to planner.
+--------------------------------------------------------------------------------
+-- NOTE:
+-- The file rowsecurity.sql has a wider test coverage but the issue is most of
+-- the queries in that file are falling back to planner because of not supported
+-- features by ORCA such as non default collation, VIEW with WITH CHECK OPTION,
+-- Queries on coordinator-only tables, Query has row level security enabled and
+-- security quals contain sublinks etc. So rowsecurity.sql file is not providing
+-- much help in testing ORCA side changes.
+-- But on a high level some of the tests covered in rowsecurity.sql is
+ -- Table inheritance and RLS policy
+ -- There are tests related to partition relations but the test cases are
+ -- falling back due to various reasons like non default collation, VIEW with
+ -- WITH CHECK OPTION.
+ -- CTE with RLS
+ -- RLS with joins
+ -- View with WITH CHECK OPTION
+ -- Recursive Queries
+ -- Testing the output of queries by granting permissions to various roles
+ -- and groups and superuser database non-superuser with bypass privilege can
+ -- bypass RLS policy when disabled
+ --- RLS policy does not apply to table owner when RLS enabled.
+ -- RLS policy does not apply to table owner when RLS disabled.
+ -- only owner can change policies
+ -- FORCE ROW LEVEL SECURITY applies RLS to owners too
+ -- PREPARE statements
+ -- Duplicate policy names
+ -- Multiple policies on a table
+ -- INSERT in a table with no RLS by selecting from a relation having RLS
+ -- Default Deny policy
+ -- UPDATE/UPDATE with FROM clause/INSERT with Row-level security etc etc.
+-- So the tests that have been covered in qp_rowsecurity are mostly similar to
+-- that in rowsecurity.sql but since they are not falling back to planner, able
+-- to verify the ORCA side changes.
+--------------------------------------------------------------------------------
+----- SELECT queries on relation having row level security enabled -------------
+--------------------------------------------------------------------------------
+set optimizer_trace_fallback to on;
+create user new_user;
+create table foo_rls ( a int, b int, c int) distributed by (a);
+create table bar_rls ( p int, q int) distributed by (p);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+insert into foo_rls values (NULL,50,500);;
+insert into foo_rls values (NULL,60,NULL);
+insert into foo_rls values (NULL,70,NULL);
+insert into foo_rls values (NULL,NULL,600);
+insert into foo_rls values (NULL,NULL,700);
+vacuum analyze foo_rls;
+grant select on foo_rls to new_user;
+grant select on bar_rls to new_user;
+alter table foo_rls enable row level security;
+CREATE OR REPLACE FUNCTION leak_data(int) RETURNS boolean AS $$
+BEGIN
+ RAISE NOTICE 'Value of column is: %',$1;
+RETURN true;
+END;
+$$ LANGUAGE plpgsql;
+-- Permissive policy
+create policy p1 on foo_rls using (a * 10 = b and c > 300);
+set session authorization new_user;
+-- Query plan will have the filter defined in the policy [(a * 10) = b) AND (c > 300)]
+-- before query filter [leak_data(a)]
+explain (costs off ) select * from foo_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: ((c > 300) AND ((a * 10) = b) AND leak_data(a))
+ Optimizer: Postgres-based planner
+(4 rows)
+
+select * from foo_rls where leak_data(a);
+NOTICE: Value of column is: 5
+NOTICE: Value of column is: 4
+ a | b | c
+---+----+-----
+ 4 | 40 | 400
+ 5 | 50 | 500
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+-- All permissive policies which are applicable to a given query
+-- will be combined together using the Boolean “OR” operator
+create policy p1 on foo_rls as permissive for select using (a * 10 >= 30 );
+create policy p2 on foo_rls as permissive for select
+using (LEAST(a,b) >= 2);
+set session authorization new_user;
+-- The filter defined in the two permissive policies will be OR'ed together
+explain (costs off )select * from foo_rls where leak_data(c);
+ QUERY PLAN
+-----------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ Optimizer: Postgres-based planner
+(4 rows)
+
+select * from foo_rls where leak_data(c);
+NOTICE: Value of column is: 200
+NOTICE: Value of column is: 300
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: 400
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: <NULL>
+NOTICE: Value of column is: <NULL>
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 2 | 20 | 200
+ 3 | 30 | 300
+ 4 | 40 | 400
+ | 50 | 500
+ | 60 |
+ | 70 |
+(7 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+-- Restrictive policies
+-- There needs to be at least one permissive policy to grant access to records
+create policy p1 on foo_rls as restrictive for select using (a > 3);
+create policy p2 on foo_rls as restrictive for select using (b > 35);
+set session authorization new_user;
+-- No permissive policies defined on the relation, so no records will be
+-- returned
+explain (costs off ) select * from foo_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------
+ Result
+ One-Time Filter: false
+ Optimizer: Postgres-based planner
+(3 rows)
+
+reset session authorization ;
+create policy p3 on foo_rls as permissive for select using (c % 100 = 0);
+set session authorization new_user;
+-- Now after creating a permissive policy, the query will return records and the
+-- restrictive policies will be AND'ed with permissive policies
+explain (costs off ) select * from foo_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ Optimizer: Postgres-based planner
+(4 rows)
+
+select * from foo_rls where leak_data(a);
+NOTICE: Value of column is: 4
+NOTICE: Value of column is: 5
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 4 | 40 | 400
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+drop policy p3 on foo_rls;
+-- The RTE of the relation containing security quals is present inside a
+-- RTE_SUBQUERY rtekind
+create policy p1 on foo_rls as permissive for select using (b + 1 = 4 );
+create policy p2 on foo_rls as permissive for select using (b is distinct
+from c);
+set session authorization new_user;
+explain (costs off ) select * from (select * from foo_rls) t1, bar_rls where
+t1.a=bar_rls.p and bar_rls.q is null and leak_data(c);
+ QUERY PLAN
+------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Join
+ Hash Cond: (bar_rls.p = foo_rls.a)
+ -> Seq Scan on bar_rls
+ Filter: (q IS NULL)
+ -> Hash
+ -> Seq Scan on foo_rls
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ Optimizer: Postgres-based planner
+(9 rows)
+
+-- The RTE of the relation containing security quals is present inside a
+-- SUBLINK node
+explain (costs off ) select * from bar_rls where bar_rls.p in (select a
+from foo_rls where abs(a) >= 10 and leak_data(c)) and bar_rls.q is not null;
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Semi Join
+ Hash Cond: (bar_rls.p = foo_rls.a)
+ -> Seq Scan on bar_rls
+ Filter: (q IS NOT NULL)
+ -> Hash
+ -> Seq Scan on foo_rls
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (abs(a) >= 10) AND leak_data(c))
+ Optimizer: Postgres-based planner
+(9 rows)
+
+-- The RTE of the relation containing security quals is present inside a CTE
+explain (costs off ) with cte as (select * from foo_rls where
+a > LEAST(a,b)) select * from cte left join bar_rls on
+cte.a=bar_rls.p and q = 10 and leak_data(cte.a);
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Right Join
+ Hash Cond: (bar_rls.p = foo_rls.a)
+ Join Filter: leak_data(foo_rls.a)
+ -> Seq Scan on bar_rls
+ Filter: (q = 10)
+ -> Hash
+ -> Seq Scan on foo_rls
+ Filter: ((a > LEAST(a, b)) AND ((b IS DISTINCT FROM c) OR ((b + 1) = 4)))
+ Optimizer: Postgres-based planner
+(10 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+-- ORCA will fallback to planner if SUBLINK is present inside a security qual
+create policy p1 on foo_rls as permissive for select using (a in (select p
+from bar_rls));
+set session authorization new_user;
+explain (costs off ) select * from foo_rls;
+ QUERY PLAN
+-----------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: (hashed SubPlan 1)
+ SubPlan 1
+ -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Seq Scan on bar_rls
+ Optimizer: Postgres-based planner
+(7 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+-- ORCA will not generate any index plans when row level security is enabled
+-- for a relation
+create policy p1 on foo_rls as permissive for select using (b = 10);
+create index btindex on foo_rls using btree(a);
+-- Index Scan is generated by ORCA when the owner of the table runs the query
+set enable_seqscan to off;
+explain (costs off) select * from foo_rls where a is null and b = 10;
+ QUERY PLAN
+-------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Index Scan using btindex on foo_rls
+ Index Cond: (a IS NULL)
+ Filter: (b = 10)
+ Optimizer: Postgres-based planner
+(5 rows)
+
+-- Index Scan is not generated by ORCA when RLS enabled by ORCA
+set session authorization new_user;
+explain (costs off) select * from foo_rls where a is null;
+ QUERY PLAN
+-------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Index Scan using btindex on foo_rls
+ Index Cond: (a IS NULL)
+ Filter: (b = 10)
+ Optimizer: Postgres-based planner
+(5 rows)
+
+reset session authorization;
+-- Index Only Scan is generated by ORCA when the owner of the table runs the query
+set optimizer_enable_indexscan to off;
+explain (costs off) select a from foo_rls where a is null;
+ QUERY PLAN
+------------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Index Only Scan using btindex on foo_rls
+ Index Cond: (a IS NULL)
+ Optimizer: Postgres-based planner
+(4 rows)
+
+-- Index Only Scan is not generated by ORCA when RLS enabled
+set session authorization new_user;
+explain (costs off) select a from foo_rls where a is null;
+ QUERY PLAN
+-------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Index Scan using btindex on foo_rls
+ Index Cond: (a IS NULL)
+ Filter: (b = 10)
+ Optimizer: Postgres-based planner
+(5 rows)
+
+reset session authorization;
+set optimizer_enable_indexscan to on;
+reset enable_seqscan;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+drop table bar_rls cascade;
+--------------------------------------------------------------------------------
+----------- SELECT queries on partitioned tables with RLS enabled --------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20), default partition other_part);
+create table bar_part_rls ( p int, q int) distributed by (p) partition by range(q)
+(start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,5)i;
+insert into foo_part_rls values (NULL,50,500);;
+insert into foo_part_rls values (NULL,60,NULL);
+insert into foo_part_rls values (NULL,70,NULL);
+insert into foo_part_rls values (NULL,NULL,600);
+insert into foo_part_rls values (NULL,NULL,700);
+analyze foo_part_rls;
+grant select on foo_part_rls to new_user;
+grant select on bar_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+-- Permissive policy
+create policy p1 on foo_part_rls using (a * 10 = b and c > 300);
+set session authorization new_user;
+-- Query plan will have the filter defined in the policy [(a * 10) = b) AND (c > 300)]
+-- before query filter [leak_data(a)]
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: ((c > 300) AND ((a * 10) = b) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: ((c > 300) AND ((a * 10) = b) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: ((c > 300) AND ((a * 10) = b) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: ((c > 300) AND ((a * 10) = b) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_6
+ Filter: ((c > 300) AND ((a * 10) = b) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: ((c > 300) AND ((a * 10) = b) AND leak_data(a))
+ Optimizer: Postgres-based planner
+(15 rows)
+
+select * from foo_part_rls where leak_data(a);
+NOTICE: Value of column is: 4
+NOTICE: Value of column is: 5
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 4 | 40 | 400
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+-- All permissive policies which are applicable to a given query
+-- will be combined together using the Boolean “OR” operator
+create policy p1 on foo_part_rls as permissive for select using (a * 10 >= 30 );
+create policy p2 on foo_part_rls as permissive for select
+using (LEAST(a,b) >= 2);
+set session authorization new_user;
+-- The filter defined in the two permissive policies will be OR'ed together
+explain (costs off )select * from foo_part_rls where leak_data(c);
+ QUERY PLAN
+-----------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_6
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ Optimizer: Postgres-based planner
+(15 rows)
+
+select * from foo_part_rls where leak_data(c);
+NOTICE: Value of column is: 200
+NOTICE: Value of column is: 300
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: 400
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: <NULL>
+NOTICE: Value of column is: <NULL>
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 2 | 20 | 200
+ 3 | 30 | 300
+ 4 | 40 | 400
+ | 50 | 500
+ | 60 |
+ | 70 |
+(7 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+-- Restrictive policies
+-- There needs to be at least one permissive policy to grant access to records
+create policy p1 on foo_part_rls as restrictive for select using (a > 3);
+create policy p2 on foo_part_rls as restrictive for select using (b > 35);
+set session authorization new_user;
+-- No permissive policies defined on the relation, so no records will be
+-- returned
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------
+ Result
+ One-Time Filter: false
+ Optimizer: Postgres-based planner
+(3 rows)
+
+reset session authorization ;
+create policy p3 on foo_part_rls as permissive for select using (c % 100 = 0);
+set session authorization new_user;
+-- Now after creating a permissive policy, the query will return records and the
+-- restrictive policies will be AND'ed with permissive policies
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_6
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ Optimizer: Postgres-based planner
+(13 rows)
+
+select * from foo_part_rls where leak_data(a);
+NOTICE: Value of column is: 4
+NOTICE: Value of column is: 5
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 4 | 40 | 400
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+drop policy p3 on foo_part_rls;
+-- The RTE of the relation containing security quals is present inside a
+-- RTE_SUBQUERY rtekind
+create policy p1 on foo_part_rls as permissive for select using (b + 1 = 4 );
+create policy p2 on foo_part_rls as permissive for select using (b is distinct
+from c);
+set session authorization new_user;
+explain (costs off ) select * from (select * from foo_part_rls) t1, bar_part_rls
+where t1.a=bar_part_rls.p and bar_part_rls.q is not null and leak_data(c);
+ QUERY PLAN
+------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Join
+ Hash Cond: (bar_part_rls_1_prt_1.p = foo_part_rls_1_prt_2.a)
+ -> Append
+ -> Seq Scan on bar_part_rls_1_prt_1
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_2
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_3
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_4
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_5
+ Filter: (q IS NOT NULL)
+ -> Hash
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_6
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ Optimizer: Postgres-based planner
+(29 rows)
+
+-- The RTE of the relation containing security quals is present inside a
+-- SUBLINK node
+explain (costs off ) select * from bar_part_rls where bar_part_rls.p in
+(select a from foo_part_rls where abs(a) >= 10 and leak_data(c)) and
+bar_part_rls.q is not null;
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Semi Join
+ Hash Cond: (bar_part_rls_1_prt_1.p = foo_part_rls_1_prt_2.a)
+ -> Append
+ -> Seq Scan on bar_part_rls_1_prt_1
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_2
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_3
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_4
+ Filter: (q IS NOT NULL)
+ -> Seq Scan on bar_part_rls_1_prt_5
+ Filter: (q IS NOT NULL)
+ -> Hash
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (abs(a) >= 10) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (abs(a) >= 10) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (abs(a) >= 10) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (abs(a) >= 10) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_6
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (abs(a) >= 10) AND leak_data(c))
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (abs(a) >= 10) AND leak_data(c))
+ Optimizer: Postgres-based planner
+(29 rows)
+
+-- The RTE of the relation containing security quals is present inside a CTE
+explain (costs off ) with cte as (select * from foo_part_rls where
+a > LEAST(a,b)) select * from cte left join bar_part_rls on
+cte.a=bar_part_rls.p and q = 10 and leak_data(cte.a);
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Right Join
+ Hash Cond: (bar_part_rls_1_prt_1.p = foo_part_rls_1_prt_2.a)
+ Join Filter: leak_data(foo_part_rls_1_prt_2.a)
+ -> Seq Scan on bar_part_rls_1_prt_1
+ Filter: (q = 10)
+ -> Hash
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: ((a > LEAST(a, b)) AND ((b IS DISTINCT FROM c) OR ((b + 1) = 4)))
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: ((a > LEAST(a, b)) AND ((b IS DISTINCT FROM c) OR ((b + 1) = 4)))
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: ((a > LEAST(a, b)) AND ((b IS DISTINCT FROM c) OR ((b + 1) = 4)))
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: ((a > LEAST(a, b)) AND ((b IS DISTINCT FROM c) OR ((b + 1) = 4)))
+ -> Seq Scan on foo_part_rls_1_prt_6
+ Filter: ((a > LEAST(a, b)) AND ((b IS DISTINCT FROM c) OR ((b + 1) = 4)))
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: ((a > LEAST(a, b)) AND ((b IS DISTINCT FROM c) OR ((b + 1) = 4)))
+ Optimizer: Postgres-based planner
+(21 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+-- ORCA will fallback to planner if SUBLINK is present inside a security qual
+create policy p1 on foo_part_rls as permissive for select using (a in
+(select p from bar_part_rls));
+set session authorization new_user;
+explain (costs off ) select * from foo_part_rls where foo_part_rls.b <15;
+ QUERY PLAN
+-----------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: ((hashed SubPlan 1 (copy 2)) AND (b < 15))
+ SubPlan 1 (copy 2)
+ -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Append
+ -> Seq Scan on bar_part_rls_1_prt_1
+ -> Seq Scan on bar_part_rls_1_prt_2
+ -> Seq Scan on bar_part_rls_1_prt_3
+ -> Seq Scan on bar_part_rls_1_prt_4
+ -> Seq Scan on bar_part_rls_1_prt_5
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: ((hashed SubPlan 1 (copy 3)) AND (b < 15))
+ SubPlan 1 (copy 3)
+ -> Broadcast Motion 3:3 (slice3; segments: 3)
+ -> Append
+ -> Seq Scan on bar_part_rls_1_prt_1 bar_part_rls_1_prt_1_1
+ -> Seq Scan on bar_part_rls_1_prt_2 bar_part_rls_1_prt_2_1
+ -> Seq Scan on bar_part_rls_1_prt_3 bar_part_rls_1_prt_3_1
+ -> Seq Scan on bar_part_rls_1_prt_4 bar_part_rls_1_prt_4_1
+ -> Seq Scan on bar_part_rls_1_prt_5 bar_part_rls_1_prt_5_1
+ Optimizer: Postgres-based planner
+(23 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+-- ORCA will not generate any index plans when row level security is enabled
+-- for a relation
+create policy p1 on foo_part_rls as permissive for select using (b = 10);
+create index btindex on foo_part_rls using btree(a);
+-- Dynamic Index Scan is generated by ORCA when the owner of the table runs
+-- the query
+set enable_seqscan to off;
+explain (costs off) select * from foo_part_rls where a is null;
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Append
+ -> Index Scan using foo_part_rls_1_prt_2_a_idx on foo_part_rls_1_prt_2
+ Index Cond: (a IS NULL)
+ -> Index Scan using foo_part_rls_1_prt_3_a_idx on foo_part_rls_1_prt_3
+ Index Cond: (a IS NULL)
+ -> Index Scan using foo_part_rls_1_prt_4_a_idx on foo_part_rls_1_prt_4
+ Index Cond: (a IS NULL)
+ -> Index Scan using foo_part_rls_1_prt_5_a_idx on foo_part_rls_1_prt_5
+ Index Cond: (a IS NULL)
+ -> Index Scan using foo_part_rls_1_prt_6_a_idx on foo_part_rls_1_prt_6
+ Index Cond: (a IS NULL)
+ -> Index Scan using foo_part_rls_1_prt_other_part_a_idx on foo_part_rls_1_prt_other_part
+ Index Cond: (a IS NULL)
+ Optimizer: Postgres-based planner
+(15 rows)
+
+-- Dynamic Index Scan is not generated by ORCA when RLS is enabled
+set session authorization new_user;
+explain (costs off) select * from foo_part_rls where a is null;
+ QUERY PLAN
+---------------------------------------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Index Scan using foo_part_rls_1_prt_2_a_idx on foo_part_rls_1_prt_2
+ Index Cond: (a IS NULL)
+ Filter: (b = 10)
+ Optimizer: Postgres-based planner
+(5 rows)
+
+reset session authorization;
+reset enable_seqscan;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+drop table bar_part_rls cascade;
+drop function leak_data(int);
+--------------------------------------------------------------------------------
+----------------- Creating policies on leaf partitions -------------------------
+--------------------------------------------------------------------------------
+create table rootpart (a int, b int) distributed by (a) partition by range(a)
+(start(0) end(10) every(5));
+insert into rootpart select i,i from generate_series(0,9)i;
+-- select permission is only for root partition and not for child partition
+grant select on rootpart to new_user;
+alter table rootpart_1_prt_2 enable row level security;
+create policy p1 on rootpart_1_prt_2 using (a>=7);
+set session authorization new_user;
+explain (costs off) select * from rootpart;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on rootpart_1_prt_1
+ -> Seq Scan on rootpart_1_prt_2
+ Optimizer: Postgres-based planner
+(5 rows)
+
+-- Issue #16961
+-- ORCA and planner should not generate a plan and show error permission denied
+-- for leaf partition
+explain (costs off) select * from rootpart_1_prt_2;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on rootpart_1_prt_2
+ Filter: (a >= 7)
+ Optimizer: Postgres-based planner
+(4 rows)
+
+reset session authorization;
+drop policy p1 on rootpart_1_prt_2;
+drop table rootpart;
+--------------------------------------------------------------------------------
+----------------- Grant SELECT to only a leaf partition ------------------------
+--------------------------------------------------------------------------------
+create table rootpart (a int, b int) distributed by (a) partition by range(a)
+(start(0) end(10) every(5));
+insert into rootpart select i,i from generate_series(0,9)i;
+grant select on rootpart_1_prt_2 to new_user;
+alter table rootpart_1_prt_2 enable row level security;
+create policy p1 on rootpart_1_prt_2 using (a>=7);
+set session authorization new_user;
+-- Since the SELECT permission is only for a leaf partition [rootpart_1_prt_2],
+-- querying the root will error out
+explain (costs off) select * from rootpart;
+ERROR: permission denied for table rootpart
+explain (costs off) select * from rootpart_1_prt_1;
+ERROR: permission denied for table rootpart_1_prt_1
+-- Below query will work fine as the user has SELECT permission on this root
+-- partition
+explain (costs off) select * from rootpart_1_prt_2;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on rootpart_1_prt_2
+ Filter: (a >= 7)
+ Optimizer: Postgres-based planner
+(4 rows)
+
+reset session authorization;
+drop policy p1 on rootpart_1_prt_2;
+drop table rootpart;
+--------------------------------------------------------------------------------
+-------------------------- Multilevel Partitions -------------------------------
+--------------------------------------------------------------------------------
+create table rootTab(a int) distributed by (a) partition by range(a);
+create table roottabmid1(a int) distributed by (a) partition by range(a);
+create table roottableaf1(a int) distributed by (a);
+create table roottableaf2(a int) distributed by (a);
+alter table roottab attach partition roottabmid1 for values from (0) to (10);
+alter table roottabmid1 attach partition roottableaf1 for values from (0) to (5);
+alter table roottabmid1 attach partition roottableaf2 for values from (5) to (10);
+insert into roottab select i from generate_series(0,9)i;
+grant select on roottab to new_user;
+alter table roottableaf2 enable row level security;
+create policy p1 on roottableaf2 using (a>=7);
+set session authorization new_user;
+-- Querying the root will fallback to planner as ORCA doesn't supports
+-- Multi-level partitioned tables
+explain (costs off) select * from roottab;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on roottableaf1
+ -> Seq Scan on roottableaf2
+ Optimizer: Postgres-based planner
+(5 rows)
+
+explain (costs off) select * from roottabmid1;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on roottableaf1
+ -> Seq Scan on roottableaf2
+ Optimizer: Postgres-based planner
+(5 rows)
+
+explain (costs off) select * from roottableaf1;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on roottableaf1
+ Optimizer: Postgres-based planner
+(3 rows)
+
+explain (costs off) select * from roottableaf2;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on roottableaf2
+ Filter: (a >= 7)
+ Optimizer: Postgres-based planner
+(4 rows)
+
+reset session authorization;
+drop policy p1 on roottableaf2;
+drop table roottab;
+--------------------------------------------------------------------------------
+------------------- Inherited Tables with RLS enabled --------------------------
+--------------------------------------------------------------------------------
+create table parent (a int, b int) distributed by (a);
+create table child1 (c int) inherits (parent);
+NOTICE: table has parent, setting distribution columns to match parent table
+create table child2 (d int) inherits (parent);
+NOTICE: table has parent, setting distribution columns to match parent table
+-- SELECT permission on parent
+grant select on parent to new_user;
+alter table parent enable row level security;
+create policy p1 on parent using (a>=7);
+set session authorization new_user;
+-- Querying the parent will fallback to planner as ORCA doesn't supports
+-- Inherited tables
+explain (costs off) select * from parent;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on parent
+ Filter: (a >= 7)
+ -> Seq Scan on child1
+ Filter: (a >= 7)
+ -> Seq Scan on child2
+ Filter: (a >= 7)
+ Optimizer: Postgres-based planner
+(9 rows)
+
+-- Below queries will error out as no SELECT permission for user on child
+-- relations
+explain (costs off) select * from child1;
+ERROR: permission denied for table child1
+explain (costs off) select * from child2;
+ERROR: permission denied for table child2
+reset session authorization;
+grant select on child1 to new_user;
+set session authorization new_user;
+-- After granting SELECT permission the below query will work
+explain (costs off) select * from child1;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on child1
+ Optimizer: Postgres-based planner
+(3 rows)
+
+reset session authorization;
+drop policy p1 on parent;
+drop table parent cascade;
+NOTICE: drop cascades to 2 other objects
+DETAIL: drop cascades to table child1
+drop cascades to table child2
+--------------------------------------------------------------------------------
+----- INSERT queries on relation having row level security enabled -------------
+------ ORCA will fallback to planner for INSERT with RLS anabled ---------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant insert on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=3);
+set session authorization new_user;
+explain (costs off) insert into foo_rls values (1,1,1);
+ QUERY PLAN
+-----------------------------------
+ Insert on foo_rls
+ -> Result
+ Optimizer: Postgres-based planner
+(3 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+--------------------------------------------------------------------------------
+--------- INSERT queries on partitioned relation having RLS enabled ------------
+--------- ORCA will fallback to planner for INSERT with RLS anabled ------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant insert on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=500);
+set session authorization new_user;
+explain (costs off) insert into foo_part_rls values (-10,-10,-10);
+ QUERY PLAN
+-----------------------------------
+ Insert on foo_part_rls
+ -> Result
+ Optimizer: Postgres-based planner
+(3 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+--------------------------------------------------------------------------------
+----- UPDATE queries on relation having row level security enabled -------------
+------ ORCA will fallback to planner for UPDATE with RLS anabled ---------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant select,update on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=3);
+set session authorization new_user;
+explain (costs off) update foo_rls set a=-10 where c=4;
+ QUERY PLAN
+---------------------------------------------------------------
+ Update on foo_rls
+ -> Explicit Redistribute Motion 3:3 (slice1; segments: 3)
+ -> Split
+ -> Seq Scan on foo_rls
+ Filter: ((c >= 3) AND (c = 4))
+ Optimizer: Postgres-based planner
+(6 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+--------------------------------------------------------------------------------
+--------- UPDATE queries on partitioned relation having RLS enabled ------------
+--------- ORCA will fallback to planner for UPDATE with RLS anabled ------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant select,update on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=500);
+set session authorization new_user;
+explain (costs off) update foo_part_rls set a=10 where foo_part_rls.c = 800;
+ QUERY PLAN
+---------------------------------------------------------------
+ Update on foo_part_rls
+ Update on foo_part_rls_1_prt_1
+ Update on foo_part_rls_1_prt_2
+ Update on foo_part_rls_1_prt_3
+ Update on foo_part_rls_1_prt_4
+ Update on foo_part_rls_1_prt_5
+ -> Explicit Redistribute Motion 3:3 (slice1; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_1
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice2; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice3; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice4; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice5; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: ((c >= 500) AND (c = 800))
+ Optimizer: Postgres-based planner
+(27 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+--------------------------------------------------------------------------------
+----- DELETE queries on relation having row level security enabled -------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant select,delete on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=300);
+set session authorization new_user;
+explain (costs off) delete from foo_rls where foo_rls.b=30;
+ QUERY PLAN
+-------------------------------------------
+ Delete on foo_rls
+ -> Seq Scan on foo_rls
+ Filter: ((c >= 300) AND (b = 30))
+ Optimizer: Postgres-based planner
+(4 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+--------------------------------------------------------------------------------
+----- DELETE queries on on partitioned relation having RLS enabled -------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant select,delete on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=300);
+set session authorization new_user;
+explain (costs off) delete from foo_part_rls where foo_part_rls.b=30;
+ QUERY PLAN
+-------------------------------------------
+ Delete on foo_part_rls
+ Delete on foo_part_rls_1_prt_2
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: ((c >= 300) AND (b = 30))
+ Optimizer: Postgres-based planner
+(5 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+drop user new_user;
+reset optimizer_trace_fallback;
diff --git a/src/test/regress/expected/qp_rowsecurity_optimizer.out b/src/test/regress/expected/qp_rowsecurity_optimizer.out
new file mode 100644
index 0000000000..d091049e40
--- /dev/null
+++ b/src/test/regress/expected/qp_rowsecurity_optimizer.out
@@ -0,0 +1,920 @@
+--------------------------------------------------------------------------------
+-- Current implementation only supports SELECT and DELETE queries.
+-- Foreign Scan / Dynamic Foreign Scan with row level security is not supported.
+-- Any sort of index plans will not be generated by ORCA
+-- for a relation having RLS enabled.
+-- If the security quals contains sublinks then ORCA will fall back to planner.
+--------------------------------------------------------------------------------
+-- NOTE:
+-- The file rowsecurity.sql has a wider test coverage but the issue is most of
+-- the queries in that file are falling back to planner because of not supported
+-- features by ORCA such as non default collation, VIEW with WITH CHECK OPTION,
+-- Queries on coordinator-only tables, Query has row level security enabled and
+-- security quals contain sublinks etc. So rowsecurity.sql file is not providing
+-- much help in testing ORCA side changes.
+-- But on a high level some of the tests covered in rowsecurity.sql is
+ -- Table inheritance and RLS policy
+ -- There are tests related to partition relations but the test cases are
+ -- falling back due to various reasons like non default collation, VIEW with
+ -- WITH CHECK OPTION.
+ -- CTE with RLS
+ -- RLS with joins
+ -- View with WITH CHECK OPTION
+ -- Recursive Queries
+ -- Testing the output of queries by granting permissions to various roles
+ -- and groups and superuser database non-superuser with bypass privilege can
+ -- bypass RLS policy when disabled
+ --- RLS policy does not apply to table owner when RLS enabled.
+ -- RLS policy does not apply to table owner when RLS disabled.
+ -- only owner can change policies
+ -- FORCE ROW LEVEL SECURITY applies RLS to owners too
+ -- PREPARE statements
+ -- Duplicate policy names
+ -- Multiple policies on a table
+ -- INSERT in a table with no RLS by selecting from a relation having RLS
+ -- Default Deny policy
+ -- UPDATE/UPDATE with FROM clause/INSERT with Row-level security etc etc.
+-- So the tests that have been covered in qp_rowsecurity are mostly similar to
+-- that in rowsecurity.sql but since they are not falling back to planner, able
+-- to verify the ORCA side changes.
+--------------------------------------------------------------------------------
+----- SELECT queries on relation having row level security enabled -------------
+--------------------------------------------------------------------------------
+set optimizer_trace_fallback to on;
+create user new_user;
+create table foo_rls ( a int, b int, c int) distributed by (a);
+create table bar_rls ( p int, q int) distributed by (p);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+insert into foo_rls values (NULL,50,500);;
+insert into foo_rls values (NULL,60,NULL);
+insert into foo_rls values (NULL,70,NULL);
+insert into foo_rls values (NULL,NULL,600);
+insert into foo_rls values (NULL,NULL,700);
+vacuum analyze foo_rls;
+grant select on foo_rls to new_user;
+grant select on bar_rls to new_user;
+alter table foo_rls enable row level security;
+CREATE OR REPLACE FUNCTION leak_data(int) RETURNS boolean AS $$
+BEGIN
+ RAISE NOTICE 'Value of column is: %',$1;
+RETURN true;
+END;
+$$ LANGUAGE plpgsql;
+-- Permissive policy
+create policy p1 on foo_rls using (a * 10 = b and c > 300);
+set session authorization new_user;
+-- Query plan will have the filter defined in the policy [(a * 10) = b) AND (c > 300)]
+-- before query filter [leak_data(a)]
+explain (costs off ) select * from foo_rls where leak_data(a);
+ QUERY PLAN
+-------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: ((((a * 10) = b) AND (c > 300)) AND leak_data(a))
+ Optimizer: GPORCA
+(4 rows)
+
+select * from foo_rls where leak_data(a);
+NOTICE: Value of column is: 4
+NOTICE: Value of column is: 5
+ a | b | c
+---+----+-----
+ 4 | 40 | 400
+ 5 | 50 | 500
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+-- All permissive policies which are applicable to a given query
+-- will be combined together using the Boolean “OR” operator
+create policy p1 on foo_rls as permissive for select using (a * 10 >= 30 );
+create policy p2 on foo_rls as permissive for select
+using (LEAST(a,b) >= 2);
+set session authorization new_user;
+-- The filter defined in the two permissive policies will be OR'ed together
+explain (costs off )select * from foo_rls where leak_data(c);
+ QUERY PLAN
+-----------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ Optimizer: GPORCA
+(4 rows)
+
+select * from foo_rls where leak_data(c);
+NOTICE: Value of column is: 200
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: 300
+NOTICE: Value of column is: 400
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: <NULL>
+NOTICE: Value of column is: <NULL>
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 2 | 20 | 200
+ 3 | 30 | 300
+ 4 | 40 | 400
+ | 50 | 500
+ | 60 |
+ | 70 |
+(7 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+-- Restrictive policies
+-- There needs to be at least one permissive policy to grant access to records
+create policy p1 on foo_rls as restrictive for select using (a > 3);
+create policy p2 on foo_rls as restrictive for select using (b > 35);
+set session authorization new_user;
+-- No permissive policies defined on the relation, so no records will be
+-- returned
+explain (costs off ) select * from foo_rls where leak_data(a);
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: (false AND leak_data(a))
+ Optimizer: GPORCA
+(4 rows)
+
+reset session authorization ;
+create policy p3 on foo_rls as permissive for select using (c % 100 = 0);
+set session authorization new_user;
+-- Now after creating a permissive policy, the query will return records and the
+-- restrictive policies will be AND'ed with permissive policies
+explain (costs off ) select * from foo_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ Optimizer: GPORCA
+(4 rows)
+
+select * from foo_rls where leak_data(a);
+NOTICE: Value of column is: 4
+NOTICE: Value of column is: 5
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 4 | 40 | 400
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+drop policy p3 on foo_rls;
+-- The RTE of the relation containing security quals is present inside a
+-- RTE_SUBQUERY rtekind
+create policy p1 on foo_rls as permissive for select using (b + 1 = 4 );
+create policy p2 on foo_rls as permissive for select using (b is distinct
+from c);
+set session authorization new_user;
+explain (costs off ) select * from (select * from foo_rls) t1, bar_rls where
+t1.a=bar_rls.p and bar_rls.q is null and leak_data(c);
+ QUERY PLAN
+------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Join
+ Hash Cond: (foo_rls.a = bar_rls.p)
+ -> Seq Scan on foo_rls
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ -> Hash
+ -> Seq Scan on bar_rls
+ Filter: (q IS NULL)
+ Optimizer: GPORCA
+(9 rows)
+
+-- The RTE of the relation containing security quals is present inside a
+-- SUBLINK node
+explain (costs off ) select * from bar_rls where bar_rls.p in (select a
+from foo_rls where abs(a) >= 10 and leak_data(c)) and bar_rls.q is not null;
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Semi Join
+ Hash Cond: (bar_rls.p = foo_rls.a)
+ -> Seq Scan on bar_rls
+ Filter: (NOT (q IS NULL))
+ -> Hash
+ -> Seq Scan on foo_rls
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND ((abs(a) >= 10) AND leak_data(c)))
+ Optimizer: GPORCA
+(9 rows)
+
+-- The RTE of the relation containing security quals is present inside a CTE
+explain (costs off ) with cte as (select * from foo_rls where
+a > LEAST(a,b)) select * from cte left join bar_rls on
+cte.a=bar_rls.p and q = 10 and leak_data(cte.a);
+ QUERY PLAN
+-----------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Left Join
+ Hash Cond: (foo_rls.a = bar_rls.p)
+ Join Filter: leak_data(foo_rls.a)
+ -> Seq Scan on foo_rls
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (a > LEAST(a, b)))
+ -> Hash
+ -> Seq Scan on bar_rls
+ Filter: (q = 10)
+ Optimizer: GPORCA
+(10 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+-- ORCA will fallback to planner if SUBLINK is present inside a security qual
+create policy p1 on foo_rls as permissive for select using (a in (select p
+from bar_rls));
+set session authorization new_user;
+explain (costs off ) select * from foo_rls;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
+ QUERY PLAN
+-----------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on foo_rls
+ Filter: (hashed SubPlan 1)
+ SubPlan 1
+ -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Seq Scan on bar_rls
+ Optimizer: Postgres-based planner
+(7 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+-- ORCA will not generate any index plans when row level security is enabled
+-- for a relation
+create policy p1 on foo_rls as permissive for select using (b = 10);
+create index btindex on foo_rls using btree(a);
+-- Index Scan is generated by ORCA when the owner of the table runs the query
+set enable_seqscan to off;
+explain (costs off) select * from foo_rls where a is null and b = 10;
+ QUERY PLAN
+-------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Index Scan using btindex on foo_rls
+ Index Cond: (a IS NULL)
+ Filter: (b = 10)
+ Optimizer: GPORCA
+(5 rows)
+
+-- Index Scan is not generated by ORCA when RLS enabled by ORCA
+set session authorization new_user;
+explain (costs off) select * from foo_rls where a is null;
+ QUERY PLAN
+--------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Seq Scan on foo_rls
+ Filter: ((b = 10) AND (a IS NULL))
+ Optimizer: GPORCA
+(4 rows)
+
+reset session authorization;
+-- Index Only Scan is generated by ORCA when the owner of the table runs the query
+set optimizer_enable_indexscan to off;
+explain (costs off) select a from foo_rls where a is null;
+ QUERY PLAN
+------------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Index Only Scan using btindex on foo_rls
+ Index Cond: (a IS NULL)
+ Optimizer: GPORCA
+(4 rows)
+
+-- Index Only Scan is not generated by ORCA when RLS enabled
+set session authorization new_user;
+explain (costs off) select a from foo_rls where a is null;
+ QUERY PLAN
+--------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Seq Scan on foo_rls
+ Filter: ((b = 10) AND (a IS NULL))
+ Optimizer: GPORCA
+(4 rows)
+
+reset session authorization;
+set optimizer_enable_indexscan to on;
+reset enable_seqscan;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+drop table bar_rls cascade;
+--------------------------------------------------------------------------------
+----------- SELECT queries on partitioned tables with RLS enabled --------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20), default partition other_part);
+create table bar_part_rls ( p int, q int) distributed by (p) partition by range(q)
+(start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,5)i;
+insert into foo_part_rls values (NULL,50,500);;
+insert into foo_part_rls values (NULL,60,NULL);
+insert into foo_part_rls values (NULL,70,NULL);
+insert into foo_part_rls values (NULL,NULL,600);
+insert into foo_part_rls values (NULL,NULL,700);
+analyze foo_part_rls;
+grant select on foo_part_rls to new_user;
+grant select on bar_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+-- Permissive policy
+create policy p1 on foo_part_rls using (a * 10 = b and c > 300);
+set session authorization new_user;
+-- Query plan will have the filter defined in the policy [(a * 10) = b) AND (c > 300)]
+-- before query filter [leak_data(a)]
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+ QUERY PLAN
+-------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: ((((a * 10) = b) AND (c > 300)) AND leak_data(a))
+ Optimizer: GPORCA
+(5 rows)
+
+select * from foo_part_rls where leak_data(a);
+NOTICE: Value of column is: 4
+NOTICE: Value of column is: 5
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 4 | 40 | 400
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+-- All permissive policies which are applicable to a given query
+-- will be combined together using the Boolean “OR” operator
+create policy p1 on foo_part_rls as permissive for select using (a * 10 >= 30 );
+create policy p2 on foo_part_rls as permissive for select
+using (LEAST(a,b) >= 2);
+set session authorization new_user;
+-- The filter defined in the two permissive policies will be OR'ed together
+explain (costs off )select * from foo_part_rls where leak_data(c);
+ QUERY PLAN
+-----------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: (((LEAST(a, b) >= 2) OR ((a * 10) >= 30)) AND leak_data(c))
+ Optimizer: GPORCA
+(5 rows)
+
+select * from foo_part_rls where leak_data(c);
+NOTICE: Value of column is: 200
+NOTICE: Value of column is: 300
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: 400
+NOTICE: Value of column is: 500
+NOTICE: Value of column is: <NULL>
+NOTICE: Value of column is: <NULL>
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 2 | 20 | 200
+ 3 | 30 | 300
+ 4 | 40 | 400
+ | 50 | 500
+ | 60 |
+ | 70 |
+(7 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+-- Restrictive policies
+-- There needs to be at least one permissive policy to grant access to records
+create policy p1 on foo_part_rls as restrictive for select using (a > 3);
+create policy p2 on foo_part_rls as restrictive for select using (b > 35);
+set session authorization new_user;
+-- No permissive policies defined on the relation, so no records will be
+-- returned
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+ QUERY PLAN
+----------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: (false AND leak_data(a))
+ Optimizer: GPORCA
+(5 rows)
+
+reset session authorization ;
+create policy p3 on foo_part_rls as permissive for select using (c % 100 = 0);
+set session authorization new_user;
+-- Now after creating a permissive policy, the query will return records and the
+-- restrictive policies will be AND'ed with permissive policies
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+ QUERY PLAN
+-----------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: ((a > 3) AND (b > 35) AND ((c % 100) = 0) AND leak_data(a))
+ Optimizer: GPORCA
+(5 rows)
+
+select * from foo_part_rls where leak_data(a);
+NOTICE: Value of column is: 4
+NOTICE: Value of column is: 5
+ a | b | c
+---+----+-----
+ 5 | 50 | 500
+ 4 | 40 | 400
+(2 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+drop policy p3 on foo_part_rls;
+-- The RTE of the relation containing security quals is present inside a
+-- RTE_SUBQUERY rtekind
+create policy p1 on foo_part_rls as permissive for select using (b + 1 = 4 );
+create policy p2 on foo_part_rls as permissive for select using (b is distinct
+from c);
+set session authorization new_user;
+explain (costs off ) select * from (select * from foo_part_rls) t1, bar_part_rls
+where t1.a=bar_part_rls.p and bar_part_rls.q is not null and leak_data(c);
+ QUERY PLAN
+------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Join
+ Hash Cond: (foo_part_rls.a = bar_part_rls.p)
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND leak_data(c))
+ -> Hash
+ -> Dynamic Seq Scan on bar_part_rls
+ Number of partitions to scan: 5 (out of 5)
+ Filter: (NOT (q IS NULL))
+ Optimizer: GPORCA
+(11 rows)
+
+-- The RTE of the relation containing security quals is present inside a
+-- SUBLINK node
+explain (costs off ) select * from bar_part_rls where bar_part_rls.p in
+(select a from foo_part_rls where abs(a) >= 10 and leak_data(c)) and
+bar_part_rls.q is not null;
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Semi Join
+ Hash Cond: (bar_part_rls.p = foo_part_rls.a)
+ -> Dynamic Seq Scan on bar_part_rls
+ Number of partitions to scan: 5 (out of 5)
+ Filter: (NOT (q IS NULL))
+ -> Hash
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND ((abs(a) >= 10) AND leak_data(c)))
+ Optimizer: GPORCA
+(11 rows)
+
+-- The RTE of the relation containing security quals is present inside a CTE
+explain (costs off ) with cte as (select * from foo_part_rls where
+a > LEAST(a,b)) select * from cte left join bar_part_rls on
+cte.a=bar_part_rls.p and q = 10 and leak_data(cte.a);
+ QUERY PLAN
+-----------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Hash Left Join
+ Hash Cond: (foo_part_rls.a = bar_part_rls.p)
+ Join Filter: leak_data(foo_part_rls.a)
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: (((b IS DISTINCT FROM c) OR ((b + 1) = 4)) AND (a > LEAST(a, b)))
+ -> Hash
+ -> Dynamic Seq Scan on bar_part_rls
+ Number of partitions to scan: 1 (out of 5)
+ Filter: (q = 10)
+ Optimizer: GPORCA
+(12 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+-- ORCA will fallback to planner if SUBLINK is present inside a security qual
+create policy p1 on foo_part_rls as permissive for select using (a in
+(select p from bar_part_rls));
+set session authorization new_user;
+explain (costs off ) select * from foo_part_rls where foo_part_rls.b <15;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
+ QUERY PLAN
+-----------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: ((hashed SubPlan 1 (copy 2)) AND (b < 15))
+ SubPlan 1 (copy 2)
+ -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Append
+ -> Seq Scan on bar_part_rls_1_prt_1
+ -> Seq Scan on bar_part_rls_1_prt_2
+ -> Seq Scan on bar_part_rls_1_prt_3
+ -> Seq Scan on bar_part_rls_1_prt_4
+ -> Seq Scan on bar_part_rls_1_prt_5
+ -> Seq Scan on foo_part_rls_1_prt_other_part
+ Filter: ((hashed SubPlan 1 (copy 3)) AND (b < 15))
+ SubPlan 1 (copy 3)
+ -> Broadcast Motion 3:3 (slice3; segments: 3)
+ -> Append
+ -> Seq Scan on bar_part_rls_1_prt_1 bar_part_rls_1_prt_1_1
+ -> Seq Scan on bar_part_rls_1_prt_2 bar_part_rls_1_prt_2_1
+ -> Seq Scan on bar_part_rls_1_prt_3 bar_part_rls_1_prt_3_1
+ -> Seq Scan on bar_part_rls_1_prt_4 bar_part_rls_1_prt_4_1
+ -> Seq Scan on bar_part_rls_1_prt_5 bar_part_rls_1_prt_5_1
+ Optimizer: Postgres-based planner
+(23 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+-- ORCA will not generate any index plans when row level security is enabled
+-- for a relation
+create policy p1 on foo_part_rls as permissive for select using (b = 10);
+create index btindex on foo_part_rls using btree(a);
+-- Dynamic Index Scan is generated by ORCA when the owner of the table runs
+-- the query
+set enable_seqscan to off;
+explain (costs off) select * from foo_part_rls where a is null;
+ QUERY PLAN
+-----------------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Dynamic Index Scan on btindex on foo_part_rls
+ Index Cond: (a IS NULL)
+ Number of partitions to scan: 6 (out of 6)
+ Optimizer: GPORCA
+(5 rows)
+
+-- Dynamic Index Scan is not generated by ORCA when RLS is enabled
+set session authorization new_user;
+explain (costs off) select * from foo_part_rls where a is null;
+ QUERY PLAN
+----------------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1)
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 6 (out of 6)
+ Filter: ((b = 10) AND (a IS NULL))
+ Optimizer: GPORCA
+(5 rows)
+
+reset session authorization;
+reset enable_seqscan;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+drop table bar_part_rls cascade;
+drop function leak_data(int);
+--------------------------------------------------------------------------------
+----------------- Creating policies on leaf partitions -------------------------
+--------------------------------------------------------------------------------
+create table rootpart (a int, b int) distributed by (a) partition by range(a)
+(start(0) end(10) every(5));
+insert into rootpart select i,i from generate_series(0,9)i;
+-- select permission is only for root partition and not for child partition
+grant select on rootpart to new_user;
+alter table rootpart_1_prt_2 enable row level security;
+create policy p1 on rootpart_1_prt_2 using (a>=7);
+set session authorization new_user;
+explain (costs off) select * from rootpart;
+ QUERY PLAN
+----------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Dynamic Seq Scan on rootpart
+ Number of partitions to scan: 2 (out of 2)
+ Optimizer: GPORCA
+(4 rows)
+
+-- Issue #16961
+-- ORCA and planner should not generate a plan and show error permission denied
+-- for leaf partition
+explain (costs off) select * from rootpart_1_prt_2;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on rootpart_1_prt_2
+ Filter: (a >= 7)
+ Optimizer: GPORCA
+(4 rows)
+
+reset session authorization;
+drop policy p1 on rootpart_1_prt_2;
+drop table rootpart;
+--------------------------------------------------------------------------------
+----------------- Grant SELECT to only a leaf partition ------------------------
+--------------------------------------------------------------------------------
+create table rootpart (a int, b int) distributed by (a) partition by range(a)
+(start(0) end(10) every(5));
+insert into rootpart select i,i from generate_series(0,9)i;
+grant select on rootpart_1_prt_2 to new_user;
+alter table rootpart_1_prt_2 enable row level security;
+create policy p1 on rootpart_1_prt_2 using (a>=7);
+set session authorization new_user;
+-- Since the SELECT permission is only for a leaf partition [rootpart_1_prt_2],
+-- querying the root will error out
+explain (costs off) select * from rootpart;
+ERROR: permission denied for table rootpart
+explain (costs off) select * from rootpart_1_prt_1;
+ERROR: permission denied for table rootpart_1_prt_1
+-- Below query will work fine as the user has SELECT permission on this root
+-- partition
+explain (costs off) select * from rootpart_1_prt_2;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on rootpart_1_prt_2
+ Filter: (a >= 7)
+ Optimizer: GPORCA
+(4 rows)
+
+reset session authorization;
+drop policy p1 on rootpart_1_prt_2;
+drop table rootpart;
+--------------------------------------------------------------------------------
+-------------------------- Multilevel Partitions -------------------------------
+--------------------------------------------------------------------------------
+create table rootTab(a int) distributed by (a) partition by range(a);
+create table roottabmid1(a int) distributed by (a) partition by range(a);
+create table roottableaf1(a int) distributed by (a);
+create table roottableaf2(a int) distributed by (a);
+alter table roottab attach partition roottabmid1 for values from (0) to (10);
+alter table roottabmid1 attach partition roottableaf1 for values from (0) to (5);
+alter table roottabmid1 attach partition roottableaf2 for values from (5) to (10);
+insert into roottab select i from generate_series(0,9)i;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Multi-level partitioned tables
+grant select on roottab to new_user;
+alter table roottableaf2 enable row level security;
+create policy p1 on roottableaf2 using (a>=7);
+set session authorization new_user;
+-- Querying the root will fallback to planner as ORCA doesn't supports
+-- Multi-level partitioned tables
+explain (costs off) select * from roottab;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Multi-level partitioned tables
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on roottableaf1
+ -> Seq Scan on roottableaf2
+ Optimizer: Postgres-based planner
+(5 rows)
+
+explain (costs off) select * from roottabmid1;
+ QUERY PLAN
+----------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Dynamic Seq Scan on roottabmid1
+ Number of partitions to scan: 2 (out of 2)
+ Optimizer: GPORCA
+(4 rows)
+
+explain (costs off) select * from roottableaf1;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on roottableaf1
+ Optimizer: GPORCA
+(3 rows)
+
+explain (costs off) select * from roottableaf2;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on roottableaf2
+ Filter: (a >= 7)
+ Optimizer: GPORCA
+(4 rows)
+
+reset session authorization;
+drop policy p1 on roottableaf2;
+drop table roottab;
+--------------------------------------------------------------------------------
+------------------- Inherited Tables with RLS enabled --------------------------
+--------------------------------------------------------------------------------
+create table parent (a int, b int) distributed by (a);
+create table child1 (c int) inherits (parent);
+NOTICE: table has parent, setting distribution columns to match parent table
+create table child2 (d int) inherits (parent);
+NOTICE: table has parent, setting distribution columns to match parent table
+-- SELECT permission on parent
+grant select on parent to new_user;
+alter table parent enable row level security;
+create policy p1 on parent using (a>=7);
+set session authorization new_user;
+-- Querying the parent will fallback to planner as ORCA doesn't supports
+-- Inherited tables
+explain (costs off) select * from parent;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on parent
+ Filter: (a >= 7)
+ -> Seq Scan on child1
+ Filter: (a >= 7)
+ -> Seq Scan on child2
+ Filter: (a >= 7)
+ Optimizer: Postgres-based planner
+(9 rows)
+
+-- Below queries will error out as no SELECT permission for user on child
+-- relations
+explain (costs off) select * from child1;
+ERROR: permission denied for table child1
+explain (costs off) select * from child2;
+ERROR: permission denied for table child2
+reset session authorization;
+grant select on child1 to new_user;
+set session authorization new_user;
+-- After granting SELECT permission the below query will work
+explain (costs off) select * from child1;
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on child1
+ Optimizer: GPORCA
+(3 rows)
+
+reset session authorization;
+drop policy p1 on parent;
+drop table parent cascade;
+NOTICE: drop cascades to 2 other objects
+DETAIL: drop cascades to table child1
+drop cascades to table child2
+--------------------------------------------------------------------------------
+----- INSERT queries on relation having row level security enabled -------------
+------ ORCA will fallback to planner for INSERT with RLS anabled ---------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant insert on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=3);
+set session authorization new_user;
+explain (costs off) insert into foo_rls values (1,1,1);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
+ QUERY PLAN
+-----------------------------------
+ Insert on foo_rls
+ -> Result
+ Optimizer: Postgres-based planner
+(3 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+--------------------------------------------------------------------------------
+--------- INSERT queries on partitioned relation having RLS enabled ------------
+--------- ORCA will fallback to planner for INSERT with RLS anabled ------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant insert on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=500);
+set session authorization new_user;
+explain (costs off) insert into foo_part_rls values (-10,-10,-10);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
+ QUERY PLAN
+-----------------------------------
+ Insert on foo_part_rls
+ -> Result
+ Optimizer: Postgres-based planner
+(3 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+--------------------------------------------------------------------------------
+----- UPDATE queries on relation having row level security enabled -------------
+------ ORCA will fallback to planner for UPDATE with RLS anabled ---------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant select,update on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=3);
+set session authorization new_user;
+explain (costs off) update foo_rls set a=-10 where c=4;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
+ QUERY PLAN
+---------------------------------------------------------------
+ Update on foo_rls
+ -> Explicit Redistribute Motion 3:3 (slice1; segments: 3)
+ -> Split
+ -> Seq Scan on foo_rls
+ Filter: ((c >= 3) AND (c = 4))
+ Optimizer: Postgres-based planner
+(6 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+--------------------------------------------------------------------------------
+--------- UPDATE queries on partitioned relation having RLS enabled ------------
+--------- ORCA will fallback to planner for UPDATE with RLS anabled ------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant select,update on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=500);
+set session authorization new_user;
+explain (costs off) update foo_part_rls set a=10 where foo_part_rls.c = 800;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
+ QUERY PLAN
+---------------------------------------------------------------
+ Update on foo_part_rls
+ Update on foo_part_rls_1_prt_1
+ Update on foo_part_rls_1_prt_2
+ Update on foo_part_rls_1_prt_3
+ Update on foo_part_rls_1_prt_4
+ Update on foo_part_rls_1_prt_5
+ -> Explicit Redistribute Motion 3:3 (slice1; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_1
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice2; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_2
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice3; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_3
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice4; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_4
+ Filter: ((c >= 500) AND (c = 800))
+ -> Explicit Redistribute Motion 3:3 (slice5; segments: 3)
+ -> Split
+ -> Seq Scan on foo_part_rls_1_prt_5
+ Filter: ((c >= 500) AND (c = 800))
+ Optimizer: Postgres-based planner
+(27 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+--------------------------------------------------------------------------------
+----- DELETE queries on relation having row level security enabled -------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant select,delete on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=300);
+set session authorization new_user;
+explain (costs off) delete from foo_rls where foo_rls.b=30;
+ QUERY PLAN
+-------------------------------------------
+ Delete on foo_rls
+ -> Seq Scan on foo_rls
+ Filter: ((c >= 300) AND (b = 30))
+ Optimizer: GPORCA
+(4 rows)
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+--------------------------------------------------------------------------------
+----- DELETE queries on on partitioned relation having RLS enabled -------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant select,delete on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=300);
+set session authorization new_user;
+explain (costs off) delete from foo_part_rls where foo_part_rls.b=30;
+ QUERY PLAN
+----------------------------------------------------
+ Delete on foo_part_rls
+ -> Dynamic Seq Scan on foo_part_rls
+ Number of partitions to scan: 1 (out of 5)
+ Filter: ((c >= 300) AND (b = 30))
+ Optimizer: GPORCA
+(5 rows)
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+drop user new_user;
+reset optimizer_trace_fallback;
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 15ee758b15..3c5b7436d8 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -5,6 +5,7 @@
-- Suppress NOTICE messages when users/groups don't exist
SET client_min_messages TO 'warning';
SET gp_enable_relsize_collection to on;
+set optimizer_trace_fallback to on;
DROP USER IF EXISTS regress_rls_alice;
DROP USER IF EXISTS regress_rls_bob;
DROP USER IF EXISTS regress_rls_carol;
@@ -4252,3 +4253,4 @@ CREATE POLICY p1 ON rls_tbl_force USING (c1 = 5) WITH CHECK (c1 < 5);
CREATE POLICY p2 ON rls_tbl_force FOR SELECT USING (c1 = 8);
CREATE POLICY p3 ON rls_tbl_force FOR UPDATE USING (c1 = 8) WITH CHECK (c1 >= 5);
CREATE POLICY p4 ON rls_tbl_force FOR DELETE USING (c1 = 8);
+reset optimizer_trace_fallback;
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity_optimizer.out
similarity index 69%
copy from src/test/regress/expected/rowsecurity.out
copy to src/test/regress/expected/rowsecurity_optimizer.out
index 15ee758b15..12c06c0431 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity_optimizer.out
@@ -4,7 +4,7 @@
-- Clean up in case a prior regression run failed
-- Suppress NOTICE messages when users/groups don't exist
SET client_min_messages TO 'warning';
-SET gp_enable_relsize_collection to on;
+set optimizer_trace_fallback to on;
DROP USER IF EXISTS regress_rls_alice;
DROP USER IF EXISTS regress_rls_bob;
DROP USER IF EXISTS regress_rls_carol;
@@ -46,6 +46,8 @@ INSERT INTO uaccount VALUES
('regress_rls_bob', 1),
('regress_rls_carol', 2),
('regress_rls_dave', 3);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
ANALYZE uaccount;
CREATE TABLE category (
cid int primary key,
@@ -65,6 +67,7 @@ CREATE TABLE document (
dauthor name,
dtitle text
);
+WARNING: referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced
GRANT ALL ON document TO public;
INSERT INTO document VALUES
( 1, 11, 1, 'regress_rls_bob', 'my first novel'),
@@ -77,6 +80,8 @@ INSERT INTO document VALUES
( 8, 44, 1, 'regress_rls_carol', 'great manga'),
( 9, 22, 1, 'regress_rls_dave', 'awesome science fiction'),
(10, 33, 2, 'regress_rls_dave', 'awesome technology book');
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
ANALYZE document;
ALTER TABLE document ENABLE ROW LEVEL SECURITY;
-- user's security level must be higher than or equal to document's
@@ -99,6 +104,8 @@ CREATE POLICY p2r ON document AS RESTRICTIVE TO regress_rls_dave
CREATE POLICY p1r ON document AS RESTRICTIVE TO regress_rls_dave
USING (cid <> 44);
\dp
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------------------+----------+-------+---------------------------------------------+-------------------+--------------------------------------------
@@ -119,6 +126,32 @@ CREATE POLICY p1r ON document AS RESTRICTIVE TO regress_rls_dave
(3 rows)
\d document
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
Table "regress_rls_schema.document"
Column | Type | Collation | Nullable | Default
---------+---------+-----------+----------+---------
@@ -142,8 +175,11 @@ Policies:
POLICY "p2r" AS RESTRICTIVE
TO regress_rls_dave
USING (((cid <> 44) AND (cid < 50)))
+Distributed by: (did)
SELECT * FROM pg_policies WHERE schemaname = 'regress_rls_schema' AND tablename = 'document' ORDER BY policyname;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
schemaname | tablename | policyname | permissive | roles | cmd | qual | with_check
--------------------+-----------+------------+-------------+--------------------+-----+--------------------------------------------+------------
regress_rls_schema | document | p1 | PERMISSIVE | {public} | ALL | (dlevel <= ( SELECT uaccount.seclv +|
@@ -157,11 +193,13 @@ SELECT * FROM pg_policies WHERE schemaname = 'regress_rls_schema' AND tablename
SET SESSION AUTHORIZATION regress_rls_bob;
SET row_security TO ON;
SELECT * FROM document WHERE f_leak(dtitle) ORDER BY did;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my first novel
-NOTICE: f_leak => my first manga
NOTICE: f_leak => great science fiction
-NOTICE: f_leak => great manga
+NOTICE: f_leak => my first manga
NOTICE: f_leak => awesome science fiction
+NOTICE: f_leak => great manga
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-------------------------
1 | 11 | 1 | regress_rls_bob | my first novel
@@ -172,11 +210,13 @@ NOTICE: f_leak => awesome science fiction
(5 rows)
SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my first manga
+NOTICE: f_leak => my first novel
NOTICE: f_leak => great science fiction
-NOTICE: f_leak => great manga
NOTICE: f_leak => awesome science fiction
+NOTICE: f_leak => great manga
cid | did | dlevel | dauthor | dtitle | cname
-----+-----+--------+-------------------+-------------------------+-----------------
11 | 1 | 1 | regress_rls_bob | my first novel | novel
@@ -189,6 +229,8 @@ NOTICE: f_leak => awesome science fiction
-- try a sampled version
SELECT * FROM document TABLESAMPLE BERNOULLI(50) REPEATABLE(0)
WHERE f_leak(dtitle) ORDER BY did;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => great manga
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-------------
@@ -198,16 +240,18 @@ NOTICE: f_leak => great manga
-- viewpoint from regress_rls_carol
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
+NOTICE: f_leak => my second manga
NOTICE: f_leak => my second novel
NOTICE: f_leak => my science fiction
-NOTICE: f_leak => my first manga
-NOTICE: f_leak => my second manga
NOTICE: f_leak => great science fiction
-NOTICE: f_leak => great technology book
-NOTICE: f_leak => great manga
NOTICE: f_leak => awesome science fiction
NOTICE: f_leak => awesome technology book
+NOTICE: f_leak => my first manga
+NOTICE: f_leak => great technology book
+NOTICE: f_leak => my first novel
+NOTICE: f_leak => great manga
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-------------------------
1 | 11 | 1 | regress_rls_bob | my first novel
@@ -223,16 +267,18 @@ NOTICE: f_leak => awesome technology book
(10 rows)
SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my second novel
+NOTICE: f_leak => my first novel
+NOTICE: f_leak => my second manga
NOTICE: f_leak => my science fiction
NOTICE: f_leak => my first manga
-NOTICE: f_leak => my second manga
-NOTICE: f_leak => great science fiction
NOTICE: f_leak => great technology book
-NOTICE: f_leak => great manga
+NOTICE: f_leak => great science fiction
NOTICE: f_leak => awesome science fiction
NOTICE: f_leak => awesome technology book
+NOTICE: f_leak => great manga
cid | did | dlevel | dauthor | dtitle | cname
-----+-----+--------+-------------------+-------------------------+-----------------
11 | 1 | 1 | regress_rls_bob | my first novel | novel
@@ -250,6 +296,8 @@ NOTICE: f_leak => awesome technology book
-- try a sampled version
SELECT * FROM document TABLESAMPLE BERNOULLI(50) REPEATABLE(0)
WHERE f_leak(dtitle) ORDER BY did;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => great technology book
NOTICE: f_leak => great manga
NOTICE: f_leak => awesome technology book
@@ -261,8 +309,10 @@ NOTICE: f_leak => awesome technology book
(3 rows)
EXPLAIN (COSTS OFF) SELECT * FROM document WHERE f_leak(dtitle);
- QUERY PLAN
------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
+ QUERY PLAN
+--------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
InitPlan 1 (returns $0) (slice2)
-> Gather Motion 1:1 (slice3; segments: 1)
@@ -274,6 +324,8 @@ EXPLAIN (COSTS OFF) SELECT * FROM document WHERE f_leak(dtitle);
(8 rows)
EXPLAIN (COSTS OFF) SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
-----------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -294,13 +346,15 @@ EXPLAIN (COSTS OFF) SELECT * FROM document NATURAL JOIN category WHERE f_leak(dt
-- viewpoint from regress_rls_dave
SET SESSION AUTHORIZATION regress_rls_dave;
SELECT * FROM document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my second novel
-NOTICE: f_leak => my science fiction
+NOTICE: f_leak => my first novel
NOTICE: f_leak => great science fiction
-NOTICE: f_leak => great technology book
NOTICE: f_leak => awesome science fiction
NOTICE: f_leak => awesome technology book
+NOTICE: f_leak => my science fiction
+NOTICE: f_leak => great technology book
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-------------------------
1 | 11 | 1 | regress_rls_bob | my first novel
@@ -313,12 +367,14 @@ NOTICE: f_leak => awesome technology book
(7 rows)
SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle) ORDER BY did;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my first novel
NOTICE: f_leak => my second novel
-NOTICE: f_leak => my science fiction
NOTICE: f_leak => great science fiction
-NOTICE: f_leak => great technology book
NOTICE: f_leak => awesome science fiction
+NOTICE: f_leak => my science fiction
+NOTICE: f_leak => great technology book
NOTICE: f_leak => awesome technology book
cid | did | dlevel | dauthor | dtitle | cname
-----+-----+--------+-------------------+-------------------------+-----------------
@@ -332,6 +388,8 @@ NOTICE: f_leak => awesome technology book
(7 rows)
EXPLAIN (COSTS OFF) SELECT * FROM document WHERE f_leak(dtitle);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
----------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -345,6 +403,8 @@ EXPLAIN (COSTS OFF) SELECT * FROM document WHERE f_leak(dtitle);
(8 rows)
EXPLAIN (COSTS OFF) SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -366,9 +426,13 @@ EXPLAIN (COSTS OFF) SELECT * FROM document NATURAL JOIN category WHERE f_leak(dt
-- 44 would technically fail for both p2r and p1r, but we should get an error
-- back from p1r for this because it sorts first
INSERT INTO document VALUES (100, 44, 1, 'regress_rls_dave', 'testing sorting of policies'); -- fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy "p1r" for table "document"
-- Just to see a p2r error
INSERT INTO document VALUES (100, 55, 1, 'regress_rls_dave', 'testing sorting of policies'); -- fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy "p2r" for table "document"
-- only owner can change policies
ALTER POLICY p1 ON document USING (true); --fail
@@ -380,11 +444,13 @@ ALTER POLICY p1 ON document USING (dauthor = current_user);
-- viewpoint from regress_rls_bob again
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => my second novel
+NOTICE: f_leak => my first novel
+NOTICE: f_leak => my second manga
NOTICE: f_leak => my science fiction
NOTICE: f_leak => my first manga
-NOTICE: f_leak => my second manga
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-----------------+--------------------
1 | 11 | 1 | regress_rls_bob | my first novel
@@ -395,8 +461,10 @@ NOTICE: f_leak => my second manga
(5 rows)
SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle) ORDER by did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => my second novel
+NOTICE: f_leak => my first novel
NOTICE: f_leak => my science fiction
NOTICE: f_leak => my first manga
NOTICE: f_leak => my second manga
@@ -412,8 +480,10 @@ NOTICE: f_leak => my second manga
-- viewpoint from rls_regres_carol again
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => great science fiction
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => great technology book
+NOTICE: f_leak => great science fiction
NOTICE: f_leak => great manga
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-----------------------
@@ -423,9 +493,11 @@ NOTICE: f_leak => great manga
(3 rows)
SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle) ORDER by did;
-NOTICE: f_leak => great science fiction
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => great technology book
NOTICE: f_leak => great manga
+NOTICE: f_leak => great science fiction
cid | did | dlevel | dauthor | dtitle | cname
-----+-----+--------+-------------------+-----------------------+-----------------
22 | 6 | 1 | regress_rls_carol | great science fiction | science fiction
@@ -434,8 +506,10 @@ NOTICE: f_leak => great manga
(3 rows)
EXPLAIN (COSTS OFF) SELECT * FROM document WHERE f_leak(dtitle);
- QUERY PLAN
----------------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+ QUERY PLAN
+----------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on document
Filter: ((dauthor = 'regress_rls_carol'::name) AND f_leak(dtitle))
@@ -443,8 +517,10 @@ EXPLAIN (COSTS OFF) SELECT * FROM document WHERE f_leak(dtitle);
(4 rows)
EXPLAIN (COSTS OFF) SELECT * FROM document NATURAL JOIN category WHERE f_leak(dtitle);
- QUERY PLAN
----------------------------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+ QUERY PLAN
+----------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Hash Join
Hash Cond: (category.cid = document.cid)
@@ -466,6 +542,8 @@ ALTER TABLE category ENABLE ROW LEVEL SECURITY;
-- cannot delete PK referenced by invisible FK
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM document d FULL OUTER JOIN category c on d.cid = c.cid ORDER BY d.did, c.cid;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
did | cid | dlevel | dauthor | dtitle | cid | cname
-----+-----+--------+-----------------+--------------------+-----+------------
1 | 11 | 1 | regress_rls_bob | my first novel | 11 | novel
@@ -485,6 +563,8 @@ DETAIL: Key is still referenced from table "document".
-- can insert FK referencing invisible PK
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM document d FULL OUTER JOIN category c on d.cid = c.cid ORDER BY d.did, c.cid;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
did | cid | dlevel | dauthor | dtitle | cid | cname
-----+-----+--------+-------------------+-----------------------+-----+-----------------
6 | 22 | 1 | regress_rls_carol | great science fiction | 22 | science fiction
@@ -493,21 +573,31 @@ SELECT * FROM document d FULL OUTER JOIN category c on d.cid = c.cid ORDER BY d.
(3 rows)
INSERT INTO document VALUES (11, 33, 1, current_user, 'hoge');
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
-- UNIQUE or PRIMARY KEY constraint violation DOES reveal presence of row
SET SESSION AUTHORIZATION regress_rls_bob;
INSERT INTO document VALUES (8, 44, 1, 'regress_rls_bob', 'my third manga'); -- Must fail with unique violation, revealing presence of did we can't see
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: duplicate key value violates unique constraint "document_pkey"
SELECT * FROM document WHERE did = 8; -- and confirm we can't see it
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+---------+--------
(0 rows)
-- RLS policies are checked before constraints
INSERT INTO document VALUES (8, 44, 1, 'regress_rls_carol', 'my third manga'); -- Should fail with RLS check violation, not duplicate key violation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "document"
-- GPDB: UPDATE on distributed key column not allowed on relation with update triggers
-- start_ignore
UPDATE document SET did = 8, dauthor = 'regress_rls_carol' WHERE did = 5; -- Should fail with RLS check violation, not duplicate key violation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "document"
-- end_ignore
-- database superuser does bypass RLS policy when enabled
@@ -661,6 +751,7 @@ GRANT ALL ON t1 TO public;
COPY t1 FROM stdin WITH ;
ANALYZE t1;
CREATE TABLE t2 (c float) INHERITS (t1);
+NOTICE: table has parent, setting distribution columns to match parent table
GRANT ALL ON t2 TO public;
COPY t2 FROM stdin;
ANALYZE t2;
@@ -675,6 +766,8 @@ ALTER TABLE t1 ENABLE ROW LEVEL SECURITY;
ALTER TABLE t2 ENABLE ROW LEVEL SECURITY;
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b
-----+---+-----
102 | 2 | bbb
@@ -685,20 +778,24 @@ SELECT * FROM t1;
(5 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: ((a % 2) = 0)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: ((a % 2) = 0)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: ((a % 2) = 0)
Optimizer: Postgres query optimizer
(9 rows)
SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
NOTICE: f_leak => bbb
NOTICE: f_leak => dad
NOTICE: f_leak => bcd
@@ -714,21 +811,25 @@ NOTICE: f_leak => yyy
(5 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
-----------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: (((a % 2) = 0) AND f_leak(b))
Optimizer: Postgres query optimizer
(9 rows)
-- reference to system column
SELECT tableoid::regclass, * FROM t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
tableoid | id | a | b
----------+-----+---+-----
t1 | 102 | 2 | bbb
@@ -739,20 +840,25 @@ SELECT tableoid::regclass, * FROM t1;
(5 rows)
EXPLAIN (COSTS OFF) SELECT *, t1 FROM t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: ((a % 2) = 0)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: ((a % 2) = 0)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: ((a % 2) = 0)
+ Optimizer: Postgres-based planner
(9 rows)
-- reference to whole-row reference
SELECT *, t1 FROM t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b | t1
-----+---+-----+-------------
102 | 2 | bbb | (102,2,bbb)
@@ -763,21 +869,25 @@ SELECT *, t1 FROM t1;
(5 rows)
EXPLAIN (COSTS OFF) SELECT *, t1 FROM t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: ((a % 2) = 0)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: ((a % 2) = 0)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: ((a % 2) = 0)
Optimizer: Postgres query optimizer
(9 rows)
-- for share/update lock
SELECT * FROM t1 FOR SHARE;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b
-----+---+-----
102 | 2 | bbb
@@ -788,20 +898,24 @@ SELECT * FROM t1 FOR SHARE;
(5 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1 FOR SHARE;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: ((a % 2) = 0)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: ((a % 2) = 0)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: ((a % 2) = 0)
Optimizer: Postgres query optimizer
(9 rows)
SELECT * FROM t1 WHERE f_leak(b) FOR SHARE;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
NOTICE: f_leak => bbb
NOTICE: f_leak => dad
NOTICE: f_leak => bcd
@@ -817,15 +931,17 @@ NOTICE: f_leak => yyy
(5 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b) FOR SHARE;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
-----------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: (((a % 2) = 0) AND f_leak(b))
Optimizer: Postgres query optimizer
(9 rows)
@@ -849,24 +965,26 @@ EXPLAIN (COSTS OFF) SELECT a, b, tableoid::regclass FROM t2 UNION ALL SELECT a,
-> Seq Scan on t2
Filter: ((a % 2) = 1)
-> Seq Scan on t3
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(6 rows)
-- superuser is allowed to bypass RLS checks
RESET SESSION AUTHORIZATION;
SET row_security TO OFF;
SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
NOTICE: f_leak => aba
NOTICE: f_leak => bbb
NOTICE: f_leak => ccc
NOTICE: f_leak => dad
NOTICE: f_leak => abc
NOTICE: f_leak => bcd
-NOTICE: f_leak => cde
NOTICE: f_leak => def
-NOTICE: f_leak => xxx
+NOTICE: f_leak => cde
NOTICE: f_leak => yyy
NOTICE: f_leak => zzz
+NOTICE: f_leak => xxx
id | a | b
-----+---+-----
101 | 1 | aba
@@ -883,15 +1001,17 @@ NOTICE: f_leak => zzz
(11 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: f_leak(b)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: f_leak(b)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: f_leak(b)
Optimizer: Postgres query optimizer
(9 rows)
@@ -900,17 +1020,19 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
SET SESSION AUTHORIZATION regress_rls_exempt_user;
SET row_security TO OFF;
SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
NOTICE: f_leak => aba
NOTICE: f_leak => bbb
NOTICE: f_leak => ccc
NOTICE: f_leak => dad
NOTICE: f_leak => abc
+NOTICE: f_leak => def
NOTICE: f_leak => bcd
NOTICE: f_leak => cde
-NOTICE: f_leak => def
-NOTICE: f_leak => xxx
NOTICE: f_leak => yyy
NOTICE: f_leak => zzz
+NOTICE: f_leak => xxx
id | a | b
-----+---+-----
101 | 1 | aba
@@ -927,15 +1049,17 @@ NOTICE: f_leak => zzz
(11 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: f_leak(b)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: f_leak(b)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: f_leak(b)
Optimizer: Postgres query optimizer
(9 rows)
@@ -951,11 +1075,16 @@ CREATE TABLE part_document (
dauthor name,
dtitle text
) PARTITION BY RANGE (cid);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'did' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
GRANT ALL ON part_document TO public;
-- Create partitions for document categories
CREATE TABLE part_document_fiction PARTITION OF part_document FOR VALUES FROM (11) to (12);
+NOTICE: table has parent, setting distribution columns to match parent table
CREATE TABLE part_document_satire PARTITION OF part_document FOR VALUES FROM (55) to (56);
+NOTICE: table has parent, setting distribution columns to match parent table
CREATE TABLE part_document_nonfiction PARTITION OF part_document FOR VALUES FROM (99) to (100);
+NOTICE: table has parent, setting distribution columns to match parent table
GRANT ALL ON part_document_fiction TO public;
GRANT ALL ON part_document_satire TO public;
GRANT ALL ON part_document_nonfiction TO public;
@@ -970,6 +1099,8 @@ INSERT INTO part_document VALUES
( 8, 55, 2, 'regress_rls_carol', 'great satire'),
( 9, 11, 1, 'regress_rls_dave', 'awesome science fiction'),
(10, 99, 2, 'regress_rls_dave', 'awesome technology book');
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
ALTER TABLE part_document ENABLE ROW LEVEL SECURITY;
-- Create policy on parent
-- user's security level must be higher than or equal to document's
@@ -979,6 +1110,30 @@ CREATE POLICY pp1 ON part_document AS PERMISSIVE
CREATE POLICY pp1r ON part_document AS RESTRICTIVE TO regress_rls_dave
USING (cid < 55);
\d+ part_document
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
Partitioned table "regress_rls_schema.part_document"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
---------+---------+-----------+----------+---------+----------+--------------+-------------
@@ -999,8 +1154,11 @@ Policies:
Partitions: part_document_fiction FOR VALUES FROM (11) TO (12),
part_document_nonfiction FOR VALUES FROM (99) TO (100),
part_document_satire FOR VALUES FROM (55) TO (56)
+Distributed by: (did)
SELECT * FROM pg_policies WHERE schemaname = 'regress_rls_schema' AND tablename like '%part_document%' ORDER BY policyname;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
schemaname | tablename | policyname | permissive | roles | cmd | qual | with_check
--------------------+---------------+------------+-------------+--------------------+-----+--------------------------------------------+------------
regress_rls_schema | part_document | pp1 | PERMISSIVE | {public} | ALL | (dlevel <= ( SELECT uaccount.seclv +|
@@ -1013,9 +1171,11 @@ SELECT * FROM pg_policies WHERE schemaname = 'regress_rls_schema' AND tablename
SET SESSION AUTHORIZATION regress_rls_bob;
SET row_security TO ON;
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => great science fiction
NOTICE: f_leak => awesome science fiction
+NOTICE: f_leak => my first novel
NOTICE: f_leak => my first satire
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-------------------------
@@ -1026,19 +1186,21 @@ NOTICE: f_leak => my first satire
(4 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
- QUERY PLAN
------------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
+ QUERY PLAN
+------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
InitPlan 1 (returns $0) (slice2)
-> Gather Motion 1:1 (slice3; segments: 1)
-> Seq Scan on uaccount
Filter: (pguser = 'regress_rls_bob'::name)
-> Append
- -> Seq Scan on part_document_fiction part_document_1
+ -> Seq Scan on part_document_fiction
Filter: ((dlevel <= $0) AND f_leak(dtitle))
- -> Seq Scan on part_document_satire part_document_2
+ -> Seq Scan on part_document_satire
Filter: ((dlevel <= $0) AND f_leak(dtitle))
- -> Seq Scan on part_document_nonfiction part_document_3
+ -> Seq Scan on part_document_nonfiction
Filter: ((dlevel <= $0) AND f_leak(dtitle))
Optimizer: Postgres query optimizer
(13 rows)
@@ -1046,15 +1208,17 @@ EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
-- viewpoint from regress_rls_carol
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my second novel
+NOTICE: f_leak => my first novel
NOTICE: f_leak => great science fiction
-NOTICE: f_leak => awesome science fiction
NOTICE: f_leak => my first satire
+NOTICE: f_leak => awesome science fiction
NOTICE: f_leak => great satire
NOTICE: f_leak => my science textbook
-NOTICE: f_leak => my history book
NOTICE: f_leak => great technology book
+NOTICE: f_leak => my history book
NOTICE: f_leak => awesome technology book
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-------------------------
@@ -1071,19 +1235,21 @@ NOTICE: f_leak => awesome technology book
(10 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
- QUERY PLAN
------------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
+ QUERY PLAN
+--------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
InitPlan 1 (returns $0) (slice2)
-> Gather Motion 1:1 (slice3; segments: 1)
-> Seq Scan on uaccount
Filter: (pguser = 'regress_rls_carol'::name)
-> Append
- -> Seq Scan on part_document_fiction part_document_1
+ -> Seq Scan on part_document_fiction
Filter: ((dlevel <= $0) AND f_leak(dtitle))
- -> Seq Scan on part_document_satire part_document_2
+ -> Seq Scan on part_document_satire
Filter: ((dlevel <= $0) AND f_leak(dtitle))
- -> Seq Scan on part_document_nonfiction part_document_3
+ -> Seq Scan on part_document_nonfiction
Filter: ((dlevel <= $0) AND f_leak(dtitle))
Optimizer: Postgres query optimizer
(13 rows)
@@ -1091,8 +1257,10 @@ EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
-- viewpoint from regress_rls_dave
SET SESSION AUTHORIZATION regress_rls_dave;
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my second novel
+NOTICE: f_leak => my first novel
NOTICE: f_leak => great science fiction
NOTICE: f_leak => awesome science fiction
did | cid | dlevel | dauthor | dtitle
@@ -1104,6 +1272,8 @@ NOTICE: f_leak => awesome science fiction
(4 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
--------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -1111,25 +1281,33 @@ EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
-> Gather Motion 1:1 (slice3; segments: 1)
-> Seq Scan on uaccount
Filter: (pguser = 'regress_rls_dave'::name)
- -> Seq Scan on part_document_fiction part_document
+ -> Seq Scan on part_document_fiction
Filter: ((cid < 55) AND (dlevel <= $0) AND f_leak(dtitle))
Optimizer: Postgres query optimizer
(8 rows)
-- pp1 ERROR
INSERT INTO part_document VALUES (100, 11, 5, 'regress_rls_dave', 'testing pp1'); -- fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "part_document"
-- pp1r ERROR
INSERT INTO part_document VALUES (100, 99, 1, 'regress_rls_dave', 'testing pp1r'); -- fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy "pp1r" for table "part_document"
-- Show that RLS policy does not apply for direct inserts to children
-- This should fail with RLS POLICY pp1r violation.
INSERT INTO part_document VALUES (100, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); -- fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy "pp1r" for table "part_document"
-- But this should succeed.
INSERT INTO part_document_satire VALUES (100, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); -- success
-- We still cannot see the row using the parent
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my first novel
NOTICE: f_leak => my second novel
NOTICE: f_leak => great science fiction
@@ -1162,6 +1340,8 @@ CREATE POLICY pp3 ON part_document_satire AS RESTRICTIVE
-- This should fail with RLS violation now.
SET SESSION AUTHORIZATION regress_rls_dave;
INSERT INTO part_document_satire VALUES (101, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); -- fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "part_document_satire"
-- And now we cannot see directly into the partition either, due to RLS
SELECT * FROM part_document_satire WHERE f_leak(dtitle) ORDER BY did;
@@ -1172,8 +1352,10 @@ SELECT * FROM part_document_satire WHERE f_leak(dtitle) ORDER BY did;
-- The parent looks same as before
-- viewpoint from regress_rls_dave
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my second novel
+NOTICE: f_leak => my first novel
NOTICE: f_leak => great science fiction
NOTICE: f_leak => awesome science fiction
did | cid | dlevel | dauthor | dtitle
@@ -1185,6 +1367,8 @@ NOTICE: f_leak => awesome science fiction
(4 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
--------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -1192,7 +1376,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
-> Gather Motion 1:1 (slice3; segments: 1)
-> Seq Scan on uaccount
Filter: (pguser = 'regress_rls_dave'::name)
- -> Seq Scan on part_document_fiction part_document
+ -> Seq Scan on part_document_fiction
Filter: ((cid < 55) AND (dlevel <= $0) AND f_leak(dtitle))
Optimizer: Postgres query optimizer
(8 rows)
@@ -1200,6 +1384,8 @@ EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
-- viewpoint from regress_rls_carol
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => my first novel
NOTICE: f_leak => my second novel
NOTICE: f_leak => great science fiction
@@ -1209,8 +1395,8 @@ NOTICE: f_leak => great satire
NOTICE: f_leak => testing RLS with partitions
NOTICE: f_leak => my science textbook
NOTICE: f_leak => my history book
-NOTICE: f_leak => great technology book
NOTICE: f_leak => awesome technology book
+NOTICE: f_leak => great technology book
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-------------------+-----------------------------
1 | 11 | 1 | regress_rls_bob | my first novel
@@ -1227,19 +1413,21 @@ NOTICE: f_leak => awesome technology book
(11 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
- QUERY PLAN
------------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
+ QUERY PLAN
+--------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
InitPlan 1 (returns $0) (slice2)
-> Gather Motion 1:1 (slice3; segments: 1)
-> Seq Scan on uaccount
Filter: (pguser = 'regress_rls_carol'::name)
-> Append
- -> Seq Scan on part_document_fiction part_document_1
+ -> Seq Scan on part_document_fiction
Filter: ((dlevel <= $0) AND f_leak(dtitle))
- -> Seq Scan on part_document_satire part_document_2
+ -> Seq Scan on part_document_satire
Filter: ((dlevel <= $0) AND f_leak(dtitle))
- -> Seq Scan on part_document_nonfiction part_document_3
+ -> Seq Scan on part_document_nonfiction
Filter: ((dlevel <= $0) AND f_leak(dtitle))
Optimizer: Postgres query optimizer
(13 rows)
@@ -1254,11 +1442,13 @@ ALTER POLICY pp1 ON part_document USING (dauthor = current_user);
-- viewpoint from regress_rls_bob again
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
-NOTICE: f_leak => my first novel
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => my second novel
+NOTICE: f_leak => my first novel
NOTICE: f_leak => my first satire
-NOTICE: f_leak => my science textbook
NOTICE: f_leak => my history book
+NOTICE: f_leak => my science textbook
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-----------------+---------------------
1 | 11 | 1 | regress_rls_bob | my first novel
@@ -1271,6 +1461,8 @@ NOTICE: f_leak => my history book
-- viewpoint from rls_regres_carol again
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM part_document WHERE f_leak(dtitle) ORDER BY did;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => great science fiction
NOTICE: f_leak => great satire
NOTICE: f_leak => great technology book
@@ -1282,15 +1474,17 @@ NOTICE: f_leak => great technology book
(3 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
- QUERY PLAN
----------------------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+ QUERY PLAN
+----------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on part_document_fiction part_document_1
+ -> Seq Scan on part_document_fiction
Filter: ((dauthor = 'regress_rls_carol'::name) AND f_leak(dtitle))
- -> Seq Scan on part_document_satire part_document_2
+ -> Seq Scan on part_document_satire
Filter: ((dauthor = 'regress_rls_carol'::name) AND f_leak(dtitle))
- -> Seq Scan on part_document_nonfiction part_document_3
+ -> Seq Scan on part_document_nonfiction
Filter: ((dauthor = 'regress_rls_carol'::name) AND f_leak(dtitle))
Optimizer: Postgres query optimizer
(9 rows)
@@ -1390,12 +1584,18 @@ CREATE POLICY pp3 ON part_document AS RESTRICTIVE
USING ((SELECT dlevel <= seclv FROM uaccount WHERE pguser = current_user));
SET SESSION AUTHORIZATION regress_rls_carol;
INSERT INTO part_document VALUES (100, 11, 5, 'regress_rls_carol', 'testing pp3'); -- fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy "pp3" for table "part_document"
----- Dependencies -----
SET SESSION AUTHORIZATION regress_rls_alice;
SET row_security TO ON;
CREATE TABLE dependee (x integer, y integer);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'x' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE dependent (x integer, y integer);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'x' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY d1 ON dependent FOR ALL
TO PUBLIC
USING (x = (SELECT d.x FROM dependee d WHERE d.y = y));
@@ -1410,7 +1610,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM dependent; -- After drop, should be unqualifie
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on dependent
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(3 rows)
----- RECURSION ----
@@ -1419,6 +1619,8 @@ EXPLAIN (COSTS OFF) SELECT * FROM dependent; -- After drop, should be unqualifie
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE rec1 (x integer, y integer);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'x' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY r1 ON rec1 USING (x = (SELECT r.x FROM rec1 r WHERE y = r.y));
ALTER TABLE rec1 ENABLE ROW LEVEL SECURITY;
SET SESSION AUTHORIZATION regress_rls_bob;
@@ -1429,6 +1631,8 @@ ERROR: infinite recursion detected in policy for relation "rec1"
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE rec2 (a integer, b integer);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
ALTER POLICY r1 ON rec1 USING (x = (SELECT a FROM rec2 WHERE b = y));
CREATE POLICY r2 ON rec2 USING (a = (SELECT x FROM rec1 WHERE y = b));
ALTER TABLE rec2 ENABLE ROW LEVEL SECURITY;
@@ -1468,8 +1672,12 @@ ERROR: infinite recursion detected in policy for relation "rec1"
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE s1 (a int, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO s1 (SELECT x, md5(x::text) FROM generate_series(-10,10) x);
CREATE TABLE s2 (x int, y text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'x' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO s2 (SELECT x, md5(x::text) FROM generate_series(-6,6) x);
GRANT SELECT ON s1, s2 TO regress_rls_bob;
CREATE POLICY p1 ON s1 USING (a in (select x from s2 where y like '%2f%'));
@@ -1488,6 +1696,8 @@ DROP POLICY p3 on s1;
ALTER POLICY p2 ON s2 USING (x % 2 = 0);
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM s1 WHERE f_leak(b); -- OK
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => c81e728d9d4c2f636f067f89cc14862c
NOTICE: f_leak => a87ff679a2f3e71d9181a67b7542122c
a | b
@@ -1497,6 +1707,8 @@ NOTICE: f_leak => a87ff679a2f3e71d9181a67b7542122c
(2 rows)
EXPLAIN (COSTS OFF) SELECT * FROM only s1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
-----------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -1513,6 +1725,8 @@ SET SESSION AUTHORIZATION regress_rls_alice;
ALTER POLICY p1 ON s1 USING (a in (select x from v2)); -- using VIEW in RLS policy
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM s1 WHERE f_leak(b); -- OK
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
NOTICE: f_leak => 0267aaf632e87a63288a08331f22c7c3
NOTICE: f_leak => 1679091c5a880faf6fb5e6087eb1b2dc
a | b
@@ -1522,6 +1736,8 @@ NOTICE: f_leak => 1679091c5a880faf6fb5e6087eb1b2dc
(2 rows)
EXPLAIN (COSTS OFF) SELECT * FROM s1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
-----------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -1535,6 +1751,8 @@ EXPLAIN (COSTS OFF) SELECT * FROM s1 WHERE f_leak(b);
(8 rows)
SELECT (SELECT x FROM s1 LIMIT 1) xx, * FROM s2 WHERE y like '%28%';
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
xx | x | y
----+----+----------------------------------
-6 | -6 | 596a3d04481816330f07e4f97510c28f
@@ -1543,6 +1761,8 @@ SELECT (SELECT x FROM s1 LIMIT 1) xx, * FROM s2 WHERE y like '%28%';
(3 rows)
EXPLAIN (COSTS OFF) SELECT (SELECT x FROM s1 LIMIT 1) xx, * FROM s2 WHERE y like '%28%';
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -1571,6 +1791,8 @@ ERROR: infinite recursion detected in policy for relation "s1"
-- prepared statement with regress_rls_alice privilege
PREPARE p1(int) AS SELECT * FROM t1 WHERE a <= $1;
EXECUTE p1(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b
-----+---+-----
102 | 2 | bbb
@@ -1579,15 +1801,17 @@ EXECUTE p1(2);
(3 rows)
EXPLAIN (COSTS OFF) EXECUTE p1(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
----------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: ((a <= 2) AND ((a % 2) = 0))
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: ((a <= 2) AND ((a % 2) = 0))
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: ((a <= 2) AND ((a % 2) = 0))
Optimizer: Postgres query optimizer
(9 rows)
@@ -1596,17 +1820,19 @@ EXPLAIN (COSTS OFF) EXECUTE p1(2);
RESET SESSION AUTHORIZATION;
SET row_security TO OFF;
SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
NOTICE: f_leak => aba
NOTICE: f_leak => bbb
NOTICE: f_leak => ccc
NOTICE: f_leak => dad
NOTICE: f_leak => abc
+NOTICE: f_leak => def
NOTICE: f_leak => bcd
NOTICE: f_leak => cde
-NOTICE: f_leak => def
-NOTICE: f_leak => xxx
NOTICE: f_leak => yyy
NOTICE: f_leak => zzz
+NOTICE: f_leak => xxx
id | a | b
-----+---+-----
101 | 1 | aba
@@ -1623,21 +1849,25 @@ NOTICE: f_leak => zzz
(11 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: f_leak(b)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: f_leak(b)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: f_leak(b)
Optimizer: Postgres query optimizer
(9 rows)
-- plan cache should be invalidated
EXECUTE p1(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b
-----+---+-----
101 | 1 | aba
@@ -1649,21 +1879,25 @@ EXECUTE p1(2);
(6 rows)
EXPLAIN (COSTS OFF) EXECUTE p1(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: (a <= 2)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: (a <= 2)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: (a <= 2)
Optimizer: Postgres query optimizer
(9 rows)
PREPARE p2(int) AS SELECT * FROM t1 WHERE a = $1;
EXECUTE p2(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b
-----+---+-----
102 | 2 | bbb
@@ -1672,15 +1906,17 @@ EXECUTE p2(2);
(3 rows)
EXPLAIN (COSTS OFF) EXECUTE p2(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: (a = 2)
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: (a = 2)
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: (a = 2)
Optimizer: Postgres query optimizer
(9 rows)
@@ -1689,6 +1925,8 @@ EXPLAIN (COSTS OFF) EXECUTE p2(2);
SET SESSION AUTHORIZATION regress_rls_bob;
SET row_security TO ON;
EXECUTE p2(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b
-----+---+-----
102 | 2 | bbb
@@ -1697,15 +1935,17 @@ EXECUTE p2(2);
(3 rows)
EXPLAIN (COSTS OFF) EXECUTE p2(2);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
QUERY PLAN
---------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Append
- -> Seq Scan on t1 t1_1
+ -> Seq Scan on t1
Filter: ((a = 2) AND ((a % 2) = 0))
- -> Seq Scan on t2 t1_2
+ -> Seq Scan on t2
Filter: ((a = 2) AND ((a % 2) = 0))
- -> Seq Scan on t3 t1_3
+ -> Seq Scan on t3
Filter: ((a = 2) AND ((a % 2) = 0))
Optimizer: Postgres query optimizer
(9 rows)
@@ -1715,41 +1955,51 @@ EXPLAIN (COSTS OFF) EXECUTE p2(2);
--
SET SESSION AUTHORIZATION regress_rls_bob;
EXPLAIN (COSTS OFF) UPDATE t1 SET b = b || b WHERE f_leak(b);
- QUERY PLAN
------------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
+ QUERY PLAN
+-----------------------------------------------
Update on t1
- Update on t1 t1_1
- Update on t2 t1_2
- Update on t3 t1_3
- -> Result
- -> Append
- -> Seq Scan on t1 t1_1
- Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_2
- Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_3
- Filter: (((a % 2) = 0) AND f_leak(b))
-(12 rows)
+ Update on t1
+ Update on t2
+ Update on t3
+ -> Seq Scan on t1
+ Filter: (((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t2
+ Filter: (((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t3
+ Filter: (((a % 2) = 0) AND f_leak(b))
+ Optimizer: Postgres-based planner
+(11 rows)
UPDATE t1 SET b = b || b WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => bbb
NOTICE: f_leak => dad
NOTICE: f_leak => bcd
NOTICE: f_leak => def
NOTICE: f_leak => yyy
EXPLAIN (COSTS OFF) UPDATE only t1 SET b = b || '_updt' WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-----------------------------------------------
Update on t1
-> Seq Scan on t1
Filter: (((a % 2) = 0) AND f_leak(b))
-(3 rows)
+ Optimizer: Postgres-based planner
+(4 rows)
UPDATE only t1 SET b = b || '_updt' WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => bbbbbb
NOTICE: f_leak => daddad
-- returning clause with system column
UPDATE only t1 SET b = b WHERE f_leak(b) RETURNING tableoid::regclass, *, t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => bbbbbb_updt
NOTICE: f_leak => daddad_updt
tableoid | id | a | b | t1
@@ -1759,9 +2009,11 @@ NOTICE: f_leak => daddad_updt
(2 rows)
UPDATE t1 SET b = b WHERE f_leak(b) RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => bbbbbb_updt
-NOTICE: f_leak => daddad_updt
NOTICE: f_leak => bcdbcd
+NOTICE: f_leak => daddad_updt
NOTICE: f_leak => defdef
NOTICE: f_leak => yyyyyy
id | a | b
@@ -1774,10 +2026,12 @@ NOTICE: f_leak => yyyyyy
(5 rows)
UPDATE t1 SET b = b WHERE f_leak(b) RETURNING tableoid::regclass, *, t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => bbbbbb_updt
-NOTICE: f_leak => daddad_updt
-NOTICE: f_leak => bcdbcd
NOTICE: f_leak => defdef
+NOTICE: f_leak => bcdbcd
+NOTICE: f_leak => daddad_updt
NOTICE: f_leak => yyyyyy
tableoid | id | a | b | t1
----------+-----+---+-------------+---------------------
@@ -1791,6 +2045,8 @@ NOTICE: f_leak => yyyyyy
-- updates with from clause
EXPLAIN (COSTS OFF) UPDATE t2 SET b=t2.b FROM t3
WHERE t2.a = 3 and t3.a = 2 AND f_leak(t2.b) AND f_leak(t3.b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-----------------------------------------------------------------
Update on t2
@@ -1806,60 +2062,84 @@ WHERE t2.a = 3 and t3.a = 2 AND f_leak(t2.b) AND f_leak(t3.b);
UPDATE t2 SET b=t2.b FROM t3
WHERE t2.a = 3 and t3.a = 2 AND f_leak(t2.b) AND f_leak(t3.b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => cde
NOTICE: f_leak => yyyyyy
EXPLAIN (COSTS OFF) UPDATE t1 SET b=t1.b FROM t2
WHERE t1.a = 3 and t2.a = 3 AND f_leak(t1.b) AND f_leak(t2.b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-----------------------------------------------------------------------------
Update on t1
- Update on t1 t1_1
- Update on t2 t1_2
- Update on t3 t1_3
+ Update on t1
+ Update on t2 t2_1
+ Update on t3
+ -> Nested Loop
+ -> Seq Scan on t1
+ Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
+ -> Materialize
+ -> Broadcast Motion 3:3 (slice1; segments: 3)
+ -> Seq Scan on t2
+ Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
-> Nested Loop
- -> Broadcast Motion 3:3 (slice1; segments: 3)
- -> Seq Scan on t2
- Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
- -> Append
- -> Seq Scan on t1 t1_1
- Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_2
- Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_3
- Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t2 t2_1
+ Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
+ -> Materialize
+ -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Seq Scan on t2
+ Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
+ -> Nested Loop
+ -> Seq Scan on t3
+ Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
+ -> Materialize
+ -> Broadcast Motion 3:3 (slice3; segments: 3)
+ -> Seq Scan on t2
+ Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
Optimizer: Postgres query optimizer
-(16 rows)
+(26 rows)
UPDATE t1 SET b=t1.b FROM t2
WHERE t1.a = 3 and t2.a = 3 AND f_leak(t1.b) AND f_leak(t2.b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
+NOTICE: f_leak => cde
+NOTICE: f_leak => cde
NOTICE: f_leak => cde
EXPLAIN (COSTS OFF) UPDATE t2 SET b=t2.b FROM t1
WHERE t1.a = 3 and t2.a = 3 AND f_leak(t1.b) AND f_leak(t2.b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-----------------------------------------------------------------------------------
Update on t2
- -> Explicit Redistribute Motion 3:3 (slice1; segments: 3)
- -> Nested Loop
- -> Broadcast Motion 3:3 (slice2; segments: 3)
- -> Seq Scan on t2
- Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
- -> Append
- -> Seq Scan on t1 t1_1
- Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_2
- Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_3
- Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
+ -> Nested Loop
+ -> Seq Scan on t2
+ Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
+ -> Materialize
+ -> Broadcast Motion 3:3 (slice1; segments: 3)
+ -> Append
+ -> Seq Scan on t1
+ Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t2 t2_1
+ Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t3
+ Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
Optimizer: Postgres query optimizer
(14 rows)
UPDATE t2 SET b=t2.b FROM t1
WHERE t1.a = 3 and t2.a = 3 AND f_leak(t1.b) AND f_leak(t2.b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => cde
-- updates with from clause self join
EXPLAIN (COSTS OFF) UPDATE t2 t2_1 SET b = t2_2.b FROM t2 t2_2
WHERE t2_1.a = 3 AND t2_2.a = t2_1.a AND t2_2.b = t2_1.b
AND f_leak(t2_1.b) AND f_leak(t2_2.b) RETURNING *, t2_1, t2_2;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-----------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -1879,6 +2159,8 @@ AND f_leak(t2_1.b) AND f_leak(t2_2.b) RETURNING *, t2_1, t2_2;
UPDATE t2 t2_1 SET b = t2_2.b FROM t2 t2_2
WHERE t2_1.a = 3 AND t2_2.a = t2_1.a AND t2_2.b = t2_1.b
AND f_leak(t2_1.b) AND f_leak(t2_2.b) RETURNING *, t2_1, t2_2;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => cde
NOTICE: f_leak => cde
id | a | b | c | id | a | b | c | t2_1 | t2_2
@@ -1889,41 +2171,70 @@ NOTICE: f_leak => cde
EXPLAIN (COSTS OFF) UPDATE t1 t1_1 SET b = t1_2.b FROM t1 t1_2
WHERE t1_1.a = 4 AND t1_2.a = t1_1.a AND t1_2.b = t1_1.b
AND f_leak(t1_1.b) AND f_leak(t1_2.b) RETURNING *, t1_1, t1_2;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-----------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Update on t1 t1_1
- Update on t1 t1_1_1
- Update on t2 t1_1_2
- Update on t3 t1_1_3
+ Update on t1 t1_1
+ Update on t2 t1_1_1
+ Update on t3 t1_1_2
-> Explicit Redistribute Motion 3:3 (slice2; segments: 3)
-> Hash Join
- Hash Cond: (t1_1.b = t1_2.b)
- -> Broadcast Motion 3:3 (slice3; segments: 3)
- -> Append
- -> Seq Scan on t1 t1_1_1
- Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_1_2
- Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_1_3
- Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ Hash Cond: (t1_2.b = t1_1.b)
+ -> Append
+ -> Seq Scan on t1 t1_2
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t2 t1_2_1
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t3 t1_2_2
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
-> Hash
- -> Append
- -> Seq Scan on t1 t1_2_1
+ -> Broadcast Motion 3:3 (slice3; segments: 3)
+ -> Seq Scan on t1 t1_1
Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_2_2
+ -> Explicit Redistribute Motion 3:3 (slice4; segments: 3)
+ -> Hash Join
+ Hash Cond: (t1_2.b = t1_1_1.b)
+ -> Append
+ -> Seq Scan on t1 t1_2
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t2 t1_2_1
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t3 t1_2_2
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Hash
+ -> Broadcast Motion 3:3 (slice5; segments: 3)
+ -> Seq Scan on t2 t1_1_1
Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_2_3
+ -> Explicit Redistribute Motion 3:3 (slice6; segments: 3)
+ -> Hash Join
+ Hash Cond: (t1_2.b = t1_1_2.b)
+ -> Append
+ -> Seq Scan on t1 t1_2
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t2 t1_2_1
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t3 t1_2_2
+ Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
+ -> Hash
+ -> Broadcast Motion 3:3 (slice7; segments: 3)
+ -> Seq Scan on t3 t1_1_2
Filter: ((a = 4) AND ((a % 2) = 0) AND f_leak(b))
Optimizer: Postgres query optimizer
-(25 rows)
+(48 rows)
UPDATE t1 t1_1 SET b = t1_2.b FROM t1 t1_2
WHERE t1_1.a = 4 AND t1_2.a = t1_1.a AND t1_2.b = t1_1.b
AND f_leak(t1_1.b) AND f_leak(t1_2.b) RETURNING *, t1_1, t1_2;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => daddad_updt
NOTICE: f_leak => daddad_updt
NOTICE: f_leak => defdef
+NOTICE: f_leak => defdef
+NOTICE: f_leak => daddad_updt
NOTICE: f_leak => defdef
id | a | b | id | a | b | t1_1 | t1_2
-----+---+-------------+-----+---+-------------+---------------------+---------------------
@@ -1934,6 +2245,8 @@ NOTICE: f_leak => defdef
RESET SESSION AUTHORIZATION;
SET row_security TO OFF;
SELECT * FROM t1 ORDER BY a,b;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
id | a | b
-----+---+-------------
101 | 1 | aba
@@ -1952,6 +2265,8 @@ SELECT * FROM t1 ORDER BY a,b;
SET SESSION AUTHORIZATION regress_rls_bob;
SET row_security TO ON;
EXPLAIN (COSTS OFF) DELETE FROM only t1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: ONLY in the FROM clause
QUERY PLAN
-----------------------------------------------
Delete on t1
@@ -1961,22 +2276,26 @@ EXPLAIN (COSTS OFF) DELETE FROM only t1 WHERE f_leak(b);
(4 rows)
EXPLAIN (COSTS OFF) DELETE FROM t1 WHERE f_leak(b);
- QUERY PLAN
------------------------------------------------------
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Inherited tables
+ QUERY PLAN
+-----------------------------------------------
Delete on t1
- Delete on t1 t1_1
- Delete on t2 t1_2
- Delete on t3 t1_3
- -> Append
- -> Seq Scan on t1 t1_1
- Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t2 t1_2
- Filter: (((a % 2) = 0) AND f_leak(b))
- -> Seq Scan on t3 t1_3
- Filter: (((a % 2) = 0) AND f_leak(b))
+ Delete on t1
+ Delete on t2
+ Delete on t3
+ -> Seq Scan on t1
+ Filter: (((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t2
+ Filter: (((a % 2) = 0) AND f_leak(b))
+ -> Seq Scan on t3
+ Filter: (((a % 2) = 0) AND f_leak(b))
+ Optimizer: Postgres-based planner
(11 rows)
DELETE FROM only t1 WHERE f_leak(b) RETURNING tableoid::regclass, *, t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: RETURNING clause
NOTICE: f_leak => bbbbbb_updt
NOTICE: f_leak => daddad_updt
tableoid | id | a | b | t1
@@ -1986,6 +2305,8 @@ NOTICE: f_leak => daddad_updt
(2 rows)
DELETE FROM t1 WHERE f_leak(b) RETURNING tableoid::regclass, *, t1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: RETURNING clause
NOTICE: f_leak => bcdbcd
NOTICE: f_leak => defdef
NOTICE: f_leak => yyyyyy
@@ -2001,6 +2322,8 @@ NOTICE: f_leak => yyyyyy
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE b1 (a int, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO b1 (SELECT x, md5(x::text) FROM generate_series(-10,10) x);
CREATE POLICY p1 ON b1 USING (a % 2 = 0);
ALTER TABLE b1 ENABLE ROW LEVEL SECURITY;
@@ -2010,6 +2333,8 @@ CREATE VIEW bv1 WITH (security_barrier) AS SELECT * FROM b1 WHERE a > 0 WITH CHE
GRANT ALL ON bv1 TO regress_rls_carol;
SET SESSION AUTHORIZATION regress_rls_carol;
EXPLAIN (COSTS OFF) SELECT * FROM bv1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: views with security_barrier ON
QUERY PLAN
---------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
@@ -2021,11 +2346,13 @@ EXPLAIN (COSTS OFF) SELECT * FROM bv1 WHERE f_leak(b);
(6 rows)
SELECT * FROM bv1 WHERE f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: views with security_barrier ON
NOTICE: f_leak => c81e728d9d4c2f636f067f89cc14862c
-NOTICE: f_leak => a87ff679a2f3e71d9181a67b7542122c
NOTICE: f_leak => 1679091c5a880faf6fb5e6087eb1b2dc
-NOTICE: f_leak => c9f0f895fb98ab9159f51fd0297e236d
NOTICE: f_leak => d3d9446802a44259755d38e6d163e820
+NOTICE: f_leak => a87ff679a2f3e71d9181a67b7542122c
+NOTICE: f_leak => c9f0f895fb98ab9159f51fd0297e236d
a | b
----+----------------------------------
2 | c81e728d9d4c2f636f067f89cc14862c
@@ -2036,27 +2363,39 @@ NOTICE: f_leak => d3d9446802a44259755d38e6d163e820
(5 rows)
INSERT INTO bv1 VALUES (-1, 'xxx'); -- should fail view WCO
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "b1"
INSERT INTO bv1 VALUES (11, 'xxx'); -- should fail RLS check
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "b1"
INSERT INTO bv1 VALUES (12, 'xxx'); -- ok
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
EXPLAIN (COSTS OFF) UPDATE bv1 SET b = 'yyy' WHERE a = 4 AND f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-----------------------------------------------------------------------
Update on b1
-> Seq Scan on b1
Filter: ((a > 0) AND (a = 4) AND ((a % 2) = 0) AND f_leak(b))
-(3 rows)
+ Optimizer: Postgres-based planner
+(4 rows)
UPDATE bv1 SET b = 'yyy' WHERE a = 4 AND f_leak(b);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => a87ff679a2f3e71d9181a67b7542122c
EXPLAIN (COSTS OFF) DELETE FROM bv1 WHERE a = 6 AND f_leak(b);
- QUERY PLAN
------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------
Delete on b1
-> Seq Scan on b1
- Filter: ((a > 0) AND (a = 6) AND ((a % 2) = 0) AND f_leak(b))
-(3 rows)
+ Filter: (((a % 2) = 0) AND (a > 0) AND ((a = 6) AND f_leak(b)))
+ Optimizer: GPORCA
+(4 rows)
DELETE FROM bv1 WHERE a = 6 AND f_leak(b);
NOTICE: f_leak => 1679091c5a880faf6fb5e6087eb1b2dc
@@ -2110,6 +2449,8 @@ SELECT * FROM document WHERE did = 2;
-- alternative UPDATE path happens to be taken):
INSERT INTO document VALUES (2, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_carol', 'my first novel')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle, dauthor = EXCLUDED.dauthor;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "document"
-- Violates USING qual for UPDATE policy p3.
--
@@ -2117,13 +2458,19 @@ ERROR: new row violates row-level security policy for table "document"
-- updated is not a "novel"/cid 11 (row is not leaked, even though we have
-- SELECT privileges sufficient to see the row in this instance):
INSERT INTO document VALUES (33, 22, 1, 'regress_rls_bob', 'okay science fiction'); -- preparation for next statement
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
INSERT INTO document VALUES (33, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_bob', 'Some novel, replaces sci-fi') -- takes UPDATE path
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy (USING expression) for table "document"
-- Fine (we UPDATE, since INSERT WCOs and UPDATE security barrier quals + WCOs
-- not violated):
INSERT INTO document VALUES (2, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_bob', 'my first novel')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-----------------+----------------
2 | 11 | 2 | regress_rls_bob | my first novel
@@ -2132,6 +2479,8 @@ INSERT INTO document VALUES (2, (SELECT cid from category WHERE cname = 'novel')
-- Fine (we INSERT, so "cid = 33" ("technology") isn't evaluated):
INSERT INTO document VALUES (78, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_bob', 'some technology novel')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle, cid = 33 RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-----------------+-----------------------
78 | 11 | 1 | regress_rls_bob | some technology novel
@@ -2141,6 +2490,8 @@ INSERT INTO document VALUES (78, (SELECT cid from category WHERE cname = 'novel'
-- case in respect of *existing* tuple):
INSERT INTO document VALUES (78, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_bob', 'some technology novel')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle, cid = 33 RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-----------------+-----------------------
78 | 33 | 1 | regress_rls_bob | some technology novel
@@ -2150,12 +2501,16 @@ INSERT INTO document VALUES (78, (SELECT cid from category WHERE cname = 'novel'
-- passing quals:
INSERT INTO document VALUES (78, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_bob', 'some technology novel')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle, cid = 33 RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy (USING expression) for table "document"
-- Don't fail just because INSERT doesn't satisfy WITH CHECK option that
-- originated as a barrier/USING() qual from the UPDATE. Note that the UPDATE
-- path *isn't* taken, and so UPDATE-related policy does not apply:
INSERT INTO document VALUES (79, (SELECT cid from category WHERE cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
did | cid | dlevel | dauthor | dtitle
-----+-----+--------+-----------------+----------------------------------
79 | 33 | 1 | regress_rls_bob | technology book, can only insert
@@ -2167,6 +2522,8 @@ INSERT INTO document VALUES (79, (SELECT cid from category WHERE cname = 'techno
-- irrelevant, in fact.
INSERT INTO document VALUES (79, (SELECT cid from category WHERE cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy (USING expression) for table "document"
-- Test default USING qual enforced as WCO
SET SESSION AUTHORIZATION regress_rls_alice;
@@ -2189,6 +2546,8 @@ SET SESSION AUTHORIZATION regress_rls_bob;
-- UPDATE to make this fail:
INSERT INTO document VALUES (79, (SELECT cid from category WHERE cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "document"
-- UPDATE path is taken here. Existing tuple passes, since its cid
-- corresponds to "novel", but default USING qual is enforced against
@@ -2196,6 +2555,8 @@ ERROR: new row violates row-level security policy for table "document"
-- explicit WCO), and so this fails:
INSERT INTO document VALUES (2, (SELECT cid from category WHERE cname = 'technology'), 1, 'regress_rls_bob', 'my first novel')
ON CONFLICT (did) DO UPDATE SET cid = EXCLUDED.cid, dtitle = EXCLUDED.dtitle RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "document"
SET SESSION AUTHORIZATION regress_rls_alice;
DROP POLICY p3_with_default ON document;
@@ -2210,22 +2571,32 @@ SET SESSION AUTHORIZATION regress_rls_bob;
-- Fails, since ALL WCO is enforced in insert path:
INSERT INTO document VALUES (80, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_carol', 'my first novel')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle, cid = 33;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "document"
-- Fails, since ALL policy USING qual is enforced (existing, target tuple is in
-- violation, since it has the "manga" cid):
INSERT INTO document VALUES (4, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_bob', 'my first novel')
ON CONFLICT (did) DO UPDATE SET dtitle = EXCLUDED.dtitle;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy (USING expression) for table "document"
-- Fails, since ALL WCO are enforced:
INSERT INTO document VALUES (1, (SELECT cid from category WHERE cname = 'novel'), 1, 'regress_rls_bob', 'my first novel')
ON CONFLICT (did) DO UPDATE SET dauthor = 'regress_rls_carol';
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "document"
--
-- ROLE/GROUP
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE z1 (a int, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE z2 (a int, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
GRANT SELECT ON z1,z2 TO regress_rls_group1, regress_rls_group2,
regress_rls_bob, regress_rls_carol;
INSERT INTO z1 VALUES
@@ -2252,7 +2623,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM z1 WHERE f_leak(b);
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
PREPARE plancache_test AS SELECT * FROM z1 WHERE f_leak(b);
@@ -2262,23 +2633,26 @@ EXPLAIN (COSTS OFF) EXECUTE plancache_test;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
PREPARE plancache_test2 AS WITH q AS MATERIALIZED (SELECT * FROM z1 WHERE f_leak(b)) SELECT * FROM q,z2;
EXPLAIN (COSTS OFF) EXECUTE plancache_test2;
- QUERY PLAN
----------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3)
- -> Nested Loop
- -> Shared Scan (share slice:id 1:0)
+ QUERY PLAN
+------------------------------------------------------------
+ Sequence
+ -> Shared Scan (share slice:id 0:0)
+ -> Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
+ -> Nested Loop
+ Join Filter: true
+ -> Shared Scan (share slice:id 0:0)
-> Materialize
- -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Gather Motion 3:1 (slice2; segments: 3)
-> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ Optimizer: GPORCA
+(12 rows)
PREPARE plancache_test3 AS WITH q AS MATERIALIZED (SELECT * FROM z2) SELECT * FROM q,z1 WHERE f_leak(z1.b);
EXPLAIN (COSTS OFF) EXECUTE plancache_test3;
@@ -2286,14 +2660,13 @@ EXPLAIN (COSTS OFF) EXECUTE plancache_test3;
-----------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
+ Join Filter: true
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- -> Materialize
- -> Shared Scan (share slice:id 1:0)
- -> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ -> Seq Scan on z2
+ Optimizer: GPORCA
+(8 rows)
SET ROLE regress_rls_group1;
SELECT * FROM z1 WHERE f_leak(b);
@@ -2311,7 +2684,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM z1 WHERE f_leak(b);
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test;
@@ -2320,36 +2693,38 @@ EXPLAIN (COSTS OFF) EXECUTE plancache_test;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test2;
- QUERY PLAN
----------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3)
- -> Nested Loop
- -> Shared Scan (share slice:id 1:0)
+ QUERY PLAN
+------------------------------------------------------------
+ Sequence
+ -> Shared Scan (share slice:id 0:0)
+ -> Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
+ -> Nested Loop
+ Join Filter: true
+ -> Shared Scan (share slice:id 0:0)
-> Materialize
- -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Gather Motion 3:1 (slice2; segments: 3)
-> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ Optimizer: GPORCA
+(12 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test3;
QUERY PLAN
-----------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
+ Join Filter: true
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- -> Materialize
- -> Shared Scan (share slice:id 1:0)
- -> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ -> Seq Scan on z2
+ Optimizer: GPORCA
+(8 rows)
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM z1 WHERE f_leak(b);
@@ -2367,7 +2742,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM z1 WHERE f_leak(b);
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test;
@@ -2376,36 +2751,38 @@ EXPLAIN (COSTS OFF) EXECUTE plancache_test;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test2;
- QUERY PLAN
----------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3)
- -> Nested Loop
- -> Shared Scan (share slice:id 1:0)
+ QUERY PLAN
+------------------------------------------------------------
+ Sequence
+ -> Shared Scan (share slice:id 0:0)
+ -> Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
+ -> Nested Loop
+ Join Filter: true
+ -> Shared Scan (share slice:id 0:0)
-> Materialize
- -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Gather Motion 3:1 (slice2; segments: 3)
-> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ Optimizer: GPORCA
+(12 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test3;
QUERY PLAN
-----------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
+ Join Filter: true
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
- -> Materialize
- -> Shared Scan (share slice:id 1:0)
- -> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ -> Seq Scan on z2
+ Optimizer: GPORCA
+(8 rows)
SET ROLE regress_rls_group2;
SELECT * FROM z1 WHERE f_leak(b);
@@ -2423,7 +2800,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM z1 WHERE f_leak(b);
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test;
@@ -2432,36 +2809,38 @@ EXPLAIN (COSTS OFF) EXECUTE plancache_test;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test2;
- QUERY PLAN
----------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3)
- -> Nested Loop
- -> Shared Scan (share slice:id 1:0)
+ QUERY PLAN
+------------------------------------------------------------
+ Sequence
+ -> Shared Scan (share slice:id 0:0)
+ -> Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
+ -> Nested Loop
+ Join Filter: true
+ -> Shared Scan (share slice:id 0:0)
-> Materialize
- -> Broadcast Motion 3:3 (slice2; segments: 3)
+ -> Gather Motion 3:1 (slice2; segments: 3)
-> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ Optimizer: GPORCA
+(12 rows)
EXPLAIN (COSTS OFF) EXECUTE plancache_test3;
QUERY PLAN
-----------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
+ Join Filter: true
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 1) AND f_leak(b))
- -> Materialize
- -> Shared Scan (share slice:id 1:0)
- -> Seq Scan on z2
- Optimizer: Postgres query optimizer
-(9 rows)
+ -> Seq Scan on z2
+ Optimizer: GPORCA
+(8 rows)
--
-- Views should follow policy for view owner.
@@ -2491,7 +2870,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM rls_view;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: f_leak(b)
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
-- Query as view/table owner. Should return all records.
@@ -2515,7 +2894,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM rls_view;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: f_leak(b)
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
DROP VIEW rls_view;
@@ -2541,7 +2920,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM rls_view;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
-- Query as role that is not owner of table but is owner of view.
@@ -2562,7 +2941,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM rls_view;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
-- Query as role that is not the owner of the table or view without permissions.
@@ -2589,7 +2968,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM rls_view;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on z1
Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
SET SESSION AUTHORIZATION regress_rls_bob;
@@ -2599,6 +2978,8 @@ DROP VIEW rls_view;
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE x1 (a int, b text, c text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
GRANT ALL ON x1 TO PUBLIC;
INSERT INTO x1 VALUES
(1, 'abc', 'regress_rls_bob'),
@@ -2617,9 +2998,11 @@ CREATE POLICY p4 ON x1 FOR DELETE USING (a < 8);
ALTER TABLE x1 ENABLE ROW LEVEL SECURITY;
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM x1 WHERE f_leak(b) ORDER BY a ASC;
-NOTICE: f_leak => abc
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => bcd
NOTICE: f_leak => def
+NOTICE: f_leak => abc
NOTICE: f_leak => efg
NOTICE: f_leak => fgh
NOTICE: f_leak => fgh
@@ -2634,11 +3017,13 @@ NOTICE: f_leak => fgh
(6 rows)
UPDATE x1 SET b = b || '_updt' WHERE f_leak(b) RETURNING *;
-NOTICE: f_leak => abc
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => bcd
-NOTICE: f_leak => def
+NOTICE: f_leak => abc
NOTICE: f_leak => efg
NOTICE: f_leak => fgh
+NOTICE: f_leak => def
NOTICE: f_leak => fgh
a | b | c
---+----------+-------------------
@@ -2652,11 +3037,13 @@ NOTICE: f_leak => fgh
SET SESSION AUTHORIZATION regress_rls_carol;
SELECT * FROM x1 WHERE f_leak(b) ORDER BY a ASC;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
+NOTICE: f_leak => fgh_updt
NOTICE: f_leak => cde
NOTICE: f_leak => fgh
NOTICE: f_leak => bcd_updt
NOTICE: f_leak => def_updt
-NOTICE: f_leak => fgh_updt
NOTICE: f_leak => fgh_updt
a | b | c
---+----------+-------------------
@@ -2669,11 +3056,13 @@ NOTICE: f_leak => fgh_updt
(6 rows)
UPDATE x1 SET b = b || '_updt' WHERE f_leak(b) RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
NOTICE: f_leak => cde
+NOTICE: f_leak => fgh_updt
NOTICE: f_leak => fgh
NOTICE: f_leak => bcd_updt
NOTICE: f_leak => def_updt
-NOTICE: f_leak => fgh_updt
NOTICE: f_leak => fgh_updt
a | b | c
---+---------------+-------------------
@@ -2686,11 +3075,13 @@ NOTICE: f_leak => fgh_updt
(6 rows)
DELETE FROM x1 WHERE f_leak(b) RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
NOTICE: f_leak => cde_updt
+NOTICE: f_leak => fgh_updt_updt
NOTICE: f_leak => fgh_updt
NOTICE: f_leak => bcd_updt_updt
NOTICE: f_leak => def_updt_updt
-NOTICE: f_leak => fgh_updt_updt
NOTICE: f_leak => fgh_updt_updt
a | b | c
---+---------------+-------------------
@@ -2707,7 +3098,11 @@ NOTICE: f_leak => fgh_updt_updt
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE y1 (a int, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE y2 (a int, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
GRANT ALL ON y1, y2 TO regress_rls_bob;
CREATE POLICY p1 ON y1 FOR ALL USING (a % 2 = 0);
CREATE POLICY p2 ON y1 FOR SELECT USING (a > 2);
@@ -2724,6 +3119,8 @@ SET SESSION AUTHORIZATION regress_rls_alice;
CREATE VIEW rls_sbv WITH (security_barrier) AS
SELECT * FROM y1 WHERE f_leak(b);
EXPLAIN (COSTS OFF) SELECT * FROM rls_sbv WHERE (a = 1);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: views with security_barrier ON
QUERY PLAN
------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
@@ -2738,6 +3135,8 @@ SET SESSION AUTHORIZATION regress_rls_bob;
CREATE VIEW rls_sbv WITH (security_barrier) AS
SELECT * FROM y1 WHERE f_leak(b);
EXPLAIN (COSTS OFF) SELECT * FROM rls_sbv WHERE (a = 1);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: views with security_barrier ON
QUERY PLAN
------------------------------------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
@@ -2795,7 +3194,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM y2 WHERE f_leak(b);
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on y2
Filter: ((((a % 4) = 0) OR ((a % 3) = 0) OR ((a % 2) = 0)) AND f_leak(b))
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
--
@@ -2846,13 +3245,15 @@ EXPLAIN (COSTS OFF) SELECT * FROM y2 WHERE f_leak('abc');
---------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on y2
- Filter: (f_leak('abc'::text) AND (((a % 4) = 0) OR ((a % 3) = 0) OR ((a % 2) = 0)))
- Optimizer: Postgres query optimizer
+ Filter: ((((a % 4) = 0) OR ((a % 3) = 0) OR ((a % 2) = 0)) AND f_leak('abc'::text))
+ Optimizer: GPORCA
(4 rows)
CREATE TABLE test_qual_pushdown (
abc text
);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'abc' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO test_qual_pushdown VALUES ('abc'),('def');
ANALYZE test_qual_pushdown;
SELECT * FROM y2 JOIN test_qual_pushdown ON (b = abc) WHERE f_leak(abc);
@@ -2874,7 +3275,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM y2 JOIN test_qual_pushdown ON (b = abc) WHERE
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Seq Scan on test_qual_pushdown
Filter: f_leak(abc)
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(10 rows)
SELECT * FROM y2 JOIN test_qual_pushdown ON (b = abc) WHERE f_leak(b);
@@ -2897,18 +3298,19 @@ NOTICE: f_leak => 98f13708210194c475687be6106a3b84
(0 rows)
EXPLAIN (COSTS OFF) SELECT * FROM y2 JOIN test_qual_pushdown ON (b = abc) WHERE f_leak(b);
- QUERY PLAN
------------------------------------------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Hash Join
Hash Cond: (y2.b = test_qual_pushdown.abc)
- -> Seq Scan on y2
- Filter: ((((a % 4) = 0) OR ((a % 3) = 0) OR ((a % 2) = 0)) AND f_leak(b))
+ -> Redistribute Motion 3:3 (slice2; segments: 3)
+ Hash Key: y2.b
+ -> Seq Scan on y2
+ Filter: ((((a % 4) = 0) OR ((a % 3) = 0) OR ((a % 2) = 0)) AND f_leak(b))
-> Hash
- -> Broadcast Motion 3:3 (slice2; segments: 3)
- -> Seq Scan on test_qual_pushdown
- Optimizer: Postgres query optimizer
-(9 rows)
+ -> Seq Scan on test_qual_pushdown
+ Optimizer: GPORCA
+(10 rows)
DROP TABLE test_qual_pushdown;
--
@@ -2920,6 +3322,8 @@ NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table t2
drop cascades to table t3
CREATE TABLE t1 (a integer);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
GRANT SELECT ON t1 TO regress_rls_bob, regress_rls_carol;
CREATE POLICY p1 ON t1 TO regress_rls_bob USING ((a % 2) = 0);
CREATE POLICY p2 ON t1 TO regress_rls_carol USING ((a % 4) = 0);
@@ -2934,7 +3338,7 @@ EXPLAIN (COSTS OFF) EXECUTE role_inval;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1
Filter: ((a % 2) = 0)
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
-- Change to regress_rls_carol
@@ -2946,7 +3350,7 @@ EXPLAIN (COSTS OFF) EXECUTE role_inval;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1
Filter: ((a % 4) = 0)
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
-- Change back to regress_rls_bob
@@ -2958,7 +3362,7 @@ EXPLAIN (COSTS OFF) EXECUTE role_inval;
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1
Filter: ((a % 2) = 0)
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
--
@@ -2967,6 +3371,8 @@ EXPLAIN (COSTS OFF) EXECUTE role_inval;
RESET SESSION AUTHORIZATION;
DROP TABLE t1 CASCADE;
CREATE TABLE t1 (a integer, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY p1 ON t1 USING (a % 2 = 0);
ALTER TABLE t1 ENABLE ROW LEVEL SECURITY;
GRANT ALL ON t1 TO regress_rls_bob;
@@ -3001,18 +3407,24 @@ NOTICE: f_leak => 98f13708210194c475687be6106a3b84
EXPLAIN (COSTS OFF)
WITH cte1 AS MATERIALIZED (SELECT * FROM t1 WHERE f_leak(b)) SELECT * FROM cte1;
- QUERY PLAN
------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
- -> Shared Scan (share slice:id 1:0)
- -> Seq Scan on t1
- Filter: (((a % 2) = 0) AND f_leak(b))
- Optimizer: Postgres query optimizer
-(5 rows)
+ -> Sequence
+ -> Shared Scan (share slice:id 1:0)
+ -> Seq Scan on t1
+ Filter: (((a % 2) = 0) AND f_leak(b))
+ -> Shared Scan (share slice:id 1:0)
+ Optimizer: GPORCA
+(7 rows)
WITH cte1 AS (UPDATE t1 SET a = a + 1 RETURNING *) SELECT * FROM cte1; --fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "t1"
WITH cte1 AS (UPDATE t1 SET a = a RETURNING *) SELECT * FROM cte1; --ok
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
a | b
----+----------------------------------
0 | cfcd208495d565ef66e7dff9f98764da
@@ -3029,8 +3441,12 @@ WITH cte1 AS (UPDATE t1 SET a = a RETURNING *) SELECT * FROM cte1; --ok
(11 rows)
WITH cte1 AS (INSERT INTO t1 VALUES (21, 'Fail') RETURNING *) SELECT * FROM cte1; --fail
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "t1"
WITH cte1 AS (INSERT INTO t1 VALUES (20, 'Success') RETURNING *) SELECT * FROM cte1; --ok
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
a | b
----+---------
20 | Success
@@ -3046,6 +3462,8 @@ SELECT polname, relname
FROM pg_policy pol
JOIN pg_class pc ON (pc.oid = pol.polrelid)
WHERE relname = 't1';
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
polname | relname
---------+---------
p1 | t1
@@ -3056,6 +3474,8 @@ SELECT polname, relname
FROM pg_policy pol
JOIN pg_class pc ON (pc.oid = pol.polrelid)
WHERE relname = 't1';
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
polname | relname
---------+---------
p2 | t1
@@ -3066,14 +3486,16 @@ SELECT polname, relname
--
SET SESSION AUTHORIZATION regress_rls_bob;
CREATE TABLE t2 (a integer, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO t2 (SELECT * FROM t1);
EXPLAIN (COSTS OFF) INSERT INTO t2 (SELECT * FROM t1);
- QUERY PLAN
--------------------------------------
+ QUERY PLAN
+-------------------------------
Insert on t2
-> Seq Scan on t1
Filter: ((a % 2) = 0)
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(4 rows)
SELECT * FROM t2;
@@ -3098,10 +3520,11 @@ EXPLAIN (COSTS OFF) SELECT * FROM t2;
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t2
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(3 rows)
CREATE TABLE t3 AS SELECT * FROM t1;
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry.
SELECT * FROM t3;
a | b
----+----------------------------------
@@ -3120,6 +3543,7 @@ SELECT * FROM t3;
(12 rows)
SELECT * INTO t4 FROM t1;
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry.
SELECT * FROM t4;
a | b
----+----------------------------------
@@ -3142,7 +3566,11 @@ SELECT * FROM t4;
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE blog (id integer, author text, post text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE comment (blog_id integer, message text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'blog_id' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
GRANT ALL ON blog, comment TO regress_rls_bob;
CREATE POLICY blog_1 ON blog USING (id % 2 = 0);
ALTER TABLE blog ENABLE ROW LEVEL SECURITY;
@@ -3235,7 +3663,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1;
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(3 rows)
-- Check that default deny does not apply to table owner.
@@ -3272,7 +3700,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1;
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1
- Optimizer: Postgres query optimizer
+ Optimizer: GPORCA
(3 rows)
-- Check that default deny applies to non-owner/non-superuser when RLS on.
@@ -3284,12 +3712,13 @@ SELECT * FROM t1;
(0 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1;
- QUERY PLAN
--------------------------------------
- Result
- One-Time Filter: false
- Optimizer: Postgres query optimizer
-(3 rows)
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on t1
+ Filter: false
+ Optimizer: GPORCA
+(4 rows)
SET SESSION AUTHORIZATION regress_rls_bob;
SELECT * FROM t1;
@@ -3298,12 +3727,13 @@ SELECT * FROM t1;
(0 rows)
EXPLAIN (COSTS OFF) SELECT * FROM t1;
- QUERY PLAN
--------------------------------------
- Result
- One-Time Filter: false
- Optimizer: Postgres query optimizer
-(3 rows)
+ QUERY PLAN
+------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ -> Seq Scan on t1
+ Filter: false
+ Optimizer: GPORCA
+(4 rows)
--
-- COPY TO/FROM
@@ -3312,6 +3742,8 @@ RESET SESSION AUTHORIZATION;
DROP TABLE copy_t CASCADE;
ERROR: table "copy_t" does not exist
CREATE TABLE copy_t (a integer, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY p1 ON copy_t USING (a % 2 = 0);
ALTER TABLE copy_t ENABLE ROW LEVEL SECURITY;
GRANT ALL ON copy_t TO regress_rls_bob, regress_rls_exempt_user;
@@ -3397,6 +3829,8 @@ ERROR: permission denied for table copy_t
RESET SESSION AUTHORIZATION;
SET row_security TO ON;
CREATE TABLE copy_rel_to (a integer, b text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY p1 ON copy_rel_to USING (a % 2 = 0);
ALTER TABLE copy_rel_to ENABLE ROW LEVEL SECURITY;
GRANT ALL ON copy_rel_to TO regress_rls_bob, regress_rls_exempt_user;
@@ -3465,6 +3899,8 @@ DROP TABLE copy_rel_to CASCADE;
-- Check WHERE CURRENT OF
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE current_check (currentid int, payload text, rlsuser text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'currentid' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
GRANT ALL ON current_check TO PUBLIC;
INSERT INTO current_check VALUES
(1, 'abc', 'regress_rls_bob'),
@@ -3486,6 +3922,8 @@ SELECT * FROM current_check;
-- Cannot UPDATE row 2
UPDATE current_check SET payload = payload || '_new' WHERE currentid = 2 RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
currentid | payload | rlsuser
-----------+---------+---------
(0 rows)
@@ -3502,6 +3940,8 @@ FETCH ABSOLUTE 1 FROM current_check_cursor;
-- Still cannot UPDATE row 2 through cursor
UPDATE current_check SET payload = payload || '_new' WHERE CURRENT OF current_check_cursor RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
currentid | payload | rlsuser
-----------+---------+---------
(0 rows)
@@ -3514,6 +3954,8 @@ FETCH RELATIVE 1 FROM current_check_cursor;
(1 row)
UPDATE current_check SET payload = payload || '_new' WHERE CURRENT OF current_check_cursor RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
currentid | payload | rlsuser
-----------+---------+-----------------
4 | def_new | regress_rls_bob
@@ -3528,14 +3970,23 @@ SELECT * FROM current_check;
-- Plan should be a subquery TID scan
EXPLAIN (COSTS OFF) UPDATE current_check SET payload = payload WHERE CURRENT OF current_check_cursor;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
-------------------------------------------------------------
Update on current_check
-> Tid Scan on current_check
TID Cond: CURRENT OF current_check_cursor
Filter: ((currentid = 4) AND ((currentid % 2) = 0))
-(4 rows)
+ Optimizer: Postgres-based planner
+(5 rows)
+-- start_ignore
+-- GPDB: does not support backwards scans, commit and restart
+COMMIT;
+BEGIN;
+DECLARE current_check_cursor SCROLL CURSOR FOR SELECT * FROM current_check;
+-- end_ignore
-- Similarly can only delete row 4
FETCH ABSOLUTE 1 FROM current_check_cursor;
currentid | payload | rlsuser
@@ -3544,6 +3995,8 @@ FETCH ABSOLUTE 1 FROM current_check_cursor;
(1 row)
DELETE FROM current_check WHERE CURRENT OF current_check_cursor RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: CURRENT OF
currentid | payload | rlsuser
-----------+---------+---------
(0 rows)
@@ -3555,6 +4008,8 @@ FETCH RELATIVE 1 FROM current_check_cursor;
(1 row)
DELETE FROM current_check WHERE CURRENT OF current_check_cursor RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: CURRENT OF
currentid | payload | rlsuser
-----------+---------+-----------------
4 | def_new | regress_rls_bob
@@ -3583,6 +4038,8 @@ SELECT row_security_active('current_check');
SELECT attname, most_common_vals FROM pg_stats
WHERE tablename = 'current_check'
ORDER BY 1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: views with security_barrier ON
attname | most_common_vals
-----------+-------------------
currentid |
@@ -3601,6 +4058,8 @@ SELECT row_security_active('current_check');
SELECT attname, most_common_vals FROM pg_stats
WHERE tablename = 'current_check'
ORDER BY 1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: views with security_barrier ON
attname | most_common_vals
---------+------------------
(0 rows)
@@ -3610,10 +4069,13 @@ SELECT attname, most_common_vals FROM pg_stats
--
BEGIN;
CREATE TABLE coll_t (c) AS VALUES ('bar'::text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry.
CREATE POLICY coll_p ON coll_t USING (c < ('foo'::text COLLATE "C"));
ALTER TABLE coll_t ENABLE ROW LEVEL SECURITY;
GRANT SELECT ON coll_t TO regress_rls_alice;
SELECT (string_to_array(polqual, ':'))[7] AS inputcollid FROM pg_policy WHERE polrelid = 'coll_t'::regclass;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
inputcollid
------------------
inputcollid 950
@@ -3621,6 +4083,8 @@ SELECT (string_to_array(polqual, ':'))[7] AS inputcollid FROM pg_policy WHERE po
SET SESSION AUTHORIZATION regress_rls_alice;
SELECT * FROM coll_t;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
c
-----
bar
@@ -3635,12 +4099,15 @@ BEGIN;
CREATE ROLE regress_rls_eve;
CREATE ROLE regress_rls_frank;
CREATE TABLE tbl1 (c) AS VALUES ('bar'::text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry.
GRANT SELECT ON TABLE tbl1 TO regress_rls_eve;
CREATE POLICY P ON tbl1 TO regress_rls_eve, regress_rls_frank USING (true);
SELECT refclassid::regclass, deptype
FROM pg_depend
WHERE classid = 'pg_policy'::regclass
AND refobjid = 'tbl1'::regclass;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
refclassid | deptype
------------+---------
pg_class | a
@@ -3650,6 +4117,8 @@ SELECT refclassid::regclass, deptype
FROM pg_shdepend
WHERE classid = 'pg_policy'::regclass
AND refobjid IN ('regress_rls_eve'::regrole, 'regress_rls_frank'::regrole);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
refclassid | deptype
------------+---------
pg_authid | r
@@ -3687,11 +4156,13 @@ ROLLBACK; -- cleanup
--
BEGIN;
CREATE TABLE t (c int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY p ON t USING (c % 2 = 1);
ALTER TABLE t ENABLE ROW LEVEL SECURITY;
SAVEPOINT q;
CREATE RULE "_RETURN" AS ON SELECT TO t DO INSTEAD
- SELECT * FROM generate_series(1,5) t0(c); -- fails due to row-level security enabled
+ SELECT * FROM generate_series(1,5) t0(c); -- fails due to row level security enabled
ERROR: could not convert table "t" to a view because it has row security enabled
ROLLBACK TO q;
ALTER TABLE t DISABLE ROW LEVEL SECURITY;
@@ -3709,6 +4180,7 @@ ROLLBACK;
--
BEGIN;
CREATE TABLE t (c) AS VALUES ('bar'::text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry.
CREATE POLICY p ON t USING (max(c)); -- fails: aggregate functions are not allowed in policy expressions
ERROR: aggregate functions are not allowed in policy expressions
ROLLBACK;
@@ -3717,7 +4189,11 @@ ROLLBACK;
--
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE r1 (a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE r2 (a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO r1 VALUES (10), (20);
INSERT INTO r2 VALUES (10), (20);
GRANT ALL ON r1, r2 TO regress_rls_bob;
@@ -3745,19 +4221,27 @@ SELECT * FROM r2;
-- r2 is read-only
INSERT INTO r2 VALUES (2); -- Not allowed
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "r2"
UPDATE r2 SET a = 2 RETURNING *; -- Updates nothing
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
a
---
(0 rows)
DELETE FROM r2 RETURNING *; -- Deletes nothing
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: RETURNING clause
a
---
(0 rows)
-- r2 can be used as a non-target relation in DML
INSERT INTO r1 SELECT a + 1 FROM r2 RETURNING *; -- OK
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
a
----
11
@@ -3765,6 +4249,8 @@ INSERT INTO r1 SELECT a + 1 FROM r2 RETURNING *; -- OK
(2 rows)
UPDATE r1 SET a = r2.a + 2 FROM r2 WHERE r1.a = r2.a RETURNING *; -- OK
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
a | a
----+----
12 | 10
@@ -3772,6 +4258,8 @@ UPDATE r1 SET a = r2.a + 2 FROM r2 WHERE r1.a = r2.a RETURNING *; -- OK
(2 rows)
DELETE FROM r1 USING r2 WHERE r1.a = r2.a + 2 RETURNING *; -- OK
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: RETURNING clause
a | a
----+----
12 | 10
@@ -3801,6 +4289,8 @@ DROP TABLE r2;
SET SESSION AUTHORIZATION regress_rls_alice;
SET row_security = on;
CREATE TABLE r1 (a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO r1 VALUES (10), (20);
CREATE POLICY p1 ON r1 USING (false);
ALTER TABLE r1 ENABLE ROW LEVEL SECURITY;
@@ -3813,9 +4303,13 @@ TABLE r1;
-- RLS error
INSERT INTO r1 VALUES (1);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "r1"
-- No error (unable to see any rows to update)
UPDATE r1 SET a = 1;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
TABLE r1;
a
---
@@ -3847,6 +4341,9 @@ SET SESSION AUTHORIZATION regress_rls_alice;
SET row_security = on;
CREATE TABLE r1 (a int PRIMARY KEY);
CREATE TABLE r2 (a int REFERENCES r1);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
+WARNING: referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced
INSERT INTO r1 VALUES (10), (20);
INSERT INTO r2 VALUES (10), (20);
-- Create policies on r2 which prevent the
@@ -3881,6 +4378,9 @@ DROP TABLE r1;
-- Ensure cascaded DELETE works
CREATE TABLE r1 (a int PRIMARY KEY);
CREATE TABLE r2 (a int REFERENCES r1 ON DELETE CASCADE);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
+WARNING: referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced
INSERT INTO r1 VALUES (10), (20);
INSERT INTO r2 VALUES (10), (20);
-- Create policies on r2 which prevent the
@@ -3908,6 +4408,9 @@ DROP TABLE r1;
-- Ensure cascaded UPDATE works
CREATE TABLE r1 (a int PRIMARY KEY);
CREATE TABLE r2 (a int REFERENCES r1 ON UPDATE CASCADE);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
+WARNING: referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced
INSERT INTO r1 VALUES (10), (20);
INSERT INTO r2 VALUES (10), (20);
-- Create policies on r2 which prevent the
@@ -3939,12 +4442,16 @@ DROP TABLE r1;
SET SESSION AUTHORIZATION regress_rls_alice;
SET row_security = on;
CREATE TABLE r1 (a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY p1 ON r1 FOR SELECT USING (false);
CREATE POLICY p2 ON r1 FOR INSERT WITH CHECK (true);
ALTER TABLE r1 ENABLE ROW LEVEL SECURITY;
ALTER TABLE r1 FORCE ROW LEVEL SECURITY;
-- Works fine
INSERT INTO r1 VALUES (10), (20);
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
-- No error, but no rows
TABLE r1;
a
@@ -3959,6 +4466,8 @@ HINT: To disable the policy for the table's owner, use ALTER TABLE NO FORCE ROW
SET row_security = on;
-- Error
INSERT INTO r1 VALUES (10), (20) RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "r1"
DROP TABLE r1;
--
@@ -3976,6 +4485,8 @@ ALTER TABLE r1 ENABLE ROW LEVEL SECURITY;
ALTER TABLE r1 FORCE ROW LEVEL SECURITY;
-- Works fine
UPDATE r1 SET a = 30;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
-- Show updated rows
ALTER TABLE r1 NO FORCE ROW LEVEL SECURITY;
TABLE r1;
@@ -3986,6 +4497,8 @@ TABLE r1;
-- reset value in r1 for test with RETURNING
UPDATE r1 SET a = 10;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Operator Update on replicated tables not supported
-- Verify row reset
TABLE r1;
a
@@ -3996,30 +4509,44 @@ TABLE r1;
ALTER TABLE r1 FORCE ROW LEVEL SECURITY;
-- Error
UPDATE r1 SET a = 30 RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "r1"
-- UPDATE path of INSERT ... ON CONFLICT DO UPDATE should also error out
INSERT INTO r1 VALUES (10)
ON CONFLICT (a) DO UPDATE SET a = 30 RETURNING *;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "r1"
-- Should still error out without RETURNING (use of arbiter always requires
-- SELECT permissions)
INSERT INTO r1 VALUES (10)
ON CONFLICT (a) DO UPDATE SET a = 30;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "r1"
INSERT INTO r1 VALUES (10)
ON CONFLICT ON CONSTRAINT r1_pkey DO UPDATE SET a = 30;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
ERROR: new row violates row-level security policy for table "r1"
DROP TABLE r1;
-- Check dependency handling
RESET SESSION AUTHORIZATION;
CREATE TABLE dep1 (c1 int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE dep2 (c1 int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY dep_p1 ON dep1 TO regress_rls_bob USING (c1 > (select max(dep2.c1) from dep2));
ALTER POLICY dep_p1 ON dep1 TO regress_rls_bob,regress_rls_carol;
-- Should return one
SELECT count(*) = 1 FROM pg_depend
WHERE objid = (SELECT oid FROM pg_policy WHERE polname = 'dep_p1')
AND refobjid = (SELECT oid FROM pg_class WHERE relname = 'dep2');
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
?column?
----------
t
@@ -4030,6 +4557,8 @@ ALTER POLICY dep_p1 ON dep1 USING (true);
SELECT count(*) = 1 FROM pg_shdepend
WHERE objid = (SELECT oid FROM pg_policy WHERE polname = 'dep_p1')
AND refobjid = (SELECT oid FROM pg_authid WHERE rolname = 'regress_rls_bob');
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
?column?
----------
t
@@ -4039,6 +4568,8 @@ SELECT count(*) = 1 FROM pg_shdepend
SELECT count(*) = 1 FROM pg_shdepend
WHERE objid = (SELECT oid FROM pg_policy WHERE polname = 'dep_p1')
AND refobjid = (SELECT oid FROM pg_authid WHERE rolname = 'regress_rls_carol');
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
?column?
----------
t
@@ -4048,6 +4579,8 @@ SELECT count(*) = 1 FROM pg_shdepend
SELECT count(*) = 0 FROM pg_depend
WHERE objid = (SELECT oid FROM pg_policy WHERE polname = 'dep_p1')
AND refobjid = (SELECT oid FROM pg_class WHERE relname = 'dep2');
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Queries on coordinator-only tables
?column?
----------
t
@@ -4058,7 +4591,11 @@ RESET SESSION AUTHORIZATION;
CREATE ROLE regress_rls_dob_role1;
CREATE ROLE regress_rls_dob_role2;
CREATE TABLE dob_t1 (c1 int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE dob_t2 (c1 int) PARTITION BY RANGE (c1);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY p1 ON dob_t1 TO regress_rls_dob_role1 USING (true);
DROP OWNED BY regress_rls_dob_role1;
DROP POLICY p1 ON dob_t1; -- should fail, already gone
@@ -4082,8 +4619,12 @@ DROP USER regress_rls_dob_role1;
DROP USER regress_rls_dob_role2;
-- Bug #15708: view + table with RLS should check policies as view owner
CREATE TABLE ref_tbl (a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO ref_tbl VALUES (1);
CREATE TABLE rls_tbl (a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO rls_tbl VALUES (10);
ALTER TABLE rls_tbl ENABLE ROW LEVEL SECURITY;
CREATE POLICY p1 ON rls_tbl USING (EXISTS (SELECT 1 FROM ref_tbl));
@@ -4096,8 +4637,12 @@ SET SESSION AUTHORIZATION regress_rls_alice;
SELECT * FROM ref_tbl; -- Permission denied
ERROR: permission denied for table ref_tbl
SELECT * FROM rls_tbl; -- Permission denied
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
ERROR: permission denied for table rls_tbl
SELECT * FROM rls_view; -- OK
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Query has row level security enabled and security quals contain sublinks
a
----
10
@@ -4109,6 +4654,8 @@ DROP TABLE rls_tbl;
DROP TABLE ref_tbl;
-- Leaky operator test
CREATE TABLE rls_tbl (a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO rls_tbl SELECT x/10 FROM generate_series(1, 100) x;
ANALYZE rls_tbl;
ALTER TABLE rls_tbl ENABLE ROW LEVEL SECURITY;
@@ -4131,13 +4678,19 @@ DROP TABLE rls_tbl;
-- Bug #16006: whole-row Vars in a policy don't play nice with sub-selects
SET SESSION AUTHORIZATION regress_rls_alice;
CREATE TABLE rls_tbl (a int, b int, c int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE POLICY p1 ON rls_tbl USING (rls_tbl >= ROW(1,1,1));
ALTER TABLE rls_tbl ENABLE ROW LEVEL SECURITY;
ALTER TABLE rls_tbl FORCE ROW LEVEL SECURITY;
INSERT INTO rls_tbl SELECT 10, 20, 30;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
EXPLAIN (VERBOSE, COSTS OFF)
INSERT INTO rls_tbl
SELECT * FROM (SELECT b, c FROM rls_tbl ORDER BY a) ss;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
QUERY PLAN
--------------------------------------------------------------------------
Insert on regress_rls_schema.rls_tbl
@@ -4152,13 +4705,16 @@ INSERT INTO rls_tbl
-> Seq Scan on regress_rls_schema.rls_tbl rls_tbl_1
Output: rls_tbl_1.b, rls_tbl_1.c, rls_tbl_1.a
Filter: (rls_tbl_1.* >= ROW(1, 1, 1))
- Optimizer: Postgres query optimizer
- Settings: gp_enable_relsize_collection=on
-(14 rows)
+ Optimizer: Postgres-based planner
+(13 rows)
INSERT INTO rls_tbl
SELECT * FROM (SELECT b, c FROM rls_tbl ORDER BY a) ss;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: View with WITH CHECK OPTION
SELECT * FROM rls_tbl;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: ROW EXPRESSION
a | b | c
----+----+----
10 | 20 | 30
@@ -4169,6 +4725,8 @@ DROP TABLE rls_tbl;
RESET SESSION AUTHORIZATION;
-- CVE-2023-2455: inlining an SRF may introduce an RLS dependency
create table rls_t (c text);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into rls_t values ('invisible to bob');
alter table rls_t enable row level security;
grant select on rls_t to regress_rls_alice, regress_rls_bob;
@@ -4180,6 +4738,8 @@ create function rls_f () returns setof rls_t
prepare q as select current_user, * from rls_f();
set role regress_rls_alice;
execute q;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
current_user | c
-------------------+------------------
regress_rls_alice | invisible to bob
@@ -4187,6 +4747,8 @@ execute q;
set role regress_rls_bob;
execute q;
+INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
+DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: Non-default collation
current_user | c
--------------+---
(0 rows)
@@ -4240,15 +4802,20 @@ DROP ROLE regress_rls_group2;
-- pg_dump/pg_restore
CREATE SCHEMA regress_rls_schema;
CREATE TABLE rls_tbl (c1 int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
ALTER TABLE rls_tbl ENABLE ROW LEVEL SECURITY;
CREATE POLICY p1 ON rls_tbl USING (c1 > 5);
CREATE POLICY p2 ON rls_tbl FOR SELECT USING (c1 <= 3);
CREATE POLICY p3 ON rls_tbl FOR UPDATE USING (c1 <= 3) WITH CHECK (c1 > 5);
CREATE POLICY p4 ON rls_tbl FOR DELETE USING (c1 <= 3);
CREATE TABLE rls_tbl_force (c1 int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Greenplum Database data distribution key for this table.
+HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
ALTER TABLE rls_tbl_force ENABLE ROW LEVEL SECURITY;
ALTER TABLE rls_tbl_force FORCE ROW LEVEL SECURITY;
CREATE POLICY p1 ON rls_tbl_force USING (c1 = 5) WITH CHECK (c1 < 5);
CREATE POLICY p2 ON rls_tbl_force FOR SELECT USING (c1 = 8);
CREATE POLICY p3 ON rls_tbl_force FOR UPDATE USING (c1 = 8) WITH CHECK (c1 >= 5);
CREATE POLICY p4 ON rls_tbl_force FOR DELETE USING (c1 = 8);
+reset optimizer_trace_fallback;
diff --git a/src/test/regress/greenplum_schedule b/src/test/regress/greenplum_schedule
index 42ebacfd14..1db65cd253 100755
--- a/src/test/regress/greenplum_schedule
+++ b/src/test/regress/greenplum_schedule
@@ -199,7 +199,7 @@ test: rpt rpt_joins rpt_tpch rpt_returning
test: bfv_cte
test: bfv_joins bfv_subquery bfv_planner bfv_legacy bfv_temp bfv_dml
-test: qp_olap_mdqa qp_misc gp_recursive_cte qp_dml_joins qp_skew qp_select partition_prune_opfamily gp_tsrf qp_join_union_all qp_join_universal
+test: qp_olap_mdqa qp_misc gp_recursive_cte qp_dml_joins qp_skew qp_select partition_prune_opfamily gp_tsrf qp_join_union_all qp_join_universal qp_rowsecurity
test: qp_misc_jiras qp_with_clause qp_executor qp_olap_windowerr qp_olap_window qp_derived_table qp_bitmapscan qp_dropped_cols
test: qp_with_functional_inlining qp_with_functional_noinlining
diff --git a/src/test/regress/sql/qp_rowsecurity.sql b/src/test/regress/sql/qp_rowsecurity.sql
new file mode 100644
index 0000000000..ca644cd5c9
--- /dev/null
+++ b/src/test/regress/sql/qp_rowsecurity.sql
@@ -0,0 +1,466 @@
+--------------------------------------------------------------------------------
+-- Current implementation only supports SELECT and DELETE queries.
+-- Foreign Scan / Dynamic Foreign Scan with row level security is not supported.
+-- Any sort of index plans will not be generated by ORCA
+-- for a relation having RLS enabled.
+-- If the security quals contains sublinks then ORCA will fall back to planner.
+--------------------------------------------------------------------------------
+-- NOTE:
+-- The file rowsecurity.sql has a wider test coverage but the issue is most of
+-- the queries in that file are falling back to planner because of not supported
+-- features by ORCA such as non default collation, VIEW with WITH CHECK OPTION,
+-- Queries on coordinator-only tables, Query has row level security enabled and
+-- security quals contain sublinks etc. So rowsecurity.sql file is not providing
+-- much help in testing ORCA side changes.
+-- But on a high level some of the tests covered in rowsecurity.sql is
+ -- Table inheritance and RLS policy
+ -- There are tests related to partition relations but the test cases are
+ -- falling back due to various reasons like non default collation, VIEW with
+ -- WITH CHECK OPTION.
+ -- CTE with RLS
+ -- RLS with joins
+ -- View with WITH CHECK OPTION
+ -- Recursive Queries
+ -- Testing the output of queries by granting permissions to various roles
+ -- and groups and superuser database non-superuser with bypass privilege can
+ -- bypass RLS policy when disabled
+ --- RLS policy does not apply to table owner when RLS enabled.
+ -- RLS policy does not apply to table owner when RLS disabled.
+ -- only owner can change policies
+ -- FORCE ROW LEVEL SECURITY applies RLS to owners too
+ -- PREPARE statements
+ -- Duplicate policy names
+ -- Multiple policies on a table
+ -- INSERT in a table with no RLS by selecting from a relation having RLS
+ -- Default Deny policy
+ -- UPDATE/UPDATE with FROM clause/INSERT with Row-level security etc etc.
+-- So the tests that have been covered in qp_rowsecurity are mostly similar to
+-- that in rowsecurity.sql but since they are not falling back to planner, able
+-- to verify the ORCA side changes.
+
+--------------------------------------------------------------------------------
+----- SELECT queries on relation having row level security enabled -------------
+--------------------------------------------------------------------------------
+set optimizer_trace_fallback to on;
+create user new_user;
+create table foo_rls ( a int, b int, c int) distributed by (a);
+create table bar_rls ( p int, q int) distributed by (p);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+insert into foo_rls values (NULL,50,500);;
+insert into foo_rls values (NULL,60,NULL);
+insert into foo_rls values (NULL,70,NULL);
+insert into foo_rls values (NULL,NULL,600);
+insert into foo_rls values (NULL,NULL,700);
+vacuum analyze foo_rls;
+grant select on foo_rls to new_user;
+grant select on bar_rls to new_user;
+alter table foo_rls enable row level security;
+
+CREATE OR REPLACE FUNCTION leak_data(int) RETURNS boolean AS $$
+BEGIN
+ RAISE NOTICE 'Value of column is: %',$1;
+RETURN true;
+END;
+$$ LANGUAGE plpgsql;
+
+-- Permissive policy
+create policy p1 on foo_rls using (a * 10 = b and c > 300);
+set session authorization new_user;
+-- Query plan will have the filter defined in the policy [(a * 10) = b) AND (c > 300)]
+-- before query filter [leak_data(a)]
+explain (costs off ) select * from foo_rls where leak_data(a);
+select * from foo_rls where leak_data(a);
+reset session authorization;
+drop policy p1 on foo_rls;
+
+-- All permissive policies which are applicable to a given query
+-- will be combined together using the Boolean “OR” operator
+create policy p1 on foo_rls as permissive for select using (a * 10 >= 30 );
+create policy p2 on foo_rls as permissive for select
+using (LEAST(a,b) >= 2);
+set session authorization new_user;
+-- The filter defined in the two permissive policies will be OR'ed together
+explain (costs off )select * from foo_rls where leak_data(c);
+select * from foo_rls where leak_data(c);
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+
+-- Restrictive policies
+-- There needs to be at least one permissive policy to grant access to records
+create policy p1 on foo_rls as restrictive for select using (a > 3);
+create policy p2 on foo_rls as restrictive for select using (b > 35);
+set session authorization new_user;
+-- No permissive policies defined on the relation, so no records will be
+-- returned
+explain (costs off ) select * from foo_rls where leak_data(a);
+reset session authorization ;
+create policy p3 on foo_rls as permissive for select using (c % 100 = 0);
+set session authorization new_user;
+-- Now after creating a permissive policy, the query will return records and the
+-- restrictive policies will be AND'ed with permissive policies
+explain (costs off ) select * from foo_rls where leak_data(a);
+select * from foo_rls where leak_data(a);
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+drop policy p3 on foo_rls;
+
+-- The RTE of the relation containing security quals is present inside a
+-- RTE_SUBQUERY rtekind
+create policy p1 on foo_rls as permissive for select using (b + 1 = 4 );
+create policy p2 on foo_rls as permissive for select using (b is distinct
+from c);
+set session authorization new_user;
+explain (costs off ) select * from (select * from foo_rls) t1, bar_rls where
+t1.a=bar_rls.p and bar_rls.q is null and leak_data(c);
+
+-- The RTE of the relation containing security quals is present inside a
+-- SUBLINK node
+explain (costs off ) select * from bar_rls where bar_rls.p in (select a
+from foo_rls where abs(a) >= 10 and leak_data(c)) and bar_rls.q is not null;
+
+-- The RTE of the relation containing security quals is present inside a CTE
+explain (costs off ) with cte as (select * from foo_rls where
+a > LEAST(a,b)) select * from cte left join bar_rls on
+cte.a=bar_rls.p and q = 10 and leak_data(cte.a);
+
+reset session authorization;
+drop policy p1 on foo_rls;
+drop policy p2 on foo_rls;
+
+-- ORCA will fallback to planner if SUBLINK is present inside a security qual
+create policy p1 on foo_rls as permissive for select using (a in (select p
+from bar_rls));
+set session authorization new_user;
+explain (costs off ) select * from foo_rls;
+reset session authorization;
+drop policy p1 on foo_rls;
+
+-- ORCA will not generate any index plans when row level security is enabled
+-- for a relation
+create policy p1 on foo_rls as permissive for select using (b = 10);
+create index btindex on foo_rls using btree(a);
+-- Index Scan is generated by ORCA when the owner of the table runs the query
+set enable_seqscan to off;
+explain (costs off) select * from foo_rls where a is null and b = 10;
+-- Index Scan is not generated by ORCA when RLS enabled by ORCA
+set session authorization new_user;
+explain (costs off) select * from foo_rls where a is null;
+reset session authorization;
+-- Index Only Scan is generated by ORCA when the owner of the table runs the query
+set optimizer_enable_indexscan to off;
+explain (costs off) select a from foo_rls where a is null;
+-- Index Only Scan is not generated by ORCA when RLS enabled
+set session authorization new_user;
+explain (costs off) select a from foo_rls where a is null;
+reset session authorization;
+set optimizer_enable_indexscan to on;
+reset enable_seqscan;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+drop table bar_rls cascade;
+
+--------------------------------------------------------------------------------
+----------- SELECT queries on partitioned tables with RLS enabled --------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20), default partition other_part);
+create table bar_part_rls ( p int, q int) distributed by (p) partition by range(q)
+(start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,5)i;
+insert into foo_part_rls values (NULL,50,500);;
+insert into foo_part_rls values (NULL,60,NULL);
+insert into foo_part_rls values (NULL,70,NULL);
+insert into foo_part_rls values (NULL,NULL,600);
+insert into foo_part_rls values (NULL,NULL,700);
+analyze foo_part_rls;
+grant select on foo_part_rls to new_user;
+grant select on bar_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+
+-- Permissive policy
+create policy p1 on foo_part_rls using (a * 10 = b and c > 300);
+set session authorization new_user;
+-- Query plan will have the filter defined in the policy [(a * 10) = b) AND (c > 300)]
+-- before query filter [leak_data(a)]
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+select * from foo_part_rls where leak_data(a);
+reset session authorization;
+drop policy p1 on foo_part_rls;
+
+-- All permissive policies which are applicable to a given query
+-- will be combined together using the Boolean “OR” operator
+create policy p1 on foo_part_rls as permissive for select using (a * 10 >= 30 );
+create policy p2 on foo_part_rls as permissive for select
+using (LEAST(a,b) >= 2);
+set session authorization new_user;
+-- The filter defined in the two permissive policies will be OR'ed together
+explain (costs off )select * from foo_part_rls where leak_data(c);
+select * from foo_part_rls where leak_data(c);
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+
+-- Restrictive policies
+-- There needs to be at least one permissive policy to grant access to records
+create policy p1 on foo_part_rls as restrictive for select using (a > 3);
+create policy p2 on foo_part_rls as restrictive for select using (b > 35);
+set session authorization new_user;
+-- No permissive policies defined on the relation, so no records will be
+-- returned
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+reset session authorization ;
+create policy p3 on foo_part_rls as permissive for select using (c % 100 = 0);
+set session authorization new_user;
+-- Now after creating a permissive policy, the query will return records and the
+-- restrictive policies will be AND'ed with permissive policies
+explain (costs off ) select * from foo_part_rls where leak_data(a);
+select * from foo_part_rls where leak_data(a);
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+drop policy p3 on foo_part_rls;
+
+-- The RTE of the relation containing security quals is present inside a
+-- RTE_SUBQUERY rtekind
+create policy p1 on foo_part_rls as permissive for select using (b + 1 = 4 );
+create policy p2 on foo_part_rls as permissive for select using (b is distinct
+from c);
+set session authorization new_user;
+explain (costs off ) select * from (select * from foo_part_rls) t1, bar_part_rls
+where t1.a=bar_part_rls.p and bar_part_rls.q is not null and leak_data(c);
+
+-- The RTE of the relation containing security quals is present inside a
+-- SUBLINK node
+explain (costs off ) select * from bar_part_rls where bar_part_rls.p in
+(select a from foo_part_rls where abs(a) >= 10 and leak_data(c)) and
+bar_part_rls.q is not null;
+
+-- The RTE of the relation containing security quals is present inside a CTE
+explain (costs off ) with cte as (select * from foo_part_rls where
+a > LEAST(a,b)) select * from cte left join bar_part_rls on
+cte.a=bar_part_rls.p and q = 10 and leak_data(cte.a);
+
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop policy p2 on foo_part_rls;
+
+-- ORCA will fallback to planner if SUBLINK is present inside a security qual
+create policy p1 on foo_part_rls as permissive for select using (a in
+(select p from bar_part_rls));
+set session authorization new_user;
+explain (costs off ) select * from foo_part_rls where foo_part_rls.b <15;
+reset session authorization;
+drop policy p1 on foo_part_rls;
+
+-- ORCA will not generate any index plans when row level security is enabled
+-- for a relation
+create policy p1 on foo_part_rls as permissive for select using (b = 10);
+create index btindex on foo_part_rls using btree(a);
+-- Dynamic Index Scan is generated by ORCA when the owner of the table runs
+-- the query
+set enable_seqscan to off;
+explain (costs off) select * from foo_part_rls where a is null;
+-- Dynamic Index Scan is not generated by ORCA when RLS is enabled
+set session authorization new_user;
+explain (costs off) select * from foo_part_rls where a is null;
+reset session authorization;
+reset enable_seqscan;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+drop table bar_part_rls cascade;
+drop function leak_data(int);
+
+--------------------------------------------------------------------------------
+----------------- Creating policies on leaf partitions -------------------------
+--------------------------------------------------------------------------------
+create table rootpart (a int, b int) distributed by (a) partition by range(a)
+(start(0) end(10) every(5));
+insert into rootpart select i,i from generate_series(0,9)i;
+-- select permission is only for root partition and not for child partition
+grant select on rootpart to new_user;
+alter table rootpart_1_prt_2 enable row level security;
+create policy p1 on rootpart_1_prt_2 using (a>=7);
+set session authorization new_user;
+explain (costs off) select * from rootpart;
+-- Issue #16961
+-- ORCA and planner should not generate a plan and show error permission denied
+-- for leaf partition
+explain (costs off) select * from rootpart_1_prt_2;
+reset session authorization;
+drop policy p1 on rootpart_1_prt_2;
+drop table rootpart;
+
+--------------------------------------------------------------------------------
+----------------- Grant SELECT to only a leaf partition ------------------------
+--------------------------------------------------------------------------------
+create table rootpart (a int, b int) distributed by (a) partition by range(a)
+(start(0) end(10) every(5));
+insert into rootpart select i,i from generate_series(0,9)i;
+grant select on rootpart_1_prt_2 to new_user;
+alter table rootpart_1_prt_2 enable row level security;
+create policy p1 on rootpart_1_prt_2 using (a>=7);
+set session authorization new_user;
+-- Since the SELECT permission is only for a leaf partition [rootpart_1_prt_2],
+-- querying the root will error out
+explain (costs off) select * from rootpart;
+explain (costs off) select * from rootpart_1_prt_1;
+-- Below query will work fine as the user has SELECT permission on this root
+-- partition
+explain (costs off) select * from rootpart_1_prt_2;
+reset session authorization;
+drop policy p1 on rootpart_1_prt_2;
+drop table rootpart;
+
+--------------------------------------------------------------------------------
+-------------------------- Multilevel Partitions -------------------------------
+--------------------------------------------------------------------------------
+create table rootTab(a int) distributed by (a) partition by range(a);
+create table roottabmid1(a int) distributed by (a) partition by range(a);
+create table roottableaf1(a int) distributed by (a);
+create table roottableaf2(a int) distributed by (a);
+alter table roottab attach partition roottabmid1 for values from (0) to (10);
+alter table roottabmid1 attach partition roottableaf1 for values from (0) to (5);
+alter table roottabmid1 attach partition roottableaf2 for values from (5) to (10);
+insert into roottab select i from generate_series(0,9)i;
+grant select on roottab to new_user;
+alter table roottableaf2 enable row level security;
+create policy p1 on roottableaf2 using (a>=7);
+set session authorization new_user;
+-- Querying the root will fallback to planner as ORCA doesn't supports
+-- Multi-level partitioned tables
+explain (costs off) select * from roottab;
+explain (costs off) select * from roottabmid1;
+explain (costs off) select * from roottableaf1;
+explain (costs off) select * from roottableaf2;
+reset session authorization;
+drop policy p1 on roottableaf2;
+drop table roottab;
+
+--------------------------------------------------------------------------------
+------------------- Inherited Tables with RLS enabled --------------------------
+--------------------------------------------------------------------------------
+create table parent (a int, b int) distributed by (a);
+create table child1 (c int) inherits (parent);
+create table child2 (d int) inherits (parent);
+-- SELECT permission on parent
+grant select on parent to new_user;
+alter table parent enable row level security;
+create policy p1 on parent using (a>=7);
+set session authorization new_user;
+-- Querying the parent will fallback to planner as ORCA doesn't supports
+-- Inherited tables
+explain (costs off) select * from parent;
+-- Below queries will error out as no SELECT permission for user on child
+-- relations
+explain (costs off) select * from child1;
+explain (costs off) select * from child2;
+reset session authorization;
+grant select on child1 to new_user;
+set session authorization new_user;
+-- After granting SELECT permission the below query will work
+explain (costs off) select * from child1;
+reset session authorization;
+drop policy p1 on parent;
+drop table parent cascade;
+
+
+--------------------------------------------------------------------------------
+----- INSERT queries on relation having row level security enabled -------------
+------ ORCA will fallback to planner for INSERT with RLS anabled ---------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant insert on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=3);
+set session authorization new_user;
+explain (costs off) insert into foo_rls values (1,1,1);
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+
+--------------------------------------------------------------------------------
+--------- INSERT queries on partitioned relation having RLS enabled ------------
+--------- ORCA will fallback to planner for INSERT with RLS anabled ------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant insert on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=500);
+set session authorization new_user;
+explain (costs off) insert into foo_part_rls values (-10,-10,-10);
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+
+--------------------------------------------------------------------------------
+----- UPDATE queries on relation having row level security enabled -------------
+------ ORCA will fallback to planner for UPDATE with RLS anabled ---------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant select,update on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=3);
+set session authorization new_user;
+explain (costs off) update foo_rls set a=-10 where c=4;
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+
+--------------------------------------------------------------------------------
+--------- UPDATE queries on partitioned relation having RLS enabled ------------
+--------- ORCA will fallback to planner for UPDATE with RLS anabled ------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant select,update on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=500);
+set session authorization new_user;
+explain (costs off) update foo_part_rls set a=10 where foo_part_rls.c = 800;
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+
+--------------------------------------------------------------------------------
+----- DELETE queries on relation having row level security enabled -------------
+--------------------------------------------------------------------------------
+create table foo_rls ( a int, b int, c int) distributed by (a);
+insert into foo_rls select i,i*10,i*100 from generate_series(1,5)i;
+analyze foo_rls;
+grant select,delete on foo_rls to new_user;
+alter table foo_rls enable row level security;
+create policy p1 on foo_rls using (c>=300);
+set session authorization new_user;
+explain (costs off) delete from foo_rls where foo_rls.b=30;
+reset session authorization;
+drop policy p1 on foo_rls;
+drop table foo_rls cascade;
+
+--------------------------------------------------------------------------------
+----- DELETE queries on on partitioned relation having RLS enabled -------------
+--------------------------------------------------------------------------------
+create table foo_part_rls ( a int, b int, c int) distributed by (a)
+partition by range(b) (start(0) end(100) every(20));
+insert into foo_part_rls select i,i*10,i*100 from generate_series(1,9)i;
+analyze foo_part_rls;
+grant select,delete on foo_part_rls to new_user;
+alter table foo_part_rls enable row level security;
+create policy p1 on foo_part_rls using (c>=300);
+set session authorization new_user;
+explain (costs off) delete from foo_part_rls where foo_part_rls.b=30;
+reset session authorization;
+drop policy p1 on foo_part_rls;
+drop table foo_part_rls cascade;
+drop user new_user;
+reset optimizer_trace_fallback;
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 741a4bd5c5..ecfddbb819 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -8,6 +8,7 @@
SET client_min_messages TO 'warning';
SET gp_enable_relsize_collection to on;
+set optimizer_trace_fallback to on;
DROP USER IF EXISTS regress_rls_alice;
DROP USER IF EXISTS regress_rls_bob;
DROP USER IF EXISTS regress_rls_carol;
@@ -1917,3 +1918,4 @@ CREATE POLICY p1 ON rls_tbl_force USING (c1 = 5) WITH CHECK (c1 < 5);
CREATE POLICY p2 ON rls_tbl_force FOR SELECT USING (c1 = 8);
CREATE POLICY p3 ON rls_tbl_force FOR UPDATE USING (c1 = 8) WITH CHECK (c1 >= 5);
CREATE POLICY p4 ON rls_tbl_force FOR DELETE USING (c1 = 8);
+reset optimizer_trace_fallback;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org