Note that there are some explanatory texts on larger screens.

plurals
  1. POReally Slow MySQL Insert Query
    primarykey
    data
    text
    <p>I've got a table with about half a million records in it. It's not huge. A couple varchar(255) fields, some ints, a float, and a couple timestamps. There are indices on the ints as well as foreign key constraints. Inserts are taking <em>forever</em>. I'm talking 1-4 seconds to insert <em>one</em> row. I've had to deal with slow select queries plenty of times, but I'm stuck trying to figure out what's going on with this insert.</p> <p>EDIT: Okay, I was really just asking for ideas on how to debug this, but, here's all the tables involved. Inserting into "ingredients" is what takes forever. Hopefully throwing a good portion of my schema onto the web doesn't bite me later...</p> <pre><code>CREATE TABLE `ingredients` ( `id` int(11) NOT NULL AUTO_INCREMENT, `quantity` float DEFAULT NULL, `food` varchar(255) NOT NULL, `unit_id` int(11) DEFAULT NULL, `ingredient_group_id` int(11) DEFAULT NULL, `order_by` int(11) NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `description` varchar(255) DEFAULT NULL, `range` float DEFAULT NULL, PRIMARY KEY (`id`), KEY `unit_id` (`unit_id`), KEY `ingredient_group_id` (`ingredient_group_id`), CONSTRAINT `ingredients_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`), CONSTRAINT `ingredients_ibfk_2` FOREIGN KEY (`ingredient_group_id`) REFERENCES `ingredient_groups` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=269974 DEFAULT CHARSET=utf8 CREATE TABLE `units` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `abbreviation` varchar(255) CHARACTER SET latin1 NOT NULL, `type` int(11) NOT NULL, `si` float NOT NULL, `lower_bound` float DEFAULT NULL, `lower_unit_id` int(11) DEFAULT NULL, `upper_bound` float DEFAULT NULL, `upper_unit_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `lower_unit_id` (`lower_unit_id`), KEY `upper_unit_id` (`upper_unit_id`), CONSTRAINT `units_ibfk_1` FOREIGN KEY (`lower_unit_id`) REFERENCES `units` (`id`), CONSTRAINT `units_ibfk_2` FOREIGN KEY (`upper_unit_id`) REFERENCES `units` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 CREATE TABLE `ingredient_groups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `recipe_id` int(11) NOT NULL, `order_by` int(11) NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, PRIMARY KEY (`id`), KEY `recipe_id` (`recipe_id`), CONSTRAINT `ingredient_groups_ibfk_1` FOREIGN KEY (`recipe_id`) REFERENCES `recipes` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=32739 DEFAULT CHARSET=utf8 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload