Friday, June 27, 2008

A Sress-Relief Trip To Lonavla

Our team had planned for a trip to Lonavla. I had hesitated to go, as I was not feeling well.I was down with cough and cold. After Hari and Charan left, I was feeling a bit restless and alone. Since we were staying and sharing things together for last one year, It look sometime for me to overcome their separation. They played an eminent role in all my success in last couple of years. Last weekend I was suppose to be alone in home. To avoid this I said OK for Lonavla.
Amit and Anant were the tour managers. As per our plan we have started from Yantra Park by a mini bus at 7 AM. As usual we got the last seat along with Amol. It remembers me the Industrial visit we had in college days.

Oh !! Those were golden days, when we use to start the journey by shouting SALA PULA SALA PULA KUMTAHLAKA. Normally I use to avoid being in a group. My affinity towards groupisim was increased because of the unity we had in our college days. Mootai Annamalai and Maheswaran all use to get themselves involved in 'OOO Poodu'.I feel these kind of small things are playing immense role in bringing people together and creating better relationships. As I was thinning about my olden days we have reached a place in Pune-Mumbai Highway where we had the first stopping for having Vada pav to break our fast. I am planning to write a blog in Vada Pav, the quintessential food for all Mumbaikars.

Amol,Me Sendhil and Gokul


After the first stop we had an hour of journey and reached Lonavla. As I heard It was really a pleasant place with full of greeneries. The monsoon was started already and it has added a bit of lush to the greens around. Actually Lonavla is lying some 600Feet from ground. As we came out of the bus with preparation for taking bath we saw lot of families, couples and friends were already there for enjoying their weekend. We had to trek for about 500 meters in the small mountain to reach a water falls. We spent couple of hours in the water falls.

From there our tour mangers directed us Tiger point. Its a place about five to six miles from Lonavla. It was like “suicide point” in Kodaikanal. We reached there at 3 PM so it was very windy. We were taking snaps and spend the evening there.

We started our journey back to Mumbai from Tiger point. I have to talk about the immaculate highways between Mumbai and Pune. It was really well planned and constructed. Maintaining road of that much width and lanes in hilly area is really difficult. In the return journey I shared my seat with Saurabh , Mr. Billing in our project. He was discussing about his plan to name his child as "Billing”. I know he has gone crazy after doing billing for last two years.

We reached home by half past eight in the evening. I was feeling free after coming back from the trip. Really having some trips to some remote places now and then will definitely relive stress.

Tuesday, June 24, 2008

முதல் தமிழ் வலைபதிவு

வணக்கம் நண்பர்களே !
எனது 50 ஆவது வலைப்பதிவை தமிழில் எழுழ்துவதில் பெரும் மகிழ்ச்சி அடைகிறேன்.இந்தியமொழி அனைத்தும் வழ்ங்கம்படும் இந்த மும்பை நகரம் மொழி மட்டுமல்லாது பல கலாச்சாரங்களின் தொகுப்பாக நான் கண்கிறேன்.சரியாக 2 ஆண்டுகளுக்கு முன்பு ஒரு சாமானிய தமிழனாக, மும்பை பணியை கட்டாய தாலியாக ஏற்ற எங்களுக்கு, இந்த மாநகரம் கற்றுக் கொடுத்திருபவை ஏராளம்.எலக்ட்ரானிக்ஸ் மற்றும் ப்ரோக்ரம்மிங்கில் மட்டும் இருந்த எனது ஆர்வம், மொழி, கலாச்சாரம், லெமுரியா என்று பல பரிமானம் எடுத்து இங்குதான்.
எனது தாய் மொழி அல்லாத பிற மொழியை கேட்கவும் பேசவும் இங்கே வாய்ப்பு கிடைத்தது.தமிழின் அண்டைய மொழியான தெலுங்கு,மலையாளம் போன்ற மொழிகளை கேட்கும் போது நம் மொழியின் தொன்மையும், தொடர்பும் இனிமையும் புலப்படும்.தமிழின் தோற்றத்தின் மேல் ஆர்வம்; தமிழர் கலாச்சரத்தின் மீது மரியாதையை என பல மாற்றங்களை என்னுள் விதைத்தது மும்பை வாழ்க்கை.
நான் எழதிய 49 படிமத்தின் முடிவில், எதோ எனது எண்ணங்கள் அனைத்தும் எழுத்துகளாக மாறாமல் போனதுபோல் ஓர் மாயை மட்டுமே முடிவுரையாக நிற்கும்.தமிழில் சிந்தித்தால் .... இதோ ஒரு கச்சிதமான வரிவடிவம் பெற்றுஇருகிறது என் எண்ணம்.

