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

Need help speeding up query...if possible...

Here's the breakdown:
MySQL 4.0.12
Table: Assignment (indexes are created on proper fields) 419,234 records
Table: Finders (indexes are created on proper fields) 5,345,657 records
My user wants to be able to do a wild card search on lastname in the finders
table. So, I wrote the following query.

SELECT Finders.Lastname, Assignment.currentcard
FROM Finders JOIN Assignment on Finders.assignmentid=Assignment.assignmentid
WHERE Assignment.jobnumber='50720'
AND Finders.lastname like 'DU%'

This query takes about 35 seconds to return the 33,000 records. Not
acceptable. From my understanding, I'm pretty much stuck since I'm using
the 'LIKE' and wild card. True?
I tried using "AND left(Finders.lastname,2) = 'DU'...but that didn't seem to
speed anything up.
I tried using "AND substring(Finders.lastname,1,2) = 'DU' ... but that
didn't seem to speed up either.
I tried
SELECT Finders.Lastname, Assignment.currentcard
FROM Finders, Assignment
WHERE Finders.assignmentid=Assignment.assignmentid
AND Assignment.jobnumber='50720'
AND Finders.lastname like 'DU%'
but that didn't work either.

So, I tried
create temporary table JOBS select assignmentid, currentcard, jobnumber from
Assignment where jobnumber = '50720';
SELECT JOBS.currentcard, JOBS.assignmentid, Finders.firstname
FROM JOBS join Finders on Finders.assignmentid = JOBS.assignmentid
WHERE Finders.lastname like 'MI%'
but I'm not getting very good times there either.

I'm thinking version 5.0 would help, but that's not a possibilty.
Does anyone have any ideas? I'm in dire need of some help.

-Bruce
Jul 23 '05 #1
3 1370
Bruce D wrote:
Here's the breakdown:
MySQL 4.0.12
Table: Assignment (indexes are created on proper fields) 419,234 records
Table: Finders (indexes are created on proper fields) 5,345,657 records
My user wants to be able to do a wild card search on lastname in the finders
table. So, I wrote the following query.

SELECT Finders.Lastname, Assignment.currentcard
FROM Finders JOIN Assignment on Finders.assignmentid=Assignment.assignmentid
WHERE Assignment.jobnumber='50720'
AND Finders.lastname like 'DU%'

This query takes about 35 seconds to return the 33,000 records. Not
acceptable. From my understanding, I'm pretty much stuck since I'm using
the 'LIKE' and wild card. True?
I tried using "AND left(Finders.lastname,2) = 'DU'...but that didn't seem to
speed anything up.
I tried using "AND substring(Finders.lastname,1,2) = 'DU' ... but that
didn't seem to speed up either.
I tried
SELECT Finders.Lastname, Assignment.currentcard
FROM Finders, Assignment
WHERE Finders.assignmentid=Assignment.assignmentid
AND Assignment.jobnumber='50720'
AND Finders.lastname like 'DU%'
but that didn't work either.

So, I tried
create temporary table JOBS select assignmentid, currentcard, jobnumber from
Assignment where jobnumber = '50720';
SELECT JOBS.currentcard, JOBS.assignmentid, Finders.firstname
FROM JOBS join Finders on Finders.assignmentid = JOBS.assignmentid
WHERE Finders.lastname like 'MI%'
but I'm not getting very good times there either.

I'm thinking version 5.0 would help, but that's not a possibilty.
Does anyone have any ideas? I'm in dire need of some help.

-Bruce

How about this:

SELECT Finders.Lastname, Assignment.currentcard
FROM Finders JOIN Assignment on Finders.assignmentid=Assignment.assignmentid AND Assignment.jobnumber='50720'
WHERE Finders.lastname like 'DU%'
Jul 23 '05 #2
Bruce D wrote:
Here's the breakdown:
MySQL 4.0.12
Table: Assignment (indexes are created on proper fields) 419,234 records
Table: Finders (indexes are created on proper fields) 5,345,657 records
My user wants to be able to do a wild card search on lastname in the finders
table.


