Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL 4.1 Subquery Performance SLOW


MySQL 4.1 Subquery Performance SLOW

Closed Thread
  #1 (permalink)  
Old 06-04-04, 03:48 PM
TokenSDragon TokenSDragon is offline
New Member
 
Join Date: Jun 2004
Location: Dayton, Ohio
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL 4.1 Subquery Performance SLOW

I've got a bit of a problem. I'm supposed to port an existing nicely optimized database over from MSSQL to MySQL. So now with Subquery capabilities in MySQL that's at least an option... the problem is they are about a billion times SLOWER in MySQL. (and unfortunately I'm not exagerating)

Is there a syntax issue I'm missing?

Database tables are as follows:
Patients (this has a single record for each patient)
Evals (this has multiple records for each patient id. )

(pretty darn simple ey?)

Goal: I need to return the Total number of unique patients with 2 or more entries in the evals table that fall within a certain Patient_ID range.

Query: --------------------------------------------------
SELECT COUNT(*)
FROM Patients
WHERE Key_ID IN
(
SELECT DISTINCT Evals.Patient_ID FROM Evals
INNER JOIN Patients ON Patients.Key_ID = Evals.Patient_ID
WHERE (Evals.Location_ID = 2)
AND (Patients.Center_ID = 2)
AND (Patients.Key_ID >= 820)

GROUP BY Evals.Patient_ID
HAVING (COUNT(Evals.Patient_ID) > 1))
)
------------------------------------------------------------------

The same exact query runs in the following amount of time:
MSSQL response time: 0.01 seconds
MySQL 4.1 response time: 78 seconds.

Is there another way to write this query? Is there a bug in MySQL? Is there a workaround in MySQL? Any suggestions would be happily appreciated.
  #2 (permalink)  
Old 06-15-07, 12:32 PM
sebastianmacias sebastianmacias is offline
New Member
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by TokenSDragon View Post

The same exact query runs in the following amount of time:
MSSQL response time: 0.01 seconds
MySQL 4.1 response time: 78 seconds.

Is there another way to write this query? Is there a bug in MySQL? Is there a workaround in MySQL? Any suggestions would be happily appreciated.
You might consider rewriting the queries to use JOINS instead of sub queries. Performance will improve a lot! I guarantee it.

Sebastian Macias
Senior Web Software Engineer
digital-telepathy inc.
  #3 (permalink)  
Old 06-15-07, 12:46 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Please don't bump 3 year old topics.


Closed.
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
mysql crash IMPORTANT comby PHP 0 03-02-04 10:27 AM
great product for dumping/recovering MySQL databases Dave Brown General Advertisements 1 10-03-03 07:40 AM


All times are GMT -5. The time now is 10:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.