[tarantool-patches] Re: [PATCH v5 3/6] sql: introduce tuple_fetcher class

Kirill Shcherbatov kshcherbatov at tarantool.org
Sun Jun 2 21:50:14 MSK 2019


Hi! I've renamed tuple_fetcher to vdbe_field_ref as you've proposed.
Here and everywhere. The corresponding diff below:

================================================

diff --git a/src/box/sql.c b/src/box/sql.c
index 07ceec2d2..b4702fd78 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -1345,36 +1345,37 @@ sql_checks_resolve_space_def_reference(ExprList *expr_list,
 }
 
 /**
- * Initialize a new tuple_fetcher instance with given tuple
+ * Initialize a new vdbe_field_ref instance with given tuple
  * data.
- * @param fetcher The tuple_fetcher instance to initialize.
+ * @param field_ref The vdbe_field_ref instance to initialize.
  * @param tuple The tuple object pointer or NULL when undefined.
  * @param data The tuple data (is always defined).
  * @param data_sz The size of tuple data (is always defined).
  */
 static void
-tuple_fetcher_create(struct tuple_fetcher *fetcher, struct tuple *tuple,
-		     const char *data, uint32_t data_sz)
+vdbe_field_ref_create(struct vdbe_field_ref *field_ref, struct tuple *tuple,
+		      const char *data, uint32_t data_sz)
 {
-	fetcher->tuple = tuple;
-	fetcher->data = data;
-	fetcher->data_sz = data_sz;
+	field_ref->tuple = tuple;
+	field_ref->data = data;
+	field_ref->data_sz = data_sz;
 
 	const char *field0 = data;
-	fetcher->field_count = mp_decode_array((const char **) &field0);
-	fetcher->slots[0] = (uint32_t)(field0 - data);
-	fetcher->rightmost_slot = 0;
+	field_ref->field_count = mp_decode_array((const char **) &field0);
+	field_ref->slots[0] = (uint32_t)(field0 - data);
+	field_ref->rightmost_slot = 0;
 }
 
 void
