Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online DDL: explicitly reject FOREIGN KEY DDLs #8055

Closed
shlomi-noach opened this issue May 6, 2021 · 7 comments
Closed

Online DDL: explicitly reject FOREIGN KEY DDLs #8055

shlomi-noach opened this issue May 6, 2021 · 7 comments

Comments

@shlomi-noach
Copy link
Contributor

shlomi-noach commented May 6, 2021

Online DDL does not support FOREIGN KEYs at this time, and this is documented.

Right now a schema migration that has a FOREIGN KEY clause fails with an obscure parsing error. e.g.:

mysql> set @@ddl_strategy='online';
Query OK, 0 rows affected (0.00 sec)

mysql> alter table corder add FOREIGN KEY my_fk(customer_id) references customer(customer_id);
+--------------------------------------+
| uuid                                 |
+--------------------------------------+
| a8c5cd57_ae2d_11eb_9dfd_0a43f95f28a3 |
+--------------------------------------+

show vitess_migrations \G
*************************** 1. row ***************************
                 id: 1
     migration_uuid: a8c5cd57_ae2d_11eb_9dfd_0a43f95f28a3
           keyspace: commerce
              shard: 0
       mysql_schema: vt_commerce
        mysql_table: corder
migration_statement: alter table corder
           strategy: online
            options: -skip-topo
    added_timestamp: 2021-05-06 05:41:09
requested_timestamp: 2021-05-06 05:41:09
    ready_timestamp: 2021-05-06 05:41:10
  started_timestamp: 2021-05-06 05:41:10
 liveness_timestamp: 2021-05-06 05:41:10
completed_timestamp: NULL
  cleanup_timestamp: NULL
   migration_status: failed
           log_path: 
          artifacts: 
            retries: 0
             tablet: zone1-0000000100
     tablet_failure: 0
           progress: 0
  migration_context: vtgate:78e4ef9d-ae2d-11eb-9dfd-0a43f95f28a3
         ddl_action: alter
            message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table corder' at line 1 (errno 1064) (sqlstate 42000) during query: ALTER TABLE `_a8c5cd57_ae2d_11eb_9dfd_0a43f95f28a3_20210506054110_vrepl` alter table corder
        eta_seconds: -1

We should do better analysis of the query/schema to determine that it contains FOREIGN KEY constraints and clearly indicate these are not supported.

@shlomi-noach
Copy link
Contributor Author

Our parsing for FOREIGN KEYs do not take into account the optional index name. Thus, we are able to parse:

alter table corder add FOREIGN KEY (customer_id) references customer(customer_id);

But are unable to parse the following valid MySQL statement:

alter table corder add FOREIGN KEY my_fk (customer_id) references customer(customer_id);

The 2nd query creates, in addition to the foreign key, an index called my_fk on the FK columns.

@shlomi-noach
Copy link
Contributor Author

There's two aspects to this problem. One is the specific parsing limitation mentioned above (work in progress), and the other is #8057

@shlomi-noach
Copy link
Contributor Author

Fixed by #8058 and #8094

@harshit-gangal
Copy link
Member

For online-ddl you should disable partialDDL

@shlomi-noach
Copy link
Contributor Author

For online-ddl you should disable partialDDL

Not sure I understand?

@harshit-gangal
Copy link
Member

If you disable partialDDL then any DDL which the parser does not understand completely will fail and this will make parser output reliable to be used to manipulating or verifying those DDLs

@shlomi-noach
Copy link
Contributor Author

I can't find how to disable partialDDL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants