mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
Rename RowCompareType to CompareType
RowCompareType served as a way to describe the fundamental meaning of an operator, notionally independent of an operator class (although so far this was only really supported for btrees). Its original purpose was for use inside RowCompareExpr, and it has also found some small use outside, such as for get_op_btree_interpretation(). We want to expand this now, as a more general way to describe operator semantics for other index access methods, including gist (to improve GistTranslateStratnum()) and others not written yet. To avoid future confusion, we rename the type to CompareType and the symbols from ROWCOMPARE_XXX to COMPARE_XXX to reflect their more general purpose. Reviewed-by: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
This commit is contained in:
@ -2102,7 +2102,7 @@ ExecInitExprRec(Expr *node, ExprState *state,
|
|||||||
|
|
||||||
/* Finally, examine the last comparison result */
|
/* Finally, examine the last comparison result */
|
||||||
scratch.opcode = EEOP_ROWCOMPARE_FINAL;
|
scratch.opcode = EEOP_ROWCOMPARE_FINAL;
|
||||||
scratch.d.rowcompare_final.rctype = rcexpr->rctype;
|
scratch.d.rowcompare_final.cmptype = rcexpr->cmptype;
|
||||||
ExprEvalPushStep(state, &scratch);
|
ExprEvalPushStep(state, &scratch);
|
||||||
|
|
||||||
/* adjust jump targets */
|
/* adjust jump targets */
|
||||||
|
@ -1500,22 +1500,22 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
|
|||||||
EEO_CASE(EEOP_ROWCOMPARE_FINAL)
|
EEO_CASE(EEOP_ROWCOMPARE_FINAL)
|
||||||
{
|
{
|
||||||
int32 cmpresult = DatumGetInt32(*op->resvalue);
|
int32 cmpresult = DatumGetInt32(*op->resvalue);
|
||||||
RowCompareType rctype = op->d.rowcompare_final.rctype;
|
CompareType cmptype = op->d.rowcompare_final.cmptype;
|
||||||
|
|
||||||
*op->resnull = false;
|
*op->resnull = false;
|
||||||
switch (rctype)
|
switch (cmptype)
|
||||||
{
|
{
|
||||||
/* EQ and NE cases aren't allowed here */
|
/* EQ and NE cases aren't allowed here */
|
||||||
case ROWCOMPARE_LT:
|
case COMPARE_LT:
|
||||||
*op->resvalue = BoolGetDatum(cmpresult < 0);
|
*op->resvalue = BoolGetDatum(cmpresult < 0);
|
||||||
break;
|
break;
|
||||||
case ROWCOMPARE_LE:
|
case COMPARE_LE:
|
||||||
*op->resvalue = BoolGetDatum(cmpresult <= 0);
|
*op->resvalue = BoolGetDatum(cmpresult <= 0);
|
||||||
break;
|
break;
|
||||||
case ROWCOMPARE_GE:
|
case COMPARE_GE:
|
||||||
*op->resvalue = BoolGetDatum(cmpresult >= 0);
|
*op->resvalue = BoolGetDatum(cmpresult >= 0);
|
||||||
break;
|
break;
|
||||||
case ROWCOMPARE_GT:
|
case COMPARE_GT:
|
||||||
*op->resvalue = BoolGetDatum(cmpresult > 0);
|
*op->resvalue = BoolGetDatum(cmpresult > 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1344,7 +1344,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
|
|||||||
&op_lefttype,
|
&op_lefttype,
|
||||||
&op_righttype);
|
&op_righttype);
|
||||||
|
|
||||||
if (op_strategy != rc->rctype)
|
if (op_strategy != rc->cmptype)
|
||||||
elog(ERROR, "RowCompare index qualification contains wrong operator");
|
elog(ERROR, "RowCompare index qualification contains wrong operator");
|
||||||
|
|
||||||
opfuncid = get_opfamily_proc(opfamily,
|
opfuncid = get_opfamily_proc(opfamily,
|
||||||
@ -1421,7 +1421,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
|
|||||||
MemSet(this_scan_key, 0, sizeof(ScanKeyData));
|
MemSet(this_scan_key, 0, sizeof(ScanKeyData));
|
||||||
this_scan_key->sk_flags = SK_ROW_HEADER;
|
this_scan_key->sk_flags = SK_ROW_HEADER;
|
||||||
this_scan_key->sk_attno = first_sub_key->sk_attno;
|
this_scan_key->sk_attno = first_sub_key->sk_attno;
|
||||||
this_scan_key->sk_strategy = rc->rctype;
|
this_scan_key->sk_strategy = rc->cmptype;
|
||||||
/* sk_subtype, sk_collation, sk_func not used in a header */
|
/* sk_subtype, sk_collation, sk_func not used in a header */
|
||||||
this_scan_key->sk_argument = PointerGetDatum(first_sub_key);
|
this_scan_key->sk_argument = PointerGetDatum(first_sub_key);
|
||||||
}
|
}
|
||||||
|
@ -1770,7 +1770,7 @@ llvm_compile_expr(ExprState *state)
|
|||||||
|
|
||||||
case EEOP_ROWCOMPARE_FINAL:
|
case EEOP_ROWCOMPARE_FINAL:
|
||||||
{
|
{
|
||||||
RowCompareType rctype = op->d.rowcompare_final.rctype;
|
CompareType cmptype = op->d.rowcompare_final.cmptype;
|
||||||
|
|
||||||
LLVMValueRef v_cmpresult;
|
LLVMValueRef v_cmpresult;
|
||||||
LLVMValueRef v_result;
|
LLVMValueRef v_result;
|
||||||
@ -1786,18 +1786,18 @@ llvm_compile_expr(ExprState *state)
|
|||||||
l_load(b, TypeSizeT, v_resvaluep, ""),
|
l_load(b, TypeSizeT, v_resvaluep, ""),
|
||||||
LLVMInt32TypeInContext(lc), "");
|
LLVMInt32TypeInContext(lc), "");
|
||||||
|
|
||||||
switch (rctype)
|
switch (cmptype)
|
||||||
{
|
{
|
||||||
case ROWCOMPARE_LT:
|
case COMPARE_LT:
|
||||||
predicate = LLVMIntSLT;
|
predicate = LLVMIntSLT;
|
||||||
break;
|
break;
|
||||||
case ROWCOMPARE_LE:
|
case COMPARE_LE:
|
||||||
predicate = LLVMIntSLE;
|
predicate = LLVMIntSLE;
|
||||||
break;
|
break;
|
||||||
case ROWCOMPARE_GT:
|
case COMPARE_GT:
|
||||||
predicate = LLVMIntSGT;
|
predicate = LLVMIntSGT;
|
||||||
break;
|
break;
|
||||||
case ROWCOMPARE_GE:
|
case COMPARE_GE:
|
||||||
predicate = LLVMIntSGE;
|
predicate = LLVMIntSGE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -3675,7 +3675,7 @@ expand_indexqual_rowcompare(PlannerInfo *root,
|
|||||||
{
|
{
|
||||||
RowCompareExpr *rc = makeNode(RowCompareExpr);
|
RowCompareExpr *rc = makeNode(RowCompareExpr);
|
||||||
|
|
||||||
rc->rctype = (RowCompareType) op_strategy;
|
rc->cmptype = (CompareType) op_strategy;
|
||||||
rc->opnos = new_ops;
|
rc->opnos = new_ops;
|
||||||
rc->opfamilies = list_copy_head(clause->opfamilies,
|
rc->opfamilies = list_copy_head(clause->opfamilies,
|
||||||
matching_cols);
|
matching_cols);
|
||||||
|
@ -1664,7 +1664,7 @@ clause_is_strict_for(Node *clause, Node *subexpr, bool allow_false)
|
|||||||
#define BTEQ BTEqualStrategyNumber
|
#define BTEQ BTEqualStrategyNumber
|
||||||
#define BTGE BTGreaterEqualStrategyNumber
|
#define BTGE BTGreaterEqualStrategyNumber
|
||||||
#define BTGT BTGreaterStrategyNumber
|
#define BTGT BTGreaterStrategyNumber
|
||||||
#define BTNE ROWCOMPARE_NE
|
#define BTNE COMPARE_NE
|
||||||
|
|
||||||
/* We use "none" for 0/false to make the tables align nicely */
|
/* We use "none" for 0/false to make the tables align nicely */
|
||||||
#define none 0
|
#define none 0
|
||||||
|
@ -2807,7 +2807,7 @@ make_row_comparison_op(ParseState *pstate, List *opname,
|
|||||||
List *largs, List *rargs, int location)
|
List *largs, List *rargs, int location)
|
||||||
{
|
{
|
||||||
RowCompareExpr *rcexpr;
|
RowCompareExpr *rcexpr;
|
||||||
RowCompareType rctype;
|
CompareType cmptype;
|
||||||
List *opexprs;
|
List *opexprs;
|
||||||
List *opnos;
|
List *opnos;
|
||||||
List *opfamilies;
|
List *opfamilies;
|
||||||
@ -2928,15 +2928,15 @@ make_row_comparison_op(ParseState *pstate, List *opname,
|
|||||||
errhint("Row comparison operators must be associated with btree operator families."),
|
errhint("Row comparison operators must be associated with btree operator families."),
|
||||||
parser_errposition(pstate, location)));
|
parser_errposition(pstate, location)));
|
||||||
}
|
}
|
||||||
rctype = (RowCompareType) i;
|
cmptype = (CompareType) i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For = and <> cases, we just combine the pairwise operators with AND or
|
* For = and <> cases, we just combine the pairwise operators with AND or
|
||||||
* OR respectively.
|
* OR respectively.
|
||||||
*/
|
*/
|
||||||
if (rctype == ROWCOMPARE_EQ)
|
if (cmptype == COMPARE_EQ)
|
||||||
return (Node *) makeBoolExpr(AND_EXPR, opexprs, location);
|
return (Node *) makeBoolExpr(AND_EXPR, opexprs, location);
|
||||||
if (rctype == ROWCOMPARE_NE)
|
if (cmptype == COMPARE_NE)
|
||||||
return (Node *) makeBoolExpr(OR_EXPR, opexprs, location);
|
return (Node *) makeBoolExpr(OR_EXPR, opexprs, location);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2953,7 +2953,7 @@ make_row_comparison_op(ParseState *pstate, List *opname,
|
|||||||
{
|
{
|
||||||
OpBtreeInterpretation *opinfo = lfirst(j);
|
OpBtreeInterpretation *opinfo = lfirst(j);
|
||||||
|
|
||||||
if (opinfo->strategy == rctype)
|
if (opinfo->strategy == cmptype)
|
||||||
{
|
{
|
||||||
opfamily = opinfo->opfamily_id;
|
opfamily = opinfo->opfamily_id;
|
||||||
break;
|
break;
|
||||||
@ -2989,7 +2989,7 @@ make_row_comparison_op(ParseState *pstate, List *opname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rcexpr = makeNode(RowCompareExpr);
|
rcexpr = makeNode(RowCompareExpr);
|
||||||
rcexpr->rctype = rctype;
|
rcexpr->cmptype = cmptype;
|
||||||
rcexpr->opnos = opnos;
|
rcexpr->opnos = opnos;
|
||||||
rcexpr->opfamilies = opfamilies;
|
rcexpr->opfamilies = opfamilies;
|
||||||
rcexpr->inputcollids = NIL; /* assign_expr_collations will fix this */
|
rcexpr->inputcollids = NIL; /* assign_expr_collations will fix this */
|
||||||
|
6
src/backend/utils/cache/lsyscache.c
vendored
6
src/backend/utils/cache/lsyscache.c
vendored
@ -595,7 +595,7 @@ get_op_hash_functions(Oid opno,
|
|||||||
*
|
*
|
||||||
* In addition to the normal btree operators, we consider a <> operator to be
|
* In addition to the normal btree operators, we consider a <> operator to be
|
||||||
* a "member" of an opfamily if its negator is an equality operator of the
|
* a "member" of an opfamily if its negator is an equality operator of the
|
||||||
* opfamily. ROWCOMPARE_NE is returned as the strategy number for this case.
|
* opfamily. COMPARE_NE is returned as the strategy number for this case.
|
||||||
*/
|
*/
|
||||||
List *
|
List *
|
||||||
get_op_btree_interpretation(Oid opno)
|
get_op_btree_interpretation(Oid opno)
|
||||||
@ -666,11 +666,11 @@ get_op_btree_interpretation(Oid opno)
|
|||||||
if (op_strategy != BTEqualStrategyNumber)
|
if (op_strategy != BTEqualStrategyNumber)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* OK, report it with "strategy" ROWCOMPARE_NE */
|
/* OK, report it with "strategy" COMPARE_NE */
|
||||||
thisresult = (OpBtreeInterpretation *)
|
thisresult = (OpBtreeInterpretation *)
|
||||||
palloc(sizeof(OpBtreeInterpretation));
|
palloc(sizeof(OpBtreeInterpretation));
|
||||||
thisresult->opfamily_id = op_form->amopfamily;
|
thisresult->opfamily_id = op_form->amopfamily;
|
||||||
thisresult->strategy = ROWCOMPARE_NE;
|
thisresult->strategy = COMPARE_NE;
|
||||||
thisresult->oplefttype = op_form->amoplefttype;
|
thisresult->oplefttype = op_form->amoplefttype;
|
||||||
thisresult->oprighttype = op_form->amoprighttype;
|
thisresult->oprighttype = op_form->amoprighttype;
|
||||||
result = lappend(result, thisresult);
|
result = lappend(result, thisresult);
|
||||||
|
@ -494,7 +494,7 @@ typedef struct ExprEvalStep
|
|||||||
/* for EEOP_ROWCOMPARE_FINAL */
|
/* for EEOP_ROWCOMPARE_FINAL */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
RowCompareType rctype;
|
CompareType cmptype;
|
||||||
} rowcompare_final;
|
} rowcompare_final;
|
||||||
|
|
||||||
/* for EEOP_MINMAX */
|
/* for EEOP_MINMAX */
|
||||||
|
@ -1435,6 +1435,31 @@ typedef struct RowExpr
|
|||||||
ParseLoc location; /* token location, or -1 if unknown */
|
ParseLoc location; /* token location, or -1 if unknown */
|
||||||
} RowExpr;
|
} RowExpr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CompareType - fundamental semantics of certain operators
|
||||||
|
*
|
||||||
|
* These enum symbols represent the fundamental semantics of certain operators
|
||||||
|
* that the system needs to have some hardcoded knowledge about. (For
|
||||||
|
* example, RowCompareExpr needs to know which operators can be determined to
|
||||||
|
* act like =, <>, <, etc.) Index access methods map (some of) strategy
|
||||||
|
* numbers to these values so that the system can know about the meaning of
|
||||||
|
* (some of) the operators without needing hardcoded knowledge of index AM's
|
||||||
|
* strategy numbering.
|
||||||
|
*
|
||||||
|
* XXX Currently, this mapping is not fully developed and the values are
|
||||||
|
* chosen to match btree strategy numbers, which is not going to work very
|
||||||
|
* well for other access methods.
|
||||||
|
*/
|
||||||
|
typedef enum CompareType
|
||||||
|
{
|
||||||
|
COMPARE_LT = 1, /* BTLessStrategyNumber */
|
||||||
|
COMPARE_LE = 2, /* BTLessEqualStrategyNumber */
|
||||||
|
COMPARE_EQ = 3, /* BTEqualStrategyNumber */
|
||||||
|
COMPARE_GE = 4, /* BTGreaterEqualStrategyNumber */
|
||||||
|
COMPARE_GT = 5, /* BTGreaterStrategyNumber */
|
||||||
|
COMPARE_NE = 6, /* no such btree strategy */
|
||||||
|
} CompareType;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RowCompareExpr - row-wise comparison, such as (a, b) <= (1, 2)
|
* RowCompareExpr - row-wise comparison, such as (a, b) <= (1, 2)
|
||||||
*
|
*
|
||||||
@ -1446,26 +1471,14 @@ typedef struct RowExpr
|
|||||||
*
|
*
|
||||||
* A RowCompareExpr node is only generated for the < <= > >= cases;
|
* A RowCompareExpr node is only generated for the < <= > >= cases;
|
||||||
* the = and <> cases are translated to simple AND or OR combinations
|
* the = and <> cases are translated to simple AND or OR combinations
|
||||||
* of the pairwise comparisons. However, we include = and <> in the
|
* of the pairwise comparisons.
|
||||||
* RowCompareType enum for the convenience of parser logic.
|
|
||||||
*/
|
*/
|
||||||
typedef enum RowCompareType
|
|
||||||
{
|
|
||||||
/* Values of this enum are chosen to match btree strategy numbers */
|
|
||||||
ROWCOMPARE_LT = 1, /* BTLessStrategyNumber */
|
|
||||||
ROWCOMPARE_LE = 2, /* BTLessEqualStrategyNumber */
|
|
||||||
ROWCOMPARE_EQ = 3, /* BTEqualStrategyNumber */
|
|
||||||
ROWCOMPARE_GE = 4, /* BTGreaterEqualStrategyNumber */
|
|
||||||
ROWCOMPARE_GT = 5, /* BTGreaterStrategyNumber */
|
|
||||||
ROWCOMPARE_NE = 6, /* no such btree strategy */
|
|
||||||
} RowCompareType;
|
|
||||||
|
|
||||||
typedef struct RowCompareExpr
|
typedef struct RowCompareExpr
|
||||||
{
|
{
|
||||||
Expr xpr;
|
Expr xpr;
|
||||||
|
|
||||||
/* LT LE GE or GT, never EQ or NE */
|
/* LT LE GE or GT, never EQ or NE */
|
||||||
RowCompareType rctype;
|
CompareType cmptype;
|
||||||
/* OID list of pairwise comparison ops */
|
/* OID list of pairwise comparison ops */
|
||||||
List *opnos pg_node_attr(query_jumble_ignore);
|
List *opnos pg_node_attr(query_jumble_ignore);
|
||||||
/* OID list of containing operator families */
|
/* OID list of containing operator families */
|
||||||
|
@ -458,6 +458,7 @@ CommonEntry
|
|||||||
CommonTableExpr
|
CommonTableExpr
|
||||||
CompactAttribute
|
CompactAttribute
|
||||||
CompareScalarsContext
|
CompareScalarsContext
|
||||||
|
CompareType
|
||||||
CompiledExprState
|
CompiledExprState
|
||||||
CompositeIOData
|
CompositeIOData
|
||||||
CompositeTypeStmt
|
CompositeTypeStmt
|
||||||
@ -2494,7 +2495,6 @@ RoleSpecType
|
|||||||
RoleStmtType
|
RoleStmtType
|
||||||
RollupData
|
RollupData
|
||||||
RowCompareExpr
|
RowCompareExpr
|
||||||
RowCompareType
|
|
||||||
RowExpr
|
RowExpr
|
||||||
RowIdentityVarInfo
|
RowIdentityVarInfo
|
||||||
RowMarkClause
|
RowMarkClause
|
||||||
|
Reference in New Issue
Block a user