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

slow query, sql code attached

I have a database that keeps records on the issue and failure of an item.
Currently, the database is poorly desisned; therefore I'm performing queries
to break the data into normalized tables and attempting to perform a "left
join" query to build a cross-reference table.

The left join query is currently taking nearly 2 hours for MySQL to process,
using Navicat as a front-end. My system specs are 1.4Mhz Pentium Processor
with 1GB of RAM running on Windows XP. The first table "CDID" has the
following layout:
TblID INT 11 Primary
Holder ID INT 11 Index
CD Serial VARCHAR 26 Index
Fail Rsn VARCHAR 5
CD Type CHAR 3
Holder ID-CD Serial as Normal Index
This table contains 6,671,610 records.

The second table "TranTBL"
CDTblID INT 11 Primary
Holder ID INT 11 Index
CD Serial VARCHAR 26 Index
CDExpire Dt Date 0
Expire Rsn VARCHAR 4
Fail Dt Date 0
CardType CHAR 3
Issue Dt Date 0
Expire Dt Date 0
Race CHAR 2
Gender CHAR 2
Marital Status CHAR 2
Ethnicity VARCHAR 2
Height Smallint 6
Weight Smallint 6
DOB Date 0
Holder ID-CD Serial as Normal Index
This table contains 5,879,210 records.

My sql code for the query is as follows:

SELECT

`CDID`.`Holder ID`,

`CDID`.`CD Serial`,

`CDID`.`Fail Rsn`,

`TranTBL`.`Fail Dt`,

`TranTBL`.`Issue Dt`,

`TranTBL`.`Expire Dt`

FROM

`CDID`,

`TranTBL`

WHERE

`CDID`.`Holder ID`= `TranTBL`.`Holder ID` AND

`CDID`.`CD Serial`= `TranTBL`.`CD Serial`

Explain Provides the following:

Table Type Possible keys key
key length ref
rows extra

IDCD All Holder ID-CD Serial Null
8 Null
6,671,610 Null

TranTBL ref Holder ID-CD Serial Holder ID-CD Serial 8
IDCD.Holder ID, IDCD.CD Serial 1 Using where

Thanks in advance for any assistance or suggestions that you can offer.

Trent
Jul 20 '05 #1
4 2953
DBNovice wrote:
I have a database that keeps records on the issue and failure of an item.
Currently, the database is poorly desisned; therefore I'm performing queries
to break the data into normalized tables and attempting to perform a "left
join" query to build a cross-reference table.

The left join query is currently taking nearly 2 hours for MySQL to process, [snip]
Thanks in advance for any assistance or suggestions that you can offer.


1/ I don't see any left join query in your post!

2/ The explain output doesn't seem to match the tables/query you have
described. Can you confirm it is the correct one.

3/ Assuming the explain output _is_ correct, can you confirm that you
haven't omitted anything like ORDER BY or GROUP By or any other WHERE
clauses in your query?

4/ The reason it takes so long is that mysql is finding a need to scan
all the records in the first table. We need to identify why.
Jul 20 '05 #2
DBNovice wrote:
I have a database that keeps records on the issue and failure of an item.
Currently, the database is poorly desisned; therefore I'm performing queries
to break the data into normalized tables and attempting to perform a "left
join" query to build a cross-reference table.

2metre replied:
1/ I don't see any left join query in your post!

2/ The explain output doesn't seem to match the tables/query you have
described. Can you confirm it is the correct one.

3/ Assuming the explain output _is_ correct, can you confirm that you
haven't omitted anything like ORDER BY or GROUP By or any other WHERE
clauses in your query?

4/ The reason it takes so long is that mysql is finding a need to scan all
the records in the first table. We need to identify why.

Thanks for the reply 2metre! Sorry, I had to edit the query for sensitive
info that's why EXPLAIN results were inconsistent with the original query.
I didn't use ORDER BY or GROUP BY in the query... should I use them? Here
it is:

The left join query is currently taking nearly 2 hours for MySQL to process,
using Navicat as a front-end. My system specs are 1.4Mhz Pentium Processor
with 1GB of RAM running on Windows XP. The first table "CDID" has the
following layout:
TblID INT 11 Primary
Holder ID INT 11 Index
CD Serial VARCHAR 26 Index
Fail Rsn VARCHAR 5
CD Type CHAR 3
Holder ID-CD Serial as Normal Index
This table contains 6,671,610 records.

The second table "TranTBL"
CDTblID INT 11 Primary
Holder ID INT 11 Index
CD Serial VARCHAR 26 Index
CDExpire Dt Date 0
Expire Rsn VARCHAR 4
Fail Dt Date 0
CardType CHAR 3
Issue Dt Date 0
Expire Dt Date 0
Race CHAR 2
Gender CHAR 2
Marital Status CHAR 2
Ethnicity VARCHAR 2
Height Smallint 6
Weight Smallint 6
DOB Date 0
Holder ID-CD Serial as Normal Index
This table contains 5,879,210 records.

My sql code for the query is as follows:

SELECT

`CDID`.`Holder ID`,

`CDID`.`CD Serial`,

`CDID`.`Fail Rsn`,

`TranTBL`.`Fail Dt`,

`TranTBL`.`Issue Dt`,

`TranTBL`.`Expire Dt`

FROM

`CDID`,

Left Join `TranTBL` ON `CDID`.`Holder ID`= `TranTBL`.`Holder ID`

WHERE
`CDID`.`CD Serial`= `TranTBL`.`CD Serial`

Explain Provides the following:

Table Type Possible keys key
key length ref
rows extra

IDCD All Holder ID-CD Serial Null
8 Null
6,671,610 Null

