PostgreSQL Source Code  git master
bitmapset.c File Reference
#include "postgres.h"
#include "common/hashfn.h"
#include "nodes/bitmapset.h"
#include "nodes/pg_list.h"
#include "port/pg_bitutils.h"
Include dependency graph for bitmapset.c:

Go to the source code of this file.

Macros

#define WORDNUM(x)   ((x) / BITS_PER_BITMAPWORD)
 
#define BITNUM(x)   ((x) % BITS_PER_BITMAPWORD)
 
#define BITMAPSET_SIZE(nwords)    (offsetof(Bitmapset, words) + (nwords) * sizeof(bitmapword))
 
#define RIGHTMOST_ONE(x)   ((signedbitmapword) (x) & -((signedbitmapword) (x)))
 
#define HAS_MULTIPLE_ONES(x)   ((bitmapword) RIGHTMOST_ONE(x) != (x))
 
#define bmw_leftmost_one_pos(w)   pg_leftmost_one_pos32(w)
 
#define bmw_rightmost_one_pos(w)   pg_rightmost_one_pos32(w)
 
#define bmw_popcount(w)   pg_popcount32(w)
 

Functions

static bool bms_is_empty_internal (const Bitmapset *a)
 
Bitmapsetbms_copy (const Bitmapset *a)
 
bool bms_equal (const Bitmapset *a, const Bitmapset *b)
 
int bms_compare (const Bitmapset *a, const Bitmapset *b)
 
Bitmapsetbms_make_singleton (int x)
 
void bms_free (Bitmapset *a)
 
Bitmapsetbms_union (const Bitmapset *a, const Bitmapset *b)
 
Bitmapsetbms_intersect (const Bitmapset *a, const Bitmapset *b)
 
Bitmapsetbms_difference (const Bitmapset *a, const Bitmapset *b)
 
bool bms_is_subset (const Bitmapset *a, const Bitmapset *b)
 
BMS_Comparison bms_subset_compare (const Bitmapset *a, const Bitmapset *b)
 
bool bms_is_member (int x, const Bitmapset *a)
 
int bms_member_index (Bitmapset *a, int x)
 
bool bms_overlap (const Bitmapset *a, const Bitmapset *b)
 
bool bms_overlap_list (const Bitmapset *a, const List *b)
 
bool bms_nonempty_difference (const Bitmapset *a, const Bitmapset *b)
 
int bms_singleton_member (const Bitmapset *a)
 
bool bms_get_singleton_member (const Bitmapset *a, int *member)
 
int bms_num_members (const Bitmapset *a)
 
BMS_Membership bms_membership (const Bitmapset *a)
 
Bitmapsetbms_add_member (Bitmapset *a, int x)
 
Bitmapsetbms_del_member (Bitmapset *a, int x)
 
Bitmapsetbms_add_members (Bitmapset *a, const Bitmapset *b)
 
Bitmapsetbms_add_range (Bitmapset *a, int lower, int upper)
 
Bitmapsetbms_int_members (Bitmapset *a, const Bitmapset *b)
 
Bitmapsetbms_del_members (Bitmapset *a, const Bitmapset *b)
 
Bitmapsetbms_join (Bitmapset *a, Bitmapset *b)
 
int bms_next_member (const Bitmapset *a, int prevbit)
 
int bms_prev_member (const Bitmapset *a, int prevbit)
 
uint32 bms_hash_value (const Bitmapset *a)
 
uint32 bitmap_hash (const void *key, Size keysize)
 
int bitmap_match (const void *key1, const void *key2, Size keysize)
 

Macro Definition Documentation

◆ BITMAPSET_SIZE

#define BITMAPSET_SIZE (   nwords)     (offsetof(Bitmapset, words) + (nwords) * sizeof(bitmapword))

Definition at line 30 of file bitmapset.c.

◆ BITNUM

#define BITNUM (   x)    ((x) % BITS_PER_BITMAPWORD)

Definition at line 28 of file bitmapset.c.

◆ bmw_leftmost_one_pos

#define bmw_leftmost_one_pos (   w)    pg_leftmost_one_pos32(w)

Definition at line 56 of file bitmapset.c.

◆ bmw_popcount

#define bmw_popcount (   w)    pg_popcount32(w)

Definition at line 58 of file bitmapset.c.

◆ bmw_rightmost_one_pos

#define bmw_rightmost_one_pos (   w)    pg_rightmost_one_pos32(w)

Definition at line 57 of file bitmapset.c.

◆ HAS_MULTIPLE_ONES

#define HAS_MULTIPLE_ONES (   x)    ((bitmapword) RIGHTMOST_ONE(x) != (x))

Definition at line 52 of file bitmapset.c.

◆ RIGHTMOST_ONE

#define RIGHTMOST_ONE (   x)    ((signedbitmapword) (x) & -((signedbitmapword) (x)))

Definition at line 50 of file bitmapset.c.

◆ WORDNUM

#define WORDNUM (   x)    ((x) / BITS_PER_BITMAPWORD)

Definition at line 27 of file bitmapset.c.

Function Documentation

◆ bitmap_hash()

uint32 bitmap_hash ( const void *  key,
Size  keysize 
)

Definition at line 1173 of file bitmapset.c.

1174 {
1175  Assert(keysize == sizeof(Bitmapset *));
1176  return bms_hash_value(*((const Bitmapset *const *) key));
1177 }
uint32 bms_hash_value(const Bitmapset *a)
Definition: bitmapset.c:1150
Assert(fmt[strlen(fmt) - 1] !='\n')

References Assert(), bms_hash_value(), and sort-test::key.

Referenced by build_join_rel_hash().

◆ bitmap_match()

int bitmap_match ( const void *  key1,
const void *  key2,
Size  keysize 
)

Definition at line 1183 of file bitmapset.c.

1184 {
1185  Assert(keysize == sizeof(Bitmapset *));
1186  return !bms_equal(*((const Bitmapset *const *) key1),
1187  *((const Bitmapset *const *) key2));
1188 }
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

References Assert(), and bms_equal().

Referenced by build_join_rel_hash().

◆ bms_add_member()

Bitmapset* bms_add_member ( Bitmapset a,
int  x 
)

Definition at line 755 of file bitmapset.c.

756 {
757  int wordnum,
758  bitnum;
759 
760  if (x < 0)
761  elog(ERROR, "negative bitmapset member not allowed");
762  if (a == NULL)
763  return bms_make_singleton(x);
764  wordnum = WORDNUM(x);
765  bitnum = BITNUM(x);
766 
767  /* enlarge the set if necessary */
768  if (wordnum >= a->nwords)
769  {
770  int oldnwords = a->nwords;
771  int i;
772 
773  a = (Bitmapset *) repalloc(a, BITMAPSET_SIZE(wordnum + 1));
774  a->nwords = wordnum + 1;
775  /* zero out the enlarged portion */
776  for (i = oldnwords; i < a->nwords; i++)
777  a->words[i] = 0;
778  }
779 
780  a->words[wordnum] |= ((bitmapword) 1 << bitnum);
781  return a;
782 }
#define BITMAPSET_SIZE(nwords)
Definition: bitmapset.c:30
#define WORDNUM(x)
Definition: bitmapset.c:27
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:186
#define BITNUM(x)
Definition: bitmapset.c:28
uint32 bitmapword
Definition: bitmapset.h:44
#define ERROR
Definition: elog.h:39
int x
Definition: isn.c:71
int a
Definition: isn.c:69
int i
Definition: isn.c:73
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1456

