Commit 7955fe52 authored by unknown's avatar unknown
Browse files

Many files:

  InnoDB true VARCHAR


sql/ha_innodb.h:
  InnoDB true VARCHAR
sql/ha_innodb.cc:
  InnoDB true VARCHAR
innobase/include/data0type.h:
  InnoDB true VARCHAR
innobase/include/que0que.h:
  InnoDB true VARCHAR
innobase/include/row0mysql.h:
  InnoDB true VARCHAR
innobase/include/data0type.ic:
  InnoDB true VARCHAR
innobase/include/row0mysql.ic:
  InnoDB true VARCHAR
innobase/row/row0ins.c:
  InnoDB true VARCHAR
innobase/row/row0mysql.c:
  InnoDB true VARCHAR
innobase/row/row0sel.c:
  InnoDB true VARCHAR
innobase/trx/trx0trx.c:
  InnoDB true VARCHAR
parent 4db638f3
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -24,7 +24,11 @@ extern dtype_t* dtype_binary;
/*-------------------------------------------*/
/* The 'MAIN TYPE' of a column */
#define	DATA_VARCHAR	1	/* character varying of the
				latin1_swedish_ci charset-collation */
				latin1_swedish_ci charset-collation; note
				that the MySQL format for this, DATA_BINARY,
				DATA_VARMYSQL, is also affected by whether the
				'precise type' contains
				DATA_MYSQL_TRUE_VARCHAR */
#define DATA_CHAR	2	/* fixed length character of the
				latin1_swedish_ci charset-collation */
#define DATA_FIXBINARY	3	/* binary string of fixed length */
@@ -102,6 +106,8 @@ columns, and for them the precise type is usually not used at all.

#define DATA_MYSQL_TYPE_MASK 255 /* AND with this mask to extract the MySQL
				 type from the precise type */
#define DATA_MYSQL_TRUE_VARCHAR 15 /* MySQL type code for the >= 5.0.3
				   format true VARCHAR */

/* Precise data types for system columns and the length of those columns;
NOTE: the values must run from 0 up in the order given! All codes must
@@ -134,6 +140,10 @@ be less than 256 */
				In earlier versions this was set for some
				BLOB columns.
*/
#define	DATA_LONG_TRUE_VARCHAR 4096	/* this is ORed to the precise data
				type when the column is true VARCHAR where
				MySQL uses 2 bytes to store the data len;
				for shorter VARCHARs MySQL uses only 1 byte */
/*-------------------------------------------*/

/* This many bytes we need to store the type information affecting the
@@ -144,6 +154,15 @@ SQL null*/
store the charset-collation number; one byte is left unused, though */
#define DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE	6

/*************************************************************************
Gets the MySQL type code from a dtype. */
UNIV_INLINE
ulint
dtype_get_mysql_type(
/*=================*/
				/* out: MySQL type code; this is NOT an InnoDB
				type code! */
	dtype_t*	type);	/* in: type struct */
/*************************************************************************
Determine how many bytes the first n characters of the given string occupy.
If the string is shorter than n characters, returns the number of bytes
+13 −0
Original line number Diff line number Diff line
@@ -32,6 +32,19 @@ dtype_get_charset_coll(
	return((prtype >> 16) & 0xFFUL);
}

/*************************************************************************
Gets the MySQL type code from a dtype. */
UNIV_INLINE
ulint
dtype_get_mysql_type(
/*=================*/
				/* out: MySQL type code; this is NOT an InnoDB
				type code! */
	dtype_t*	type)	/* in: type struct */
{
	return(type->prtype & 0xFFUL);
}

/*************************************************************************
Sets the mbminlen and mbmaxlen members of a data type structure. */
UNIV_INLINE
+2 −1
Original line number Diff line number Diff line
@@ -359,7 +359,8 @@ struct que_thr_struct{
					the control came */
	ulint		resource;	/* resource usage of the query thread
					thus far */
  ulint   lock_state;	/* lock state of thread (table or row) */
  	ulint   	lock_state;	/* lock state of thread (table or
					row) */
};

#define QUE_THR_MAGIC_N		8476583
+61 −41
Original line number Diff line number Diff line
@@ -21,36 +21,6 @@ Created 9/17/2000 Heikki Tuuri

typedef struct row_prebuilt_struct row_prebuilt_t;

/***********************************************************************
Stores a variable-length field (like VARCHAR) length to dest, in the
MySQL format. */
UNIV_INLINE
byte*
row_mysql_store_var_len(
/*====================*/
			/* out: dest + 2 */
	byte*	dest,	/* in: where to store */
	ulint	len);	/* in: length, must fit in two bytes */
