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

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)
 
bool bms_is_empty (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_first_member (Bitmapset *a)
 
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 32 of file bitmapset.c.

◆ BITNUM

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

Definition at line 30 of file bitmapset.c.

◆ bmw_leftmost_one_pos

#define bmw_leftmost_one_pos (   w)    pg_leftmost_one_pos32(w)

Definition at line 58 of file bitmapset.c.

◆ bmw_popcount

#define bmw_popcount (   w)    pg_popcount32(w)

Definition at line 60 of file bitmapset.c.

◆ bmw_rightmost_one_pos

#define bmw_rightmost_one_pos (   w)    pg_rightmost_one_pos32(w)

Definition at line 59 of file bitmapset.c.

◆ HAS_MULTIPLE_ONES

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

Definition at line 54 of file bitmapset.c.

◆ RIGHTMOST_ONE

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

Definition at line 52 of file bitmapset.c.

◆ WORDNUM

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

Definition at line 29 of file bitmapset.c.

Function Documentation

◆ bitmap_hash()

uint32 bitmap_hash ( const void *  key,
Size  keysize 
)

Definition at line 1179 of file bitmapset.c.

1180 {
1181  Assert(keysize == sizeof(Bitmapset *));
1182  return bms_hash_value(*((const Bitmapset *const *) key));
1183 }
uint32 bms_hash_value(const Bitmapset *a)
Definition: bitmapset.c:1156
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 1189 of file bitmapset.c.

1190 {
1191  Assert(keysize == sizeof(Bitmapset *));
1192  return !bms_equal(*((const Bitmapset *const *) key1),
1193  *((const Bitmapset *const *) key2));
1194 }
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 738 of file bitmapset.c.

739 {
740  int wordnum,
741  bitnum;
742 
743  if (x < 0)
744  elog(ERROR, "negative bitmapset member not allowed");
745  if (a == NULL)
746  return bms_make_singleton(x);
747  wordnum = WORDNUM(x);
748  bitnum = BITNUM(x);
749 
750  /* enlarge the set if necessary */
751  if (wordnum >= a->nwords)
752  {
753  int oldnwords = a->nwords;
754  int i;
755 
756  a = (Bitmapset *) repalloc(a, BITMAPSET_SIZE(wordnum + 1));
757  a->nwords = wordnum + 1;
758  /* zero out the enlarged portion */
759  for (i = oldnwords; i < a->nwords; i++)
760  a->words[i] = 0;
761  }
762 
763  a->words[wordnum] |= ((bitmapword) 1 << bitnum);
764  return a;
765 }
#define BITMAPSET_SIZE(nwords)
Definition: bitmapset.c:32
#define WORDNUM(x)
Definition: bitmapset.c:29
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:186
#define BITNUM(x)
Definition: bitmapset.c:30
uint32 bitmapword
Definition: bitmapset.h:44
#define ERROR
Definition: elog.h:33
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:1188

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_appendrel_attrs_multilevel(), adjust_child_relids(), adjust_child_relids_multilevel(), adjust_relid_set(), adjust_view_column_set(), alias_relid_set(), AlterPublicationTables(), apply_handle_update(), 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(), deparseColumnRef(), dependencies_clauselist_selectivity(), DiscreteKnapsack(), do_analyze_rel(), DoCopy(), estimate_multivariate_ndistinct(), EvalPlanQualBegin(), ExecAsyncAppendResponse(), ExecBuildUpdateProjection(), ExecInitAgg(), ExecInitAppend(), ExecNestLoop(), ExecRecursiveUnion(), ExecReScanGather(), ExecReScanGatherMerge(), ExecReScanRecursiveUnion(), ExecReScanSetParamPlan(), ExecScanSubPlan(), ExecSetParamPlan(), execute_attr_map_cols(), expand_single_inheritance_child(), ExplainPreScanNode(), ExplainSubPlans(), extract_rollup_sets(), extractRemainingColumns(), fetch_remote_table_info(), fetch_statentries_for_relation(), fill_extraUpdatedCols(), 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(), get_eclass_for_sort_expr(), get_matching_partitions(), get_primary_key_attnos(), get_relation_constraint_attnos(), get_relation_statistics(), get_relids_in_jointree(), HeapDetermineColumnsInfo(), infer_arbiter_indexes(), load_enum_cache_data(), logicalrep_read_attrs(), make_datum_param(), make_modifytable(), make_one_rel(), make_partition_pruneinfo(), make_partitionedrel_pruneinfo(), make_row_comparison_op(), make_window_input_target(), makeDependencyGraphWalker(), markRTEForSelectPriv(), 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(), RelationGetIdentityKeyBitmap(), RelationGetIndexAttrBitmap(), remove_useless_groupby_columns(), 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_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 795 of file bitmapset.c.

796 {
797  Bitmapset *result;
798  const Bitmapset *other;
799  int otherlen;
800  int i;
801 
802  /* Handle cases where either input is NULL */
803  if (a == NULL)
804  return bms_copy(b);
805  if (b == NULL)
806  return a;
807  /* Identify shorter and longer input; copy the longer one if needed */
808  if (a->nwords < b->nwords)
809  {
810  result = bms_copy(b);
811  other = a;
812  }
813  else
814  {
815  result = a;
816  other = b;
817  }
818  /* And union the shorter input into the result */
819  otherlen = other->nwords;
820  for (i = 0; i < otherlen; i++)
821  result->words[i] |= other->words[i];
822  if (result != a)
823  pfree(a);
824  return result;
825 }
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:1175
int nwords
Definition: bitmapset.h:51
bitmapword words[FLEXIBLE_ARRAY_MEMBER]
Definition: bitmapset.h:52

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(), build_index_paths(), check_outerjoin_delay(), choose_best_statistics(), choose_bitmap_and(), create_bitmap_and_path(), create_bitmap_or_path(), create_lateral_join_info(), CreatePartitionPruneState(), deconstruct_recurse(), DiscreteKnapsack(), ExecFindMatchingSubPlans(), ExecInitAgg(), expand_partitioned_rtentry(), ExplainPreScanNode(), finalize_plan(), find_nonnullable_rels_walker(), foreign_join_ok(), get_eclass_indexes_for_relids(), heap_update(), join_is_legal(), make_outerjoininfo(), perform_pruning_combine_step(), pull_varnos_walker(), reduce_outer_joins_pass1(), reduce_outer_joins_pass2(), statext_is_compatible_clause(), transformOnConflictArbiter(), try_partitionwise_join(), and update_placeholder_eval_levels().

◆ bms_add_range()

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

Definition at line 836 of file bitmapset.c.

837 {
838  int lwordnum,
839  lbitnum,
840  uwordnum,
841  ushiftbits,
842  wordnum;
843 
844  /* do nothing if nothing is called for, without further checking */
845  if (upper < lower)
846  return a;
847 
848  if (lower < 0)
849  elog(ERROR, "negative bitmapset member not allowed");
850  uwordnum = WORDNUM(upper);
851 
852  if (a == NULL)
853  {
854  a = (Bitmapset *) palloc0(BITMAPSET_SIZE(uwordnum + 1));
855  a->nwords = uwordnum + 1;
856  }
857  else if (uwordnum >= a->nwords)
858  {
859  int oldnwords = a->nwords;
860  int i;
861 
862  /* ensure we have enough words to store the upper bit */
863  a = (Bitmapset *) repalloc(a, BITMAPSET_SIZE(uwordnum + 1));
864  a->nwords = uwordnum + 1;
865  /* zero out the enlarged portion */
866  for (i = oldnwords; i < a->nwords; i++)
867  a->words[i] = 0;
868  }
869 
870  wordnum = lwordnum = WORDNUM(lower);
871 
872  lbitnum = BITNUM(lower);
873  ushiftbits = BITS_PER_BITMAPWORD - (BITNUM(upper) + 1);
874 
875  /*
876  * Special case when lwordnum is the same as uwordnum we must perform the
877  * upper and lower masking on the word.
878  */
879  if (lwordnum == uwordnum)
880  {
881  a->words[lwordnum] |= ~(bitmapword) (((bitmapword) 1 << lbitnum) - 1)
882  & (~(bitmapword) 0) >> ushiftbits;
883  }
884  else
885  {
886  /* turn on lbitnum and all bits left of it */
887  a->words[wordnum++] |= ~(bitmapword) (((bitmapword) 1 << lbitnum) - 1);
888 
889  /* turn on all bits for any intermediate words */
890  while (wordnum < uwordnum)
891  a->words[wordnum++] = ~(bitmapword) 0;
892 
893  /* turn on upper's bit and all bits right of it. */
894  a->words[uwordnum] |= (~(bitmapword) 0) >> ushiftbits;
895  }
896 
897  return a;
898 }
#define BITS_PER_BITMAPWORD
Definition: bitmapset.h:43
void * palloc0(Size size)
Definition: mcxt.c:1099
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:48
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:79

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 bms_is_empty(b) ? 0 : -1;
155  else if (b == NULL)
156  return bms_is_empty(a) ? 0 : +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 }
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:703
#define Min(x, y)
Definition: c.h:997

