1

During extension development, we've used the following method to add columns to the sales order grid in Magento 2

  1. Add custom table to installation
  2. Add sales_order_grid.xml to add new columns config
  3. Use plugin on the CollectionFactory -> aroundGetReport, inside which we use join on our custom table

    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <plugin
            name="sales_order_shipperhq_columns"
            type="Company\Module\Plugin\Order\CollectionFactory"
            sortOrder="100"
            disabled="false"
    />
    

    $result = $proceed($requestName);
    if ($requestName == 'sales_order_grid_data_source') {
        if ($result instanceof \Magento\Sales\Model\ResourceModel\Order\Grid\Collection) {
            $select = $result->getSelect();
            $select->joinLeft(
                ['our_order_table' => $this->_resource->getTableName('custom_sales_order_grid')],
                'entity_id' . '=our_order_table.' . 'order_id' ,
                []
            );
    
        }
    } 
    

We are seeing severe performance impacts on loading the sales order grid when these additional columns are in place on a "live store" with a modest number of orders.

I'm looking for some advice on how best to add these columns without impacting performance. We also want to avoid extending the core Magento tables: this would aid performance but breaks compatibility with Enterprise split database architecture.

0

We found some performance improvements by

  • Indexing against the order_id column in our custom table 'custom_sales_order_grid'
  • Reducing the column size of the order_id field in our custom table

These changes improved performance.

We still see a slower load time with our custom table join than without, and we don't see any Magento specific changes available, as far as we can tell, to improve this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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