A perfect example of teams or individual developers not talking to one another. While the main eav_attribute
table's atrtibute_code
is a varchar(255)
, this code value is often used in other tables.
In catalog_product_link_attribute
there's a product_link_attribute_code
attribute (which is the attribute code), and this column is a varchar(32)
. Back in prehistoric times when the sales objects were EAV objects, they had an attribute_code column which had varchar(50)
as a length.
# Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.45-0.9.46.php
$installer->getConnection()->addColumn($this->getTable('sales_order'), $attribute['attribute_code'], 'varchar(50) NULL');
I imagine there's others as well.
Without an actual specification or agreement on what was being built, the developer in charge of the UI for the attribute section likely looked at all the attribute_code
columns, picked the shortest one, and enforced a length to make sure users couldn't create an attribute code that would be too long for one of the various tables other developers were working on.
As for why a developer would choose a varchar
length that wasn't 255
— there's a school of thought about database design that says you only make your columns as long as they need to be to save disk space, reduce RAM, be more efficient in join operations, etc. Some developers still hold to this vs. the modern trend of "make it as large as possible and worry about performance implications later". It's clear there was disagreement on the maximum length of a varchar
for attribute_code
's among the Magento core team at one point, and now it lives on in legacy code.