References a, b, bms_is_empty(), i, and Min.

Referenced by append_startup_cost_compare(), and append_total_cost_compare().

◆ bms_copy()

Bitmapset* bms_copy ( const Bitmapset a)

Definition at line 74 of file bitmapset.c.

75 {
76  Bitmapset *result;
77  size_t size;
78 
79  if (a == NULL)
80  return NULL;
81  size = BITMAPSET_SIZE(a->nwords);
82  result = (Bitmapset *) palloc(size);
83  memcpy(result, a, size);
84  return result;
85 }
void * palloc(Size size)
Definition: mcxt.c:1068

References a, BITMAPSET_SIZE, and palloc().

Referenced by adjust_child_relids(), adjust_relid_set(), bms_add_members(), bms_difference(), bms_intersect(), bms_union(), build_child_join_rel(), build_index_paths(), build_join_rel(), build_simple_rel(), calc_nestloop_required_outer(), check_equivalence_delay(), check_outerjoin_delay(), choose_bitmap_and(), classify_matching_subplans(), create_lateral_join_info(), CreatePartitionPruneState(), DiscreteKnapsack(), distribute_qual_to_rels(), ExecFindMatchingSubPlans(), expand_single_inheritance_child(), fetch_upper_rel(), finalize_plan(), finalize_primnode(), find_hash_columns(), find_placeholder_info(), fixup_whole_row_references(), generate_base_implied_equalities_const(), generate_base_implied_equalities_no_const(), get_relation_statistics_worker(), innerrel_is_unique(), join_is_legal(), load_enum_cache_data(), logicalrep_partition_open(), logicalrep_relmap_update(), make_outerjoininfo(), partition_bounds_copy(), perform_pruning_combine_step(), process_implied_equality(), reconsider_full_join_clause(), reconsider_outer_join_clause(), RelationGetIdentityKeyBitmap(), RelationGetIndexAttrBitmap(), remove_rel_from_query(), and reparameterize_path_by_child().

