Commit 60952481 authored by heikki@hundin.mysql.fi's avatar heikki@hundin.mysql.fi
Browse files

ha_innobase.cc, ha_innobase.h:

  Backport from 4.0.4 the bug fix of the crash when a temporary table was created inside LOCK TABLES and used
parent 4753ea60
Loading
Loading
Loading
Loading
+43 −1
Original line number Diff line number Diff line
@@ -1977,7 +1977,8 @@ convert_search_mode_to_innobase(
		case HA_READ_AFTER_KEY:		return(PAGE_CUR_G);
		case HA_READ_BEFORE_KEY:	return(PAGE_CUR_L);
		case HA_READ_PREFIX:		return(PAGE_CUR_GE);
		case HA_READ_PREFIX_LAST:	return(PAGE_CUR_LE);
		case HA_READ_PREFIX_LAST:	ut_a(0); return(PAGE_CUR_LE);
		        /* HA_READ_PREFIX_LAST does not yet work in InnoDB! */
			/* the above PREFIX flags mean that the last
			field in the key value may just be a prefix
			of the complete fixed length field */
@@ -3413,6 +3414,47 @@ ha_innobase::reset(void)
  	return(0);
}


/**********************************************************************
When we create a temporary table inside MySQL LOCK TABLES, MySQL will
not call external_lock for the temporary table when it uses it. Instead,
it will call this function. */

int
ha_innobase::start_stmt(
/*====================*/
	              /* out: 0 or error code */
        THD*    thd)  /* in: handle to the user thread */
{
  row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
  trx_t*          trx;

  update_thd(thd);

  trx = prebuilt->trx;

  innobase_release_stat_resources(trx);
  trx_mark_sql_stat_end(trx);

  auto_inc_counter_for_this_stat = 0;
  prebuilt->sql_stat_start = TRUE;
  prebuilt->hint_no_need_to_fetch_extra_cols = TRUE;
  prebuilt->read_just_key = 0;

  if (prebuilt->select_lock_type == LOCK_NONE) {
          /* This handle is for a temporary table created inside
          this same LOCK TABLES; since MySQL does NOT call external_lock
          in this case, we must use x-row locks inside InnoDB to be
          prepared for an update of a row */

          prebuilt->select_lock_type = LOCK_X;
  }

  thd->transaction.all.innodb_active_trans = 1;

  return(0);
}

/**********************************************************************
As MySQL will execute an external lock for every new table it uses when it
starts to process an SQL statement, we can use this function to store the
+2 −0
Original line number Diff line number Diff line
@@ -139,6 +139,8 @@ class ha_innobase: public handler
  	int extra(enum ha_extra_function operation);
  	int reset(void);
  	int external_lock(THD *thd, int lock_type);
	int start_stmt(THD *thd);

  	void position(byte *record);
  	ha_rows records_in_range(int inx,
			   const byte *start_key,uint start_key_len,