Solved

Transact SQL Query - how to force the join order ?

Posted on 2013-12-12
3
523 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

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.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
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…

751 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