~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_union.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-07-30 02:39:13 UTC
  • mto: (1115.3.11 captain)
  • mto: This revision was merged to the branch mainline in revision 1121.
  • Revision ID: osullivan.padraig@gmail.com-20090730023913-o2zuocp32l6btnc2
Removing references to MY_BITMAP throughout the code base and updating calls
to MyBitmap in various places to use the new interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
  UNION  of select's
18
18
  UNION's  were introduced by Monty and Sinisa <sinisa@mysql.com>
19
19
*/
20
 
#include "config.h"
 
20
#include <drizzled/server_includes.h>
21
21
#include <drizzled/sql_select.h>
22
22
#include <drizzled/error.h>
23
23
#include <drizzled/item/type_holder.h>
24
24
#include <drizzled/sql_base.h>
25
25
#include <drizzled/sql_union.h>
26
26
 
27
 
namespace drizzled
28
 
{
29
 
 
30
27
bool drizzle_union(Session *session, LEX *, select_result *result,
31
28
                   Select_Lex_Unit *unit, uint64_t setup_tables_done_option)
32
29
{
59
56
    unit->offset_limit_cnt--;
60
57
    return 0;
61
58
  }
62
 
  fill_record(session, table->field, values, true);
 
59
  fill_record(session, table->field, values, 1);
63
60
  if (session->is_error())
64
61
    return 1;
65
62
 
66
 
  if ((error= table->cursor->ha_write_row(table->record[0])))
 
63
  if ((error= table->file->ha_write_row(table->record[0])))
67
64
  {
68
65
    /* create_myisam_from_heap will generate error if needed */
69
 
    if (table->cursor->is_fatal_error(error, HA_CHECK_DUP) &&
 
66
    if (table->file->is_fatal_error(error, HA_CHECK_DUP) &&
70
67
        create_myisam_from_heap(session, table, tmp_table_param.start_recinfo,
71
68
                                &tmp_table_param.recinfo, error, 1))
72
69
      return 1;
84
81
bool select_union::flush()
85
82
{
86
83
  int error;
87
 
  if ((error=table->cursor->extra(HA_EXTRA_NO_CACHE)))
 
84
  if ((error=table->file->extra(HA_EXTRA_NO_CACHE)))
88
85
  {
89
 
    table->print_error(error, MYF(0));
 
86
    table->file->print_error(error, MYF(0));
90
87
    return 1;
91
88
  }
92
89
  return 0;
104
101
                         duplicates on insert
105
102
      options            create options
106
103
      table_alias        name of the temporary table
 
104
      bit_fields_as_long convert bit fields to uint64_t
107
105
 
108
106
  DESCRIPTION
109
107
    Create a temporary table that is used to store the result of a UNION,
117
115
bool
118
116
select_union::create_result_table(Session *session_arg, List<Item> *column_types,
119
117
                                  bool is_union_distinct, uint64_t options,
120
 
                                  const char *table_alias)
 
118
                                  const char *table_alias,
 
119
                                  bool bit_fields_as_long)
121
120
{
122
 
  assert(table == NULL);
 
121
  assert(table == 0);
123
122
  tmp_table_param.init();
124
123
  tmp_table_param.field_count= column_types->elements;
 
124
  tmp_table_param.bit_fields_as_long= bit_fields_as_long;
125
125
 
126
126
  if (! (table= create_tmp_table(session_arg, &tmp_table_param, *column_types,
127
 
                                 (order_st*) NULL, is_union_distinct, 1,
 
127
                                 (order_st*) 0, is_union_distinct, 1,
128
128
                                 options, HA_POS_ERROR, (char*) table_alias)))
129
129
    return true;
130
 
  table->cursor->extra(HA_EXTRA_WRITE_CACHE);
131
 
  table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
 
130
  table->file->extra(HA_EXTRA_WRITE_CACHE);
 
131
  table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
132
132
  return false;
133
133
}
134
134
 
142
142
 
143
143
void select_union::cleanup()
144
144
{
145
 
  table->cursor->extra(HA_EXTRA_RESET_STATE);
146
 
  table->cursor->ha_delete_all_rows();
147
 
  table->free_io_cache();
148
 
  table->filesort_free_buffers();
 
145
  table->file->extra(HA_EXTRA_RESET_STATE);
 
146
  table->file->ha_delete_all_rows();
 
147
  free_io_cache(table);
 
148
  filesort_free_buffers(table,0);
149
149
}
150
150
 
151
151
 
273
273
                                sl->order_list.elements) +
274
274
                               sl->group_list.elements,
275
275
                               can_skip_order_by ?
276
 
                               (order_st*) NULL : (order_st *)sl->order_list.first,
 
276
                               (order_st*) 0 : (order_st *)sl->order_list.first,
277
277
                               (order_st*) sl->group_list.first,
278
278
                               sl->having,
279
279
                               sl, this);
353
353
                     TMP_TABLE_ALL_COLUMNS);
