Running vtexplain, Vitess complains that the table does not have a primary key:
$ vtexplain -schema-file schema.sql -vschema-file vschema.json -shards 2 -sql 'insert into bar (c1) values (1);'
W1219 16:54:05.261187 63356 dml.go:361] no primary key for table bar
----------------------------------------------------------------------
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
Note the dml.go error.
However, if we change the schema to have the traditional primary key syntax:
$ 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:
Scenario:
Problem:
1 ks1/-80: begin 1 ks1/-80: insert into bar(c1) values (1) / vtgate:: keyspace_id:166b40b44aba4bd6 / 1 ks1/-80: commit
$ cat schema.sql create table bar( c1 bigint not null, PRIMARY KEY (c1)) engine=innodb;
$ 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
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)