Bug #117899 Feature Request: Type-Hinted Dynamic Columns for Flexible Data Storage
Submitted: 7 Apr 8:28 Modified: 8 Apr 6:43
Reporter: Reza Rezaei Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Data Types Severity:S4 (Feature request)
Version:All MySQL versions, 8.x, 9.x OS:Any
Assigned to: CPU Architecture:Any
Tags: data-types, dynamic-types, feature-request, flexibility

[7 Apr 8:28] Reza Rezaei
Description:
I propose introducing 'type-hinted' dynamic columns in MySQL to enhance flexibility and support diverse data structures within a single column, while maintaining explicit type management.

Use Case:

Configuration tables, data logging, and other scenarios often require storing values of varying types (strings, integers, booleans, JSON, etc.). Currently, we must resort to storing all values as strings, using JSON columns (for structured data), or implementing complex type conversion logic in the application layer.

Proposed Solution:

Introduce a new column type, TYPE_HINTED_DYNAMIC, which requires explicit type specification during data insertion.

Syntax:

SQL

CREATE TABLE dynamic_table (
    `id` INT PRIMARY KEY AUTO_INCREMENT,
    `dynamic_value` TYPE_HINTED_DYNAMIC
);

INSERT INTO dynamic_table (`dynamic_value`) VALUES
    (TYPE_HINTED_DYNAMIC('string', 'Hello')),
    (TYPE_HINTED_DYNAMIC('integer', 123)),
    (TYPE_HINTED_DYNAMIC('boolean', TRUE)),
    (TYPE_HINTED_DYNAMIC('json', '{"key": "value"}'));
Retrieval:

When retrieving data, the type information would be included, allowing the application to handle the value appropriately.

Benefits:

Explicit Type Management: Users retain control over data types, reducing the risk of unexpected type conversions.
Flexibility: Supports diverse data types within a single column.
Simplified Application Logic: Eliminates the need for complex type conversion logic in the application layer.
Potential Performance Improvements: Allows MySQL to optimize storage and retrieval based on the specified type.
Considerations:

Potential performance overhead for type checking during insertion.
Implementation complexity within the MySQL engine.
Compatibility with the SQL standard.
Example Use Case (Configuration Table):

SQL

CREATE TABLE configs (
    `key` VARCHAR(255) PRIMARY KEY,
    `value` TYPE_HINTED_DYNAMIC
);

INSERT INTO configs (`key`, `value`) VALUES
    ('schedule_enabled', TYPE_HINTED_DYNAMIC('boolean', TRUE)),
    ('price_decrement', TYPE_HINTED_DYNAMIC('decimal', 0.05)),
    ('api_keys', TYPE_HINTED_DYNAMIC('json', '["key1", "key2"]'));
This approach provides a more controlled and efficient way to handle dynamic data types in MySQL. I believe it would be a valuable addition to the database's capabilities.

Notification Request:

I would greatly appreciate it if you could notify me via email at merezarezaei@gmail.com if this feature request is considered for implementation or if there are any updates regarding its status. I am very curious about the potential for this feature and would like to stay informed.

Thank you for your time and consideration.

How to repeat:
This is a feature request, not a bug. To demonstrate the potential, create a table with the proposed TYPE_HINTED_DYNAMIC column and attempt to insert values with various data types using the syntax provided.

Suggested fix:
Implement the TYPE_HINTED_DYNAMIC column type, including the necessary syntax and type-checking mechanisms.
[8 Apr 6:43] MySQL Verification Team
Hello Reza Rezaei,

Thank you for the feature request!

regards,
Umesh