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? -
SELECT ...
-
FROM tbl_Enterprise_Master_Items item_master
-
LEFT JOIN vw_Enterprise_Item_Quantities quantities ON
-
COALESCE( CASE WHEN item_master.Item_Identifier = quantities.ID_1 THEN 1 END,
-
CASE WHEN item_master.Item_Identifier = quantities.ID_2 THEN 1 END,
-
CASE WHEN item_master.Item_Identifier = quantities.ID_3 THEN 1 END,
-
CASE WHEN item_master.Item_Identifier = quantities.ID_4 THEN 1 END
-
) = 1
-
--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
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
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |
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: 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 ...
| |