Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I'm looking to add indexes the table to it to make lookups faster. If you manually add an index in MySQL, it will disappear at the next Magento "reindexing" event.

share|improve this question

1 Answer 1

This happens here \Mage_Catalog_Model_Resource_Product_Flat_Indexer::prepareFlatTable

The table is built with magentos DDL $table = $adapter->newTable($tableName);

$table->addColumn(...);
$table->addIndex(...);
$table->addForeignKey();
$table->setComment("Catalog Product Flat (Store {$storeId})");
$adapter->createTable($table);

And if you are looking for a nice event, I think catalog_product_flat_rebuild should do

//\Mage_Catalog_Model_Resource_Product_Flat_Indexer::updateEventAttributes
public function updateEventAttributes($storeId = null)
{
    Mage::dispatchEvent('catalog_product_flat_rebuild', array(
        'store_id' => $storeId,
        'table'    => $this->getFlatTableName($storeId)
    ));
}

This method is called in

public function rebuild($store = null)
{
    // ...
    $this->prepareFlatTable($storeId);
    $this->cleanNonWebsiteProducts($storeId);
    $this->updateStaticAttributes($storeId);
    $this->updateEavAttributes($storeId);
    $this->updateEventAttributes($storeId);
    // ...

But I only read code, so please test, whether this works as expected :-)

share|improve this answer
    
What do you think about copying this file to the local folder and editing public function getFlatIndexes and adding my own $this->_indexes['IDX_MYCOLUMN'] = array('type'=>'unique','fields'=>array('my_column'))? –  Buttle Butkus Mar 21 at 6:14
    
I prefer always events, because with the next magento update (and if something was changed) you burn in hell with this approach :-) –  Fabian Blechschmidt Mar 21 at 9:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.