Skip to content

MDEV-31414: Implement optional lengths for string types#4551

Open
OsamaNabih wants to merge 1 commit intoMariaDB:mainfrom
OsamaNabih:main
Open

MDEV-31414: Implement optional lengths for string types#4551
OsamaNabih wants to merge 1 commit intoMariaDB:mainfrom
OsamaNabih:main

Conversation

@OsamaNabih
Copy link
Copy Markdown

@OsamaNabih OsamaNabih commented Jan 17, 2026

Jira: https://jira.mariadb.org/browse/MDEV-31414
Adding support for SQL standard 2023's T081: Optional string types maximum length

This PR allows the user to not specify a length for a VARCHAR field. We default to making the field a TEXT type.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 17, 2026

CLA assistant check
All committers have signed the CLA.

@FooBarrior
Copy link
Copy Markdown
Contributor

Hi,

Is 16383 reported as the maximum due to collation choice?

That is a nice guess!

Our documentation claims it's 21,844 characters, though I think it's a bit outdated, since we support 4-byte encodings for some time. So yes, it's got to be UINT16_MAX/4 - header_length, where header_length is something like 3.

Copy link
Copy Markdown
Contributor

@FooBarrior FooBarrior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We follow the TDD paradigm - every feature should be covered with tests (and every bugfix, if possible). Include both .test and .result files in the commit.

I'm fine with a hard constant of 16383 in scope of this small work, we can always extend it and make a function of charset any time we want, since 16383 is expected to be the minimum of the maximums.

Comment thread sql/sql_type.cc Outdated
Comment thread sql/sql_type.cc Outdated
@FooBarrior
Copy link
Copy Markdown
Contributor

FooBarrior commented Jan 17, 2026

You can try to make tha max value variable if you want. Though it may require some research.

The problem is that we have (at least) three layers of charset settings:

  • system-wide
  • per-table
  • per-field

One overrides another. At some point, Filed would get a deduced value of charset, and perhaps Create_field would get it, too. Though it's hard to say, when exactly. Create_field has charset field in its parent Column_definition_attributes, you may check if it's set to the right encoding at different points in time.

You'd have to test all three cases though:

  • When a system-wide encoding is set
  • When it's overriden with table
  • When the latter is overriden with field charset.

Again, I'm NOT putting this as a requirement for this submission!

@github-actions github-actions Bot added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Jan 18, 2026
@OsamaNabih
Copy link
Copy Markdown
Author

OsamaNabih commented Jan 20, 2026

You can try to make tha max value variable if you want. Though it may require some research.

The problem is that we have (at least) three layers of charset settings:

* system-wide

* per-table

* per-field

One overrides another. At some point, Filed would get a deduced value of charset, and perhaps Create_field would get it, too. Though it's hard to say, when exactly. Create_field has charset field in its parent Column_definition_attributes, you may check if it's set to the right encoding at different points in time.

You'd have to test all three cases though:

* When a system-wide encoding is set

* When it's overriden with table

* When the latter is overriden with field charset.

Again, I'm NOT putting this as a requirement for this submission!

That is very informative.
I was mainly focusing on the CREATE TABLE scenario so I only paid attention to the system-wide encoding, but your comment made me realize there are other scenarios where T081 applies as well.
For example ALTER, CAST, CREATE TYPE...etc
For some of these scenarios, we need to handle the situation where the table/field were already created with a different charset than the system-wide one.

To verify my understanding, we are okay with limiting the scope of this PR to the CREATE TABLE scenario?

