Commit c60a8c2f authored by marko's avatar marko

branches/zip: Add row_ext_t for caching prefixes of externally stored columns.

This will be needed for fixing Bug #22496.

REC_MAX_INDEX_COL_LEN: New constant, copied from DICT_MAX_INDEX_COL_LEN.

row_ext_create(), row_ext_lookup(), row_ext_lookup_low(): New functions.
parent 6e269ddf
...@@ -70,6 +70,7 @@ EXTRA_DIST = include/btr0btr.h include/btr0btr.ic include/btr0cur.h include/btr ...@@ -70,6 +70,7 @@ EXTRA_DIST = include/btr0btr.h include/btr0btr.ic include/btr0cur.h include/btr
include/read0read.h include/read0read.ic include/read0types.h \ include/read0read.h include/read0read.ic include/read0types.h \
include/rem0cmp.h include/rem0cmp.ic include/rem0rec.h include/rem0rec.ic \ include/rem0cmp.h include/rem0cmp.ic include/rem0rec.h include/rem0rec.ic \
include/rem0types.h \ include/rem0types.h \
include/row0ext.h include/row0ext.ic \
include/row0ins.h include/row0ins.ic include/row0mysql.h include/row0mysql.ic \ include/row0ins.h include/row0ins.ic include/row0mysql.h include/row0mysql.ic \
include/row0purge.h include/row0purge.ic include/row0row.h include/row0row.ic \ include/row0purge.h include/row0purge.ic include/row0row.h include/row0row.ic \
include/row0sel.h include/row0sel.ic include/row0types.h \ include/row0sel.h include/row0sel.ic include/row0types.h \
......
...@@ -165,12 +165,7 @@ struct dict_col_struct{ ...@@ -165,12 +165,7 @@ struct dict_col_struct{
is defined on the entire column */ is defined on the entire column */
}; };
/* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the max index column #define DICT_MAX_INDEX_COL_LEN REC_MAX_INDEX_COL_LEN
length + 1. Starting from 4.1.6, we set it to < 3 * 256, so that one can
create a column prefix index on 255 characters of a TEXT field also in the
UTF-8 charset. In that charset, a character may take at most 3 bytes. */
#define DICT_MAX_INDEX_COL_LEN 768
/* Data structure for a field in an index */ /* Data structure for a field in an index */
struct dict_field_struct{ struct dict_field_struct{
......
...@@ -17,4 +17,10 @@ typedef byte rec_t; ...@@ -17,4 +17,10 @@ typedef byte rec_t;
#define REC_MAX_HEAP_NO (2 * 8192 - 1) #define REC_MAX_HEAP_NO (2 * 8192 - 1)
#define REC_MAX_N_OWNED (16 - 1) #define REC_MAX_N_OWNED (16 - 1)
/* REC_MAX_INDEX_COL_LEN is measured in bytes and is the max index column
length + 1. Starting from 4.1.6, we set it to 3 * 256, so that one can
create a column prefix index on 255 characters of a TEXT field also in the
UTF-8 charset. Under MySQL, a UTF-8 character may take at most 3 bytes. */
#define REC_MAX_INDEX_COL_LEN 768
#endif #endif
/******************************************************
Caching of externally stored column prefixes
(c) 2006 Innobase Oy
Created September 2006 Marko Makela
*******************************************************/
#ifndef row0ext_h
#define row0ext_h
#include "univ.i"
#include "row0types.h"
#include "mem0mem.h"
/************************************************************************
Creates a cache of column prefixes of externally stored columns. */
UNIV_INLINE
row_ext_t*
row_ext_create(
/*===========*/
/* out,own: column prefix cache */
ulint n_ext, /* in: number of externally stored columns */
const ulint* ext, /* in: col_no's of externally stored columns */
ulint zip_size,/* compressed page size, or 0 */
mem_heap_t* heap); /* in: heap where created */
/************************************************************************
Looks up a column prefix of an externally stored column. */
UNIV_INLINE
byte*
row_ext_lookup(
/*===========*/
/* out: column prefix */
row_ext_t* ext, /* in/out: column prefix cache */
ulint col, /* in: column number */
const byte* field, /* in: locally stored part of the column */
ulint f_len, /* in: length of field, in bytes */
ulint* len); /* out: length of prefix, in bytes,
at most REC_MAX_INDEX_COL_LEN */
/* Prefixes of externally stored columns */
struct row_ext_struct{
ulint n_ext; /* number of externally stored columns */
const ulint* ext; /* col_no's of externally stored columns */
ulint zip_size;/* compressed page size, or 0 */
char* buf; /* backing store of the column prefix cache */
ulint len[1]; /* prefix lengths; 0 if not cached */
};
#ifndef UNIV_NONINL
#include "row0ext.ic"
#endif
#endif
/******************************************************
Caching of externally stored column prefixes
(c) 2006 Innobase Oy
Created September 2006 Marko Makela
*******************************************************/
#include "rem0types.h"
/************************************************************************
Looks up and caches a column prefix of an externally stored column. */
byte*
row_ext_lookup_low(
/*===============*/
/* out: column prefix */
row_ext_t* ext, /* in/out: column prefix cache */
ulint i, /* in: index of ext->ext[] */
const byte* field, /* in: locally stored part of the column */
ulint f_len, /* in: length of field, in bytes */
ulint* len); /* out: length of prefix, in bytes,
at most REC_MAX_INDEX_COL_LEN */
/************************************************************************
Creates a cache of column prefixes of externally stored columns. */
UNIV_INLINE
row_ext_t*
row_ext_create(
/*===========*/
/* out,own: column prefix cache */
ulint n_ext, /* in: number of externally stored columns */
const ulint* ext, /* in: col_no's of externally stored columns */
ulint zip_size,/* compressed page size, or 0 */
mem_heap_t* heap) /* in: heap where created */
{
row_ext_t* ret = mem_heap_alloc(heap, (sizeof *ret) - 1 + n_ext);
ret->n_ext = n_ext;
ret->ext = ext;
ret->zip_size = zip_size;
ret->buf = mem_heap_alloc(heap, n_ext * REC_MAX_INDEX_COL_LEN);
#ifdef UNIV_DEBUG
memset(ret->buf, 0xaa, n_ext * REC_MAX_INDEX_COL_LEN);
#endif
memset(ret->len, 0, n_ext * sizeof *ret->len);
return(ret);
}
/************************************************************************
Looks up a column prefix of an externally stored column. */
UNIV_INLINE
byte*
row_ext_lookup(
/*===========*/
/* out: column prefix */
row_ext_t* ext, /* in/out: column prefix cache */
ulint col, /* in: column number */
const byte* field, /* in: locally stored part of the column */
ulint f_len, /* in: length of field, in bytes */
ulint* len) /* out: length of prefix, in bytes,
at most REC_MAX_INDEX_COL_LEN */
{
ulint i;
ut_ad(ext);
ut_ad(field);
ut_ad(len);
for (i = 0; i < ext->n_ext; i++) {
if (col == ext->ext[i]) {
/* Return from the cache if found */
if (ext->len[i]) {
*len = ext->len[i];
ut_ad(*len > f_len);
return(ext->buf + i * REC_MAX_INDEX_COL_LEN);
}
/* Update the cache */
return(row_ext_lookup_low(ext, i, field, f_len, len));
}
}
/* The column should always be found. */
ut_error;
return(NULL);
}
...@@ -34,4 +34,6 @@ typedef struct undo_node_struct undo_node_t; ...@@ -34,4 +34,6 @@ typedef struct undo_node_struct undo_node_t;
typedef struct purge_node_struct purge_node_t; typedef struct purge_node_struct purge_node_t;
typedef struct row_ext_struct row_ext_t;
#endif #endif
...@@ -19,7 +19,8 @@ include ../include/Makefile.i ...@@ -19,7 +19,8 @@ include ../include/Makefile.i
noinst_LIBRARIES = librow.a noinst_LIBRARIES = librow.a
librow_a_SOURCES = row0ins.c row0mysql.c row0purge.c row0row.c row0sel.c\ librow_a_SOURCES = row0ext.c\
row0ins.c row0mysql.c row0purge.c row0row.c row0sel.c\
row0uins.c row0umod.c row0undo.c row0upd.c row0vers.c row0uins.c row0umod.c row0undo.c row0upd.c row0vers.c
EXTRA_PROGRAMS = EXTRA_PROGRAMS =
/******************************************************
Caching of externally stored column prefixes
(c) 2006 Innobase Oy
Created September 2006 Marko Makela
*******************************************************/
#include "row0ext.h"
#ifdef UNIV_NONINL
#include "row0ext.ic"
#endif
#include "btr0cur.h"
/************************************************************************
Looks up and caches a column prefix of an externally stored column. */
byte*
row_ext_lookup_low(
/*===============*/
/* out: column prefix */
row_ext_t* ext, /* in/out: column prefix cache */
ulint i, /* in: index of ext->ext[] */
const byte* field, /* in: locally stored part of the column */
ulint f_len, /* in: length of field, in bytes */
ulint* len) /* out: length of prefix, in bytes,
at most REC_MAX_INDEX_COL_LEN */
{
byte* buf = ext->buf + i * REC_MAX_INDEX_COL_LEN;
ut_ad(i < ext->n_ext);
*len = ext->len[i] = btr_copy_externally_stored_field_prefix(
buf,
REC_MAX_INDEX_COL_LEN, ext->zip_size, field, f_len);
return(buf);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment