I have a table that has an on delete trigger that updates another table. THe table I'm trying to truncate has 130,000 rows. I have duplicate schema and data on my dev server as well as the client's deployment stating server. (5,5,49)
On my dev server (5.5.29) when I truncate the table, it's instant, as in by the time I type show full processlist, the truncate is finished.
When I run the same truncate on the staging server I see this in the process list:
| 3377 | root | localhost:46410 | database | Query | 533 | Sending data | DELETE FROM PriceCode44 |
| 3378 | root | localhost:46800 | database | Query | 521 | Waiting for table metadata lock | truncate table `PriceCode44` |
There are no foreign keys in the database related to this table.
My solution was to drop the table and recreate it, but I'm concerned that at some point the client is going to need to truncate the table, and since the delete trigger is updating a lot of data it takes a long time.
What could be the possibly cause of this, and how can I avoid it?
Adding if it's not clear - the documented truncate behavior is the desired behavior. I just want to whack the data in the table.
Here is the create table:
CREATE TABLE `InsynchPriceCode44` (
`PriceCodeRecord` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`PriceCode` varchar(4) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`ItemCode` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`CustomerPriceLevel` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`ARDivisionNo` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`CustomerNo` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`Description` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
`Method` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`BreakQty1` decimal(9,0) DEFAULT NULL,
`BreakQty2` decimal(9,0) DEFAULT NULL,
`BreakQty3` decimal(9,0) DEFAULT NULL,
`BreakQty4` decimal(9,0) DEFAULT NULL,
`BreakQty5` decimal(9,0) DEFAULT NULL,
`DiscountMarkupPriceRate1` decimal(12,3) DEFAULT NULL,
`DiscountMarkupPriceRate2` decimal(12,3) DEFAULT NULL,
`DiscountMarkupPriceRate3` decimal(12,3) DEFAULT NULL,
`DiscountMarkupPriceRate4` decimal(12,3) DEFAULT NULL,
`DiscountMarkupPriceRate5` decimal(12,3) DEFAULT NULL,
PRIMARY KEY (`PriceCodeRecord`,`PriceCode`,`ItemCode`,`CustomerPriceLevel`,`ARDivisionNo`,`CustomerNo`),
KEY `PriceCodeRecord_2` (`PriceCodeRecord`,`PriceCode`,`CustomerPriceLevel`) USING BTREE,
KEY `PriceCodeRecord_3` (`PriceCodeRecord`,`ItemCode`,`CustomerPriceLevel`) USING BTREE,
KEY `PriceCodeRecord` (`PriceCodeRecord`,`ItemCode`,`CustomerNo`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT
This is identical to my dev server.