summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/btree/bt_ret.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/btree/bt_ret.c')
-rw-r--r--src/third_party/wiredtiger/src/btree/bt_ret.c171
1 files changed, 109 insertions, 62 deletions
diff --git a/src/third_party/wiredtiger/src/btree/bt_ret.c b/src/third_party/wiredtiger/src/btree/bt_ret.c
index 6409a1a180c..f17fa1b85d1 100644
--- a/src/third_party/wiredtiger/src/btree/bt_ret.c
+++ b/src/third_party/wiredtiger/src/btree/bt_ret.c
@@ -9,64 +9,21 @@
#include "wt_internal.h"
/*
- * __wt_kv_return --
- * Return a page referenced key/value pair to the application.
+ * __key_return --
+ * Change the cursor to reference an internal return key.
*/
-int
-__wt_kv_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_UPDATE *upd)
+static inline int
+__key_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt)
{
- WT_BTREE *btree;
- WT_CELL *cell;
- WT_CELL_UNPACK unpack;
WT_CURSOR *cursor;
WT_ITEM *tmp;
WT_PAGE *page;
WT_ROW *rip;
- uint8_t v;
-
- btree = S2BT(session);
page = cbt->ref->page;
cursor = &cbt->iface;
- switch (page->type) {
- case WT_PAGE_COL_FIX:
- /*
- * The interface cursor's record has usually been set, but that
- * isn't universally true, specifically, cursor.search_near may
- * call here without first setting the interface cursor.
- */
- cursor->recno = cbt->recno;
-
- /* If the cursor references a WT_UPDATE item, return it. */
- if (upd != NULL) {
- cursor->value.data = WT_UPDATE_DATA(upd);
- cursor->value.size = upd->size;
- return (0);
- }
-
- /* Take the value from the original page. */
- v = __bit_getv_recno(cbt->ref, cursor->recno, btree->bitcnt);
- return (__wt_buf_set(session, &cursor->value, &v, 1));
- case WT_PAGE_COL_VAR:
- /*
- * The interface cursor's record has usually been set, but that
- * isn't universally true, specifically, cursor.search_near may
- * call here without first setting the interface cursor.
- */
- cursor->recno = cbt->recno;
-
- /* If the cursor references a WT_UPDATE item, return it. */
- if (upd != NULL) {
- cursor->value.data = WT_UPDATE_DATA(upd);
- cursor->value.size = upd->size;
- return (0);
- }
-
- /* Take the value from the original page cell. */
- cell = WT_COL_PTR(page, &page->pg_var[cbt->slot]);
- break;
- case WT_PAGE_ROW_LEAF:
+ if (page->type == WT_PAGE_ROW_LEAF) {
rip = &page->pg_row[cbt->slot];
/*
@@ -79,7 +36,10 @@ __wt_kv_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_UPDATE *upd)
if (cbt->ins != NULL) {
cursor->key.data = WT_INSERT_KEY(cbt->ins);
cursor->key.size = WT_INSERT_KEY_SIZE(cbt->ins);
- } else if (cbt->compare == 0) {
+ return (0);
+ }
+
+ if (cbt->compare == 0) {
/*
* If not in an insert list and there's an exact match,
* the row-store search function built the key we want
@@ -97,16 +57,51 @@ __wt_kv_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_UPDATE *upd)
cursor->key.data = cbt->row_key->data;
cursor->key.size = cbt->row_key->size;
- } else
- WT_RET(__wt_row_leaf_key(
- session, page, rip, &cursor->key, false));
-
- /* If the cursor references a WT_UPDATE item, return it. */
- if (upd != NULL) {
- cursor->value.data = WT_UPDATE_DATA(upd);
- cursor->value.size = upd->size;
return (0);
}
+ return (__wt_row_leaf_key(
+ session, page, rip, &cursor->key, false));
+ }
+
+ /*
+ * WT_PAGE_COL_FIX, WT_PAGE_COL_VAR:
+ * The interface cursor's record has usually been set, but that
+ * isn't universally true, specifically, cursor.search_near may call
+ * here without first setting the interface cursor.
+ */
+ cursor->recno = cbt->recno;
+ return (0);
+}
+
+/*
+ * __value_return --
+ * Change the cursor to reference an internal return value.
+ */
+static inline int
+__value_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_UPDATE *upd)
+{
+ WT_BTREE *btree;
+ WT_CELL *cell;
+ WT_CELL_UNPACK unpack;
+ WT_CURSOR *cursor;
+ WT_PAGE *page;
+ WT_ROW *rip;
+ uint8_t v;
+
+ btree = S2BT(session);
+
+ page = cbt->ref->page;
+ cursor = &cbt->iface;
+
+ /* If the cursor references a WT_UPDATE item, return it. */
+ if (upd != NULL) {
+ cursor->value.data = WT_UPDATE_DATA(upd);
+ cursor->value.size = upd->size;
+ return (0);
+ }
+
+ if (page->type == WT_PAGE_ROW_LEAF) {
+ rip = &page->pg_row[cbt->slot];
/* Simple values have their location encoded in the WT_ROW. */
if (__wt_row_leaf_value(page, rip, &cursor->value))
@@ -121,13 +116,65 @@ __wt_kv_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_UPDATE *upd)
cursor->value.size = 0;
return (0);
}
- break;
- WT_ILLEGAL_VALUE(session);
+ __wt_cell_unpack(cell, &unpack);
+ return (__wt_page_cell_data_ref(
+ session, page, &unpack, &cursor->value));
+
}
- /* The value is an on-page cell, unpack and expand it as necessary. */
- __wt_cell_unpack(cell, &unpack);
- WT_RET(__wt_page_cell_data_ref(session, page, &unpack, &cursor->value));
+ if (page->type == WT_PAGE_COL_VAR) {
+ /* Take the value from the original page cell. */
+ cell = WT_COL_PTR(page, &page->pg_var[cbt->slot]);
+ __wt_cell_unpack(cell, &unpack);
+ return (__wt_page_cell_data_ref(
+ session, page, &unpack, &cursor->value));
+ }
+
+ /* WT_PAGE_COL_FIX: Take the value from the original page. */
+ v = __bit_getv_recno(cbt->ref, cursor->recno, btree->bitcnt);
+ return (__wt_buf_set(session, &cursor->value, &v, 1));
+}
+
+/*
+ * __wt_key_return --
+ * Change the cursor to reference an internal return key.
+ */
+int
+__wt_key_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt)
+{
+ WT_CURSOR *cursor;
+
+ cursor = &cbt->iface;
+
+ /*
+ * We may already have an internal key, in which case the cursor may
+ * not be set up to get another copy (for example, when we rely on a
+ * search-function result).
+ */
+ F_CLR(cursor, WT_CURSTD_KEY_EXT);
+ if (!F_ISSET(cursor, WT_CURSTD_KEY_INT)) {
+ WT_RET(__key_return(session, cbt));
+ F_SET(cursor, WT_CURSTD_KEY_INT);
+ }
+ return (0);
+}
+
+/*
+ * __wt_kv_return --
+ * Return a page referenced key/value pair to the application.
+ */
+int
+__wt_kv_return(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_UPDATE *upd)
+{
+ WT_CURSOR *cursor;
+
+ cursor = &cbt->iface;
+
+ WT_RET(__wt_key_return(session, cbt));
+
+ F_CLR(cursor, WT_CURSTD_VALUE_EXT);
+ WT_RET(__value_return(session, cbt, upd));
+ F_SET(cursor, WT_CURSTD_VALUE_INT);
return (0);
}