Please post the actual DDL you used to create these tables and their
indexes. In other words, don't make readers guess what you considered
the proper fields to index, what table storage type you're using, how
long the string fields are, etc.

Also please post the results of running your query with EXPLAIN.

Regards,
Bill K.
Jul 23 '05 #3
Sorry...I lost formatting...

Here are the indexes.
Finders:
Keyname Type Cardinality Action Field
PRIMARY PRIMARY 5659954 Drop Edit FinderID
FinderNumber INDEX 55 Drop Edit FinderNumber
StreetNumber INDEX 38242 Drop Edit StreetNumber
StreetName INDEX 82028 Drop Edit StreetName
Zip INDEX 1510 Drop Edit Zip
Phone INDEX 2829977 Drop Edit Phone
AssignmentID INDEX 435381 Drop Edit AssignmentID
Name INDEX 2829977 Drop Edit LastName, FirstName

Assignment:
Keyname Type Cardinality Action Field
PRIMARY PRIMARY 419649 Drop Edit AssignmentID
KitStatusID INDEX 1 Drop Edit KitStatusID
AssignCode INDEX 419649 Drop Edit AssignCode
AssignZip INDEX 1509 Drop Edit AssignZip
AssignStreet INDEX 83929 Drop Edit AssignStreet
Volunteer_FinderID INDEX 419649 Drop Edit Volunteer_FinderID
BranchID INDEX 1 Drop Edit BranchID
JobNumber INDEX 1 Drop Edit JobNumber
CurrentCard INDEX 1 Drop Edit CurrentCard

Here's the explain.

EXPLAIN SELECT Finders.Lastname, Assignment.currentcard
FROM Finders
JOIN Assignment ON Finders.assignmentid = Assignment.assignmentid
WHERE Assignment.jobnumber = '50720' AND Finders.lastname
LIKE 'DU%'

Finders range AssignmentID,Name Name 15 NULL 32284 Using where
Assignment eq_ref PRIMARY,JobNumber PRIMARY 4 Finders.AssignmentID 1 Using
where

I'm using MyISAM tables.
TIA,
-bruce
Jul 23 '05 #4

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

Similar topics

0
by: Bennett Haselton | last post by:
I have a MySQL query running inside a CGI script on my site that, at random intervals, seems to take 10-20 seconds to complete instead of less than 1 second. I spent so much time trying to track...
0
by: Apollo | last post by:
I have about 20K records that result from the following query. Front end for the database is ACCESS97 and pulling up 20K records makes a huge performance hit. For the form in question I am using...
6
by: LRW | last post by:
I have a querey formed with a few joins and a lot of fields, and no kidding, it takes up to 2 minutes for the PHP page to poulate with all the results (usually around 300). Now, we have a pretty...
3
by: David | last post by:
Consider this SQL Query: ----------------------------------------------------------------- SELECT c.CASE_NBR, DATEDIFF(d, c.CREATE_DT, GETDATE()) AS Age, c.AFFD_RCVD, c.PRV_CRD_ISS, x.RegE,...
2
by: Wayne | last post by:
I am running a complex query using about 25 criteria that are entered on a query form. If any individual criteria isn't required its field is left as "*" on the form. When I run the query the...
0
by: Tiga | last post by:
Right off I know nothing about programming so any help will be useful. We have an application that I have manipulated by creating an IF statement which is below. ...
2
by: simon_w3 | last post by:
Hi All, I'm trying to figure out how I can speed up a fragment of code (which has been converted from vb6 to .NET) that reads data from a database. My knowledge on database programming is...
11
by: Dan Sugalski | last post by:
Is there any good way to speed up SQL that uses like and has placeholders? Here's the scoop. I've got a system that uses a lot of pre-generated SQL with placeholders in it. At runtime these SQL...
3
by: bplantes | last post by:
I have designed a form to bridge one customer record with a master customer record in a table. For example: CustomerName, CustomerNumber: ABC Company, 101; ABC Corp. , 102; ABC Inc., 103; ...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.