473,396 Members | 1,655 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,396 software developers and data experts.

This query is very slow; how can I optimize it?

chathura86
227 100+
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.  
  3. MINIMUMPAYMENT.CARDNO,
  4. CARD.NAMEONCARD, 
  5. MINIMUMPAYMENT.MINPAYMENTCOUNT, 
  6. CARD.CREDITLIMIT, 
  7. LASTSTATEMENTSUMMARY.MINAMOUNT AS MIN_PYM, 
  8. CARDTYPE.NAME 
  9.  
  10. FROM 
  11.  
  12. MINIMUMPAYMENT, CARD, CARDTYPE, LASTSTATEMENTSUMMARY
  13.  
  14. WHERE 
  15.  
  16. (CARD.CARDNO = MINIMUMPAYMENT.CARDNO AND CARDTYPE.ID = CARD.CARDTYPEID 
  17. AND LASTSTATEMENTSUMMARY.CARDNO = CARD.CARDNO) AND 
  18. NOT EXISTS(SELECT CRASMF.CARDNO FROM CRASMF WHERE CRASMF.CARDNO = MINIMUMPAYMENT.CARDNO AND CRASMF.STATUS!=2)
Please some one help me to optimize this query because it takes some time to give the resut.the tables are very big, some contains more than 60,000 records.

Regards,

Chathura Bamunusinghe.
Oct 6 '07 #1
5 1470
pbmods
5,821 Expert 4TB
Heya, Chathura.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

[CODE=mysql]
MySQL code goes here.
[/CODE]

What do you get when you EXPLAIN your query?
Oct 6 '07 #2
chathura86
227 100+
Heya, Chathura.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

Expand|Select|Wrap|Line Numbers
  1. MySQL code goes here.
  2.  
What do you get when you EXPLAIN your query?

[HTML]<h3>query result(5 records)</h3><table border=1>
<tr>
<td bgcolor=silver class='medium'>id</td><td bgcolor=silver class='medium'>select_type</td><td bgcolor=silver class='medium'>table</td><td bgcolor=silver class='medium'>type</td><td bgcolor=silver class='medium'>possible_keys</td><td bgcolor=silver class='medium'>key</td><td bgcolor=silver class='medium'>key_len</td><td bgcolor=silver class='medium'>ref</td><td bgcolor=silver class='medium'>rows</td><td bgcolor=silver class='medium'>Extra</td></tr>
<tr>
<td class='normal' valign='top'>1</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>MINIMUMPAYMENT</td>
<td class='normal' valign='top'>ALL</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>(NULL)</td>
<td class='normal' valign='top'>(NULL)</td>
<td class='normal' valign='top'>(NULL)</td>
<td class='normal' valign='top'>1286</td>
<td class='normal' valign='top'>Using where</td>
</tr>
<tr>
<td class='normal' valign='top'>1</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>LASTSTATEMENTSUMMARY</td>
<td class='normal' valign='top'>eq_ref</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>18</td>
<td class='normal' valign='top'>abccreditcard.MINIMUMPAYMENT.CARDNO</td>
<td class='normal' valign='top'>1</td>
<td class='normal' valign='top'>&nbsp;</td>
</tr>
<tr>
<td class='normal' valign='top'>1</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>CARD</td>
<td class='normal' valign='top'>eq_ref</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>18</td>
<td class='normal' valign='top'>abccreditcard.MINIMUMPAYMENT.CARDNO</td>
<td class='normal' valign='top'>1</td>
<td class='normal' valign='top'>&nbsp;</td>
</tr>
<tr>
<td class='normal' valign='top'>1</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>CARDTYPE</td>
<td class='normal' valign='top'>eq_ref</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>PRIMARY</td>
<td class='normal' valign='top'>4</td>
<td class='normal' valign='top'>abccreditcard.CARD.CARDTYPEID</td>
<td class='normal' valign='top'>1</td>
<td class='normal' valign='top'>&nbsp;</td>
</tr>
<tr>
<td class='normal' valign='top'>2</td>
<td class='normal' valign='top'>DEPENDENT SUBQUERY</td>
<td class='normal' valign='top'>CRASMF</td>
<td class='normal' valign='top'>ALL</td>
<td class='normal' valign='top'>(NULL)</td>
<td class='normal' valign='top'>(NULL)</td>
<td class='normal' valign='top'>(NULL)</td>
<td class='normal' valign='top'>(NULL)</td>
<td class='normal' valign='top'>1899</td>
<td class='normal' valign='top'>Using where</td>
</tr>
</table>[/HTML]

this is what i got when i export it to html. couldnt find a way to attach it or send it as an image.

regards,
Oct 6 '07 #3
pbmods
5,821 Expert 4TB
Heya, Chathura.

Looks like your CRASMF table might not be indexed properly. Be sure that both the CARDNO and STATUS columns are indexed.

Also note that you are returning every single row from MINIMUMPAYMENT. This might be desirable, or it might not. You might want to add a LIMIT clause to your query.
Oct 6 '07 #4
chathura86
227 100+
Heya, Chathura.

Looks like your CRASMF table might not be indexed properly. Be sure that both the CARDNO and STATUS columns are indexed.

Also note that you are returning every single row from MINIMUMPAYMENT. This might be desirable, or it might not. You might want to add a LIMIT clause to your query.
created the indexes but still no different.
cannot put a LIMIT because i want all the rows.

regards,
Oct 6 '07 #5
chathura86
227 100+
created the indexes but still no different.
cannot put a LIMIT because i want all the rows.

regards,
Found the problem. it was caused by a bad relationship

Thanks for the help.

regards.
Oct 10 '07 #6

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

Similar topics

5
by: Shay | last post by:
essentially I am trying to do some counts based on some assumptions in the recordset. So I get the RS back, put the values into a variable, move to the next record in the RS and compare what is in...
5
by: xeqister | last post by:
Greetings all, We have a complicated statement in DB2 which takes long hour to complete and we have created most of the indexes. Does anybody knows how to tune the following statement to optimize...
4
by: Huaer.XC | last post by:
>From the following MySQL command: EXPLAIN SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id) JOIN t3 ON t3.name = t1.name WHERE t1.id IN(123, 124); which result is:...
10
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All...
19
by: octangle | last post by:
This code is attempting to find records that have a RegJrnID that does not occur more than one time in the table. The reason that I want to find records with non-duplicated RegJrnID values is to...
0
by: vssp | last post by:
Hai friends previously I have optimized the query using index that time in my database only 65000 record ,right now in my database 1,50000 recoreds so i need again optimize the query .Now my...
4
by: pmacdiddie | last post by:
Hi, I posted this a while ago, and I though I got a solution. I added referencial intergrity between the tables "tblJobs" and tblJobsLineItems" as was suggested. The time went to .5 seconds....
4
by: dycharles | last post by:
I've been making a program for inventory system using java with a database using postgresql. My problem is, when I query the 20,000 data from my database at one time is slow or it will took 3-5...
2
by: bravo | last post by:
hi everyone , i am trying to join two tables , the query is working fine when the records in the tables are less but when the records are in huge numbers say 1-2 million then the system hangs... i am...
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:
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.