/* * bms_add_member - add a specified member to set * * Input set is modified or recycled! */ Bitmapset * bms_add_member(Bitmapset *a, int x) { int wordnum, bitnum; if (x < 0) elog(ERROR, "negative bitmapset member not allowed"); if (a == NULL) return bms_make_singleton(x); wordnum = WORDNUM(x); bitnum = BITNUM(x); if (wordnum >= a->nwords) { /* Slow path: make a larger set and union the input set into it */ Bitmapset *result; int nwords; int i; result = bms_make_singleton(x); nwords = a->nwords; for (i = 0; i < nwords; i++) result->words[i] |= a->words[i]; pfree(a); return result; } /* Fast path: x fits in existing set */ a->words[wordnum] |= ((bitmapword) 1 << bitnum); return a; }
/* * bms_add_member - add a specified member to set * * Input set is modified or recycled! */ Bitmapset * bms_add_member(Bitmapset *a, int x) { int wordnum, bitnum; if (x < 0) elog(ERROR, "negative bitmapset member not allowed"); if (a == NULL) return bms_make_singleton(x); wordnum = WORDNUM(x); bitnum = BITNUM(x); /* enlarge the set if necessary */ if (wordnum >= a->nwords) { int oldnwords = a->nwords; int i; a = (Bitmapset *) repalloc(a, BITMAPSET_SIZE(wordnum + 1)); a->nwords = wordnum + 1; /* zero out the enlarged portion */ for (i = oldnwords; i < a->nwords; i++) a->words[i] = 0; } a->words[wordnum] |= ((bitmapword) 1 << bitnum); return a; }
/* * build_base_rel_tlists * Add targetlist entries for each var needed in the query's final tlist * to the appropriate base relations. * * We mark such vars as needed by "relation 0" to ensure that they will * propagate up through all join plan steps. */ void build_base_rel_tlists(PlannerInfo *root, List *final_tlist) { List *tlist_vars = pull_var_clause((Node *) final_tlist, PVC_INCLUDE_PLACEHOLDERS); if (tlist_vars != NIL) { add_vars_to_targetlist(root, tlist_vars, bms_make_singleton(0)); list_free(tlist_vars); } }
void CombinerDestReceiverFlush(DestReceiver *self) { CombinerState *c = (CombinerState *) self; int i; int ntups = 0; Size size = 0; microbatch_t *mb; if (CombinerFlushHook) CombinerFlushHook(); mb = microbatch_new(CombinerTuple, bms_make_singleton(c->cont_query->id), NULL); microbatch_add_acks(mb, c->cont_exec->batch->sync_acks); for (i = 0; i < continuous_query_num_combiners; i++) { List *tups = c->tups_per_combiner[i]; ListCell *lc; if (tups == NIL) continue; ntups += list_length(tups); foreach(lc, tups) { tagged_ref_t *ref = lfirst(lc); HeapTuple tup = (HeapTuple) ref->ptr; uint64 hash = ref->tag; if (!microbatch_add_tuple(mb, tup, hash)) { microbatch_send_to_combiner(mb, i); microbatch_add_tuple(mb, tup, hash); } size += HEAPTUPLESIZE + tup->t_len; } if (!microbatch_is_empty(mb)) { microbatch_send_to_combiner(mb, i); microbatch_reset(mb); } list_free_deep(tups); c->tups_per_combiner[i] = NIL; }
/* * pg_column_is_updatable - determine whether a column is updatable * * This function encapsulates the decision about just what * information_schema.columns.is_updatable actually means. It's not clear * whether deletability of the column's relation should be required, so * we want that decision in C code where we could change it without initdb. */ Datum pg_column_is_updatable(PG_FUNCTION_ARGS) { Oid reloid = PG_GETARG_OID(0); AttrNumber attnum = PG_GETARG_INT16(1); AttrNumber col = attnum - FirstLowInvalidHeapAttributeNumber; bool include_triggers = PG_GETARG_BOOL(2); int events; /* System columns are never updatable */ if (attnum <= 0) PG_RETURN_BOOL(false); events = relation_is_updatable(reloid, include_triggers, bms_make_singleton(col)); /* We require both updatability and deletability of the relation */ #define REQ_EVENTS ((1 << CMD_UPDATE) | (1 << CMD_DELETE)) PG_RETURN_BOOL((events & REQ_EVENTS) == REQ_EVENTS); }