/***********************************************************************
Reads a MySQL format variable-length field (like VARCHAR) length and
returns pointer to the field data. */
UNIV_INLINE
byte*
row_mysql_read_var_ref(
/*===================*/
			/* out: field + 2 */
	ulint*	len,	/* out: variable-length field length */
	byte*	field);	/* in: field */
/***********************************************************************
Reads a MySQL format variable-length field (like VARCHAR) length and
returns pointer to the field data. */

byte*
row_mysql_read_var_ref_noninline(
/*=============================*/
			/* out: field + 2 */
	ulint*	len,	/* out: variable-length field length */
	byte*	field);	/* in: field */
/***********************************************************************
Frees the blob heap in prebuilt when no longer needed. */

@@ -60,6 +30,30 @@ row_mysql_prebuilt_free_blob_heap(
	row_prebuilt_t*	prebuilt);	/* in: prebuilt struct of a
					ha_innobase:: table handle */
/***********************************************************************
Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row
format. */

byte*
row_mysql_store_true_var_len(
/*=========================*/
			/* out: pointer to the data, we skip the 1 or 2 bytes
			at the start that are used to store the len */
	byte*	dest,	/* in: where to store */
	ulint	len,	/* in: length, must fit in two bytes */
	ulint	lenlen);/* in: storage length of len: either 1 or 2 bytes */
/***********************************************************************
Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and
returns a pointer to the data. */

byte*
row_mysql_read_true_varchar(
/*========================*/
			/* out: pointer to the data, we skip the 1 or 2 bytes
			at the start that are used to store the len */
	ulint*	len,	/* out: variable-length field length */
	byte*	field,	/* in: field in the MySQL format */
	ulint	lenlen);/* in: storage length of len: either 1 or 2 bytes */
/***********************************************************************
Stores a reference to a BLOB in the MySQL format. */

void
@@ -83,24 +77,40 @@ row_mysql_read_blob_ref(
	ulint	col_len);	/* in: BLOB reference length (not BLOB
				length) */
/******************************************************************
Stores a non-SQL-NULL field given in the MySQL format in the Innobase
format. */
UNIV_INLINE
void
Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format.
The counterpart of this function is row_sel_field_store_in_mysql_format() in
row0sel.c. */

byte*
row_mysql_store_col_in_innobase_format(
/*===================================*/
	dfield_t*	dfield,		/* in/out: dfield */
	byte*		buf,		/* in/out: buffer for the converted
					value */
					/* out: up to which byte we used
					buf in the conversion */
	dfield_t*	dfield,		/* in/out: dfield where dtype
					information must be already set when
					this function is called! */
	byte*		buf,		/* in/out: buffer for a converted
					integer value; this must be at least
					col_len long then! */
	ibool		row_format_col,	/* TRUE if the mysql_data is from
					a MySQL row, FALSE if from a MySQL
					key value;
					in MySQL, a true VARCHAR storage
					format differs in a row and in a
					key value: in a key value the length
					is always stored in 2 bytes! */
	byte*		mysql_data,	/* in: MySQL column value, not
					SQL NULL; NOTE that dfield may also
					get a pointer to mysql_data,
					therefore do not discard this as long
					as dfield is used! */
	ulint		col_len,	/* in: MySQL column length */
	ulint		type,		/* in: data type */
	bool		comp,		/* in: TRUE=compact format */
	ulint		is_unsigned);	/* in: != 0 if unsigned integer type */
	ulint		col_len,	/* in: MySQL column length; NOTE that
					this is the storage length of the
					column in the MySQL format row, not
					necessarily the length of the actual
					payload data; if the column is a true
					VARCHAR then this is irrelevant */
	ibool		comp);		/* in: TRUE = compact format */
/********************************************************************
Handles user errors and lock waits detected by the database engine. */

@@ -457,6 +467,16 @@ struct mysql_row_templ_struct {
					zero if column cannot be NULL */
	ulint	type;			/* column type in Innobase mtype
					numbers DATA_CHAR... */
	ulint	mysql_type;		/* MySQL type code; this is always
					< 256 */
	ulint	mysql_length_bytes;	/* if mysql_type
					== DATA_MYSQL_TRUE_VARCHAR, this tells
					whether we should use 1 or 2 bytes to
					store the MySQL true VARCHAR data
					length at the start of row in the MySQL
					format (NOTE that the MySQL key value
					format always uses 2 bytes for the data
					len) */ 
	ulint	charset;		/* MySQL charset-collation code
					of the column, or zero */
	ulint	mbminlen;		/* minimum length of a char, in bytes,
+0 −146
Original line number Diff line number Diff line
@@ -5,149 +5,3 @@ MySQL interface for Innobase

Created 1/23/2001 Heikki Tuuri
*******************************************************/

/***********************************************************************
Stores a variable-length field (like VARCHAR) length to dest, in the
MySQL format. No real var implemented in MySQL yet! */
UNIV_INLINE
byte*
row_mysql_store_var_len(
/*====================*/
			/* out: dest + 2 */
	byte*	dest,	/* in: where to store */
	ulint	len __attribute__((unused)))  /* in: length, must fit in two
                                                 bytes */
{
	ut_ad(len < 256 * 256);
/*	
	mach_write_to_2_little_endian(dest, len);

	return(dest + 2);
*/
	return(dest);	/* No real var implemented in MySQL yet! */
}

/***********************************************************************
Reads a MySQL format variable-length field (like VARCHAR) length and
returns pointer to the field data. No real var implemented in MySQL yet! */
UNIV_INLINE
byte*
row_mysql_read_var_ref(
/*===================*/
			/* out: field + 2 */
	ulint*	len,	/* out: variable-length field length; does not work
			yet! */
	byte*	field)	/* in: field */
{
/*	
	*len = mach_read_from_2_little_endian(field);

	return(field + 2);
*/
	UT_NOT_USED(len);

	return(field);	/* No real var implemented in MySQL yet! */
}

/******************************************************************
Stores a non-SQL-NULL field given in the MySQL format in the Innobase
format. */
UNIV_INLINE
void
row_mysql_store_col_in_innobase_format(
/*===================================*/
	dfield_t*	dfield,		/* in/out: dfield */
	byte*		buf,		/* in/out: buffer for the converted
					value; this must be at least col_len
					long! */
	byte*		mysql_data,	/* in: MySQL column value, not
					SQL NULL; NOTE that dfield may also
					get a pointer to mysql_data,
					therefore do not discard this as long
					as dfield is used! */
	ulint		col_len,	/* in: MySQL column length */
	ulint		type,		/* in: data type */
	bool		comp,		/* in: TRUE=compact format */
	ulint		is_unsigned)	/* in: != 0 if unsigned integer type */
{
	byte*	ptr 	= mysql_data;

	if (type == DATA_INT) {
		/* Store integer data in Innobase in a big-endian format,
		sign bit negated */

		ptr = buf + col_len;

		for (;;) {
			ptr--;
			*ptr = *mysql_data;
			if (ptr == buf) {
				break;
			}
			mysql_data++;
		}

		if (!is_unsigned) {
			*ptr = (byte) (*ptr ^ 128);
		}
	} else if (type == DATA_VARCHAR || type == DATA_VARMYSQL
						|| type == DATA_BINARY) {
		/* Remove trailing spaces. */

		/* Handle UCS2 strings differently. */
		ulint	mbminlen	= dtype_get_mbminlen(
						dfield_get_type(dfield));
		ptr = row_mysql_read_var_ref(&col_len, mysql_data);
		if (mbminlen == 2) {
			/* space=0x0020 */
			/* Trim "half-chars", just in case. */
			col_len &= ~1;

			while (col_len >= 2 && ptr[col_len - 2] == 0x00
					&& ptr[col_len - 1] == 0x20) {
				col_len -= 2;
			}
		} else {
			ut_a(mbminlen == 1);
			/* space=0x20 */
			while (col_len > 0 && ptr[col_len - 1] == 0x20) {
				col_len--;
			}
		}
	} else if (comp && type == DATA_MYSQL
			&& dtype_get_mbminlen(dfield_get_type(dfield)) == 1
			&& dtype_get_mbmaxlen(dfield_get_type(dfield)) > 1) {
		/* We assume that this CHAR field is encoded in a
		variable-length character set where spaces have
		1:1 correspondence to 0x20 bytes, such as UTF-8.

		Consider a CHAR(n) field, a field of n characters.
		It will contain between n*mbminlen and n*mbmaxlen bytes.
		We will try to truncate it to n bytes by stripping
		space padding.  If the field contains single-byte
		characters only, it will be truncated to n characters.
		Consider a CHAR(5) field containing the string ".a   "
		where "." denotes a 3-byte character represented by
		the bytes "$%&".  After our stripping, the string will
		be stored as "$%&a " (5 bytes).  The string ".abc "
		will be stored as "$%&abc" (6 bytes).

		The space padding will be restored in row0sel.c, function
		row_sel_field_store_in_mysql_format(). */

		ulint		n_chars;
		dtype_t*	dtype = dfield_get_type(dfield);

		ut_a(!(dtype_get_len(dtype) % dtype_get_mbmaxlen(dtype)));
		n_chars = dtype_get_len(dtype) / dtype_get_mbmaxlen(dtype);

		/* Strip space padding. */
		while (col_len > n_chars && ptr[col_len - 1] == 0x20) {
			col_len--;
		}
	} else if (type == DATA_BLOB) {
		ptr = row_mysql_read_blob_ref(&col_len, mysql_data, col_len);
	}

	dfield_set_data(dfield, ptr, col_len);
}
Loading