aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/optimizer/plan/planner.c12
-rw-r--r--src/backend/utils/cache/lsyscache.c68
2 files changed, 78 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 5da863d85de..88cb97f445f 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -5911,10 +5911,18 @@ plan_create_index_workers(Oid tableOid, Oid indexOid)
* Currently, parallel workers can't access the leader's temporary tables.
* Furthermore, any index predicate or index expressions must be parallel
* safe.
+ *
+ * Fetch the list of expressions and predicates directly from the
+ * catalogs. Retrieving this information from the relcache would cause
+ * the expressions and predicates to be flattened, losing properties that
+ * can be important to check if parallel workers can be used. For
+ * example, immutable parallel-unsafe functions, that cannot be used in
+ * parallel workers, would be changed to Const nodes, that are safe in
+ * parallel workers.
*/
if (heap->rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
- !is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index)) ||
- !is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index)))
+ !is_parallel_safe(root, (Node *) get_index_expressions(indexOid)) ||
+ !is_parallel_safe(root, (Node *) get_index_predicate(indexOid)))
{
parallel_workers = 0;
goto done;
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 5564b53f257..3c232aa960f 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -3511,6 +3511,74 @@ get_index_column_opclass(Oid index_oid, int attno)
}
/*
+ * get_index_expressions
+ *
+ * Given the index OID, its a List of its expressions or NIL if none.
+ */
+List *
+get_index_expressions(Oid index_oid)
+{
+ List *result;
+ HeapTuple tuple;
+ Datum exprDatum;
+ bool isnull;
+ char *exprString;
+
+ tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid));
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "cache lookup failed for index %u", index_oid);
+
+ exprDatum = SysCacheGetAttr(INDEXRELID, tuple,
+ Anum_pg_index_indexprs, &isnull);
+ if (isnull)
+ {
+ ReleaseSysCache(tuple);
+ return NIL;
+ }
+
+ exprString = TextDatumGetCString(exprDatum);
+ result = (List *) stringToNode(exprString);
+ pfree(exprString);
+ ReleaseSysCache(tuple);
+
+ return result;
+}
+
+/*
+ * get_index_predicate
+ *
+ * Given the index OID, return a List of its predicate or NIL if none.
+ */
+List *
+get_index_predicate(Oid index_oid)
+{
+ List *result;
+ HeapTuple tuple;
+ Datum predDatum;
+ bool isnull;
+ char *predString;
+
+ tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid));
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "cache lookup failed for index %u", index_oid);
+
+ predDatum = SysCacheGetAttr(INDEXRELID, tuple,
+ Anum_pg_index_indpred, &isnull);
+ if (isnull)
+ {
+ ReleaseSysCache(tuple);
+ return NIL;
+ }
+
+ predString = TextDatumGetCString(predDatum);
+ result = (List *) stringToNode(predString);
+ pfree(predString);
+ ReleaseSysCache(tuple);
+
+ return result;
+}
+
+/*
* get_index_isreplident
*
* Given the index OID, return pg_index.indisreplident.