1

I am querying data from a process historian that was stored using OPC. The querys run very slow. What table merging method should I expect to be faster and why when I query the data?

This:

and a1.TS >'15-MAR-18 07:00'                                             
and a1.TS = a2.TS                                                   
and a2.TS = a3.TS
and a3.TS = a4.TS
and a4.TS = a5.TS
and a5.TS = a6.TS
and a6.TS = a7.TS 
and a7.TS = a8.TS
and a8.TS = a9.TS
and a9.TS = a10.TS
and a10.TS = a11.TS

or this:

and a1.TS >'15-MAR-18 07:00'                                             
and a1.TS = a2.TS                                                   
and a1.TS = a3.TS
and a1.TS = a4.TS
and a1.TS = a5.TS
and a1.TS = a6.TS
and a1.TS = a7.TS 
and a1.TS = a8.TS
and a1.TS = a9.TS
and a1.TS = a10.TS
and a1.TS = a11.TS
Vince Miller
  • 190
  • 1
  • 2
  • 15

1 Answers1

2

I think the second is preferable. Why? The first imposes a particular ordering on the joins. It is possible that the optimizer recognizes that the two structures are identical, but that I wouldn't assume that is true.

One of the steps in optimization is choosing the ordering of the join operations. This can have a big impact, particularly with regards to indexes and reducing data size.

In a well-structured database, you might not see much of a difference in performance. You can inspect the query plan to see if they are the same. In particular, you want TS to be the first key in an index on all the tables.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786