473,402 Members | 2,053 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,402 software developers and data experts.

Is this Query inefficient?

Suppose I have a customer table ("customer"):-
Primary Key cust_id long integer
cust_name text(40)
cust_type text(1)

containing 80000 rows.
There are about 10000 rows where customer type = "A"
To retrieve these rows I use query

Select * from customer where cust_type = get_type()

But function get_type() gets its data using a lookup in a parameter
file and for this example will evaluate to "A"

function get_type() as string
Dim db As Database
Dim rs As Recordset
Dim sqlstr As String
Set db = CurrentDb
sqlstr = "select spa_param.pp_data from spa_param where
(spa_param.pp_key = 'CUSTTYPE');"
Set rs = db.OpenRecordset(sqlstr)
If rs.RecordCount = 1 Then
rs.MoveFirst
get_type = (rs!pp_data)
Else
' do the error routine
get_type = ""
End If
rs.Close
Set rs = Nothing
Set db = Nothing
end function

My question is:-
Will get_type() be evaluated once and used in the query on the
customer table or will it be evaluated for each row that is read in
the customer table.

Thanks in advance

Mike
Nov 13 '05 #1
1 1261
Mike Ridley wrote:
Suppose I have a customer table ("customer"):-
Primary Key cust_id long integer
cust_name text(40)
cust_type text(1)

containing 80000 rows.
There are about 10000 rows where customer type = "A"
To retrieve these rows I use query

Select * from customer where cust_type = get_type()

But function get_type() gets its data using a lookup in a parameter
file and for this example will evaluate to "A"

function get_type() as string
Dim db As Database
Dim rs As Recordset
Dim sqlstr As String
Set db = CurrentDb
sqlstr = "select spa_param.pp_data from spa_param where
(spa_param.pp_key = 'CUSTTYPE');"
Set rs = db.OpenRecordset(sqlstr)
If rs.RecordCount = 1 Then
rs.MoveFirst
get_type = (rs!pp_data)
Else
' do the error routine
get_type = ""
End If
rs.Close
Set rs = Nothing
Set db = Nothing
end function

My question is:-
Will get_type() be evaluated once and used in the query on the
customer table or will it be evaluated for each row that is read in
the customer table.

Thanks in advance

Mike


A function without parameters will be executed once for the whole query.
If you were to pass in a column name to the function call then it would
execute for each row. So in your case, there's no problem.

--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Nov 13 '05 #2

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

Similar topics

9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
5
by: Jason | last post by:
The following stored procedure is taking too long (in my opinion). The problem seems to be the SUM line. When commented out the query takes a second or two. When included the response time climbs...
2
by: Adam Nemitoff | last post by:
I have two tables populated during the use of an application to log user events and application states. They are named "EventTable" and "StateTable" and the structures follow: EventTable: ID...
10
by: Thomas R. Hummel | last post by:
I have a stored procedure that suddenly started performing horribly. The query plan didn't look right to me, so I copy/pasted the code and ran it (it's a single SELECT statement). That ran pretty...
0
by: Robert Wille | last post by:
I have a number of very common queries that the optimizer plans a very inefficient plan for. I am using postgres 7.2.3. I vacuum hourly. I'm wonderingwhat I can do to make the queries faster. Here...
6
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group by fields to give me a Count on another field by...
1
by: forey | last post by:
Hi All, I'm trying to find the best way to accomplish the following: I have a union query in an Access XP database (pasted below) SELECT Contacts.Company,Contacts.dba, Contacts.Misc1,...
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
0
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex...
1
by: Andy_Khosravi | last post by:
Background: Access 2003 (converted from A97 DB recently), database is split into FE/BE with the FE residing on client machine. I've got a question about how I can possibly optimize a query I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
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...
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...

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.