நன்றி : கூகிள் transliterate

Saturday, June 7, 2008

Wiki Relation - Six Degrees

Wikipedia has now become a standard reference for definition of any matter in this universe.You can see almost all bloggers create a back link to Wiki page for definition of any words they use.It is having analogy with magazines in late 95's referring to oxford dictionary for any peculiar word in their article.I recently read an article on new Mars rover in daily local paper, where they have used a new word related to Mars surface property and the explanation was given like... "As Per Wikipedia....."It shows the power and growth of wikipedia as a standard reference  in last couple of years.

Today I heard the concept of finding the relationship between any two the articles in Wikipedia.It is not the logical relation.It is the number of links between the two articles.In simple words it the number of clicks required to reach one article from other.We can say it the distance between the two articles.So the biggest distance between any two article will define the diameter of the Wikipedia.I have read that this project was an attempt to find the diameter of Wikipedia, but it has given a handy algorithm to find out the distance between two articles.

Example( You can also have a try)

I gave vague unrelated topic,but see! Wiki is having awesome relationship between articles

               Wiki Blog

                                  Wiki relation between Y2K and Purananuru

According to Stephen Dolan,Wikipedia has 2301486 articles with 55550003 links between them.The largest "strongly-connected-component" of Wikipedia has 2111480 articles. That is, there are 2111480 articles with the property that from any of them, it is possible to get to any other one. The rest are mostly pages that no-one has linked to or disambiguation pages.

Stephen has used graph theory to convert the relation between articles as a graph.From Wikipedia's database Stephen got the XML and used scripts to parse the XML to find the graph.Finally distributed Computing algorithms has been used to identify

  • The diameter of Wikipedia
  • The distance between any two articles.

The techincal concepts like parsing, graph Theory and distributed computing has been clearly explained in Stephen's site

It is really an interesting game to play.I tried combinations of two completely different articles but I was able to get the maximum distance of 4.If any one could get more than four please comment on this blog.

Thursday, May 8, 2008

A View on Oracle Locks

Reliability of a database has been determined by the degree to which it strives to achieve atomicity, consistency, isolation and durability, what we can call simply as ACID properties. Oracle is a robust and highly reliable database which has these ACID properties. Locks play a vital role in achieving couple of these properties. Oracle defined lock as Mode and type. Mode defines the way in which a session locks a row or set of rows in a table. Type can be defined as the transaction type which makes this lock happened.

Modes of Lock
There are six lock modes in oracle out of which the sixth lock is NULL lock.They are

Lock Mode Abbreviation
Row Shared SS
Row Exclusive RX
Share S
Share Row Exclusive SRX/SSX
Exclusive X


Lock types
There are three lock types like TM .TX and UL. They are classified according to the transaction which is locking the table. TX denotes a transactional lock which occurs when any transaction changes data from a table. TM is a DML lock which occurs when ever an object is changed. UL is a user defined lock.

Data Dictionary Views
Oracle uses any one of the above locks modes according to the transaction type to achieve the Isolation of ACID. Oracle provides couple of data dictionary views to identify almost all details about locks like who is locking an object, which sessions are waiting for the same object and session details. File and the block where the lock has been made can also be easily identified from the data dictionary views.
• V$lock
• V$locked_object

We will take an example where we will create a lock and we will try to gather the lock details

ses1>create table test_lock(
2 id number,
3 name varchar(200));
Table created.

