vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.62k stars 2.1k forks source link

Vitess DDL processing does not seem to understand per-column primary key syntax #5600

Closed aquarapid closed 3 years ago

aquarapid commented 4 years ago

Scenario:

Problem:

1 ks1/-80: begin 1 ks1/-80: insert into bar(c1) values (1) / vtgate:: keyspace_id:166b40b44aba4bd6 / 1 ks1/-80: commit


  Note the dml.go error.

However, if we change the schema to have the traditional primary key syntax:

$ cat schema.sql create table bar( c1 bigint not null, PRIMARY KEY (c1)) engine=innodb;


then vtexplain works fine:

$ vtexplain -schema-file schema.sql -vschema-file vschema.json -shards 2 -sql 'insert into bar (c1) values (1);'

insert into bar (c1) values (1)

1 ks1/-80: begin 1 ks1/-80: insert into bar(c1) values (1) / vtgate:: keyspace_id:166b40b44aba4bd6 / 1 ks1/-80: commit



So the per-column primary key syntax seems to not work as expected, although using it with vtgate/mysqld results in the same table, as per show create table:

mysql> create table bar( c1 bigint not null PRIMARY KEY) engine=innodb; Query OK, 0 rows affected (0.11 sec)

mysql> show create table bar\G 1. row Table: bar Create Table: CREATE TABLE bar ( c1 bigint(20) NOT NULL, PRIMARY KEY (c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci 1 row in set (0.01 sec)

mysql> drop table bar; Query OK, 0 rows affected (0.05 sec)

mysql> create table bar( c1 bigint not null, PRIMARY KEY (c1)) engine=innodb; Query OK, 0 rows affected (0.11 sec)

mysql> show create table bar\G 1. row Table: bar Create Table: CREATE TABLE bar ( c1 bigint(20) NOT NULL, PRIMARY KEY (c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci 1 row in set (0.00 sec)

aquarapid commented 3 years ago

This seems to work in vtexplain with Vitess 9.0 (daa6085). Closing.