← Back to team overview

maria-developers team mailing list archive

Re: MDEV-318 IF (NOT) EXIST clauses for ALTER TABLE

 

18.12.2012 15:30, Sergei Golubchik wrote:
And one more thing.
It's easy to imagine a user that likes to do the ALTER IF EXISTS
queries often.

But even if the 'new_field' exists already, ADD FIELD IF EXISTS
new_field still does a lot.
The list of calls is:
       mysql_create_table_no_lock()  - creates the .frm file with the
                                       temporary name
       mysql_rename_table()
       mysql_rename_table()   once more
       quick_rm_table()  - removes the old .frm
       query_cache_invalidate()
       reopen_table()
Hmm, I don't see it. If the field exists, mysql_alter_table will notice
it in compare_tables() - that is, before mysql_create_table_no_lock().


It's easy to see, just run the ALTER TABLE ADD FIELD IF NOT EXISTS (int existing_field). If the added field already exists, the ALTER TABLE will recreate the table anyway.

The can mysql_compare_tables notice it. But in the IF EXISTS case we don't break
the command. So that the alter_table process will be continued.
We can check in the mysql_compare_tables() if the tables are equal and
return the specific code for that. But it's not trivial to implement.
It wasn't a problem until this MDEV as the ALTER list could never be empty. But
now i think it can be useful to perform the NOOP ALTER possible faster.

Otherwise i'm working now to reform the mysql_alter_table() so we can do the IF EXISTS checks in the same places where we return the errors about (not yet) existing objects. It seems working, but the modification is going to be significant. Are we ok with big changes
in this part of code?

Regards.
HF



Follow ups

References