Saturday, November 10, 2012

Oracle cursor exit can be better

I read a linkedin discussion on the cursor where if the cursor %NOTFOUND statement is place after the processing statement, the result will printed the last fetch twice. Example from the discussion below:

DECLARE
I EMPLOYEES.FIRST_NAME%TYPE;
J EMPLOYEES.SALARY%TYPE;

CURSOR C1

IS
SELECT FIRST_NAME,SALARY
FROM EMPLOYEES
WHERE EMPLOYEE_ID BETWEEN 100 AND 105;

BEGIN


OPEN C1;

LOOP
FETCH C1 INTO I,J;
DBMS_OUTPUT.PUT_LINE(I||' SALARY IS '|| J);
EXIT WHEN C1%NOTFOUND;
END LOOP;
CLOSE C1;
END;
/


The correct way was to put the %NOTFOUND a line after the FETCH cursor so the %NOTFOUND statement can be validated straight away after the FETCH statement. Example:

OPEN C1;
LOOP
FETCH C1 INTO I,J;

EXIT WHEN C1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(I||' SALARY IS '|| J);
END LOOP;
CLOSE C1;
END;


Then it puzzled me. Why there is need for an extra line of EXIT WHEN C1%NOTFOUND which can caused potential bug and confusion? Since it's related to the fetch statement, why not oracle put them together as an option? Example:

My idea, not oracle actual code
OPEN C1;
LOOP
FETCH C1 INTO I,J
EXIT WHEN C1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(I||' SALARY IS '|| J);
END LOOP;
CLOSE C1;
END;


This way it causes less confusion and less bug prone.

Well, it just an idea.

Reference
Linkedin Discussion - Hi one small doubt

Saturday, November 3, 2012

Fan noise in AMD APU chip for Ubuntu 12.04

I have installed Ubuntu (Wubi option) on my laptop with AMD APU chip (A6-4400m with internal 7520 GPU and dedicated 7670m GPU). Lately, I have been experiencing loud fan noise but it was normal when I was using Windows 7. I suspected that it may be a bug in Ubuntu that caused high usage of CPU resources. However, the processes monitor did not show high CPU hogging caused by applications. Then I realized that it was the GPU that made all the noise.

After couple of tries in updating the proprietary driver and manual install AMD driver, finally I got the AMD catalyst  control installed and selected the power saving GPU option (including settting maximum battery saving in powerplay option). What the setting does was turning off the dedicated GPU, which is resources hogging and hence, the fan noise. After turning that off, Ubuntu uses the built in GPU the fan noise is gone. :)

Update 13/01/2013: I noticed the fan noise still exist even though I have switched off the dual graphic option. I checked the system monitor to investigate which application was hogging CPU resources and it turned out to be compiz, which mainly used for user interface 3Dd effect. From this discovery, I'm now using 2D option (At Ubuntu login, click on the Ubuntu logo just above the password field and choose 2D option) in order to turn off the compiz feature. Anyway, I'll monitor whether this will help to reduce the fan noise and CPU hogging for couple of weeks.

Update 01/11/2015: After a couple of attempts, I finally switched to Xubuntu with the minimal user interface that solve the cpu hogging isuse.

Links
https://help.ubuntu.com/community/BinaryDriverHowto/ATI