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

Schema of "Create table t SELECT * FROM tbl" drops default values when compared to MySql #6016

Closed
nicktobey opened this issue May 4, 2023 · 2 comments · Fixed by dolthub/go-mysql-server#2465
Assignees
Labels
bug Something isn't working correctness We don't return the same result as MySQL sql Issue with SQL

Comments

@nicktobey
Copy link
Contributor

nicktobey commented May 4, 2023

Example repro:

CREATE TABLE source (
    v1 INT PRIMARY KEY AUTO_INCREMENT,
    v2 INT DEFAULT 1,
    v3 INT 
);
CREATE TABLE dest SELECT * FROM source;
SHOW CREATE TABLE dest;

MySql output:

Table | Create Table
dest | CREATE TABLE `dest` (   `v1` int(11) NOT NULL DEFAULT '0',   `v2` int(11) DEFAULT '1',   `v3` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8

Dolt output:

+-------+------------------------------------------------------------------+
| Table | Create Table                                                     |
+-------+------------------------------------------------------------------+
| dest  | CREATE TABLE `dest` (                                            |
|       |   `v1` int NOT NULL,                                             |
|       |   `v2` int,                                                      |
|       |   `v3` int                                                       |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin |
+-------+------------------------------------------------------------------+
@nicktobey
Copy link
Contributor Author

Note that MySql both preserves default values from the original table when present, and creates new ones when not present. We do neither.

@nicktobey
Copy link
Contributor Author

nicktobey commented May 4, 2023

I believe that the original default value isn't being preserved because we generate a plan that looks like this:

+------------------------------------------+
| plan                                     |
+------------------------------------------+
| TableCopier                              |
|  ├─ Source: Project                      |
|  |  ├─ Child: ResolvedTable              |
|  |  └─ Projection: StarExpression        |
|  └─ Destination: CreateTable             |
+------------------------------------------+

the CreateTable node is assigned the Schema of the Project node, but the schema of the Project node doesn't reflect the defaultness of the underlying table. (I'm not sure whether that's a bug or intended behavior.)

@timsehn timsehn transferred this issue from dolthub/go-mysql-server May 24, 2023
@timsehn timsehn added bug Something isn't working sql Issue with SQL labels May 24, 2023
@timsehn timsehn added the correctness We don't return the same result as MySQL label Jul 7, 2023
@timsehn timsehn changed the title Schema of "SELECT * FROM tbl" drops default values when compared to MySql Schema of "Create table t SELECT * FROM tbl" drops default values when compared to MySql Apr 15, 2024
@jycor jycor self-assigned this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctness We don't return the same result as MySQL sql Issue with SQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants