how to improve performance of my query? - mysql

we have written a query like below and also created proper indexes on table.
QUERY
SELECT ref_order_id, order_id, cams_ref_order_id
FROM cart_entries_archive
WHERE regular_price <> product_price
AND ref_order_id >0
AND cams_ref_order_id > 0;
But the query is performing full table scan due to this we are getting load spikes .
we tried by adding indexes on where clause columns but still performing full scan .Please rewrite the query if possible.
query explain plan
mysql> explain select ref_order_id,order_id,cams_ref_order_id from cart_entries_archive where regular_price <> product_price and ref_order_id >0 and cams_ref_order_id > 0;
+----+-------------+----------------------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------------------+------+---------------+------+---------+------+---------+-------------+
| 1 | SIMPLE | cart_entries_archive | ALL | NULL | NULL | NULL | NULL | 6490560 | Using where |
+----+-------------+----------------------+------+---------------+------+---------+------+---------+-------------+
1 row in set (0.00 sec)
Table structure:
mysql> show create table cart_entries_archive\G
*************************** 1. row ***************************
Table: cart_entries_archive
Create Table: CREATE TABLE `cart_entries_archive` (
`row_mod` datetime DEFAULT NULL,
`row_create` datetime DEFAULT NULL,
`address_id` int(11) DEFAULT NULL,
`backorder_date` datetime DEFAULT NULL,
`cancelled_date` datetime DEFAULT NULL,
`cart_entry_id` int(11) NOT NULL,
`cart_id` int(11) NOT NULL,
`delivery_date` datetime DEFAULT NULL,
`delivery_method` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`delivery_note` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`discount_amount` decimal(8,2) DEFAULT '0.00',
`gift_message` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`occasion` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`order_date` datetime DEFAULT NULL,
`order_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`order_status` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`product_name` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`product_extra` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`product_price` decimal(8,2) DEFAULT '0.00',
`product_count` int(11) DEFAULT NULL,
`product_cost` decimal(8,2) DEFAULT '0.00',
`product_sku` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`product_notes` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`parent_product_sku` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`returned_date` datetime DEFAULT NULL,
`release_date` datetime DEFAULT NULL,
`regular_price` decimal(8,2) DEFAULT '0.00',
`shipping_cost` decimal(8,2) DEFAULT '0.00',
`service_charge` decimal(8,2) DEFAULT '0.00',
`sku_option_name` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`sku_option_value` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`shipping_company` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`shipping_fname` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`shipping_lname` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`shipping_address` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`shipping_address2` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`shipping_city` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`shipping_country` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`shipping_province` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`shipping_postal_code` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`shipping_phone` varchar(20) COLLATE latin1_bin DEFAULT NULL,
`shipping_phone_ext` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`ship_tracking_number` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`status` varchar(20) COLLATE latin1_bin DEFAULT NULL,
`tax` decimal(8,2) DEFAULT '0.00',
`total_charge` decimal(8,2) DEFAULT '0.00',
`website_id` int(11) DEFAULT NULL,
`microsite_id` int(11) DEFAULT NULL,
`defer_reason` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`defer_key` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`shipping_evening_phone` varchar(20) COLLATE latin1_bin DEFAULT NULL,
`shipping_mobile_phone` varchar(20) COLLATE latin1_bin DEFAULT NULL,
`shipping_email` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`shipping_title` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`shipping_district` varchar(30) COLLATE latin1_bin DEFAULT NULL,
`location_type` varchar(20) COLLATE latin1_bin DEFAULT NULL,
`occasion_id` int(11) DEFAULT NULL,
`occasion_date` datetime DEFAULT NULL,
`occasion_do_remind` int(11) DEFAULT NULL,
`coupon_ref_source_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`delivery_date_verified` int(11) DEFAULT NULL,
`florist_peak_charge` float DEFAULT NULL,
`member_id` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`delivery_location_code` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`simply_iflora` int(11) DEFAULT NULL,
`rotation_weight` int(11) DEFAULT NULL,
`area_charge` decimal(8,2) DEFAULT NULL,
`cf_indicator` varchar(5) COLLATE latin1_bin DEFAULT NULL,
`category_id` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`cms_note` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`qas_queried` int(11) DEFAULT NULL,
`shipping_verified` int(11) DEFAULT NULL,
`occasion_event_name` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`push_date` datetime DEFAULT NULL,
`ref_order_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`relationship` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`std_delivery_id` int(11) DEFAULT NULL,
`opt_delivery_id` int(11) DEFAULT NULL,
`service_date` datetime DEFAULT NULL,
`parameters` varchar(1024) COLLATE latin1_bin DEFAULT NULL,
`order_type` varchar(32) COLLATE latin1_bin DEFAULT NULL,
`cams_ref_order_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`membership_discount` decimal(8,2) DEFAULT NULL,
PRIMARY KEY (`cart_entry_id`),
UNIQUE KEY `idx_2204` (`cart_entry_id`,`cart_id`),
UNIQUE KEY `idx_2318` (`cart_entry_id`,`order_id`),
KEY `idx_1049` (`order_date`),
KEY `idx_726` (`cart_id`),
KEY `idx_840` (`order_id`),
KEY `idx_row_create` (`row_create`),
KEY `idx_1035` (`push_date`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
1 row in set (0.00 sec)

Your where clause uses ">" rather than "=", making it far less likely that an index will be useful. What % of rows in that table meet the criteria where ref_order_id>0 and cams_ref_order_id>0 ? If it is a high percentage, a table scan could be the fastest approach. Even if 10% of the records meet that criteria, it might mean the RDBMS has to read almost every page of the table.
If you want it to be "Index Only", you could add the following index:
create index TMP001 on cart_entries_archive
(ref_order_id, cams_ref_order_id, order_id, regular_price, product_price)
The fields from the where clause lead the index and everything else follows. If this is the only query you care about, and if the cost of maintaining the index is negligible, then create it and you're done.

Related

Improving MySQL Update Performance

I've got a process to import/update data from a CSV file. The process of saving that data from the csv to a "temp" table works fine. (temp_mls_transactions)
The next step is to update the existing records in the production table (tbl_mlsTransactions) with the data from the "temp" table. This step is causing the issue. IF it completes, its about 17 minutes for 7k records.
After the update is complete, we delete the common records from the "temp" table. Then insert the remaining records.
Here is the update query:
UPDATE tbl_MLSTransactions mt USE INDEX(idx_mlsNumber_association) INNER JOIN temp_mls_import temp USE INDEX (idx_mlsAssociationID_mlsID) ON mt.mlsNumber=temp.mlsNumber AND mt.mlsAssociationID=temp.mlsAssociationID
SET mt.activeStatusDate=temp.activeStatusDate,
mt.closeDate=temp.closeDate,
mt.closePrice=temp.closePrice,
mt.coListAgentMLSID=temp.coListAgentMLSID,
mt.coSellingAgentMLSID=temp.coSellingAgentMLSID,
mt.currentPrice=temp.currentPrice,
mt.dateAvailable=temp.dateAvailable,
mt.daysToClose=temp.daysToClose,
mt.daysToContract=temp.daysToContract,
mt.DOM=temp.DOM,
mt.expectedClosingDate=temp.expectedClosingDate,
mt.expirationDate=temp.expirationDate,
mt.address=temp.address,
mt.address2=temp.address2,
mt.city=temp.city,
mt.state=temp.state,
mt.zip=temp.zip,
mt.lastChangeType=temp.lastChangeType,
mt.lastDateAvailable=temp.lastDateAvailable,
mt.lastListPrice=temp.lastListPrice,
mt.lastStatus=temp.lastStatus,
mt.latitude=temp.latitude,
mt.listAgentMLSID=temp.listAgentMLSID,
mt.listPrice=temp.listPrice,
mt.listingContractDate=temp.listingContractDate,
mt.longitude=temp.longitude,
mt.originalListPrice=temp.originalListPrice,
mt.pendingDate=temp.pendingDate,
mt.propertyStatus=temp.propertyStatus,
mt.sellingAgentMLSID=temp.sellingAgentMLSID,
mt.status=temp.status,
mt.statusContractualSearchDate=temp.statusContractualSearchDate,
mt.withdrawnDate=temp.withdrawnDate,
mt.withdrawnStatus=temp.withdrawnStatus,
mt.listOfficeMLSID=temp.listOfficeMLSID,
mt.coListOfficeMLSID=temp.coListOfficeMLSID,
mt.sellingOfficeMLSID=temp.sellingOfficeMLSID,
mt.coSellingOfficeMLSID=temp.coSellingOfficeMLSID;
Here is the create statement for the "temp" table
CREATE TABLE `temp_mls_import` (
`tempID` int(11) NOT NULL AUTO_INCREMENT,
`activeStatusDate` date DEFAULT NULL,
`address` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`address2` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`city` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`state` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`zip` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`availability` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`bathsFull` int(11) DEFAULT NULL,
`bathsHalf` int(11) DEFAULT NULL,
`bathsTotal` decimal(10,2) DEFAULT NULL,
`bedsTotal` decimal(10,2) DEFAULT NULL,
`CDOM` int(11) DEFAULT NULL,
`closeDate` date DEFAULT NULL,
`closePrice` decimal(15,2) DEFAULT NULL,
`coListAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coListOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`contractStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`county` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`currentPrice` decimal(15,2) DEFAULT NULL,
`dateAvailable` date DEFAULT NULL,
`daysToClose` int(11) DEFAULT NULL,
`daysToContract` int(11) DEFAULT NULL,
`DOM` int(11) DEFAULT NULL,
`expectedClosingDate` date DEFAULT NULL,
`expectedLeaseDate` date DEFAULT NULL,
`expirationDate` date DEFAULT NULL,
`expirationRenewalDate` date DEFAULT NULL,
`lastChangeType` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`lastDateAvailable` date DEFAULT NULL,
`lastListPrice` decimal(15,2) DEFAULT NULL,
`lastStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`latitude` float DEFAULT NULL,
`listAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listPrice` decimal(15,2) DEFAULT NULL,
`listingContractDate` date DEFAULT NULL,
`longitude` float DEFAULT NULL,
`mlsNumber` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`offMarketDate` date DEFAULT NULL,
`officePrimaryBoardID` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`originalEntryTimestamp` timestamp NULL DEFAULT NULL,
`originalListPrice` decimal(15,2) DEFAULT NULL,
`PDOM` int(11) DEFAULT NULL,
`pendingDate` date DEFAULT NULL,
`photoCount` int(11) DEFAULT NULL,
`postalCodePlus4` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`priceChangeTimestamp` timestamp NULL DEFAULT NULL,
`propertyStatus` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`propertyType` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`providerModificationTimestamp` timestamp NULL DEFAULT NULL,
`realtorComYN` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`SPLPRatio` decimal(10,2) DEFAULT NULL,
`sqftHeated` decimal(10,2) DEFAULT NULL,
`sqftTotal` decimal(10,2) DEFAULT NULL,
`status` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`statusChangeTimestamp` timestamp NULL DEFAULT NULL,
`statusContractualSearchDate` date DEFAULT NULL,
`teamName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`tempOffMarketDate` date DEFAULT NULL,
`unitNumber` int(11) DEFAULT NULL,
`withdrawnDate` date DEFAULT NULL,
`withdrawnStatus` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`yearBuilt` int(11) DEFAULT NULL,
`mlsAssociationID` int(11) DEFAULT NULL,
PRIMARY KEY (`tempID`),
KEY `idx_mlsAssociationID_mlsID` (`mlsNumber`,`mlsAssociationID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
And here is the create statement for the production table
CREATE TABLE `tbl_mlstransactions` (
`transactionID` int(11) NOT NULL AUTO_INCREMENT,
`activeStatusDate` date DEFAULT NULL,
`address` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`address2` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`city` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`state` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`zip` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`availability` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`bathsFull` int(11) DEFAULT NULL,
`bathsHalf` int(11) DEFAULT NULL,
`bathsTotal` decimal(10,2) DEFAULT NULL,
`bedsTotal` decimal(10,2) DEFAULT NULL,
`CDOM` int(11) DEFAULT NULL,
`closeDate` date DEFAULT NULL,
`closePrice` decimal(15,2) DEFAULT NULL,
`coListAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coListOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`contractStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`county` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`currentPrice` decimal(15,2) DEFAULT NULL,
`dateAvailable` date DEFAULT NULL,
`daysToClose` int(11) DEFAULT NULL,
`daysToContract` int(11) DEFAULT NULL,
`DOM` int(11) DEFAULT NULL,
`expectedClosingDate` date DEFAULT NULL,
`expectedLeaseDate` date DEFAULT NULL,
`expirationDate` date DEFAULT NULL,
`expirationRenewalDate` date DEFAULT NULL,
`lastChangeType` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`lastDateAvailable` date DEFAULT NULL,
`lastListPrice` decimal(15,2) DEFAULT NULL,
`lastStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`latitude` float DEFAULT NULL,
`listAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listPrice` decimal(15,2) DEFAULT NULL,
`listingContractDate` date DEFAULT NULL,
`longitude` float DEFAULT NULL,
`mlsNumber` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`offMarketDate` date DEFAULT NULL,
`officePrimaryBoardID` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`originalEntryTimestamp` timestamp NULL DEFAULT NULL,
`originalListPrice` decimal(15,2) DEFAULT NULL,
`PDOM` int(11) DEFAULT NULL,
`pendingDate` date DEFAULT NULL,
`photoCount` int(11) DEFAULT NULL,
`postalCodePlus4` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`priceChangeTimestamp` timestamp NULL DEFAULT NULL,
`propertyStatus` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`propertyType` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`providerModificationTimestamp` timestamp NULL DEFAULT NULL,
`realtorComYN` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`SPLPRatio` decimal(10,2) DEFAULT NULL,
`sqftHeated` decimal(10,2) DEFAULT NULL,
`sqftTotal` decimal(10,2) DEFAULT NULL,
`status` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`statusChangeTimestamp` timestamp NULL DEFAULT NULL,
`statusContractualSearchDate` date DEFAULT NULL,
`teamName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`tempOffMarketDate` date DEFAULT NULL,
`unitNumber` int(11) DEFAULT NULL,
`withdrawnDate` date DEFAULT NULL,
`withdrawnStatus` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`yearBuilt` int(11) DEFAULT NULL,
`mlsAssociationID` int(11) DEFAULT NULL,
PRIMARY KEY (`transactionID`),
KEY `idx_agentListInfo` (`listAgentMLSID`(191),`coListAgentMLSID`(191),`closeDate`,`status`),
KEY `idx_agentSellInfo` (`sellingAgentMLSID`(191),`coSellingAgentMLSID`(191),`closeDate`,`status`),
KEY `IDX_listAgentMLSID` (`listAgentMLSID`(191)) USING BTREE,
KEY `idx_coListAgentMLSID` (`coListAgentMLSID`(191)),
KEY `IDX_sellingAgentMLSID` (`sellingAgentMLSID`(191)) USING BTREE,
KEY `idx_coSellingAgentMLSID` (`coSellingAgentMLSID`(191)),
KEY `idx_productionSearch` (`mlsAssociationID`,`status`,`closeDate`),
KEY `idx_agentIDs` (`listAgentMLSID`(191),`coListAgentMLSID`(191),`sellingAgentMLSID`(191),`coSellingAgentMLSID`(191)),
KEY `idx_closeDate` (`closeDate`),
KEY `idx_mlsNumber_association` (`mlsNumber`,`mlsAssociationID`)
) ENGINE=InnoDB AUTO_INCREMENT=4543783 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
The import is not currently running, but here is the output from the explain statement on the update query
id,select_type,table,partitions,type,possible_keys,key,key_len,ref,rows,filtered,Extra
1,SIMPLE,temp,NULL,ALL,idx_mlsAssociationID_mlsID,NULL,NULL,NULL,1,100.00,"Using where"
1,UPDATE,mt,NULL,ref,idx_mlsNumber_association,idx_mlsNumber_association,128,"agenttracker.temp.mlsNumber,agenttracker.temp.mlsAssociationID",1,100.00,NULL
Any suggestions on how to make this quicker?
UPDATE:
I ran a few different files and when the ID's (MlsNumber, AgentID's, etc) are shorter (i.e. 5-10 characters) the update completes in 0.25 seconds. When they are longer (i.e. 25-27 characters) is when there is a problem.
Here are a couple examples of the long and short MLS Numbers:
20191104230040909159000000
20191104230040909159000000
20191104230040909159000000
Short:
4PRW01
20593419
20698727

Unrecognized data type - MYSQL

I created a database table in MySQL, but it would show up errors. Please help to solving this issue and constructive feedback is appreciated.
CREATE TABLE `bldsvs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`monday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`tuesday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`wednesday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`thursday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`friday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`saturday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`sunday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
'positionID` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`status` enum('1','0') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

multiple joins SQL query optimization

I have the following query :
SELECT
COUNT(DISTINCT a0_.id) AS sclr0
FROM
account a0_
INNER JOIN customer c1_ ON (c1_.account = a0_.id)
LEFT JOIN sf_user_data s2_ ON (s2_.user_id = a0_.id)
LEFT JOIN address a3_ ON (c1_.customer_address = a3_.id)
WHERE
a3_.city IS NOT NULL
resulting in the following output :
sclr0
+--------+
298279
with the following EXPLAIN :
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
+--+---------------+-------+-----------+-------+--------------------------------------------+-----------------------+-----------+--------------------------------+-------+-----------+-------+
1 SIMPLE c1_ NULL ALL UNIQ_81398E097D3656A4,UNIQ_81398E091193CB3F NULL NULL NULL 405508 100.00 NULL
1 SIMPLE a0_ NULL eq_ref PRIMARY PRIMARY 8 evoportail.c1_.account 1 100.00 Using index
1 SIMPLE s2_ NULL eq_ref UNIQ_E904BFD1A76ED395 UNIQ_E904BFD1A76ED395 8 evoportail.c1_.account 1 100.00 Using index
1 SIMPLE a3_ NULL eq_ref PRIMARY PRIMARY 8 evoportail.c1_.customer_address 1 90.00 Using where
approximative number of rows in the tables :
account : 430000
customer: 430000
sf_user_data : 115000
address : 550000
Right now, this query is running in 3 seconds. Is there any way to speed it up ?
the CREATE statements :
CREATE TABLE `account` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`identifier` varchar(255) collate utf8_bin NOT NULL,
`hash` varchar(255) collate utf8_bin default NULL,
`date_create` datetime default NULL,
`group` varchar(50) collate utf8_bin default NULL,
`sub_group` varchar(50) collate utf8_bin NOT NULL default 'NULL',
`date_last_action` datetime default NULL,
`date_last_connection` datetime default NULL,
`connection_counter` int(10) unsigned default NULL,
`connection_since_customer` int(10) unsigned NOT NULL default '0',
`salt` varchar(255) collate utf8_bin default NULL,
`roles` longtext collate utf8_bin COMMENT '(DC2Type:array)',
`is_v3` tinyint(1) NOT NULL default '1',
`password_token` varchar(255) collate utf8_bin default NULL,
`password_token_expired_at` datetime default NULL,
`is_included_in_newsletters` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `identifier_UNIQUE` (`identifier`)
) ENGINE=MyISAM AUTO_INCREMENT=434243 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `address` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`city` varchar(64) collate utf8_bin default NULL,
`street` varchar(255) collate utf8_bin default NULL,
`complement` varchar(128) collate utf8_bin default NULL,
`zipcode` varchar(16) collate utf8_bin default NULL,
`country_id` int(11) default NULL,
`cedex` tinyint(1) NOT NULL default '0',
`abroad` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `IDX_D4E6F81F92F3E70` (`country_id`)
) ENGINE=MyISAM AUTO_INCREMENT=541873 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `customer` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`account` bigint(20) unsigned NOT NULL,
`source` varchar(250) collate utf8_bin NOT NULL default 'DECLARATION',
`last_source` varchar(250) collate utf8_bin NOT NULL,
`source_domain_name` varchar(255) collate utf8_bin default NULL,
`subscription_offer` varchar(255) collate utf8_bin default NULL,
`formalities_center_address` bigint(20) unsigned default NULL,
`customer_address` bigint(20) unsigned default NULL,
`business_address` bigint(20) unsigned default NULL,
`shipping_address` bigint(20) default NULL,
`activity` text collate utf8_bin,
`state` enum('NONE','CREATE','UPDATE','COMPLETE') collate utf8_bin NOT NULL default 'NONE',
`num_dossier` varchar(255) collate utf8_bin default NULL,
`email` varchar(255) collate utf8_bin NOT NULL,
`lastname` varchar(255) collate utf8_bin NOT NULL,
`firstname` varchar(255) collate utf8_bin NOT NULL,
`sexe` int(1) NOT NULL default '0',
`activityset` int(1) NOT NULL default '0',
`phone` varchar(16) collate utf8_bin NOT NULL,
`business_name` varchar(255) collate utf8_bin default NULL,
`payment_method` enum('NONE','CB_OK','CB_KO','CHEQUE_OK','CHEQUE_KO','WAITING','IMPACTPLUS_OK','PRELEV') collate utf8_bin default 'NONE',
`payment_waiting_comment` text collate utf8_bin,
`sub_sent_recovery` smallint(6) default '0',
`transaction_number` varchar(30) collate utf8_bin default NULL,
`transaction_date` datetime default NULL,
`properties` set('ACCRE','CFE','WANT_WEBSITE','HAVE_WEBSITE','NEWSLETTER','SUBSCRIBE','OLD_CUSTOMER') collate utf8_bin default NULL,
`comments` text collate utf8_bin,
`activity_declaration` varchar(512) collate utf8_bin default NULL COMMENT 'file:///',
`cfe_center` varchar(255) collate utf8_bin default NULL,
`date_create` datetime default NULL,
`date_complete` datetime default NULL,
`date_subscribe` datetime default NULL,
`date_next_payement` datetime default NULL,
`date_ae_subscribe` datetime default NULL,
`siret` varchar(128) collate utf8_bin default NULL,
`current_quotation` bigint(20) unsigned default NULL,
`current_invoice` bigint(20) unsigned default NULL,
`has_create_quotation` tinyint(1) NOT NULL default '0',
`has_create_invoice` tinyint(1) NOT NULL default '0',
`created_by` int(20) NOT NULL default '0',
`updated_by` int(11) NOT NULL default '0',
`updated_date` datetime default NULL,
`abo_running` tinyint(1) NOT NULL default '1',
`show_bn` tinyint(1) NOT NULL default '1',
`taxe_type_activite` enum('NULL','ACHAT','SERVICE','BOTH') collate utf8_bin default NULL,
`taxe_categorie_activite` enum('NULL','COMMERCIALE','ARTISANALE','CIPAV','RSI') collate utf8_bin default NULL,
`taxe_liberatoire` enum('NULL','OUI','NON') collate utf8_bin default NULL,
`taxe_statut_accre` enum('NULL','OUI','NON','DK') collate utf8_bin default NULL,
`know` varchar(50) collate utf8_bin default NULL,
`sms_relance` int(11) default NULL,
`fdae` int(1) NOT NULL default '0',
`display_fdae` tinyint(1) NOT NULL default '0',
`show_dispense_immat` enum('RCS','RM','RSAC') collate utf8_bin default NULL,
`show_dispense_immat_city` varchar(255) collate utf8_bin default NULL,
`subscription_fdae` date default NULL,
`nbsocial` varchar(30) collate utf8_bin default NULL,
`atclic` int(1) NOT NULL default '0',
`merassurance` int(1) NOT NULL default '0',
`dossier_canceled` tinyint(1) NOT NULL default '0',
`dossier_canceled_date` datetime default NULL,
`tva_intra` varchar(20) collate utf8_bin default NULL,
`site_url` varchar(100) collate utf8_bin default NULL,
`freeguide` tinyint(1) NOT NULL default '0',
`hiscox` int(1) NOT NULL default '0',
`assurland` int(1) NOT NULL default '0',
`unpaid_advisor` int(11) default NULL,
`unpaid_date` datetime default NULL,
`ecl_send` tinyint(1) default NULL,
`ecl_date` datetime default NULL,
`birthdateyear` int(11) NOT NULL default '0',
`quaCategorie` varchar(500) collate utf8_bin default NULL,
`quaNature` varchar(500) collate utf8_bin default NULL,
`quaType` varchar(500) collate utf8_bin default NULL,
`april` int(1) NOT NULL default '0',
`date_guide` datetime default NULL,
`no_pub` tinyint(1) NOT NULL default '0',
`campaign_manual` tinyint(1) NOT NULL default '0',
`export_matmut` date default NULL,
`formality_date` datetime default NULL,
`call_count_commerciaux` int(11) default '0',
`call_count_assistance` int(11) default '0',
`call_last` datetime default NULL,
`prospect` tinyint(1) default NULL,
`gender_id` int(11) default NULL,
`birthdate` date default NULL,
`current_customer_source_history_id` int(11) default NULL,
`original_customer_source_history_id` int(11) default NULL,
`bounce` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_81398E097D3656A4` (`account`),
UNIQUE KEY `UNIQ_81398E09E7927C74` (`email`),
UNIQUE KEY `UNIQ_81398E091193CB3F` (`customer_address`),
UNIQUE KEY `UNIQ_81398E09507DD4CC` (`business_address`),
UNIQUE KEY `UNIQ_81398E09BA38C653` (`formalities_center_address`),
KEY `num_dossier` (`num_dossier`),
KEY `sub_send_recovery` (`sub_sent_recovery`),
KEY `dossier_canceled` (`dossier_canceled`),
KEY `freeguide` (`freeguide`),
KEY `IDX_81398E09708A0E0` (`gender_id`),
KEY `IDX_81398E0935655550` (`current_customer_source_history_id`),
KEY `IDX_81398E0981A1F986` (`original_customer_source_history_id`)
) ENGINE=MyISAM AUTO_INCREMENT=433026 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `sf_user_data` (
`id` int(11) NOT NULL auto_increment,
`user_id` bigint(20) unsigned NOT NULL,
`register_id` int(11) default NULL,
`insurance_id` int(11) default NULL,
`activity_started_at` date default NULL,
`accre_request_accepted` tinyint(1) default NULL,
`accre_request_accepted_at` date default NULL,
`declaration_frequency_months` smallint(6) default NULL,
`declaration_reminder` tinyint(1) default NULL,
`activities_number` smallint(6) default NULL,
`computed_main_activity_percent_total` double default NULL,
`computed_secondary_activity_percent_total` double default NULL,
`company_address_is_personal_address` tinyint(1) default NULL,
`register_city` varchar(255) collate utf8_unicode_ci default NULL,
`invoice_last_increment` smallint(6) NOT NULL default '0',
`quotation_last_increment` smallint(6) NOT NULL default '0',
`asset_last_increment` smallint(6) NOT NULL default '0',
`payplug_parameters` varchar(255) collate utf8_unicode_ci default NULL,
`displayed_first_connection_dialog` tinyint(1) NOT NULL default '0',
`displayed_first_invoice_display_dialog` tinyint(1) NOT NULL default '0',
`payplug_parameters_created_at` date default NULL,
`payplug_first_payment_at` date default NULL,
`latest_payplug_http_code` int(11) default NULL,
`register_number` varchar(255) collate utf8_unicode_ci default NULL,
`register_code` varchar(255) collate utf8_unicode_ci default NULL,
`register_bis_city` varchar(255) collate utf8_unicode_ci default NULL,
`register_bis_number` varchar(255) collate utf8_unicode_ci default NULL,
`registerBis_id` int(11) default NULL,
`main_activity_type_id` int(11) default NULL,
`secondary_activity_type_id` int(11) default NULL,
`declaration_reminder_popup` tinyint(1) default NULL,
`declaration_reminder_popup_latest_choice` smallint(6) default NULL COMMENT '1 = Me le rappeler demain, 2 = Ne plus afficher cette alerte',
`declaration_reminder_popup_latest_choice_date` date default NULL,
`main_activity_id` int(11) default NULL,
`secondary_activity_id` int(11) default NULL,
`primary_socio_economic_classification_id` int(11) default NULL,
`secondary_socio_economic_classification_id` int(11) default NULL,
`income_bracket_id` int(11) default NULL,
`main_activity_custom` varchar(255) collate utf8_unicode_ci default NULL,
`secondary_activity_custom` varchar(255) collate utf8_unicode_ci default NULL,
`default_further_information` longtext collate utf8_unicode_ci,
`gclid` varchar(255) collate utf8_unicode_ci default NULL,
`main_activity_type_old_id` smallint(6) default NULL,
`main_activity_nature_old_id` smallint(6) default NULL,
`secondary_activity_type_old_id` smallint(6) default NULL,
`secondary_activity_nature_old_id` smallint(6) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_E904BFD1A76ED395` (`user_id`),
UNIQUE KEY `UNIQ_E904BFD1D1E63CD1` (`insurance_id`),
KEY `IDX_E904BFD14976CB7E` (`register_id`),
KEY `IDX_E904BFD1DBC024CC` (`registerBis_id`),
KEY `IDX_E904BFD12E864BE8` (`main_activity_type_id`),
KEY `IDX_E904BFD132198C62` (`secondary_activity_type_id`),
KEY `IDX_E904BFD15543A800` (`main_activity_id`),
KEY `IDX_E904BFD1798B8812` (`secondary_activity_id`),
KEY `IDX_E904BFD1D17B29D3` (`primary_socio_economic_classification_id`),
KEY `IDX_E904BFD17758CEBC` (`secondary_socio_economic_classification_id`),
KEY `IDX_E904BFD1BAF920D3` (`income_bracket_id`)
) ENGINE=MyISAM AUTO_INCREMENT=116384 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
It seems like this simple amendment will be faster:
SELECT COUNT(DISTINCT a0_.id) sclr0
FROM account a0_
JOIN customer c1_
ON c1_.account = a0_.id
JOIN address a3_
ON c1_.customer_address = a3_.id
And if data integrity is important to you, consider switching to InnoDB.
Change LEFT JOIN address a3 to plain JOIN. That way, the optimizer could consider starting with address. And add INDEX(city) to address.
Currently, the EXPLAIN is showing hitting 405K rows in each of 3 tables. (1.2M total) With the above change, the optimizer would start with the city index, there by looking at, say 1K rows. After that, it would look up 1K rows in each of the other two tables. (3K total)
LEFT JOIN sf_user_data s2_ ON (s2_.user_id = a0_.id) seems to be totally useless; remove it. (Now down to 2K rows)
Don't blindly use (255), use reasonable numbers. In doing so, if identifier is not very big, make it the PRIMARY KEY and get rid of id.
It is extremely rare to have 6 different columns each being UNIQUE. I think you will run into business-logic trouble because of it.

is there any methods to optimize a slow running query?

we are getting frequent slow log alerts because of below query.this query using indexes
i was tried to optimize this query but no luck support me to optimize slow query and how to improve the performance.
i want the output in best time.
My query is
select t.row_mod,
t.widget_info_id,
t.widget_name,
t.text1,
m.pretty_name,
w.website_id,
w.fol3_website_id
from fbw_info_text t,
fbw_info_meta m,
fol3_website w
where t.widget_info_id = m.widget_info_id
and t.widget_name = m.widget_name
and (
m.widget_type = 'checkbox'
or t.widget_name in (
'ccapi_approved_transactions_msg',
'ccapi_declined_transactions_msg',
'ccapi_failed_transactions_msg'
)
)
and t.website_id = w.website_id
and (
(t.row_mod >= '2013-10-24 20:57:32'
and t.row_mod <= '2013-10-24 20:59:32')
or
(m.row_mod >= '2013-10-24 20:57:32'
and m.row_mod <= '2013-10-24 20:59:32')
)
order by widget_info_id, widget_name;
Explain Plan:
+----+-------------+-------+-------+-------------------------------------+----------+---------+----------------------------------------+-------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+-------------------------------------+----------+---------+----------------------------------------+-------+----------------------------------------------+
| 1 | SIMPLE | w | index | idx_1055,idx_1786 | idx_1522 | 4 | NULL | 25953 | Using index; Using temporary; Using filesort |
| 1 | SIMPLE | t | ref | idx_4639,idx_1055,idx_2718,idx_3388 | idx_1055 | 53 | cms.w.website_id | 12 | Using where |
| 1 | SIMPLE | m | ref | idx_2718 | idx_2718 | 105 | cms.t.widget_name,cms.t.widget_info_id | 1 | Using where |
+----+-------------+-------+-------+-------------------------------------+----------+---------+----------------------------------------+-------+----------------------------------------------+
3 rows in set (0.01 sec)
Table structures
mysql> show create table fbw_info_text\G
*************************** 1. row ***************************
Table: fbw_info_text
Create Table: CREATE TABLE `fbw_info_text` (
`row_mod` datetime DEFAULT NULL,
`row_create` datetime DEFAULT NULL,
`widget_info_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`widget_name` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`website_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`text1` longtext COLLATE latin1_bin,
`text2` longtext COLLATE latin1_bin,
`submitted_user_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`use_default` varchar(1) COLLATE latin1_bin DEFAULT NULL,
`active_flag` varchar(1) COLLATE latin1_bin DEFAULT NULL,
`status` varchar(1) COLLATE latin1_bin DEFAULT NULL,
UNIQUE KEY `idx_4639` (`website_id`,`widget_info_id`,`widget_name`,`status`),
KEY `idx_1055` (`website_id`),
KEY `idx_2718` (`widget_info_id`,`widget_name`),
KEY `idx_3388` (`widget_info_id`,`website_id`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
1 row in set (0.01 sec)
mysql> show create table fbw_info_meta\G
*************************** 1. row ***************************
Table: fbw_info_meta
Create Table: CREATE TABLE `fbw_info_meta` (
`row_mod` datetime DEFAULT NULL,
`row_create` datetime DEFAULT NULL,
`widget_name` varchar(50) COLLATE latin1_bin NOT NULL,
`pretty_name` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`widget_info_id` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`widget_type` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`needs_approval` varchar(1) COLLATE latin1_bin DEFAULT NULL,
`widget_value` longtext COLLATE latin1_bin,
`widget_order` int(11) DEFAULT NULL,
`widget_attributes` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`capability_name` varchar(30) COLLATE latin1_bin DEFAULT NULL,
`design_type` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`on_approval_hook` longtext COLLATE latin1_bin,
`display_hook` longtext COLLATE latin1_bin,
`status` varchar(1) COLLATE latin1_bin DEFAULT NULL,
`needs_archive` varchar(1) COLLATE latin1_bin DEFAULT NULL,
UNIQUE KEY `idx_2718` (`widget_name`,`widget_info_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
1 row in set (0.00 sec)
mysql> show create table fol3_website\G
*************************** 1. row ***************************
Table: fol3_website
Create Table: CREATE TABLE `fol3_website` (
`row_mod` datetime DEFAULT NULL,
`row_create` datetime DEFAULT NULL,
`fol3_website_id` int(11) NOT NULL,
`website_id` varchar(50) COLLATE latin1_bin NOT NULL,
`activate_default_host` int(11) DEFAULT '0',
`active` int(11) NOT NULL DEFAULT '1',
`advance_notice_days` int(11) DEFAULT '0',
`catrequest` int(11) DEFAULT '0',
`chain` int(11) DEFAULT NULL,
`color_scheme` varchar(30) COLLATE latin1_bin DEFAULT NULL,
`conversion_rate` int(11) DEFAULT '0',
`comment` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`creation_date` datetime DEFAULT NULL,
`defunct_2` varchar(5) COLLATE latin1_bin DEFAULT NULL,
`default_website` varchar(50) COLLATE latin1_bin NOT NULL,
`designtype` varchar(25) COLLATE latin1_bin DEFAULT NULL,
`key_contact_name` varchar(55) COLLATE latin1_bin DEFAULT NULL,
`key_contact_phone` varchar(60) COLLATE latin1_bin DEFAULT NULL,
`language_id` varchar(5) COLLATE latin1_bin DEFAULT NULL,
`defunct_0` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`mercury` int(11) NOT NULL DEFAULT '1',
`mgnt_defaults_last_applied` datetime DEFAULT NULL,
`rank` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`return_url` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`defunct_1` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`store_id` varchar(15) COLLATE latin1_bin NOT NULL,
`defunct_3` varchar(10) COLLATE latin1_bin DEFAULT NULL,
`display_website_url` varchar(25) COLLATE latin1_bin DEFAULT NULL,
`webloyalty` int(11) DEFAULT NULL,
`name` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`transmission_type` int(11) DEFAULT NULL,
`segment` int(11) DEFAULT NULL,
`site_id` varchar(25) COLLATE latin1_bin DEFAULT NULL,
`canonical_status` int(1) DEFAULT '0',
`canonical_domain` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`mobile_site_active` tinyint(1) DEFAULT '1',
UNIQUE KEY `idx_1055` (`website_id`),
UNIQUE KEY `idx_1522` (`fol3_website_id`),
UNIQUE KEY `idx_1786` (`website_id`,`active`),
KEY `idx_1867` (`transmission_type`),
KEY `idx_857` (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
1 row in set (0.00 sec)
You can try SHOW Profiling functionality of MySQL to find out where most of the time has been taken by a query execution and optimize based on result:
set profiling=1;
Run your slow query (eg SELECT * FROM table WHERE name='xxx';
SHOW PROFILES;
http://dev.mysql.com/doc/refman/5.0/en/show-profile.html
Analyze EXPLAIN EXTENED output and optimize query accourdingly and profile the query again to see gain in performance.

MySQL Update Issue - NULL fields get updated, but not fields already containing data

I am struggling with a MySQL query. Here's the problem:
SELECT * from sf_forecasts WHERE contentid='1234' AND fulldate='2012-12-13'
There is one record in my table that matches this criteria, and this query finds it with no difficulty. However, when I move to update it using this query...
UPDATE sf_forecasts
SET listingTitle ='Some Snow Resort', location ='49.23, -115.22'
WHERE contentid='1234' AND fulldate='2012-12-13'
...I always get a notice of "0 rows affected." Strangely, the query is actually updating the record, but it's only touching fields that are NULL. If my example record has a 'location' value of NULL, the query will update the data, but if it already contains a non-NULL value, the query will not change it, even though the query clearly contains new information.
What gives?
P.S. I am using a PRIMARY key of contentid+fulldate (b-tree, unique) if this matters.
P.S.S. Here is the 'SHOW CREATE TABLE sf_forecasts' results as requested below:
sf_forecasts CREATE TABLE `sf_forecasts` (
`contentid` int(11) NOT NULL,
`fulldate` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`listingTitle` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`location` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`dayofmonth` smallint(2) NOT NULL,
`dayofweek` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`minTempF` smallint(4) NOT NULL,
`maxTempF` smallint(4) NOT NULL,
`minTempC` smallint(4) NOT NULL,
`maxTempC` smallint(4) NOT NULL,
`skyCondition` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`precip` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`snowPotential` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`wind` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`minTempF_custom` smallint(4) DEFAULT NULL,
`maxTempF_custom` smallint(4) DEFAULT NULL,
`minTempC_custom` smallint(4) DEFAULT NULL,
`maxTempC_custom` smallint(4) DEFAULT NULL,
`baseH_custom` smallint(4) DEFAULT NULL,
`baseL_custom` smallint(4) DEFAULT NULL,
`topH_custom` smallint(4) DEFAULT NULL,
`topL_custom` smallint(4) DEFAULT NULL,
`skyCondition_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`precip_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`snowPotential_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`wind_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`icon` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`icon_custom` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
`shortrange_custom` varchar(5000) COLLATE utf8_unicode_ci DEFAULT NULL,
`longrange_custom` varchar(5000) COLLATE utf8_unicode_ci DEFAULT NULL,
`scCode` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`scUpdate` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`lastUpdate` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`skys` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`contentid`,`fulldate`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
The issue is with difference in datatype length defined and length of data being updated
Your location is varchar(10) and you are trying to insert 14 characters
You can always check if there are errors after query execution:
SHOW ERRORS;
SHOW WARNINGS;