~drizzle-trunk/drizzle/development

244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
1
/* Copyright (C) 2000-2002 MySQL AB
2
   Copyright (C) 2008 eBay, Inc
3
4
   This program is free software; you can redistribute it and/or modify
5
   it under the terms of the GNU General Public License as published by
6
   the Free Software Foundation; version 2 of the License.
7
8
   This program is distributed in the hope that it will be useful,
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
   GNU General Public License for more details.
12
13
   You should have received a copy of the GNU General Public License
14
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
16
17
/* Implements various base record-related functions, such as encode and decode into chunks */
18
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
19
#include "heap_priv.h"
612.2.13 by Monty Taylor
Work on removing global.h from headers that should be installed.
20
543 by Monty Taylor
Renamed drizzle_common again. Removed sql_common. (empty)
21
#include <drizzled/common.h>
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
22
612.2.13 by Monty Taylor
Work on removing global.h from headers that should be installed.
23
#include <string.h>
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
24
#include <algorithm>
25
26
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
27
using namespace drizzled;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
28
29
/**
30
  Calculate size of the record for the purpose of storing in chunks
31
32
  Walk through the fields of the record and calculates the exact space
33
  needed in chunks as well the the total chunk count
34
35
  @param       info         the hosting table
36
  @param       record       the record in standard unpacked format
37
  @param[out]  chunk_count  the number of chunks needed for this record
38
39
  @return The size of the required storage in bytes
40
*/
41
1749.3.4 by Brian Aker
Next pass through heap.
42
uint32_t hp_get_encoded_data_length(HP_SHARE *info, const unsigned char *, uint32_t *chunk_count)
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
43
{
1707.1.6 by Brian Aker
Style cleanup.
44
  uint32_t dst_offset= info->fixed_data_length;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
45
1749.3.4 by Brian Aker
Next pass through heap.
46
  /* Nothing more to copy */
47
  *chunk_count= 1;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
48
  return dst_offset;
49
}
50
1749.3.8 by Brian Aker
Cleaned up name of calls around datachunk
51
bool hp_compare_record_data_to_chunkset(HP_SHARE *info, const unsigned char *record, unsigned char *pos)
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
52
{
481 by Brian Aker
Remove all of uchar.
53
  unsigned char* curr_chunk= pos;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
54
1749.3.8 by Brian Aker
Cleaned up name of calls around datachunk
55
  if (memcmp(curr_chunk, record, (size_t) info->fixed_data_length))
56
  {
57
    return 1;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
58
  }
59
60
  return 0;
61
}
62
63
/**
64
  Stores record in the heap table chunks
65
66
  Copies data from original unpacked record into the preallocated chunkset
67
68
  @param  info         the hosting table
69
  @param  record       the record in standard unpacked format
70
  @param  pos          the target chunkset
71
*/
72
481 by Brian Aker
Remove all of uchar.
73
void hp_copy_record_data_to_chunkset(HP_SHARE *info, const unsigned char *record, unsigned char *pos)
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
74
{
1749.3.8 by Brian Aker
Cleaned up name of calls around datachunk
75
  unsigned char* curr_chunk= pos;
76
77
  memcpy(curr_chunk, record, (size_t) info->fixed_data_length);
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
78
}
79
80
81
/*
82
  Macro to switch curr_chunk to the next chunk in the chunkset and reset src_offset
83
*/
84
#define SWITCH_TO_NEXT_CHUNK_FOR_READ(info, curr_chunk, src_offset) \
85
      { \
481 by Brian Aker
Remove all of uchar.
86
        curr_chunk= *((unsigned char**) (curr_chunk + info->recordspace.offset_link)); \
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
87
        src_offset= 0; \
88
        /*dump_chunk(info, curr_chunk);*/ \
89
      }
90
91
92
/**
93
  Copies record data from storage to unpacked record format
94
95
  Copies data from chunkset into its original unpacked record
96
97
  @param       info         the hosting table
98
  @param[out]  record       the target record in standard unpacked format
99
  @param       pos          the source chunkset
100
*/
101
481 by Brian Aker
Remove all of uchar.
102
void hp_extract_record(HP_SHARE *info, unsigned char *record, const unsigned char *pos)
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
103
{
481 by Brian Aker
Remove all of uchar.
104
  const unsigned char* curr_chunk= pos;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
105
106
  memcpy(record, curr_chunk, (size_t) info->fixed_data_length);
107
}