Tuesday, January 20, 2009

First level of Performance Tuning in SQL Server

A Simple way to performance tune your query:
a) Check if the WHERE clause is using INDEX or FULL TABLE scan using query plan
b) Ensure the columns used in WHERE clause is in the order of the index creation (if applicable)
c) Include the WHERE condition that would limit the number of records to be searched and then the JOIN condition

Recently I have created a query which took nearly 4 minutes to get executed. I did the following changes, which made my query get executed in 2 minutes.
(I have changed the table names for this sample)
Initial Query:
SELECT FROM Employee empINNER JOIN Address adr ON emp.EmpID = adr.EmpIDLEFT OUTER JOIN Phone ph ON emp.EmpID = ph.EmpIDLEFT OUTER JOIN FamilyMembers fly ON emp.EmpID = fly.EmpIDLEFT OUTER JOIN BankDet bk ON emp.EmpID = bk.EmpID
I commented all the JOINs and uncommented each JOINs and verified the execution time. Only for Phone it took more time. Hence I moved the JOIN condition for Phone at the end of the JOINs. This limited the records to be processed for the Phone table and reduced the timing.

Tuned Query:
SELECT FROM Employee empINNER JOIN Address adr ON emp.EmpID = adr.EmpIDLEFT OUTER JOIN FamilyMembers fly ON emp.EmpID = fly.EmpIDLEFT OUTER JOIN BankDet bk ON emp.EmpID = bk.EmpIDLEFT OUTER JOIN Phone ph ON emp.EmpID = ph.EmpID

Sunday, January 18, 2009

Covey's impressive answers (An extract from The Economic Times)



How can you be effective in time when negativism is so pervasive ? This is a perfect time to create long-term competitive advantage . It’s in times like these that people can adapt and make sacrifices . This is really an opportunity for creative businesses to gain long-term competitive advantage. Even if we find that we are not in control of anything, one always has the power of choice to do what one can do.

Every management expert says that tough times should be used to build competitive advantage. But is it easy to think about building competitive advantage when all you are thinking of is survival?

It’s tough because everything around people is negative. When the external factors over which one has no control in a way start to become negative it starts to affect our creative juices. You have to be creative in these times and take advantage of this ‘valley’ and turn it into a ‘peak’ , a new initiative can make a difference and the key to that is to move away from the industrial age model because the industrial age model is top down and command-and-control.

And tough times help unleash the creative force in people’s own professional lives and that feeds upon itself and the creative juices get going again. It’s not easy but it’s within reach. And it’s the perfect time to do so.

This profits vs principles war is seeing the wrong winner in some cases. Do you think there needs to be a rethink on the ‘hows’ of the business?
I think that’s part of it. People have to look up to themselves to begin with - an inside out approach. They must also learn how to involve other people all the way; to involve the entire organisation to look at these issues; to develop systems and structures which reward the right things.

What’s the new model of openness that you are advocating these days? It involves being clear and transparent. In taking the reality of what is happening with the people and then asking them: What do you think we can do in this situation? You will find that it will work on the basic underlying forces that produce trust and openness. We have had misaligned systems that rewarded people for wrong things and this has been happening all around the world.

This is the perfect time to unleash people’s creative energies and come up with new creative ideas and companies can do this with suppliers and their customers because everybody is feeding on the paranoia and the fear.

It’s like a cancer that feeds upon itself and people get victimised by all these forces. So they criticise, they complain, they compare, they become cynical, they compete. This is the perfect time to take advantage of this and turn it around. And you have to be creative on how to do that and that will be the main challenge.

Why have you focused on habits to bring about change? Because people co-relate habits of thought and habits of actions which are completely misaligned with these new realities. And it’s like trying to play tennis with a golf club. The habits, not only of people, but also the structures of the system (Covey calls them habits of organisations) of the organisation are misaligned. The result is that people get negative and pessimistic and discouraged and disparaged and that feeds on itself.

How does one prioritise one’s life when there are so many demands on one’s time because of one’s role as a father, husband, employee, boss?
You have to get everybody in the culture on the same page about what is really important. The thing that is important now is taking advantage of this difficult time by unleashing the creative energy but what’s happening now is that fear is sprayed everywhere. And people have no control over this situation. What is important is the need for a balanced life, in which you learn to say no to things that are urgent even though not important.

Most people spend half their lives doing things that are urgent even though not important and they know it. They don’t have the courage to say no to things that are not important. My Seven Habits book deals with personal and interpersonal, The Eight Habit deals with the organisational. And unless people wake up and change the structures and systems, the entire culture , it won’t happen.

Do you believe in fate? I believe in faith. One of the things that I have admired about India is the spiritualism of the people. That’s a great advantage and because of that spirituality, if one can learn to change the systems we have and learn to synergise with each other, then India can again become a dominant force in the world.

If we look at the progress India has made in the past decade, it’s tremendous. I admire that. You have such tremendous traits, only if you can get out the vindictiveness, defensiveness and the negative energy out of the way.

Full article: http://economictimes.indiatimes.com/Features/Corporate_Dossier/Be_effective_in_tough_times_and_win_back_trust_Stephen_Covey/articleshow/msid-3986583,curpg-1.cms