From: Zardosht Kasheff Date: September 20 2010 2:44pm Subject: Re: question on mysql_alter_table List-Archive: http://lists.mysql.com/internals/38107 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable The MySQL Cluster code base has changed the handler interface and mysql_alter_table_ to support these functions I list below. I am trying to port them, and mysql cluster's implementation of mysql_alter_table to 5.1. However, I want to do it in a way that is safe, so I do not risk breaking other storage engines. So, the current mysql_alter_table will become old_mysql_alter_table, and MySQL Cluster's implementation will be new_mysql_alter_table. I realize there is a bunch in common between the two functions, but I do not understand them well enough to just merge them. Thanks -Zardosht virtual int check_if_supported_alter(TABLE *altered_table, HA_CREATE_INFO *create_info, HA_ALTER_FLAGS *alter_flags, uint table_changes); virtual int alter_table_phase1(THD *thd, TABLE *altered_table, HA_CREATE_INFO *create_info, HA_ALTER_INFO *alter_info, HA_ALTER_FLAGS *alter_flags) virtual int alter_table_phase2(THD *thd, TABLE *altered_table, HA_CREATE_INFO *create_info, HA_ALTER_INFO *alter_info, HA_ALTER_FLAGS *alter_flags) virtual int alter_table_phase3(THD *thd, TABLE *table) { return HA_ERR_UNSUPPORTED; } On Mon, Sep 20, 2010 at 10:35 AM, Konstantin Osipov wrote: > * Zardosht Kasheff [10/09/20 11:31]: >> I am trying to make a change to mysql_alter_table, but I want the >> change to apply only when the table being altered is created with my >> storage engine. So, I have two different versions of mysql_alter_table >> written, one named old_mysql_alter_table, which is the current >> functionality, and the other is new_mysql_alter_table, which has my >> changes. > > Maybe you could start by telling what exactly it is that you > want from ALTER that requires a completely new implementation? > >> I would like to implement mysql_alter_table as such: >> =A0 =A0 if (use_new) { >> =A0 =A0 =A0 =A0 bool failed =3D new_mysql_alter_table( >> =A0 =A0 =A0 =A0 =A0 =A0 thd, >> =A0 =A0 =A0 =A0 =A0 =A0 new_db, >> =A0 =A0 =A0 =A0 =A0 =A0 new_name, >> =A0 =A0 =A0 =A0 =A0 =A0 create_info, >> =A0 =A0 =A0 =A0 =A0 =A0 table_list, >> =A0 =A0 =A0 =A0 =A0 =A0 alter_info, >> =A0 =A0 =A0 =A0 =A0 =A0 order_num, >> =A0 =A0 =A0 =A0 =A0 =A0 order, >> =A0 =A0 =A0 =A0 =A0 =A0 ignore >> =A0 =A0 =A0 =A0 =A0 =A0 ); >> =A0 =A0 } >> =A0 =A0 else return old_mysql_alter_table( >> =A0 =A0 =A0 =A0 thd, >> =A0 =A0 =A0 =A0 new_db, >> =A0 =A0 =A0 =A0 new_name, >> =A0 =A0 =A0 =A0 create_info, >> =A0 =A0 =A0 =A0 table_list, >> =A0 =A0 =A0 =A0 alter_info, >> =A0 =A0 =A0 =A0 order_num, >> =A0 =A0 =A0 =A0 order, >> =A0 =A0 =A0 =A0 ignore >> =A0 =A0 =A0 =A0 ); > >> >> I do not know how to evaluate use_new. Ideally, I would do something >> like the following: >> =A0 =A0 ulong alter_flags=3D 0; >> =A0 =A0 alter_flags=3D table_list->table->s->db_type() ? >> table_list->table->s->db_type()->alter_table_flags(alter_info->flags) >> : 0; >> =A0 =A0 bool use_new =3D (alter_flags & HA_FLAG_THAT_ONLY_MY_ENGINE_HAS)= ? true:false; >> >> The problem is that table_list->table is not yet set, and I do not see >> how to get easily get access to the table that is about to be altered. >> >> Any ideas on how I could solve this problem? > > You can only look at the storage engine after the table is opened. > The table is opened in the beginning of mysql_alter_table(). > Look for open_ltable(). > > > -- >