2003-02-08 15:20:55 -05:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* bitmapset.h
|
|
|
|
|
* PostgreSQL generic bitmap set package
|
|
|
|
|
*
|
|
|
|
|
* A bitmap set can represent any set of nonnegative integers, although
|
|
|
|
|
* it is mainly intended for sets where the maximum value is not large,
|
|
|
|
|
* say at most a few hundred. By convention, a NULL pointer is always
|
|
|
|
|
* accepted by all operations to represent the empty set. (But beware
|
|
|
|
|
* that this is not the only representation of the empty set. Use
|
|
|
|
|
* bms_is_empty() in preference to testing for NULL.)
|
|
|
|
|
*
|
|
|
|
|
*
|
2019-01-02 12:44:25 -05:00
|
|
|
* Copyright (c) 2003-2019, PostgreSQL Global Development Group
|
2003-02-08 15:20:55 -05:00
|
|
|
*
|
2010-09-20 16:08:53 -04:00
|
|
|
* src/include/nodes/bitmapset.h
|
2003-02-08 15:20:55 -05:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef BITMAPSET_H
|
|
|
|
|
#define BITMAPSET_H
|
|
|
|
|
|
2017-03-26 23:20:54 -04:00
|
|
|
/*
|
|
|
|
|
* Forward decl to save including pg_list.h
|
|
|
|
|
*/
|
|
|
|
|
struct List;
|
|
|
|
|
|
2003-02-08 15:20:55 -05:00
|
|
|
/*
|
|
|
|
|
* Data representation
|
2018-12-20 12:19:07 -05:00
|
|
|
*
|
|
|
|
|
* Larger bitmap word sizes generally give better performance, so long as
|
|
|
|
|
* they're not wider than the processor can handle efficiently. We use
|
|
|
|
|
* 64-bit words if pointers are that large, else 32-bit words.
|
2003-02-08 15:20:55 -05:00
|
|
|
*/
|
2018-12-20 12:19:07 -05:00
|
|
|
#if SIZEOF_VOID_P >= 8
|
|
|
|
|
|
|
|
|
|
#define BITS_PER_BITMAPWORD 64
|
|
|
|
|
typedef uint64 bitmapword; /* must be an unsigned type */
|
|
|
|
|
typedef int64 signedbitmapword; /* must be the matching signed type */
|
|
|
|
|
|
|
|
|
|
#else
|
2003-02-08 15:20:55 -05:00
|
|
|
|
|
|
|
|
#define BITS_PER_BITMAPWORD 32
|
|
|
|
|
typedef uint32 bitmapword; /* must be an unsigned type */
|
2003-08-03 20:43:34 -04:00
|
|
|
typedef int32 signedbitmapword; /* must be the matching signed type */
|
2003-02-08 15:20:55 -05:00
|
|
|
|
2018-12-20 12:19:07 -05:00
|
|
|
#endif
|
|
|
|
|
|
2003-08-03 20:43:34 -04:00
|
|
|
typedef struct Bitmapset
|
|
|
|
|
{
|
|
|
|
|
int nwords; /* number of words in array */
|
2015-02-20 00:11:42 -05:00
|
|
|
bitmapword words[FLEXIBLE_ARRAY_MEMBER]; /* really [nwords] */
|
|
|
|
|
} Bitmapset;
|
2003-02-08 15:20:55 -05:00
|
|
|
|
|
|
|
|
|
2012-01-27 19:26:38 -05:00
|
|
|
/* result of bms_subset_compare */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
BMS_EQUAL, /* sets are equal */
|
|
|
|
|
BMS_SUBSET1, /* first set is a subset of the second */
|
|
|
|
|
BMS_SUBSET2, /* second set is a subset of the first */
|
|
|
|
|
BMS_DIFFERENT /* neither set is a subset of the other */
|
|
|
|
|
} BMS_Comparison;
|
|
|
|
|
|
2003-02-08 15:20:55 -05:00
|
|
|
/* result of bms_membership */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
BMS_EMPTY_SET, /* 0 members */
|
|
|
|
|
BMS_SINGLETON, /* 1 member */
|
|
|
|
|
BMS_MULTIPLE /* >1 member */
|
2003-08-08 17:42:59 -04:00
|
|
|
} BMS_Membership;
|
2003-02-08 15:20:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* function prototypes in nodes/bitmapset.c
|
|
|
|
|
*/
|
|
|
|
|
|
2003-08-08 17:42:59 -04:00
|
|
|
extern Bitmapset *bms_copy(const Bitmapset *a);
|
|
|
|
|
extern bool bms_equal(const Bitmapset *a, const Bitmapset *b);
|
Improve the heuristic for ordering child paths of a parallel append.
Commit ab7271677 introduced code that attempts to order the child
scans of a Parallel Append node in a way that will minimize execution
time, based on total cost and startup cost. However, it failed to
think hard about what to do when estimated costs are exactly equal;
a case that's particularly likely to occur when comparing on startup
cost. In such a case the ordering of the child paths would be left
to the whims of qsort, an algorithm that isn't even stable.
We can improve matters by applying the rule used elsewhere in the
planner: if total costs are equal, sort on startup cost, and
vice versa. When both cost estimates are exactly equal, rather
than letting qsort do something unpredictable, sort based on the
child paths' relids, which should typically result in sorting in
inheritance order. (The latter provision requires inventing a
qsort-style comparator for bitmapsets, but maybe we'll have use
for that for other reasons in future.)
This results in a few plan changes in the select_parallel test,
but those all look more reasonable than before, when the actual
underlying cost numbers are taken into account.
Discussion: https://postgr.es/m/4944.1515446989@sss.pgh.pa.us
2018-01-09 13:07:52 -05:00
|
|
|
extern int bms_compare(const Bitmapset *a, const Bitmapset *b);
|
2003-02-08 15:20:55 -05:00
|
|
|
extern Bitmapset *bms_make_singleton(int x);
|
2003-08-08 17:42:59 -04:00
|
|
|
extern void bms_free(Bitmapset *a);
|
2003-08-03 20:43:34 -04:00
|
|
|
|
2003-08-08 17:42:59 -04:00
|
|
|
extern Bitmapset *bms_union(const Bitmapset *a, const Bitmapset *b);
|
|
|
|
|
extern Bitmapset *bms_intersect(const Bitmapset *a, const Bitmapset *b);
|
|
|
|
|
extern Bitmapset *bms_difference(const Bitmapset *a, const Bitmapset *b);
|
|
|
|
|
extern bool bms_is_subset(const Bitmapset *a, const Bitmapset *b);
|
2012-01-27 19:26:38 -05:00
|
|
|
extern BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b);
|
2003-08-08 17:42:59 -04:00
|
|
|
extern bool bms_is_member(int x, const Bitmapset *a);
|
|
|
|
|
extern bool bms_overlap(const Bitmapset *a, const Bitmapset *b);
|
2017-03-26 23:20:54 -04:00
|
|
|
extern bool bms_overlap_list(const Bitmapset *a, const struct List *b);
|
2003-08-08 17:42:59 -04:00
|
|
|
extern bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b);
|
|
|
|
|
extern int bms_singleton_member(const Bitmapset *a);
|
2014-11-28 14:16:24 -05:00
|
|
|
extern bool bms_get_singleton_member(const Bitmapset *a, int *member);
|
2003-08-08 17:42:59 -04:00
|
|
|
extern int bms_num_members(const Bitmapset *a);
|
2003-02-08 15:20:55 -05:00
|
|
|
|
|
|
|
|
/* optimized tests when we don't need to know exact membership count: */
|
2003-08-08 17:42:59 -04:00
|
|
|
extern BMS_Membership bms_membership(const Bitmapset *a);
|
|
|
|
|
extern bool bms_is_empty(const Bitmapset *a);
|
2003-02-08 15:20:55 -05:00
|
|
|
|
|
|
|
|
/* these routines recycle (modify or free) their non-const inputs: */
|
|
|
|
|
|
2003-08-08 17:42:59 -04:00
|
|
|
extern Bitmapset *bms_add_member(Bitmapset *a, int x);
|
|
|
|
|
extern Bitmapset *bms_del_member(Bitmapset *a, int x);
|
|
|
|
|
extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b);
|
2017-11-29 17:06:14 -05:00
|
|
|
extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper);
|
2003-08-08 17:42:59 -04:00
|
|
|
extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b);
|
|
|
|
|
extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b);
|
|
|
|
|
extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b);
|
2003-02-08 15:20:55 -05:00
|
|
|
|
|
|
|
|
/* support for iterating through the integer elements of a set: */
|
2003-08-08 17:42:59 -04:00
|
|
|
extern int bms_first_member(Bitmapset *a);
|
2014-11-28 13:37:25 -05:00
|
|
|
extern int bms_next_member(const Bitmapset *a, int prevbit);
|
2018-04-07 11:01:11 -04:00
|
|
|
extern int bms_prev_member(const Bitmapset *a, int prevbit);
|
2003-02-08 15:20:55 -05:00
|
|
|
|
2005-06-08 19:02:05 -04:00
|
|
|
/* support for hashtables using Bitmapsets as keys: */
|
|
|
|
|
extern uint32 bms_hash_value(const Bitmapset *a);
|
|
|
|
|
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 15:18:54 -04:00
|
|
|
#endif /* BITMAPSET_H */
|