Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-318

IF (NOT) EXIST clauses for ALTER TABLE (MWL #252)

    Details

    • Type: Task
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Fix Version/s: 10.0.2
    • Component/s: None
    • Labels:

      Description

      MySQL / MariaDB SQL is great as a functional language: you tell what you want
      and not how to do it. This includes suppressing of errors when the situation you
      want already exists. So there is a CREATE TABLE IF NOT EXISTS statement, for
      example (you say that you want the table to exist, not that it has to be built
      right now). It would be nice if altering a table could be done the same way:

      ALTER TABLE SomeTable ADD COLUMN IF NOT EXISTS SomeColumn ...
      
      ALTER TABLE SomeTable DROP COLUMN IF EXISTS SomeColumn ...
      
      ALTER TABLE SomeTable DROP FOREIGN KEY IF EXISTS SomeConstraint ...
      

      This would make definition scripts more legible and more friendly to existing
      databases. It would facilitate what I call "repeatable scripts", that can both
      create a new database and update an existing one to the latest structure.

      Mind you, this is already possible using temporary stored procedures (as shown
      in http://www.howtoforge.com/node/4833), but it would make definition scripts
      more maintainable and the SQL language more consistent.

      Specific plan for this task:

      extend the ALTER TABLE statement with the IF [NOT] EXISTS options.
      That involves:

          ALTER TABLE ADD/DROP COLUMN
          ALTER TABLE ADD/DROP INDEX
          ALTER TABLE ADD/DROP FOREIGN KEY
          ALTER TABLE ADD/DROP PARTITION
          ALTER TABLE CHANGE COLUMN
          ALTER TABLE MODIFY COLUMN
      

      Like CREATE TABLE IF NOT EXISTS, and similar existing commands,
      the ALTER TABLE ... IF [NOT] EXISTS will return warnings instead of errors
      if the modified object (column, index or partition) already exists (doesn't exist yet).
      If the ALTER TABLE command consists of multiple operations, it's not interrupted in the IF [NOT] EXISTS case, but succeedes with the appropriate
      amount of warnings.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              ratzpo Rasmus Johansson added a comment -

              (Mdcallag - 2012-06-04 23:51:43)
              This feature will make online schema change easier to do for large sharded deployments

              Show
              ratzpo Rasmus Johansson added a comment - (Mdcallag - 2012-06-04 23:51:43) This feature will make online schema change easier to do for large sharded deployments
              Hide
              ratzpo Rasmus Johansson added a comment -

              As a first part create a detailed implementation description/specification and a rough estimate. Let's then ask for feedback on that before starting implementation.

              Show
              ratzpo Rasmus Johansson added a comment - As a first part create a detailed implementation description/specification and a rough estimate. Let's then ask for feedback on that before starting implementation.
              Hide
              ratzpo Rasmus Johansson added a comment -

              This feature is wanted for both 5.3 and 5.5. Added fix versions accordingly.

              Show
              ratzpo Rasmus Johansson added a comment - This feature is wanted for both 5.3 and 5.5. Added fix versions accordingly.
              Show
              holyfoot Alexey Botchkov added a comment - Patch for this task: http://lists.askmonty.org/pipermail/commits/2012-July/003510.html
              Hide
              holyfoot Alexey Botchkov added a comment -

              Pushed into the 10-hf.

              Show
              holyfoot Alexey Botchkov added a comment - Pushed into the 10-hf.

                People

                • Assignee:
                  holyfoot Alexey Botchkov
                  Reporter:
                  ratzpo Rasmus Johansson
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Due:
                    Created:
                    Updated:
                    Resolved:

                    Time Tracking

                    Estimated:
                    Original Estimate - 1 week Original Estimate - 1 week
                    1w
                    Remaining:
                    Remaining Estimate - 0 minutes
                    0m
                    Logged:
                    Time Spent - 1 week, 4 days, 1 hour, 15 minutes
                    1w 4d 1h 15m