Be more consistent about errors for opfamily member lookup failures.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Jul 2017 15:23:27 +0000 (11:23 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Jul 2017 15:23:27 +0000 (11:23 -0400)
Add error checks in some places that were calling get_opfamily_member
or get_opfamily_proc and just assuming that the call could never fail.
Also, standardize the wording for such errors in some other places.

None of these errors are expected in normal use, hence they're just
elog not ereport.  But they may be handy for diagnosing omissions in
custom opclasses.

Rushabh Lathia found the oversight in RelationBuildPartitionKey();
I found the others by grepping for all callers of these functions.

Discussion: https://postgr.es/m/CAGPqQf2R9Nk8htpv0FFi+FP776EwMyGuORpc9zYkZKC8sFQE3g@mail.gmail.com

src/backend/catalog/index.c
src/backend/catalog/partition.c
src/backend/executor/execExpr.c
src/backend/executor/execReplication.c
src/backend/executor/nodeIndexscan.c
src/backend/optimizer/path/indxpath.c
src/backend/optimizer/path/pathkeys.c
src/backend/optimizer/plan/createplan.c
src/backend/utils/cache/relcache.c

index 027abd56b0d1814a99fd65eb640f1457bba39371..d25b39bb54eb964f983d65bff36d0c84b2be1069 100644 (file)
@@ -1738,6 +1738,10 @@ BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
                                index->rd_opcintype[i],
                                index->rd_opcintype[i],
                                ii->ii_UniqueStrats[i]);
+       if (!OidIsValid(ii->ii_UniqueOps[i]))
+           elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
+                ii->ii_UniqueStrats[i], index->rd_opcintype[i],
+                index->rd_opcintype[i], index->rd_opfamily[i]);
        ii->ii_UniqueProcs[i] = get_opcode(ii->ii_UniqueOps[i]);
    }
 }
index 74736e0ea10ebbfa378ee5a332b03ebc1183f129..e20ddce2db513b3364809ebc9fc9d5fa265bc14c 100644 (file)
@@ -1187,14 +1187,15 @@ get_partition_operator(PartitionKey key, int col, StrategyNumber strategy,
                                      key->partopcintype[col],
                                      key->partopcintype[col],
                                      strategy);
+       if (!OidIsValid(operoid))
+           elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
+                strategy, key->partopcintype[col], key->partopcintype[col],
+                key->partopfamily[col]);
        *need_relabel = true;
    }
    else
        *need_relabel = false;
 
-   if (!OidIsValid(operoid))
-       elog(ERROR, "could not find operator for partitioning");
-
    return operoid;
 }
 
index 5267a011bbbb17b87fe9df6ce4c63f1fc3e4f973..7496189fabf25f60a6e3fd98937ef9dd70a95c09 100644 (file)
@@ -1640,6 +1640,9 @@ ExecInitExprRec(Expr *node, PlanState *parent, ExprState *state,
                                             lefttype,
                                             righttype,
                                             BTORDER_PROC);
+                   if (!OidIsValid(proc))
+                       elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
+                            BTORDER_PROC, lefttype, righttype, opfamily);
 
                    /* Set up the primary fmgr lookup information */
                    finfo = palloc0(sizeof(FmgrInfo));
index bc53d07c7db09dcedf3796d42aebb8b292275163..3819de28ad9f1b98eaffba84552b8c28e7bcdaea 100644 (file)
@@ -81,9 +81,8 @@ build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel,
        operator = get_opfamily_member(opfamily, optype,
                                       optype,
                                       BTEqualStrategyNumber);
-
        if (!OidIsValid(operator))
-           elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
+           elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
                 BTEqualStrategyNumber, optype, optype, opfamily);
 
        regop = get_opcode(operator);
index d8aceb1f2c873964b6ebac36f8b5c78c72305a5c..75b10115f5281c25b3e37537e9c4dec54a1b8fbd 100644 (file)
@@ -1367,6 +1367,9 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
                                             op_lefttype,
                                             op_righttype,
                                             BTORDER_PROC);
