473,395 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help with optimization of queries

My queries have been taking really really long to load these last few weeks, and I'm guessing it could be because of more users and increased table size. Anyway the table that's involved is as follows:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE IF NOT EXISTS `dsitesubmissions` (
  2.   `submit_id` int(11) NOT NULL auto_increment,
  3.   `siteid` int(11) NOT NULL default '0',
  4.   `did` int(11) NOT NULL default '0',
  5.   `transactionid` int(11) NOT NULL default '0',
  6.   `registration_date` datetime NOT NULL default '0000-00-00 00:00:00',
  7.   `submission_date` datetime default NULL,
  8.   `approved` enum('Unknown','Rejected','Approved') default 'Unknown',
  9.   `link_location` varchar(255) default NULL,
  10.   `tdid` int(11) default NULL,
  11.   `payment_status` enum('Paid','Unpaid','Previous Submission','Custom') NOT NULL default 'Unpaid',
  12.   `operator_id` int(10) NOT NULL default '0',
  13.   `time_taken` decimal(10,2) NOT NULL default '0.00',
  14.   `trylater` int(11) NOT NULL default '0',
  15.   `skipped` int(11) NOT NULL default '0',
  16.   `url_error` int(11) NOT NULL default '0',
  17.   `link_urls` varchar(255) NOT NULL default 'none',
  18.   `link_text` varchar(255) NOT NULL default 'none',
  19.   `category_text` varchar(255) NOT NULL default 'none',
  20.   `category_index` int(10) NOT NULL default '0',
  21.   PRIMARY KEY  (`submit_id`),
  22.   UNIQUE KEY `sd` (`siteid`,`did`),
  23.   KEY `registration_date` (`registration_date`),
  24.   KEY `submission_date` (`submission_date`),
  25.   KEY `transactionid` (`transactionid`),
  26.   KEY `siteid` (`siteid`),
  27.   KEY `did` (`did`),
  28.   KEY `tdid` (`tdid`)
  29. ) ENGINE=MyISAM 
  30.  
It has 4.5 million records and the query that's been taking long is shown below:
Expand|Select|Wrap|Line Numbers
  1. SELECT submit_id
  2. FROM dsitesubmissions AS a, dsitedetails c
  3. WHERE (submission_date IS NULL OR submission_date='0000-00-00 00:00:00'
  4. )
  5. AND payment_status = 'Paid'
  6. AND c.status = 'Active'
  7. AND DATE_FORMAT( a.registration_date, '%Y-%m-%d' ) <= CURDATE( )
  8. AND c.siteid = a.siteid
  9. AND selection_needed = 'No'
  10.  
When I do an explain it shows:

Expand|Select|Wrap|Line Numbers
  1. select_type     table     type     possible_keys     key     ref     rows     Extra
  2.  
  3. SIMPLE     a     ref_or_null     sd,submission_date,siteid     submission_date     const     67587     Using where
  4.  
  5. SIMPLE     c     eq_ref     PRIMARY     PRIMARY     inksmax_main.a.siteid     1     Using where
  6.  
While I think 67000 is a relatively small number of rows out of the 4.6 million rows, I dont know why the query's been taking so long...could it be a problem that there are inserts/updates also taking place on the same table every few seconds concurrently while the selects are being run? If so, that's a situation I cannot avoid.

I need a solution fast.
Aug 21 '08 #1
1 1358
mwasif
802 Expert 512MB
Change
Expand|Select|Wrap|Line Numbers
  1. DATE_FORMAT( a.registration_date, '%Y-%m-%d' ) <= CURDATE( )
to
Expand|Select|Wrap|Line Numbers
  1. a.registration_date <= NOW( )
Do you have index on c.siteid? If it is not, then create an index on it.

Now do an EXPLAIN and compare the results.
Aug 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: JustSomeGuy | last post by:
I have a routine that evaluates a polynomial equation that have 3 variables x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array. This routine is quite slow and I'd like to...
0
by: Jesse Sheidlower | last post by:
I'm struggling with speed issues on some queries that I would have expected to be relatively fast. Perhaps even more frustratingly, when I've tried to break these down into their components, they...
2
by: ensnare | last post by:
This query is running REAL slow ... like 1.2 secs ... any ideas on how I could optimize it? Perhaps my indexes are incorrect? $this->query = "SELECT m.username as username, e.title as title,...
20
by: andy.rich | last post by:
I am getting the following error and I do not know why. Can anyone help? -------------------------------------------------------- this is what appears on the screen...
19
by: nospammmer | last post by:
Hello group, I have a rather general but interesting inquiry that is related to PHP and I hope this is the appropriate place to post it. I'm looking for a way to improve dramatically the...
13
by: LUIS FAJARDO | last post by:
I have the following sintax: Select * From Inventory Where PartId = Coalesce(v_PartId, PartId) this type of query is used within an store procedure that provide the v_PartId parameter, the...
5
by: Praveen_db2 | last post by:
Dear All Db2 version: 8.1 OS: Windows I have 2 questions: 1) What is the optimizer which db2 uses, rule based or cost based? If any one can clear out the difference between the two it will be...
2
by: Ruggiero | last post by:
Sorry for my bad english What is the optimization technique used by Access dbms? Thanks
8
by: deko | last post by:
I'm trying to open a Recordset based on a parameterized query. I'm kind of new to parameterized queries, so I'm sure I'm missing something simple. Set qdfs = db.QueryDefs Set qdf =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.