◆ bms_del_member()

Bitmapset* bms_del_member ( Bitmapset a,
int  x 
)

Definition at line 775 of file bitmapset.c.

776 {
777  int wordnum,
778  bitnum;
779 
780  if (x < 0)
781  elog(ERROR, "negative bitmapset member not allowed");
782  if (a == NULL)
783  return NULL;
784  wordnum = WORDNUM(x);
785  bitnum = BITNUM(x);
786  if (wordnum < a->nwords)
787  a->words[wordnum] &= ~((bitmapword) 1 << bitnum);
788  return a;
789 }

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

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

◆ bms_del_members()

Bitmapset* bms_del_members ( Bitmapset a,
const Bitmapset b 
)

Definition at line 930 of file bitmapset.c.

931 {
932  int shortlen;
933  int i;
934 
935  /* Handle cases where either input is NULL */
936  if (a == NULL)
937  return NULL;
938  if (b == NULL)
939  return a;
940  /* Remove b's bits from a; we need never copy */
941  shortlen = Min(a->nwords, b->nwords);
942  for (i = 0; i < shortlen; i++)
943  a->words[i] &= ~b->words[i];
944  return a;
945 }

References a, b, i, and Min.

Referenced by build_join_rel(), calc_nestloop_required_outer(), classify_matching_subplans(), DiscreteKnapsack(), finalize_plan(), make_partition_pruneinfo(), and min_join_parameterization().

◆ bms_difference()

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

Definition at line 291 of file bitmapset.c.

292 {
293  Bitmapset *result;
294  int shortlen;
295  int i;
296 
297  /* Handle cases where either input is NULL */
298  if (a == NULL)
299  return NULL;
300  if (b == NULL)
301  return bms_copy(a);
302  /* Copy the left input */
303  result = bms_copy(a);
304  /* And remove b's bits from result */
305  shortlen = Min(a->nwords, b->nwords);
306  for (i = 0; i < shortlen; i++)
307  result->words[i] &= ~b->words[i];
308  return result;
309 }

References a, b, bms_copy(), 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(), finalize_plan(), find_placeholder_info(), pull_varnos_walker(), 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 bms_is_empty(b);
108  }
109  else if (b == NULL)
110  return bms_is_empty(a);
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, bms_is_empty(), i, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_path_precheck(), add_paths_to_append_rel(), adjust_appendrel_attrs_multilevel(), adjust_child_relids_multilevel(), AlterPublicationTables(), bitmap_match(), bms_equal_any(), choose_bitmap_and(), create_append_path(), create_merge_append_path(), create_unique_path(), 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(), has_join_restriction(), infer_arbiter_indexes(), is_safe_restriction_clause_for(), join_is_legal(), make_one_rel(), make_partitionedrel_pruneinfo(), match_pathkeys_to_index(), pgoutput_column_list_init(), populate_joinrel_with_paths(), pull_varnos_walker(), and try_partitionwise_join().

