PostgreSQL Source Code  git master
equalfuncs.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "utils/datum.h"
#include "equalfuncs.funcs.c"
#include "equalfuncs.switch.c"
Include dependency graph for equalfuncs.c:

Go to the source code of this file.

Macros

#define COMPARE_SCALAR_FIELD(fldname)
 
#define COMPARE_NODE_FIELD(fldname)
 
#define COMPARE_BITMAPSET_FIELD(fldname)
 
#define COMPARE_STRING_FIELD(fldname)
 
#define equalstr(a, b)    (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
 
#define COMPARE_ARRAY_FIELD(fldname)
 
#define COMPARE_POINTER_FIELD(fldname, sz)
 
#define COMPARE_LOCATION_FIELD(fldname)    ((void) 0)
 
#define COMPARE_COERCIONFORM_FIELD(fldname)    ((void) 0)
 

Functions

static bool _equalConst (const Const *a, const Const *b)
 
static bool _equalExtensibleNode (const ExtensibleNode *a, const ExtensibleNode *b)
 
static bool _equalA_Const (const A_Const *a, const A_Const *b)
 
static bool _equalBitmapset (const Bitmapset *a, const Bitmapset *b)
 
static bool _equalList (const List *a, const List *b)
 
bool equal (const void *a, const void *b)
 

Macro Definition Documentation

◆ COMPARE_ARRAY_FIELD

#define COMPARE_ARRAY_FIELD (   fldname)
Value:
do { \
if (memcmp(a->fldname, b->fldname, sizeof(a->fldname)) != 0) \
return false; \
} while (0)
int b
Definition: isn.c:70
int a
Definition: isn.c:69

Definition at line 66 of file equalfuncs.c.

◆ COMPARE_BITMAPSET_FIELD

#define COMPARE_BITMAPSET_FIELD (   fldname)
Value:
do { \
if (!bms_equal(a->fldname, b->fldname)) \
return false; \
} while (0)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

Definition at line 48 of file equalfuncs.c.

◆ COMPARE_COERCIONFORM_FIELD

#define COMPARE_COERCIONFORM_FIELD (   fldname)     ((void) 0)

Definition at line 84 of file equalfuncs.c.

◆ COMPARE_LOCATION_FIELD

#define COMPARE_LOCATION_FIELD (   fldname)     ((void) 0)

Definition at line 80 of file equalfuncs.c.

◆ COMPARE_NODE_FIELD

#define COMPARE_NODE_FIELD (   fldname)
Value:
do { \
if (!equal(a->fldname, b->fldname)) \
return false; \
} while (0)
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:225

Definition at line 41 of file equalfuncs.c.

◆ COMPARE_POINTER_FIELD

#define COMPARE_POINTER_FIELD (   fldname,
  sz 
)
Value:
do { \
if (memcmp(a->fldname, b->fldname, (sz)) != 0) \
return false; \
} while (0)

Definition at line 73 of file equalfuncs.c.

◆ COMPARE_SCALAR_FIELD

#define COMPARE_SCALAR_FIELD (   fldname)
Value:
do { \
if (a->fldname != b->fldname) \
return false; \
} while (0)

Definition at line 34 of file equalfuncs.c.

◆ COMPARE_STRING_FIELD

#define COMPARE_STRING_FIELD (   fldname)
Value:
do { \
if (!equalstr(a->fldname, b->fldname)) \
return false; \
} while (0)
#define equalstr(a, b)
Definition: equalfuncs.c:62

Definition at line 55 of file equalfuncs.c.

◆ equalstr

#define equalstr (   a,
  b 
)     (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))

Definition at line 62 of file equalfuncs.c.

Function Documentation

◆ _equalA_Const()

static bool _equalA_Const ( const A_Const a,
const A_Const b 
)
static

Definition at line 134 of file equalfuncs.c.

135 {
136  /*
137  * Hack for in-line val field. Also val is not valid is isnull is true.
138  */
139  if (!a->isnull && !b->isnull &&
140  !equal(&a->val, &b->val))
141  return false;
142  COMPARE_SCALAR_FIELD(isnull);
143  COMPARE_LOCATION_FIELD(location);
144 
145  return true;
146 }
#define COMPARE_LOCATION_FIELD(fldname)
Definition: equalfuncs.c:80
#define COMPARE_SCALAR_FIELD(fldname)
Definition: equalfuncs.c:34

