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
commands/trigger.h \
executor/tuptable.h \
foreign/fdwapi.h \
+ nodes/bitmapset.h \
nodes/extensible.h \
nodes/lockoptions.h \
nodes/replnodes.h \
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;
if (a == NULL)
{
a = (Bitmapset *) palloc0(BITMAPSET_SIZE(uwordnum + 1));
+ a->type = T_Bitmapset;
a->nwords = uwordnum + 1;
}
else if (uwordnum >= a->nwords)
return newnode;
}
+static Bitmapset *
+_copyBitmapset(const Bitmapset *from)
+{
+ return bms_copy(from);
+}
+
/*
* copyObjectImpl -- implementation of copyObject(); see nodes/nodes.h
return true;
}
+static bool
+_equalBitmapset(const Bitmapset *a, const Bitmapset *b)
+{
+ return bms_equal(a, b);
+}
+
/*
* Lists are handled specially
*/
commands/trigger.h
executor/tuptable.h
foreign/fdwapi.h
+ nodes/bitmapset.h
nodes/extensible.h
nodes/lockoptions.h
nodes/replnodes.h
* 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)
_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, '{');
#include <ctype.h>
#include "common/string.h"
+#include "nodes/bitmapset.h"
#include "nodes/pg_list.h"
#include "nodes/readfuncs.h"
#include "nodes/value.h"
* 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 ...)
*----------
*/
tok_len, token);
l = lappend_int(l, val);
}
+ result = (Node *) l;
}
else if (tok_len == 1 && token[0] == 'o')
{
tok_len, token);
l = lappend_oid(l, val);
}
+ result = (Node *) l;
}
else if (tok_len == 1 && token[0] == 'x')
{
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
{
if (token == NULL)
elog(ERROR, "unterminated List structure");
}
+ result = (Node *) l;
}
- result = (Node *) l;
break;
}
case RIGHT_PAREN:
/*
* _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)
}
/*
- * 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)
List **considered_relids);
static bool eclass_already_used(EquivalenceClass *parent_ec, Relids oldrelids,
List *indexjoinclauses);
-static bool bms_equal_any(Relids relids, List *relids_list);
static void get_index_paths(PlannerInfo *root, RelOptInfo *rel,
IndexOptInfo *index, IndexClauseSet *clauses,
List **bitindexpaths);
Path *path = (Path *) lfirst(lc);
Relids required_outer = PATH_REQ_OUTER(path);
- if (!bms_equal_any(required_outer, all_path_outers))
- all_path_outers = lappend(all_path_outers, required_outer);
+ all_path_outers = list_append_unique(all_path_outers,
+ required_outer);
}
/* Now, for each distinct parameterization set ... */
int num_considered_relids;
/* If we already tried its relids set, no need to do so again */
- if (bms_equal_any(clause_relids, *considered_relids))
+ if (list_member(*considered_relids, clause_relids))
continue;
/*
int indexcol;
/* If we already considered this relids set, don't repeat the work */
- if (bms_equal_any(relids, *considered_relids))
+ if (list_member(*considered_relids, relids))
return;
/* Identify indexclauses usable with this relids set */
return false;
}
-/*
- * bms_equal_any
- * True if relids is bms_equal to any member of relids_list
- *
- * Perhaps this should be in bitmapset.c someday.
- */
-static bool
-bms_equal_any(Relids relids, List *relids_list)
-{
- ListCell *lc;
-
- foreach(lc, relids_list)
- {
- if (bms_equal(relids, (Relids) lfirst(lc)))
- return true;
- }
- return false;
-}
-
/*
* get_index_paths
#ifndef BITMAPSET_H
#define BITMAPSET_H
+#include "nodes/nodes.h"
+
/*
* Forward decl to save including pg_list.h
*/
typedef struct Bitmapset
{
+ pg_node_attr(custom_copy_equal, special_read_write)
+
+ NodeTag type;
int nwords; /* number of words in array */
bitmapword words[FLEXIBLE_ARRAY_MEMBER]; /* really [nwords] */
} Bitmapset;
'commands/trigger.h',
'executor/tuptable.h',
'foreign/fdwapi.h',
+ 'nodes/bitmapset.h',
'nodes/extensible.h',
'nodes/lockoptions.h',
'nodes/replnodes.h',
/*
* cache space for remembering if we have proven this relation unique
- *
- * can't print unique_for_rels/non_unique_for_rels; BMSes aren't Nodes
*/
/* known unique for these other relid set(s) */
- List *unique_for_rels pg_node_attr(read_write_ignore);
+ List *unique_for_rels;
/* known not unique for these set(s) */
- List *non_unique_for_rels pg_node_attr(read_write_ignore);
+ List *non_unique_for_rels;
/*
* used by various scans and joins: