0

My question is pretty straightforward and I would like to extend my knowledge about the matter of improving SQL queries perfomance-wise.

I am very often faced lately with bequithed scripts from my collegues who are a bit "messy" when writing scripts.

They write join clauses the old way by writing tables one after another delimited with commas.

I know that output wise those scripts are the same, but can there be a perfomance improvement by rewriting those scricts into the classic join clauses?

EDIT: So I have rewritten the poorly written code and I have together 3 examples, however only as pictures the formatting was really crazy, maybe I can later reformat it again - here is the album https://i.stack.imgur.com/Fkje9.jpg

So on the first picture is kind of a mixed approach between joins and cartezian products, it took 35 minutes to run the result.

The second picture is my rewritten code - it took a little over a minute to gain the same result.

The last one I have specifically rewritten the code to only cartezian products - it runs for an hour now and I dont know when it will stop.

So can anyone help me get some usefull information from the stats in the pictures? Which indicators are good to look at for performance? Because the approximated time of the last approach was the least, however it turns out it is the slowest one.

Thank you.

Emil Holub
  • 168
  • 10
  • 1
    Answer is NO. Both should have identical execution plan. – Pரதீப் Nov 02 '16 at 15:12
  • @Prdp - Actually the answer is it totally depends. In simple queries you are completely correct but moving predicates around in more complicated queries can have unexpected effects. That's why it is important to look at the execution plan often when optimizing queries. –  Nov 02 '16 at 15:36
  • Can someone unmark it as duplicate? I added aditional info – Emil Holub Nov 02 '16 at 16:17
  • Why isn't it a duplicate? You haven't shown any of the queries (or the table structures, indexes, data) so we have no idea if they are logically the same. – Alex Poole Nov 02 '16 at 16:45
  • There are many tables and I did not have the time to anonymize them, I can post the script later – Emil Holub Nov 03 '16 at 07:20

0 Answers0