~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: Brian Aker
  • Date: 2011-02-12 10:06:03 UTC
  • mfrom: (2154.2.16 drizzle-build)
  • Revision ID: brian@tangent.org-20110212100603-i5ww0s02p8l4a8q7
Merge in solaris tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
#include "drizzled/internal/my_bit.h"
59
59
#include "drizzled/internal/my_sys.h"
60
60
#include "drizzled/internal/iocache.h"
 
61
#include "drizzled/plugin/storage_engine.h"
61
62
 
62
63
#include <drizzled/debug.h>
63
64
 
133
134
static bool add_ref_to_table_cond(Session *session, JoinTable *join_tab);
134
135
static void free_blobs(Field **ptr); /* Rename this method...conflicts with another in global namespace... */
135
136
 
 
137
Join::Join(Session *session_arg, 
 
138
           List<Item> &fields_arg, 
 
139
           uint64_t select_options_arg,
 
140
           select_result *result_arg) :
 
141
  join_tab(NULL),
 
142
  best_ref(NULL),
 
143
  map2table(NULL),
 
144
  join_tab_save(NULL),
 
145
  table(NULL),
 
146
  all_tables(NULL),
 
147
  sort_by_table(NULL),
 
148
  tables(0),
 
149
  outer_tables(0),
 
150
  const_tables(0),
 
151
  send_group_parts(0),
 
152
  sort_and_group(false),
 
153
  first_record(false),
 
154
  full_join(false),
 
155
  group(false),
 
156
  no_field_update(false),
 
157
  do_send_rows(true),
 
158
  resume_nested_loop(false),
 
159
  no_const_tables(false),
 
160
  select_distinct(false),
 
161
  group_optimized_away(false),
 
162
  simple_order(false),
 
163
  simple_group(false),
 
164
  no_order(false),
 
165
  skip_sort_order(false),
 
166
  union_part(false),
 
167
  optimized(false),
 
168
  need_tmp(false),
 
169
  hidden_group_fields(false),
 
170
  const_table_map(0),
 
171
  found_const_table_map(0),
 
172
  outer_join(0),
 
173
  send_records(0),
 
174
  found_records(0),
 
175
  examined_rows(0),
 
176
  row_limit(0),
 
177
  select_limit(0),
 
178
  fetch_limit(HA_POS_ERROR),
 
179
  session(session_arg),
 
180
  fields_list(fields_arg), 
 
181
  join_list(NULL),
 
182
  unit(NULL),
 
183
  select_lex(NULL),
 
184
  select(NULL),
 
185
  exec_tmp_table1(NULL),
 
186
  exec_tmp_table2(NULL),
 
187
  sum_funcs(NULL),
 
188
  sum_funcs2(NULL),
 
189
  having(NULL),
 
190
  tmp_having(NULL),
 
191
  having_history(NULL),
 
192
  select_options(select_options_arg),
 
193
  result(result_arg),
 
194
  lock(session_arg->lock),
 
195
  tmp_join(NULL),
 
196
  all_fields(fields_arg),
 
197
  error(0),
 
198
  cond_equal(NULL),
 
199
  return_tab(NULL),
 
200
  ref_pointer_array(NULL),
 
201
  items0(NULL),
 
202
  items1(NULL),
 
203
  items2(NULL),
 
204
  items3(NULL),
 
205
  ref_pointer_array_size(0),
 
206
  zero_result_cause(NULL),
 
207
  sortorder(NULL),
 
208
  table_reexec(NULL),
 
209
  join_tab_reexec(NULL)
 
210
{
 
211
  select_distinct= test(select_options & SELECT_DISTINCT);
 
212
  if (&fields_list != &fields_arg) /* only copy if not same*/
 
213
    fields_list= fields_arg;
 
214
  memset(&keyuse, 0, sizeof(keyuse));
 
215
  tmp_table_param.init();
 
216
  tmp_table_param.end_write_records= HA_POS_ERROR;
 
217
  rollup.setState(Rollup::STATE_NONE);
 
218
}
 
219
 
 
220
  /** 
 
221
   * This method is currently only used when a subselect EXPLAIN is performed.
 
222
   * I pulled out the init() method and have simply reset the values to what
 
223
   * was previously in the init() method.  See the note about the hack in 
 
224
   * sql_union.cc...
 
225
   */
 
