[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Query, view and table optimization

Asked by WarrenBarrett in SQL Query Syntax, MySQL Server, Databases Miscellaneous

Tags: Sun, MySQL, 5.0.27, SQL

I am trying to optimize the 2 queries below (one of them is a view), but I cant figure out how to get it to use the indexes I have set up.
The queries are run a minimum of 900 times every 2 minutes, so I would like them to be as optimized as possible.
I have included all the relevant tables so you can see how I have set everything up. I dont know if it matters, but the only table that is updated regularly is tblflightdata (every 2 minutes it is truncated and repopulated with new data), the other 3 tables are updated relatively infrequently.
In the bottom query: 'USA5286' is unique, 'JFK' could be one of 2 values (currently, may be higher at a later date, but probably not more than 10 values), the last value is always 'U'.
I have also included the result of an EXPLAIN executed on the query (which uses the view).

Hope you can help,
Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `qryflightdatadetail` AS select `fu`.`ID` AS `ID`,`fu`.`tempId` AS `tempId`,`fu`.`airport` AS `airport`,`ic1`.`City` AS `AirportCityName`,`fu`.`recordType` AS `recordType`,`fu`.`boundType` AS `boundType`,`fu`.`airline` AS `airline`,`fu`.`FlightNumber` AS `FlightNumber`,`fu`.`flightdate` AS `flightdate`,`fu`.`schTime` AS `schTime`,`fu`.`estTime` AS `estTime`,`fu`.`flightType` AS `flightType`,`fu`.`carrierType` AS `carrierType`,`fu`.`cityI` AS `cityI`,`ic2`.`City` AS `CityIName`,`fu`.`cityII` AS `cityII`,`ic3`.`City` AS `CityIIName`,`fu`.`cityIII` AS `cityIII`,`ic4`.`City` AS `CityIIIName`,`fu`.`StatusRemark` AS `StatusRemark`,`sr`.`KeyDescription` AS `FlightStatus`,`fu`.`bagClaim` AS `bagClaim`,`fu`.`gate` AS `gate`,`fu`.`flightKey` AS `flightKey`,`fu`.`terminal` AS `terminal` from (((((`tblflightdata` `FU` left join `tbliatacodes` `IC2` on `fu`.`cityI` = `ic2`.`ShortCode`) left join `tbliatacodes` `IC3` on `fu`.`cityII` = `ic3`.`ShortCode`) left join `tbliatacodes` `IC4` on `fu`.`cityIII` = `ic4`.`ShortCode`) left join `tblstatusremarks` `SR` on (`fu`.`StatusRemark` = `sr`.`LookupID` and `fu`.`flightType` = `sr`.`FlightType` and `fu`.`boundType` = `sr`.`BoundType`)) left join `tbliatacodes` `IC1` on `fu`.`airport` = `ic1`.`ShortCode`);
 
SELECT DISTINCT FDD.AirportCityName, FDD.boundType, FDD.airline, FDD.FlightNumber, FDD.flightdate, FDD.schTime, FDD.estTime, FDD.CityIName, FDD.CityIIName, FDD.CityIIIName, FDD.FlightStatus, FDD.bagClaim, FDD.gate, FDD.terminal, MC.PlaneStatus, FD.StatusRemark, FD.statusCompare AS ContentLookupCode FROM (qryFlightDataDetail AS FDD LEFT JOIN tblMessageContent as MC ON MC.StatusName = FDD.FlightStatus) LEFT JOIN tblFlightData AS FD ON FD.FlightNumber = FDD.FlightNumber WHERE FDD.FlightNumber='USA5286' AND FDD.airport='JFK' AND FD.StatusCompare <> 'U';
 
 
id 	select_type 	table 	type 	possible_keys 	key 	key_len 	ref 	rows 	Extra
1 	SIMPLE 	FU 	ALL 	airport 	NULL 	NULL 	NULL 	578 	Using where; Using temporary
1 	SIMPLE 	IC2 	ALL 	ShortCode 	NULL 	NULL 	NULL 	4124 	 
1 	SIMPLE 	IC3 	ALL 	ShortCode 	NULL 	NULL 	NULL 	4124 	 
1 	SIMPLE 	IC4 	ALL 	ShortCode 	NULL 	NULL 	NULL 	4124 	 
1 	SIMPLE 	SR 	ref 	BoundType,FlightType,LookupID 	LookupID 	4 	Boo.FU.StatusRemark 	1 	 
1 	SIMPLE 	MC 	ALL 	StatusName 	NULL 	NULL 	NULL 	58 	 
1 	SIMPLE 	FD 	ALL 	NULL 	NULL 	NULL 	NULL 	578 	Using where
1 	SIMPLE 	IC1 	ALL 	ShortCode 	NULL 	NULL 	NULL 	4124 	 
 
 
CREATE TABLE IF NOT EXISTS `tblflightdata` (
  `ID` int(5) NOT NULL auto_increment,
  `tempId` int(1) NOT NULL,
  `airport` tinytext collate utf8_unicode_ci NOT NULL,
  `recordType` enum('D+') collate utf8_unicode_ci NOT NULL,
  `boundType` enum('I','O') collate utf8_unicode_ci NOT NULL,
  `airline` tinytext collate utf8_unicode_ci NOT NULL,
  `FlightNumber` tinytext collate utf8_unicode_ci NOT NULL,
  `flightdate` tinytext collate utf8_unicode_ci NOT NULL,
  `schTime` tinytext collate utf8_unicode_ci NOT NULL,
  `estTime` tinytext collate utf8_unicode_ci NOT NULL,
  `flightType` enum('D','I') collate utf8_unicode_ci NOT NULL,
  `carrierType` enum('P') collate utf8_unicode_ci NOT NULL,
  `cityI` tinytext collate utf8_unicode_ci NOT NULL,
  `cityII` tinytext collate utf8_unicode_ci NOT NULL,
  `cityIII` tinytext collate utf8_unicode_ci NOT NULL,
  `StatusRemark` int(5) NOT NULL,
  `bagClaim` tinytext collate utf8_unicode_ci NOT NULL,
  `gate` tinytext collate utf8_unicode_ci NOT NULL,
  `flightKey` tinytext collate utf8_unicode_ci NOT NULL,
  `terminal` tinytext collate utf8_unicode_ci NOT NULL,
  `statusCompare` enum('C','N','U') collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`ID`),
  KEY `flightKey` (`flightKey`(20)),
  KEY `StatusRemark` (`StatusRemark`),
  KEY `airport` (`airport`(3)),
  KEY `boundType` (`boundType`),
  KEY `flightType` (`flightType`),
  KEY `cityI` (`cityI`(3)),
  KEY `cityII` (`cityII`(3)),
  KEY `cityIII` (`cityIII`(3))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=679 ;
 
CREATE TABLE IF NOT EXISTS `tbliatacodes` (
  `ID` int(5) NOT NULL auto_increment,
  `ShortCode` tinytext collate utf8_unicode_ci NOT NULL,
  `City` tinytext collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`ID`),
  KEY `ShortCode` (`ShortCode`(3))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4277 ;
 
CREATE TABLE IF NOT EXISTS `tblstatusremarks` (
  `ID` int(6) NOT NULL auto_increment,
  `BoundType` enum('I','O','X') collate utf8_unicode_ci NOT NULL,
  `FlightType` enum('D','I') collate utf8_unicode_ci NOT NULL,
  `LookupID` int(5) NOT NULL,
  `KeyDescription` tinytext collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`ID`),
  KEY `BoundType` (`BoundType`),
  KEY `FlightType` (`FlightType`),
  KEY `LookupID` (`LookupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=133 ;
 
CREATE TABLE IF NOT EXISTS `tblmessagecontent` (
  `id` int(5) NOT NULL auto_increment,
  `PlaneStatus` int(5) NOT NULL,
  `StatusName` tinytext collate utf8_unicode_ci NOT NULL,
  `SendMethod` enum('E','S') collate utf8_unicode_ci NOT NULL,
  `Content` text collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `StatusName` (`StatusName`(20))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=59 ;
[+][-]07/29/08 12:05 PM, ID: 22114445Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: SQL Query Syntax, MySQL Server, Databases Miscellaneous
Tags: Sun, MySQL, 5.0.27, SQL
Sign Up Now!
Solution Provided By: virmaior
Participating Experts: 1
Solution Grade: B
 
[+][-]08/07/08 01:36 AM, ID: 22178924Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/11/08 11:19 AM, ID: 22206804Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/11/08 11:25 AM, ID: 22206854Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_2_20070628