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

IIF vs Where in Group query, what is faster ?

215 128KB
I want to know what will be faster in this situation:

I have table1 = {ID, Type, BData, Quantity}

There are 2 type {A, B}

if I want to know sum of A, B
I can use this

Expand|Select|Wrap|Line Numbers
  1. SELECT ID, Type, Month(Bdate) as M, Sum(Quantity)
  2. FROM Table1
  3. Where Type like "A"
  4. Group by ID, Type, Month(Bdata);
  5.  
but I can even use iif to do that :
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, Month(BDate) as M, Sum(iif(Type like "a", Quantity, 0))
  2. FROM Table1
  3. Group by ID, Month(Bdate);
  4.  
my question is, which method will perform better ?
IIF or Where ?
Nov 9 '15 #1
14 1210
Rabbit
12,516 Expert Mod 8TB
The true test is run both multiple times and see what the average run time is. But you will most likely find that WHERE is faster.
Nov 9 '15 #2
hvsummer
215 128KB
omg, I did use a lot of sumiif function in query... ==
Do I have to change all of them back into Where Method ? :(
Nov 10 '15 #3
zmbd
5,501 Expert Mod 4TB
depends... is the return of data within an acceptable timeframe.
If so, then leave it alone
If not, then change things around.

One will find that WHERE clauses tend to work faster (but not noticeably when using small data sets).
IIF(), [field] IS NULL, and other SQL type commands will tend to work faster, but not noticeably when using small data sets, than the VBA NZ(), or any domain function such as DCOUNT() or DSUM - once again, small datasets the performance hit isn't likely to be noticed by the user. In-fact, I have an early DB that uses domain functions on over 5000 records and the return is under 5 seconds... used to be less than 2; however, the back-end is on the server now.

In this case, I think that this will have to be a judgment call on your part unless Rabbit, Neopa, or one of the other more experienced DBA/DD have better insight.
Nov 10 '15 #4
hvsummer
215 128KB
well, my DBs hit 1.2GB a couple day ago, 1.5million rows of main table and somewhat 200k rows the rest tables.

and query return data in 30s-60s, I will never use Domain function (except in Vba function), query will be code with purely SQL.
Nov 10 '15 #5
zmbd
5,501 Expert Mod 4TB
AT that size, you need to be absolutely sure that your data is properly normalized.
Nov 10 '15 #6
hvsummer
215 128KB
if I could not be sure, what I can do now when it already reach that size hahaha

btw, my data will not be normalized for sure, I got data raw from another online-database, and working on it, (data raw mean it content everything in detal and information that can be duplicate with another table).
and any table connect to this main table will have *-to-M relationship (1-to-m, m-to-m)
Nov 10 '15 #7
zmbd
5,501 Expert Mod 4TB
I would suspect therefore that your "raw data" is the root source of a majority of your lag and database size; thus, I'd be looking for anything that indexes the data and filters using the WHERE or the other criteria clauses and avoid any domain/VBA functions as much as possible.

Maybe one of the other Experts here will have better solutions.

As for normalization, I would be looking at some VBA coding to pull that data apart. I've done that in the past and it's a real pain but worth the effort.
Nov 10 '15 #8
MikeTheBike
639 Expert 512MB
Hi

Just a small question on the topic of query speed with large datasets,
I figured (assumed) WHERE would be quicker than IIF()
but would this
Expand|Select|Wrap|Line Numbers
  1. Where Type = "A"
be quicker then
Expand|Select|Wrap|Line Numbers
  1. Where Type like "A"
???

As it would seem that in this case the only possible option are 'A' or 'B'



MTB
Nov 10 '15 #9
zmbd
5,501 Expert Mod 4TB
Agreed that the equality would more than likely be faster; however, you lose wild cards such as:
Expand|Select|Wrap|Line Numbers
  1. WHERE LastName Like '[A-D]*';")
Nov 10 '15 #10
hvsummer
215 128KB
ok 0.0 I think I know how to pull those data apart with vba.. but, yeah, but if i do that I need something bigger than 2GB limit, already 1.2GB mean I don't have enough space to do that with vba.

I'll consider this later, now I'm working on improve some new complex query that I have not done before.
Nov 11 '15 #11
zmbd
5,501 Expert Mod 4TB
if your data is duplicated across tables/records, the normalization should reduce the over all size.
Nov 11 '15 #12
hvsummer
215 128KB
but the memory buffer to transfer data between old and new table can't handle 1.3GB. the only way to do this is split database, then manipulate it within vba of back-end db...
Nov 11 '15 #13
zmbd
5,501 Expert Mod 4TB
split databases are a very common occurrence.
you can search here on Bytes and find hundreds of threads covering various aspects of how to connect and parse records. :)
Nov 11 '15 #14
strive4peace
39 Expert 32bit
for speed, another thing to realize is that inequality comparisons are FASTER than equality comparisons.

also, on IIF ... even if the condition is true, the false argument is still evaluated.
Nov 15 '15 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sks | last post by:
Hi, I have a table which logs for sake of argument page hits: id, timestamp, ipaddress Now, I'm running a query to get an activity report and I want to group together all the hits from a...
5
by: me | last post by:
I have a shopping cart that errors out when try to do a search select p.products_ship_price, p.products_id, p.products_model, pd.products_name, p.products_quantity, p.products_image,...
6
by: Driesen via SQLMonster.com | last post by:
Hi guys Is there any way I can run this query faster? Should I take out the ORDER BY clause? This is supposed to return 17,000 rows and takes around 30 minutes or so. Is there no way at all to...
3
by: Not Me | last post by:
Hi, In the past I seem to have been able to speed up queries by making them a join rather than ... not a join :o) An example would be select * from x where a in (select a from y) would...
4
by: Gordon White | last post by:
I'm working on a DB for a local 5K race. I want to make the DB as flexible as possible and to avoid hard coding anything that I don't need to so that we can reuse this for other races. As such, I...
2
by: vicky | last post by:
I have a query which runs under 15 sec. through query analyzer. But when same query is getting executed by .net console application, using ado.net, it takes 10-15 min. What can be the problem?
1
by: BertDick | last post by:
I'm trying to use the IRR function in Ms Access using the code below. Function MyIRR(mygroupid, myguess) as double Dim Values(4) as double' an array with 5 elements Dim x dim rs as...
3
by: JC2710 | last post by:
Hi This question should be really easy but I just cant do it!! I have a table below: Code Group Test Price 56 1 1 2298 56 1 2 1215 56 1 3 1378 56 2 1 492 56 2 2 600
5
by: eko99312 | last post by:
Pardon me if this question already been asked before. I tried to sort a query to meet my desire. Here is the example: Date Customer Supplier Price 31-Oct-09 Charlie Australia $ 100...
4
by: jonnyyadav | last post by:
This query is taking 3 minutes to execute it. pls healp me to make it faster. select histpric.timetick, stcurr.externalid, stcurr.assetid,stcurr.asset_name,bsnshistpr.bse_price,...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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: 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...

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.