Re: Like query slow on number field
- From: eselk2003@xxxxxxxxx
- Date: Tue, 30 Sep 2008 08:36:19 -0700 (PDT)
On Sep 29, 4:56 pm, "Jeff Boyce" <nonse...@xxxxxxxxxxxx> wrote:
How many records are in the table?
55,657
Where is the data stored?
Where are you asking from?
On a Win2003 server, over a 100mbps LAN, query is from a workstation
running XP.
How many fields are in the table (your SELECT * gets them all)?
39 -- although see my code below, I was incorrect about the "SELECT *"
part, I'm only asking for one field.
Are you sure it's the getting that's slow, and not the ORDER BY?
It is this one line of VBA script that takes about 3 to 4 seconds to
execute (when I press F8 on this line):
Set rs = CurrentDb.OpenRecordset("" & _
"SELECT CUSTOMER.[CUSTOMER #], " & _
"CUSTOMER.[" & SearchField & "] FROM CUSTOMER " & _
"WHERE (((CUSTOMER.[" & SearchField & "]) Like """ & find_text &
"*"")) " & _
"ORDER BY CUSTOMER.[" & SearchField & "];")
Here is a condensed version with variable set to the field that is
slow:
SELECT [CUSTOMER #], [CUSTOMER #]
FROM CUSTOMER
WHERE ((([CUSTOMER #]) Like "5*"))
ORDER BY [CUSTOMER #]
I did just notice that when SearchField is [CUSTOMER #], I end up
asking for the customer# field twice, but I don't think that would
effect speed very much.
I use it for a list that updates as the user types in a textbox. If
SearchField is any indexed string/text field, the above line of code
executes in less than a second (fast enough that you don't notice much
delay while typing). If SearchField is a non-indexed field, it takes
4+ seconds to execute. If SearchField is an indexed numeric field, it
takes 3+ seconds to execute, which I imagine is because it isn't/can't
use the index... at least until I read Lord Kelvan's reply, it seems
he is able to get <1 second results (could it just be because he used
cstr(), of course I'll try it to find out).
I haven't tried without the ORDER BY. I have tried changing it to
"SELECT TOP 1", but that didn't speed it up at all, in which case I
would think ORDER BY wouldn't matter since I am only asking for 1
record.
You called it a primary key, so I'm assuming you have it indexed.
Yes, indexed with no duplicates (although for string fields, indexed
with or without duplicates is fast either way).
.
- Follow-Ups:
- Re: Like query slow on number field
- From: eselk2003
- Re: Like query slow on number field
- References:
- Like query slow on number field
- From: eselk2003
- Re: Like query slow on number field
- From: Jeff Boyce
- Like query slow on number field
- Prev by Date: Using Yes/No data type
- Next by Date: Re: Use of "Where" in Query Total line
- Previous by thread: Re: Like query slow on number field
- Next by thread: Re: Like query slow on number field
- Index(es):
Relevant Pages
|