Bug #119807 Generated default values bypass BLOB/TEXT/JSON default value restriction
Submitted: 29 Jan 9:05 Modified: 29 Jan 12:20
Reporter: huanlong wang Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:8.0.34 OS:Any
Assigned to: CPU Architecture:Any

[29 Jan 9:05] huanlong wang
Description:
The check for default values on BLOB/TEXT/JSON columns only applies to constant defaults, not expression defaults, allowing bypass of the restriction.

How to repeat:
1. Connect to MySQL 8.0.34
2. Run:
   CREATE TABLE t1 (a TEXT DEFAULT '');  -- Fails (good)
   CREATE TABLE t2 (a TEXT DEFAULT (concat('', '')));  -- Succeeds (bug!)

Expected Result:
All statements should fail with ERROR 1101.

Actual Result:
Only constant defaults are caught; expression defaults bypass the check.

Suggested fix:
Analysis:
In Create_field::init(), the check only tests fld_default_value but not fld_default_val_expr. This creates an inconsistency.

Suggested Fix:
Extend the check to cover both default value types.
[29 Jan 12:20] MySQL Verification Team
Please see this section of the manual:

https://dev.mysql.com/doc/refman/8.4/en/data-type-defaults.html
 The BLOB, TEXT, GEOMETRY, and JSON data types can be assigned a default value only if the value is written as an expression, even if the expression value is a literal:

    This is permitted (literal default specified as expression):

    CREATE TABLE t2 (b BLOB DEFAULT ('abc'));

    This produces an error (literal default not specified as expression):

    CREATE TABLE t2 (b BLOB DEFAULT 'abc');

Expression default values must adhere to the following rules. An error occurs if an expression contains disallowed constructs.