query very slow

S

SusanV

I have a form based on a user input query (single field, which is indexed)
that pulls data from a linked table with over 376,000 records (and growing).
It takes several minutes for the query to run before loading the report.

Users are impatient, and I'd like to improve performance if possible. Is
there any way to speed this query up at all or is this simply a matter of
there being too many records? I've already compacted / repaired the
database, no change.

Thanks in Advance,

SusanV
 
S

SusanV

Oh sure, wasn't thinking, sorry!

SELECT FleetPM.VesselName, FleetPM.EquipmentName, FleetPM.HSC,
FleetPM.MCode, MCode.MCodeTitle, FleetPM.TaskCode, FleetPM.Frequency,
FleetPM.OpStat
FROM MCode INNER JOIN FleetPM ON MCode.MCode = FleetPM.MCode
WHERE (((FleetPM.MCode) Like '*' & [Enter the MCode number to check] & '*'))
ORDER BY FleetPM.VesselName;
 
B

Brendan Reynolds

The Jet database engine can't use an index when you use a leading wildcard
like that. I believe it can use an index with a trailing wildcard, so if you
can use "LIKE [Enter the MCode number] & '*'" instead of "LIKE '*' & [Enter
the MCode number] & '*'" you may see a significant improvement.

--
Brendan Reynolds (MVP)

SusanV said:
Oh sure, wasn't thinking, sorry!

SELECT FleetPM.VesselName, FleetPM.EquipmentName, FleetPM.HSC,
FleetPM.MCode, MCode.MCodeTitle, FleetPM.TaskCode, FleetPM.Frequency,
FleetPM.OpStat
FROM MCode INNER JOIN FleetPM ON MCode.MCode = FleetPM.MCode
WHERE (((FleetPM.MCode) Like '*' & [Enter the MCode number to check] &
'*'))
ORDER BY FleetPM.VesselName;
 
S

SusanV

Thanks - much faster! I didn't know that about the leading wildcard,
interesting... Out of curiosity, I changed it to =[Enter the MCode number to
check] and it runs even faster - in about 3-4 seconds. Wow!

Thanks tons,

SusanV


Brendan Reynolds said:
The Jet database engine can't use an index when you use a leading wildcard
like that. I believe it can use an index with a trailing wildcard, so if
you can use "LIKE [Enter the MCode number] & '*'" instead of "LIKE '*' &
[Enter the MCode number] & '*'" you may see a significant improvement.

--
Brendan Reynolds (MVP)

SusanV said:
Oh sure, wasn't thinking, sorry!

SELECT FleetPM.VesselName, FleetPM.EquipmentName, FleetPM.HSC,
FleetPM.MCode, MCode.MCodeTitle, FleetPM.TaskCode, FleetPM.Frequency,
FleetPM.OpStat
FROM MCode INNER JOIN FleetPM ON MCode.MCode = FleetPM.MCode
WHERE (((FleetPM.MCode) Like '*' & [Enter the MCode number to check] &
'*'))
ORDER BY FleetPM.VesselName;




Brendan Reynolds said:
If you post the SQL for the query, someone may be able to advise.

--
Brendan Reynolds (MVP)

I have a form based on a user input query (single field, which is
indexed) that pulls data from a linked table with over 376,000 records
(and growing). It takes several minutes for the query to run before
loading the report.

Users are impatient, and I'd like to improve performance if possible.
Is there any way to speed this query up at all or is this simply a
matter of there being too many records? I've already compacted /
repaired the database, no change.

Thanks in Advance,

SusanV
 
B

Brendan Reynolds

You're welcome.

And what a good example of how important appropriate indexing is!

--
Brendan Reynolds (MVP)

SusanV said:
Thanks - much faster! I didn't know that about the leading wildcard,
interesting... Out of curiosity, I changed it to =[Enter the MCode number
to check] and it runs even faster - in about 3-4 seconds. Wow!

Thanks tons,

SusanV


Brendan Reynolds said:
The Jet database engine can't use an index when you use a leading
wildcard like that. I believe it can use an index with a trailing
wildcard, so if you can use "LIKE [Enter the MCode number] & '*'" instead
of "LIKE '*' & [Enter the MCode number] & '*'" you may see a significant
improvement.

--
Brendan Reynolds (MVP)

SusanV said:
Oh sure, wasn't thinking, sorry!

SELECT FleetPM.VesselName, FleetPM.EquipmentName, FleetPM.HSC,
FleetPM.MCode, MCode.MCodeTitle, FleetPM.TaskCode, FleetPM.Frequency,
FleetPM.OpStat
FROM MCode INNER JOIN FleetPM ON MCode.MCode = FleetPM.MCode
WHERE (((FleetPM.MCode) Like '*' & [Enter the MCode number to check] &
'*'))
ORDER BY FleetPM.VesselName;




If you post the SQL for the query, someone may be able to advise.

--
Brendan Reynolds (MVP)

I have a form based on a user input query (single field, which is
indexed) that pulls data from a linked table with over 376,000 records
(and growing). It takes several minutes for the query to run before
loading the report.

Users are impatient, and I'd like to improve performance if possible.
Is there any way to speed this query up at all or is this simply a
matter of there being too many records? I've already compacted /
repaired the database, no change.

Thanks in Advance,

SusanV
 
S

SusanV

Just curious - why is it that it doesn't use the index for the leading
wildcard?

Brendan Reynolds said:
You're welcome.

And what a good example of how important appropriate indexing is!

--
Brendan Reynolds (MVP)

SusanV said:
Thanks - much faster! I didn't know that about the leading wildcard,
interesting... Out of curiosity, I changed it to =[Enter the MCode number
to check] and it runs even faster - in about 3-4 seconds. Wow!

Thanks tons,

SusanV


Brendan Reynolds said:
The Jet database engine can't use an index when you use a leading
wildcard like that. I believe it can use an index with a trailing
wildcard, so if you can use "LIKE [Enter the MCode number] & '*'"
instead of "LIKE '*' & [Enter the MCode number] & '*'" you may see a
significant improvement.

--
Brendan Reynolds (MVP)

Oh sure, wasn't thinking, sorry!

SELECT FleetPM.VesselName, FleetPM.EquipmentName, FleetPM.HSC,
FleetPM.MCode, MCode.MCodeTitle, FleetPM.TaskCode, FleetPM.Frequency,
FleetPM.OpStat
FROM MCode INNER JOIN FleetPM ON MCode.MCode = FleetPM.MCode
WHERE (((FleetPM.MCode) Like '*' & [Enter the MCode number to check] &
'*'))
ORDER BY FleetPM.VesselName;




message If you post the SQL for the query, someone may be able to advise.

--
Brendan Reynolds (MVP)

I have a form based on a user input query (single field, which is
indexed) that pulls data from a linked table with over 376,000 records
(and growing). It takes several minutes for the query to run before
loading the report.

Users are impatient, and I'd like to improve performance if possible.
Is there any way to speed this query up at all or is this simply a
matter of there being too many records? I've already compacted /
repaired the database, no change.

Thanks in Advance,

SusanV
 
J

John Vinson

Just curious - why is it that it doesn't use the index for the leading
wildcard?

Because the Index is on the *actual contents* of the field. If the
field contains

FVQQ831234RW99512

then that's what the index contains. Trailing wildcards work because
if you're searching for FV*, JET can quickly locate that part of the
index; but if you're looking for *RW*, JET must look in every record
anyway to see if any of them contain that substring somewhere within
the field. You might have AAQQ3421235RW12312 or ZZWXRW12312AC12345 -
since there's no way to predict where the RW might occur, it must look
at each record anyway.

John W. Vinson[MVP]
 
S

SusanV

That makes perfect sense - and clearly explains why the leading wildcard
makes the query take so long.

Again, thanks for your help and a great explanation!

SusanV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top