Wednesday, September 2, 2009

DELETE vs. TRUNCATE

“If both Truncate and Delete commands delete all the rows of a table, then what is the difference between DELETE and TRUNCATE command?

Any interviewer may ask this question. The most expected replies could be any of the below:

  1. DELETE is a DML while TRUNCATE is a DDL statement
  2. DELETE is less drastic, in that a deletion can be rolled back whereas a truncation cannot be.
  3. DELETE is also more controllable, in that it is possible to choose which rows to delete, whereas a truncation always affects the whole table.
  4. DELETE is, however, a lot slower and can place a lot of strain on the database. TRUNCATE is virtually instantaneous and effortless

(To know more such answers, look through Geek Interviews Page. I don’t take liability for the irrelevant answers :))

Alright! But how does one prove that TRUNCATE is virtually instantaneous, effortless and is really of better performance than DELETE? How does it work internally?

As said in the first point, TRUNCATE is a DDL command and it operates within the data dictionary and affects the structure of the table, not the contents of the table. However, the change it makes to the structure has the side effect of destroying all the rows in the table.

An insight to it…

The data dictionary will have the definition of data and also table’s physical location. When a table is created, a table is allocated a single area of space (fixed size) in the database’s data files. This is known as an extent and initially will be empty. Then, as rows are inserted into the table, the extent fills up. Once an extent is full, more extents will be allocated to the table automatically. Therefore, a table may consist of one or more extents which hold the rows. Along with tracking the extent allocation, the data dictionary also tracks how much of the space allocated to the table has been used. This is done with the high water mark. The high water mark is the last position in the last extent that has been used; all space below the high water mark has been used for rows at one time or another, and none of the space above the high water mark have been used yet.

It should be noted that it is possible for there to be plenty of space below the high water mark that is not being used at the moment; this is because of rows having been removed with a DELETE command. Inserting rows into a table pushes the high water mark up. Deleting them leaves the high water mark where it is; the space they occupied remains assigned to the table but is freed up for inserting more rows. Truncating a table resets the high water mark. That is, within the data dictionary, the recorded position of the high water mark is moved to the beginning of the table’s first extent. As Oracle assumes that there can be no rows above the high water mark, this has the effect of removing every row from the table. The table is emptied and remains empty until subsequent insertions begin to push the high water mark back up again. In this manner, one DDL command, which does little more than make an update in the data dictionary, can annihilate billions of rows in a table.

Tuesday, August 4, 2009

Short Definition of the Whole World

Worldwide survey was conducted by the UN. The only question asked was:

"Would you please give your honest opinion about solutions to the food shortage in the rest of the world?"

The survey was a huge failure!


In Africa they didn't know what 'food' meant, In India they didn't know what 'honest' meant, In Europe they didn't know what 'shortage' meant, In China they didn't know what 'opinion' meant, In the Middle East they didn't know what 'solution' meant, In South America they didn't know what 'please' meant, And in the USA they didn't know what 'the rest of the world' meant!

About LPIC Exam

https://www.lpi.org

Unlike M$, Cisco exams, LPIC exam do NOT have any dumps or even single focused study guides. It is not narrowed down towards any single Distribution either. You need to try out various distributions including Ubuntu, Fedora, Mandrake, Debian, etc. If you got RHEL DVD then go for it as well.

There are a plenty of resources out there in the Internet. Searching for LPIC Dumps or some other relative keyword may bring you a million links. Yet, LPIC have revised their exam this April 2009 and hence they all may seem 60-70 percent outdated. I have done a search for it last night and collected these resources from various forums, blogs and websites. If you are preparing for the latest LPIC certification exams, you should do ok with the below resources.

LPIC-1 Recommended Books

LPI Linux Certification in a Nutshell (In a Nutshell (O'Reilly)) by Steven Pritchard Steven Pritchard (Author)
LPIC-1: Linux Professional Institute Certification Study Guide by Roderick W. Smith,
LPIC 1 Certification Bible by Angie Nash and Jason Nash
LPIC Prep Kit: 101 General Linux I by Theresa Hadden Martinez

LPIC-1 Mock Exams and Study Materials

NONGNU
ITExamPractice
Wiki
IBM Material

Linux + vs LPIC Certifications

Just a word of advice rather suggestion I would like to give is – If you are in a dilemma on whether to do Linux+ or LPIC then my move will be towards LPIC. LPIC ($150 for 101 exam and $150 102 exam) costs the same as Linux + ($300). CompTIA may sound familiar but then most of their certifications like Security+, Network+ are not considered very seriously. They however might be an add-on for you resume if you are a total fresher.

Good luck!

An interesting read...

http://www.forbes.com/2009/05/13/lie-detector-madoff-entrepreneurs-sales-marketing-liar.html



http://www.privateislandsonline.com/sale-price-under-250K.htm

You can also own islands with as less than 18 laks INR. The best part is, you can rule it as your own kingdom :)