I'm working on trying to optimize a View SQL query and I noticed that the query being executed is using a join on a the entity_id field of a field table. I noticed that for some reason unbeknownst to me the entity_id field is not a primary key. The delta field is a primary key.

Can anyone enlighten me as to why this is the case? Can I safely tag entity_id as a primary key without incurring a wrath of unintended consequences? Thank you for your help.

The field tables store the usages of that field for all entities that use that field. In other words, nodes and users could both have the same field on them. In this case, a particular field could be on both nodes and users. In this case, the entity ID may not be unique.