Tuesday, December 20, 2011

Bulk Inserts / Updates for Oracle

Today I got a problem on performance enhancement where the basic problem was to move data from one database (A) to another(B) with some transformation. B had exposed Stored Procs to insert and update data and A had to use this interface as per design. Now B only allow insert or update of 1 item at a time as it took parameters like varchar2, int and so on.This slowed down things a lot when bulk updates were required like 1000 rows at a time. So started looking google for something which can make things better.

I knew SQLLoader had parallel execution facilities but how to do it PL/SQL. The simplest was to pass a table of records to the SP (modified) and it will do the update one by one. Still it was technically sequential update with just saves on network transfer of one row at a time by making it a array of records. How to make it really parallel.

So found the Bulk Collect and ForALL of oracle. Never knew Oracle also implemented Collections like other object oriented languages. A simple self explainatory example is :

SQL> create or replace procedure fast_proc is
2         type TObjectTable is table of ALL_OBJECTS%ROWTYPE;
3         ObjectTable$ TObjectTable;
4         begin
5         select
6                     * BULK COLLECT INTO ObjectTable$
7         from ALL_OBJECTS;
8
9         forall x in ObjectTable$.First..ObjectTable$.Last
10       insert into t1 values ObjectTable$(x) ;
11       end;
12 /


More details at :
  1. http://www.dba-oracle.com/oracle_tips_rittman_bulk%20binds_FORALL.htm 
  2. http://www.akadia.com/services/ora_bulk_insert.html 
  3. http://psoug.org/reference/array_processing.html

while going through all this, I did learn the sql mantra:
  1. You should do it in a single SQL statement if at all possible.
  2. If you cannot do it in a single SQL Statement, then do it in PL/SQL.
  3. If you cannot do it in PL/SQL, try a Java Stored Procedure.
  4. If you cannot do it in Java, do it in a C external procedure.
  5. If you cannot do it in a C external routine, you might want to seriously think about why it is you need to do it…


Thursday, November 17, 2011

Error 1001. The specified service has been marked for deletion

Currently I am developing a windows service and after a few Install/UnInstalls from Visual Studio - I got this error:

Error 1001. The specified service has been marked for deletion

Looking at google, I found the most simplest answer to it although MSDN asks you to reboot you workstation:
Just close your Services console (services.msc). It creates a lock on the service hence prevents its complete removal. Just close down your Services console and wow its gone.

Monday, November 7, 2011

Flipkart Pricing

Just a month back I was looking for a 2GB SD card for my camera. I never realized that SD cards are now sol obsolete that you wont find them easily in shops so I went online looking for it. It was easier to get a micro SD card but not the normal one which my camera needs.

Finally I reached Flipkart and I got it in there. I had used it earlier too and it was like 20-30 rupees cheaper than similar online sites and I had used in earlier and liked its speed of delivery. So I order one for Rs 220.











All good. I got it in 2-3 days and all was well.

Around a month back I was checking out some new stuff in there and happened to reach the page again selling the 2 GB SD card  . Wow in a month, the price is up almost 25% to Rs 270. Same was the case for portable hard disks, mp3 players. I was checking out the Sony 2GB mp3 player. The official Sony India site sold it for Rs 2,490 and so did Flipkart. Even Big Bazaar gave a Rs 50 discount if you ordered it online. I order it from another online site which I had used earlier which sold it for Rs 2,200.

Seeing this, in good faith I put on these comparisons - bottom-line being, people flock to online sites to get things cheaper than offline (as they trade off the customer and post delivery service for it). Now if online sites built on this theory and Flipkart being one of them forget this basic tenet and somehow feel that they are big enough now and can sell things on MRP - in my opinion the people who came flocking to them will leave to in droves - as online folks have little loyalty and are more fickle minded - as the human interaction between sales team and customers is the only thing which does not exist in online selling (hence they can and should sell cheaper).

Things would have ended out there but today I got this mail:

Dear Customer,

Thank you for sharing your thoughts at Flipkart.com for "SanDisk Memory Card SD 2GB", dated 02/11/2011.


We would like to inform that your review has been removed since it speaks about price comparison, which is against Flipkart.com review policy. This is because pricing and competition are subject to change with time, and the review might be misleading to our future customers.


However, we have escalated the issue to the concerned department and they are looking into the same.


Thanks for your understanding.


Yours Sincerely,

Sunita Mathew
Customer Review Team
Flipkart.com


Now I get a feel that they are no way different from offline shops or even web 1.0 sites. They all want comments like "Excellent Flipkart" and good stuff. Anything critical about them will be removed. Fine they can as they own the site - but I have my blog :) and I can put it here for others to read.

Final say - Please online sites, be atleast 10-20% cheaper than offline shops as more in India (and even in US) price is the single biggest factor for buying the same product. Everyone including Google ranks products on price so if you lose on the price, no amount of funding can save you guys. Remember what amazon says - we are a logistics company , a distribution company and not a fancy site ( although as engineers we marvel their technology too) but that did not make amazon what it is today.

Sunday, May 1, 2011

Delete Internet Explorer History when disabled by Admin

Sometime Domain Admins disable deletion of Internet Explorer's history by setting a domain group policy. The Internet Explorer "Delete Browsing History" looks like:






















where the check-box next to History is disabled. Still if you want to clear it off, you have 2 options:
  1. Go to registry and enable the check-box - a cumbersome way
  2. Or go the command line way. Just type in the following in the command window:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

and you are all set :)

Sunday, January 30, 2011

Vehicle Routing Problem

Goal:
  1. Come up with a close to optimal solution to Vehicle routing problem related to Cab Management system which can be arrived at linear space and time
  2. Finally publish an article on it.

Create a Facebook App (done)

Goal:
  1. Create a Facebook App.
Done:
  1. Created a small app for QwestIndia site at Facebook named Job 'Openings'.
  2. It pulls data from our Qwest India site: Current Opening's Page .
  3. Its a simple .NET app on Qwest India site which publishes the Current Openings Page at QI site in raw restricted format of HTML allowed by FB.
  4. Details about it is available at FB developers site for Canvas.

Facebook Album Downloader

Goal:
  1. Write a .NET/Java app which can download albums from Facebook.
  2. Port it to Android :)
  3. Publish it

Authentication of WCF services using IIS/AD

Goal: Should write a comprehensible article of WCF Bare webhttp services with authentication with code

TODO's

I was planning to maintain a list of TODO's and was looking for something good to maintain it.
The GMail task list, Outlook task list are pretty basic. Others available will need me to maintain a new account.
So used this blog to maintain it.
Posts labeled as TODO is a todo :)

Tuesday, January 4, 2011

Find locks in Oracle Tables

A lot of time we as developers see Oracle tables being locked. As we all share one dev database, the reason might be some long running query or service on some other workstation.

An easy way to find it out is through a query:


SELECT s1.username
'.'
s1.program
'@'
s1.machine
' ( SID='
s1.sid
' ) is blocking '
s2.username
'.'
s2.program
'@'
s2.machine
' ( SID='
s2.sid
' ) '
AS blocking_status
FROM v$lock l1,
v$session s1,
v$lock l2,
v$session s2
WHERE s1.sid = l1.sid
AND s2.sid = l2.sid
AND l1.BLOCK = 1
AND l2.request > 0
AND l1.id1 = l2.id1
AND l2.id2 = l2.id2