We have encountered rather weird behavior which is very hard to reproduce. When inserting specific strings that resemble scientific notation into a varchar column, it would be inserted as 65 of 9 which would indicate an overflow, meaning, that our string is randomly being inserted as a decimal which is way too big. Another weird part of this is that even with a same string, behavior varies. Most of the time, it would be inserted properly, yet on some occasions the very same string would be inserted as 99999999999999999999999999999999999999999999999999999999999999999
.
Example of incorrectly inserted values
4840e430eac9f22a5e8609a1c95faaeb8c921f66e24e55cf839a00eb35790c00
2e540795-afe5-4644-a3d0-2aaae007c76e
Table create code:
CREATE TABLE `table1` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`UUID` CHAR(36) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`irrelevantColumn` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`columnName` VARCHAR(510) NOT NULL COLLATE 'utf8mb4_unicode_ci',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UUID_irrelevantColumn_UNIQUE` (`UUID`, `irrelevantColumn`) USING BTREE,
INDEX `table1_uuid_index` (`UUID`) USING BTREE,
INDEX `table1_attributename_index` (`attributeName`) USING BTREE,
CONSTRAINT `table1_uuid_foreign` FOREIGN KEY (`UUID`) REFERENCES `table2` (`uuid`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=123456
;
We have determined the issue likely to be on the side of MySQL, rather than Laravel or ProxySQL, as query being sent to MySQL is like this (according to query logs produced by Laravel and ProxySQL). Below is an example of a query from taken directly from said log.
insert into `table1` (`irrelevantColumn`, `columnName`, `UUID`)
values (
'someString',
'4840e430eac9f22a5e8609a1c95faaeb8c921f66e24e55cf839a00eb35790c00',
'2e540795-afe5-4644-a3d0-2aaae007c76e'
)
We would like to determine what causes this behavior and how it can be prevented.
Stack used:
- Laravel 11 + Octane (strict mode enabled in the config)
- ProxySQL 2.7.1
- AWS RDS MySQL version: 8.0.35, Engine being used is InnoDB
Laravel starts a session with the following parameters
SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci', time_zone='+00:00', SESSION sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'