Bug #120055 UNIQUE constraint causes Segmentation Fault during dumpInstance
Submitted: 13 Mar 17:58 Modified: 15 Mar 11:01
Reporter: Duke Lee Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Shell Dump & Load Severity:S2 (Serious)
Version:8.0.45 OS:Ubuntu (22.04)
Assigned to: CPU Architecture:x86

[13 Mar 17:58] Duke Lee
Description:
If a table contains a UNIQUE constraint that contains a mix of functional and non-functional parts where any non-functional part is declared after any functional part, dumpInstance will segfault.

I've marked the severity of this bug as S2 because there are no error messages aside from the segfault, which makes tracking down the source of the error difficult and will likely break people's production processes.

How to repeat:
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE test (
    test_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    col1    CHAR(1),
    col2    CHAR(1),
    col3    CHAR(1),
    UNIQUE ((UPPER(col1)), col2)
);

mysqlsh -- util dumpInstance ./dump --includeSchemas=testdb --includeTables=testdb.test

Acquiring global read lock
Global read lock acquired
Initializing - done 
Segmentation fault (core dumped)

The following example UNIQUE patterns will result in a segfault:

UNIQUE ((UPPER(col1)), col2)
UNIQUE (col1, (UPPER(col2)), col3)
UNIQUE ((UPPER(col1)), (UPPER(col2)), col3)

Note that these examples show a non-functional key part after a functional key part, which seems to be the cause of the segfault.

The following example UNIQUE patterns will NOT result in a segfault:

UNIQUE (col1, (UPPER(col2)))
UNIQUE (col1, col2, (UPPER(col3)))
UNIQUE (col1, (UPPER(col2)), (UPPER(col3)))

A hacky workaround exists that requires all trailing non-functional key parts to be wrapped inside an identity-returning function, like COALESCE, which makes that key part functional and should retain uniqueness logic. For example:

UNIQUE(col1, (CONCAT(col1, col2)), (COALESCE(col3)))
[15 Mar 11:01] MySQL Verification Team
Thanks for the report.  I repeated crash on 8.4.0 shell.

This is no longer repeatable in 9.6.0 which is the current recommended version:
https://www.mysql.com/support/supportedplatforms/compatibility.html