References a, b, COMPARE_LOCATION_FIELD, COMPARE_SCALAR_FIELD, and equal().

◆ _equalBitmapset()

static bool _equalBitmapset ( const Bitmapset a,
const Bitmapset b 
)
static

Definition at line 149 of file equalfuncs.c.

150 {
151  return bms_equal(a, b);
152 }

References a, b, and bms_equal().

◆ _equalConst()

static bool _equalConst ( const Const a,
const Const b 
)
static

Definition at line 96 of file equalfuncs.c.

97 {
98  COMPARE_SCALAR_FIELD(consttype);
99  COMPARE_SCALAR_FIELD(consttypmod);
100  COMPARE_SCALAR_FIELD(constcollid);
101  COMPARE_SCALAR_FIELD(constlen);
102  COMPARE_SCALAR_FIELD(constisnull);
103  COMPARE_SCALAR_FIELD(constbyval);
104  COMPARE_LOCATION_FIELD(location);
105 
106  /*
107  * We treat all NULL constants of the same type as equal. Someday this
108  * might need to change? But datumIsEqual doesn't work on nulls, so...
109  */
110  if (a->constisnull)
111  return true;
112  return datumIsEqual(a->constvalue, b->constvalue,
113  a->constbyval, a->constlen);
114 }
bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
Definition: datum.c:223

References a, b, COMPARE_LOCATION_FIELD, COMPARE_SCALAR_FIELD, and datumIsEqual().

◆ _equalExtensibleNode()

static bool _equalExtensibleNode ( const ExtensibleNode a,
const ExtensibleNode b 
)
static

Definition at line 117 of file equalfuncs.c.

118 {
119  const ExtensibleNodeMethods *methods;
120 
121  COMPARE_STRING_FIELD(extnodename);
122 
123  /* At this point, we know extnodename is the same for both nodes. */
124  methods = GetExtensibleNodeMethods(a->extnodename, false);
125 
126  /* compare the private fields */
127  if (!methods->nodeEqual(a, b))
128  return false;
129 
130  return true;
131 }
#define COMPARE_STRING_FIELD(fldname)
Definition: equalfuncs.c:55
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
Definition: extensible.c:125
bool(* nodeEqual)(const struct ExtensibleNode *a, const struct ExtensibleNode *b)
Definition: extensible.h:68

References a, b, COMPARE_STRING_FIELD, GetExtensibleNodeMethods(), and ExtensibleNodeMethods::nodeEqual.

◆ _equalList()

static bool _equalList ( const List a,
const List b 
)
static

Definition at line 158 of file equalfuncs.c.

159 {
160  const ListCell *item_a;
161  const ListCell *item_b;
162 
163  /*
164  * Try to reject by simple scalar checks before grovelling through all the
165  * list elements...
166  */
168  COMPARE_SCALAR_FIELD(length);
169 
170  /*
171  * We place the switch outside the loop for the sake of efficiency; this
172  * may not be worth doing...
173  */
174  switch (a->type)
175  {
176  case T_List:
177  forboth(item_a, a, item_b, b)
178  {
179  if (!equal(lfirst(item_a), lfirst(item_b)))
180  return false;
181  }
182  break;
183  case T_IntList:
184  forboth(item_a, a, item_b, b)
185  {
186  if (lfirst_int(item_a) != lfirst_int(item_b))
187  return false;
188  }
189  break;
190  case T_OidList:
191  forboth(item_a, a, item_b, b)
192  {
193  if (lfirst_oid(item_a) != lfirst_oid(item_b))
194  return false;
195  }
196  break;
197  case T_XidList:
198  forboth(item_a, a, item_b, b)
199  {
200  if (lfirst_xid(item_a) != lfirst_xid(item_b))
201  return false;
202  }
203  break;
204  default:
205  elog(ERROR, "unrecognized list node type: %d",
206  (int) a->type);
207  return false; /* keep compiler quiet */
208  }
209 
210  /*
211  * If we got here, we should have run out of elements of both lists
212  */
213  Assert(item_a == NULL);
214  Assert(item_b == NULL);
215 
216  return true;
217 }
#define ERROR
Definition: elog.h:39
Assert(fmt[strlen(fmt) - 1] !='\n')
#define lfirst(lc)
Definition: pg_list.h:172
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:467
#define lfirst_int(lc)
Definition: pg_list.h:173
#define lfirst_oid(lc)
Definition: pg_list.h:174
#define lfirst_xid(lc)
Definition: pg_list.h:175

References a, Assert(), b, COMPARE_SCALAR_FIELD, elog(), equal(), ERROR, forboth, lfirst, lfirst_int, lfirst_oid, lfirst_xid, and generate_unaccent_rules::type.

Referenced by equal().

◆ equal()

bool equal ( const void *  a,
const void *  b 
)

Definition at line 225 of file equalfuncs.c.

226 {
227  bool retval;
228 
229  if (a == b)
230  return true;
231 
232  /*
233  * note that a!=b, so only one of them can be NULL
234  */
235  if (a == NULL || b == NULL)
236  return false;
237 
238  /*
239  * are they the same type of nodes?
240  */
241  if (nodeTag(a) != nodeTag(b))
242  return false;
243 
244  /* Guard against stack overflow due to overly complex expressions */
246 
247  switch (nodeTag(a))
248  {
249 #include "equalfuncs.switch.c"
250 
251  case T_List:
252  case T_IntList:
253  case T_OidList:
254  case T_XidList:
255  retval = _equalList(a, b);
256  break;
257 
258  default:
259  elog(ERROR, "unrecognized node type: %d",
260  (int) nodeTag(a));
261  retval = false; /* keep compiler quiet */
262  break;
263  }
264 
265  return retval;
266 }
static bool _equalList(const List *a, const List *b)
Definition: equalfuncs.c:158
#define nodeTag(nodeptr)
Definition: nodes.h:133
void check_stack_depth(void)
Definition: postgres.c:3454

References _equalList(), a, b, check_stack_depth(), elog(), ERROR, and nodeTag.

Referenced by _equalA_Const(), _equalList(), add_row_identity_var(), add_sp_item_to_pathtarget(), add_unique_group_var(), addRangeClause(), AlterPublicationTables(), calc_hist_selectivity_scalar(), calc_length_hist_frac(), check_new_partition_bound(), check_ungrouped_columns_walker(), clause_is_strict_for(), CompareIndexInfo(), convert_subquery_pathkeys(), create_projection_path(), CreateStatistics(), deparseParam(), deparseVar(), dependencies_clauselist_selectivity(), dependency_is_compatible_expression(), ec_member_matches_foreign(), equalPolicy(), equalRuleLocks(), estimate_multivariate_ndistinct(), examine_variable(), ExecInitWindowAgg(), expand_grouping_sets(), exprs_known_equal(), finalize_grouping_exprs_walker(), find_compatible_agg(), find_ec_member_matching_expr(), find_em_for_rel_target(), find_list_position(), findTargetlistEntrySQL92(), findTargetlistEntrySQL99(), fix_expr_common(), fix_indexqual_operand(), fix_scan_expr_mutator(), fix_upper_expr_mutator(), get_eclass_for_sort_expr(), get_partition_for_tuple(), grouping_planner(), infer_collation_opclass_match(), is_exprlist_member(), length_hist_bsearch(), list_delete(), list_member(), match_boolean_partition_clause(), match_clause_to_partition_key(), match_eclasses_to_foreign_key_col(), match_expr_to_partition_keys(), match_index_to_operand(), matches_boolean_partition_clause(), maybe_reread_subscription(), mcv_match_expression(), MergeAttributes(), MergeCheckConstraint(), MergeWithExistingConstraint(), operator_predicate_proof(), optimize_window_clauses(), pg_parse_query(), pg_plan_query(), pg_rewrite_query(), plan_union_children(), predicate_implied_by_simple_clause(), predicate_refuted_by_simple_clause(), preprocess_groupclause(), process_duplicate_ors(), process_equivalence(), process_matched_tle(), process_subquery_nestloop_params(), rbound_bsearch(), recomputeNamespacePath(), reconsider_full_join_clause(), reconsider_outer_join_clause(), RelationGetIndexAttrBitmap(), replace_nestloop_param_placeholdervar(), replace_nestloop_param_var(), search_indexed_tlist_for_sortgroupref(), stat_find_expression(), tlist_member(), tlist_same_exprs(), transformIndexConstraints(), transformPartitionBound(), transformWindowFuncCall(), and trivial_subqueryscan().