-tuple_fetcher_prepare_data(struct tuple_fetcher *fetcher, const char *data,
+vdbe_field_ref_prepare_data(struct vdbe_field_ref *field_ref, const char *data,
 			   uint32_t data_sz)
 {
-	tuple_fetcher_create(fetcher, NULL, data, data_sz);
+	vdbe_field_ref_create(field_ref, NULL, data, data_sz);
 }
 
 void
-tuple_fetcher_prepare_tuple(struct tuple_fetcher *fetcher, struct tuple *tuple)
+vdbe_field_ref_prepare_tuple(struct vdbe_field_ref *field_ref,
+			     struct tuple *tuple)
 {
-	tuple_fetcher_create(fetcher, tuple, tuple_data(tuple), tuple->bsize);
+	vdbe_field_ref_create(field_ref, tuple, tuple_data(tuple), tuple->bsize);
 }
diff --git a/src/box/sql.h b/src/box/sql.h
index a13f78ae8..066a0d322 100644
--- a/src/box/sql.h
+++ b/src/box/sql.h
@@ -394,13 +394,13 @@ sqlSrcListDelete(struct sql *db, struct SrcList *list);
  * to be solved and is usually equal to the greatest number of
  * fields in the tuple.
  *
- * +------------------------+
- * |  struct tuple_fetcher  |
- * +------------------------+
- * |     RESERVED MEMORY    |
- * +------------------------+
+ * +-------------------------+
+ * |  struct vdbe_field_ref  |
+ * +-------------------------+
+ * |      RESERVED MEMORY    |
+ * +-------------------------+
  */
-struct tuple_fetcher {
+struct vdbe_field_ref {
 	/** Tuple pointer or NULL when undefined. */
 	struct tuple *tuple;
 	/** Tuple data pointer. */
@@ -422,24 +422,25 @@ struct tuple_fetcher {
 };
 
 /**
- * Initialize a new tuple_fetcher instance with given tuple
+ * Initialize a new vdbe_field_ref instance with given tuple
  * data.
- * @param fetcher The tuple_fetcher instance to initialize.
+ * @param field_ref The vdbe_field_ref instance to initialize.
  * @param data The tuple data.
  * @param data_sz The size of tuple data.
  */
 void
-tuple_fetcher_prepare_data(struct tuple_fetcher *fetcher, const char *data,
+vdbe_field_ref_prepare_data(struct vdbe_field_ref *field_ref, const char *data,
 			   uint32_t data_sz);
 
 /**
- * Initialize a new tuple_fetcher instance with given tuple
+ * Initialize a new vdbe_field_ref instance with given tuple
  * data.
- * @param fetcher The tuple_fetcher instance to initialize.
+ * @param field_ref The vdbe_field_ref instance to initialize.
  * @param tuple The tuple object pointer.
  */
 void
-tuple_fetcher_prepare_tuple(struct tuple_fetcher *fetcher, struct tuple *tuple);
+vdbe_field_ref_prepare_tuple(struct vdbe_field_ref *field_ref,
+			     struct tuple *tuple);
 
 #if defined(__cplusplus)
 } /* extern "C" { */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 250646c9b..256ee77a0 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -615,7 +615,7 @@ mem_type_to_str(const struct Mem *p)
 
 /**
  * Try to get a current tuple field using its field map.
- * @param tuple Tuple to process.
+ * @param field_ref The vdbe_field_ref instance to use.
  * @param fieldno Number of a field to get.
  * @param[out] field_size Result field size.
  * @retval not NULL MessagePack field.
@@ -623,17 +623,17 @@ mem_type_to_str(const struct Mem *p)
  *              offset to @a fieldno.
  */
 static const void *
-tuple_fetcher_tuple_field_fast(struct tuple_fetcher *fetcher, uint32_t fieldno,
-			       uint32_t *field_size)
+vdbe_field_ref_tuple_field_fast(struct vdbe_field_ref *field_ref,
+				uint32_t fieldno, uint32_t *field_size)
 {
-	if (fetcher->tuple == NULL)
+	if (field_ref->tuple == NULL)
 		return NULL;
-	struct tuple_format *format = tuple_format(fetcher->tuple);
+	struct tuple_format *format = tuple_format(field_ref->tuple);
 	if (fieldno >= tuple_format_field_count(format) ||
 	    tuple_format_field(format, fieldno)->offset_slot ==
 	    TUPLE_OFFSET_SLOT_NIL)
 		return NULL;
-	const char *field = tuple_field(fetcher->tuple, fieldno);
+	const char *field = tuple_field(field_ref->tuple, fieldno);
 	const char *end = field;
 	mp_next(&end);
 	*field_size = end - field;
@@ -641,21 +641,21 @@ tuple_fetcher_tuple_field_fast(struct tuple_fetcher *fetcher, uint32_t fieldno,
 }
 
 /**
- * Fetch field by field_idx using tuple_fetcher and store result
+ * Fetch field by field_idx using vdbe_field_ref and store result
  * in dest_mem.
- * @param fetcher The initialized tuple_fetcher instance to use.
+ * @param field_ref The initialized vdbe_field_ref instance to use.
  * @param field_idx The id of the field to fetch.
  * @param[out] dest_mem The memory variable to store result.
  * @retval SQL_OK Status code in case of success.
  * @retval sql_ret_code Error code otherwise.
  */
 static int
-tuple_fetcher_fetch(struct tuple_fetcher *fetcher, uint32_t field_idx,
+vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t field_idx,
 		    struct Mem *dest_mem)
 {
 	sqlVdbeMemSetNull(dest_mem);
-	uint32_t *slots = fetcher->slots;
-	if (field_idx >= fetcher->field_count) {
+	uint32_t *slots = field_ref->slots;
+	if (field_idx >= field_ref->field_count) {
 		UPDATE_MAX_BLOBSIZE(dest_mem);
 		return SQL_OK;
 	}
@@ -669,10 +669,10 @@ tuple_fetcher_fetch(struct tuple_fetcher *fetcher, uint32_t field_idx,
 	 * field_map+1-th field.
 	 */
 	const char *data;
-	if (fetcher->rightmost_slot <= field_idx) {
+	if (field_ref->rightmost_slot <= field_idx) {
 		uint32_t field_sz;
-		data = tuple_fetcher_tuple_field_fast(fetcher, field_idx,
-						      &field_sz);
+		data = vdbe_field_ref_tuple_field_fast(field_ref, field_idx,
+						       &field_sz);
 		if (data != NULL) {
 			/*
 			 * Special case for tarantool spaces: for
@@ -684,17 +684,17 @@ tuple_fetcher_fetch(struct tuple_fetcher *fetcher, uint32_t field_idx,
 			 * better - it saves offsets to all fields
 			 * visited in mp_next() cycle.
 			 */
-			uint32_t offset = (uint32_t)(data - fetcher->data);
+			uint32_t offset = (uint32_t)(data - field_ref->data);
 			slots[field_idx] = offset;
 			slots[field_idx + 1] = offset + field_sz;
 		} else {
-			uint32_t i = fetcher->rightmost_slot;
-			data = fetcher->data + slots[i];
+			uint32_t i = field_ref->rightmost_slot;
+			data = field_ref->data + slots[i];
 			do {
 				mp_next(&data);
-				slots[++i] = (uint32_t)(data - fetcher->data);
+				slots[++i] = (uint32_t)(data - field_ref->data);
 			} while (i <= field_idx);
-			fetcher->rightmost_slot = i;
+			field_ref->rightmost_slot = i;
 		}
 	}
 
@@ -705,7 +705,7 @@ tuple_fetcher_fetch(struct tuple_fetcher *fetcher, uint32_t field_idx,
 	 */
 	assert(sqlVdbeCheckMemInvariants(dest_mem) != 0);
 	uint32_t dummy;
-	data = fetcher->data + slots[field_idx];
+	data = field_ref->data + slots[field_idx];
 	if (vdbe_decode_msgpack_into_mem(data, dest_mem, &dummy) != 0)
 		return SQL_TARANTOOL_ERROR;
 
@@ -2747,8 +2747,8 @@ case OP_Column: {
 				pReg = &aMem[pC->uc.pseudoTableReg];
 				assert(pReg->flags & MEM_Blob);
 				assert(memIsValid(pReg));
-				tuple_fetcher_prepare_data(&pC->fetcher,
-							   pReg->z, pReg->n);
+				vdbe_field_ref_prepare_data(&pC->field_ref,
+							    pReg->z, pReg->n);
 			} else {
 				sqlVdbeMemSetNull(pDest);
 				goto op_column_out;
@@ -2760,8 +2760,8 @@ case OP_Column: {
 			assert(sqlCursorIsValid(pCrsr));
 			assert(pCrsr->curFlags & BTCF_TaCursor ||
 			       pCrsr->curFlags & BTCF_TEphemCursor);
-			tuple_fetcher_prepare_tuple(&pC->fetcher,
-						    pCrsr->last_tuple);
+			vdbe_field_ref_prepare_tuple(&pC->field_ref,
+						     pCrsr->last_tuple);
 		}
 		pC->cacheStatus = p->cacheCtr;
 	}
@@ -2783,12 +2783,12 @@ case OP_Column: {
 	}
 	struct Mem *default_val_mem =
 		pOp->p4type == P4_MEM ? pOp->p4.pMem : NULL;
-	rc = tuple_fetcher_fetch(&pC->fetcher, p2, pDest);
+	rc = vdbe_field_ref_fetch(&pC->field_ref, p2, pDest);
 	if (rc != SQL_OK)
 		goto abort_due_to_error;
 
 	if ((pDest->flags & MEM_Null) &&
-	    (uint32_t) p2  >= pC->fetcher.field_count &&
+	    (uint32_t) p2  >= pC->field_ref.field_count &&
 	    default_val_mem != NULL) {
 		sqlVdbeMemShallowCopy(pDest, default_val_mem, MEM_Static);
 	}
@@ -2804,7 +2804,7 @@ op_column_out:
 /* Opcode: Fetch P1 P2 P3 P4 P5
  * Synopsis: r[P3]=PX
  *
- * Interpret data P1 points at as an initialized tuple_fetcher
+ * Interpret data P1 points at as an initialized vdbe_field_ref
  * object.
  *
  * Fetch the P2-th column from its tuple. The value extracted
@@ -2812,12 +2812,12 @@ op_column_out:
  * P2 fields, then extract a NULL.
  */
 case OP_Fetch: {
-	struct tuple_fetcher *fetcher =
-		(struct tuple_fetcher *) p->aMem[pOp->p1].u.p;
+	struct vdbe_field_ref *field_ref =
+		(struct vdbe_field_ref *) p->aMem[pOp->p1].u.p;
 	uint32_t field_idx = pOp->p2;
 	struct Mem *dest_mem = &aMem[pOp->p3];
 	memAboutToChange(p, dest_mem);
-	rc = tuple_fetcher_fetch(fetcher, field_idx, dest_mem);
+	rc = vdbe_field_ref_fetch(field_ref, field_idx, dest_mem);
 	if (rc != SQL_OK)
 		goto abort_due_to_error;
 	REGISTER_TRACE(p, pOp->p3, dest_mem);
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 1a428afa9..68e867fbe 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -119,7 +119,7 @@ struct VdbeCursor {
 	 * Auxiliary VDBE structure to speed-up tuple data
 	 * field access.
 	 */
-	struct tuple_fetcher fetcher;
+	struct vdbe_field_ref field_ref;
 };
 
 /*




More information about the Tarantool-patches mailing list