◆ bms_first_member()

int bms_first_member ( Bitmapset a)

Definition at line 998 of file bitmapset.c.

999 {
1000  int nwords;
1001  int wordnum;
1002 
1003  if (a == NULL)
1004  return -1;
1005  nwords = a->nwords;
1006  for (wordnum = 0; wordnum < nwords; wordnum++)
1007  {
1008  bitmapword w = a->words[wordnum];
1009 
1010  if (w != 0)
1011  {
1012  int result;
1013 
1014  w = RIGHTMOST_ONE(w);
1015  a->words[wordnum] &= ~w;
1016 
1017  result = wordnum * BITS_PER_BITMAPWORD;
1018  result += bmw_rightmost_one_pos(w);
1019  return result;
1020  }
1021  }
1022  return -1;
1023 }
#define bmw_rightmost_one_pos(w)
Definition: bitmapset.c:59
#define RIGHTMOST_ONE(x)
Definition: bitmapset.c:52

References a, BITS_PER_BITMAPWORD, bmw_rightmost_one_pos, and RIGHTMOST_ONE.

Referenced by check_relation_privileges(), check_selective_binary_conversion(), convert_EXISTS_sublink_to_join(), find_hash_columns(), HeapDetermineColumnsInfo(), logicalrep_report_missing_attrs(), and make_row_comparison_op().

◆ bms_free()

◆ bms_get_singleton_member()

bool bms_get_singleton_member ( const Bitmapset a,
int *  member 
)

Definition at line 617 of file bitmapset.c.

618 {
619  int result = -1;
620  int nwords;
621  int wordnum;
622 
623  if (a == NULL)
624  return false;
625  nwords = a->nwords;
626  for (wordnum = 0; wordnum < nwords; wordnum++)
627  {
628  bitmapword w = a->words[wordnum];
629 
630  if (w != 0)
631  {
632  if (result >= 0 || HAS_MULTIPLE_ONES(w))
633  return false;
634  result = wordnum * BITS_PER_BITMAPWORD;
635  result += bmw_rightmost_one_pos(w);
636  }
637  }
638  if (result < 0)
639  return false;
640  *member = result;
641  return true;
642 }
#define HAS_MULTIPLE_ONES(x)
Definition: bitmapset.c:54

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 1156 of file bitmapset.c.

1157 {
1158  int lastword;
1159 
1160  if (a == NULL)
1161  return 0; /* All empty sets hash to 0 */
1162  for (lastword = a->nwords; --lastword >= 0;)
1163  {
1164  if (a->words[lastword] != 0)
1165  break;
1166  }
1167  if (lastword < 0)
1168  return 0; /* All empty sets hash to 0 */
1169  return DatumGetUInt32(hash_any((const unsigned char *) a->words,
1170  (lastword + 1) * sizeof(bitmapword)));
1171 }
static Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.h:31
#define DatumGetUInt32(X)
Definition: postgres.h:530

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 904 of file bitmapset.c.

905 {
906  int shortlen;
907  int i;
908 
909  /* Handle cases where either input is NULL */
910  if (a == NULL)
911  return NULL;
912  if (b == NULL)
913  {
914  pfree(a);
915  return NULL;
916  }
917  /* Intersect b into a; we need never copy */
918  shortlen = Min(a->nwords, b->nwords);
919  for (i = 0; i < shortlen; i++)
920  a->words[i] &= b->words[i];
921  for (; i < a->nwords; i++)
922  a->words[i] = 0;
923  return a;
924 }

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

Referenced by check_outerjoin_delay(), classify_matching_subplans(), find_nonnullable_rels_walker(), find_placeholder_info(), get_common_eclass_indexes(), make_outerjoininfo(), make_row_comparison_op(), perform_pruning_combine_step(), and relation_is_updatable().

◆ bms_intersect()

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

Definition at line 259 of file bitmapset.c.

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

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

Referenced by get_eclass_for_sort_expr(), get_matching_part_pairs(), make_outerjoininfo(), match_eclasses_to_foreign_key_col(), process_equivalence(), reconsider_full_join_clause(), reconsider_outer_join_clause(), set_param_references(), and UpdateChangedParamSet().

◆ bms_is_empty()

bool bms_is_empty ( const Bitmapset a)

Definition at line 703 of file bitmapset.c.

704 {
705  int nwords;
706  int wordnum;
707 
708  if (a == NULL)
709  return true;
710  nwords = a->nwords;
711  for (wordnum = 0; wordnum < nwords; wordnum++)
712  {
713  bitmapword w = a->words[wordnum];
714 
715  if (w != 0)
716  return false;
717  }
718  return true;
719 }

References a.

Referenced by add_eq_member(), add_vars_to_targetlist(), bms_compare(), bms_equal(), bms_is_subset(), bms_nonempty_difference(), bms_subset_compare(), build_index_paths(), build_join_rel(), calc_nestloop_required_outer(), check_index_predicates(), classify_matching_subplans(), compute_semijoin_info(), consider_groupingsets_paths(), convert_ANY_sublink_to_join(), convert_EXISTS_sublink_to_join(), create_foreign_join_path(), create_foreign_upper_path(), create_lateral_join_info(), distribute_qual_to_rels(), eclass_useful_for_merging(), ExecAppend(), ExecAppendAsyncBegin(), ExecAppendAsyncRequest(), ExecCheckRTEPerms(), ExecCheckRTEPermsModified(), ExecInitParallelPlan(), ExecParallelReinitialize(), ExecReScanSetParamPlan(), ExtractReplicaIdentity(), filter_event_trigger(), finalize_plan(), find_em_for_rel(), find_nonnullable_rels_walker(), find_placeholder_info(), find_single_rel_for_clauses(), findDefaultOnlyColumns(), gen_partprune_steps_internal(), generate_join_implied_equalities(), generate_join_implied_equalities_for_ecs(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_cheapest_parallel_safe_total_inner(), get_joinrel_parampathinfo(), get_matching_list_bounds(), get_matching_range_bounds(), get_steps_using_prefix_recurse(), get_useful_ecs_for_relation(), GetParentedForeignKeyRefs(), hash_inner_and_outer(), is_pseudo_constant_clause_relids(), logicalrep_report_missing_attrs(), make_outerjoininfo(), make_partitionedrel_pruneinfo(), make_restrictinfo_internal(), match_clause_to_partition_key(), match_unsorted_outer(), min_join_parameterization(), PartitionPruneFixSubPlanMap(), pg_get_expr_worker(), postgresForeignAsyncConfigureWait(), postgresGetForeignJoinPaths(), postgresGetForeignPaths(), preprocess_grouping_sets(), process_equivalence(), process_implied_equality(), recurse_set_operations(), relation_has_unique_index_for(), relation_is_updatable(), remove_rel_from_query(), remove_result_refs(), rewriteTargetView(), sepgsql_dml_privileges(), set_subquery_pathlist(), sort_inner_and_outer(), substitute_phv_relids_walker(), TopologicalSort(), try_partial_hashjoin_path(), try_partial_mergejoin_path(), try_partial_nestloop_path(), UpdateChangedParamSet(), and use_physical_tlist().

◆ bms_is_member()

bool bms_is_member ( int  x,
const Bitmapset a 
)

Definition at line 427 of file bitmapset.c.

428 {
429  int wordnum,
430  bitnum;
431 
432  /* XXX better to just return false for x<0 ? */
433  if (x < 0)
434  elog(ERROR, "negative bitmapset member not allowed");
435  if (a == NULL)
436  return false;
437  wordnum = WORDNUM(x);
438  bitnum = BITNUM(x);
439  if (wordnum >= a->nwords)
440  return false;
441  if ((a->words[wordnum] & ((bitmapword) 1 << bitnum)) != 0)
442  return true;
443  return false;
444 }

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

Referenced by add_row_identity_var(), adjust_appendrel_attrs_mutator(), adjust_child_relids(), adjust_relid_set(), adjust_rowcount_for_semijoins(), bms_is_subset_singleton(), bms_member_index(), check_index_predicates(), check_redundant_nullability_qual(), check_relation_privileges(), checkInsertTargets(), clauselist_selectivity_ext(), clauselist_selectivity_or(), column_in_column_list(), ComputePartitionAttrs(), consider_groupingsets_paths(), contain_invalid_rfcolumn_walker(), cost_incremental_sort(), create_foreignscan_plan(), create_lateral_join_info(), 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(), ExecComputeStoredGenerated(), 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(), get_foreign_key_join_selectivity(), get_matching_hash_bounds(), get_translated_update_targetlist(), get_variable(), get_xmltable(), 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(), match_opclause_to_indexcol(), match_rowcompare_to_indexcol(), match_saopclause_to_indexcol(), 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(), 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_is_compatible_clause(), 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 315 of file bitmapset.c.

316 {
317  int shortlen;
318  int longlen;
319  int i;
320 
321  /* Handle cases where either input is NULL */
322  if (a == NULL)
323  return true; /* empty set is a subset of anything */
324  if (b == NULL)
325  return bms_is_empty(a);
326  /* Check common words */
327  shortlen = Min(a->nwords, b->nwords);
328  for (i = 0; i < shortlen; i++)
329  {
330  if ((a->words[i] & ~b->words[i]) != 0)
331  return false;
332  }
333  /* Check extra words */
334  if (a->nwords > b->nwords)
335  {
336  longlen = a->nwords;
337  for (; i < longlen; i++)
338  {
339  if (a->words[i] != 0)
340  return false;
341  }
342  }
343  return true;
344 }

References a, b, bms_is_empty(), i, and Min.

Referenced by add_child_rel_equivalences(), add_paths_to_joinrel(), add_placeholders_to_joinrel(), add_vars_to_targetlist(), check_functional_grouping(), check_index_only(), check_outerjoin_delay(), choose_best_statistics(), clause_sides_match_join(), compute_semijoin_info(), convert_ANY_sublink_to_join(), convert_EXISTS_sublink_to_join(), create_index_paths(), deconstruct_recurse(), 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(), 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(), statext_mcv_clauselist_selectivity(), subbuild_joinrel_joinlist(), subbuild_joinrel_restrictlist(), try_partial_nestloop_path(), update_placeholder_eval_levels(), and use_physical_tlist().

◆ bms_join()

Bitmapset* bms_join ( Bitmapset a,
Bitmapset b 
)

Definition at line 951 of file bitmapset.c.

952 {
953  Bitmapset *result;
954  Bitmapset *other;
955  int otherlen;
956  int i;
957 
958  /* Handle cases where either input is NULL */
959  if (a == NULL)
960  return b;
961  if (b == NULL)
962  return a;
963  /* Identify shorter and longer input; use longer one as result */
964  if (a->nwords < b->nwords)
965  {
966  result = b;
967  other = a;
968  }
969  else
970  {
971  result = a;
972  other = b;
973  }
974  /* And union the shorter input into the result */
975  otherlen = other->nwords;
976  for (i = 0; i < otherlen; i++)
977  result->words[i] |= other->words[i];
978  if (other != result) /* pure paranoia */
979  pfree(other);
980  return result;
981 }

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

Referenced by add_paths_to_joinrel(), alias_relid_set(), 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 453 of file bitmapset.c.

454 {
455  int i;
456  int bitnum;
457  int wordnum;
458  int result = 0;
459  bitmapword mask;
460 
461  /* return -1 if not a member of the bitmap */
462  if (!bms_is_member(x, a))
463  return -1;
464 
465  wordnum = WORDNUM(x);
466  bitnum = BITNUM(x);
467 
468  /* count bits in preceding words */
469  for (i = 0; i < wordnum; i++)
470  {
471  bitmapword w = a->words[i];
472 
473  /* No need to count the bits in a zero word */
474  if (w != 0)
475  result += bmw_popcount(w);
476  }
477 
478  /*
479  * Now add bits of the last word, but only those before the item. We can
480  * do that by applying a mask and then using popcount again. To get
481  * 0-based index, we want to count only preceding bits, not the item
482  * itself, so we subtract 1.
483  */
484  mask = ((bitmapword) 1 << bitnum) - 1;
485  result += bmw_popcount(a->words[wordnum] & mask);
486 
487  return result;
488 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
#define bmw_popcount(w)
Definition: bitmapset.c:60

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 674 of file bitmapset.c.

675 {
676  BMS_Membership result = BMS_EMPTY_SET;
677  int nwords;
678  int wordnum;
679 
680  if (a == NULL)
681  return BMS_EMPTY_SET;
682  nwords = a->nwords;
683  for (wordnum = 0; wordnum < nwords; wordnum++)
684  {
685  bitmapword w = a->words[wordnum];
686 
687  if (w != 0)
688  {
689  if (result != BMS_EMPTY_SET || HAS_MULTIPLE_ONES(w))
690  return BMS_MULTIPLE;
691  result = BMS_SINGLETON;
692  }
693  }
694  return result;
695 }
BMS_Membership
Definition: bitmapset.h:67
@ BMS_SINGLETON
Definition: bitmapset.h:69
@ BMS_EMPTY_SET
Definition: bitmapset.h:68
@ BMS_MULTIPLE
Definition: bitmapset.h:70

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

Referenced by add_child_join_rel_equivalences(), bms_is_subset_singleton(), clauselist_selectivity_ext(), 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(), generate_base_implied_equalities_const(), get_foreign_key_join_selectivity(), grouping_planner(), process_implied_equality(), remove_useless_groupby_columns(), set_rel_pathlist(), set_tablesample_rel_pathlist(), statext_mcv_clauselist_selectivity(), and treat_as_join_clause().

◆ bms_next_member()

int bms_next_member ( const Bitmapset a,
int  prevbit 
)

Definition at line 1045 of file bitmapset.c.

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

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_view_column_set(), alias_relid_set(), apply_scanjoin_target_to_paths(), approximate_joinrel_size(), build_attnums_array(), choose_next_subplan_for_worker(), choose_next_subplan_locally(), clauselist_apply_dependencies(), ComputePartitionAttrs(), create_lateral_join_info(), create_partitionwise_grouping_paths(), CreateStatistics(), deparseLockingClause(), dependencies_clauselist_selectivity(), EstimateParamExecSpace(), ExecAppendAsyncBegin(), ExecAppendAsyncEventWait(), ExecAppendAsyncRequest(), ExecCheckRTEPerms(), ExecCheckRTEPermsModified(), ExecInitAgg(), ExecInitAppend(), ExecInitMergeAppend(), ExecMergeAppend(), ExecReScanAppend(), ExecScanReScan(), ExecSetParamPlanMulti(), expand_partitioned_rtentry(), find_appinfos_by_relids(), find_dependent_phvs_in_jointree(), 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(), logicalrep_rel_mark_updatable(), lookup_var_attr_stats(), make_build_data(), make_partitionedrel_pruneinfo(), 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 547 of file bitmapset.c.

548 {
549  int shortlen;
550  int i;
551 
552  /* Handle cases where either input is NULL */
553  if (a == NULL)
554  return false;
555  if (b == NULL)
556  return !bms_is_empty(a);
557  /* Check words in common */
558  shortlen = Min(a->nwords, b->nwords);
559  for (i = 0; i < shortlen; i++)
560  {
561  if ((a->words[i] & ~b->words[i]) != 0)
562  return true;
563  }
564  /* Check extra words in a */
565  for (; i < a->nwords; i++)
566  {
567  if (a->words[i] != 0)
568  return true;
569  }
570  return false;
571 }

References a, b, bms_is_empty(), i, and Min.

Referenced by add_placeholders_to_base_rels(), add_placeholders_to_joinrel(), allow_star_schema_join(), 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 494 of file bitmapset.c.

495 {
496  int shortlen;
497  int i;
498 
499  /* Handle cases where either input is NULL */
500  if (a == NULL || b == NULL)
501  return false;
502  /* Check words in common */
503  shortlen = Min(a->nwords, b->nwords);
504  for (i = 0; i < shortlen; i++)
505  {
506  if ((a->words[i] & b->words[i]) != 0)
507  return true;
508  }
509  return false;
510 }

References a, b, i, and Min.

Referenced by add_child_join_rel_equivalences(), add_child_rel_equivalences(), add_paths_to_joinrel(), adjust_child_relids_multilevel(), allow_star_schema_join(), calc_nestloop_required_outer(), calc_non_nestloop_required_outer(), check_outerjoin_delay(), choose_bitmap_and(), classify_matching_subplans(), compute_semijoin_info(), create_nestloop_path(), distribute_qual_to_rels(), eclass_useful_for_merging(), ExecReScanAgg(), ExecReScanAppend(), ExecReScanFunctionScan(), ExecReScanMergeAppend(), ExecUpdateLockMode(), fill_extraUpdatedCols(), generate_implied_equalities_for_column(), generate_join_implied_equalities(), generate_join_implied_equalities_for_ecs(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), 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_relevant_eclass_joinclause(), have_relevant_joinclause(), heap_update(), identify_current_nestloop_params(), 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(), partitions_are_ordered(), pullup_replace_vars_callback(), reduce_outer_joins_pass2(), reparameterize_path_by_child(), replace_nestloop_params_mutator(), select_outer_pathkeys_for_merge(), try_hashjoin_path(), try_mergejoin_path(), try_nestloop_path(), try_partitionwise_join(), and update_placeholder_eval_levels().

◆ bms_overlap_list()

bool bms_overlap_list ( const Bitmapset a,
const List b 
)

Definition at line 516 of file bitmapset.c.

517 {
518  ListCell *lc;
519  int wordnum,
520  bitnum;
521 
522  if (a == NULL || b == NIL)
523  return false;
524 
525  foreach(lc, b)
526  {
527  int x = lfirst_int(lc);
528 
529  if (x < 0)
530  elog(ERROR, "negative bitmapset member not allowed");
531  wordnum = WORDNUM(x);
532  bitnum = BITNUM(x);
533  if (wordnum < a->nwords)
534  if ((a->words[wordnum] & ((bitmapword) 1 << bitnum)) != 0)
535  return true;
536  }
537 
538  return false;
539 }
#define NIL
Definition: pg_list.h:66
#define lfirst_int(lc)
Definition: pg_list.h:171

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 1104 of file bitmapset.c.

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

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 579 of file bitmapset.c.

580 {
581  int result = -1;
582  int nwords;
583  int wordnum;
584 
585  if (a == NULL)
586  elog(ERROR, "bitmapset is empty");
587  nwords = a->nwords;
588  for (wordnum = 0; wordnum < nwords; wordnum++)
589  {
590  bitmapword w = a->words[wordnum];
591 
592  if (w != 0)
593  {
594  if (result >= 0 || HAS_MULTIPLE_ONES(w))
595  elog(ERROR, "bitmapset has multiple members");
596  result = wordnum * BITS_PER_BITMAPWORD;
597  result += bmw_rightmost_one_pos(w);
598  }
599  }
600  if (result < 0)
601  elog(ERROR, "bitmapset is empty");
602  return result;
603 }

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 352 of file bitmapset.c.

353 {
354  BMS_Comparison result;
355  int shortlen;
356  int longlen;
357  int i;
358 
359  /* Handle cases where either input is NULL */
360  if (a == NULL)
361  {
362  if (b == NULL)
363  return BMS_EQUAL;
364  return bms_is_empty(b) ? BMS_EQUAL : BMS_SUBSET1;
365  }
366  if (b == NULL)
367  return bms_is_empty(a) ? BMS_EQUAL : BMS_SUBSET2;
368  /* Check common words */
369  result = BMS_EQUAL; /* status so far */
370  shortlen = Min(a->nwords, b->nwords);
371  for (i = 0; i < shortlen; i++)
372  {
373  bitmapword aword = a->words[i];
374  bitmapword bword = b->words[i];
375 
376  if ((aword & ~bword) != 0)
377  {
378  /* a is not a subset of b */
379  if (result == BMS_SUBSET1)
380  return BMS_DIFFERENT;
381  result = BMS_SUBSET2;
382  }
383  if ((bword & ~aword) != 0)
384  {
385  /* b is not a subset of a */
386  if (result == BMS_SUBSET2)
387  return BMS_DIFFERENT;
388  result = BMS_SUBSET1;
389  }
390  }
391  /* Check extra words */
392  if (a->nwords > b->nwords)
393  {
394  longlen = a->nwords;
395  for (; i < longlen; i++)
396  {
397  if (a->words[i] != 0)
398  {
399  /* a is not a subset of b */
400  if (result == BMS_SUBSET1)
401  return BMS_DIFFERENT;
402  result = BMS_SUBSET2;
403  }
404  }
405  }
406  else if (a->nwords < b->nwords)
407  {
408  longlen = b->nwords;
409  for (; i < longlen; i++)
410  {
411  if (b->words[i] != 0)
412  {
413  /* b is not a subset of a */
414  if (result == BMS_SUBSET2)
415  return BMS_DIFFERENT;
416  result = BMS_SUBSET1;
417  }
418  }
419  }
420  return result;
421 }
BMS_Comparison
Definition: bitmapset.h:58
@ BMS_DIFFERENT
Definition: bitmapset.h:62
@ BMS_SUBSET1
Definition: bitmapset.h:60
@ BMS_EQUAL
Definition: bitmapset.h:59
@ BMS_SUBSET2
Definition: bitmapset.h:61

References a, b, BMS_DIFFERENT, BMS_EQUAL, bms_is_empty(), 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 225 of file bitmapset.c.

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

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

Referenced by build_child_join_rel(), build_join_rel(), 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_path(), create_nestloop_plan(), deconstruct_recurse(), ExecConstraints(), ExecGetAllUpdatedCols(), ExecPartitionCheckEmitError(), ExecWithCheckOptions(), finalize_plan(), find_hash_columns(), foreign_join_ok(), generate_base_implied_equalities_const(), generate_base_implied_equalities_no_const(), 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(), has_legal_joinclause(), index_unchanged_by_update(), join_is_removable(), make_join_rel(), make_outerjoininfo(), make_restrictinfo_internal(), min_join_parameterization(), postgresGetForeignPaths(), postgresPlanForeignModify(), pull_up_sublinks_jointree_recurse(), reduce_unique_semijoins(), remove_useless_joins(), resolve_special_varno(), substitute_phv_relids_walker(), and try_partitionwise_join().