Beispiel #1
0
static void *
column_find_value(sql_trans *tr, sql_column *c, oid rid)
{
	BUN q;
	BAT *b, *d = NULL;
	void *res = NULL;
	sql_dbat *bat = c->t->data;

	if (bat->dbid) 
		d = store_funcs.bind_del(tr, c->t, RDONLY);
	b = full_column(c, d, NULL);
	if (d)
		bat_destroy(d);

	q = BUNfnd(b, (ptr) &rid);
	if (q != BUN_NONE) {
		BATiter bi = bat_iterator(b);
		void *r;
		int sz;

		res = BUNtail(bi, q);
		sz = ATOMlen(b->ttype, res);
		r = GDKzalloc(sz);
		memcpy(r,res,sz);
		res = r;
	}
	bat_destroy(b);
	return res;
}
Beispiel #2
0
log_bid 
ebat_copy(log_bid b, oid ibase, int temp)
{
	/* make a copy of b */
	BAT *o = temp_descriptor(b);
	BAT *c;
	log_bid r;

	if (!ebats[o->ttype]) 
		ebats[o->ttype] = bat_new(TYPE_void, o->ttype, 0, TRANSIENT);

	if (!temp && BATcount(o)) {
		c = BATcopy(o, TYPE_void, o->ttype, TRUE, PERSISTENT);
		BATseqbase(c, ibase );
		c->H->dense = 1;
		BATcommit(c);
		bat_set_access(c, BAT_READ);
		r = temp_create(c);
		bat_destroy(c);
	} else {
		c = ebats[o->ttype];
		r = temp_create(c);
	}
	bat_destroy(o);
	return r;
}
Beispiel #3
0
static BAT *
delta_full_bat_( sql_column *c, sql_delta *bat, int temp, BAT *d, BAT *s)
{
	/* return full normalized column bat

		if (s) {
			b := b.semijoin(s);
			i := i.semijoin(s);
			u := u.semijoin(s);
		}
		b := b.kunion(i);
		b := b.kdiff(u);
		b := b.kunion(u);
		b := b.kdiff(reverse(d));
	*/
	BAT *r, *b, *u, *i = temp_descriptor(bat->ibid);
	r = i; 
	if (temp) {
		if (s) {
			r = BATsemijoin(i,s);
			bat_destroy(i);
		}
		return r;
	}
	b = temp_descriptor(bat->bid);
	u = temp_descriptor(bat->ubid);
	if (s) {
		BAT *t;

		t = BATsemijoin(b,s); bat_destroy(b); b = t;
		t = BATsemijoin(i,s); bat_destroy(i); i = t;
		t = BATsemijoin(u,s); bat_destroy(u); u = t;
	}
	assert(b->ttype == i->ttype);
	if (BATcount(i)) {
		r = BATkunion(b,i); bat_destroy(b); b = r;
	}
	bat_destroy(i); 
	if (BATcount(u)) {
		r = BATkdiff(b,u); bat_destroy(b); b = r;
		assert(b->ttype == u->ttype);
		r = BATkunion(b,u); bat_destroy(b); b = r;
	}
	bat_destroy(u); 
	if (d && BATcount(d)) {
		r = BATkdiff(b,BATmirror(d)); bat_destroy(b); b = r;
	}
	if (!bat->cached && !c->base.wtime && !s) 
		bat->cached = temp_descriptor(b->batCacheid);
	return b;
}
Beispiel #4
0
static oid
column_find_row(sql_trans *tr, sql_column *c, const void *value, ...)
{
	va_list va;
	BAT *b = NULL, *s = NULL, *r = NULL;
	oid rid = oid_nil;
	sql_column *n = NULL;

	va_start(va, value);
	s = delta_cands(tr, c->t);
	if (!s)
		goto return_nil;
	b = full_column(tr, c);
	if (!b) {
		bat_destroy(s);
		goto return_nil;
	}
	r = BATselect(b, s, value, NULL, true, false, false);
	bat_destroy(s);
	full_destroy(c, b);
	if (!r)
		goto return_nil;
	s = r;
	while ((n = va_arg(va, sql_column *)) != NULL) {
		value = va_arg(va, void *);
		c = n;

		b = full_column(tr, c);
		if (!b) {
			bat_destroy(s);
			goto return_nil;
		}
		r = BATselect(b, s, value, NULL, true, false, false);
		bat_destroy(s);
		full_destroy(c, b);
		if (!r)
			goto return_nil;
		s = r;
	}
	va_end(va);
	if (BATcount(s) == 1) {
		rid = BUNtoid(s, 0);
	}
	bat_destroy(s);
	return rid;
  return_nil:
	va_end(va);
	return oid_nil;
}
Beispiel #5
0
log_bid 
ebat2real(log_bid b, oid ibase)
{
	/* make a copy of b */
	BAT *o = temp_descriptor(b);
	BAT *c = BATcopy(o, TYPE_void, ATOMtype(o->ttype), TRUE);
	log_bid r;

	BATseqbase(c, ibase );
	c->H->dense = 1;
	r = temp_create(c);
	bat_destroy(c);
	bat_destroy(o);
	return r;
}
Beispiel #6
0
static void
full_destroy(sql_column *c, BAT *b)
{
	sql_delta *d = c->data;
	assert(d);
	if (d->cached != b)
		bat_destroy(b);
}
Beispiel #7
0
log_bid
temp_copy(log_bid b, int temp)
{
	/* make a copy of b, if temp is set only create a empty bat */
	BAT *o = temp_descriptor(b);
	BAT *c;
	log_bid r;

	if (!temp) {
		c = BATcopy(o, o->htype, o->ttype, TRUE);
		bat_set_access(c, BAT_READ);
		BATcommit(c);
	} else {
		c = bat_new(o->htype, o->ttype, COLSIZE);
	}
	r = temp_create(c);
	bat_destroy(c);
	bat_destroy(o);
	return r;
}
Beispiel #8
0
static oid
column_find_row(sql_trans *tr, sql_column *c, void *value, ...)
{
	va_list va;
	BUN q;
	BAT *b = NULL, *s = NULL, *r = NULL, *d = NULL;
	oid rid = oid_nil;
	sql_column *nc;
	void *nv;
	sql_dbat *bat = c->t->data;

	if (bat->dbid) 
		d = store_funcs.bind_del(tr, c->t, RDONLY);
	va_start(va, value);
	while ((nc = va_arg(va, sql_column *)) != NULL) {
		nv = va_arg(va, void *);

		b = full_column(c, d, s);
		if (s)
			bat_destroy(s);
		s = BATselect(b, value, value);
		bat_destroy(b);
		c = nc;
		value = nv;
	}
	va_end(va);
	b = full_column(c, d, s);
	if (s)
		bat_destroy(s);
	if (d)
		bat_destroy(d);

	r = BATmirror(b);
	q = BUNfnd(r, value);
	if (q != BUN_NONE) {
		BATiter ri = bat_iterator(r);
		rid = *(oid *) BUNtail(ri, q);
	}
	bat_destroy(b);
	return rid;
}
Beispiel #9
0
static BAT *
_delta_cands(sql_trans *tr, sql_table *t)
{
	sql_column *c = t->columns.set->h->data;
	/* create void,void bat with length and oid's set */
	size_t nr = store_funcs.count_col(tr, c, 1);
	BAT *tids = BATdense(0, 0, (BUN) nr);

	if (!tids)
		return NULL;

	if (store_funcs.count_del(tr, t)) {
		BAT *d, *diff = NULL;

		if ((d = store_funcs.bind_del(tr, t, RD_INS)) != NULL) {
			diff = BATdiff(tids, d, NULL, NULL, false, BUN_NONE);
			bat_destroy(d);
		}
		bat_destroy(tids);
		tids = diff;
	}
	return tids;
}
Beispiel #10
0
log_bid 
eubat_copy(log_bid b, int temp)
{
	/* make a copy of b */
	BAT *o = temp_descriptor(b);
	BAT *c;
	log_bid r;

	if (!eubats[o->ttype]) 
		eubats[o->ttype] = bat_new(TYPE_oid, o->ttype, 0);

	if (!temp && BATcount(o)) {
		c = BATcopy(o, TYPE_oid, o->ttype, TRUE);
		BATcommit(c);
		r = temp_create(c);
		bat_set_access(c, BAT_READ);
		bat_destroy(c);
	} else {
		c = eubats[o->ttype];
		r = temp_create(c);
	}
	bat_destroy(o);
	return r;
}
Beispiel #11
0
static int
table_dump(sql_trans *tr, sql_table *t)
{
	node *n = cs_first_node(&t->columns);
	int i, l = cs_size(&t->columns);
	BAT **b = (BAT**)GDKzalloc(sizeof(BAT*) * l);
	
	(void)tr;
	for (i = 0; n; n = n->next, i++) {
		sql_column *c = n->data;
		sql_delta *bat = c->data;

		b[i] = temp_descriptor(bat->bid);
	}
	BATmultiprintf(GDKstdout, l +1, b, TRUE, 0, 1);
	for (i = 0; i < l; i++)
		bat_destroy(b[i]);
	GDKfree(b);
	return 0;
}
Beispiel #12
0
static int
table_check(sql_trans *tr, sql_table *t)
{
	node *n = cs_first_node(&t->columns);
	BUN cnt = BUN_NONE;

	(void)tr;
	for (; n; n = n->next) {
		sql_column *c = n->data;
		sql_delta *bat = c->data;
		BAT *b = temp_descriptor(bat->bid);

		if (cnt == BUN_NONE) {
			cnt = BATcount(b);
		} else if (cnt != BATcount(b)) {
			assert(0);
			return (int)(cnt - BATcount(b));
		}
		bat_destroy(b);
	}
	return 0;
}
Beispiel #13
0
static BAT *
delta_full_bat_( sql_column *c, sql_delta *bat, int temp)
{
	/* return full normalized column bat
	 * 	b := b.copy()
		b := b.append(i);
		b := b.replace(u);
	*/
	BAT *r, *b, *ui, *uv, *i = temp_descriptor(bat->ibid);
	int needcopy = 1;

	if (!i)
		return NULL;
	r = i; 
	if (temp) 
		return r;
	b = temp_descriptor(bat->bid);
	if (!b) {
		b = i;
	} else {
		if (BATcount(i)) {
			r = COLcopy(b, b->ttype, true, TRANSIENT); 
			bat_destroy(b); 
			if (r == NULL) {
				bat_destroy(i);
				return NULL;
			}
			b = r;
			if (BATappend(b, i, NULL, true) != GDK_SUCCEED) {
				bat_destroy(b);
				bat_destroy(i);
				return NULL;
			}
			needcopy = 0;
		}
		bat_destroy(i); 
	}
	if (bat->uibid && bat->ucnt) {
		ui = temp_descriptor(bat->uibid);
		uv = temp_descriptor(bat->uvbid);
		if (ui && BATcount(ui)) {
			if (needcopy) {
				r = COLcopy(b, b->ttype, true, TRANSIENT); 
				bat_destroy(b); 
				b = r;
				if(b == NULL) {
					bat_destroy(ui);
					bat_destroy(uv);
					return NULL;
				}
			}
			if (void_replace_bat(b, ui, uv, true) != GDK_SUCCEED) {
				bat_destroy(ui);
				bat_destroy(uv);
				bat_destroy(b);
				return NULL;
			}
		}
		bat_destroy(ui); 
		bat_destroy(uv); 
	}
	(void)c;
	if (!store_initialized && !bat->cached) 
		bat->cached = b;
	return b;
}
Beispiel #14
0
/* returns table rids, for the given select ranges */
static rids *
rids_select( sql_trans *tr, sql_column *key, const void *key_value_low, const void *key_value_high, ...)
{
	va_list va;
	BAT *b = NULL, *r = NULL, *s = NULL;
	rids *rs = ZNEW(rids);
	const void *kvl = key_value_low, *kvh = key_value_high;
	/* if pointers are equal, make it an inclusive select */
	bool hi = key_value_low == key_value_high;

	if(!rs)
		return NULL;
	s = delta_cands(tr, key->t);
	if (s == NULL) {
		GDKfree(rs);
		return NULL;
	}
	b = full_column(tr, key);
	if (b == NULL) {
		bat_destroy(s);
		GDKfree(rs);
		return NULL;
	}
	if (!kvl)
		kvl = ATOMnilptr(b->ttype);
	if (!kvh && kvl != ATOMnilptr(b->ttype))
		kvh = ATOMnilptr(b->ttype);
	if (key_value_low) {
		BAThash(b);
		r = BATselect(b, s, kvl, kvh, true, hi, false);
		bat_destroy(s);
		s = r;
	}
	full_destroy(key, b);
	if (s == NULL) {
		GDKfree(rs);
		return NULL;
	}
	if (key_value_low || key_value_high) {
		va_start(va, key_value_high);
		while ((key = va_arg(va, sql_column *)) != NULL) {
			kvl = va_arg(va, void *);
			kvh = va_arg(va, void *);
	
			b = full_column(tr, key);
			if (!kvl)
				kvl = ATOMnilptr(b->ttype);
			if (!kvh && kvl != ATOMnilptr(b->ttype))
				kvh = ATOMnilptr(b->ttype);
			assert(kvh);
			r = BATselect(b, s, kvl, kvh, true, hi, false);
			bat_destroy(s);
			s = r;
			full_destroy(key, b);
			if (s == NULL) {
				GDKfree(rs);
				va_end(va);
				return NULL;
			}
		}
		va_end(va);
	}