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

Table schema stores unnormalized expression for default values, which leads to unexpected behaviors. #8190

Closed
nicktobey opened this issue Aug 1, 2024 · 0 comments · Fixed by dolthub/go-mysql-server#2629

Comments

@nicktobey
Copy link
Contributor

nicktobey commented Aug 1, 2024

When creating a table with default values, we store the default value expression as a string in the table schema.

So for example, CREATE TABLE foo (f float default '1.0'); stores the string '1.0' in the table schema.

However, SHOW CREATE TABLE normalizes these values before displaying them, so SHOW CREATE TABLE foo; produces the following output:

+-------+------------------------------------------------------------------+
| Table | Create Table                                                     |
+-------+------------------------------------------------------------------+
| foo   | CREATE TABLE `foo` (                                             |
|       |   `f` float DEFAULT '1'                                          |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin |
+-------+------------------------------------------------------------------+

This leads to several unexpected results, primarily occurring if the table is dropped and recreated with the generated CREATE TABLE statement.

  • dolt status shows that the table has been modified, but dolt diff does not show any differences:
% dolt status
On branch merge

Changes not staged for commit:
  (use "dolt add <table>" to update what will be committed)
  (use "dolt checkout <table>" to discard changes in working directory)
	modified:         foo
% dolt diff
diff --dolt a/foo b/foo
--- a/foo
+++ b/foo
%
  • The two versions of the table schema have different hashes, which means that they are considered different for the purposes of merging. This may lead to unresolvable merge conflicts.

I don't see any benefit to storing these default values in an unnormalized state. This is especially true if we normalize them before displaying them to the user, since it makes it nearly impossible for the user to tell how the two schemas differ.

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

Successfully merging a pull request may close this issue.

1 participant