Advertisement

12.21.2007 at 09:20AM PST, ID: 23038602
[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!

7.2

help speeding up a query

Asked by theamzngq in MySQL Server, ColdFusion Application Server

Tags: , , , ,

I have a query that works correctly, but is very slow to execute.  Can anyone suggest a faster way to write it, or deal with it?  I'm also using coldfusion for the logic portion, just so you know.

The `jobsworked` and `timein` tables store staff time entries per job.  The job info is stored in the `jobitems` table, and staff info in the `staff` table.  Staff billing rates are in the `billingrates` table.  The Job Cost is calculated by multiplying the hours worked on a job by the rate that was in effect at the time the hours were worked (timein.dateworked column, as well as billingrates.validasof).  As I mentioned, the query below works perfectly, but it is slow.  I'm trying to find a way to re-write it, or better index my tables, to speed it up.

I'll list the query here, and below the source code for all the tables:

select jobsworked.jobitemsid,jobcostlink,namedisplay,jobsworked.staffid,hours,dateworked,
                              (SELECT rate FROM billingrates WHERE staffid=staff.staffid AND validasof <= timein.dateworked
                                    ORDER BY validasof DESC LIMIT 1) AS rate,
                              (SELECT validasof FROM billingrates      WHERE staffid=staff.staffid AND validasof <= timein.dateworked
                                    ORDER BY validasof DESC      LIMIT 1) AS validasof
                              from timein
                              inner join jobsworked using(jobsworkedid)
                              inner join staff on staff.staffid = jobsworked.staffid
                              inner join jobitems on jobitems.jobitemsid = jobsworked.jobitemsid
                              where jobsworked.jobitemsid in (#list_of_jobitemsids#) and hours > 0
                              order by namedisplay

Tables:
CREATE TABLE `jobsworked` (
  `JobsWorkedID` int(10) unsigned NOT NULL auto_increment,
  `StaffID` int(10) NOT NULL default '0',
  `JobItemsID` int(10) NOT NULL default '0',
  `WorkDescription` text NOT NULL,
  `ForWeekStarting` date default NULL,
  PRIMARY KEY  (`JobsWorkedID`),
  KEY `jwid_jiid_idx` (`JobsWorkedID`,`JobItemsID`)
) ENGINE=MyISAM AUTO_INCREMENT=200698 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

CREATE TABLE `timein` (
  `TimeInID` int(10) unsigned NOT NULL auto_increment,
  `DateWorked` date NOT NULL default '0000-00-00',
  `JobsWorkedID` int(10) NOT NULL default '0',
  `Hours` float(10,2) NOT NULL default '0.00',
  `Pushed` int(1) NOT NULL default '0',
  PRIMARY KEY  (`TimeInID`),
  KEY `jwid_hours_timein_idx` (`JobsWorkedID`,`Hours`)
) ENGINE=MyISAM AUTO_INCREMENT=1213784 DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED;

CREATE TABLE `staff` (
  `StaffID` int(5) NOT NULL auto_increment,
  `FirstName` varchar(50) default NULL,
  `Middle` varchar(50) NOT NULL default '',
  `LastName` varchar(50) default NULL,
  `Dept` varchar(5) NOT NULL default '',
  `SubDivision` varchar(25) NOT NULL default '',
  `NameDisplay` varchar(50) default NULL
  PRIMARY KEY  (`StaffID`),
  UNIQUE KEY `StaffID` (`StaffID`,`Status`,`NameDisplay`)
) ENGINE=MyISAM AUTO_INCREMENT=408 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

CREATE TABLE `jobitems` (
  `JobItemsID` int(10) NOT NULL auto_increment,
  `Description` text NOT NULL,
  PRIMARY KEY  (`JobItemsID`),
  KEY `jiid_ciid_idx` (`JobItemsID`,`CompanyInfoID`),
  KEY `jiid_jobitems_idx` (`JobItemsID`,`JobsID`,`Status`)
) ENGINE=MyISAM AUTO_INCREMENT=52619 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

CREATE TABLE `billingrates` (
  `BillingRateID` int(10) NOT NULL auto_increment,
  `staffid` int(10) default NULL,
  `name` varchar(255) default NULL,
  `rate` smallint(5) default NULL,
  `validasof` date default NULL,
  PRIMARY KEY  (`BillingRateID`),
  KEY `staffid` (`staffid`,`rate`)
) ENGINE=MyISAM AUTO_INCREMENT=601 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
Start Free Trial
[+][-]12.21.2007 at 09:24AM PST, ID: 20515011

View this solution now by starting your 7-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: MySQL Server, ColdFusion Application Server
Tags: dynamic, query, row_format, speeding, up
Sign Up Now!
Solution Provided By: asvforce
Participating Experts: 2
Solution Grade: A
 
 
[+][-]12.21.2007 at 11:20AM PST, ID: 20515734

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.21.2007 at 11:30AM PST, ID: 20515810

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.21.2007 at 03:27PM PST, ID: 20517072

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.21.2007 at 11:12PM PST, ID: 20517956

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.22.2007 at 12:53AM PST, ID: 20518071

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.09.2008 at 04:29PM PST, ID: 20623903

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.09.2008 at 04:31PM PST, ID: 20623910

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.10.2008 at 11:41AM PST, ID: 20630278

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.10.2008 at 01:03PM PST, ID: 20631190

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.10.2008 at 02:40PM PST, ID: 20632178

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.10.2008 at 02:55PM PST, ID: 20632283

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.10.2008 at 03:00PM PST, ID: 20632315

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628