I have the following MySQL query:
INSERT INTO shopious_instagram_item_viewer (created, viewer_id, item_id) VALUES ('2014-11-11 21:26:53', 210054, 714755)\G
Here's how the table is structured:
I am wondering why a simple insert like this would take me on average 37 seconds to complete based on the analysis of percona toolkit.
# Query 2: 0.00 QPS, 0.09x concurrency, ID 0x32289FAFEDA31EE5 at byte 271077009
# This item is included in the report because it matches --limit.
# Scores: V/M = 4.60
# Time range: 2014-11-07 07:12:26 to 2014-11-13 06:18:39
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 0 2459
# Exec time 16 48495s 1s 52s 20s 37s 10s 19s
# Lock time 0 256ms 21us 122ms 104us 54us 3ms 38us
# Rows sent 0 0 0 0 0 0 0 0
# Rows examine 0 0 0 0 0 0 0 0
# Query size 0 287.03k 115 120 119.53 118.34 0.72 118.34
# String:
# Databases ShopiousDirectory
# Hosts localhost
# Users root
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s #############
# 10s+ ################################################################
# Tables
# SHOW TABLE STATUS FROM `ShopiousDirectory` LIKE 'shopious_instagram_item_viewer'\G
# SHOW CREATE TABLE `ShopiousDirectory`.`shopious_instagram_item_viewer`\G
INSERT INTO shopious_instagram_item_viewer (created, viewer_id, item_id) VALUES ('2014-11-11 21:26:53', 210054, 714755)\G
I am planning to add indexes, but don't think that helps a lot on insertion.
You could disable FK checks before the insert and re-enable them after: