mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Make Bitmapsets be valid Nodes.
Add a NodeTag field to struct Bitmapset. This is free because of alignment considerations on 64-bit hardware. While it adds some space on 32-bit machines, we aren't optimizing for that case anymore. The advantage is that data structures such as Lists of Bitmapsets are now first-class objects to the Node infrastructure, and don't require special-case code to handle. This patch includes removal of one such special case, in indxpath.c: bms_equal_any() can now be replaced by list_member(). There may be more existing code that could be simplified, but I didn't look very hard. We also get to drop the read_write_ignore annotations on a couple of RelOptInfo fields. The outfuncs/readfuncs support is arranged so that nothing changes in the string representation of a Bitmapset field; therefore, this doesn't need a catversion bump. Amit Langote and Tom Lane Discussion: https://postgr.es/m/109089.1668197158@sss.pgh.pa.us
This commit is contained in:
@@ -52,6 +52,7 @@ node_headers = \
|
||||
commands/trigger.h \
|
||||
executor/tuptable.h \
|
||||
foreign/fdwapi.h \
|
||||
nodes/bitmapset.h \
|
||||
nodes/extensible.h \
|
||||
nodes/lockoptions.h \
|
||||
nodes/replnodes.h \
|
||||
|
||||
@@ -194,6 +194,7 @@ bms_make_singleton(int x)
|
||||
wordnum = WORDNUM(x);
|
||||
bitnum = BITNUM(x);
|
||||
result = (Bitmapset *) palloc0(BITMAPSET_SIZE(wordnum + 1));
|
||||
result->type = T_Bitmapset;
|
||||
result->nwords = wordnum + 1;
|
||||
result->words[wordnum] = ((bitmapword) 1 << bitnum);
|
||||
return result;
|
||||
@@ -852,6 +853,7 @@ bms_add_range(Bitmapset *a, int lower, int upper)
|
||||
if (a == NULL)
|
||||
{
|
||||
a = (Bitmapset *) palloc0(BITMAPSET_SIZE(uwordnum + 1));
|
||||
a->type = T_Bitmapset;
|
||||
a->nwords = uwordnum + 1;
|
||||
}
|
||||
else if (uwordnum >= a->nwords)
|
||||
|
||||
@@ -160,6 +160,12 @@ _copyExtensibleNode(const ExtensibleNode *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static Bitmapset *
|
||||
_copyBitmapset(const Bitmapset *from)
|
||||
{
|
||||
return bms_copy(from);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* copyObjectImpl -- implementation of copyObject(); see nodes/nodes.h
|
||||
|
||||
@@ -145,6 +145,12 @@ _equalA_Const(const A_Const *a, const A_Const *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalBitmapset(const Bitmapset *a, const Bitmapset *b)
|
||||
{
|
||||
return bms_equal(a, b);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lists are handled specially
|
||||
*/
|
||||
|
||||
@@ -65,6 +65,7 @@ my @all_input_files = qw(
|
||||
commands/trigger.h
|
||||
executor/tuptable.h
|
||||
foreign/fdwapi.h
|
||||
nodes/bitmapset.h
|
||||
nodes/extensible.h
|
||||
nodes/lockoptions.h
|
||||
nodes/replnodes.h
|
||||
|
||||
@@ -314,6 +314,9 @@ _outList(StringInfo str, const List *node)
|
||||
* converts a bitmap set of integers
|
||||
*
|
||||
* Note: the output format is "(b int int ...)", similar to an integer List.
|
||||
*
|
||||
* We export this function for use by extensions that define extensible nodes.
|
||||
* That's somewhat historical, though, because calling outNode() will work.
|
||||
*/
|
||||
void
|
||||
outBitmapset(StringInfo str, const Bitmapset *bms)
|
||||
@@ -844,6 +847,8 @@ outNode(StringInfo str, const void *obj)
|
||||
_outString(str, (String *) obj);
|
||||
else if (IsA(obj, BitString))
|
||||
_outBitString(str, (BitString *) obj);
|
||||
else if (IsA(obj, Bitmapset))
|
||||
outBitmapset(str, (Bitmapset *) obj);
|
||||
else
|
||||
{
|
||||
appendStringInfoChar(str, '{');
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include "common/string.h"
|
||||
#include "nodes/bitmapset.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "nodes/readfuncs.h"
|
||||
#include "nodes/value.h"
|
||||
@@ -347,6 +348,7 @@ nodeRead(const char *token, int tok_len)
|
||||
* Could be an integer list: (i int int ...)
|
||||
* or an OID list: (o int int ...)
|
||||
* or an XID list: (x int int ...)
|
||||
* or a bitmapset: (b int int ...)
|
||||
* or a list of nodes/values: (node node ...)
|
||||
*----------
|
||||
*/
|
||||
@@ -372,6 +374,7 @@ nodeRead(const char *token, int tok_len)
|
||||
tok_len, token);
|
||||
l = lappend_int(l, val);
|
||||
}
|
||||
result = (Node *) l;
|
||||
}
|
||||
else if (tok_len == 1 && token[0] == 'o')
|
||||
{
|
||||
@@ -392,6 +395,7 @@ nodeRead(const char *token, int tok_len)
|
||||
tok_len, token);
|
||||
l = lappend_oid(l, val);
|
||||
}
|
||||
result = (Node *) l;
|
||||
}
|
||||
else if (tok_len == 1 && token[0] == 'x')
|
||||
{
|
||||
@@ -412,6 +416,30 @@ nodeRead(const char *token, int tok_len)
|
||||
tok_len, token);
|
||||
l = lappend_xid(l, val);
|
||||
}
|
||||
result = (Node *) l;
|
||||
}
|
||||
else if (tok_len == 1 && token[0] == 'b')
|
||||
{
|
||||
/* Bitmapset -- see also _readBitmapset() */
|
||||
Bitmapset *bms = NULL;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int val;
|
||||
char *endptr;
|
||||
|
||||
token = pg_strtok(&tok_len);
|
||||
if (token == NULL)
|
||||
elog(ERROR, "unterminated Bitmapset structure");
|
||||
if (tok_len == 1 && token[0] == ')')
|
||||
break;
|
||||
val = (int) strtol(token, &endptr, 10);
|
||||
if (endptr != token + tok_len)
|
||||
elog(ERROR, "unrecognized integer: \"%.*s\"",
|
||||
tok_len, token);
|
||||
bms = bms_add_member(bms, val);
|
||||
}
|
||||
result = (Node *) bms;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -426,8 +454,8 @@ nodeRead(const char *token, int tok_len)
|
||||
if (token == NULL)
|
||||
elog(ERROR, "unterminated List structure");
|
||||
}
|
||||
result = (Node *) l;
|
||||
}
|
||||
result = (Node *) l;
|
||||
break;
|
||||
}
|
||||
case RIGHT_PAREN:
|
||||
|
||||
@@ -194,6 +194,10 @@ nullable_string(const char *token, int length)
|
||||
|
||||
/*
|
||||
* _readBitmapset
|
||||
*
|
||||
* Note: this code is used in contexts where we know that a Bitmapset
|
||||
* is expected. There is equivalent code in nodeRead() that can read a
|
||||
* Bitmapset when we come across one in other contexts.
|
||||
*/
|
||||
static Bitmapset *
|
||||
_readBitmapset(void)
|
||||
@@ -234,7 +238,8 @@ _readBitmapset(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* for use by extensions which define extensible nodes
|
||||
* We export this function for use by extensions that define extensible nodes.
|
||||
* That's somewhat historical, though, because calling nodeRead() will work.
|
||||
*/
|
||||
Bitmapset *
|
||||
readBitmapset(void)
|
||||
|
||||
Reference in New Issue
Block a user