Hi,
This looks very promising. Column default values are needed for
referential action set default in foreign keys. Any idea of MySQL
version where this new alter table interface is planned ?
R: Jan
> Hi Jan!
>
> We are in the process of re-designing the current on-line alter table
> interface (which currently
> only supports add/drop index). The old interface is based on handlers
> having "capability"
> flags (handlerton::alter_table_flags) and the MySQL server orchestrates
> the steps needed for
> different alter table operations. After discussions this approach has
> been decided to
> be too complex since different storage engines need to do various
> operations in
> different ways. Also adding flags and new handler calls for each
> possible change will
> make the handler interface huge.
> The current plan is to add more general calls (note that the interface
> is still under design
> and might change, but you should get the idea):
>
> One call for asking the handler if it can do the alteration on-line:
>
> int handler::check_if_supported_alter(TABLE *altered_table,
> HA_CREATE_INFO *create_info,
> HA_ALTER_FLAGS alter_flags,
> uint table_changes);
>
> where HA_ALTER_FLAGS is defined by:
> #define HA_ADD_INDEX (1L << 0)
> #define HA_DROP_INDEX (1L << 1)
> #define HA_ALTER_INDEX (1L << 2)
> #define HA_RENAME_INDEX (1L << 3)
> #define HA_ADD_UNIQUE_INDEX (1L << 4)
> #define HA_DROP_UNIQUE_INDEX (1L << 5)
> #define HA_ALTER_UNIQUE_INDEX (1L << 6)
> #define HA_RENAME_UNIQUE_INDEX (1L << 7)
> #define HA_ADD_PK_INDEX (1L << 8)
> #define HA_DROP_PK_INDEX (1L << 9)
> #define HA_ALTER_PK_INDEX (1L << 10)
> #define HA_ADD_COLUMN (1L << 11)
> #define HA_DROP_COLUMN (1L << 12)
> #define HA_ALTER_COLUMN_NAME (1L << 13)
> #define HA_ALTER_COLUMN_TYPE (1L << 14)
> #define HA_ALTER_COLUMN_ORDER (1L << 15)
> #define HA_ADD_FOREIGN_KEY (1L << 16)
> #define HA_DROP_FOREIGN_KEY (1L << 17)
> #define HA_ADD_CONSTRAINT (1L << 18)
> #define HA_ADD_PARTITION (1L << 19)
> #define HA_DROP_PARTITION (1L << 20)
> #define HA_COALESCE_PARTITION (1L << 21)
> #define HA_REORGANIZE_PARTITION (1L << 22)
> #define HA_CHANGE_CHARACTER_SET (1L << 23)
> #define HA_SET_DEFAULT_CHARACTER_SET (1L << 24)
> #define HA_RENAME_TABLE (1L << 25)
>
>
> Two calls are currently planned for executing the actual alteration:
>
> int handler::prepare_alter_table(TABLE *altered_table,
> HA_CREATE_INFO *create_info,
> HA_ALTER_FLAGS alter_flags);
>
> int handler::alter_table(TABLE *altered_table,
> HA_CREATE_INFO *create_info,
> HA_ALTER_FLAGS alter_flags);
>
>
> The only flag I see missing here would be for setting/changing column
> defaults, I will consider
> adding some flag(s) for that. The flags are supposed to hint what
> changes are made to the table,
> and the 'altered_table' argument will allow the handler to check exactly
> what has changed.
>
> Please feel free to comment if you see something missing in the current
> proposal.
>
> BR
> -- Martin
> Jan Lindström wrote:
> > Hi,
> >
> > I propose few additional functions to MySQL storage engine handler
> > interface:
> >
> > ::add_foreign_keys(THD* thd, TABLE *table_arg, foreign_key* fk_key, uint
> > n_fkeys);
> > Assuming that HA_CAN_ADD_FOREIGN_KEYS is set this
> > function is used for implementing alter table add
> > foreign key ...
> >
> > ::drop_foreign_keys(THD* thd, TABLE *table_arg, char* fk_names, uint
> > n_fkeys);
> >
> > Assuming that HA_CAN_DROP_FOREIGN_KEYS is set
> > this function is used to implement alter table drop foreign
> > key...
> >
> > ::set_column_defaults(THD* thd, TABLE *table_arg, char* field_names,
> > mysql_byte* default_values, uint n_defvalues);
> >
> > Assuming that HA_CAN_SET_DEFAUL_CASCADE is set this function
> > is used to modify column default value in alter table modify
> > column a set default ...
> >
> > Note that this would require that storage engine can in ::create
> > determine default value for the column (e.g.
> > Field->get_default_value())
> >
> > ::add_columns(THD* thd, TABLE *table_arg, Field* fields, uint n_fields);
> >
> > Assuming that HA_CAN_ADD_COLUMNS is set this function is used
> > to implement alter table add column ...
> >
> > ::drop_columns(THD* thd, TABLE *table_arg, char* field_names, uint
> > n_fields);
> > Assuming that HA_CAN_DROP_COLUMNS is set this function is used
> > to implement alter table drop column ...
> >
> > R: Jan Lindström
> > Solid Information Technology Ltd
> >
> >
> >
>
>