{"id":382556,"date":"2023-05-19T10:06:04","date_gmt":"2023-05-19T10:06:04","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=382556"},"modified":"2023-05-19T10:06:11","modified_gmt":"2023-05-19T10:06:11","slug":"how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/","title":{"rendered":"How to add custom indexer for slow MySQL queries in Magento2"},"content":{"rendered":"\n<p>In this guide, we will learn how we can create custom indexers for slow MySQL queries.<\/p>\n\n\n\n<p>In Magento 2, indexers play a crucial role in improving the performance of your e-commerce store. They are responsible for indexing and organizing data to enable faster search and retrieval of information. Magento transforms data such as products, categories, customer etc., to improve the performance of your storefront using indexers. Magento has a very sophisticated architecture that stores lots of merchant data in many database tables. To\u00a0optimize store performance, Magento stores the data into special tables using indexers.<\/p>\n\n\n\n<p><strong>Step 1: Create a new module using the <a href=\"https:\/\/webkul.com\/blog\/magento-development-01-module-registration\/\">guide<\/a>.<\/strong><\/p>\n\n\n\n<p><strong>Step 2: Lets create a simple API for retrieving the result of product attributes, like name , quantity, price using MySQL  queries.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;routes xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n        xsi:noNamespaceSchemaLocation=&quot;urn:magento:module:Magento_Webapi:etc\/webapi.xsd&quot;&gt;\n    \n    &lt;route url=&quot;\/V1\/test\/api\/me&quot; method=&quot;GET&quot;&gt;\n        &lt;service class=&quot;Webkul\\Test\\Api\\TestApiManagementInterface&quot; method=&quot;getApiData&quot;\/&gt;\n        &lt;resources&gt;\n            &lt;resource ref=&quot;anonymous&quot;\/&gt;\n        &lt;\/resources&gt;\n    &lt;\/route&gt;\n    \n&lt;\/routes&gt;<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace Webkul\\Test\\Model;\n\nclass TestApiManagement implements \\Webkul\\Test\\Api\\TestApiManagementInterface\n{\n    const SEVERE_ERROR = 0;\n    const SUCCESS = 1;\n    const LOCAL_ERROR = 2;\n\n    protected $productCollectionFactory;\n    protected $attributeFactory;\n    protected $attributeCollectionFactory;\n\n    public function __construct(\n        \\Magento\\Eav\\Model\\ResourceModel\\Entity\\AttributeFactory $attributeFactory,\n        \\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory $productCollectionFactory,\n        \\Webkul\\Test\\Model\\ResourceModel\\Attribute\\CollectionFactory $attributeCollectionFactory\n    ) {\n        $this-&gt;productCollectionFactory = $productCollectionFactory;\n        $this-&gt;attributeFactory = $attributeFactory;\n        $this-&gt;attributeCollectionFactory = $attributeCollectionFactory;\n    }\n\n    \/**\n     * get test Api data.\n     *\n     * @api\n     *\n     * @param int $id\n     *\n     *\/\n    public function getApiData($id)\n    {\n        $model = $this-&gt;productCollectionFactory\n            -&gt;create();\n        $eavAttribute = $this-&gt;attributeFactory-&gt;create();\n        $productAttributeId = $eavAttribute-&gt;getIdByCode(&#039;catalog_product&#039;, &#039;name&#039;);\n        $proPriceAttId = $eavAttribute-&gt;getIdByCode(&#039;catalog_product&#039;, &#039;price&#039;);\n        $proWeightAttId = $eavAttribute-&gt;getIdByCode(&#039;catalog_product&#039;, &#039;weight&#039;);\n        \n        $catalogProductEntityVarchar = $model-&gt;getTable(&#039;catalog_product_entity_varchar&#039;);\n        $catalogProductEntityDecimal = $model-&gt;getTable(&#039;catalog_product_entity_decimal&#039;);\n        $cataloginventoryStockItem = $model-&gt;getTable(&#039;cataloginventory_stock_item&#039;);\n        $sql = $catalogProductEntityVarchar.&#039; as cpev&#039;;\n        $cond = &#039;e.entity_id = cpev.entity_id&#039;;\n        $fields = &#091;&#039;product_name&#039; =&gt; &#039;value&#039;];\n        $model-&gt;getSelect()\n            -&gt;join($sql, $cond, $fields)\n            -&gt;where(&#039;cpev.store_id = 0 AND cpev.attribute_id = &#039;.$productAttributeId);\n\n        $sql = $catalogProductEntityDecimal.&#039; as cped&#039;;\n        $cond = &#039;e.entity_id = cped.entity_id&#039;;\n        $fields = &#091;&#039;product_price&#039; =&gt; &#039;value&#039;];\n        $model-&gt;getSelect()\n            -&gt;join($sql, $cond, $fields)\n            -&gt;where(&#039;cped.store_id = 0 AND (cped.attribute_id =\n            &#039;.$proPriceAttId.&#039;)&#039;);\n        $model-&gt;getSelect()-&gt;join(\n            $cataloginventoryStockItem.&#039; as csi&#039;,\n            &#039;e.entity_id = csi.product_id&#039;,\n            &#091;&quot;product_qty&quot; =&gt; &quot;qty&quot;]\n        )-&gt;where(&quot;csi.website_id = 0 OR csi.website_id = 1&quot;);\n        return $model-&gt;getData();\n    }\n\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png\" alt=\"apiwithsql\" class=\"wp-image-382565\" width=\"762\" height=\"268\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-300x106.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-250x88.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-768x270.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql.png 1387w\" sizes=\"(max-width: 762px) 100vw, 762px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Now let&#8217;s learn how we can achieve the same result using custom indexer to fasten the process.<br><strong>Step 3<\/strong>: In your module&#8217;s etc directory, <strong>create a new XML file named your_index_name.xml<\/strong>.This file will define the configuration for your custom indexer. Specify the name, ID, and other settings for your indexer, such as the data source and the schedule for updating the index.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot; ?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Indexer\/etc\/indexer.xsd&quot;&gt;\n    &lt;indexer id=&quot;product_attributes_indexer&quot; class=&quot;Webkul\\Test\\Model\\Indexer\\ProductAttributesIndexer&quot; view_id=&quot;product_attributes_indexer&quot; &gt;\n        &lt;title translate=&quot;true&quot;&gt;Product Attributes Indexer&lt;\/title&gt;\n        &lt;description translate=&quot;true&quot;&gt;Indexes product attributes like name, price, and quantity&lt;\/description&gt;\n    &lt;\/indexer&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p><strong>A change log table is created according to the naming rule &#8211; INDEXER_TABLE_NAME + &#8216;_cl&#8217;<\/strong>, in case of\u00a0<code>product_attributes_indexer<\/code>\u00a0it will be\u00a0<code>product_attributes_indexer_cl<\/code>. The table contains the\u00a0<code>version_id<\/code>\u00a0auto-increment column and\u00a0<code>entity_id<\/code>\u00a0column that contains identifiers of entities to be re-indexed.<\/p>\n\n\n\n<p><strong>Step 4<\/strong>: In your module&#8217;s etc directory, <strong>create mview.xml <\/strong> which is used to track database changes for a certain entity and running change handle (execute() method).<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Mview\/etc\/mview.xsd&quot;&gt;\n    &lt;view id=&quot;product_attributes_indexer&quot; class=&quot;Webkul\\Test\\Model\\Indexer\\ProductAttributesIndexer&quot; group=&quot;indexer&quot;&gt;\n        &lt;subscriptions&gt;\n            &lt;table name=&quot;catalog_product_entity&quot; entity_column=&quot;entity_id&quot; \/&gt;\n        &lt;\/subscriptions&gt;\n    &lt;\/view&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p><strong>Step 5<\/strong>:<strong> Implement the Indexer Class  Webkul\\Test\\Model\\Indexer\\ProductAttributesIndexer <\/strong> that extends the <code>\\Magento\\Framework\\Indexer\\AbstractProcessor<\/code> class.<\/p>\n\n\n\n<p>Basically, Indexer should be able to perform with 3 types of action :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Row index :<\/strong>&nbsp;For single entity.&nbsp;<strong>executeRow($id)&nbsp;<\/strong>method will be call in this indexer process.<\/li>\n\n\n\n<li><strong>List index :<\/strong>&nbsp;For processing set of entity.&nbsp;<strong>executeList(array $ids)&nbsp;<\/strong>method will be call in this indexer process.<\/li>\n\n\n\n<li><strong>Full index :<\/strong>&nbsp;For processing all entities from specific dictionary.&nbsp;<strong>executeFull()&nbsp;<\/strong>method will be call in this indexer process.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\Test\\Model\\Indexer;\n\nuse Magento\\Framework\\Indexer\\ActionInterface;\nuse Magento\\Framework\\Mview\\ActionInterface as MviewActionInterface;\nuse Magento\\Framework\\Indexer\\IndexerInterfaceFactory;\n\nclass ProductAttributesIndexer implements ActionInterface, MviewActionInterface\n{\n    private $indexerFactory;\n\n    public function __construct(\n        IndexerInterfaceFactory $indexerFactory,\n        \\Magento\\Framework\\App\\ResourceConnection $resourceConnection,\n        \\Magento\\Eav\\Model\\ResourceModel\\Entity\\AttributeFactory $attributeFactory,\n        \\Webkul\\Test\\Model\\ResourceModel\\Attribute $indexattribute\n    ) {\n        $this-&gt;indexerFactory = $indexerFactory;\n        $this-&gt;resource = $resourceConnection;\n        $this-&gt;connection = $resourceConnection-&gt;getConnection();\n        $this-&gt;attributeFactory = $attributeFactory;\n        $this-&gt;productAttributesData = $indexattribute;\n    }\n\n    public function execute($ids)\n    {\n        $indexer = $this-&gt;indexerFactory-&gt;create()-&gt;load(&#039;product_attributes_indexer&#039;);\n        if ($indexer-&gt;isInvalid()) {\n            return;\n        }\n        $connection = $this-&gt;connection;\n        $customTable = $this-&gt;productAttributesData-&gt;getMainTable();\n        $productTable = $connection-&gt;getTableName(&#039;catalog_product_entity&#039;);\n        $eavAttribute = $this-&gt;attributeFactory-&gt;create();\n        $productAttributeId = $eavAttribute-&gt;getIdByCode(&#039;catalog_product&#039;, &#039;name&#039;);\n        $proPriceAttId = $eavAttribute-&gt;getIdByCode(&#039;catalog_product&#039;, &#039;price&#039;);\n        $proWeightAttId = $eavAttribute-&gt;getIdByCode(&#039;catalog_product&#039;, &#039;weight&#039;);\n        $catalogProductEntityVarchar = $connection-&gt;getTableName(&#039;catalog_product_entity_varchar&#039;);\n        $catalogProductEntityDecimal = $connection-&gt;getTableName(&#039;catalog_product_entity_decimal&#039;);\n        $cataloginventoryStockItem = $connection-&gt;getTableName(&#039;cataloginventory_stock_item&#039;);\n        $select = $connection-&gt;select()-&gt;from(&#091;&#039;e&#039; =&gt; $productTable], &#091;&#039;entity_id&#039;]);\n       if (!empty($ids)) {\n            $select-&gt;where(\n                &quot;e.entity_id IN(?)&quot;,\n                $ids\n            );\n        }\n        $sql = $catalogProductEntityVarchar.&#039; as cpev&#039;;\n        $cond = &#039;e.entity_id = cpev.entity_id&#039;;\n        $fields = &#091;&#039;product_name&#039; =&gt; &#039;value&#039;];\n        $select\n            -&gt;join($sql, $cond, $fields)\n            -&gt;where(&#039;cpev.store_id = 0 AND cpev.attribute_id = &#039;.$productAttributeId);\n\n        $sql = $catalogProductEntityDecimal.&#039; as cped&#039;;\n        $cond = &#039;e.entity_id = cped.entity_id&#039;;\n        $fields = &#091;&#039;product_price&#039; =&gt; &#039;value&#039;];\n        $select\n            -&gt;join($sql, $cond, $fields)\n            -&gt;where(&#039;cped.store_id = 0 AND (cped.attribute_id =\n            &#039;.$proPriceAttId.&#039;)&#039;);\n        $select-&gt;join(\n            $cataloginventoryStockItem.&#039; as csi&#039;,\n            &#039;e.entity_id = csi.product_id&#039;,\n            &#091;&quot;product_qty&quot; =&gt; &quot;qty&quot;]\n        )-&gt;where(&quot;csi.website_id = 0 OR csi.website_id = 1&quot;);\n        $data = $connection-&gt;fetchAll($select);\n        foreach ($data as $item) {\n            $entityId = $item&#091;&#039;entity_id&#039;];\n            $name = $item&#091;&#039;product_name&#039;];\n            $price = $item&#091;&#039;product_price&#039;];\n            $quantity = $item&#091;&#039;product_qty&#039;];\n            \/\/save data in your custom indexer table\n            $connection-&gt;insertOnDuplicate($customTable, &#091;\n                &#039;product_id&#039; =&gt; $entityId,\n                &#039;name&#039; =&gt; $name,\n                &#039;price&#039; =&gt; $price,\n                &#039;qty&#039; =&gt; $quantity\n            ]);\n        }\n       \n    }\n\n    public function executeFull()\n    {\n        $this-&gt;execute(&#091;]);\n    }\n\n    public function executeList(array $ids)\n    {\n        $this-&gt;execute($ids);\n    }\n\n    public function executeRow($id)\n    {\n        $this-&gt;execute(&#091;$id]);\n    }\n}<\/pre>\n\n\n\n<p><strong>Step 6<\/strong>: <strong>Configure Dependency Injection<\/strong> To ensure that your custom indexer is properly instantiated and used within the Magento system, you need to configure dependency injection.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;type name=&quot;Magento\\Framework\\Indexer\\ConfigInterface&quot;&gt;\n        &lt;arguments&gt;\n            &lt;argument name=&quot;indexers&quot; xsi:type=&quot;array&quot;&gt;\n                &lt;item name=&quot;product_attributes_indexer&quot; xsi:type=&quot;string&quot;&gt;Webkul\\Test\\Model\\Indexer\\ProductAttributesIndexer&lt;\/item&gt;\n            &lt;\/argument&gt;\n        &lt;\/arguments&gt;\n  &lt;\/type&gt;<\/pre>\n\n\n\n<p><strong>Step7<\/strong>: Test and Verify Once you have implemented your custom indexer, it&#8217;s important to thoroughly test and verify its functionality. Run the necessary commands to trigger indexing and ensure that your data is properly indexed and searchable.<br><strong>php bin\/magento indexer:reindex  product_attributes_indexer<\/strong><\/p>\n\n\n\n<p>Now let&#8217;s create the function in api model to use the above indexer result:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;routes xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n        xsi:noNamespaceSchemaLocation=&quot;urn:magento:module:Magento_Webapi:etc\/webapi.xsd&quot;&gt;\n    \n    &lt;route url=&quot;\/V1\/test\/api\/index&quot; method=&quot;GET&quot;&gt;\n        &lt;service class=&quot;Webkul\\Test\\Api\\TestApiManagementInterface&quot; method=&quot;getIndexData&quot;\/&gt;\n        &lt;resources&gt;\n            &lt;resource ref=&quot;anonymous&quot;\/&gt;\n        &lt;\/resources&gt;\n    &lt;\/route&gt;\n&lt;\/routes&gt;<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\">public function getIndexData()\n    {\n        \/** \\Webkul\\Test\\Model\\ResourceModel\\Attribute\\CollectionFactory *\/\n        $attributeCollection = $this-&gt;attributeCollectionFactory-&gt;create();\n        return $attributeCollection-&gt;getData();\n    }<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"442\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apidatawithIndexer-1200x442.png\" alt=\"apidatawithIndexer\" class=\"wp-image-382568\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apidatawithIndexer-1200x442.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apidatawithIndexer-300x110.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apidatawithIndexer-250x92.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apidatawithIndexer-768x283.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apidatawithIndexer.png 1375w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>As you can check the result of both the process, it took half the time in fetching the result using the custom indexers result.<\/p>\n\n\n\n<p>We hope it will help you. Thank you!!<\/p>\n\n\n\n<p>If any issue or doubt please feel free to mention in comment section.<\/p>\n\n\n\n<p>We would be happy to help. Happy Coding!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we will learn how we can create custom indexers for slow MySQL queries. In Magento 2, indexers play a crucial role in improving the performance of your e-commerce store. They are responsible for indexing and organizing data to enable faster search and retrieval of information. Magento transforms data such as products, categories, <a href=\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":375,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[292,14214,12091,2070],"class_list":["post-382556","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-api","tag-custom-indexer","tag-indexer","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to add custom indexer for slow MySQL queries in Magento2 - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Learn how to create custom indexers for slow MySQL queries in magento2.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add custom indexer for slow MySQL queries in Magento2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to create custom indexers for slow MySQL queries in magento2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-19T10:06:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-19T10:06:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png\" \/>\n<meta name=\"author\" content=\"Radhika Garg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Radhika Garg\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\"},\"author\":{\"name\":\"Radhika Garg\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727\"},\"headline\":\"How to add custom indexer for slow MySQL queries in Magento2\",\"datePublished\":\"2023-05-19T10:06:04+00:00\",\"dateModified\":\"2023-05-19T10:06:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\"},\"wordCount\":485,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png\",\"keywords\":[\"api\",\"Custom Indexer\",\"indexer\",\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\",\"name\":\"How to add custom indexer for slow MySQL queries in Magento2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png\",\"datePublished\":\"2023-05-19T10:06:04+00:00\",\"dateModified\":\"2023-05-19T10:06:11+00:00\",\"description\":\"Learn how to create custom indexers for slow MySQL queries in magento2.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql.png\",\"width\":1387,\"height\":488,\"caption\":\"apiwithsql\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add custom indexer for slow MySQL queries in Magento2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727\",\"name\":\"Radhika Garg\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Radhika Garg\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/radhika-garg178\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add custom indexer for slow MySQL queries in Magento2 - Webkul Blog","description":"Learn how to create custom indexers for slow MySQL queries in magento2.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to add custom indexer for slow MySQL queries in Magento2 - Webkul Blog","og_description":"Learn how to create custom indexers for slow MySQL queries in magento2.","og_url":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-05-19T10:06:04+00:00","article_modified_time":"2023-05-19T10:06:11+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png","type":"","width":"","height":""}],"author":"Radhika Garg","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Radhika Garg","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/"},"author":{"name":"Radhika Garg","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727"},"headline":"How to add custom indexer for slow MySQL queries in Magento2","datePublished":"2023-05-19T10:06:04+00:00","dateModified":"2023-05-19T10:06:11+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/"},"wordCount":485,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png","keywords":["api","Custom Indexer","indexer","Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/","url":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/","name":"How to add custom indexer for slow MySQL queries in Magento2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql-1200x422.png","datePublished":"2023-05-19T10:06:04+00:00","dateModified":"2023-05-19T10:06:11+00:00","description":"Learn how to create custom indexers for slow MySQL queries in magento2.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/apiwithsql.png","width":1387,"height":488,"caption":"apiwithsql"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-indexer-for-slow-mysql-queries-in-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add custom indexer for slow MySQL queries in Magento2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727","name":"Radhika Garg","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Radhika Garg"},"url":"https:\/\/webkul.com\/blog\/author\/radhika-garg178\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/382556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/375"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=382556"}],"version-history":[{"count":7,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/382556\/revisions"}],"predecessor-version":[{"id":382615,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/382556\/revisions\/382615"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=382556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=382556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=382556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}