473,842 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_da ta from spa_param where
(spa_param.pp_k ey = 'CUSTTYPE');"
Set rs = db.OpenRecordse t(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 1276
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_da ta from spa_param where
(spa_param.pp_k ey = 'CUSTTYPE');"
Set rs = db.OpenRecordse t(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
3142
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 SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
5
3908
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 to minute and a half. Is my code that inefficient or is SUM and ABS calls just that slow? Any suggestions to spead this up? Thanks, - Jason
2
1301
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 EventTimeStep EventID -- ------------- --------- 1 5 E1 2 22 E2
10
3750
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 well and used a query plan that made sense. Now, I know what you're all thinking... stored procedures have to optimize for variable parameters, etc. Here's what I've tried to fix the issue: 1. Recompiled the stored procedure 2. Created a new,...
0
1613
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 are the relevant tables: create table image( imageid integer not null, /* The image's ID */ containerid integer not null, /* The container that owns it */ name varchar(120) not null, /* Its name */ state bigint not null default 0,...
6
17934
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 year & month When I try to place a date filter 'Between x And y ' on an expression field
1
5835
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, Contacts.Misc2, Contacts.Address1, Contacts.City, Contacts.State, Contacts.Zip1, Contacts.top_50, Contacts.B_ID as BID,'BCM' as thesource FROM Contacts
10
3286
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 procedure to do this in VB.NET (2005 Express Edition). But I always get the message that the Jet database engine does not recognize the syntax (of the Date function I assume). I've also tried Now() and it works but only by itself. I seem to add or
0
3311
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 queries yes or no, I have prepared an example. The example is a database with the following tables: *table person with fields: -persid: autoincrement id -name: name of the person *table material with fields: -materialid: autoincrement id
1
1984
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 built. This may seem relatively straight forward to some of you more experienced programmers, but I'm almost entirely self-taught. This means that I have some gaps in my knowledge and sometimes go about doing things the hard way never knowing...
0
9715
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10612
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9453
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7858
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7038
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3145
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.