Commit cf4a47c0 authored by unknown's avatar unknown
Browse files

row0sel.c:

  Add more comments to row_search_for_mysql() and remove the ugly double use of the variable rec in that function


innobase/row/row0sel.c:
  Add more comments to row_search_for_mysql() and remove the ugly double use of the variable rec in that function
parent 67a74369
Loading
Loading
Loading
Loading
+49 −29
Original line number Diff line number Diff line
@@ -2725,6 +2725,8 @@ row_sel_get_clust_rec_for_mysql(
		    && !lock_clust_rec_cons_read_sees(clust_rec, clust_index,
						*offsets, trx->read_view)) {
		
			/* The following call returns 'offsets' associated with
			'old_vers' */
			err = row_sel_build_prev_vers_for_mysql(
					trx->read_view, clust_index,
					prebuilt, clust_rec,
@@ -3062,7 +3064,7 @@ row_search_for_mysql(
	dict_index_t*	clust_index;
	que_thr_t*	thr;
	rec_t*		rec;
	rec_t*		index_rec;
	rec_t*		result_rec;
	rec_t*		clust_rec;
	rec_t*		old_vers;
	ulint		err				= DB_SUCCESS;
@@ -3548,15 +3550,19 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
	if (comp) {
		next_offs = rec_get_next_offs(rec, TRUE);
		if (UNIV_UNLIKELY(next_offs < PAGE_NEW_SUPREMUM)) {

			goto wrong_offs;
		}
	} else {
		next_offs = rec_get_next_offs(rec, FALSE);
		if (UNIV_UNLIKELY(next_offs < PAGE_OLD_SUPREMUM)) {

			goto wrong_offs;
		}
	}

	if (UNIV_UNLIKELY(next_offs >= UNIV_PAGE_SIZE - PAGE_DIR)) {

wrong_offs:
		if (srv_force_recovery == 0 || moves_up == FALSE) {
			ut_print_timestamp(stderr);
@@ -3600,6 +3606,9 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
			goto next_rec;
		}
	}
	/*-------------------------------------------------------------*/

	/* Calculate the 'offsets' associated with 'rec' */

	offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, &heap);

@@ -3620,8 +3629,6 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
		}
	}

	/*-------------------------------------------------------------*/

	/* Note that we cannot trust the up_match value in the cursor at this
	place because we can arrive here after moving the cursor! Thus
	we have to recompare rec and search_tuple to determine if they
@@ -3768,6 +3775,8 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
                            && !lock_clust_rec_cons_read_sees(rec, index,
						offsets, trx->read_view)) {

				/* The following call returns 'offsets'
				associated with 'old_vers' */
				err = row_sel_build_prev_vers_for_mysql(
						trx->read_view, clust_index,
						prebuilt, rec,
@@ -3796,8 +3805,6 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
			is necessary, because we can only get the undo
			information via the clustered index record. */

			/* Get the clustered index record if needed */
			index_rec = rec;
			ut_ad(index != clust_index);

			goto requires_clust_rec;
@@ -3807,7 +3814,7 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
	/* NOTE that at this point rec can be an old version of a clustered
	index record built for a consistent read. We cannot assume after this
	point that rec is on a buffer pool page. Functions like
	page_rec_is_comp() cannot be used then! */
	page_rec_is_comp() cannot be used! */

	if (UNIV_UNLIKELY(rec_get_deleted_flag(rec, comp))) {

@@ -3829,19 +3836,15 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
		goto next_rec;
	}

	/* Get the clustered index record if needed and if we did
	not do the search using the clustered index */

	index_rec = rec;
	/* Get the clustered index record if needed, if we did not do the
	search using the clustered index. */

	if (index != clust_index && prebuilt->need_to_access_clustered) {

requires_clust_rec:
		/* Before and after this "if" block, "offsets" will be
		related to "rec", which may be in a secondary index "index" or
		the clustered index ("clust_index").  However, after this
		"if" block, "rec" may be pointing to
		"clust_rec" of "clust_index". */
		/* We use a 'goto' to the preceding label if a consistent
		read of a secondary index record requires us to look up old
		versions of the associated clustered index record. */

		ut_ad(rec_offs_validate(rec, index, offsets));

@@ -3850,6 +3853,10 @@ cursor lock count is done correctly. See bugs #12263 and #12456!

		mtr_has_extra_clust_latch = TRUE;

		/* The following call returns 'offsets' associated with
		'clust_rec'. Note that 'clust_rec' can be an old version
		built for a consistent read. */
		
		err = row_sel_get_clust_rec_for_mysql(prebuilt, index, rec,
							thr, &clust_rec,
							&offsets, &heap, &mtr);
@@ -3885,17 +3892,26 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
		}
		
		if (prebuilt->need_to_access_clustered) {
		        rec = clust_rec;

		        result_rec = clust_rec;

			ut_ad(rec_offs_validate(rec, clust_index, offsets));
		} else {
			/* We used 'offsets' for the clust rec, recalculate
			them for 'rec' */
			offsets = rec_get_offsets(rec, index, offsets,
						ULINT_UNDEFINED, &heap);
			result_rec = rec;
		}
	} else {
		result_rec = rec;
	}

	/* We found a qualifying row */
	ut_ad(rec_offs_validate(rec,
				rec == clust_rec ? clust_index : index,
	/* We found a qualifying record 'result_rec'. At this point,
	'offsets' are associated with 'result_rec'. */

	ut_ad(rec_offs_validate(result_rec,
				result_rec != rec ? clust_index : index,
				offsets));

	if ((match_mode == ROW_SEL_EXACT
@@ -3916,8 +3932,8 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
		not cache rows because there the cursor is a scrollable
		cursor. */

		row_sel_push_cache_row_for_mysql(prebuilt, rec, offsets);

		row_sel_push_cache_row_for_mysql(prebuilt, result_rec,
								offsets);
		if (prebuilt->n_fetch_cached == MYSQL_FETCH_CACHE_SIZE) {
			
			goto got_row;
@@ -3926,13 +3942,14 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
		goto next_rec;
	} else {
		if (prebuilt->template_type == ROW_MYSQL_DUMMY_TEMPLATE) {
			memcpy(buf + 4, rec - rec_offs_extra_size(offsets),
			memcpy(buf + 4, result_rec
						- rec_offs_extra_size(offsets),
					rec_offs_size(offsets));
			mach_write_to_4(buf,
					rec_offs_extra_size(offsets) + 4);
		} else {
			if (!row_sel_store_mysql_rec(buf, prebuilt,
							rec, offsets)) {
							result_rec, offsets)) {
				err = DB_TOO_BIG_RECORD;

				goto lock_wait_or_error;
@@ -3940,15 +3957,18 @@ cursor lock count is done correctly. See bugs #12263 and #12456!
		}

		if (prebuilt->clust_index_was_generated) {
			if (rec != index_rec) {
			if (result_rec != rec) {
				offsets = rec_get_offsets(
						index_rec, index, offsets,
						rec, index, offsets,
						ULINT_UNDEFINED, &heap);
			}
			row_sel_store_row_id_to_prebuilt(prebuilt, index_rec,
			row_sel_store_row_id_to_prebuilt(prebuilt, rec,
							index, offsets);
		}
	}

	/* From this point on, 'offsets' are invalid. */

got_row:
	/* We have an optimization to save CPU time: if this is a consistent
	read on a unique condition on the clustered index, then we do not