Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:50:49+00:00 2026-05-29T05:50:49+00:00

I have recently switched my project tables to InnoDB (thinking the relations would be

  • 0

I have recently switched my project tables to InnoDB (thinking the relations would be a nice thing to have). I’m using a PHP script to index about 500 products at a time.

A table storing word/ids association:

    CREATE TABLE `windex` (
 `word` varchar(64) NOT NULL,
 `wid` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `count` int(11) unsigned NOT NULL DEFAULT '1',
 PRIMARY KEY (`wid`),
 UNIQUE KEY `word` (`word`)
) ENGINE=InnoDB AUTO_INCREMENT=324551 DEFAULT CHARSET=latin1

Another table stores product id/word id associations:

CREATE TABLE `indx_0` (
 `wid` int(7) unsigned NOT NULL,
 `pid` int(7) unsigned NOT NULL,
 UNIQUE KEY `wid` (`wid`,`pid`),
 KEY `pid` (`pid`),
 CONSTRAINT `indx_0_ibfk_1` FOREIGN KEY (`wid`) REFERENCES `windex` (`wid`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `indx_0_ibfk_2` FOREIGN KEY (`pid`) REFERENCES `product` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1

The script was tested using MyISAM and it indexes products relatively fast (much, much faster than InnoDB). First time running in InnoDB it was ridiculously slow but after nesting more values together I ended up speeding it up by a lot (but not enough).

I would assume innodb would be much faster for this type of thing because of rowlevel locks but that’s not the case.

I construct a query that looks something like:

SELECT
title,keywords,upc,...
FROM product
WHERE indexed = 0
LIMIT 500

I create a loop and fill an array with all the words that need to be added to windex and all the word id/product id pairs that need to be added to indx_0.

Because innodb keeps increasing my auto-increment values whenever i do a “REPLACE INTO” or “INSERT IGNORE INTO” that fails because of duplicate values, I need to make sure the values I add don’t already exist. To do that I first select all values that exist using a query like such:

SELECT wid,word
FROM windex
WHERE
word = "someword1" or word = "someword2" or word = "someword3" ... ...

Then I filter out my array against the results which exist so all the new words I add are 100% new.

This takes about 20% of overall execution time. The other 80% goes into adding the pair values into indx_0, for which there are many more values.

Here’s an example of what I get.

0.4806 seconds to select products. (0.4807 sec total).
0.0319 seconds to gather 500 items. (0.5126 sec total).
5.2396 seconds to select windex values for comparison. (5.7836 sec total).
1.8986 seconds to update count. (7.6822 sec total).
0.0641 seconds to add 832 windex records. (7.7464 sec total).
17.2725 seconds to add index of 3435 pid/wid pairs. (25.7752 sec total).
Operation took 26.07 seconds to index 500 products.

The 3435 pairs are being all executed in a single query such as:

INSERT INTO indx_0(pid,wid)
VALUES (1,4),(3,9),(9,2)... ... ...

Why is InnoDB so much slower than MyISAM in my case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:50:50+00:00Added an answer on May 29, 2026 at 5:50 am

    InnoDB provides more complex keys structure than MyIsam (FOREIGN KEYS) and regenerating keys is really slow in InnoDB. You should enclose all update/insert statements into one transactions (those are actually quite fast in InnoDB, once I had about 300 000 insert queries on InnoDb table with 2 indexes and it took around 30 minutes, once I enclosed every 10 000 inserts into BEGIN TRANSACTION and COMMIT it took less than 2 minutes).

    I recommend to use:

    BEGIN TRANSACTION;
    SELECT ... FROM products;
    UPDATE ...;
    INSERT INTO ...;
    INSERT INTO ...;
    INSERT INTO ...;
    COMMIT;
    

    This will cause InnoDB to refresh indexes just once not few hundred times.

    Let me know if it worked

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently switched to using Git (eGit) from SVN... for my Eclipse Java project
I have been using rspec for a little while and recently switched style from
I have recently switched from Netbeans to Eclipse. I have a project which contains
I've been using DirectX (with XNA) for a while now, and have recently switched
I have recently switched from Eclipse Indigo to Eclipse Juno. My thinking was I
I have recently switched to git. In my previous and first commit since using
I have recently switched from using Eclipse to IntelliJ, and am preferring the experience.
I have recently switched jobs and at this new company we are using MySQL.
I'm using Magento 1.7 and i have recently switched my shop to a new
I have recently switched from using separate resource files to using a texture atlas.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.