Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 278cb43

Browse files
committed
Be more consistent about errors for opfamily member lookup failures.
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
1 parent bbbd912 commit 278cb43

File tree

9 files changed

+27
-12
lines changed

9 files changed

+27
-12
lines changed

src/backend/catalog/index.c

+4
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,10 @@ BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
17381738
index->rd_opcintype[i],
17391739
index->rd_opcintype[i],
17401740
ii->ii_UniqueStrats[i]);
1741+
if (!OidIsValid(ii->ii_UniqueOps[i]))
1742+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
1743+
ii->ii_UniqueStrats[i], index->rd_opcintype[i],
1744+
index->rd_opcintype[i], index->rd_opfamily[i]);
17411745
ii->ii_UniqueProcs[i] = get_opcode(ii->ii_UniqueOps[i]);
17421746
}
17431747
}

src/backend/catalog/partition.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1187,14 +1187,15 @@ get_partition_operator(PartitionKey key, int col, StrategyNumber strategy,
11871187
key->partopcintype[col],
11881188
key->partopcintype[col],
11891189
strategy);
1190+
if (!OidIsValid(operoid))
1191+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
1192+
strategy, key->partopcintype[col], key->partopcintype[col],
1193+
key->partopfamily[col]);
11901194
*need_relabel = true;
11911195
}
11921196
else
11931197
*need_relabel = false;
11941198

1195-
if (!OidIsValid(operoid))
1196-
elog(ERROR, "could not find operator for partitioning");
1197-
11981199
return operoid;
11991200
}
12001201

src/backend/executor/execExpr.c

+3
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,9 @@ ExecInitExprRec(Expr *node, PlanState *parent, ExprState *state,
16401640
lefttype,
16411641
righttype,
16421642
BTORDER_PROC);
1643+
if (!OidIsValid(proc))
1644+
elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
1645+
BTORDER_PROC, lefttype, righttype, opfamily);
16431646

16441647
/* Set up the primary fmgr lookup information */
16451648
finfo = palloc0(sizeof(FmgrInfo));

src/backend/executor/execReplication.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel,
8181
operator = get_opfamily_member(opfamily, optype,
8282
optype,
8383
BTEqualStrategyNumber);
84-
8584
if (!OidIsValid(operator))
86-
elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
85+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
8786
BTEqualStrategyNumber, optype, optype, opfamily);
8887

8988
regop = get_opcode(operator);

src/backend/executor/nodeIndexscan.c

+3
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,9 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
13671367
op_lefttype,
13681368
op_righttype,
13691369
BTORDER_PROC);
1370+
if (!RegProcedureIsValid(opfuncid))
1371+
elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
1372+
BTORDER_PROC, op_lefttype, op_righttype, opfamily);
13701373

13711374
inputcollation = lfirst_oid(collids_cell);
13721375
collids_cell = lnext(collids_cell);

src/backend/optimizer/path/indxpath.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3978,13 +3978,13 @@ adjust_rowcompare_for_index(RowCompareExpr *clause,
39783978
expr_op = get_opfamily_member(opfam, lefttype, righttype,
39793979
op_strategy);
39803980
if (!OidIsValid(expr_op)) /* should not happen */
3981-
elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
3981+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
39823982
op_strategy, lefttype, righttype, opfam);
39833983
if (!var_on_left)
39843984
{
39853985
expr_op = get_commutator(expr_op);
39863986
if (!OidIsValid(expr_op)) /* should not happen */
3987-
elog(ERROR, "could not find commutator of member %d(%u,%u) of opfamily %u",
3987+
elog(ERROR, "could not find commutator of operator %d(%u,%u) of opfamily %u",
39883988
op_strategy, lefttype, righttype, opfam);
39893989
}
39903990
new_ops = lappend_oid(new_ops, expr_op);

src/backend/optimizer/path/pathkeys.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ make_pathkey_from_sortinfo(PlannerInfo *root,
197197
opcintype,
198198
BTEqualStrategyNumber);
199199
if (!OidIsValid(equality_op)) /* shouldn't happen */
200-
elog(ERROR, "could not find equality operator for opfamily %u",
201-
opfamily);
200+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
201+
BTEqualStrategyNumber, opcintype, opcintype, opfamily);
202202
opfamilies = get_mergejoin_opfamilies(equality_op);
203203
if (!opfamilies) /* certainly should find some */
204204
elog(ERROR, "could not find opfamilies for equality operator %u",

src/backend/optimizer/plan/createplan.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,8 @@ create_indexscan_plan(PlannerInfo *root,
26342634
exprtype,
26352635
pathkey->pk_strategy);
26362636
if (!OidIsValid(sortop))
2637-
elog(ERROR, "failed to find sort operator for ORDER BY expression");
2637+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
2638+
pathkey->pk_strategy, exprtype, exprtype, pathkey->pk_opfamily);
26382639
indexorderbyops = lappend_oid(indexorderbyops, sortop);
26392640
}
26402641
}
@@ -5738,7 +5739,7 @@ prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys,
57385739
pk_datatype,
57395740
pathkey->pk_strategy);
57405741
if (!OidIsValid(sortop)) /* should not happen */
5741-
elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
5742+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
57425743
pathkey->pk_strategy, pk_datatype, pk_datatype,
57435744
pathkey->pk_opfamily);
57445745

@@ -6216,7 +6217,7 @@ make_unique_from_pathkeys(Plan *lefttree, List *pathkeys, int numCols)
62166217
pk_datatype,
62176218
BTEqualStrategyNumber);
62186219
if (!OidIsValid(eqop)) /* should not happen */
6219-
elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
6220+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
62206221
BTEqualStrategyNumber, pk_datatype, pk_datatype,
62216222
pathkey->pk_opfamily);
62226223

src/backend/utils/cache/relcache.c

+4
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,10 @@ RelationBuildPartitionKey(Relation relation)
945945
opclassform->opcintype,
946946
opclassform->opcintype,
947947
BTORDER_PROC);
948+
if (!OidIsValid(funcid)) /* should not happen */
949+
elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
950+
BTORDER_PROC, opclassform->opcintype, opclassform->opcintype,
951+
opclassform->opcfamily);
948952

949953
fmgr_info(funcid, &key->partsupfunc[i]);
950954

0 commit comments

Comments
 (0)