TranTBL ref Holder ID-CD Serial Holder ID-CD Serial 8
IDCD.Holder ID, IDCD.CD Serial 1 Using where

Thanks in advance for any assistance or suggestions that you can offer.

Trent
"2metre" <2m****@xxxhersham.net> wrote in message
news:cm**********@hercules.btinternet.com... DBNovice wrote:
I have a database that keeps records on the issue and failure of an item.
Currently, the database is poorly desisned; therefore I'm performing
queries to break the data into normalized tables and attempting to
perform a "left join" query to build a cross-reference table.

The left join query is currently taking nearly 2 hours for MySQL to
process,

[snip]

Thanks in advance for any assistance or suggestions that you can offer.


1/ I don't see any left join query in your post!

2/ The explain output doesn't seem to match the tables/query you have
described. Can you confirm it is the correct one.

3/ Assuming the explain output _is_ correct, can you confirm that you
haven't omitted anything like ORDER BY or GROUP By or any other WHERE
clauses in your query?

4/ The reason it takes so long is that mysql is finding a need to scan all
the records in the first table. We need to identify why.

Jul 20 '05 #3
DBNovice wrote:
SELECT

`CDID`.`Holder ID`,

`CDID`.`CD Serial`,

`CDID`.`Fail Rsn`,

`TranTBL`.`Fail Dt`,

`TranTBL`.`Issue Dt`,

`TranTBL`.`Expire Dt`

FROM

`CDID`,

Left Join `TranTBL` ON `CDID`.`Holder ID`= `TranTBL`.`Holder ID`

WHERE
`CDID`.`CD Serial`= `TranTBL`.`CD Serial`


You're double-joining the tables. MySQL doesn't appear to be able to
optimise that: either drop the left join or the where clause and include
the conditions in a single join.
Jul 20 '05 #4
Thanks, 2metre!

I removed the WHERE clause and placed both conditions in the ON statement of
the LEFT JOIN, and query zipped away. One strange thing is that when I made
the changes above and ran EXPLAIN SELECT and got the following results:

Table Type Possible keys key
key length ref
rows extra

IDCD All Holder ID-CD Serial Null
8 Null
6,671,610 Null

TranTBL ref Holder ID-CD Serial Holder ID-CD Serial
28
IDCD.Holder ID, IDCD.CD Serial 1

Which meant the entire referenced table would be read as before; however, I
ran the query without EXPLAIN in which the query processed quickly. The
EXPLAIN SELECT results at the conclusion of the query were:

Table Type Possible keys key
key length ref
rows extra

IDCD All Holder ID-CD Serial Null
8 Null
1410 Null

TranTBL ref Holder ID-CD Serial Holder ID-CD Serial 8
IDCD.Holder ID, IDCD.CD Serial 1

Which is more efficient, but why didn't the original EXPLAIN SELECT produce
these results? Am I using it incorrectly?

Lastly, I ran SHOW PROCESSLIST from the command line console while this
query was running. The response stated that this query was "Sending Data".
Does this mean that the query had completed and was in the process of
sending the results(6+ million rows) to my client which is on the same
machine? If so, are there any methods to speed this process? My client
uses Navicat as GUI-front-end. Could Navicat be the bottleneck in the
"Sending data" process.

Once again, thanks!

"2metre" <2m****@xxxhersham.net> wrote in message
news:cm**********@hercules.btinternet.com...
DBNovice wrote:
SELECT

`CDID`.`Holder ID`,

`CDID`.`CD Serial`,

`CDID`.`Fail Rsn`,

`TranTBL`.`Fail Dt`,

`TranTBL`.`Issue Dt`,

`TranTBL`.`Expire Dt`

FROM

`CDID`,

Left Join `TranTBL` ON `CDID`.`Holder ID`= `TranTBL`.`Holder ID`

WHERE
`CDID`.`CD Serial`= `TranTBL`.`CD Serial`


You're double-joining the tables. MySQL doesn't appear to be able to
optimise that: either drop the left join or the where clause and include
the conditions in a single join.

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Neil | last post by:
I have a very puzzling situation with a database. It's an Access 2000 mdb with a SQL 7 back end, with forms bound using ODBC linked tables. At our remote location (accessed via a T1 line) the time...
4
by: psql-mail | last post by:
I am running a SELECT to get all tuples within a given date range. This query is much slwoer than i expected - am i missing something? I have a table 'meta' with a column 'in_date' of type...
2
by: Yonatan Goraly | last post by:
I am in the process of adding PostgreSQL support for an application, in addition to Oracle and MS SQL. I am using PostgreSQL version 7.3.2, Red Hat 9.0 on Intel Pentium III board. I have a...
3
by: Bob C. | last post by:
When I migrated my tables to SQL Server I needed a way to overcome the slow performance of the Find method on my recordsets. Although this can be done by accessing the table directly using dao and...
15
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
11
by: nico | last post by:
Hello I have write this program that retrieve all directory and subdirectory recursively of a given directory given in parameter. For each directory, the script find all user permission for the...
7
by: Shaji | last post by:
Dear All, I am using VS.Net (and most of you, of course) for a quite long period for web development for medium to large development tasks. My humble opinion is vs.net is eating up a lot of...
3
by: Bob Graham | last post by:
This code: txRate.Text = Format(payRate, "C") (payRate is already succesfully set to a value such as 15D) takes about 3-4 seconds to run the first time, after that it's plenty fast. What...
11
by: HC | last post by:
I posted this in one of the VB forums but I'm starting to think it might be more appropriate to have it here, since it really seems to be a SQL server (MSDE/Express 2005) problem: Hey, all, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...

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.