~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   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.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
16
#include "heap_priv.h"
549 by Monty Taylor
Took gettext.h out of header files.
17
#include <drizzled/error.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
18
#include <drizzled/table.h>
19
#include <drizzled/session.h>
584.5.1 by Monty Taylor
Removed field includes from field.h.
20
#include <drizzled/field/timestamp.h>
21
#include <drizzled/field/varstring.h>
1324.2.3 by Monty Taylor
Remove plugin deinit.
22
#include "drizzled/plugin/daemon.h"
1 by brian
clean slate
23
1689.3.6 by Brian Aker
Update for HEAP to convert its lock to boost.
24
#include <boost/thread/mutex.hpp>
25
992.1.26 by Monty Taylor
Moved heap.
26
#include "heap.h"
27
#include "ha_heap.h"
28
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
29
#include <string>
30
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
31
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
32
using namespace drizzled;
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
33
using namespace std;
34
35
static const string engine_name("MEMORY");
36
1689.3.6 by Brian Aker
Update for HEAP to convert its lock to boost.
37
boost::mutex THR_LOCK_heap;
596 by Brian Aker
Refactor out dead mutexes
38
1039.3.1 by Stewart Smith
move bas_ext to StorageEngine instead of handler
39
static const char *ha_heap_exts[] = {
40
  NULL
41
};
960.2.31 by Monty Taylor
Fixed Heap.
42
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
43
class HeapEngine : public plugin::StorageEngine
960.2.31 by Monty Taylor
Fixed Heap.
44
{
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
45
public:
1324.2.13 by Monty Taylor
Took Jay's note and removed the HeapCleanup engine.
46
  explicit HeapEngine(string name_arg) :
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
47
    plugin::StorageEngine(name_arg,
48
                          HTON_STATS_RECORDS_IS_EXACT |
49
                          HTON_NULL_IN_KEY |
50
                          HTON_FAST_KEY_READ |
51
                          HTON_NO_BLOBS |
52
                          HTON_HAS_RECORDS |
53
                          HTON_SKIP_STORE_LOCK |
54
                          HTON_TEMPORARY_ONLY)
1324.2.13 by Monty Taylor
Took Jay's note and removed the HeapCleanup engine.
55
  {
56
  }
57
58
  virtual ~HeapEngine()
59
  {
60
    hp_panic(HA_PANIC_CLOSE);
61
  }
971.1.25 by Monty Taylor
Moved StorageEngine onto drizzled::Registry.
62
1869.1.4 by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy
63
  virtual Cursor *create(Table &table)
960.2.31 by Monty Taylor
Fixed Heap.
64
  {
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
65
    return new ha_heap(*this, table);
960.2.31 by Monty Taylor
Fixed Heap.
66
  }
1039.3.1 by Stewart Smith
move bas_ext to StorageEngine instead of handler
67
68
  const char **bas_ext() const {
69
    return ha_heap_exts;
70
  }
1039.3.2 by Stewart Smith
move delete_table out of handler and up into StorageEngine where it belongs.
71
1413 by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference.
72
  int doCreateTable(Session &session,
73
                    Table &table_arg,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
74
                    const TableIdentifier &identifier,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
75
                    message::Table &create_proto);
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
76
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
77
  /* For whatever reason, internal tables can be created by Cursor::open()
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
78
     for MEMORY.
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
79
     Instead of diving down a rat hole, let's just cry ourselves to sleep
80
     at night with this odd hackish workaround.
81
   */
82
  int heap_create_table(Session *session, const char *table_name,
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
83
                        Table *table_arg,
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
84
                        bool internal_table,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
85
                        message::Table &create_proto,
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
86
                        HP_SHARE **internal_share);
87
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
88
  int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
1039.3.5 by Stewart Smith
move handler::rename_table to StorageEngine
89
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
90
  int doDropTable(Session&, const TableIdentifier &identifier);
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
91
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
92
  int doGetTableDefinition(Session& session,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
93
                           const TableIdentifier &identifier,
1354.1.1 by Brian Aker
Modify ptr to reference.
94
                           message::Table &table_message);
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
95
1233.1.9 by Brian Aker
Move max key stuff up to engine.
96
  uint32_t max_supported_keys()          const { return MAX_KEY; }
97
  uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
1235.1.13 by Brian Aker
Next pass through interface to move index flag bits up to engine.
98
1711.6.12 by Brian Aker
This removes the b-tree from heap (it currently crashes the server (both
99
  uint32_t index_flags(enum  ha_key_alg ) const
1235.1.13 by Brian Aker
Next pass through interface to move index flag bits up to engine.
100
  {
1711.6.12 by Brian Aker
This removes the b-tree from heap (it currently crashes the server (both
101
    return ( HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR);
1235.1.13 by Brian Aker
Next pass through interface to move index flag bits up to engine.
102
  }
103
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
104
  bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
105
  void doGetTableIdentifiers(CachedDirectory &directory,
1642 by Brian Aker
This adds const to SchemaIdentifier.
106
                             const SchemaIdentifier &schema_identifier,
1966.2.4 by Brian Aker
Style cleanup.
107
                             TableIdentifier::vector &set_of_identifiers);
960.2.31 by Monty Taylor
Fixed Heap.
108
};
109
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
110
void HeapEngine::doGetTableIdentifiers(CachedDirectory&,
1642 by Brian Aker
This adds const to SchemaIdentifier.
111
                                       const SchemaIdentifier&,
1966.2.4 by Brian Aker
Style cleanup.
112
                                       TableIdentifier::vector&)
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
113
{
114
}
115
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
116
bool HeapEngine::doDoesTableExist(Session& session, const TableIdentifier &identifier)
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
117
{
1923.1.4 by Brian Aker
Encapsulate up the cache we use in Session for tracking table proto for temp
118
  return session.getMessageCache().doesTableMessageExist(identifier);
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
119
}
120
121
int HeapEngine::doGetTableDefinition(Session &session,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
122
                                     const TableIdentifier &identifier,
1354.1.1 by Brian Aker
Modify ptr to reference.
123
                                     message::Table &table_proto)
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
124
{
1923.1.4 by Brian Aker
Encapsulate up the cache we use in Session for tracking table proto for temp
125
  if (session.getMessageCache().getTableMessage(identifier, table_proto))
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
126
    return EEXIST;
127
128
  return ENOENT;
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
129
}
1039.3.2 by Stewart Smith
move delete_table out of handler and up into StorageEngine where it belongs.
130
/*
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
131
  We have to ignore ENOENT entries as the MEMORY table is created on open and
1039.3.2 by Stewart Smith
move delete_table out of handler and up into StorageEngine where it belongs.
132
  not when doing a CREATE on the table.
133
*/
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
134
int HeapEngine::doDropTable(Session &session, const TableIdentifier &identifier)
1039.3.2 by Stewart Smith
move delete_table out of handler and up into StorageEngine where it belongs.
135
{
1923.1.4 by Brian Aker
Encapsulate up the cache we use in Session for tracking table proto for temp
136
  session.getMessageCache().removeTableMessage(identifier);
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
137
1395.1.12 by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error
138
  int error= heap_delete_table(identifier.getPath().c_str());
139
140
  if (error == ENOENT)
141
    error= 0;
142
143
  return error;
1039.3.2 by Stewart Smith
move delete_table out of handler and up into StorageEngine where it belongs.
144
}
145
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
146
static HeapEngine *heap_storage_engine= NULL;
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
147
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
148
static int heap_init(module::Context &context)
960.2.31 by Monty Taylor
Fixed Heap.
149
{
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
150
  heap_storage_engine= new HeapEngine(engine_name);
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
151
  context.add(heap_storage_engine);
960.2.31 by Monty Taylor
Fixed Heap.
152
  return 0;
153
}
154
1 by brian
clean slate
155
156
/*****************************************************************************
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
157
** MEMORY tables
1 by brian
clean slate
158
*****************************************************************************/
159
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
160
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
1869.1.4 by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy
161
                 Table &table_arg)
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
162
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
1 by brian
clean slate
163
  internal_table(0)
164
{}
165
166
/*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
167
  Hash index statistics is updated (copied from HP_KEYDEF::hash_buckets to
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
168
  rec_per_key) after 1/MEMORY_STATS_UPDATE_THRESHOLD fraction of table records
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
169
  have been inserted/updated/deleted. delete_all_rows() and table flush cause
1 by brian
clean slate
170
  immediate update.
171
172
  NOTE
173
   hash index statistics must be updated when number of table records changes
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
174
   from 0 to non-zero value and vice versa. Otherwise records_in_range may
1 by brian
clean slate
175
   erroneously return 0 and 'range' may miss records.
176
*/
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
177
#define MEMORY_STATS_UPDATE_THRESHOLD 10
1 by brian
clean slate
178
1749.3.17 by Brian Aker
Remove direct use of name from heap.
179
int ha_heap::doOpen(const drizzled::TableIdentifier &identifier, int mode, uint32_t test_if_locked)
1 by brian
clean slate
180
{
1749.3.17 by Brian Aker
Remove direct use of name from heap.
181
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(identifier.getPath().c_str(), mode)) && errno == ENOENT))
1 by brian
clean slate
182
  {
183
    internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
184
    file= 0;
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
185
    HP_SHARE *internal_share= NULL;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
186
    message::Table create_proto;
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
187
1869.1.5 by Brian Aker
getTable()
188
    if (not heap_storage_engine->heap_create_table(getTable()->in_use,
1749.3.17 by Brian Aker
Remove direct use of name from heap.
189
                                                   identifier.getPath().c_str(),
1869.1.5 by Brian Aker
getTable()
190
                                                   getTable(),
1749.3.17 by Brian Aker
Remove direct use of name from heap.
191
                                                   internal_table,
192
                                                   create_proto,
193
                                                   &internal_share))
1 by brian
clean slate
194
    {
195
        file= internal_table ?
196
          heap_open_from_share(internal_share, mode) :
197
          heap_open_from_share_and_register(internal_share, mode);
198
      if (!file)
199
      {
200
         /* Couldn't open table; Remove the newly created table */
1689.3.6 by Brian Aker
Update for HEAP to convert its lock to boost.
201
        THR_LOCK_heap.lock();
1 by brian
clean slate
202
        hp_free(internal_share);
1689.3.6 by Brian Aker
Update for HEAP to convert its lock to boost.
203
        THR_LOCK_heap.unlock();
1 by brian
clean slate
204
      }
205
    }
206
  }
207
  ref_length= sizeof(HEAP_PTR);
208
  if (file)
209
  {
210
    /* Initialize variables for the opened table */
211
    set_keys_for_scanning();
212
    /*
213
      We cannot run update_key_stats() here because we do not have a
214
      lock on the table. The 'records' count might just be changed
215
      temporarily at this moment and we might get wrong statistics (Bug
216
      #10178). Instead we request for update. This will be done in
217
      ha_heap::info(), which is always called before key statistics are
218
      used.
219
    */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
220
    key_stat_version= file->getShare()->key_stat_version - 1;
1 by brian
clean slate
221
  }
222
  return (file ? 0 : 1);
223
}
224
225
int ha_heap::close(void)
226
{
227
  return internal_table ? hp_close(file) : heap_close(file);
228
}
229
230
231
/*
232
  Create a copy of this table
233
234
  DESCRIPTION
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
235
    Do same as default implementation but use file->s->name instead of
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
236
    table->getShare()->path. This is needed by Windows where the clone() call sees
237
    '/'-delimited path in table->getShare()->path, while ha_peap::open() was called
1 by brian
clean slate
238
    with '\'-delimited path.
239
*/
240
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
241
Cursor *ha_heap::clone(memory::Root *)
1 by brian
clean slate
242
{
1869.1.5 by Brian Aker
getTable()
243
  Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
244
  TableIdentifier identifier(getTable()->getShare()->getSchemaName(),
245
                             getTable()->getShare()->getTableName(),
246
                             getTable()->getShare()->getPath());
1185 by Brian Aker
Merge Engine changes.
247
1869.1.7 by Brian Aker
Cleanup of caller to ha_open().
248
  if (new_handler && !new_handler->ha_open(identifier, getTable()->db_stat,
1 by brian
clean slate
249
                                           HA_OPEN_IGNORE_IF_LOCKED))
250
    return new_handler;
971.6.11 by Eric Day
Removed purecov messages.
251
  return NULL;
1 by brian
clean slate
252
}
253
254
1711.6.12 by Brian Aker
This removes the b-tree from heap (it currently crashes the server (both
255
const char *ha_heap::index_type(uint32_t )
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
256
{
1711.6.12 by Brian Aker
This removes the b-tree from heap (it currently crashes the server (both
257
  return ("HASH");
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
258
}
259
260
1 by brian
clean slate
261
/*
262
  Compute which keys to use for scanning
263
264
  SYNOPSIS
265
    set_keys_for_scanning()
266
    no parameter
267
268
  DESCRIPTION
269
    Set the bitmap btree_keys, which is used when the upper layers ask
270
    which keys to use for scanning. For each btree index the
271
    corresponding bit is set.
272
273
  RETURN
274
    void
275
*/
276
277
void ha_heap::set_keys_for_scanning(void)
278
{
279
}
280
281
282
void ha_heap::update_key_stats()
283
{
1869.1.5 by Brian Aker
getTable()
284
  for (uint32_t i= 0; i < getTable()->getShare()->sizeKeys(); i++)
1 by brian
clean slate
285
  {
1869.1.5 by Brian Aker
getTable()
286
    KeyInfo *key= &getTable()->key_info[i];
1711.6.12 by Brian Aker
This removes the b-tree from heap (it currently crashes the server (both
287
1 by brian
clean slate
288
    if (!key->rec_per_key)
289
      continue;
1711.6.12 by Brian Aker
This removes the b-tree from heap (it currently crashes the server (both
290
1 by brian
clean slate
291
    {
292
      if (key->flags & HA_NOSAME)
293
        key->rec_per_key[key->key_parts-1]= 1;
294
      else
295
      {
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
296
        ha_rows hash_buckets= file->getShare()->keydef[i].hash_buckets;
297
        uint32_t no_records= hash_buckets ? (uint) (file->getShare()->records/hash_buckets) : 2;
1 by brian
clean slate
298
        if (no_records < 2)
299
          no_records= 2;
300
        key->rec_per_key[key->key_parts-1]= no_records;
301
      }
302
    }
303
  }
304
  records_changed= 0;
305
  /* At the end of update_key_stats() we can proudly claim they are OK. */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
306
  key_stat_version= file->getShare()->key_stat_version;
1 by brian
clean slate
307
}
308
309
1491.1.2 by Jay Pipes
Cursor::write_row() -> Cursor::doInsertRecord(). Cursor::ha_write_row() -> Cursor::insertRecord()
310
int ha_heap::doInsertRecord(unsigned char * buf)
1 by brian
clean slate
311
{
312
  int res;
1869.1.5 by Brian Aker
getTable()
313
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
1 by brian
clean slate
314
  {
315
    if ((res= update_auto_increment()))
316
      return res;
317
  }
318
  res= heap_write(file,buf);
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
319
  if (!res && (++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
320
               file->getShare()->records))
1 by brian
clean slate
321
  {
322
    /*
323
       We can perform this safely since only one writer at the time is
324
       allowed on the table.
325
    */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
326
    file->getShare()->key_stat_version++;
1 by brian
clean slate
327
  }
328
  return res;
329
}
330
1491.1.3 by Jay Pipes
Cursor::update_row() changed to doUpdateRecord() and updateRecord()
331
int ha_heap::doUpdateRecord(const unsigned char * old_data, unsigned char * new_data)
1 by brian
clean slate
332
{
333
  int res;
1619.3.5 by Stewart Smith
move ha_statistic_increment for ha_update_count (the Handler_update status variable) to the Cursor layer so that each Storage Engine's Cursor doesn't have to increment it.
334
1 by brian
clean slate
335
  res= heap_update(file,old_data,new_data);
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
336
  if (!res && ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
337
              file->getShare()->records)
1 by brian
clean slate
338
  {
339
    /*
340
       We can perform this safely since only one writer at the time is
341
       allowed on the table.
342
    */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
343
    file->getShare()->key_stat_version++;
1 by brian
clean slate
344
  }
345
  return res;
346
}
347
1491.1.4 by Jay Pipes
delete_row() is now deleteRecord() and doDeleteRecord() in Cursor
348
int ha_heap::doDeleteRecord(const unsigned char * buf)
1 by brian
clean slate
349
{
350
  int res;
1619.3.7 by Stewart Smith
move ha_statistic_increment for ha_delete_count (the Handler_delete status variable) to the Cursor layer so that each Storage Engine's Cursor doesn't have to increment it.
351
1 by brian
clean slate
352
  res= heap_delete(file,buf);
1869.1.5 by Brian Aker
getTable()
353
  if (!res && getTable()->getShare()->getType() == message::Table::STANDARD &&
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
354
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->getShare()->records)
1 by brian
clean slate
355
  {
356
    /*
357
       We can perform this safely since only one writer at the time is
358
       allowed on the table.
359
    */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
360
    file->getShare()->key_stat_version++;
1 by brian
clean slate
361
  }
362
  return res;
363
}
364
481 by Brian Aker
Remove all of uchar.
365
int ha_heap::index_read_map(unsigned char *buf, const unsigned char *key,
1 by brian
clean slate
366
                            key_part_map keypart_map,
367
                            enum ha_rkey_function find_flag)
368
{
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
369
  assert(inited==INDEX);
1273.16.8 by Brian Aker
Remove typedef.
370
  ha_statistic_increment(&system_status_var::ha_read_key_count);
1 by brian
clean slate
371
  int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
1869.1.5 by Brian Aker
getTable()
372
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
1 by brian
clean slate
373
  return error;
374
}
375
481 by Brian Aker
Remove all of uchar.
376
int ha_heap::index_read_last_map(unsigned char *buf, const unsigned char *key,
1 by brian
clean slate
377
                                 key_part_map keypart_map)
378
{
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
379
  assert(inited==INDEX);
1273.16.8 by Brian Aker
Remove typedef.
380
  ha_statistic_increment(&system_status_var::ha_read_key_count);
1 by brian
clean slate
381
  int error= heap_rkey(file, buf, active_index, key, keypart_map,
382
		       HA_READ_PREFIX_LAST);
1869.1.5 by Brian Aker
getTable()
383
  getTable()->status= error ? STATUS_NOT_FOUND : 0;
1 by brian
clean slate
384
  return error;
385
}
386
482 by Brian Aker
Remove uint.
387
int ha_heap::index_read_idx_map(unsigned char *buf, uint32_t index, const unsigned char *key,
1 by brian
clean slate
388
                                key_part_map keypart_map,
389
                                enum ha_rkey_function find_flag)
390
{
1273.16.8 by Brian Aker
Remove typedef.
391
  ha_statistic_increment(&system_status_var::ha_read_key_count);
1 by brian
clean slate
392
  int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
1869.1.5 by Brian Aker
getTable()
393
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
1 by brian
clean slate
394
  return error;
395
}
396
481 by Brian Aker
Remove all of uchar.
397
int ha_heap::index_next(unsigned char * buf)
1 by brian
clean slate
398
{
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
399
  assert(inited==INDEX);
1273.16.8 by Brian Aker
Remove typedef.
400
  ha_statistic_increment(&system_status_var::ha_read_next_count);
1 by brian
clean slate
401
  int error=heap_rnext(file,buf);
1869.1.5 by Brian Aker
getTable()
402
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
1 by brian
clean slate
403
  return error;
404
}
405
481 by Brian Aker
Remove all of uchar.
406
int ha_heap::index_prev(unsigned char * buf)
1 by brian
clean slate
407
{
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
408
  assert(inited==INDEX);
1273.16.8 by Brian Aker
Remove typedef.
409
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
1 by brian
clean slate
410
  int error=heap_rprev(file,buf);
1869.1.5 by Brian Aker
getTable()
411
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
1 by brian
clean slate
412
  return error;
413
}
414
481 by Brian Aker
Remove all of uchar.
415
int ha_heap::index_first(unsigned char * buf)
1 by brian
clean slate
416
{
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
417
  assert(inited==INDEX);
1273.16.8 by Brian Aker
Remove typedef.
418
  ha_statistic_increment(&system_status_var::ha_read_first_count);
1 by brian
clean slate
419
  int error=heap_rfirst(file, buf, active_index);
1869.1.5 by Brian Aker
getTable()
420
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
1 by brian
clean slate
421
  return error;
422
}
423
481 by Brian Aker
Remove all of uchar.
424
int ha_heap::index_last(unsigned char * buf)
1 by brian
clean slate
425
{
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
426
  assert(inited==INDEX);
1273.16.8 by Brian Aker
Remove typedef.
427
  ha_statistic_increment(&system_status_var::ha_read_last_count);
1 by brian
clean slate
428
  int error=heap_rlast(file, buf, active_index);
1869.1.5 by Brian Aker
getTable()
429
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
1 by brian
clean slate
430
  return error;
431
}
432
1491.1.10 by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan
433
int ha_heap::doStartTableScan(bool scan)
1 by brian
clean slate
434
{
435
  return scan ? heap_scan_init(file) : 0;
436
}
437
481 by Brian Aker
Remove all of uchar.
438
int ha_heap::rnd_next(unsigned char *buf)
1 by brian
clean slate
439
{
1273.16.8 by Brian Aker
Remove typedef.
440
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
1 by brian
clean slate
441
  int error=heap_scan(file, buf);
1869.1.5 by Brian Aker
getTable()
442
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
1 by brian
clean slate
443
  return error;
444
}
445
481 by Brian Aker
Remove all of uchar.
446
int ha_heap::rnd_pos(unsigned char * buf, unsigned char *pos)
1 by brian
clean slate
447
{
448
  int error;
449
  HEAP_PTR heap_position;
1273.16.8 by Brian Aker
Remove typedef.
450
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
212.6.8 by Mats Kindahl
Removing extreneous explicit casts for the heap storage engine.
451
  memcpy(&heap_position, pos, sizeof(HEAP_PTR));
1 by brian
clean slate
452
  error=heap_rrnd(file, buf, heap_position);
1869.1.5 by Brian Aker
getTable()
453
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
1 by brian
clean slate
454
  return error;
455
}
456
653 by Brian Aker
More solaris bits
457
void ha_heap::position(const unsigned char *)
1 by brian
clean slate
458
{
459
  *(HEAP_PTR*) ref= heap_position(file);	// Ref is aligned
460
}
461
482 by Brian Aker
Remove uint.
462
int ha_heap::info(uint32_t flag)
1 by brian
clean slate
463
{
464
  HEAPINFO hp_info;
465
  (void) heap_info(file,&hp_info,flag);
466
467
  errkey=                     hp_info.errkey;
468
  stats.records=              hp_info.records;
469
  stats.deleted=              hp_info.deleted;
470
  stats.mean_rec_length=      hp_info.reclength;
471
  stats.data_file_length=     hp_info.data_length;
472
  stats.index_file_length=    hp_info.index_length;
473
  stats.max_data_file_length= hp_info.max_records * hp_info.reclength;
474
  stats.delete_length=        hp_info.deleted * hp_info.reclength;
475
  if (flag & HA_STATUS_AUTO)
476
    stats.auto_increment_value= hp_info.auto_increment;
477
  /*
478
    If info() is called for the first time after open(), we will still
479
    have to update the key statistics. Hoping that a table lock is now
480
    in place.
481
  */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
482
  if (key_stat_version != file->getShare()->key_stat_version)
1 by brian
clean slate
483
    update_key_stats();
484
  return 0;
485
}
486
487
int ha_heap::extra(enum ha_extra_function operation)
488
{
489
  return heap_extra(file,operation);
490
}
491
492
493
int ha_heap::reset()
494
{
495
  return heap_reset(file);
496
}
497
498
499
int ha_heap::delete_all_rows()
500
{
501
  heap_clear(file);
1869.1.5 by Brian Aker
getTable()
502
  if (getTable()->getShare()->getType() == message::Table::STANDARD)
1 by brian
clean slate
503
  {
504
    /*
505
       We can perform this safely since only one writer at the time is
506
       allowed on the table.
507
    */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
508
    file->getShare()->key_stat_version++;
1 by brian
clean slate
509
  }
510
  return 0;
511
}
512
513
/*
514
  Disable indexes.
515
516
  SYNOPSIS
517
    disable_indexes()
518
    mode        mode of operation:
519
                HA_KEY_SWITCH_NONUNIQ      disable all non-unique keys
520
                HA_KEY_SWITCH_ALL          disable all keys
521
                HA_KEY_SWITCH_NONUNIQ_SAVE dis. non-uni. and make persistent
522
                HA_KEY_SWITCH_ALL_SAVE     dis. all keys and make persistent
523
524
  DESCRIPTION
525
    Disable indexes and clear keys to use for scanning.
526
527
  IMPLEMENTATION
528
    HA_KEY_SWITCH_NONUNIQ       is not implemented.
529
    HA_KEY_SWITCH_NONUNIQ_SAVE  is not implemented with HEAP.
530
    HA_KEY_SWITCH_ALL_SAVE      is not implemented with HEAP.
531
532
  RETURN
533
    0  ok
534
    HA_ERR_WRONG_COMMAND  mode not implemented.
535
*/
536
482 by Brian Aker
Remove uint.
537
int ha_heap::disable_indexes(uint32_t mode)
1 by brian
clean slate
538
{
539
  int error;
540
541
  if (mode == HA_KEY_SWITCH_ALL)
542
  {
543
    if (!(error= heap_disable_indexes(file)))
544
      set_keys_for_scanning();
545
  }
546
  else
547
  {
548
    /* mode not implemented */
549
    error= HA_ERR_WRONG_COMMAND;
550
  }
551
  return error;
552
}
553
554
555
/*
556
  Enable indexes.
557
558
  SYNOPSIS
559
    enable_indexes()
560
    mode        mode of operation:
561
                HA_KEY_SWITCH_NONUNIQ      enable all non-unique keys
562
                HA_KEY_SWITCH_ALL          enable all keys
563
                HA_KEY_SWITCH_NONUNIQ_SAVE en. non-uni. and make persistent
564
                HA_KEY_SWITCH_ALL_SAVE     en. all keys and make persistent
565
566
  DESCRIPTION
567
    Enable indexes and set keys to use for scanning.
568
    The indexes might have been disabled by disable_index() before.
569
    The function works only if both data and indexes are empty,
570
    since the heap storage engine cannot repair the indexes.
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
571
    To be sure, call Cursor::delete_all_rows() before.
1 by brian
clean slate
572
573
  IMPLEMENTATION
574
    HA_KEY_SWITCH_NONUNIQ       is not implemented.
575
    HA_KEY_SWITCH_NONUNIQ_SAVE  is not implemented with HEAP.
576
    HA_KEY_SWITCH_ALL_SAVE      is not implemented with HEAP.
577
578
  RETURN
579
    0  ok
580
    HA_ERR_CRASHED  data or index is non-empty. Delete all rows and retry.
581
    HA_ERR_WRONG_COMMAND  mode not implemented.
582
*/
583
482 by Brian Aker
Remove uint.
584
int ha_heap::enable_indexes(uint32_t mode)
1 by brian
clean slate
585
{
586
  int error;
587
588
  if (mode == HA_KEY_SWITCH_ALL)
589
  {
590
    if (!(error= heap_enable_indexes(file)))
591
      set_keys_for_scanning();
592
  }
593
  else
594
  {
595
    /* mode not implemented */
596
    error= HA_ERR_WRONG_COMMAND;
597
  }
598
  return error;
599
}
600
601
602
/*
603
  Test if indexes are disabled.
604
605
  SYNOPSIS
606
    indexes_are_disabled()
607
    no parameters
608
609
  RETURN
610
    0  indexes are not disabled
611
    1  all indexes are disabled
612
   [2  non-unique indexes are disabled - NOT YET IMPLEMENTED]
613
*/
614
615
int ha_heap::indexes_are_disabled(void)
616
{
617
  return heap_indexes_are_disabled(file);
618
}
619
653 by Brian Aker
More solaris bits
620
void ha_heap::drop_table(const char *)
1 by brian
clean slate
621
{
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
622
  file->getShare()->delete_on_close= 1;
1 by brian
clean slate
623
  close();
624
}
625
626
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
627
int HeapEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
1 by brian
clean slate
628
{
1923.1.4 by Brian Aker
Encapsulate up the cache we use in Session for tracking table proto for temp
629
  session.getMessageCache().renameTableMessage(from, to);
1390 by Brian Aker
Update interface to use Identifiers directly.
630
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
1 by brian
clean slate
631
}
632
633
482 by Brian Aker
Remove uint.
634
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
1 by brian
clean slate
635
                                  key_range *max_key)
636
{
1869.1.5 by Brian Aker
getTable()
637
  KeyInfo *key= &getTable()->key_info[inx];
1 by brian
clean slate
638
639
  if (!min_key || !max_key ||
640
      min_key->length != max_key->length ||
641
      min_key->length != key->key_length ||
642
      min_key->flag != HA_READ_KEY_EXACT ||
643
      max_key->flag != HA_READ_AFTER_KEY)
644
    return HA_POS_ERROR;			// Can only use exact keys
645
646
  if (stats.records <= 1)
647
    return stats.records;
648
649
  /* Assert that info() did run. We need current statistics here. */
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
650
  assert(key_stat_version == file->getShare()->key_stat_version);
1 by brian
clean slate
651
  return key->rec_per_key[key->key_parts-1];
652
}
653
1413 by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference.
654
int HeapEngine::doCreateTable(Session &session,
1208.3.2 by brian
Update for Cursor renaming.
655
                              Table &table_arg,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
656
                              const TableIdentifier &identifier,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
657
                              message::Table& create_proto)
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
658
{
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
659
  int error;
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
660
  HP_SHARE *internal_share;
1358.1.9 by Brian Aker
Update for std::string
661
  const char *table_name= identifier.getPath().c_str();
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
662
1413 by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference.
663
  error= heap_create_table(&session, table_name, &table_arg,
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
664
                           false, 
665
                           create_proto,
666
                           &internal_share);
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
667
668
  if (error == 0)
669
  {
1923.1.4 by Brian Aker
Encapsulate up the cache we use in Session for tracking table proto for temp
670
    session.getMessageCache().storeTableMessage(identifier, create_proto);
1183.1.21 by Brian Aker
Fixed temp engines to no longer write out DFE. I have two designs right now
671
  }
672
673
  return error;
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
674
}
675
676
677
int HeapEngine::heap_create_table(Session *session, const char *table_name,
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
678
                                  Table *table_arg,
679
                                  bool internal_table, 
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
680
                                  message::Table &create_proto,
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
681
                                  HP_SHARE **internal_share)
1 by brian
clean slate
682
{
1697.2.4 by Brian Aker
REmove malloc for vectors.
683
  uint32_t key, parts, mem_per_row_keys= 0;
684
  uint32_t keys= table_arg->getShare()->sizeKeys();
482 by Brian Aker
Remove uint.
685
  uint32_t auto_key= 0, auto_key_type= 0;
686
  uint32_t max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
1697.2.4 by Brian Aker
REmove malloc for vectors.
687
  uint32_t column_count= table_arg->getShare()->sizeFields();
688
  std::vector<HP_KEYDEF> keydef;
1 by brian
clean slate
689
  int error;
690
  bool found_real_auto_increment= 0;
691
1126.5.3 by Jay Pipes
Adds an error catch in heap_create_table which traps when a call to create a HEAP table with more than UINT32_MAX occurs. This allows us to safely use a cast without worrying about truncation.
692
  /* 
693
   * We cannot create tables with more rows than UINT32_MAX.  This is a
694
   * limitation of the HEAP engine.  Here, since TableShare::getMaxRows()
695
   * can return a number more than that, we trap it here instead of casting
696
   * to a truncated integer.
697
   */
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
698
  uint64_t num_rows= table_arg->getShare()->getMaxRows();
1126.5.3 by Jay Pipes
Adds an error catch in heap_create_table which traps when a call to create a HEAP table with more than UINT32_MAX occurs. This allows us to safely use a cast without worrying about truncation.
699
  if (num_rows > UINT32_MAX)
700
    return -1;
701
1 by brian
clean slate
702
  for (key= parts= 0; key < keys; key++)
703
    parts+= table_arg->key_info[key].key_parts;
704
1697.2.4 by Brian Aker
REmove malloc for vectors.
705
  keydef.resize(keys);
706
  std::vector<HA_KEYSEG> seg_buffer;
707
  seg_buffer.resize(parts);
708
  HA_KEYSEG *seg= &seg_buffer[0];
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
709
1 by brian
clean slate
710
  for (key= 0; key < keys; key++)
711
  {
1574.1.1 by Brian Aker
Small touchup for using array, not increment.
712
    KeyInfo *pos= &table_arg->key_info[key];
1534 by Brian Aker
Remove of KeyPartInfo
713
    KeyPartInfo *key_part=     pos->key_part;
714
    KeyPartInfo *key_part_end= key_part + pos->key_parts;
1 by brian
clean slate
715
716
    keydef[key].keysegs=   (uint) pos->key_parts;
717
    keydef[key].flag=      (pos->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL));
718
    keydef[key].seg=       seg;
719
1711.6.12 by Brian Aker
This removes the b-tree from heap (it currently crashes the server (both
720
    mem_per_row_keys+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
1 by brian
clean slate
721
722
    for (; key_part != key_part_end; key_part++, seg++)
723
    {
724
      Field *field= key_part->field;
725
726
      {
727
        if ((seg->type = field->key_type()) != (int) HA_KEYTYPE_TEXT &&
728
            seg->type != HA_KEYTYPE_VARTEXT1 &&
729
            seg->type != HA_KEYTYPE_VARTEXT2 &&
730
            seg->type != HA_KEYTYPE_VARBINARY1 &&
731
            seg->type != HA_KEYTYPE_VARBINARY2)
732
          seg->type= HA_KEYTYPE_BINARY;
733
      }
734
      seg->start=   (uint) key_part->offset;
735
      seg->length=  (uint) key_part->length;
736
      seg->flag=    key_part->key_part_flag;
737
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
738
      next_field_pos= seg->start + seg->length;
739
      if (field->type() == DRIZZLE_TYPE_VARCHAR)
740
      {
1782.4.5 by Brian Aker
Encapsulate the length of the bytes in the varchar header.
741
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->pack_length_no_ptr());
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
742
      }
743
744
      if (next_field_pos > key_part_size) {
745
        key_part_size= next_field_pos;
746
      }
747
1315.2.15 by Stewart Smith
remove the now unused SET_FLAG define. We don't have the SET field type, and this flag was never set.
748
      if (field->flags & ENUM_FLAG)
1 by brian
clean slate
749
        seg->charset= &my_charset_bin;
750
      else
751
        seg->charset= field->charset();
752
      if (field->null_ptr)
753
      {
754
	seg->null_bit= field->null_bit;
1672.3.6 by Brian Aker
First pass in encapsulating row
755
	seg->null_pos= (uint) (field->null_ptr - (unsigned char*) table_arg->getInsertRecord());
1 by brian
clean slate
756
      }
757
      else
758
      {
759
	seg->null_bit= 0;
760
	seg->null_pos= 0;
761
      }
762
      if (field->flags & AUTO_INCREMENT_FLAG &&
763
          table_arg->found_next_number_field &&
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
764
          key == table_arg->getShare()->next_number_index)
1 by brian
clean slate
765
      {
766
        /*
767
          Store key number and type for found auto_increment key
768
          We have to store type as seg->type can differ from it
769
        */
770
        auto_key= key+ 1;
771
	auto_key_type= field->key_type();
772
      }
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
773
      if ((uint)field->field_index + 1 > max_key_fieldnr)
774
      {
775
        /* Do not use seg->fieldnr as it's not reliable in case of temp tables */
776
        max_key_fieldnr= field->field_index + 1;
777
      }
1 by brian
clean slate
778
    }
779
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
780
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
781
  if (key_part_size < table_arg->getShare()->null_bytes + ((table_arg->getShare()->last_null_bit_pos+7) >> 3))
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
782
  {
783
    /* Make sure to include null fields regardless of the presense of keys */
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
784
    key_part_size = table_arg->getShare()->null_bytes + ((table_arg->getShare()->last_null_bit_pos+7) >> 3);
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
785
  }
786
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
787
788
1 by brian
clean slate
789
  if (table_arg->found_next_number_field)
790
  {
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
791
    keydef[table_arg->getShare()->next_number_index].flag|= HA_AUTO_KEY;
792
    found_real_auto_increment= table_arg->getShare()->next_number_key_offset == 0;
1 by brian
clean slate
793
  }
794
  HP_CREATE_INFO hp_create_info;
795
  hp_create_info.auto_key= auto_key;
796
  hp_create_info.auto_key_type= auto_key_type;
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
797
  hp_create_info.auto_increment= (create_proto.options().has_auto_increment_value() ?
798
				  create_proto.options().auto_increment_value() - 1 : 0);
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
799
  hp_create_info.max_table_size=session->variables.max_heap_table_size;
1 by brian
clean slate
800
  hp_create_info.with_auto_increment= found_real_auto_increment;
801
  hp_create_info.internal_table= internal_table;
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
802
  hp_create_info.max_chunk_size= table_arg->getShare()->block_size;
1126.5.3 by Jay Pipes
Adds an error catch in heap_create_table which traps when a call to create a HEAP table with more than UINT32_MAX occurs. This allows us to safely use a cast without worrying about truncation.
803
1749.3.17 by Brian Aker
Remove direct use of name from heap.
804
  error= heap_create(table_name,
805
                     keys, &keydef[0],
806
                     column_count,
807
                     key_part_size,
808
                     table_arg->getShare()->getRecordLength(), mem_per_row_keys,
809
                     static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
810
                     0, // Factor out MIN
811
                     &hp_create_info, internal_share);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
812
1 by brian
clean slate
813
  return (error);
814
}
815
816
653 by Brian Aker
More solaris bits
817
void ha_heap::get_auto_increment(uint64_t, uint64_t, uint64_t,
1 by brian
clean slate
818
                                 uint64_t *first_value,
819
                                 uint64_t *nb_reserved_values)
820
{
821
  ha_heap::info(HA_STATUS_AUTO);
822
  *first_value= stats.auto_increment_value;
823
  /* such table has only table-level locking so reserves up to +inf */
163 by Brian Aker
Merge Monty's code.
824
  *nb_reserved_values= UINT64_MAX;
1 by brian
clean slate
825
}
826
827
685.1.3 by Monty Taylor
Turned off stdinc - and then fixed the carnage.
828
int ha_heap::cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
829
{
830
  return memcmp(ref1, ref2, sizeof(HEAP_PTR));
831
}
832
833
1228.1.5 by Monty Taylor
Merged in some naming things.
834
DRIZZLE_DECLARE_PLUGIN
1 by brian
clean slate
835
{
1241.10.2 by Monty Taylor
Added support for embedding the drizzle version number in the plugin file.
836
  DRIZZLE_VERSION_ID,
1 by brian
clean slate
837
  "MEMORY",
177.4.3 by mark
ripped out more plugin ABI and API version checking, and plugin versions are now strings
838
  "1.0",
1 by brian
clean slate
839
  "MySQL AB",
840
  "Hash based, stored in memory, useful for temporary tables",
841
  PLUGIN_LICENSE_GPL,
842
  heap_init,
843
  NULL,                       /* system variables                */
844
  NULL                        /* config options                  */
845
}
1228.1.5 by Monty Taylor
Merged in some naming things.
846
DRIZZLE_DECLARE_PLUGIN_END;