Thursday, June 26, 2008

Query Execution Plan








Fig 1



Fig 2


Often in database programming, we face the issue of query optimization. Though the Database Management System (DBMS) has one component known as "Query Optimizer" which takes care of optimization but programmer himself needs to improve the query to get the results efficiently.
While query optimization, there should be some benchmark / indicator to show the efficiency of the query which can help the programmer to decide which part to look on for optimization.

SQL Server 2000 has one such feature know as "Query Execution Plan".
One more terminology needs to be explained before going into that.


Cost of query - It figures how much CPU and I/O the query utilises. An optimized query should take less cost. Using this factor queries are compared for efficiency.

Query Execution Plan -
It means the way the SQL Server runs our query, how it optimizes and what are the costs for different actions of a query.

One very simple example -

There are two tables -Test1 and Test2 with 2 columns id and name each.
Selection the ids and name from these 2 table using following query -

Select T1.id, T2.Name
from test1 T1, test2 T2
where
T1.id = T2.id

Using the Query execution Plan we can do analysis of the costs occurred for the actions inside the query -

Check Fig 1.
It says -

1. Table scan 40 % cost - For scanning the tables T1 and T2, it costs 40 % of the entire query.

2. Hash Matching - For matching the fetched records as per the where clause it takes
19 %.

3. Select 0 % - Finally selecting the records.

(Where does the remaining 1 % go? )


Lets add something to the query - Say sorting -

Select T1.id, T2.Name
from test1 T1, test2 T2
where
T1.id = T2.id
order by T1.id

Check Fig 2.
Now the result has -

Scanning - 36 % each

Hash matching - 17 %

Sorting - This is new and because of the order by clause. Takes 11 %.

Finally select action.

(Its correct as 100 % total appears)

That’s all for this from me. Now your suggestion and advice.


Bye.
Avaneesh S. Tiwari
26 June '08

Sunday, June 15, 2008

Dot net COM interoperability

"COM interoperability" a topic something important for a person coming from C++ / COM background to dot net world. Also a frequent question in dot net tech interviews -

I tried putting few test applications and knowing what it is.
In COM world the final output which we get is in the form of Typelibrary, a binary output.
While in dot net supported languages like C#, the output is know as Assembly, not binary but known as Intermediate Language (IL) output.

On a broad level, COM interoperability is transformation of these two different types of output files.
There could be 2 cases -

1. COM outputs to be used in dot net languages - We need to convert the TypeLibrary to assembly. It’s done by utility - TlbImp.exe - Type library import.

I never used this explicitly as there is simple option tab available while giving reference to COM dll in the dot net editor. It internally manages these all stuff of
Conversion.


2. Dot net dlls to be used in unmanaged environments - It requires conversion of Assembly to TypeLib. It could be done with - RegAsm.exe utility which stands for Register
assembly as Typelib. Honestly saying, I never required and used this.

This is what I could write, please share your experience.

Bye.
Avaneesh Tiwari

15-06-2008

Wednesday, June 11, 2008

Am beginner for non WINDOWS

After working for 4 years in WINDOWS world, I have got chance to work on non windows platform. With these tough days, as a beginner, I could share this much for now.

GNU -
GNU is an organization mainly in the area of Open Source software. Richard Stallman started it. It has been well known for the developments and distribution of tools, utilities, Applications etc. used in conjunction with Unix OS. GNU softwares are distributed with General Public License (GPL). Few applications / tools known to me -

1. GCC - Compiler used for languages like - C, C++, Objective C etc. Now the latest version is - 4.3.1. I am working on little older - 3.2.2 (February 05 release). It supports many languages as well as hardware platforms. With several setting, it can be customized and made to suit our business.

2. GDB - Debugger tool. With command line, it appeared tough for me to use as have migrated from Windows!

3. DDD - Something for my rescue. It uses GDB debugger and provides user interface to some extent. So its a user interface debugger for UNIX / Linux programmers.

Thats all for this article, please share your views.

-- By Avaneesh Tiwari

Thursday, June 5, 2008

A good begining

Friends,

Its a lovely day as I am starting my technical blog. I believe this journey will be a successful one.

-- Avaneesh Tiwari

05-06-2008