[Skip to main content](#vessel-content)

#   missing index on old store and suggestions for new index

##

- **[dan@drumscore.com](/forum/user/11292-dan-drumscore-com "View dan@drumscore.com's Profile")**
- [![dan@drumscore.com's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/11292-dan-drumscore-com "View dan@drumscore.com's Profile") Topic Author
- [ Offline](/forum/user/11292-dan-drumscore-com)

Less More

- Posts: 1
- Thank you received: 0
-
-

3 hours 17 minutes ago [\#100000911](#100000911) by [dan@drumscore.com](/forum/user/11292-dan-drumscore-com "View dan@drumscore.com's Profile")  *[missing index on old store and suggestions for new index](/forum/2-general-talk-about-hikashop/100000198-missing-index-on-old-store-and-suggestions-for-new-index#100000911 "-- HikaShop version -- : 6.8.3 -- Joomla version -- : 5.4 -- PHP version -- : 8.3 -- Browser(s) name and version -- : Firefox 161.0")* was created by *[dan@drumscore.com](/forum/user/11292-dan-drumscore-com "View dan@drumscore.com's Profile")*

-- HikaShop version -- : 6.8.3
-- Joomla version -- : 5.4
-- PHP version -- : 8.3
-- Browser(s) name and version -- : Firefox 161.0

We run HikaShop Business 6.8.3 on Joomla 5.4 MariaDB, on a shop that has been upgraded through many versions. While reviewing slow queries we found two things.

1. Possible upgrade bug: #\_\_hikashop\_order\_product has no product\_id index
tables.sql in 6.8.3 defines KEY &#96;product\_id&#96; (&#96;product\_id&#96;) on #\_\_hikashop\_order\_product, but our database does not have it. Every other index in tables.sql is present, so it looks like this key was added to tables.sql for new installs without a matching ALTER in the update routine. Could you check, and add it for upgraded sites?

2. Suggested new indexes
Each of these columns is filtered on by core queries but has no usable index, so the query scans the whole table (confirmed with EXPLAIN). Timings are warm-cache, before -&gt; after adding the index.

a) #\_\_hikashop\_file (file\_ref\_id, file\_type)
  16k rows. Used to load images/files for products and categories, on nearly every front-end page. 11.4 ms -&gt; 1.1 ms.

b) #\_\_hikashop\_category (category\_parent\_id) and (category\_left)
  10k rows. Child-category listings and tree lookups. 13.7 ms -&gt; 0.3 ms and 2.4 ms -&gt; 0.1 ms.

c) #\_\_hikashop\_product\_related (product\_related\_id, product\_related\_type)
  256k rows. The primary key starts with product\_id, so reverse lookups scan the table, e.g. the bundle check in classes/cart.php (around line 3606: "pr.product\_id IN (...) OR pr.product\_related\_id IN (...)"). 28.9 ms -&gt; 0.4 ms.

d) #\_\_hikashop\_download (order\_id)
  173k rows. The primary key is (file\_id, order\_id, file\_pos), so lookups by order alone scan the table: views/user/view.html.php (around line 856, "WHERE order\_id IN (...)") and classes/withdrawal.php (around line 164). 13.1 ms -&gt; 0.5 ms.

e) #\_\_hikashop\_order (order\_number)
  129k rows. Order lookup by number. 40.0 ms -&gt; 0.3 ms.

f) #\_\_hikashop\_cart (cart\_type, cart\_modified)
  582k rows. The old-cart cleanup query in helpers/helper.php (around line 702: "WHERE cart\_type IN ('cart','onepage') AND cart\_modified &lt; ... ORDER BY cart\_modified ASC LIMIT ..."). 144.7 ms -&gt; 0.7 ms.

g) #\_\_hikashop\_email\_log (email\_log\_date)
  60k rows, 1.2 GB of data. The back-end email log listing sorted by date sorts the whole table. 299.2 ms -&gt; 0.6 ms.

The statements we used:
ALTER TABLE #\_\_hikashop\_file            ADD INDEX file\_ref (file\_ref\_id, file\_type);
ALTER TABLE #\_\_hikashop\_category        ADD INDEX category\_parent (category\_parent\_id), ADD INDEX category\_left (category\_left);
ALTER TABLE #\_\_hikashop\_product\_related ADD INDEX related\_reverse (product\_related\_id, product\_related\_type);
ALTER TABLE #\_\_hikashop\_download        ADD INDEX download\_order (order\_id);
ALTER TABLE #\_\_hikashop\_order\_product  ADD INDEX product\_id (product\_id);
ALTER TABLE #\_\_hikashop\_order          ADD INDEX order\_number (order\_number);
ALTER TABLE #\_\_hikashop\_cart            ADD INDEX cart\_type\_modified (cart\_type, cart\_modified);
ALTER TABLE #\_\_hikashop\_email\_log      ADD INDEX email\_log\_date (email\_log\_date);

Two questions:
- Would you consider adding these to the core schema?
- If we add them ourselves in the meantime, will a future HikaShop update leave them alone, and is there a naming convention you would prefer so they don't clash with indexes you add later?

Thank you.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzItZ2VuZXJhbC10YWxrLWFib3V0LWhpa2FzaG9wLzEwMDAwMDE5OC1taXNzaW5nLWluZGV4LW9uLW9sZC1zdG9yZS1hbmQtc3VnZ2VzdGlvbnMtZm9yLW5ldy1pbmRleD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.053 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
