List:Commits« Previous MessageNext Message »
From:Sunny Bains Date:April 4 2011 9:10am
Subject:bzr push into mysql-trunk-innodb branch (Sunny.Bains:3558 to 3559)
View as plain text  
 3559 Sunny Bains	2011-04-04
      General code cleanup. Rename functions, factor out the prefetch init to
      a separate function, fold the separate mallocs into one. This is part of
      making the pre-fetch configurable via the optimizer in the future.
      
      Approved by Marko rb://641

    modified:
      storage/innobase/row/row0mysql.c
      storage/innobase/row/row0sel.c
 3558 Vasil Dimov	2011-04-04 [merge]
      Merge mysql-5.5-innodb -> mysql-trunk-innodb (empty)

=== modified file 'storage/innobase/row/row0mysql.c'
--- a/storage/innobase/row/row0mysql.c	revid:vasil.dimov@stripped
+++ b/storage/innobase/row/row0mysql.c	revid:sunny.bains@stripped
@@ -791,25 +791,37 @@ row_prebuilt_free(
 		mem_heap_free(prebuilt->old_vers_heap);
 	}
 
-	for (i = 0; i < MYSQL_FETCH_CACHE_SIZE; i++) {
-		if (prebuilt->fetch_cache[i] != NULL) {
+	if (prebuilt->fetch_cache[0] != NULL) {
+		byte*	base = prebuilt->fetch_cache[0] - 4;
+		byte*	ptr = base;
+
+		for (i = 0; i < MYSQL_FETCH_CACHE_SIZE; i++) {
+			byte*	row;
+			ulint	magic1;
+			ulint	magic2;
+
+			magic1 = mach_read_from_4(ptr);
+			ptr += 4;
+
+			row = ptr;
+			ptr += prebuilt->mysql_row_len;
+
+			magic2 = mach_read_from_4(ptr);
+			ptr += 4;
+
+			if (ROW_PREBUILT_FETCH_MAGIC_N != magic1
+			    || row != prebuilt->fetch_cache[i]
+			    || ROW_PREBUILT_FETCH_MAGIC_N != magic2) {
 
-			if ((ROW_PREBUILT_FETCH_MAGIC_N != mach_read_from_4(
-				     (prebuilt->fetch_cache[i]) - 4))
-			    || (ROW_PREBUILT_FETCH_MAGIC_N != mach_read_from_4(
-					(prebuilt->fetch_cache[i])
-					+ prebuilt->mysql_row_len))) {
 				fputs("InnoDB: Error: trying to free"
-				      " a corrupt fetch buffer.\n", stderr);
-
-				mem_analyze_corruption(
-					prebuilt->fetch_cache[i]);
+					" a corrupt fetch buffer.\n", stderr);
 
+				mem_analyze_corruption(base);
 				ut_error;
 			}
-
-			mem_free((prebuilt->fetch_cache[i]) - 4);
 		}
+
+		mem_free(base);
 	}
 
 	dict_table_close(prebuilt->table, dict_locked);

=== modified file 'storage/innobase/row/row0sel.c'
--- a/storage/innobase/row/row0sel.c	revid:vasil.dimov@stripped
+++ b/storage/innobase/row/row0sel.c	revid:sunny.bains@stripped
@@ -526,8 +526,8 @@ Pops the column values for a prefetched,
 buffers and places them to the val fields in the column nodes. */
 static
 void
-sel_pop_prefetched_row(
-/*===================*/
+sel_dequeue_prefetched_row(
+/*=======================*/
 	plan_t*	plan)	/*!< in: plan node for a table */
 {
 	sym_node_t*	column;
@@ -588,8 +588,8 @@ Pushes the column values for a prefetche
 buffers from the val fields in the column nodes. */
 UNIV_INLINE
 void
-sel_push_prefetched_row(
-/*====================*/
+sel_enqueue_prefetched_row(
+/*=======================*/
 	plan_t*	plan)	/*!< in: plan node for a table */
 {
 	sym_node_t*	column;
@@ -1365,7 +1365,7 @@ table_loop:
 	index = plan->index;
 
 	if (plan->n_rows_prefetched > 0) {
-		sel_pop_prefetched_row(plan);
+		sel_dequeue_prefetched_row(plan);
 
 		goto next_table_no_mtr;
 	}
@@ -1811,13 +1811,13 @@ skip_lock:
 		goto next_table;
 	}
 
-	sel_push_prefetched_row(plan);
+	sel_enqueue_prefetched_row(plan);
 
 	if (plan->n_rows_prefetched == SEL_MAX_N_PREFETCH) {
 
 		/* The prefetch buffer is now full */
 
-		sel_pop_prefetched_row(plan);
+		sel_dequeue_prefetched_row(plan);
 
 		goto next_table;
 	}
@@ -1916,7 +1916,7 @@ table_exhausted:
 	if (plan->n_rows_prefetched > 0) {
 		/* The table became exhausted during a prefetch */
 
-		sel_pop_prefetched_row(plan);
+		sel_dequeue_prefetched_row(plan);
 
 		goto next_table_no_mtr;
 	}
@@ -3229,8 +3229,8 @@ sel_restore_position_for_mysql(
 Pops a cached row for MySQL from the fetch cache. */
 UNIV_INLINE
 void
-row_sel_pop_cached_row_for_mysql(
-/*=============================*/
+row_sel_dequeue_cached_row_for_mysql(
+/*=================================*/
 	byte*		buf,		/*!< in/out: buffer where to copy the
 					row */
 	row_prebuilt_t*	prebuilt)	/*!< in: prebuilt struct */
@@ -3286,37 +3286,55 @@ row_sel_pop_cached_row_for_mysql(
 }
 
 /********************************************************************//**
+Initialise the prefetch cache. */
+UNIV_INLINE
+void
+row_sel_prefetch_cache_init(
+/*========================*/
+	row_prebuilt_t*	prebuilt)	/*!< in/out: prebuilt struct */
+{
+	ulint	i;
+	ulint	sz;
+	byte*	ptr;
+
+	/* Reserve space for the magic number. */
+	sz = UT_ARR_SIZE(prebuilt->fetch_cache) * (prebuilt->mysql_row_len + 8);
+	ptr = mem_alloc(sz);
+
+	for (i = 0; i < UT_ARR_SIZE(prebuilt->fetch_cache); i++) {
+
+		/* A user has reported memory corruption in these
+		buffers in Linux. Put magic numbers there to help
+		to track a possible bug. */
+
+		mach_write_to_4(ptr, ROW_PREBUILT_FETCH_MAGIC_N);
+		ptr += 4;
+
+		prebuilt->fetch_cache[i] = ptr;
+		ptr += prebuilt->mysql_row_len;
+
+		mach_write_to_4(ptr, ROW_PREBUILT_FETCH_MAGIC_N);
+		ptr += 4;
+	}
+}
+
+/********************************************************************//**
 Pushes a row for MySQL to the fetch cache. */
 UNIV_INLINE
 void
-row_sel_push_cache_row_for_mysql(
-/*=============================*/
+row_sel_enqueue_cache_row_for_mysql(
+/*================================*/
 	byte*		mysql_rec,	/*!< in/out: MySQL record */
 	row_prebuilt_t*	prebuilt)	/*!< in/out: prebuilt struct */
 {
 	ut_a(prebuilt->n_fetch_cached < MYSQL_FETCH_CACHE_SIZE);
 	ut_a(!prebuilt->templ_contains_blob);
 
-	if (UNIV_UNLIKELY(prebuilt->fetch_cache[0] == NULL)) {
-		ulint	i;
+	if (prebuilt->fetch_cache[0] == NULL) {
 		/* Allocate memory for the fetch cache */
 		ut_ad(prebuilt->n_fetch_cached == 0);
 
-		for (i = 0; i < MYSQL_FETCH_CACHE_SIZE; i++) {
-			byte*	buf;
-
-			/* A user has reported memory corruption in these
-			buffers in Linux. Put magic numbers there to help
-			to track a possible bug. */
-
-			buf = mem_alloc(prebuilt->mysql_row_len + 8);
-
-			prebuilt->fetch_cache[i] = buf + 4;
-
-			mach_write_to_4(buf, ROW_PREBUILT_FETCH_MAGIC_N);
-			mach_write_to_4(buf + 4 + prebuilt->mysql_row_len,
-					ROW_PREBUILT_FETCH_MAGIC_N);
-		}
+		row_sel_prefetch_cache_init(prebuilt);
 	}
 
 	ut_ad(prebuilt->fetch_cache_first == 0);
@@ -3676,7 +3694,7 @@ row_search_for_mysql(
 			prebuilt->fetch_cache_first = 0;
 
 		} else if (UNIV_LIKELY(prebuilt->n_fetch_cached > 0)) {
-			row_sel_pop_cached_row_for_mysql(buf, prebuilt);
+			row_sel_dequeue_cached_row_for_mysql(buf, prebuilt);
 
 			prebuilt->n_rows_fetched++;
 
@@ -4682,7 +4700,7 @@ requires_clust_rec:
 			goto next_rec;
 		}
 
-		row_sel_push_cache_row_for_mysql(buf, prebuilt);
+		row_sel_enqueue_cache_row_for_mysql(buf, prebuilt);
 
 		if (prebuilt->n_fetch_cached < MYSQL_FETCH_CACHE_SIZE) {
 			goto next_rec;
@@ -4917,7 +4935,7 @@ normal_return:
 	mtr_commit(&mtr);
 
 	if (prebuilt->n_fetch_cached > 0) {
-		row_sel_pop_cached_row_for_mysql(buf, prebuilt);
+		row_sel_dequeue_cached_row_for_mysql(buf, prebuilt);
 
 		err = DB_SUCCESS;
 	}


Attachment: [text/bzr-bundle] bzr/sunny.bains@oracle.com-20110404090301-i358y3h1z6gbh8qn.bundle
Thread
bzr push into mysql-trunk-innodb branch (Sunny.Bains:3558 to 3559) Sunny Bains4 Apr