예제 #1
0
파일: cur_join.c 프로젝트: mongodb/mongo
/*
 * __curjoin_entries_in_range --
 *	Check if a key is in the range specified by the remaining entries,
 *	returning WT_NOTFOUND if not.
 */
static int
__curjoin_entries_in_range(WT_SESSION_IMPL *session, WT_CURSOR_JOIN *cjoin,
    WT_ITEM *curkey, WT_CURSOR_JOIN_ITER *iterarg)
{
	WT_CURSOR_JOIN_ENTRY *entry;
	WT_CURSOR_JOIN_ITER *iter;
	WT_DECL_RET;
	u_int pos;
	int fastret, slowret;

	iter = iterarg;
	if (F_ISSET(cjoin, WT_CURJOIN_DISJUNCTION)) {
		fastret = 0;
		slowret = WT_NOTFOUND;
	} else {
		fastret = WT_NOTFOUND;
		slowret = 0;
	}
	pos = iter == NULL ? 0 : iter->entry_pos;
	for (entry = &cjoin->entries[pos]; pos < cjoin->entries_next;
		entry++, pos++) {
		ret = __curjoin_entry_member(session, entry, curkey, iter);
		if (ret == fastret)
			return (fastret);
		if (ret != slowret)
			break;
		iter = NULL;
	}

	return (ret == 0 ? slowret : ret);
}
예제 #2
0
/*
 * __curjoin_next --
 *	WT_CURSOR::next for join cursors.
 */
static int
__curjoin_next(WT_CURSOR *cursor)
{
	WT_CURSOR_JOIN *cjoin;
	WT_DECL_RET;
	WT_SESSION_IMPL *session;
	bool skip_left;
	u_int i;

	cjoin = (WT_CURSOR_JOIN *)cursor;

	CURSOR_API_CALL(cursor, session, next, NULL);

	if (F_ISSET(cjoin, WT_CURJOIN_ERROR))
		WT_ERR_MSG(session, WT_ERROR,
		    "join cursor encountered previous error");
	if (!F_ISSET(cjoin, WT_CURJOIN_INITIALIZED))
		WT_ERR(__curjoin_init_iter(session, cjoin));

nextkey:
	if ((ret = __curjoin_entry_iter_next(cjoin->iter, &cursor->key,
	    &cursor->recno)) == 0) {
		F_SET(cursor, WT_CURSTD_KEY_EXT);

		/*
		 * We may have already established membership for the
		 * 'left' case for the first entry, since we're
		 * using that in our iteration.
		 */
		skip_left = F_ISSET(cjoin, WT_CURJOIN_SKIP_FIRST_LEFT);
		for (i = 0; i < cjoin->entries_next; i++) {
			ret = __curjoin_entry_member(session, cjoin,
			    &cjoin->entries[i], skip_left);
			if (ret == WT_NOTFOUND)
				goto nextkey;
			skip_left = false;
			WT_ERR(ret);
		}
	}

	if (0) {
err:		F_SET(cjoin, WT_CURJOIN_ERROR);
	}
	API_END_RET(session, ret);
}