Skip to content
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

MigrationFromOTRS: explain why some columns are shortened to 190 chars #542

Closed
bschmalhofer opened this issue Oct 13, 2020 · 3 comments
Closed
Labels
enhancement New feature or request
Milestone

Comments

@bschmalhofer
Copy link
Contributor

In Kernel/System/MigrateFromOTRS/CloneDB/Driver/Base.pm there is the following dubious code:

            COLUMNVALUES:
            for my $ColumnCounter ( 1 .. $#OTRSColumns ) {
                my $Column = $OTRSColumns[$ColumnCounter];

                # Check if we need to cut the string, cause utf8mb4 only needs 191 chars.
                if ( $ShortenColumn{$Column} ) {
                    if ( $Row[$ColumnCounter] && length( $Row[$ColumnCounter] ) > 190 ) {
                        $Row[$ColumnCounter] = substr( $Row[$ColumnCounter], 0, 190 );
                    }
                }
            }

It is not obvious where the constant value of 190 characters is coming from. The suspicion is that either this value should be depend on the actual database table. At least it should be properly explained.

@bschmalhofer bschmalhofer added the enhancement New feature or request label Oct 13, 2020
@bschmalhofer bschmalhofer added this to the OTOBO 10.0.5 milestone Oct 13, 2020
@svenoe
Copy link
Contributor

svenoe commented Oct 14, 2020

The explanation is this, if I understand correctly: "# Check if we need to cut the string, cause utf8mb4 only needs 191 chars." (Though "needs" is not the right word.)

I forgot for which column types this exactly applies and when, but as we switched from utf8 to utf8mb4, the maximum size in some places has shrunken down from 255 to 191 (is it only CHAR?).

@bschmalhofer
Copy link
Contributor Author

bschmalhofer commented Oct 16, 2020

@StefanRother-OTOBO explained where the 190 chars come from:

Bei utf8mb4 belegt jedes Zeichen eines Varchar Feldes 4 bytes. Innodb hat ein Limit von 767 bytes für Keys, welches nicht überschritten werden darf.
Wir müssen also die Länge der Felder username und email auf 767 / 4 Zeichen verringern, was nach Rundung 191 Zeichen entspricht.

This explanation should be added as code comment as well. See also https://dev.mysql.com/doc/refman/5.6/en/innodb-limits.html and https://dev.mysql.com/doc/refman/5.7/en/innodb-limits.html

bschmalhofer added a commit that referenced this issue Oct 16, 2020
Try to make the logic more efficient, do less work
bschmalhofer added a commit that referenced this issue Oct 16, 2020
Just to reduce the diffs when merging
@bschmalhofer bschmalhofer changed the title MigrationFromOTRS: eliminate hardcoded column length of 190 chars MigrationFromOTRS: explain why some columns are shortened to 190 chars Oct 16, 2020
bschmalhofer added a commit that referenced this issue Oct 16, 2020
@bschmalhofer
Copy link
Contributor Author

The code comments have been enhanced. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants