~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2010-04-20 18:23:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1502.
  • Revision ID: brian@gaz-20100420182307-jwyhun4vm2dtugyb
There is room for improvement around this. We should be using rows as well
in the future as a metric for disk/memory store. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
2345
2345
  if (group)
2346
2346
  {
2347
2347
    if (! param->quick_group)
 
2348
    {
2348
2349
      group= 0;                                 // Can't use group key
 
2350
    }
2349
2351
    else for (order_st *tmp=group ; tmp ; tmp=tmp->next)
2350
2352
    {
2351
2353
      /*
2589
2591
 
2590
2592
  /* If result table is small; use a heap */
2591
2593
  /* future: storage engine selection can be made dynamic? */
2592
 
  if (blob_count || using_unique_constraint ||
 
2594
  if (blob_count || using_unique_constraint || 
 
2595
      (session->lex->select_lex.options & SELECT_BIG_RESULT) ||
 
2596
      (session->lex->current_select->olap == ROLLUP_TYPE) ||
2593
2597
      (select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
2594
2598
  {
2595
2599
    share->storage_engine= myisam_engine;
2597
2601
    if (group &&
2598
2602
        (param->group_parts > table->cursor->getEngine()->max_key_parts() ||
2599
2603
         param->group_length > table->cursor->getEngine()->max_key_length()))
 
2604
    {
2600
2605
      using_unique_constraint= true;
 
2606
    }
2601
2607
  }
2602
2608
  else
2603
2609
  {
3262
3268
  session->set_proc_info(save_proc_info);
3263
3269
}
3264
3270
 
3265
 
/**
3266
 
  If a HEAP table gets full, create a MyISAM table and copy all rows
3267
 
  to this.
3268
 
*/
3269
 
 
3270
 
bool create_myisam_from_heap(Session *session, Table *table,
3271
 
                             MI_COLUMNDEF *start_recinfo,
3272
 
                             MI_COLUMNDEF **recinfo,
3273
 
                             int error, bool ignore_last_dupp_key_error)
3274
 
{
3275
 
  Table new_table;
3276
 
  TableShare share;
3277
 
  const char *save_proc_info;
3278
 
  int write_err;
3279
 
 
3280
 
  if (table->s->db_type() != heap_engine ||
3281
 
      error != HA_ERR_RECORD_FILE_FULL)
3282
 
  {
3283
 
    table->print_error(error, MYF(0));
3284
 
    return true;
3285
 
  }
3286
 
 
3287
 
  // Release latches since this can take a long time
3288
 
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
3289
 
 
3290
 
  new_table= *table;
3291
 
  share= *table->s;
3292
 
  new_table.s= &share;
3293
 
  new_table.s->storage_engine= myisam_engine;
3294
 
  if (not (new_table.cursor= new_table.s->db_type()->getCursor(share, &new_table.mem_root)))
3295
 
    return true;                                // End of memory
3296
 
 
3297
 
  save_proc_info=session->get_proc_info();
3298
 
  session->set_proc_info("converting HEAP to MyISAM");
3299
 
 
3300
 
  if (new_table.create_myisam_tmp_table(table->key_info, start_recinfo,
3301
 
                                        recinfo, session->lex->select_lex.options |
3302
 
                                        session->options))
3303
 
    goto err2;
3304
 
  if (new_table.open_tmp_table())
3305
 
    goto err1;
3306
 
  if (table->cursor->indexes_are_disabled())
3307
 
    new_table.cursor->ha_disable_indexes(HA_KEY_SWITCH_ALL);
3308
 
  table->cursor->ha_index_or_rnd_end();
3309
 
  table->cursor->ha_rnd_init(1);
3310
 
  if (table->no_rows)
3311
 
  {
3312
 
    new_table.cursor->extra(HA_EXTRA_NO_ROWS);
3313
 
    new_table.no_rows=1;
3314
 
  }
3315
 
 
3316
 
  /* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */
3317
 
  new_table.cursor->extra(HA_EXTRA_WRITE_CACHE);
3318
 
 
3319
 
  /*
3320
 
    copy all old rows from heap table to MyISAM table
3321
 
    This is the only code that uses record[1] to read/write but this
3322
 
    is safe as this is a temporary MyISAM table without timestamp/autoincrement.
3323
 
  */
3324
 
  while (!table->cursor->rnd_next(new_table.record[1]))
3325
 
  {
3326
 
    write_err= new_table.cursor->ha_write_row(new_table.record[1]);
3327
 
    if (write_err)
3328
 
      goto err;
3329
 
  }
3330
 
  /* copy row that filled HEAP table */
3331
 
  if ((write_err=new_table.cursor->ha_write_row(table->record[0])))
3332
 
  {
3333
 
    if (new_table.cursor->is_fatal_error(write_err, HA_CHECK_DUP) ||
3334
 
        !ignore_last_dupp_key_error)
3335
 
      goto err;
3336
 
  }
3337
 
 
3338
 
  /* remove heap table and change to use myisam table */
3339
 
  (void) table->cursor->ha_rnd_end();
3340
 
  (void) table->cursor->close();                  // This deletes the table !
3341
 
  delete table->cursor;
3342
 
  table->cursor= NULL;
3343
 
  new_table.s= table->s;                       // Keep old share
3344
 
  *table= new_table;
3345
 
  *table->s= share;
3346
 
 
3347
 
  table->cursor->change_table_ptr(table, table->s);
3348
 
  table->use_all_columns();
3349
 
  if (save_proc_info)
3350
 
  {
3351
 
    const char *new_proc_info=
3352
 
      (!strcmp(save_proc_info,"Copying to tmp table") ?
3353
 
      "Copying to tmp table on disk" : save_proc_info);
3354
 
    session->set_proc_info(new_proc_info);
3355
 
  }
3356
 
  return false;
3357
 
 
3358
 
 err:
3359
 
  table->print_error(write_err, MYF(0));
3360
 
  (void) table->cursor->ha_rnd_end();
3361
 
  (void) new_table.cursor->close();
3362
 
 
3363
 
 err1:
3364
 
  {
3365
 
    TableIdentifier identifier(new_table.s->getSchemaName(), new_table.s->table_name.str, new_table.s->table_name.str);
3366
 
    new_table.s->db_type()->doDropTable(*session, identifier);
3367
 
  }
3368
 
 
3369
 
 err2:
3370
 
  delete new_table.cursor;
3371
 
  session->set_proc_info(save_proc_info);
3372
 
  table->mem_root= new_table.mem_root;
3373
 
  return true;
3374
 
}
3375
 
 
3376
3271
my_bitmap_map *Table::use_all_columns(MyBitmap *bitmap)
3377
3272
{
3378
3273
  my_bitmap_map *old= bitmap->getBitmap();