+               if (!RegProcedureIsValid(opfuncid))
+                   elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
+                        BTORDER_PROC, op_lefttype, op_righttype, opfamily);
 
                inputcollation = lfirst_oid(collids_cell);
                collids_cell = lnext(collids_cell);
index dedb9f521da2f73661b2861bf859d2eee809c0ea..f35380391ad24420f69843a3e07ab59ed353da8f 100644 (file)
@@ -3978,13 +3978,13 @@ adjust_rowcompare_for_index(RowCompareExpr *clause,
            expr_op = get_opfamily_member(opfam, lefttype, righttype,
                                          op_strategy);
            if (!OidIsValid(expr_op))   /* should not happen */
-               elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
+               elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
                     op_strategy, lefttype, righttype, opfam);
            if (!var_on_left)
            {
                expr_op = get_commutator(expr_op);
                if (!OidIsValid(expr_op))   /* should not happen */
-                   elog(ERROR, "could not find commutator of member %d(%u,%u) of opfamily %u",
+                   elog(ERROR, "could not find commutator of operator %d(%u,%u) of opfamily %u",
                         op_strategy, lefttype, righttype, opfam);
            }
            new_ops = lappend_oid(new_ops, expr_op);
index 37cfa098d49d554e6517943bd84c3a78a33b1374..9d83a5ca62b2f6a04ea957064ab1cded66f48634 100644 (file)
@@ -197,8 +197,8 @@ make_pathkey_from_sortinfo(PlannerInfo *root,
                                      opcintype,
                                      BTEqualStrategyNumber);
    if (!OidIsValid(equality_op))   /* shouldn't happen */
-       elog(ERROR, "could not find equality operator for opfamily %u",
-            opfamily);
+       elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
+            BTEqualStrategyNumber, opcintype, opcintype, opfamily);
    opfamilies = get_mergejoin_opfamilies(equality_op);
    if (!opfamilies)            /* certainly should find some */
        elog(ERROR, "could not find opfamilies for equality operator %u",
index e589d92c80553acd99aa13f0b2c3f6f86211ba42..9d838e4f39a2b1a219f5d5cd7c6bc3ead90eb44d 100644 (file)
@@ -2634,7 +2634,8 @@ create_indexscan_plan(PlannerInfo *root,
                                         exprtype,
                                         pathkey->pk_strategy);
            if (!OidIsValid(sortop))
-               elog(ERROR, "failed to find sort operator for ORDER BY expression");
+               elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
+                    pathkey->pk_strategy, exprtype, exprtype, pathkey->pk_opfamily);
            indexorderbyops = lappend_oid(indexorderbyops, sortop);
        }
    }
@@ -5738,7 +5739,7 @@ prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys,
                                     pk_datatype,
                                     pathkey->pk_strategy);
        if (!OidIsValid(sortop))    /* should not happen */
-           elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
+           elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
                 pathkey->pk_strategy, pk_datatype, pk_datatype,
                 pathkey->pk_opfamily);
 
@@ -6216,7 +6217,7 @@ make_unique_from_pathkeys(Plan *lefttree, List *pathkeys, int numCols)
                                   pk_datatype,
                                   BTEqualStrategyNumber);
        if (!OidIsValid(eqop))  /* should not happen */
-           elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
+           elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
                 BTEqualStrategyNumber, pk_datatype, pk_datatype,
                 pathkey->pk_opfamily);
 
index 43238dd8cbd0d4e61f683972843a1011a6ca2fb7..6bd93b03d080162fbe6116ef689fd797ab8bfdea 100644 (file)
@@ -945,6 +945,10 @@ RelationBuildPartitionKey(Relation relation)
                                   opclassform->opcintype,
                                   opclassform->opcintype,
                                   BTORDER_PROC);
+       if (!OidIsValid(funcid))    /* should not happen */
+           elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
+                BTORDER_PROC, opclassform->opcintype, opclassform->opcintype,
+                opclassform->opcfamily);
 
        fmgr_info(funcid, &key->partsupfunc[i]);