dolthub / dolt

Dolt – Git for Data
https://www.dolthub.com
Apache License 2.0
18k stars 516 forks source link

A failed create table still creates a table but of a different specification #3024

Open timsehn opened 2 years ago

timsehn commented 2 years ago
test-busteroni $ dolt sql
# Welcome to the DoltSQL shell.
# Statements must be terminated with ';'.
# "exit" or "quit" (or Ctrl-D) to exit.
test_busteroni> CREATE DATABASE test;
test_busteroni> CREATE TABLE IF NOT EXISTS restaurants (
             ->     id INT PRIMARY KEY,
             ->     coordinate POINT
             -> );
test_busteroni> CREATE TABLE IF NOT EXISTS hours (
             ->     restaurant_id INT PRIMARY KEY AUTO_INCREMENT,
             ->     FOREIGN KEY (restaurant_id) REFERENCES restaurants(id)
             -> );
cannot create an index over spatial type columns
test_busteroni> show tables;
+-------------+
| Table       |
+-------------+
| hours       |
| restaurants |
+-------------+
test_busteroni> show create table hours
             -> ;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                  |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
| hours | CREATE TABLE `hours` (
  `restaurant_id` int NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`restaurant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+

When piped in as a SQL statement the table is not created as in #3023.

zachmu commented 2 years ago

This happens because we create the table, then add foreign keys after it exists. The same is true for other table features (checks).

To fix this, we need to define additional interfaces that make table creation with all supported features atomic.

The same issue almost certainly applies to ALTER TABLE statements with more than one clause.