@OsamaNabih OsamaNabih force-pushed the main branch 2 times, most recently from 17e0e30 to c6e985c Compare January 20, 2026 13:59
@OsamaNabih OsamaNabih closed this Jan 20, 2026
@OsamaNabih OsamaNabih reopened this Jan 20, 2026
@OsamaNabih OsamaNabih force-pushed the main branch 2 times, most recently from fe334ea to 7adad2c Compare January 20, 2026 14:08
Comment thread mysql-test/main/varchar_no_length.cnf Outdated
Comment thread mysql-test/main/varchar_no_length.test Outdated
Comment thread mysql-test/main/varchar_no_length.test Outdated
Comment thread sql/sql_type.cc Outdated
Comment thread sql/sql_type.cc Outdated
@OsamaNabih OsamaNabih force-pushed the main branch 4 times, most recently from b0e32ff to 03b43df Compare February 4, 2026 20:02
@gkodinov gkodinov changed the title [MDEV-31414] Implement optional lengths for string types MDEV-31414: Implement optional lengths for string types Feb 19, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. This is a preliminary review.

Please fix some sanity checks:

  • Make sure this is a single commit and it has a proper commit message, according to CODING_STANDARDS.md.
  • Make sure there's no failing tests as a result of your change. I can see a couple in the buildbot results.

Comment thread mysql-test/main/varchar_no_length.result Outdated
@OsamaNabih OsamaNabih force-pushed the main branch 3 times, most recently from afe53e1 to 87cdc69 Compare February 24, 2026 10:49
Copy link
Copy Markdown
Contributor

@FooBarrior FooBarrior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more details in the commit comments. Mention SQL standard, its rule about implementation-defined lengths and describe our approach.
Remove Signed-off-by.

Comment thread mysql-test/main/varchar_no_length.test Outdated
Comment thread mysql-test/main/varchar_no_length.result Outdated
Comment thread mysql-test/main/varchar_no_length.test Outdated
Comment thread mysql-test/main/varchar_no_length.test Outdated
Comment thread mysql-test/main/varchar_no_length.test Outdated
Comment thread mysql-test/main/varchar_no_length.test Outdated
@OsamaNabih OsamaNabih force-pushed the main branch 4 times, most recently from 0a9f91e to 169b89e Compare March 4, 2026 10:57
Comment thread mysql-test/main/varchar_no_length.test Outdated
Comment thread mysql-test/main/varchar_no_length.test Outdated
Copy link
Copy Markdown
Contributor

@FooBarrior FooBarrior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please go through the test carefully, by yourself. Because I see that my edit requests stay unfulfilled, yet marked as resolved.

Comment thread mysql-test/main/varchar_no_length.test Outdated
Copy link
Copy Markdown
Contributor

@FooBarrior FooBarrior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Support SQL Standard T081 allowing the length to be ommitted
for types VARCHAR, NVARCHAR, and VARBINARY

In case of ommitted length for these types, we dothe following:
VARCHAR, NVARCHAR are mapped to TEXT type
VARBINARY is mapped to BLOB type

This approach provides flexibility to the users
And avoids complications with charsets and future ALTER table operations
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkodinov
Copy link
Copy Markdown
Member

Note that, before being merged, this needs to go through testing. So please, have some more patience.

@gkodinov gkodinov requested a review from elenst April 23, 2026 11:41
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've received the following request from the QA engineer:

Please add tests for other places where the length-less type can be used:

  • local stored procedure/function/trigger variables, via DECLARE
  • stored procedure/function parameters
  • local stored function return type
  • JSON_TABLE
  • dynamic columns
  • virtual columns

Note that the SP test should be done in both Oracle and native mode.

@OsamaNabih
Copy link
Copy Markdown
Author

I've received the following request from the QA engineer:

Please add tests for other places where the length-less type can be used:

  • local stored procedure/function/trigger variables, via DECLARE
  • stored procedure/function parameters
  • local stored function return type
  • JSON_TABLE
  • dynamic columns
  • virtual columns

Note that the SP test should be done in both Oracle and native mode.

I'll start looking into those
Are these required as a part of the scope of this PR or for a future PR?

@gkodinov
Copy link
Copy Markdown
Member

This is what is needed to:

  • document the feature fully
  • test it properly

So, I guess, for this PR. Note that it's about documenting and test coverage for the current behavior. It's not about changing it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

6 participants