226
void Join::reset(Session *session_arg, 
 
227
                 List<Item> &fields_arg, 
 
228
                 uint64_t select_options_arg,
 
229
                 select_result *result_arg)
 
230
{
 
231
  join_tab= NULL;
 
232
  best_ref= NULL;
 
233
  map2table= NULL;
 
234
  join_tab_save= NULL;
 
235
  table= NULL;
 
236
  all_tables= NULL;
 
237
  sort_by_table= NULL;
 
238
  tables= 0;
 
239
  outer_tables= 0;
 
240
  const_tables= 0;
 
241
  send_group_parts= 0;
 
242
  sort_and_group= false;
 
243
  first_record= false;
 
244
  full_join= false;
 
245
  group= false;
 
246
  no_field_update= false;
 
247
  do_send_rows= true;
 
248
  resume_nested_loop= false;
 
249
  no_const_tables= false;
 
250
  select_distinct= false;
 
251
  group_optimized_away= false;
 
252
  simple_order= false;
 
253
  simple_group= false;
 
254
  no_order= false;
 
255
  skip_sort_order= false;
 
256
  union_part= false;
 
257
  optimized= false;
 
258
  need_tmp= false;
 
259
  hidden_group_fields= false;
 
260
  const_table_map= 0;
 
261
  found_const_table_map= 0;
 
262
  outer_join= 0;
 
263
  send_records= 0;
 
264
  found_records= 0;
 
265
  examined_rows= 0;
 
266
  row_limit= 0;
 
267
  select_limit= 0;
 
268
  fetch_limit= HA_POS_ERROR;
 
269
  session= session_arg;
 
270
  fields_list= fields_arg; 
 
271
  join_list= NULL;
 
272
  unit= NULL;
 
273
  select_lex= NULL;
 
274
  select= NULL;
 
275
  exec_tmp_table1= NULL;
 
276
  exec_tmp_table2= NULL;
 
277
  sum_funcs= NULL;
 
278
  sum_funcs2= NULL;
 
279
  having= NULL;
 
280
  tmp_having= NULL;
 
281
  having_history= NULL;
 
282
  select_options= select_options_arg;
 
283
  result= result_arg;
 
284
  lock= session_arg->lock;
 
285
  tmp_join= NULL;
 
286
  all_fields= fields_arg;
 
287
  error= 0;
 
288
  cond_equal= NULL;
 
289
  return_tab= NULL;
 
290
  ref_pointer_array= NULL;
 
291
  items0= NULL;
 
292
  items1= NULL;
 
293
  items2= NULL;
 
294
  items3= NULL;
 
295
  ref_pointer_array_size= 0;
 
296
  zero_result_cause= NULL;
 
297
  sortorder= NULL;
 
298
  table_reexec= NULL;
 
299
  join_tab_reexec= NULL;
 
300
  select_distinct= test(select_options & SELECT_DISTINCT);
 
301
  if (&fields_list != &fields_arg) /* only copy if not same*/
 
302
    fields_list= fields_arg;
 
303
  memset(&keyuse, 0, sizeof(keyuse));
 
304
  tmp_table_param.init();
 
305
  tmp_table_param.end_write_records= HA_POS_ERROR;
 
306
  rollup.setState(Rollup::STATE_NONE);
 
307
}
 
308
 
 
309
bool Join::is_top_level_join() const
 
310
{
 
311
  return (unit == &session->lex->unit && (unit->fake_select_lex == 0 ||
 
312
                                          select_lex == unit->fake_select_lex));
 
313
}
 
314
 