References a, BITMAPSET_SIZE, BITNUM, bms_make_singleton(), elog(), ERROR, i, repalloc(), WORDNUM, and x.

Referenced by _readBitmapset(), add_child_rel_equivalences(), add_row_identity_var(), adjust_child_relids(), adjust_group_pathkeys_for_groupagg(), adjust_relid_set(), adjust_view_column_set(), alias_relid_set(), AlterPublicationTables(), apply_handle_update(), build_child_join_rel(), build_joinrel_tlist(), build_subplan(), check_functional_grouping(), check_index_only(), checkInsertTargets(), classify_index_clause_usage(), clauselist_apply_dependencies(), convert_EXISTS_sublink_to_join(), create_lateral_join_info(), create_list_bounds(), DecodeTextArrayToBitmapset(), deconstruct_distribute_oj_quals(), deconstruct_recurse(), deparseColumnRef(), dependencies_clauselist_selectivity(), DiscreteKnapsack(), do_analyze_rel(), DoCopy(), estimate_multivariate_ndistinct(), EvalPlanQualBegin(), ExecAsyncAppendResponse(), ExecBuildUpdateProjection(), ExecInitAgg(), ExecInitAppend(), ExecInitStoredGenerated(), ExecNestLoop(), ExecRecursiveUnion(), ExecReScanGather(), ExecReScanGatherMerge(), ExecReScanRecursiveUnion(), ExecReScanSetParamPlan(), ExecScanSubPlan(), execute_attr_map_cols(), expand_single_inheritance_child(), ExplainPreScanNode(), ExplainSubPlans(), extract_rollup_sets(), extractRemainingColumns(), fetch_remote_table_info(), fetch_statentries_for_relation(), finalize_plan(), finalize_primnode(), find_childrel_parents(), find_cols(), find_cols_walker(), find_hash_columns(), find_matching_subplans_recurse(), find_window_run_conditions(), findDefaultOnlyColumns(), fixup_inherited_columns(), fixup_whole_row_references(), func_get_detail(), gen_partprune_steps_internal(), generate_base_implied_equalities(), generate_join_implied_equalities(), get_baserel_parampathinfo(), get_dependent_generated_columns(), get_eclass_for_sort_expr(), get_matching_partitions(), get_param_path_clause_serials(), get_primary_key_attnos(), get_relation_constraint_attnos(), get_relation_statistics(), get_relids_in_jointree(), HeapDetermineColumnsInfo(), infer_arbiter_indexes(), join_is_removable(), load_enum_cache_data(), logicalrep_read_attrs(), make_datum_param(), make_join_rel(), make_modifytable(), make_outerjoininfo(), make_partition_pruneinfo(), make_partitionedrel_pruneinfo(), make_row_comparison_op(), make_window_input_target(), makeDependencyGraphWalker(), mark_rels_nulled_by_join(), markRelsAsNulledBy(), markRTEForSelectPriv(), mbms_add_member(), mbms_overlap_sets(), nodeRead(), offset_relid_set(), PartitionPruneFixSubPlanMap(), preprocess_grouping_sets(), pub_collist_to_bitmapset(), publication_translate_columns(), pull_exec_paramids_walker(), pull_paramids_walker(), pull_up_sublinks_jointree_recurse(), pull_varattnos_walker(), pull_varnos_walker(), reduce_outer_joins_pass2(), RelationGetIdentityKeyBitmap(), RelationGetIndexAttrBitmap(), remove_useless_groupby_columns(), remove_useless_joins(), remove_useless_results_recurse(), rewriteTargetListIU(), rewriteTargetView(), RI_Initial_Check(), set_join_column_names(), set_param_references(), SS_identify_outer_params(), stat_covers_expressions(), statext_is_compatible_clause(), statext_is_compatible_clause_internal(), statext_mcv_clauselist_selectivity(), transformGroupClause(), transformGroupClauseList(), transformMergeStmt(), transformRangeTableFunc(), transformUpdateTargetList(), translate_col_privs(), try_partitionwise_join(), use_physical_tlist(), and view_cols_are_auto_updatable().

◆ bms_add_members()

Bitmapset* bms_add_members ( Bitmapset a,
const Bitmapset b 
)

Definition at line 818 of file bitmapset.c.

