~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.h

edit

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#define DRIZZLED_JOIN_H
29
29
 
30
30
#include <drizzled/optimizer/position.h>
31
 
#include <drizzled/sql_select.h>
32
 
#include <drizzled/tmp_table_param.h>
 
31
#include "drizzled/sql_select.h"
33
32
#include <bitset>
34
33
 
35
34
namespace drizzled
36
35
{
37
36
 
38
 
class DrizzleLock;
39
 
class Session;
40
 
class SortField;
41
 
 
42
37
class Join :public memory::SqlAlloc
43
38
{
44
39
  Join(const Join &rhs);                        /**< not implemented */
233
228
  Join(Session *session_arg, 
234
229
       List<Item> &fields_arg, 
235
230
       uint64_t select_options_arg,
236
 
       select_result *result_arg);
 
231
       select_result *result_arg)
 
232
    :
 
233
      join_tab(NULL),
 
234
      best_ref(NULL),
 
235
      map2table(NULL),
 
236
      join_tab_save(NULL),
 
237
      table(NULL),
 
238
      all_tables(NULL),
 
239
      sort_by_table(NULL),
 
240
      tables(0),
 
241
      outer_tables(0),
 
242
      const_tables(0),
 
243
      send_group_parts(0),
 
244
      sort_and_group(false),
 
245
      first_record(false),
 
246
      full_join(false),
 
247
      group(false),
 
248
      no_field_update(false),
 
249
      do_send_rows(true),
 
250
      resume_nested_loop(false),
 
251
      no_const_tables(false),
 
252
      select_distinct(false),
 
253
      group_optimized_away(false),
 
254
      simple_order(false),
 
255
      simple_group(false),
 
256
      no_order(false),
 
257
      skip_sort_order(false),
 
258
      union_part(false),
 
259
      optimized(false),
 
260
      need_tmp(false),
 
261
      hidden_group_fields(false),
 
262
      const_table_map(0),
 
263
      found_const_table_map(0),
 
264
      outer_join(0),
 
265
      send_records(0),
 
266
      found_records(0),
 
267
      examined_rows(0),
 
268
      row_limit(0),
 
269
      select_limit(0),
 
270
      fetch_limit(HA_POS_ERROR),
 
271
      session(session_arg),
 
272
      fields_list(fields_arg), 
 
273
      join_list(NULL),
 
274
      unit(NULL),
 
275
      select_lex(NULL),
 
276
      select(NULL),
 
277
      exec_tmp_table1(NULL),
 
278
      exec_tmp_table2(NULL),
 
279
      sum_funcs(NULL),
 
280
      sum_funcs2(NULL),
 
281
      having(NULL),
 
282
      tmp_having(NULL),
 
283
      having_history(NULL),
 
284
      select_options(select_options_arg),
 
285
      result(result_arg),
 
286
      lock(session_arg->lock),
 
287
      tmp_join(NULL),
 
288
      all_fields(fields_arg),
 
289
      error(0),
 
290
      cond_equal(NULL),
 
291
      return_tab(NULL),
 
292
      ref_pointer_array(NULL),
 
293
      items0(NULL),
 
294
      items1(NULL),
 
295
      items2(NULL),
 
296
      items3(NULL),
 
297
      ref_pointer_array_size(0),
 
298
      zero_result_cause(NULL),
 
299
      sortorder(NULL),
 
300
      table_reexec(NULL),
 
301
      join_tab_reexec(NULL)
 
302
  {
 
303
    select_distinct= test(select_options & SELECT_DISTINCT);
 
304
    if (&fields_list != &fields_arg) /* only copy if not same*/
 
305
      fields_list= fields_arg;
 
306
    memset(&keyuse, 0, sizeof(keyuse));
 
307
    tmp_table_param.init();
 
308
    tmp_table_param.end_write_records= HA_POS_ERROR;
 
309
    rollup.setState(Rollup::STATE_NONE);
 
310
  }
237
311
 
238
312
  /** 
239
313
   * This method is currently only used when a subselect EXPLAIN is performed.
241
315
   * was previously in the init() method.  See the note about the hack in 
242
316
   * sql_union.cc...
243
317
   */
244
 
  void reset(Session *session_arg, 
245
 
             List<Item> &fields_arg, 
246
 
             uint64_t select_options_arg,
247
 
             select_result *result_arg);
 
318
  inline void reset(Session *session_arg, 
 
319
       List<Item> &fields_arg, 
 
320
       uint64_t select_options_arg,
 
321
       select_result *result_arg)
 
322
  {
 
323
    join_tab= NULL;
 
324
    best_ref= NULL;
 
325
    map2table= NULL;
 
326
    join_tab_save= NULL;
 
327
    table= NULL;
 
328
    all_tables= NULL;
 
329
    sort_by_table= NULL;
 
330
    tables= 0;
 
331
    outer_tables= 0;
 
332
    const_tables= 0;
 
333
    send_group_parts= 0;
 
334
    sort_and_group= false;
 
335
    first_record= false;
 
336
    full_join= false;
 
337
    group= false;
 
338
    no_field_update= false;
 
339
    do_send_rows= true;
 
340
    resume_nested_loop= false;
 
341
    no_const_tables= false;
 
342
    select_distinct= false;
 
343
    group_optimized_away= false;
 
344
    simple_order= false;
 
345
    simple_group= false;
 
346
    no_order= false;
 
347
    skip_sort_order= false;
 
348
    union_part= false;
 
349
    optimized= false;
 
350
    need_tmp= false;
 
351
    hidden_group_fields= false;
 
352
    const_table_map= 0;
 
353
    found_const_table_map= 0;
 
354
    outer_join= 0;
 
355
    send_records= 0;
 
356
    found_records= 0;
 
357
    examined_rows= 0;
 
358
    row_limit= 0;
 
359
    select_limit= 0;
 
360
    fetch_limit= HA_POS_ERROR;
 
361
    session= session_arg;
 
362
    fields_list= fields_arg; 
 
363
    join_list= NULL;
 
364
    unit= NULL;
 
365
    select_lex= NULL;
 
366
    select= NULL;
 
367
    exec_tmp_table1= NULL;
 
368
    exec_tmp_table2= NULL;
 
369
    sum_funcs= NULL;
 
370
    sum_funcs2= NULL;
 
371
    having= NULL;
 
372
    tmp_having= NULL;
 
373
    having_history= NULL;
 
374
    select_options= select_options_arg;
 
375
    result= result_arg;
 
376
    lock= session_arg->lock;
 
377
    tmp_join= NULL;
 
378
    all_fields= fields_arg;
 
379
    error= 0;
 
380
    cond_equal= NULL;
 
381
    return_tab= NULL;
 
382
    ref_pointer_array= NULL;
 
383
    items0= NULL;
 
384
    items1= NULL;
 
385
    items2= NULL;
 
386
    items3= NULL;
 
387
    ref_pointer_array_size= 0;
 
388
    zero_result_cause= NULL;
 
389
    sortorder= NULL;
 
390
    table_reexec= NULL;
 
391
    join_tab_reexec= NULL;
 
392
    select_distinct= test(select_options & SELECT_DISTINCT);
 
393
    if (&fields_list != &fields_arg) /* only copy if not same*/
 
394
      fields_list= fields_arg;
 
395
    memset(&keyuse, 0, sizeof(keyuse));
 
396
    tmp_table_param.init();
 
397
    tmp_table_param.end_write_records= HA_POS_ERROR;
 
398
    rollup.setState(Rollup::STATE_NONE);
 
399
  }
248
400
 
249
401
  int prepare(Item ***rref_pointer_array, 
250
402
              TableList *tables,
256
408
              Item *having,
257
409
              Select_Lex *select,
258
410
              Select_Lex_Unit *unit);
259
 
 
260
411
  int optimize();
261
412
  int reinit();
262
413
  void exec();
306
457
            !group_list);
307
458
  }
308
459
  bool change_result(select_result *result);
309
 
  bool is_top_level_join() const;
 
460
  bool is_top_level_join() const
 
461
  {
 
462
    return (unit == &session->lex->unit && (unit->fake_select_lex == 0 ||
 
463
                                        select_lex == unit->fake_select_lex));
 
464
  }
310
465
 
311
466
  /**
312
467
   * Copy the partial query plan into the optimal query plan.