~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Brian Aker
  • Date: 2009-11-12 16:13:04 UTC
  • mfrom: (1211.1.7 staging)
  • Revision ID: brian@gaz-20091112161304-opamiauv36fg0n6u
Rollup of Brian, Padraig, and Stewart patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
185
185
      table->found_next_number_field)
186
186
  {
187
187
    /* Table has an autoincrement, copy value to new table */
188
 
    table->file->info(HA_STATUS_AUTO);
189
 
    create_info->auto_increment_value= table->file->stats.auto_increment_value;
 
188
    table->cursor->info(HA_STATUS_AUTO);
 
189
    create_info->auto_increment_value= table->cursor->stats.auto_increment_value;
190
190
  }
191
191
  if (! (used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE)
192
192
      && table->s->hasKeyBlockSize())
539
539
    return -1;
540
540
  }
541
541
 
542
 
  error= table->file->ha_discard_or_import_tablespace(discard);
 
542
  error= table->cursor->ha_discard_or_import_tablespace(discard);
543
543
 
544
544
  session->set_proc_info("end");
545
545
 
564
564
    return 0;
565
565
  }
566
566
 
567
 
  table->file->print_error(error, MYF(0));
 
567
  table->cursor->print_error(error, MYF(0));
568
568
 
569
569
  return -1;
570
570
}
589
589
  int error= 0;
590
590
  switch (keys_onoff) {
591
591
  case ENABLE:
592
 
    error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
 
592
    error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
593
593
    break;
594
594
  case LEAVE_AS_IS:
595
595
    if (!indexes_were_disabled)
596
596
      break;
597
597
    /* fall-through: disabled indexes */
598
598
  case DISABLE:
599
 
    error= table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
 
599
    error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
600
600
  }
601
601
 
602
602
  if (error == HA_ERR_WRONG_COMMAND)
606
606
                        table->s->table_name.str);
607
607
    error= 0;
608
608
  } else if (error)
609
 
    table->file->print_error(error, MYF(0));
 
609
    table->cursor->print_error(error, MYF(0));
610
610
 
611
611
  return(error);
612
612
}
808
808
  new_db_type= create_info->db_type;
809
809
 
810
810
  if (new_db_type != old_db_type &&
811
 
      !table->file->can_switch_engines())
 
811
      !table->cursor->can_switch_engines())
812
812
  {
813
813
    assert(0);
814
814
    my_error(ER_ROW_IS_REFERENCED, MYF(0));
854
854
      pthread_mutex_lock(&LOCK_open); /* DDL wait for/blocker */
855
855
      wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
856
856
      pthread_mutex_unlock(&LOCK_open);
857
 
      error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
 
857
      error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
858
858
      /* COND_refresh will be signaled in close_thread_tables() */
859
859
      break;
860
860
    case DISABLE:
861
861
      pthread_mutex_lock(&LOCK_open); /* DDL wait for/blocker */
862
862
      wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
863
863
      pthread_mutex_unlock(&LOCK_open);
864
 
      error=table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
 
864
      error=table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
865
865
      /* COND_refresh will be signaled in close_thread_tables() */
866
866
      break;
867
867
    default:
933
933
    }
934
934
    else if (error > 0)
935
935
    {
936
 
      table->file->print_error(error, MYF(0));
 
936
      table->cursor->print_error(error, MYF(0));
937
937
      error= -1;
938
938
    }
939
939
 
1284
1284
  if (!(copy= new CopyField[to->s->fields]))
1285
1285
    return -1;
1286
1286
 
1287
 
  if (to->file->ha_external_lock(session, F_WRLCK))
 
1287
  if (to->cursor->ha_external_lock(session, F_WRLCK))
1288
1288
    return -1;
1289
1289
 
1290
1290
  /* We need external lock before we can disable/enable keys */
1291
 
  alter_table_manage_keys(to, from->file->indexes_are_disabled(), keys_onoff);
 
1291
  alter_table_manage_keys(to, from->cursor->indexes_are_disabled(), keys_onoff);
1292
1292
 
1293
1293
  /* We can abort alter table for any table type */
1294
1294
  session->abort_on_warning= !ignore;
1295
1295
 
1296
 
  from->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
1297
 
  to->file->ha_start_bulk_insert(from->file->stats.records);
 
1296
  from->cursor->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
 
1297
  to->cursor->ha_start_bulk_insert(from->cursor->stats.records);
1298
1298
 
1299
1299
  List_iterator<CreateField> it(create);
1300
1300
  CreateField *def;
1316
1316
 
1317
1317
  if (order)
