~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.h

  • Committer: Mark Atwood
  • Date: 2011-10-27 05:08:12 UTC
  • mfrom: (2445.1.11 rf)
  • Revision ID: me@mark.atwood.name-20111027050812-1icvs72lb0u4xdc4
mergeĀ lp:~olafvdspek/drizzle/refactor8

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * Defines the Join class
25
25
 */
26
26
 
27
 
#ifndef DRIZZLED_JOIN_H
28
 
#define DRIZZLED_JOIN_H
 
27
#pragma once
29
28
 
 
29
#include <drizzled/dynamic_array.h>
30
30
#include <drizzled/optimizer/position.h>
31
 
#include "drizzled/sql_select.h"
 
31
#include <drizzled/sql_select.h>
 
32
#include <drizzled/tmp_table_param.h>
32
33
#include <bitset>
33
34
 
34
 
namespace drizzled
35
 
{
36
 
 
37
 
class Join :public memory::SqlAlloc
38
 
{
39
 
  Join(const Join &rhs);                        /**< not implemented */
40
 
  Join& operator=(const Join &rhs);             /**< not implemented */
41
 
 
 
35
namespace drizzled {
 
36
 
 
37
class Join : public memory::SqlAlloc, boost::noncopyable
 
38
{
42
39
  /**
43
40
   * Contains a partial query execution plan which is extended during
44
41
   * cost-based optimization.
141
138
 
142
139
  Session       *session;
143
140
  List<Item> *fields;
144
 
  List<Item> &fields_list; /**< hold field list passed to mysql_select */
 
141
  List<Item> &fields_list; /**< hold field list passed to select_query */
145
142
  List<TableList> *join_list; /**< list of joined tables in reverse order */
146
143
  /** unit structure (with global parameters) for this select */
147
144
  Select_Lex_Unit *unit;
180
177
  DrizzleLock *lock;
181
178
 
182
179
  Join *tmp_join; /**< copy of this Join to be used with temporary tables */
183
 
  ROLLUP rollup;                                /**< Used with rollup */
 
180
  Rollup rollup;                                /**< Used with rollup */
184
181
  DYNAMIC_ARRAY keyuse;
185
182
  Item::cond_result cond_value;
186
183
  Item::cond_result having_value;
196
193
  int error;
197
194
 
198
195
  Order *order;
199
 
  Order *group_list; /**< hold parameters of mysql_select */
 
196
  Order *group_list; /**< hold parameters of select_query */
200
197
  COND *conds;                            // ---"---
201
198
  Item *conds_history; /**< store WHERE for explain */
202
 
  TableList *tables_list; /**< hold 'tables' parameter of mysql_select */
 
199
  TableList *tables_list; /**< hold 'tables' parameter of select_query */
203
200
  COND_EQUAL *cond_equal;
204
201
  JoinTable *return_tab; /**< used only for outer joins */
205
202
  Item **ref_pointer_array; /**< used pointer reference for this select */
228
225
  Join(Session *session_arg, 
229
226
       List<Item> &fields_arg, 
230
227
       uint64_t select_options_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.state= ROLLUP::STATE_NONE;
310
 
  }
 
228
       select_result *result_arg);
311
229
 
312
230
  /** 
313
231
   * This method is currently only used when a subselect EXPLAIN is performed.
315
233
   * was previously in the init() method.  See the note about the hack in 
316
234
   * sql_union.cc...
317
235
   */
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.state= ROLLUP::STATE_NONE;
399
 
  }
 
236
  void reset(Session *session_arg, 
 
237
             List<Item> &fields_arg, 
 
238
             uint64_t select_options_arg,
 
239
             select_result *result_arg);
400
240
 
401
241
  int prepare(Item ***rref_pointer_array, 
402
242
              TableList *tables,
408
248
              Item *having,
409
249
              Select_Lex *select,
410
250
              Select_Lex_Unit *unit);
 
251
 
411
252
  int optimize();
412
253
  int reinit();
413
254
  void exec();
427
268
  }
428
269
  inline void init_items_ref_array()
429
270
  {
430
 
    items0= ref_pointer_array + all_fields.elements;
 
271
    items0= ref_pointer_array + all_fields.size();
431
272
    memcpy(items0, ref_pointer_array, ref_pointer_array_size);
432
273
    current_ref_pointer_array= items0;
433
274
  }
449
290
  /** Cleanup this Join, possibly for reuse */
450
291
  void cleanup(bool full);
451
292
  void clear();
452
 
  bool save_join_tab();
453
 
  bool init_save_join_tab();
 
293
  void save_join_tab();
 
294
  void init_save_join_tab();
454
295
  bool send_row_on_empty_set()
455
296
  {
456
297
    return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
457
298
            !group_list);
458
299
  }
459
300
  bool change_result(select_result *result);
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
 
  }
 
301
  bool is_top_level_join() const;
465
302
 
466
303
  /**
467
304
   * Copy the partial query plan into the optimal query plan.
535
372
 
536
373
} /* namespace drizzled */
537
374
 
538
 
#endif /* DRIZZLED_JOIN_H */