Solved

Transact SQL Query - how to force the join order ?

Posted on 2013-12-12
3
513 Views
Last Modified: 2013-12-12
Hello,
I'm using a query for years but this time it makes me getting creasy ...

UPDATE TABLE_1 set TABLE_1.CHANGEMENT = 1 ,
    TABLE_1.VALEUR_POINTS = TABLE_2.VALEUR_POINTS,
    TABLE_1.DESIGNATION_PRODUIT = TABLE_2.DESIGNATION_PRODUIT
     FROM TABLE_2 JOIN TABLE_1 ON TABLE_1.REF_EDITEUR = TABLE_2.REF_EDITEUR  AND  TABLE_1.REF_PRODUIT = TABLE_2.REF_PRODUIT  AND ACTUEL = 1
     WHERE
     TABLE_2.REF_EDITEUR = 'ZIM'
     AND TABLE_1.GAMME = TABLE_2.GAMME
     AND TABLE_1.PROGRAM_TYPE = TABLE_2.PROGRAM_TYPE
     AND( TABLE_1.VALEUR_POINTS <> TABLE_2.VALEUR_POINTS
     OR TABLE_1.DESIGNATION_PRODUIT <> TABLE_2.DESIGNATION_PRODUIT )

this query should returned 0 because there is no entry to join.
TABLE_2 is a very little table (less than 300 entries)

if I run the query like this, it is running for a long, long , long time and have to stop it.
if I remove this line :  AND TABLE_1.PROGRAM_TYPE = TABLE_2.PROGRAM_TYPE
it is running in 0 secs.

attached the estimated plan.

I added the option FORCE ORDER but it didn't help....

thanks to help me, very urgent and important ....
plan.xml
0
Comment
Question by:bruno_boccara
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 39714615
Would like to see full table and index definitions.

But, based on the query plan, the Produits PROGRAM_TYPE is having to go thru an implicit conversion to be compared to ~tmp_Produits.  Implicit conversions can have a very bad effect on performance (likely tmp_ is nvarchar, nontmp is varchar).  If you're going to join on a column, it's best to make sure they have exactly the same data types.
0
 

Author Comment

by:bruno_boccara
ID: 39714701
unbelieveable ....

IN TABLE_2 it was nvarchar(50) , in TABLE_1 it was varchar(50)

I changed table_2 to the same and it is working in 17ms ....


MANY THANKS !! I LEARNED A LOT IN WITH YOUR ANSWER !!!
0
 

Author Closing Comment

by:bruno_boccara
ID: 39714702
wonderful
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now