~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Brian Aker
  • Date: 2010-05-20 17:33:40 UTC
  • mto: This revision was merged to the branch mainline in revision 1553.
  • Revision ID: brian@gaz-20100520173340-4giiuc3xosq2fx1m
This 1) fixes issue of reset()   2) uses a better cache design to decrease
alloc calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <drizzled/session.h>
25
25
#include "drizzled/internal/my_sys.h"
26
26
 
 
27
#include <unistd.h>
 
28
#include <fcntl.h>
 
29
 
27
30
#include <string>
28
31
 
29
32
using namespace std;
48
51
  tool= static_cast<Function *>(engine)->getFunction(tab_name); 
49
52
//  assert(tool);
50
53
 
 
54
  record_id= 0;
 
55
 
51
56
  if (not tool)
52
57
    return HA_ERR_NO_SUCH_TABLE;
53
58
 
57
62
int FunctionCursor::close(void)
58
63
{
59
64
  tool= NULL;
 
65
  wipeCache();
 
66
 
60
67
  return 0;
61
68
}
62
69
 
63
70
int FunctionCursor::doStartTableScan(bool)
64
71
{
65
 
  record_id= 0;
66
72
  rows_returned= 0;
67
73
  generator= tool->generator(table->field);
68
74
 
99
105
 
100
106
void FunctionCursor::position(const unsigned char *record)
101
107
{
102
 
  unsigned char *copy;
103
 
 
104
 
  copy= (unsigned char *)calloc(table->getShare()->reclength, sizeof(unsigned char));
105
 
  assert(copy);
106
 
  memcpy(copy, record, table->getShare()->reclength);
107
 
  row_cache.push_back(copy);
 
108
  if (row_cache.size() <= record_id * table->getShare()->reclength)
 
109
  {
 
110
    row_cache.resize(row_cache.size() + table->getShare()->reclength * 100); // Hardwired at adding an additional 100 rows of storage
 
111
  }
 
112
#if 0
 
113
  std::cerr << " position() " << table->getShare()->reclength << " " << row_cache.size() << " " << record_id << " total " << record_id * table->getShare()->reclength << "\n";
 
114
#endif
 
115
  memcpy(&row_cache[record_id * table->getShare()->reclength], record, table->getShare()->reclength);
108
116
  internal::my_store_ptr(ref, ref_length, record_id);
109
117
  record_id++;
110
118
}
111
119
 
 
120
 
 
121
void FunctionCursor::wipeCache()
 
122
{
 
123
  if (rows_returned > estimate_of_rows)
 
124
    estimate_of_rows= rows_returned;
 
125
 
 
126
  row_cache.clear();
 
127
  record_id= 0;
 
128
}
 
129
 
112
130
int FunctionCursor::extra(enum ha_extra_function operation)
113
131
{
114
132
  switch (operation)
115
133
  {
116
134
  case drizzled::HA_EXTRA_CACHE:
 
135
    break;
117
136
  case drizzled::HA_EXTRA_NO_CACHE:
118
137
    break;
119
138
  case drizzled::HA_EXTRA_RESET_STATE:
120
 
    { 
121
 
      size_t length_of_vector= row_cache.size();
122
 
 
123
 
      for (size_t x= 0; x < length_of_vector; x++)
124
 
      {
125
 
        free(row_cache[x]);
126
 
      }
127
 
 
128
 
      if (rows_returned > estimate_of_rows)
129
 
        estimate_of_rows= rows_returned;
130
 
 
131
 
      row_cache.clear();
132
 
      record_id= 0;
133
 
      delete generator; // Do this in case of an early exit from rnd_next()
134
 
 
135
 
      break;
136
 
    }
 
139
    wipeCache();
 
140
    break;
137
141
  default:
138
142
    break;
139
143
  }
153
157
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
154
158
  size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
155
159
 
156
 
  assert(position_id < row_cache.size());
157
 
  memcpy(buf, row_cache[position_id], table->getShare()->reclength);
 
160
#if 0
 
161
  std::cerr << " rnd_pos() " << table->getShare()->reclength << " " << row_cache.size() << " " << position_id << " total " << position_id * table->getShare()->reclength << "\n";
 
162
#endif
 
163
  assert(position_id * table->getShare()->reclength < row_cache.size());
 
164
  memcpy(buf, &row_cache[position_id * table->getShare()->reclength], table->getShare()->reclength);
158
165
 
159
166
  return 0;
160
167
}