~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-08-17 15:34:55 UTC
  • mto: (1117.1.9 merge)
  • mto: This revision was merged to the branch mainline in revision 1118.
  • Revision ID: brian@gaz-20090817153455-emrlqx6cbxo9knfm
Fix for Stewart's patch (includes hack to solve MAX rows problem).

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
static bool
78
78
mysql_prepare_alter_table(Session *session, Table *table,
79
79
                          HA_CREATE_INFO *create_info,
 
80
                          drizzled::message::Table *table_proto,
80
81
                          Alter_info *alter_info);
81
82
 
82
83
static void set_table_default_charset(HA_CREATE_INFO *create_info, char *db)
2540
2541
  alter_info.flags.set(ALTER_RECREATE);
2541
2542
  schema_table->table->use_all_columns();
2542
2543
  if (mysql_prepare_alter_table(session, schema_table->table,
2543
 
                                &local_create_info, &alter_info))
 
2544
                                &local_create_info, table_proto, &alter_info))
2544
2545
    return true;
2545
2546
 
 
2547
  /* I_S tables are created with MAX_ROWS for some efficiency drive.
 
2548
     When CREATE LIKE, we don't want to keep it coming across */
 
2549
  drizzled::message::Table::TableOptions *table_options;
 
2550
  table_options= table_proto->mutable_options();
 
2551
  table_options->clear_max_rows();
 
2552
 
2546
2553
  if (mysql_prepare_create_table(session, &local_create_info, &alter_info,
2547
2554
                                 tmp_table, &db_options,
2548
2555
                                 schema_table->table->file,
2549
2556
                                 &schema_table->table->s->key_info, &keys, 0))
2550
2557
    return true;
2551
2558
 
2552
 
  local_create_info.max_rows= 0;
2553
 
 
2554
2559
  table_proto->set_name("system_stupid_i_s_fix_nonsense");
2555
2560
  if(tmp_table)
2556
2561
    table_proto->set_type(drizzled::message::Table::TEMPORARY);
2929
2934
  return(error);
2930
2935
}
2931
2936
 
2932
 
static int 
 
2937
static int
2933
2938
create_temporary_table(Session *session,
2934
2939
                       Table *table,
2935
2940
                       char *new_db,
2936
2941
                       char *tmp_name,
2937
2942
                       HA_CREATE_INFO *create_info,
 
2943
                       drizzled::message::Table *create_proto,
2938
2944
                       Alter_info *alter_info,
2939
2945
                       bool db_changed)
2940
2946
{
2993
2999
    Create a table with a temporary name.
2994
3000
    We don't log the statement, it will be logged later.
2995
3001
  */
2996
 
  drizzled::message::Table table_proto;
2997
 
  table_proto.set_name(tmp_name);
2998
 
  table_proto.set_type(drizzled::message::Table::TEMPORARY);
 
3002
  create_proto->set_name(tmp_name);
 
3003
  create_proto->set_type(drizzled::message::Table::TEMPORARY);
2999
3004
 
3000
3005
  drizzled::message::Table::StorageEngine *protoengine;
3001
 
  protoengine= table_proto.mutable_engine();
 
3006
  protoengine= create_proto->mutable_engine();
3002
3007
  protoengine->set_name(new_db_type->getName());
3003
3008
 
3004
3009
  error= mysql_create_table(session, new_db, tmp_name,
3005
 
                            create_info, &table_proto, alter_info, 1, 0);
 
3010
                            create_info, create_proto, alter_info, 1, 0);
3006
3011
 
3007
3012
  return(error);
3008
3013
}
3052
3057
static bool
3053
3058
mysql_prepare_alter_table(Session *session, Table *table,
3054
3059
                          HA_CREATE_INFO *create_info,
 
3060
                          drizzled::message::Table *table_proto,
3055
3061
                          Alter_info *alter_info)
