oracleÓÅ»¯Æ÷
What circumstances we use ALL_ROWS and what circumstances we use FIRST_ROWS optimizer mode? This article is written in oracle9i.
First_rows attempts to optimize the query to get the very first row back to the client as fast as possible. This is good for an interactive client server environment where the client runs a query and shows the user the first 10 rows or so and waits for them to page down to get more.
All_rows attempts to optimize the query to get the very last row as fast as possible. This makes sense in a stored procedure for example where the client does not regain control until the stored procedure completes. You don't care if you have to wait to get the first row if the last row gets back to you twice as fast. In a client server/interactive application you may well care about that.
In TOAD or SQL Navigator, When we select the data, it display immediately. But it does not mean that, it is faster. If we scroll down, it might be fetching the data in the background mode. First_rows is best place for OLTP environment. Also in some reporting environment, if user wants to see initial data first and later see the rest of the data, then first_rows is good option. When we run the query in the stored procedure, first_rows would not be a good choice, all_rows is good option here, because, there is no use to fetch the first few records immediatley inside the stored procedure.
Let us demonstrate the FIRST_ROWS/ALL_ROWS optimizer hint.
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
SQL> create table testtable as select * from user_objects;
Table created.
SQL> create index idx on testtable(object_type);
Index created.
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'SCREPORT',TABNAME => 'TESTTABLE',ESTIMATE_PER
CENT => 10, METHOD_OPT => 'FOR ALL COLUMNS SIZE 1', CASCADE => TRUE);
PL/SQL procedure successfully co
Ïà¹ØÎĵµ£º
ѧϰOracle DBAÒ²°ë¸ö¶àѧÆÚÁË£¬½ñÌìÃÍÈ»²Å·¢ÏÖ£¬ÔÀ´ÎÒµÄÊ黹ÊǺÜеģ¬ÉϿβÙ×÷ʱºòÒ²Ö»ÊÇÖªµÀ´ó¸ÅÔõô×ö£¬µ«ÊÇÒªÕæµÄÈ«²¿×Ô¼º×ö£¬¶ø²»È¥·Ê黹ÊÇÓÐÒ»¶¨µÄÄѶȵģ¬ËùÒÔÄØ£¬½ñÌ쿪ʼ½«DBA´ÓÍ·¸´Ï°Ò»±é£¬Í¬Ê±ÔÙ²Ù×÷Ò»±é¡£
µÚÒ»Õ£¬Ñ§µÄÊÇOracleµÄÌåϵ½á¹¹£ ......
oracleѧϰÀú³ÌÖ®´æ´¢¹ý³Ì
(1) ´æ´¢¹ý³Ìͨ¹ý²ÎÊý´«µÝ,°²È«ÐÔ¸ß,¿É·ÀÖ¹×¢Èëʽ¹¥»÷.
(2) ²éѯµÄÓï¾äÔÚ´æ´¢¹ý³ÌÀï,Óë³ÌÐò²»Ïà¹Ø,Èç¹ûÒÔºóÒªÐ޸ijÌÐò»òÕßÊý¾Ý¿â,¶¼²»»á³öÏÖÁ¬Ëø·´Ó¦,Ôö¼Óϵͳ¿ÉÀ©Õ¹ÐÔ.
(3) ÍøÕ¾Ö´ÐвéѯµÄʱºò,Ö»ÐèÒª´«µÝ¼òµ¥µÄ²ÎÊý¾Í¿ÉÒÔÁË,ÎÞÂÛÊÇ´úÂëÓÅ»¯ÉÏ»¹ÊDzéѯÓÅ»¯É϶¼¿ÉÒÔ×öµ½¸ßЧ.
(4) ÔÊÐíÄ£¿é ......
oracleÊý¾Ý¿âʵÀýÆô¶¯Ê±£¬ÐèÒª·ÖÅä¹²ÏíÄڴ棬Æô¶¯ºǫ́½ø³Ì¡£
oracleÊý¾Ý¿âʹÓõÄÄÚ´æÖ÷񻃾¼°µ½£ºPGAºÍSGA¡£
Ò»¡¢ PGA
Program Global Area£¬¹ËÃû˼ÒåÊdzÌÐòÈ«¾ÖÇø£¬ÊÇ·þÎñÆ÷½ø³Ì£¨Server Process£©Ê¹ÓõÄÒ»¿é°üº¬Êý¾ÝºÍ¿ØÖÆÐÅÏ¢µÄÄÚ´æÇøÓò£¬PGAÊǷǹ²ÏíµÄÄڴ棬ÔÚ·þÎñÆ÷½ø³ÌÆô¶¯»ò´´½¨Ê±·ÖÅ䣬²¢ÎªServer ProcessÅÅËû·Ã ......
OracleÒì³£·ÖΪ3ÖÖ:
(1)Ô¤¶¨ÒåÒì³£:no_data_foundµÈ,ÊÇOracleϵͳ¶¨ÒåµÄÒì³£.
declare
s_test varchar2
begin
select id into s_test from test; --´Ëʱtest±íÎÞÊý¾Ý
exception
when no_data_found then
raise_application_error(-20001, 'ûÓÐÊý¾Ý');
end;
(2)×Ô¶ ......