1318
1318
  {
1319
 
    if (to->s->primary_key != MAX_KEY && to->file->primary_key_is_clustered())
 
1319
    if (to->s->primary_key != MAX_KEY && to->cursor->primary_key_is_clustered())
1320
1320
    {
1321
1321
      char warn_buff[DRIZZLE_ERRMSG_SIZE];
1322
1322
      snprintf(warn_buff, sizeof(warn_buff),
1353
1353
  to->use_all_columns();
1354
1354
  init_read_record(&info, session, from, (SQL_SELECT *) 0, 1,1);
1355
1355
  if (ignore)
1356
 
    to->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
 
1356
    to->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1357
1357
  session->row_count= 0;
1358
1358
  to->restoreRecordAsDefault();        // Create empty record
1359
1359
  while (!(error=info.read_record(&info)))
1383
1383
    {
1384
1384
      copy_ptr->do_copy(copy_ptr);
1385
1385
    }
1386
 
    prev_insert_id= to->file->next_insert_id;
1387
 
    error=to->file->ha_write_row(to->record[0]);
 
1386
    prev_insert_id= to->cursor->next_insert_id;
 
1387
    error= to->cursor->ha_write_row(to->record[0]);
1388
1388
    to->auto_increment_field_not_null= false;
1389
1389
    if (error)
1390
1390
    {
1391
1391
      if (!ignore ||
1392
 
          to->file->is_fatal_error(error, HA_CHECK_DUP))
 
1392
          to->cursor->is_fatal_error(error, HA_CHECK_DUP))
1393
1393
      {
1394
 
         if (!to->file->is_fatal_error(error, HA_CHECK_DUP))
1395
 
         {
1396
 
           uint32_t key_nr= to->file->get_dup_key(error);
1397
 
           if ((int) key_nr >= 0)
1398
 
           {
1399
 
             const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
1400
 
             if (key_nr == 0 &&
1401
 
                 (to->key_info[0].key_part[0].field->flags &
1402
 
                  AUTO_INCREMENT_FLAG))
1403
 
               err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE);
1404
 
             to->file->print_keydup_error(key_nr, err_msg);
1405
 
             break;
1406
 
           }
1407
 
         }
 
1394
        if (!to->cursor->is_fatal_error(error, HA_CHECK_DUP))
 
1395
        {
 
1396
          uint32_t key_nr= to->cursor->get_dup_key(error);
 
1397
          if ((int) key_nr >= 0)
 
1398
          {
 
1399
            const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
 
1400
            if (key_nr == 0 &&
 
1401
                (to->key_info[0].key_part[0].field->flags &
 
1402
                 AUTO_INCREMENT_FLAG))
 
1403
              err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE);
 
1404
            to->cursor->print_keydup_error(key_nr, err_msg);
 
1405
            break;
 
1406
          }
 
1407
        }
1408
1408
 
1409
 
        to->file->print_error(error,MYF(0));
1410
 
        break;
 
1409
        to->cursor->print_error(error,MYF(0));
 
1410
        break;
1411
1411
      }
1412
 
      to->file->restore_auto_increment(prev_insert_id);
 
1412
      to->cursor->restore_auto_increment(prev_insert_id);
1413
1413
      delete_count++;
1414
1414
    }
1415
1415
    else
1419
1419
  from->free_io_cache();
1420
1420
  delete [] copy;                               // This is never 0
1421
1421
 
1422
 
  if (to->file->ha_end_bulk_insert() && error <= 0)
 
1422
  if (to->cursor->ha_end_bulk_insert() && error <= 0)
1423
1423
  {
1424
 
    to->file->print_error(my_errno,MYF(0));
 
1424
    to->cursor->print_error(my_errno,MYF(0));
1425
1425
    error=1;
1426
1426
  }
1427
 
  to->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
 
1427
  to->cursor->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1428
1428
 
1429
1429
  if (ha_enable_transaction(session, true))
1430
1430
  {
1446
1446
  from->free_io_cache();
1447
1447
  *copied= found_count;
1448
1448
  *deleted=delete_count;
1449
 
  to->file->ha_release_auto_increment();
1450
 
  if (to->file->ha_external_lock(session,F_UNLCK))
 
1449
  to->cursor->ha_release_auto_increment();
 
1450
  if (to->cursor->ha_external_lock(session,F_UNLCK))
1451
1451
    error=1;
1452
1452
  return(error > 0 ? -1 : 0);
1453
1453
}
1514
1514
  if (mysql_prepare_create_table(session, &local_create_info, table_proto,
1515
1515
                                 &alter_info,
1516
1516
                                 tmp_table, &db_options,
1517
 
                                 schema_table->table->file,
 
1517
                                 schema_table->table->cursor,
1518
1518
                                 &schema_table->table->s->key_info, &keys, 0))
1519
1519
    return true;
1520
1520