-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[MDEV-31414] Implement optional lengths for string types #4551
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
Open
OsamaNabih
wants to merge
13
commits into
MariaDB:main
Choose a base branch
from
OsamaNabih:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+224
−6
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2c01f57
Allow VARCHAR without length to default to a length of 65,535
OsamaNabih f3acea3
Change default VARCHAR size to 16383
OsamaNabih f7889f7
Define MAX_VARCHAR_ESTIMATED_SIZE with value 16383
OsamaNabih d41ca1e
Revert "Define MAX_VARCHAR_ESTIMATED_SIZE with value 16383"
OsamaNabih 893d343
Calculate default VARCHAR max len based on Column charset, fallback t…
OsamaNabih 9ba9be4
Add nullptr check for def->charset
OsamaNabih 0379e9e
Add initial test for CREATE TABLE statement with VARCHAR column witho…
OsamaNabih a34ec7a
Add test case for different column charsets
OsamaNabih 7a305d4
MDEV-31414 Implement optional lengths for string types
OsamaNabih 018dbda
MDEV-31414 Implement optional lengths for string types
OsamaNabih fa3c28f
MDEV-31414 Implement optional lengths for string types
OsamaNabih 86dcf32
MDEV-31414 Implement optional lengths for string types
OsamaNabih 19e2c5c
MDEV-31414 Implement optional lengths for string types
OsamaNabih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Use default conf to set collation and charset | ||
| !include include/default_my.cnf | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # | ||
| # SQL Standard T081: VARCHAR without explicit length specification | ||
| # | ||
| # | ||
| # Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) | ||
| # | ||
| CREATE TABLE t1 (a VARCHAR); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(16383) DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| # | ||
| # Basic test: CREATE TABLE with charset (scenario 1b) | ||
| # | ||
| CREATE TABLE t1 (a VARCHAR CHARSET latin1); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| # | ||
| # Test VARCHAR without length with specific column charsets or collations (scenario 2a) | ||
| # | ||
| CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(16383) DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(16383) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR CHARSET latin1); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| # | ||
| # Test VARCHAR without length with specific column charsets and collations (scenario 2b) | ||
| # | ||
| CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(16383) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
|
|
||
| # | ||
| # Basic test: CREATE TABLE with charset (Scenario 3) | ||
| # | ||
| CREATE TABLE t1 (a VARCHAR) CHARSET latin1; | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `a` varchar(65532) DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | ||
| DROP TABLE t1; | ||
|
|
||
| # | ||
| # Test ALTER TABLE MODIFY COLUMN with VARCHAR without length | ||
| # | ||
| CREATE TABLE t1 (id VARCHAR(1)); | ||
| ALTER TABLE t1 MODIFY id VARCHAR; | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `id` varchar(16383) DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # | ||
| # MDEV-31414 | ||
| # Test for SQL Standard T081: "Optional string types maximum length" | ||
| # This tests the feature that allows VARCHAR columns to be created without | ||
| # specifying a length, defaulting to the maximum VARCHAR length (65535) | ||
| # | ||
| # We have 3 scenarios for resolving charset and collation | ||
| # 1. Empty | ||
| # 2. Precisely Typed | ||
| # 3. Contextually typed | ||
| # | ||
| # Check the comment section in "lex_charset.cc" at | ||
| # CHARSET_INFO *Lex_exact_charset_extended_collation_attrs_st:: | ||
| # resolved_to_character_set | ||
|
|
||
| --echo # | ||
| --echo # SQL Standard T081: VARCHAR without explicit length specification | ||
| --echo # | ||
|
|
||
| --echo # | ||
| --echo # Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| --echo # | ||
| --echo # Basic test: CREATE TABLE with charset (scenario 1b) | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR CHARSET latin1); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| --echo # | ||
| --echo # Test VARCHAR without length with specific column charsets or collations (scenario 2a) | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| CREATE TABLE t1 (a VARCHAR CHARSET latin1); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| --echo # | ||
| --echo # Test VARCHAR without length with specific column charsets and collations (scenario 2b) | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| --echo # | ||
| --echo # Basic test: CREATE TABLE with charset (Scenario 3) | ||
| --echo # | ||
| CREATE TABLE t1 (a VARCHAR) CHARSET latin1; | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo | ||
| --echo # | ||
| --echo # Test ALTER TABLE MODIFY COLUMN with VARCHAR without length | ||
| --echo # | ||
| CREATE TABLE t1 (id VARCHAR(1)); | ||
| ALTER TABLE t1 MODIFY id VARCHAR; | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2862,8 +2862,14 @@ Type_handler_varchar::Column_definition_set_attributes( | |
| } | ||
| break; | ||
| case COLUMN_DEFINITION_ROUTINE_LOCAL: | ||
| case COLUMN_DEFINITION_TABLE_FIELD: | ||
| break; | ||
| case COLUMN_DEFINITION_TABLE_FIELD: | ||
| /* | ||
| Support SQL Standard T081: "Optional string types maximum length" | ||
| Allows users to specify VARCHAR fields without a length | ||
| In this case, has_explicit_length is false. | ||
| */ | ||
| return false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is likely correct though. |
||
| } | ||
| thd->parse_error(); | ||
| return true; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a junk config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only used it to set a default charset/collation to have consistency for the tests.
If the default charset/collation changes in the future, this may cause this test to fail, even when the logic is still correct (maybe it's better to have it fail and the dev should verify anyway?).
Also, I wasn't sure if the server's choice for the default charset changes based on the machine settings (such as language), in that case the test my fail for other machines, so I thought having it set in the .opt is better.
What do you think?