819 {
820  Bitmapset *result;
821  const Bitmapset *other;
822  int otherlen;
823  int i;
824 
825  /* Handle cases where either input is NULL */
826  if (a == NULL)
827  return bms_copy(b);
828  if (b == NULL)
829  return a;
830  /* Identify shorter and longer input; copy the longer one if needed */
831  if (a->nwords < b->nwords)
832  {
833  result = bms_copy(b);
834  other = a;
835  }
836  else
837  {
838  result = a;
839  other = b;
840  }
841  /* And union the shorter input into the result */
842  otherlen = other->nwords;
843  for (i = 0; i < otherlen; i++)
844  result->words[i] |= other->words[i];
845  if (result != a)
846  pfree(a);
847  return result;
848 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
int b
Definition: isn.c:70
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
void pfree(void *pointer)
Definition: mcxt.c:1436
int nwords
Definition: bitmapset.h:54
bitmapword words[FLEXIBLE_ARRAY_MEMBER]
Definition: bitmapset.h:55

References a, b, bms_copy(), i, if(), Bitmapset::nwords, pfree(), and Bitmapset::words.

Referenced by add_child_join_rel_equivalences(), add_child_rel_equivalences(), add_eq_member(), add_part_relids(), add_paths_to_joinrel(), add_placeholders_to_joinrel(), add_vars_to_targetlist(), adjust_standard_join_alias_expression(), build_index_paths(), choose_best_statistics(), choose_bitmap_and(), create_bitmap_and_path(), create_bitmap_or_path(), create_lateral_join_info(), CreatePartitionPruneState(), deconstruct_distribute(), deconstruct_recurse(), DiscreteKnapsack(), ExecFindMatchingSubPlans(), ExecInitAgg(), expand_partitioned_rtentry(), ExplainPreScanNode(), finalize_plan(), find_nonnullable_rels_walker(), foreign_join_ok(), get_eclass_indexes_for_relids(), get_param_path_clause_serials(), heap_update(), join_is_legal(), make_outerjoininfo(), mbms_add_members(), perform_pruning_combine_step(), pull_varnos_walker(), pullup_replace_vars_callback(), reduce_outer_joins_pass1(), reduce_outer_joins_pass2(), transformOnConflictArbiter(), and try_partitionwise_join().

◆ bms_add_range()

Bitmapset* bms_add_range ( Bitmapset a,
int  lower,
int  upper 
)

Definition at line 859 of file bitmapset.c.

860 {
861  int lwordnum,
862  lbitnum,
863  uwordnum,
864  ushiftbits,
865  wordnum;
866 
867  /* do nothing if nothing is called for, without further checking */
868  if (upper < lower)
869  return a;
870 
871  if (lower < 0)
872  elog(ERROR, "negative bitmapset member not allowed");
873  uwordnum = WORDNUM(upper);
874 
875  if (a == NULL)
876  {
877  a = (Bitmapset *) palloc0(BITMAPSET_SIZE(uwordnum + 1));
878  a->type = T_Bitmapset;
879  a->nwords = uwordnum + 1;
880  }
881  else if (uwordnum >= a->nwords)
882  {
883  int oldnwords = a->nwords;
884  int i;
885 
886  /* ensure we have enough words to store the upper bit */
887  a = (Bitmapset *) repalloc(a, BITMAPSET_SIZE(uwordnum + 1));
888  a->nwords = uwordnum + 1;
889  /* zero out the enlarged portion */
890  for (i = oldnwords; i < a->nwords; i++)
891  a->words[i] = 0;
892  }
893 
894  wordnum = lwordnum = WORDNUM(lower);
895 
896  lbitnum = BITNUM(lower);
897  ushiftbits = BITS_PER_BITMAPWORD - (BITNUM(upper) + 1);
898 
899  /*
900  * Special case when lwordnum is the same as uwordnum we must perform the
901  * upper and lower masking on the word.
902  */
903  if (lwordnum == uwordnum)
904  {
905  a->words[lwordnum] |= ~(bitmapword) (((bitmapword) 1 << lbitnum) - 1)
906  & (~(bitmapword) 0) >> ushiftbits;
907  }
908  else
909  {
910  /* turn on lbitnum and all bits left of it */
911  a->words[wordnum++] |= ~(bitmapword) (((bitmapword) 1 << lbitnum) - 1);
912 
913  /* turn on all bits for any intermediate words */
914  while (wordnum < uwordnum)
915  a->words[wordnum++] = ~(bitmapword) 0;
916 
917  /* turn on upper's bit and all bits right of it. */
918  a->words[uwordnum] |= (~(bitmapword) 0) >> ushiftbits;
919  }
920 
921  return a;
922 }
#define BITS_PER_BITMAPWORD
Definition: bitmapset.h:43
void * palloc0(Size size)
Definition: mcxt.c:1241
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:49
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:80

References a, BITMAPSET_SIZE, BITNUM, BITS_PER_BITMAPWORD, elog(), ERROR, i, lower(), palloc0(), repalloc(), upper(), and WORDNUM.

Referenced by ExecInitAppend(), ExecInitMergeAppend(), ExecInitPartitionPruning(), get_matching_hash_bounds(), get_matching_list_bounds(), get_matching_partitions(), get_matching_range_bounds(), logicalrep_rel_open(), make_partition_pruneinfo(), perform_pruning_combine_step(), and prune_append_rel_partitions().

◆ bms_compare()

int bms_compare ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 147 of file bitmapset.c.

148 {
149  int shortlen;
150  int i;
151 
152  /* Handle cases where either input is NULL */
153  if (a == NULL)
154  return (b == NULL) ? 0 : -1;
155  else if (b == NULL)
156  return +1;
157  /* Handle cases where one input is longer than the other */
158  shortlen = Min(a->nwords, b->nwords);
159  for (i = shortlen; i < a->nwords; i++)
160  {
161  if (a->words[i] != 0)
162  return +1;
163  }
164  for (i = shortlen; i < b->nwords; i++)
165  {
166  if (b->words[i] != 0)
167  return -1;
168  }
169  /* Process words in common */
170  i = shortlen;
171  while (--i >= 0)
172  {
173  bitmapword aw = a->words[i];
174  bitmapword bw = b->words[i];
175 
176  if (aw != bw)
177  return (aw > bw) ? +1 : -1;
178  }
179  return 0;
180 }
#define Min(x, y)
Definition: c.h:988

References a, b, i, and Min.

Referenced by append_startup_cost_compare(), and append_total_cost_compare().

◆ bms_copy()

◆ bms_del_member()

Bitmapset* bms_del_member ( Bitmapset a,
int  x 
)

Definition at line 792 of file bitmapset.c.

793 {
794  int wordnum,
795  bitnum;
796 
797  if (x < 0)
798  elog(ERROR, "negative bitmapset member not allowed");
799  if (a == NULL)
800  return NULL;
801  wordnum = WORDNUM(x);
802  bitnum = BITNUM(x);
803  if (wordnum < a->nwords)
804  a->words[wordnum] &= ~((bitmapword) 1 << bitnum);
805  /* If we computed an empty result, we must return NULL */
807  {
808  pfree(a);
809  return NULL;
810  }
811  return a;
812 }
static bool bms_is_empty_internal(const Bitmapset *a)
Definition: bitmapset.c:722

References a, BITNUM, bms_is_empty_internal(), elog(), ERROR, pfree(), WORDNUM, and x.

Referenced by add_nullingrels_if_needed(), adjust_child_relids(), adjust_group_pathkeys_for_groupagg(), adjust_relid_set(), build_index_paths(), BuildParameterizedTidPaths(), deconstruct_distribute_oj_quals(), dependencies_clauselist_selectivity(), DiscreteKnapsack(), finalize_plan(), finalize_primnode(), find_hash_columns(), findDefaultOnlyColumns(), fixup_whole_row_references(), get_join_domain_min_rels(), get_matching_list_bounds(), logicalrep_rel_open(), make_outerjoininfo(), postgresGetForeignPaths(), preprocess_rowmarks(), remove_rel_from_query(), remove_rel_from_restrictinfo(), substitute_phv_relids_walker(), and TopologicalSort().

◆ bms_del_members()

Bitmapset* bms_del_members ( Bitmapset a,
const Bitmapset b 
)

Definition at line 960 of file bitmapset.c.

961 {
962  int shortlen;
963  int i;
964 
965  /* Handle cases where either input is NULL */
966  if (a == NULL)
967  return NULL;
968  if (b == NULL)
969  return a;
970  /* Remove b's bits from a; we need never copy */
971  shortlen = Min(a->nwords, b->nwords);
972  for (i = 0; i < shortlen; i++)
973  a->words[i] &= ~b->words[i];
974  /* If we computed an empty result, we must return NULL */
976  {
977  pfree(a);
978  return NULL;
979  }
980  return a;
981 }

References a, b, bms_is_empty_internal(), i, if(), Min, and pfree().

Referenced by adjust_group_pathkeys_for_groupagg(), build_join_rel(), calc_nestloop_required_outer(), check_index_predicates(), classify_matching_subplans(), DiscreteKnapsack(), finalize_plan(), get_join_domain_min_rels(), make_outerjoininfo(), make_partition_pruneinfo(), min_join_parameterization(), and NumRelids().

◆ bms_difference()

Bitmapset* bms_difference ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 298 of file bitmapset.c.

299 {
300  Bitmapset *result;
301  int shortlen;
302  int i;
303 
304  /* Handle cases where either input is NULL */
305  if (a == NULL)
306  return NULL;
307  if (b == NULL)
308  return bms_copy(a);
309 
310  /*
311  * In Postgres' usage, an empty result is a very common case, so it's
312  * worth optimizing for that by testing bms_nonempty_difference(). This
313  * saves us a palloc/pfree cycle compared to checking after-the-fact.
314  */
315  if (!bms_nonempty_difference(a, b))
316  return NULL;
317 
318  /* Copy the left input */
319  result = bms_copy(a);
320  /* And remove b's bits from result */
321  shortlen = Min(a->nwords, b->nwords);
322  for (i = 0; i < shortlen; i++)
323  result->words[i] &= ~b->words[i];
324  /* Need not check for empty result, since we handled that case above */
325  return result;
326 }
bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:564

References a, b, bms_copy(), bms_nonempty_difference(), i, Min, and Bitmapset::words.

Referenced by add_child_join_rel_equivalences(), add_child_rel_equivalences(), add_paths_to_joinrel(), check_index_predicates(), consider_new_or_clause(), create_foreignscan_plan(), finalize_plan(), find_placeholder_info(), make_restrictinfo_internal(), pull_varnos_walker(), remove_nulling_relids_mutator(), and remove_useless_groupby_columns().

◆ bms_equal()

bool bms_equal ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 94 of file bitmapset.c.

95 {
96  const Bitmapset *shorter;
97  const Bitmapset *longer;
98  int shortlen;
99  int longlen;
100  int i;
101 
102  /* Handle cases where either input is NULL */
103  if (a == NULL)
104  {
105  if (b == NULL)
106  return true;
107  return false;
108  }
109  else if (b == NULL)
110  return false;
111  /* Identify shorter and longer input */
112  if (a->nwords <= b->nwords)
113  {
114  shorter = a;
115  longer = b;
116  }
117  else
118  {
119  shorter = b;
120  longer = a;
121  }
122  /* And process */
123  shortlen = shorter->nwords;
124  for (i = 0; i < shortlen; i++)
125  {
126  if (shorter->words[i] != longer->words[i])
127  return false;
128  }
129  longlen = longer->nwords;
130  for (; i < longlen; i++)
131  {
132  if (longer->words[i] != 0)
133  return false;
134  }
135  return true;
136 }

References a, b, i, Bitmapset::nwords, and Bitmapset::words.

Referenced by _equalBitmapset(), add_path_precheck(), add_paths_to_append_rel(), AlterPublicationTables(), bitmap_match(), choose_bitmap_and(), create_append_path(), create_merge_append_path(), create_unique_path(), deconstruct_distribute_oj_quals(), deconstruct_jointree(), ExecInitPartitionPruning(), extract_rollup_sets(), fetch_upper_rel(), find_dependent_phvs_walker(), find_join_rel(), find_param_path_info(), generate_implied_equalities_for_column(), get_cheapest_parameterized_child_path(), get_eclass_for_sort_expr(), get_join_domain_min_rels(), has_join_restriction(), infer_arbiter_indexes(), is_safe_restriction_clause_for(), join_is_legal(), make_one_rel(), make_partitionedrel_pruneinfo(), match_pathkeys_to_index(), merge_clump(), pgoutput_column_list_init(), populate_joinrel_with_paths(), pull_varnos_walker(), search_indexed_tlist_for_phv(), search_indexed_tlist_for_var(), set_rel_pathlist(), standard_join_search(), and try_partitionwise_join().

◆ bms_free()

◆ bms_get_singleton_member()

bool bms_get_singleton_member ( const Bitmapset a,
int *  member 
)

Definition at line 634 of file bitmapset.c.

635 {
636  int result = -1;
637  int nwords;
638  int wordnum;
639 
640  if (a == NULL)
641  return false;
642  nwords = a->nwords;
643  for (wordnum = 0; wordnum < nwords; wordnum++)
644  {
645  bitmapword w = a->words[wordnum];
646 
647  if (w != 0)
648  {
649  if (result >= 0 || HAS_MULTIPLE_ONES(w))
650  return false;
651  result = wordnum * BITS_PER_BITMAPWORD;
652  result += bmw_rightmost_one_pos(w);
653  }
654  }
655  if (result < 0)
656  return false;
657  *member = result;
658  return true;
659 }
#define bmw_rightmost_one_pos(w)
Definition: bitmapset.c:57
#define HAS_MULTIPLE_ONES(x)
Definition: bitmapset.c:52

References a, BITS_PER_BITMAPWORD, bmw_rightmost_one_pos, and HAS_MULTIPLE_ONES.

Referenced by add_placeholders_to_base_rels(), create_lateral_join_info(), find_single_rel_for_clauses(), generate_base_implied_equalities_no_const(), get_common_eclass_indexes(), join_is_removable(), reduce_unique_semijoins(), set_base_rel_consider_startup(), and statext_is_compatible_clause().

◆ bms_hash_value()

uint32 bms_hash_value ( const Bitmapset a)

Definition at line 1150 of file bitmapset.c.

1151 {
1152  int lastword;
1153 
1154  if (a == NULL)
1155  return 0; /* All empty sets hash to 0 */
1156  for (lastword = a->nwords; --lastword >= 0;)
1157  {
1158  if (a->words[lastword] != 0)
1159  break;
1160  }
1161  if (lastword < 0)
1162  return 0; /* All empty sets hash to 0 */
1163  return DatumGetUInt32(hash_any((const unsigned char *) a->words,
1164  (lastword + 1) * sizeof(bitmapword)));
1165 }
static Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.h:31
static uint32 DatumGetUInt32(Datum X)
Definition: postgres.h:222

References a, DatumGetUInt32(), and hash_any().

Referenced by bitmap_hash().

◆ bms_int_members()

Bitmapset* bms_int_members ( Bitmapset a,
const Bitmapset b 
)

Definition at line 928 of file bitmapset.c.

929 {
930  int shortlen;
931  int i;
932 
933  /* Handle cases where either input is NULL */
934  if (a == NULL)
935  return NULL;
936  if (b == NULL)
937  {
938  pfree(a);
939  return NULL;
940  }
941  /* Intersect b into a; we need never copy */
942  shortlen = Min(a->nwords, b->nwords);
943  for (i = 0; i < shortlen; i++)
944  a->words[i] &= b->words[i];
945  for (; i < a->nwords; i++)
946  a->words[i] = 0;
947  /* If we computed an empty result, we must return NULL */
949  {
950  pfree(a);
951  return NULL;
952  }
953  return a;
954 }

References a, b, bms_is_empty_internal(), i, if(), Min, and pfree().

Referenced by find_nonnullable_rels_walker(), find_placeholder_info(), get_common_eclass_indexes(), get_param_path_clause_serials(), make_outerjoininfo(), make_row_comparison_op(), mbms_int_members(), perform_pruning_combine_step(), and relation_is_updatable().

◆ bms_intersect()

Bitmapset* bms_intersect ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 260 of file bitmapset.c.

261 {
262  Bitmapset *result;
263  const Bitmapset *other;
264  int resultlen;
265  int i;
266 
267  /* Handle cases where either input is NULL */
268  if (a == NULL || b == NULL)
269  return NULL;
270  /* Identify shorter and longer input; copy the shorter one */
271  if (a->nwords <= b->nwords)
272  {
273  result = bms_copy(a);
274  other = b;
275  }
276  else
277  {
278  result = bms_copy(b);
279  other = a;
280  }
281  /* And intersect the longer input with the result */
282  resultlen = result->nwords;
283  for (i = 0; i < resultlen; i++)
284  result->words[i] &= other->words[i];
285  /* If we computed an empty result, we must return NULL */
286  if (bms_is_empty_internal(result))
287  {
288  pfree(result);
289  return NULL;
290  }
291  return result;
292 }

References a, b, bms_copy(), bms_is_empty_internal(), i, if(), Bitmapset::nwords, pfree(), and Bitmapset::words.

Referenced by build_joinrel_tlist(), classify_matching_subplans(), deconstruct_distribute_oj_quals(), distribute_qual_to_rels(), get_matching_part_pairs(), make_outerjoininfo(), match_eclasses_to_foreign_key_col(), set_param_references(), and UpdateChangedParamSet().

◆ bms_is_empty_internal()

static bool bms_is_empty_internal ( const Bitmapset a)
static

Definition at line 722 of file bitmapset.c.

723 {
724  int nwords;
725  int wordnum;
726 
727  nwords = a->nwords;
728  for (wordnum = 0; wordnum < nwords; wordnum++)
729  {
730  bitmapword w = a->words[wordnum];
731 
732  if (w != 0)
733  return false;
734  }
735  return true;
736 }

References a.

Referenced by bms_del_member(), bms_del_members(), bms_int_members(), and bms_intersect().

◆ bms_is_member()

bool bms_is_member ( int  x,
const Bitmapset a 
)

Definition at line 444 of file bitmapset.c.

445 {
446  int wordnum,
447  bitnum;
448 
449  /* XXX better to just return false for x<0 ? */
450  if (x < 0)
451  elog(ERROR, "negative bitmapset member not allowed");
452  if (a == NULL)
453  return false;
454  wordnum = WORDNUM(x);
455  bitnum = BITNUM(x);
456  if (wordnum >= a->nwords)
457  return false;
458  if ((a->words[wordnum] & ((bitmapword) 1 << bitnum)) != 0)
459  return true;
460  return false;
461 }

References a, BITNUM, elog(), ERROR, WORDNUM, and x.

Referenced by add_nulling_relids_mutator(), add_row_identity_var(), adjust_appendrel_attrs_mutator(), adjust_child_relids(), adjust_relid_set(), adjust_rowcount_for_semijoins(), bms_member_index(), build_joinrel_tlist(), check_index_predicates(), check_redundant_nullability_qual(), check_relation_privileges(), checkInsertTargets(), clause_is_computable_at(), clause_selectivity_ext(), clauselist_selectivity_ext(), clauselist_selectivity_or(), column_in_column_list(), ComputePartitionAttrs(), consider_groupingsets_paths(), contain_invalid_rfcolumn_walker(), contain_placeholder_references_walker(), cost_incremental_sort(), create_foreignscan_plan(), create_lateral_join_info(), create_nestloop_path(), deconstruct_distribute_oj_quals(), DefineIndex(), deparseFromExprForRel(), deparseLockingClause(), deparseRangeTblRef(), deparseTargetList(), deparseVar(), dependencies_clauselist_selectivity(), dependency_is_fully_matched(), do_analyze_rel(), enum_known_sorted(), estimate_multivariate_ndistinct(), examine_variable(), exec_check_rw_parameter(), ExecBuildSlotValueDescription(), ExecBuildUpdateProjection(), ExecEvalGroupingFunc(), ExecInitModifyTable(), execute_attr_map_cols(), expand_indexqual_rowcompare(), expand_single_inheritance_child(), ExplainSubPlans(), extractRemainingColumns(), ExtractReplicaIdentity(), fetch_remote_table_info(), filter_event_trigger(), find_hash_columns(), find_modifytable_subplan(), fixup_whole_row_references(), foreign_expr_walker(), func_get_detail(), gen_partprune_steps_internal(), gen_prune_steps_from_opexps(), generate_base_implied_equalities(), get_eclass_for_sort_expr(), get_eclass_indexes_for_relids(), get_foreign_key_join_selectivity(), get_join_domain_min_rels(), get_matching_hash_bounds(), get_tablefunc(), get_translated_update_targetlist(), get_variable(), has_partition_attrs(), hashagg_spill_tuple(), HeapDetermineColumnsInfo(), identify_current_nestloop_params(), index_expression_changed_walker(), index_unchanged_by_update(), InitPlan(), is_foreign_param(), is_pseudo_constant_for_index(), is_subquery_var(), IsBinaryTidClause(), isPlainForeignVar(), IsTidEqualAnyClause(), join_clause_is_movable_to(), join_is_removable(), lo_manage(), logicalrep_rel_mark_updatable(), logicalrep_write_attrs(), make_outerjoininfo(), make_window_input_target(), mark_invalid_subplans_as_finished(), mark_rels_nulled_by_join(), match_opclause_to_indexcol(), match_rowcompare_to_indexcol(), match_saopclause_to_indexcol(), mbms_is_member(), partitions_are_ordered(), perform_pruning_base_step(), plpgsql_param_fetch(), postgresExplainForeignScan(), prepare_projection_slot(), preprocess_rowmarks(), process_subquery_nestloop_params(), pub_collist_contains_invalid_column(), publication_translate_columns(), pullup_replace_vars_callback(), rangeTableEntry_used_walker(), remove_nulling_relids_mutator(), remove_rel_from_query(), remove_unused_subquery_outputs(), remove_useless_groupby_columns(), replace_nestloop_params_mutator(), rewriteTargetListIU(), rewriteValuesRTE(), send_relation_and_attrs(), set_join_column_names(), set_rtable_names(), statext_mcv_clauselist_selectivity(), substitute_phv_relids_walker(), tfuncLoadRows(), transformGroupClauseExpr(), translate_col_privs(), TriggerEnabled(), tsvector_update_trigger(), use_physical_tlist(), and view_cols_are_auto_updatable().

◆ bms_is_subset()

bool bms_is_subset ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 332 of file bitmapset.c.

333 {
334  int shortlen;
335  int longlen;
336  int i;
337 
338  /* Handle cases where either input is NULL */
339  if (a == NULL)
340  return true; /* empty set is a subset of anything */
341  if (b == NULL)
342  return false;
343  /* Check common words */
344  shortlen = Min(a->nwords, b->nwords);
345  for (i = 0; i < shortlen; i++)
346  {
347  if ((a->words[i] & ~b->words[i]) != 0)
348  return false;
349  }
350  /* Check extra words */
351  if (a->nwords > b->nwords)
352  {
353  longlen = a->nwords;
354  for (; i < longlen; i++)
355  {
356  if (a->words[i] != 0)
357  return false;
358  }
359  }
360  return true;
361 }

References a, b, i, and Min.

Referenced by add_child_rel_equivalences(), add_paths_to_joinrel(), add_placeholders_to_joinrel(), add_vars_to_targetlist(), build_joinrel_tlist(), check_functional_grouping(), check_index_only(), choose_best_statistics(), clause_sides_match_join(), compute_semijoin_info(), convert_ANY_sublink_to_join(), convert_EXISTS_sublink_to_join(), create_index_paths(), distribute_qual_to_rels(), eclass_already_used(), eclass_useful_for_merging(), extract_rollup_sets(), final_cost_hashjoin(), finalize_plan(), find_computable_ec_member(), find_ec_member_matching_expr(), find_em_for_rel(), find_join_domain(), foreign_join_ok(), generate_implied_equalities_for_column(), generate_join_implied_equalities_broken(), generate_join_implied_equalities_normal(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_cheapest_fractional_path_for_pathkeys(), get_cheapest_parameterized_child_path(), get_cheapest_path_for_pathkeys(), get_join_index_paths(), get_join_variables(), get_joinrel_parampathinfo(), get_switched_clauses(), has_join_restriction(), has_relevant_eclass_joinclause(), have_dangerous_phv(), have_join_order_restriction(), have_partkey_equi_join(), identify_current_nestloop_params(), initial_cost_mergejoin(), innerrel_is_unique(), is_simple_subquery(), join_clause_is_movable_into(), join_is_legal(), join_is_removable(), jointree_contains_lateral_outer_refs(), make_outerjoininfo(), pg_get_expr_worker(), populate_joinrel_with_paths(), process_implied_equality(), process_subquery_nestloop_params(), remove_rel_from_query(), reparameterize_path(), replace_nestloop_params_mutator(), search_indexed_tlist_for_phv(), search_indexed_tlist_for_var(), statext_mcv_clauselist_selectivity(), subbuild_joinrel_joinlist(), subbuild_joinrel_restrictlist(), try_partial_nestloop_path(), and use_physical_tlist().

◆ bms_join()

Bitmapset* bms_join ( Bitmapset a,
Bitmapset b 
)

Definition at line 987 of file bitmapset.c.

988 {
989  Bitmapset *result;
990  Bitmapset *other;
991  int otherlen;
992  int i;
993 
994  /* Handle cases where either input is NULL */
995  if (a == NULL)
996  return b;
997  if (b == NULL)
998  return a;
999  /* Identify shorter and longer input; use longer one as result */
1000  if (a->nwords < b->nwords)
1001  {
1002  result = b;
1003  other = a;
1004  }
1005  else
1006  {
1007  result = a;
1008  other = b;
1009  }
1010  /* And union the shorter input into the result */
1011  otherlen = other->nwords;
1012  for (i = 0; i < otherlen; i++)
1013  result->words[i] |= other->words[i];
1014  if (other != result) /* pure paranoia */
1015  pfree(other);
1016  return result;
1017 }

References a, b, i, if(), Bitmapset::nwords, pfree(), and Bitmapset::words.

Referenced by add_paths_to_joinrel(), alias_relid_set(), build_joinrel_tlist(), finalize_primnode(), find_nonnullable_rels_walker(), get_partkey_exec_paramids(), get_relids_in_jointree(), make_partition_pruneinfo(), process_equivalence(), pull_up_sublinks_jointree_recurse(), pull_varnos_walker(), and UpdateChangedParamSet().

◆ bms_make_singleton()

◆ bms_member_index()

int bms_member_index ( Bitmapset a,
int  x 
)

Definition at line 470 of file bitmapset.c.

471 {
472  int i;
473  int bitnum;
474  int wordnum;
475  int result = 0;
476  bitmapword mask;
477 
478  /* return -1 if not a member of the bitmap */
479  if (!bms_is_member(x, a))
480  return -1;
481 
482  wordnum = WORDNUM(x);
483  bitnum = BITNUM(x);
484 
485  /* count bits in preceding words */
486  for (i = 0; i < wordnum; i++)
487  {
488  bitmapword w = a->words[i];
489 
490  /* No need to count the bits in a zero word */
491  if (w != 0)
492  result += bmw_popcount(w);
493  }
494 
495  /*
496  * Now add bits of the last word, but only those before the item. We can
497  * do that by applying a mask and then using popcount again. To get
498  * 0-based index, we want to count only preceding bits, not the item
499  * itself, so we subtract 1.
500  */
501  mask = ((bitmapword) 1 << bitnum) - 1;
502  result += bmw_popcount(a->words[wordnum] & mask);
503 
504  return result;
505 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:444
#define bmw_popcount(w)
Definition: bitmapset.c:58

References a, BITNUM, bms_is_member(), bmw_popcount, i, WORDNUM, and x.

Referenced by clauselist_apply_dependencies(), mcv_get_match_bitmap(), and mcv_match_expression().

◆ bms_membership()

BMS_Membership bms_membership ( const Bitmapset a)

Definition at line 691 of file bitmapset.c.

692 {
693  BMS_Membership result = BMS_EMPTY_SET;
694  int nwords;
695  int wordnum;
696 
697  if (a == NULL)
698  return BMS_EMPTY_SET;
699  nwords = a->nwords;
700  for (wordnum = 0; wordnum < nwords; wordnum++)
701  {
702  bitmapword w = a->words[wordnum];
703 
704  if (w != 0)
705  {
706  if (result != BMS_EMPTY_SET || HAS_MULTIPLE_ONES(w))
707  return BMS_MULTIPLE;
708  result = BMS_SINGLETON;
709  }
710  }
711  return result;
712 }
BMS_Membership
Definition: bitmapset.h:70
@ BMS_SINGLETON
Definition: bitmapset.h:72
@ BMS_EMPTY_SET
Definition: bitmapset.h:71
@ BMS_MULTIPLE
Definition: bitmapset.h:73

References a, BMS_EMPTY_SET, BMS_MULTIPLE, BMS_SINGLETON, and HAS_MULTIPLE_ONES.

Referenced by add_child_join_rel_equivalences(), deparseFromExpr(), deparseLockingClause(), deparseVar(), dependencies_clauselist_selectivity(), dependency_is_compatible_clause(), dependency_is_compatible_expression(), distribute_qual_to_rels(), distribute_restrictinfo_to_rels(), examine_variable(), find_join_input_rel(), find_nonnullable_rels_walker(), generate_base_implied_equalities(), generate_base_implied_equalities_broken(), get_foreign_key_join_selectivity(), grouping_planner(), process_implied_equality(), remove_useless_groupby_columns(), set_tablesample_rel_pathlist(), and statext_mcv_clauselist_selectivity().

◆ bms_next_member()

int bms_next_member ( const Bitmapset a,
int  prevbit 
)

Definition at line 1039 of file bitmapset.c.

1040 {
1041  int nwords;
1042  int wordnum;
1043  bitmapword mask;
1044 
1045  if (a == NULL)
1046  return -2;
1047  nwords = a->nwords;
1048  prevbit++;
1049  mask = (~(bitmapword) 0) << BITNUM(prevbit);
1050  for (wordnum = WORDNUM(prevbit); wordnum < nwords; wordnum++)
1051  {
1052  bitmapword w = a->words[wordnum];
1053 
1054  /* ignore bits before prevbit */
1055  w &= mask;
1056 
1057  if (w != 0)
1058  {
1059  int result;
1060 
1061  result = wordnum * BITS_PER_BITMAPWORD;
1062  result += bmw_rightmost_one_pos(w);
1063  return result;
1064  }
1065 
1066  /* in subsequent words, consider all bits */
1067  mask = (~(bitmapword) 0);
1068  }
1069  return -2;
1070 }

References a, BITNUM, BITS_PER_BITMAPWORD, bmw_rightmost_one_pos, and WORDNUM.

Referenced by add_child_join_rel_equivalences(), add_child_rel_equivalences(), add_join_clause_to_rels(), add_part_relids(), adjust_group_pathkeys_for_groupagg(), adjust_view_column_set(), alias_relid_set(), apply_scanjoin_target_to_paths(), approximate_joinrel_size(), build_attnums_array(), check_relation_privileges(), check_selective_binary_conversion(), choose_next_subplan_for_worker(), choose_next_subplan_locally(), clauselist_apply_dependencies(), ComputePartitionAttrs(), convert_EXISTS_sublink_to_join(), create_lateral_join_info(), create_partitionwise_grouping_paths(), CreateStatistics(), deparseLockingClause(), dependencies_clauselist_selectivity(), EstimateParamExecSpace(), ExecAppendAsyncBegin(), ExecAppendAsyncEventWait(), ExecAppendAsyncRequest(), ExecCheckOneRelPerms(), ExecCheckPermissionsModified(), ExecInitAgg(), ExecInitAppend(), ExecInitMergeAppend(), ExecMergeAppend(), ExecReScanAppend(), ExecScanReScan(), ExecSetParamPlanMulti(), expand_partitioned_rtentry(), find_appinfos_by_relids(), find_dependent_phvs_in_jointree(), find_hash_columns(), find_matching_subplans_recurse(), fixup_inherited_columns(), format_expr_params(), generate_base_implied_equalities(), generate_implied_equalities_for_column(), generate_join_implied_equalities(), get_eclass_for_sort_expr(), get_eclass_indexes_for_relids(), get_loop_count(), get_matching_partitions(), grouping_planner(), has_relevant_eclass_joinclause(), have_relevant_eclass_joinclause(), HeapDetermineColumnsInfo(), logicalrep_rel_mark_updatable(), logicalrep_report_missing_attrs(), lookup_var_attr_stats(), make_build_data(), make_partitionedrel_pruneinfo(), make_row_comparison_op(), mark_rels_nulled_by_join(), match_eclasses_to_foreign_key_col(), offset_relid_set(), outBitmapset(), PartitionPruneFixSubPlanMap(), postgresBeginForeignScan(), postgresExplainForeignScan(), postgresPlanForeignModify(), pub_collist_contains_invalid_column(), remove_join_clause_from_rels(), remove_useless_results_recurse(), SerializeParamExecParams(), show_eval_params(), and statext_is_compatible_clause().

◆ bms_nonempty_difference()

bool bms_nonempty_difference ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 564 of file bitmapset.c.

565 {
566  int shortlen;
567  int i;
568 
569  /* Handle cases where either input is NULL */
570  if (a == NULL)
571  return false;
572  if (b == NULL)
573  return true;
574  /* Check words in common */
575  shortlen = Min(a->nwords, b->nwords);
576  for (i = 0; i < shortlen; i++)
577  {
578  if ((a->words[i] & ~b->words[i]) != 0)
579  return true;
580  }
581  /* Check extra words in a */
582  for (; i < a->nwords; i++)
583  {
584  if (a->words[i] != 0)
585  return true;
586  }
587  return false;
588 }

References a, b, i, and Min.

Referenced by add_placeholders_to_base_rels(), add_placeholders_to_joinrel(), allow_star_schema_join(), bms_difference(), build_joinrel_tlist(), ExecReScanMemoize(), foreign_join_ok(), and use_physical_tlist().

◆ bms_num_members()

◆ bms_overlap()

bool bms_overlap ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 511 of file bitmapset.c.

512 {
513  int shortlen;
514  int i;
515 
516  /* Handle cases where either input is NULL */
517  if (a == NULL || b == NULL)
518  return false;
519  /* Check words in common */
520  shortlen = Min(a->nwords, b->nwords);
521  for (i = 0; i < shortlen; i++)
522  {
523  if ((a->words[i] & b->words[i]) != 0)
524  return true;
525  }
526  return false;
527 }

References a, b, i, and Min.

Referenced by add_child_join_rel_equivalences(), add_nulling_relids_mutator(), add_paths_to_joinrel(), adjust_child_relids_multilevel(), allow_star_schema_join(), calc_nestloop_required_outer(), calc_non_nestloop_required_outer(), choose_bitmap_and(), classify_matching_subplans(), clause_is_computable_at(), compute_semijoin_info(), create_nestloop_path(), deconstruct_distribute_oj_quals(), distribute_qual_to_rels(), eclass_useful_for_merging(), ExecInitStoredGenerated(), ExecReScanAgg(), ExecReScanAppend(), ExecReScanFunctionScan(), ExecReScanMergeAppend(), ExecUpdateLockMode(), generate_implied_equalities_for_column(), generate_join_implied_equalities(), generate_join_implied_equalities_for_ecs(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_dependent_generated_columns(), get_joinrel_parampathinfo(), get_useful_ecs_for_relation(), has_join_restriction(), has_legal_joinclause(), has_partition_attrs(), have_dangerous_phv(), have_join_order_restriction(), have_partkey_equi_join(), have_relevant_eclass_joinclause(), have_relevant_joinclause(), heap_update(), join_clause_is_movable_into(), join_clause_is_movable_to(), join_is_legal(), join_is_removable(), join_search_one_level(), make_join_rel(), make_outerjoininfo(), make_rels_by_clause_joins(), make_rels_by_clauseless_joins(), make_restrictinfo_internal(), mbms_overlap_sets(), partitions_are_ordered(), reduce_outer_joins_pass2(), remove_nulling_relids_mutator(), reparameterize_path_by_child(), select_outer_pathkeys_for_merge(), set_append_rel_size(), try_hashjoin_path(), try_mergejoin_path(), try_nestloop_path(), and try_partitionwise_join().

◆ bms_overlap_list()

bool bms_overlap_list ( const Bitmapset a,
const List b 
)

Definition at line 533 of file bitmapset.c.

534 {
535  ListCell *lc;
536  int wordnum,
537  bitnum;
538 
539  if (a == NULL || b == NIL)
540  return false;
541 
542  foreach(lc, b)
543  {
544  int x = lfirst_int(lc);
545 
546  if (x < 0)
547  elog(ERROR, "negative bitmapset member not allowed");
548  wordnum = WORDNUM(x);
549  bitnum = BITNUM(x);
550  if (wordnum < a->nwords)
551  if ((a->words[wordnum] & ((bitmapword) 1 << bitnum)) != 0)
552  return true;
553  }
554 
555  return false;
556 }
#define NIL
Definition: pg_list.h:68
#define lfirst_int(lc)
Definition: pg_list.h:173

References a, b, BITNUM, elog(), ERROR, lfirst_int, NIL, WORDNUM, and x.

Referenced by preprocess_grouping_sets().

◆ bms_prev_member()

int bms_prev_member ( const Bitmapset a,
int  prevbit 
)

Definition at line 1098 of file bitmapset.c.

1099 {
1100  int wordnum;
1101  int ushiftbits;
1102  bitmapword mask;
1103 
1104  /*
1105  * If set is NULL or if there are no more bits to the right then we've
1106  * nothing to do.
1107  */
1108  if (a == NULL || prevbit == 0)
1109  return -2;
1110 
1111  /* transform -1 to the highest possible bit we could have set */
1112  if (prevbit == -1)
1113  prevbit = a->nwords * BITS_PER_BITMAPWORD - 1;
1114  else
1115  prevbit--;
1116 
1117  ushiftbits = BITS_PER_BITMAPWORD - (BITNUM(prevbit) + 1);
1118  mask = (~(bitmapword) 0) >> ushiftbits;
1119  for (wordnum = WORDNUM(prevbit); wordnum >= 0; wordnum--)
1120  {
1121  bitmapword w = a->words[wordnum];
1122 
1123  /* mask out bits left of prevbit */
1124  w &= mask;
1125 
1126  if (w != 0)
1127  {
1128  int result;
1129 
1130  result = wordnum * BITS_PER_BITMAPWORD;
1131  result += bmw_leftmost_one_pos(w);
1132  return result;
1133  }
1134 
1135  /* in subsequent words, consider all bits */
1136  mask = (~(bitmapword) 0);
1137  }
1138  return -2;
1139 }
#define bmw_leftmost_one_pos(w)
Definition: bitmapset.c:56

References a, BITNUM, BITS_PER_BITMAPWORD, bmw_leftmost_one_pos, and WORDNUM.

Referenced by choose_next_subplan_locally().

◆ bms_singleton_member()

int bms_singleton_member ( const Bitmapset a)

Definition at line 596 of file bitmapset.c.

597 {
598  int result = -1;
599  int nwords;
600  int wordnum;
601 
602  if (a == NULL)
603  elog(ERROR, "bitmapset is empty");
604  nwords = a->nwords;
605  for (wordnum = 0; wordnum < nwords; wordnum++)
606  {
607  bitmapword w = a->words[wordnum];
608 
609  if (w != 0)
610  {
611  if (result >= 0 || HAS_MULTIPLE_ONES(w))
612  elog(ERROR, "bitmapset has multiple members");
613  result = wordnum * BITS_PER_BITMAPWORD;
614  result += bmw_rightmost_one_pos(w);
615  }
616  }
617  if (result < 0)
618  elog(ERROR, "bitmapset is empty");
619  return result;
620 }

References a, BITS_PER_BITMAPWORD, bmw_rightmost_one_pos, elog(), ERROR, and HAS_MULTIPLE_ONES.

Referenced by distribute_restrictinfo_to_rels(), examine_variable(), find_join_input_rel(), fix_append_rel_relids(), get_matching_part_pairs(), and remove_useless_joins().

◆ bms_subset_compare()

BMS_Comparison bms_subset_compare ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 369 of file bitmapset.c.

370 {
371  BMS_Comparison result;
372  int shortlen;
373  int longlen;
374  int i;
375 
376  /* Handle cases where either input is NULL */
377  if (a == NULL)
378  {
379  if (b == NULL)
380  return BMS_EQUAL;
381  return BMS_SUBSET1;
382  }
383  if (b == NULL)
384  return BMS_SUBSET2;
385  /* Check common words */
386  result = BMS_EQUAL; /* status so far */
387  shortlen = Min(a->nwords, b->nwords);
388  for (i = 0; i < shortlen; i++)
389  {
390  bitmapword aword = a->words[i];
391  bitmapword bword = b->words[i];
392 
393  if ((aword & ~bword) != 0)
394  {
395  /* a is not a subset of b */
396  if (result == BMS_SUBSET1)
397  return BMS_DIFFERENT;
398  result = BMS_SUBSET2;
399  }
400  if ((bword & ~aword) != 0)
401  {
402  /* b is not a subset of a */
403  if (result == BMS_SUBSET2)
404  return BMS_DIFFERENT;
405  result = BMS_SUBSET1;
406  }
407  }
408  /* Check extra words */
409  if (a->nwords > b->nwords)
410  {
411  longlen = a->nwords;
412  for (; i < longlen; i++)
413  {
414  if (a->words[i] != 0)
415  {
416  /* a is not a subset of b */
417  if (result == BMS_SUBSET1)
418  return BMS_DIFFERENT;
419  result = BMS_SUBSET2;
420  }
421  }
422  }
423  else if (a->nwords < b->nwords)
424  {
425  longlen = b->nwords;
426  for (; i < longlen; i++)
427  {
428  if (b->words[i] != 0)
429  {
430  /* b is not a subset of a */
431  if (result == BMS_SUBSET2)
432  return BMS_DIFFERENT;
433  result = BMS_SUBSET1;
434  }
435  }
436  }
437  return result;
438 }
BMS_Comparison
Definition: bitmapset.h:61
@ BMS_DIFFERENT
Definition: bitmapset.h:65
@ BMS_SUBSET1
Definition: bitmapset.h:63
@ BMS_EQUAL
Definition: bitmapset.h:62
@ BMS_SUBSET2
Definition: bitmapset.h:64

References a, b, BMS_DIFFERENT, BMS_EQUAL, BMS_SUBSET1, BMS_SUBSET2, i, and Min.

Referenced by add_path(), consider_index_join_outer_rels(), remove_useless_groupby_columns(), and set_cheapest().

◆ bms_union()

Bitmapset* bms_union ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 226 of file bitmapset.c.

227 {
228  Bitmapset *result;
229  const Bitmapset *other;
230  int otherlen;
231  int i;
232 
233  /* Handle cases where either input is NULL */
234  if (a == NULL)
235  return bms_copy(b);
236  if (b == NULL)
237  return bms_copy(a);
238  /* Identify shorter and longer input; copy the longer one */
239  if (a->nwords <= b->nwords)
240  {
241  result = bms_copy(b);
242  other = a;
243  }
244  else
245  {
246  result = bms_copy(a);
247  other = b;
248  }
249  /* And union the shorter input into the result */
250  otherlen = other->nwords;
251  for (i = 0; i < otherlen; i++)
252  result->words[i] |= other->words[i];
253  return result;
254 }

References a, b, bms_copy(), i, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_nulling_relids_mutator(), build_child_join_rel(), build_join_rel(), build_joinrel_restrictlist(), BuildParameterizedTidPaths(), calc_nestloop_required_outer(), calc_non_nestloop_required_outer(), check_index_predicates(), check_relation_privileges(), compute_semijoin_info(), consider_index_join_outer_rels(), create_join_clause(), create_nestloop_plan(), deconstruct_distribute(), deconstruct_distribute_oj_quals(), deconstruct_jointree(), deconstruct_recurse(), ExecConstraints(), ExecGetAllUpdatedCols(), ExecPartitionCheckEmitError(), ExecWithCheckOptions(), finalize_plan(), find_hash_columns(), foreign_join_ok(), generate_join_implied_equalities(), generate_join_implied_equalities_for_ecs(), generate_nonunion_paths(), generate_recursion_path(), generate_union_paths(), get_baserel_parampathinfo(), get_joinrel_parampathinfo(), get_rel_all_updated_cols(), has_legal_joinclause(), index_unchanged_by_update(), join_is_removable(), make_join_rel(), make_outerjoininfo(), make_restrictinfo_internal(), markNullableIfNeeded(), min_join_parameterization(), postgresGetForeignPaths(), pull_up_sublinks_jointree_recurse(), reduce_unique_semijoins(), remove_useless_joins(), resolve_special_varno(), substitute_phv_relids_walker(), and try_partitionwise_join().