354
354
 
355
355
    if (union_result->create_result_table(session, &types, test(union_distinct),
356
 
                                          create_options, ""))
 
356
                                          create_options, "", false))
357
357
      goto err;
358
358
    memset(&result_table_list, 0, sizeof(result_table_list));
359
359
    result_table_list.db= (char*) "";
409
409
      {
410
410
        item->assigned(0); // We will reinit & rexecute unit
411
411
        item->reset();
412
 
        table->cursor->ha_delete_all_rows();
 
412
        table->file->ha_delete_all_rows();
413
413
      }
414
414
      /* re-enabling indexes for next subselect iteration */
415
 
      if (union_distinct && table->cursor->ha_enable_indexes(HA_KEY_SWITCH_ALL))
 
415
      if (union_distinct && table->file->ha_enable_indexes(HA_KEY_SWITCH_ALL))
416
416
      {
417
417
        assert(0);
418
418
      }
431
431
        {
432
432
          offset_limit_cnt= 0;
433
433
          /*
434
 
            We can't use LIMIT at this stage if we are using ORDER BY for the
 
434
            We can't use LIMIT at this stage if we are using order_st BY for the
435
435
            whole query
436
436
          */
437
437
          if (sl->order_list.first || describe)
447
447
          (select_limit_cnt == HA_POS_ERROR || sl->braces) ?
448
448
          sl->options & ~OPTION_FOUND_ROWS : sl->options | found_rows_for_union;
449
449
 
 
450
        if (sl->join->flatten_subqueries())
 
451
          return(true);
 
452
 
450
453
        saved_error= sl->join->optimize();
451
454
      }
452
455
      if (!saved_error)
453
456
      {
454
 
        records_at_start= table->cursor->stats.records;
 
457
        records_at_start= table->file->stats.records;
455
458
        sl->join->exec();
456
459
        if (sl == union_distinct)
457
460
        {
458
 
          if (table->cursor->ha_disable_indexes(HA_KEY_SWITCH_ALL))
 
461
          if (table->file->ha_disable_indexes(HA_KEY_SWITCH_ALL))
459
462
            return(true);
460
463
          table->no_keyread=1;
461
464
        }
479
482
        return(saved_error);
480
483
      }
481
484
      /* Needed for the following test and for records_at_start in next loop */
482
 
      int error= table->cursor->info(HA_STATUS_VARIABLE);
483
 
      if (error)
 
485
      int error= table->file->info(HA_STATUS_VARIABLE);
 
486
      if(error)
484
487
      {
485
 
        table->print_error(error, MYF(0));
 
488
        table->file->print_error(error, MYF(0));
486
489
        return(1);
487
490
      }
488
491
      if (found_rows_for_union && !sl->braces &&
495
498
          rows and actual rows added to the temporary table.
496
499
        */
497
500
        add_rows+= (uint64_t) (session->limit_found_rows - (uint64_t)
498
 
                              ((table->cursor->stats.records -  records_at_start)));
 
501
                              ((table->file->stats.records -  records_at_start)));
499
502
      }
500
503
    }
501
504
  }
575
578
      fake_select_lex->table_list.empty();
576
579
      if (!saved_error)
577
580
      {
578
 
        session->limit_found_rows = (uint64_t)table->cursor->stats.records + add_rows;
 
581
        session->limit_found_rows = (uint64_t)table->file->stats.records + add_rows;
579
582
        session->examined_row_count+= examined_rows;
580
583
      }
581
584
      /*
732
735
    for (sl= unit->first_select(); sl; sl= sl->next_select())
733
736
      sl->cleanup_all_joins(full);
734
737
}
735
 
 
736
 
} /* namespace drizzled */