opencart网,magento数据库结构
2022-10-31 11:08:20 - 米境通

magento数据结构首先要知道是EAV模式,这种结构要比普通数据结构更容易扩展,但是带来的就是查询速度慢,好在magento开发的缓存机制不错
最重要的3张表eav_entity_type,eav_entity_attribute,eav_attribute
eav_entity_type表用来定义实体的基本信息
比如entity_type_id=1是customer实体
eav_entity_attribute表用来定义实体模型包含哪些属性(当然这里还涉及到set和group)
select*fromeav_entity_attributewhereentity_type_id=1;取出customer有哪些属性
eav_attribute属性的信息
select*fromeav_attributewhereattribute_id<=上面结果范围andattribute_id>上面结果范围;取出customer的属性定义
看看magento中是怎样使用EAV模式的,还是拿customer
customer_entity用户的实体存放,当然里面也有是没有必用分开的属性,比如email,这是用户必须的,magento没有完全分开,可能也是考虑到速度
customer_entity_varchar
customer_entity_text
customer_entity_int
customer_entity_decimal
customer_entity_datetime
这几张表是实体对应的属性的值,属性值都有不同的类型,这样分开是有必要的
SELECT'cev'.*,'ea'.attribute_codeFROMcustomer_entity_varcharAS'cev'LEFTJOIN'eav_attribute'AS'ea'ON'ea'.attribute_id='cev'.attribute_idWHERE'cev'.entity_id='2';取出客户id为2的在customer_entity_varchar中的属性值
magento不仅提供了EAV模式,同时在数据库中完美支持了Flat表结构,flat和我们普通的表结构,一个产品对应一行数据,相对于EAV的多表联查来说,单表单行数据的调用效率更高,magento默认是eav模式,可以在后台开启flat(就分类和产品用到)
catalog_product_flat_1
catalog_product_flat_2
后面数字代表storeId,刷新索引的时候会重新更新这些表数据
order表结构
sales_flat_order相关,表命名中带了flat,表示order不使用eav模式。
相关问答: