magento 使用flat 表

来源:互联网 发布:手机晒密软件 编辑:程序博客网 时间:2024/04/25 07:55

转载地址:http://inchoo.net/ecommerce/magento/flat-tables-in-magento-and-product-collection/

1.按照下面的步骤操作完成
2 system-->index  manager
然后查询使用的flat表,对于大数据量,对flat表进行索引,然后
您就可以进行快速的查询,解决eav模型带来的低级速度问题。


Flat tables in Magento and product collection

Featured Image

You probaly know that Magento uses EAV database structure for categories, products. In some cases this solution is not the best or fastest.

I will get you here example how to speed up product collection. Magento has config option: “Use Flat Catalog Product”. In order to see this option, go to Magento admin section and click on: System -> Config -> Catalog and Frontend.

If you enable this option, you will adjust Magento to use “Flat resource” for product collection. Take a look at product collection class “Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection” you will see a method “_construct“.

1
2
3
4
5
6
7
8
9
10
protectedfunction _construct()
{
    if($this->isEnabledFlat()) {
        $this->_init('catalog/product','catalog/product_flat');
    }
    else{
        $this->_init('catalog/product');
    }
    $this->_initTables();
}

If flat is enabled in Magento admin section, collection will use resource: ‘catalog/product_flat’, php class “Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat
without EAV database structure. SQL queries will be simplier, faster and you would need to have better performance on product listing.
In this Flat resource there is method:

1
2
3
publicfunction getMainTable() {
        return$this->getFlatTableName($this->getStoreId());
}

This method returns flat table name and it depends about current store. Flat table name for store_id “1″ is “catalog_product_flat_1“, below you can see method which is in charge for giving current table name.

1
2
3
4
5
6
7
publicfunction getFlatTableName($store= null)
{
    if(is_null($store)) {
        $store= $this->getStoreId();
    }
    return$this->getTable('catalog/product_flat') . '_'. $store;
}

For every store you will have one flat table.

0 0
原创粉丝点击