3056
3062
{
3057
3063
  /* New column definitions are added here */
3074
3080
 
3075
3081
  create_info->varchar= false;
3076
3082
  /* Let new create options override the old ones */
3077
 
  if (!(used_fields & HA_CREATE_USED_MIN_ROWS))
3078
 
    create_info->min_rows= table->s->min_rows;
3079
 
  if (!(used_fields & HA_CREATE_USED_MAX_ROWS))
3080
 
    create_info->max_rows= table->s->max_rows;
3081
 
  if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
3082
 
    create_info->avg_row_length= table->s->avg_row_length;
 
3083
  drizzled::message::Table::TableOptions *table_options;
 
3084
  table_options= table_proto->mutable_options();
 
3085
 
 
3086
  if (! table_proto->options().has_min_rows()
 
3087
      && table->s->hasMinRows())
 
3088
    table_options->set_min_rows(table->s->getMinRows());
 
3089
 
 
3090
  if (! table_proto->options().has_max_rows()
 
3091
      && table->s->hasMaxRows())
 
3092
    table_options->set_max_rows(table->s->getMaxRows());
 
3093
 
 
3094
  if (!(table_proto->options().has_avg_row_length())
 
3095
      && table->s->getAverageRowLength())
 
3096
    table_options->set_avg_row_length(table->s->getAverageRowLength());
 
3097
 
3083
3098
  if (!(used_fields & HA_CREATE_USED_BLOCK_SIZE))
3084
3099
    create_info->block_size= table->s->block_size;
3085
3100
  if (!(used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
3383
3398
    goto err;
3384
3399
  }
3385
3400
 
3386
 
  if (!create_info->comment.str)
3387
 
  {
3388
 
    create_info->comment.str= table->s->comment.str;
3389
 
    create_info->comment.length= table->s->comment.length;
3390
 
  }
 
3401
  if (! table_proto->options().has_comment()
 
3402
      && table->s->hasComment())
 
3403
    table_options->set_comment(table->s->getComment());
3391
3404
 
3392
3405
  table->file->update_create_info(create_info);
3393
3406
  if ((create_info->table_options &
3460
3473
                       char *new_db, 
3461
3474
                       char *new_name,
3462
3475
                       HA_CREATE_INFO *create_info,
 
3476
                       drizzled::message::Table *create_proto,
3463
3477
                       TableList *table_list,
3464
3478
                       Alter_info *alter_info,
3465
3479
                       uint32_t order_num, 
3763
3777
  */
3764
3778
  new_db_type= create_info->db_type;
3765
3779
 
3766
 
  if (mysql_prepare_alter_table(session, table, create_info, alter_info))
3767
 
    goto err;
 
3780
  if (mysql_prepare_alter_table(session, table, create_info, create_proto,
 
3781
                                alter_info))
 
3782
      goto err;
3768
3783
 
3769
3784
  set_table_default_charset(create_info, db);
3770
3785
 
3776
3791
  my_casedn_str(files_charset_info, tmp_name);
3777
3792
 
3778
3793
  /* Create a temporary table with the new format */
3779
 
  error= create_temporary_table(session, table, new_db, tmp_name, create_info, alter_info, ! strcmp(db, new_db));
3780
 
 
 
3794
  error= create_temporary_table(session, table, new_db, tmp_name, create_info, create_proto, alter_info, !strcmp(db, new_db));
3781
3795
  if (error != 0)
3782
3796
    goto err;
3783
3797
 
4271
4285
{
4272
4286
  HA_CREATE_INFO create_info;
4273
4287
  Alter_info alter_info;
 
4288
  drizzled::message::Table table_proto;
4274
4289
 
4275
4290
  assert(!table_list->next_global);
4276
4291
  /*
4285
4300
  /* Force alter table to recreate table */
4286
4301
  alter_info.flags.set(ALTER_CHANGE_COLUMN);
4287
4302
  alter_info.flags.set(ALTER_RECREATE);
4288
 
  return(mysql_alter_table(session, NULL, NULL, &create_info,
4289
 
                                table_list, &alter_info, 0,
4290
 
                                (order_st *) 0, 0));
 
4303
  return(mysql_alter_table(session, NULL, NULL, &create_info, &table_proto,
 
4304
                           table_list, &alter_info, 0,
 
4305
                           (order_st *) 0, 0));
4291
4306
}
4292
4307
 
4293
4308