473,473 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Join T1.distinct_identifier to T2."choice"_identifier

aas4mis
97 New Member
I've got a primary key on t1 (Item_Identifier) and on t2 I have 4 "item" fields. t1 is the master identifier and is derived from one of the 4 fields in t2. I'm currently trying to join on a COALESCE function, but it is taking way too long. I end up cancelling after about an hour of letting it run. Does anybody know a faster alternative to the following query?

Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2. FROM    tbl_Enterprise_Master_Items item_master
  3. LEFT JOIN vw_Enterprise_Item_Quantities quantities ON
  4.         COALESCE(    CASE WHEN item_master.Item_Identifier = quantities.ID_1 THEN 1 END,
  5.                     CASE WHEN item_master.Item_Identifier = quantities.ID_2 THEN 1 END,
  6.                     CASE WHEN item_master.Item_Identifier = quantities.ID_3 THEN 1 END,
  7.                     CASE WHEN item_master.Item_Identifier = quantities.ID_4 THEN 1 END
  8.                 ) = 1
  9.  
--Side note
When joining on item_master.Item_Identifer to any of the single fields on the quantities table it takes about 4 minutes to complete.

--Thanks,
--aas4mis
May 2 '12 #1
3 1398
Rabbit
12,516 Recognized Expert Moderator MVP
Doing calculations on a field is going to slow things down. You can try and OR the conditions. But ORs can be slow as well. If so, try a UNION approach. But first and foremost, I hope you've created indexes for those fields.

You can find examples of the optimizations mentioned in this article: http://bytes.com/topic/sql-server/in...ze-sql-queries
May 2 '12 #2
aas4mis
97 New Member
There is an index on t1.item_identifer (item_master), but not on the view. The view combines quantities from multiple sources (Online,WMS, EDI, etc...), then joins the sources together and aggregates the total quantity. t2.ID_X may or may not exist in T1, which is why I used COALESCE to choose the correct identifier to match t1 on. I'm on a time crunch at the moment, so I created 4 procedures, each procedure joins and updates on t1.item_identifier = t2.ID_X. The procedures, executed 1 after the other, complete in under 5 minutes.

I'll revisit this another time, but I'm almost certain this is how it will have to be handled if I plan on taking advantage of the index. Thanks.

--aas4mis
May 2 '12 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Well, when you get a chance, try the OR approach or the UNION approach. One of them should work without having to run update queries.
May 2 '12 #4

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

Similar topics

46
by: Leo Breebaart | last post by:
I've tried Googling for this, but practically all discussions on str.join() focus on the yuck-ugly-shouldn't-it-be-a-list-method? issue, which is not my problem/question at all. What I can't...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
0
by: Soefara | last post by:
Dear Sirs, I am experiencing strange results when trying to optimize a LEFT JOIN on 3 tables using MySQL. Given 3 tables A, B, C such as the following: create table A ( uniqueId int not...
2
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1...
3
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four...
1
by: Beachvolleyballer | last post by:
hi there anyone had an idea to join following 2 queries to 1???? ----- QUERY 1 --------------------------------------------- SELECT TMS_CaseF_2.Name AS TCDomain_0, TMS_CaseF_3.Name AS...
8
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and...
7
by: Greg | last post by:
I'm a quantitative securities analyst working with Compustat data (company fiscal reports and pricing feeds). My coworker came across a problem that we fixed, but I'd like to understand 'why' it...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
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
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
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,...
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...
1
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,...
1
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: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.