Question: To my understinding it should be simple, does colA='X' or ColB='X', if any one of them is true then return the result otherwise not. 

```
TableA
╔════╦═══╦═══╦═══╦═══╗
║ id ║ A ║ B ║ C ║ D ║
╠════╬═══╬═══╬═══╬═══╣
║ 1  ║ x ║ x ║ x ║ x ║
║ 2  ║ x ║ x ║ x ║ x ║
║ 3  ║ x ║ x ║ x ║ x ║
╚════╩═══╩═══╩═══╩═══╝

TableB
╔════╦═══╗
║ id ║ A ║
╠════╬═══╣
║  1 ║ x ║
║  2 ║ x ║
║  3 ║ x ║
╚════╩═══╝

select T2.ID from tableA T1
JOIN TableB T2
ON T1.A=T2.A OR T1.B=T2.A OR T1.C=T2.A OR T1.D=T2.A /* **takes 6+ min** */

```

**This simple join takes 6+ minutes.** If I join using only one field, then it is pretty quick. **Also if I write 4 different queries, one for each OR and then Union the result, it is very quick also**.

My question is, **How does SQL OR Query works?** Does it work on current row, does all the ORING and move on to the next or does it do the *complete OR* of the two tables for *each OR*. Even then it should take long as seperate queries are fast enough. I out think an internal optimiser can optiise this really quick: I am comparing one column from one table to 4 column of second table. It should be easy to optimise. Why is it taking so long? **Is there a way to manually optimize this query**. Btw I tried changing = to != or Or to AND but it takes the same amount of time.

Answer: 
I'm not on a machine to check, but I've a feeling you'll have more luck with `SPServer.Local.ServiceInstances` - that sounds like it should give the services on the server in particular rather than the farm in general.
Unfortunately not even that is reliable, as the Foundation Web Application service can be running on servers that are not actually front end servers (i.e. the load balancer never directs traffic to them). Ultimately it is the list of servers that the load balancing mechanism has that determines which servers are true front ends, and because there's various types of load balancers and no single interface to all of them I don't believe there is any one guaranteed method of determining the number of true web front ends in a farm.