ses1>insert into test_lock values(1,'apple');
1 row created.
ses1>insert into test_lock values(2,'orange');
1 row created.
ses1>insert into test_lock values(3,'banana');
1 row created.
ses1>insert into test_lock values(4,'mango');
1 row created.
ses1>commit;
Commit complete.

ses1>column id format 99
ses1>column name format a10
ses1>select * from test_lock for update;

ID NAME
--- ----------
1 apple
2 orange
3 banana
4 mango

Session 2 created for updating a single row from the same table

SQL> set sqlprompt ses2>
ses2>
ses2>column id format 99
ses2>column name format a10
ses2>select * from test_lock where id=1 for update;

ID NAME
--- ----------
1 apple
Session 3 for studying the locks due to session 1 and 2

SQL> set sqlprompt ses3>
ses3>column addr format a18
ses3>column kaddr format a18
ses3>column sid format 999
ses3>column ty format a3
ses3>column id1 format 99999999
ses3>column id2 format 99999999
ses3>column lmode format 9999
ses3>column request format 999
ses3>column request format 999
ses3>column block format 9
ses3>set linesize 300
ses3>Select *from v$lock where type in ('TX','TM');

ADDR KADDR SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK------------------ ------------------ ---- -- --------- --------- ----- ------- ---------- -----070000000BBB72B0 070000000BBB7428 48 TX 393237 8560 6 0 2478 1070000000BB6C7E8 070000000BB6C810 48 TM 45405 0 3 0 2478 0070000000BB6C8A8 070000000BB6C8D0 54 TM 45405 0 3 0 2478 0070000000B3C3D90 070000000B3C3DB0 54 TX 393237 8560 0 6 2478 0070000000BBADD18 070000000BBADE90 75 TX 262182 9758 6 0 7460 0070000000BB6C728 070000000BB6C750 75 TM 45400 0 3 0 7460 0070000000BBE3FB0 070000000BBE4128 77 TX 589867 7411 6 0 5773 0070000000BB6C668 070000000BB6C690 77 TM 43850 0 3 0 5773 0

8 rows selected.

LMODE and REQUEST

The LMODE and REQUEST columns both use the same numbering for lock modes, in order of increasing exclusivity: from 0 for no lock, to 6 for exclusive lock. A session must obtain an exclusive TX lock in order to change data; LMODE will be 6. If it can't obtain an exclusive lock because some of the rows it wants to change are locked by another session, then it will request a TX in exclusive mode; LMODE will be 0 since it does not have the lock, and REQUEST will be 6.
You can see this interaction in the rows we selected earlier from v$lock:

SID
This is session id you can join with the V$session and v$sql for finding the session details and sql which is causing the lock.
ses3>

select q.SQL_TEXT
from v$session s,
v$sql q
where s.sid= 54 and
s.SQL_ADDRESS=q.ADDRESS;

SQL_TEXT
------------------------
select * from test_lock where id=1 for update

CTIME
Time since current mode was acquired
ID1 and ID2
The ID1 and ID2 columns point to the rollback segment and transaction table entries for that transaction.
For DML lock the column ID1 shows the object being modified

ses3>select object_name from dba_objects do where do.object_id=45405;

OBJECT_NAME
---------------------------
TEST_LOCK

Block
This column shows whether this lock is blocking some other session

Identifying Locked Table and its Row
We can identify the sid from v$lock table and the corresponding sid in v$session table will gives us the
• object ID,
• the relative file number,
• the block in the datafile,
• the row in the block that the session is waiting on

We can calculate the extended rowid from the above four parameters using the procedure rowid_create in DBMS_ROWID package.

ses3>column object_name format a15
ses3>column row_id format a60
ses3>column query format a 60
ses3>column query format a60
ses3>select do.object_name,
        dbms_rowid.rowid_create(1,
        ROW_WAIT_OBJ#,
        ROW_WAIT_FILE#,
        ROW_WAIT_BLOCK#,
        ROW_WAIT_ROW#) row_id,
        'select * from ' do.object_name ' where rowid = '''
        dbms_rowid.rowid_create(1,
        ROW_WAIT_OBJ#,
        ROW_WAIT_FILE#,
        ROW_WAIT_BLOCK#,
        ROW_WAIT_ROW#) '''' query
from v$session s,
       dba_objects do
where s.sid = 54 and
         s.ROW_WAIT_OBJ# = do.object_id;

OBJECT_NAME              ROW_ID                                                          QUERY
--------------- ------------------------- --------------------------------------------------------
TEST_LOCK AAALFdAALAAAlQ1AAA    select * from TEST_LOCK where rowid = 'AAALFdAALAAAlQ1AAA'

The third column of this query will give the query which will show the column which got locked by the session


ses3>select * from TEST_LOCK where rowid = 'AAALFdAALAAAlQ1AAA';
ID NAME
--- -------
1 apple

. So this way we can find out the
• Lock
• Type of lock and locking user
• object which is locked
• SQL which is locking
• Row which is locked

It would be good if some one reading this blog add some points I missed out :)

Monday, May 5, 2008

Real Live Cricket !!

I am proud to be a passionate lover and follower of the game cricket for long time.Even it has taken a lot of my time in return it has inculcated lot of qualities in me. I started understanding the English conversation after hearing cricket commentary. Even the way I am speaking the language has the influence of commentators I loved to hear. The passion for the game drives me to learn its sensible and exiting parts like pitch preparation and strategy used for controlling a batsman or the planning involved in field setting and using bowlers; testing batsmen patience; even some abusing words in English.

I haven’t got any opportunity to enjoy the game as a spectator among the crowd; I was just enjoying the matches on television. After being to Mumbai I was waiting for an opportunity to get an international match in Mumbai. Last Sunday we got the opportunity to watch a Twenty-Twenty match here in DY Patil Stadium in Nerul.
The match was between Mumbai Indians and Delhi Dare Devils. The effort taken by one of my friend Saurab in arranging tickets for the match has been exceptional. He was in a tight schedule last weekend as he travelled to Indore to attend one of his colleague’s marriage and he travelled back to Pune on Saturday night. He returned to Mumbai the next day morning to give tickets to us. We reached the cricket stadium by half past three in the evening.
There was a big crowd out side the DY Patil Stadium. I was accompanied by Saurabh, Hari, Gokulan and Amol. We were able to see the excitement spread in the ambience.

                                 DY Patil1

                                                             DY Patil Stadium

We went inside the stadium. It was really a well designed and constructed stadium, Galleries were remembering me the galleries of Gabba, Brisbane. It certainly looks eccentric from normal Indian grounds. The boundary size has been reduced to amplify the excitement of the game. I thought why the game has deriving its new dimensions by favoring the batsmen and curtailing the bowler’s interest in the game. Before we reached there Delhi won the toss and elected to field. There where two LCD screens for displaying the slow motions after every delivery and ads.

Five minutes before the match was scheduled one Delhi Player with red and black jersey came out. It was really difficult to identify the player in the ground from the gallery. But I identified him. He was Glen McGrath. I was excited to see him; I was shouting … Hey Mcgra… Mcgra !!.He was doing warm up and bowling with short run-up to his mates. I did not believe that I was seeing McGrath bowling. It took some time for me to bring myself back to the ground state. After that Delhi players started jogging inside the ground I was able to identify Asif ,Shewag and Ghambir.Mcgrath bowled the first over. Watching the match live on the filed is not the same as we are watching in the television. Here we are able to see the reaction of batsmen and the action of bowler and pitch of the ball direction of swing of the bat and running between wickets when ball running down the ground with the help of technology. But if you watch the match live, it is very simple. It was like a college cricket match we played. But I saw players like Sanath playing their shots fluently from middle of their bat. Sixes were hit effortlessly and elegantly by players. It is really a batsmen game.Margin of error is very less so bowlers have to be careful about on their line and length.

                                   DY Patil2

                                                             Second Innings

Shaun Pollock has been really agile in the filed and he lead the team in the absence of Sachin. We enjoyed couple of big sixers from Pollock one over point and other over the mid wicket. I was enjoying watching the game it doesn’t matter who player against whom and what was the score.

Delhi came to bat with in-form Ghambir and Shewag. The left hander failed to open his account and went back to pavilion as he was caught in short cover of a tight bowling from Mumbai Indians. Shewag was really awesome in hitting the ball without moving his feet. He played a mammoth six over the covers of Pollock and a one huge six over mid wicket of Sanath.The elegance with which the game has been played in the international level makes the game seems to be played effortlessly.Brutally punishing bowlers and ear tearing music for cheering the batsman and the cheer leaders dancing for every shot played has made this game as a tool for earning money. I guess I would be wonderful to watch a test match in DY Patil stadium,Mumbai.

Monday, April 28, 2008

Relaxing or Harbhajan Singh !!

This is not a serious analysis on why Bhajji slapped the pace man from Kerala. Harbhajan was known for his atrocities on and off the ground. There were number of incidents where he misbehaved and got suspended. He was suspended from National cricket Academy for misbehaving in the camp. He was fined for racially abusing Symonds. (Sachin helped him in getting the punishment less).It clearly shows that the man from Jalandhar don’t have control over his self. His character is leading himself as an Akthar of India, Talent with immutable animosity.
Actually I have started writing the blog for sharing a Joke I have read about this slapping inceident.By the way I lost my track. Read this !!

Harbhanjan Singh was enjoying the Match. Yuvraj Singh came and asked him, are you relaxing?? Harbhajan answered No I am Harbhajan Singh. VRV Singh Came and asked the same Question. Sardar answered No No Me Harbhajan Singh. Third one came and asked the same question Sardar was totally annoyed and decided to shift his place. While walking Harbhajan saw Sreesanth enjoying the Match. He went and asked him are you Relaxing?? Sreesanth was much educated and answered Yes I am relaxing. Harbhajan slapped him on his face and said Idiot, Sab tere Ko wahahn dhoond rahe hai aur tu Yahaan Aaram Kar raha hai

Friday, April 25, 2008

Query to find Nth MAX or MIN of a column

Writing a query for eccentric requirement is always exiting and challenging. Today I was asked to write a query to find Nth maximum or minimum value of a column in a table with one more column having a common data. (Not that much odd requirement right?).OK, I decided to write it directly without googling it. I manage to write this below query in couple of minutes. Check this query

select [column] from
(select [column],
rank() over(order by [column ]) rnk,
(select count(distinct [column]) from [table]) cnt
from [table] t ) where rnk=cnt+1-&N;


N will be the variable deciding the position of maximum data. For Nth minimum we can use the same query with desc clause in the order by section of the analytic function. Check the steps involved in this requirement

SQL> create table test_tbl(
2 id number,
3 num number);

Table created.

SQL> insert into test_tbl(
2 select rownum,dbms_random.random from task where rownum < 11);

10 rows created.

SQL> commit;

Commit complete.

SQL> select * from test_tbl;


ID NUM
---------- ----------
1 8576
2 566
3 3343
4 100
5 4
6 356
7 345
8 222
9 7465
10 122

10 rows selected.

SQL> select num from
2 (select num,
3 rank() over(order by num ) rnk,
4 (select count (distinct id ) from test_tbl) cnt
5 from test_tbl) where rnk=cnt+1-&n;
Enter value for n: 3
old 5: from test_tbl) where rnk=cnt+1-&n
new 5: from test_tbl) where rnk=cnt+1-3

NUM
----------
3343

SQL> /
Enter value for n: 2
old 5: from test_tbl) where rnk=cnt+1-&n
new 5: from test_tbl) where rnk=cnt+1-2

NUM
----------
7465

SQL> /
Enter value for n: 4
old 5: from test_tbl) where rnk=cnt+1-&n
new 5: from test_tbl) where rnk=cnt+1-4

NUM
----------
566

SQL> spool off

After writing this query I thought of checking the same functionality in the web.I found couple of queries. One of them from oracle site is

select * from tab1 a
where &n = (select count(distinct(b.col1))
from tab1 b where a.col1<=b.col1);


But if you compare the execution plan of the above two queries you will find the first one as much better. Guys, reading this can make a better query and add it as a comment in this blog!!

Subscibe Blog

Add to Google Reader or Homepage