136
315
/**
137
316
  Prepare of whole select (including sub queries in future).
138
317
 
1171
1350
*/
1172
1351
bool Join::init_save_join_tab()
1173
1352
{
1174
 
  if (!(tmp_join= (Join*)session->alloc(sizeof(Join))))
 
1353
  if (!(tmp_join= (Join*)session->getMemRoot()->allocate(sizeof(Join))))
1175
1354
    return 1;
1176
1355
 
1177
1356
  error= 0;              // Ensure that tmp_join.error= 0
1184
1363
{
1185
1364
  if (! join_tab_save && select_lex->master_unit()->uncacheable.any())
1186
1365
  {
1187
 
    if (!(join_tab_save= (JoinTable*)session->memdup((unsigned char*) join_tab,
 
1366
    if (!(join_tab_save= (JoinTable*)session->getMemRoot()->duplicate((unsigned char*) join_tab,
1188
1367
            sizeof(JoinTable) * tables)))
1189
1368
      return 1;
1190
1369
  }
2078
2257
  */
2079
2258
  tmp_table_param.group_parts= send_group_parts;
2080
2259
 
2081
 
  rollup.setNullItems((Item_null_result**) session->alloc((sizeof(Item*) +
 
2260
  rollup.setNullItems((Item_null_result**) session->getMemRoot()->allocate((sizeof(Item*) +
2082
2261
                                                                sizeof(Item**) +
2083
2262
                                                                sizeof(List<Item>) +
2084
2263
                                                                ref_pointer_array_size)
3226
3405
 
3227
3406
  table_count=join->tables;
3228
3407
  if (!(join->join_tab=join_tab=
3229
 
  (JoinTable*) session->alloc(sizeof(JoinTable)*table_count)))
 
3408
  (JoinTable*) session->getMemRoot()->allocate(sizeof(JoinTable)*table_count)))
3230
3409
    return(true);
3231
3410
 
3232
3411
  for (i= 0; i < table_count; i++)
4384
4563
  */
4385
4564
  if (!join->table_reexec)
4386
4565
  {
4387
 
    if (!(join->table_reexec= (Table**) join->session->alloc(sizeof(Table*))))
 
4566
    if (!(join->table_reexec= (Table**) join->session->getMemRoot()->allocate(sizeof(Table*))))
4388
4567
      return(true);
4389
4568
    if (join->tmp_join)
4390
4569
      join->tmp_join->table_reexec= join->table_reexec;
4392
4571
  if (!join->join_tab_reexec)
4393
4572
  {
4394
4573
    if (!(join->join_tab_reexec=
4395
 
          (JoinTable*) join->session->alloc(sizeof(JoinTable))))
 
4574
          (JoinTable*) join->session->getMemRoot()->allocate(sizeof(JoinTable))))
4396
4575
      return(true);
4397
4576
    new (join->join_tab_reexec) JoinTable();
4398
4577
    if (join->tmp_join)
4659
4838
          tab->type == AM_EQ_REF)
4660
4839
      {
4661
4840
        optimizer::SqlSelect *sel= tab->select= ((optimizer::SqlSelect*)
4662
 
            session->memdup((unsigned char*) select,
 
4841
            session->getMemRoot()->duplicate((unsigned char*) select,
4663
4842
              sizeof(*select)));
4664
4843
        if (! sel)
4665
4844
          return 1;                     // End of memory
4797
4976
                                         current_map, 0)))
4798
4977
            {
4799
4978
              tab->cache.select= (optimizer::SqlSelect*)
4800
 
                session->memdup((unsigned char*) sel, sizeof(optimizer::SqlSelect));
 
4979
                session->getMemRoot()->duplicate((unsigned char*) sel, sizeof(optimizer::SqlSelect));
4801
4980
              tab->cache.select->cond= tmp;
4802
4981
              tab->cache.select->read_tables= join->const_table_map;
4803
4982
            }
4933
5112
 
4934
5113
    if (tab->insideout_match_tab)
4935
5114
    {
4936
 
      if (! (tab->insideout_buf= (unsigned char*) join->session->alloc(tab->table->key_info
 
5115
      if (! (tab->insideout_buf= (unsigned char*) join->session->getMemRoot()->allocate(tab->table->key_info
4937
5116
                                                                       [tab->index].
4938
5117
                                                                       key_length)))
4939
5118
        return true;
5524
5703
 
5525
5704
  table_count= join->tables;
5526
5705
  stat= (JoinTable*) join->session->calloc(sizeof(JoinTable)*table_count);
5527
 
  stat_ref= (JoinTable**) join->session->alloc(sizeof(JoinTable*)*MAX_TABLES);
5528
 
  table_vector= (Table**) join->session->alloc(sizeof(Table*)*(table_count*2));
 
5706
  stat_ref= (JoinTable**) join->session->getMemRoot()->allocate(sizeof(JoinTable*)*MAX_TABLES);
 
5707
  table_vector= (Table**) join->session->getMemRoot()->allocate(sizeof(Table*)*(table_count*2));
5529
5708
  if (! stat || ! stat_ref || ! table_vector)
5530
5709
    return 1;
5531
5710