{"id":1916,"date":"2018-11-27T22:40:41","date_gmt":"2018-11-28T00:40:41","guid":{"rendered":"http:\/\/dbtimewizard.com.br\/blog\/?p=1916"},"modified":"2019-11-11T18:36:01","modified_gmt":"2019-11-11T21:36:01","slug":"tirando-um-raio-x-do-desempenho-do-codigo-plsql","status":"publish","type":"post","link":"http:\/\/dbtimewizard.com.br\/blog\/tirando-um-raio-x-do-desempenho-do-codigo-plsql\/","title":{"rendered":"Tirando um RAIO-X do desempenho do c\u00f3digo PL\/SQL"},"content":{"rendered":"<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Voc\u00ea escreveu seu c\u00f3digo PL\/SQL (Procedure, Function ou Package) e na hora de testar descobre que o desempenho n\u00e3o esta satisfat\u00f3rio, e agora? o que fazer?\u00a0A vers\u00e3o do banco Oracle 11g disp\u00f5e do recurso <strong>Hierarchical Profiler<\/strong> que permite medir o desempenho de cada linha de c\u00f3digo do PL\/SQL, com a utiliza\u00e7\u00e3o desse recurso fica f\u00e1cil identificar o que precisa ser melhorado no seu c\u00f3digo.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Neste artigo vamos ver um exemplo pr\u00e1tico de utiliza\u00e7\u00e3o do recurso <strong>Hierarchical Profiler<\/strong> utilizando a ferramenta gr\u00e1fica SQLDeveloper da Oracle.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Para realizar esta simula\u00e7\u00e3o vamos:<\/span><\/p>\n<p style=\"text-align: justify;\"><strong><span style=\"font-size: 12pt;\">1) Configurar o usu\u00e1rio para utilizar o recurso HPROF<\/span><\/strong><br \/>\n<strong><span style=\"font-size: 12pt;\">2) Executar a procedure utilizando HPROF<\/span><\/strong><br \/>\n<strong><span style=\"font-size: 12pt;\">3) Identificar a linha da procedure com baixo desempenho<\/span><\/strong><br \/>\n<strong><span style=\"font-size: 12pt;\">4) Alterar o c\u00f3digo da procedure com baixo desempenho<\/span><\/strong><br \/>\n<strong><span style=\"font-size: 12pt;\">5) Verificar desempenho da procedure ap\u00f3s altera\u00e7\u00e3o do c\u00f3digo<\/span><\/strong><\/p>\n<h2 style=\"text-align: justify;\"><span style=\"font-size: 14pt;\">1) Configurar o usu\u00e1rio para utilizar o recurso HPROF<\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Para utilizar o recurso Hierarchical Profiler precisamos configurar um diret\u00f3rio no servidor do banco, atribuir privil\u00e9gios de acesso neste diret\u00f3rio ao usu\u00e1rio no qual ser\u00e3o criados os c\u00f3digos PL\/SQL, permitir que este usu\u00e1rio execute o pacote DBMS_HPROF, criar as tabelas necess\u00e1rias ao recurso Hierarchical Profiler e criar uma PROCEDURE para realizarmos a simula\u00e7\u00e3o.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">A procedure utilizada nesta simula\u00e7\u00e3o foi criada somente para fins did\u00e1ticos e n\u00e3o deve ser considerada como melhores pr\u00e1ticas de programa\u00e7\u00e3o PL\/SQL.<\/span><\/p>\n<p>&nbsp;<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;width:800px;height:520px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/>89<br \/>90<br \/>91<br \/>92<br \/>93<br \/>94<br \/>95<br \/>96<br \/>97<br \/>98<br \/>99<br \/>100<br \/>101<br \/>102<br \/>103<br \/>104<br \/>105<br \/>106<br \/>107<br \/>108<br \/>109<br \/>110<br \/>111<br \/>112<br \/>113<br \/>114<br \/>115<br \/>116<br \/>117<br \/>118<br \/>119<br \/>120<br \/>121<br \/>122<br \/>123<br \/>124<br \/>125<br \/>126<br \/>127<br \/>128<br \/>129<br \/>130<br \/>131<br \/>132<br \/>133<br \/>134<br \/>135<br \/>136<br \/>137<br \/>138<br \/>139<br \/>140<br \/>141<br \/>142<br \/>143<br \/>144<br \/>145<br \/>146<br \/>147<br \/>148<br \/>149<br \/>150<br \/>151<br \/>152<br \/>153<br \/>154<br \/>155<br \/>156<br \/>157<br \/>158<br \/>159<br \/>160<br \/>161<br \/>162<br \/>163<br \/>164<br \/>165<br \/>166<br \/>167<br \/>168<br \/>169<br \/>170<br \/>171<br \/>172<br \/>173<br \/>174<br \/>175<br \/>176<br \/>177<br \/>178<br \/>179<br \/>180<br \/>181<br \/>182<br \/>183<br \/>184<br \/>185<br \/>186<br \/>187<br \/>188<br \/>189<br \/>190<br \/>191<br \/>192<br \/>193<br \/>194<br \/>195<br \/>196<br \/>197<br \/>198<br \/>199<br \/>200<br \/>201<br \/>202<br \/>203<br \/>204<br \/>205<br \/>206<br \/>207<br \/>208<br \/>209<br \/>210<br \/>211<br \/>212<br \/><\/div><\/td><td><div class=\"php codecolorer\"><span class=\"br0\">&#91;<\/span>oracle<span class=\"sy0\">@<\/span>odbsrv01 oracle<span class=\"br0\">&#93;<\/span>$ <a href=\"http:\/\/www.php.net\/mkdir\"><span class=\"kw3\">mkdir<\/span><\/a> <span class=\"sy0\">\/<\/span>oracle<span class=\"sy0\">\/<\/span>SH<br \/>\n<span class=\"br0\">&#91;<\/span>oracle<span class=\"sy0\">@<\/span>odbsrv01 oracle<span class=\"br0\">&#93;<\/span>$ sqlplus <span class=\"sy0\">\/<\/span> <span class=\"kw1\">as<\/span> sysdba<br \/>\n<br \/>\nSQL<span class=\"sy0\">*<\/span>Plus<span class=\"sy0\">:<\/span> Release 11<span class=\"sy0\">.<\/span>2<span class=\"sy0\">.<\/span>0<span class=\"sy0\">.<\/span>4<span class=\"sy0\">.<\/span>0 Production on Fri Nov <span class=\"nu0\">23<\/span> <span class=\"nu0\">10<\/span><span class=\"sy0\">:<\/span><span class=\"nu0\">43<\/span><span class=\"sy0\">:<\/span><span class=\"nu0\">49<\/span> <span class=\"nu0\">2018<\/span><br \/>\n<br \/>\nCopyright <span class=\"br0\">&#40;<\/span>c<span class=\"br0\">&#41;<\/span> <span class=\"nu0\">1982<\/span><span class=\"sy0\">,<\/span> <span class=\"nu0\">2013<\/span><span class=\"sy0\">,<\/span> Oracle<span class=\"sy0\">.<\/span> &nbsp;All rights reserved<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nConnected to<span class=\"sy0\">:<\/span><br \/>\nOracle Database 11g Enterprise Edition Release 11<span class=\"sy0\">.<\/span>2<span class=\"sy0\">.<\/span>0<span class=\"sy0\">.<\/span>4<span class=\"sy0\">.<\/span>0 <span class=\"sy0\">-<\/span> 64bit Production<br \/>\nWith the Partitioning<span class=\"sy0\">,<\/span> Real Application Clusters<span class=\"sy0\">,<\/span> Automatic Storage Management<span class=\"sy0\">,<\/span> OLAP<span class=\"sy0\">,<\/span><br \/>\nData Mining and Real Application Testing options<br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <br \/>\nSQL<span class=\"sy0\">&gt;<\/span> SELECT <span class=\"sy0\">*<\/span> FROM V<span class=\"re0\">$VERSION<\/span> where rownum <span class=\"sy0\">&lt;<\/span> <span class=\"nu0\">2<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\nBANNER<br \/>\n<span class=\"sy0\">--------------------------------------------------------------------------------<\/span><br \/>\nOracle Database 11g Enterprise Edition Release 11<span class=\"sy0\">.<\/span>2<span class=\"sy0\">.<\/span>0<span class=\"sy0\">.<\/span>4<span class=\"sy0\">.<\/span>0 <span class=\"sy0\">-<\/span> 64bit Production<br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> create directory PLSHPROF_DIR <span class=\"kw1\">as<\/span> <span class=\"st_h\">'\/oracle\/SH'<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<br \/>\nDirectory created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">--<\/span> Atribuir os privil\u00e9gios para usu\u00e1rio SH<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> grant read<span class=\"sy0\">,<\/span>write on directory PLSHPROF_DIR to SH<span class=\"sy0\">;<\/span><br \/>\n<br \/>\nGrant succeeded<span class=\"sy0\">.<\/span><br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> grant execute on DBMS_HPROF to SH<span class=\"sy0\">;<\/span><br \/>\n<br \/>\nGrant succeeded<span class=\"sy0\">.<\/span><br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">--<\/span> Criar <span class=\"kw1\">as<\/span> tabelas para HPROF no schema SH<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> conn sh<span class=\"sy0\">\/<\/span>sh<br \/>\nConnected<span class=\"sy0\">.<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">@<\/span>?<span class=\"sy0\">\/<\/span>rdbms<span class=\"sy0\">\/<\/span>admin<span class=\"sy0\">\/<\/span>dbmshptab<span class=\"sy0\">.<\/span>sql<span class=\"sy0\">;<\/span><br \/>\n<br \/>\nTable dropped<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nTable dropped<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nTable dropped<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nSequence dropped<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nTable created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nComment created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nTable created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nComment created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nTable created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nComment created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\n<br \/>\nSequence created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">--<\/span> Criar <span class=\"kw1\">as<\/span> tabelas auxiliares<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> CREATE TABLE SH<span class=\"sy0\">.<\/span>CUSTOMERS_COUNTRIES<br \/>\n&nbsp; <span class=\"nu0\">2<\/span> &nbsp; &nbsp; <span class=\"br0\">&#40;<\/span> &nbsp; &nbsp; &nbsp; COUNTRY_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VARCHAR2<span class=\"br0\">&#40;<\/span><span class=\"nu0\">40<\/span> BYTE<span class=\"br0\">&#41;<\/span> &nbsp; &nbsp; &nbsp; NOT <span class=\"kw4\">NULL<\/span> ENABLE<span class=\"sy0\">,<\/span><br \/>\n&nbsp; <span class=\"nu0\">3<\/span> &nbsp; &nbsp; COUNTRY_REGION &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VARCHAR2<span class=\"br0\">&#40;<\/span><span class=\"nu0\">20<\/span> BYTE<span class=\"br0\">&#41;<\/span> &nbsp; &nbsp; &nbsp; NOT <span class=\"kw4\">NULL<\/span> ENABLE<span class=\"sy0\">,<\/span><br \/>\n&nbsp; <span class=\"nu0\">4<\/span> &nbsp; &nbsp; CUST_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NOT <span class=\"kw4\">NULL<\/span> ENABLE<span class=\"sy0\">,<\/span><br \/>\n&nbsp; <span class=\"nu0\">5<\/span> &nbsp; &nbsp; CUST_GENDER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHAR<span class=\"br0\">&#40;<\/span><span class=\"nu0\">1<\/span> BYTE<span class=\"br0\">&#41;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NOT <span class=\"kw4\">NULL<\/span> ENABLE<span class=\"sy0\">,<\/span><br \/>\n&nbsp; <span class=\"nu0\">6<\/span> &nbsp; &nbsp; CUST_STATE_PROVINCE &nbsp; &nbsp; VARCHAR2<span class=\"br0\">&#40;<\/span><span class=\"nu0\">40<\/span> BYTE<span class=\"br0\">&#41;<\/span> &nbsp; &nbsp; &nbsp; NOT <span class=\"kw4\">NULL<\/span> ENABLE<span class=\"sy0\">,<\/span><br \/>\n&nbsp; <span class=\"nu0\">7<\/span> &nbsp; &nbsp; CONSTRAINT cust_countr_pk PRIMARY <a href=\"http:\/\/www.php.net\/key\"><span class=\"kw3\">KEY<\/span><\/a> <span class=\"br0\">&#40;<\/span>CUST_ID<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; <span class=\"nu0\">8<\/span> &nbsp; &nbsp; USING INDEX TABLESPACE USERS <span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; <span class=\"nu0\">9<\/span> &nbsp; &nbsp; TABLESPACE USERS <span class=\"sy0\">;<\/span><br \/>\n<br \/>\nTable created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> CREATE TABLE SH<span class=\"sy0\">.<\/span>SALES_SUM<br \/>\n&nbsp; <span class=\"nu0\">2<\/span> &nbsp; &nbsp; <span class=\"br0\">&#40;<\/span> &nbsp; &nbsp; &nbsp; CUST_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NOT <span class=\"kw4\">NULL<\/span> ENABLE<span class=\"sy0\">,<\/span><br \/>\n&nbsp; <span class=\"nu0\">3<\/span> &nbsp; &nbsp; AMOUNT_SOLD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NUMBER<span class=\"br0\">&#40;<\/span><span class=\"nu0\">10<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">2<\/span><span class=\"br0\">&#41;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NOT <span class=\"kw4\">NULL<\/span> ENABLE<span class=\"sy0\">,<\/span><br \/>\n&nbsp; <span class=\"nu0\">4<\/span> &nbsp; &nbsp; CONSTRAINT sale_sum_pk PRIMARY <a href=\"http:\/\/www.php.net\/key\"><span class=\"kw3\">KEY<\/span><\/a> <span class=\"br0\">&#40;<\/span>CUST_ID<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; <span class=\"nu0\">5<\/span> &nbsp; &nbsp; USING INDEX TABLESPACE USERS <span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; <span class=\"nu0\">6<\/span> &nbsp; &nbsp; TABLESPACE USERS <span class=\"sy0\">;<\/span><br \/>\n<br \/>\nTable created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">--<\/span> Criar uma procedure no schema SH<br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">-----------------------------------------------<\/span><br \/>\nSQL<span class=\"sy0\">&gt;<\/span> <br \/>\nSQL<span class=\"sy0\">&gt;<\/span> create or replace PROCEDURE PRC_REPORT_01<span class=\"br0\">&#40;<\/span><br \/>\n&nbsp; <span class=\"nu0\">2<\/span> &nbsp;in_country_name &nbsp; &nbsp;IN varchar2<br \/>\n&nbsp; <span class=\"nu0\">3<\/span> &nbsp;<span class=\"br0\">&#41;<\/span> IS<br \/>\n&nbsp; <span class=\"nu0\">4<\/span><br \/>\n&nbsp; <span class=\"nu0\">5<\/span> &nbsp;CURSOR c_cust_count IS<br \/>\n&nbsp; <span class=\"nu0\">6<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Select cu<span class=\"sy0\">.<\/span>cust_id<span class=\"sy0\">,<\/span> co<span class=\"sy0\">.<\/span>country_name<span class=\"sy0\">,<\/span> co<span class=\"sy0\">.<\/span>country_region<span class=\"sy0\">,<\/span> cu<span class=\"sy0\">.<\/span>cust_gender<span class=\"sy0\">,<\/span> cu<span class=\"sy0\">.<\/span>cust_state_province<br \/>\n&nbsp; <span class=\"nu0\">7<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;From customers cu<span class=\"sy0\">,<\/span> countries co<br \/>\n&nbsp; <span class=\"nu0\">8<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Where cu<span class=\"sy0\">.<\/span>country_id <span class=\"sy0\">=<\/span> co<span class=\"sy0\">.<\/span>country_id<br \/>\n&nbsp; <span class=\"nu0\">9<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and co<span class=\"sy0\">.<\/span>country_name <span class=\"sy0\">=<\/span> in_country_name<br \/>\n&nbsp;<span class=\"nu0\">10<\/span> &nbsp; &nbsp; &nbsp; &nbsp;Order By cu<span class=\"sy0\">.<\/span>cust_id<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">11<\/span><br \/>\n&nbsp;<span class=\"nu0\">12<\/span> &nbsp;CURSOR c_sales_sum IS<br \/>\n&nbsp;<span class=\"nu0\">13<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Select s<span class=\"sy0\">.<\/span>cust_id<span class=\"sy0\">,<\/span> sum<span class=\"br0\">&#40;<\/span>s<span class=\"sy0\">.<\/span>amount_sold<span class=\"br0\">&#41;<\/span> amount_sold<br \/>\n&nbsp;<span class=\"nu0\">14<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;From sales s<br \/>\n&nbsp;<span class=\"nu0\">15<\/span> &nbsp;<span class=\"sy0\">--<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;From sales s<span class=\"sy0\">,<\/span> customers_countries cc<br \/>\n&nbsp;<span class=\"nu0\">16<\/span> &nbsp;<span class=\"sy0\">--<\/span> &nbsp; &nbsp; &nbsp; &nbsp; Where s<span class=\"sy0\">.<\/span>cust_id <span class=\"sy0\">=<\/span> cc<span class=\"sy0\">.<\/span>cust_id<br \/>\n&nbsp;<span class=\"nu0\">17<\/span> &nbsp; &nbsp; &nbsp; &nbsp;Group By s<span class=\"sy0\">.<\/span>cust_id<br \/>\n&nbsp;<span class=\"nu0\">18<\/span> &nbsp; &nbsp; &nbsp; &nbsp;Order By s<span class=\"sy0\">.<\/span>cust_id<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">19<\/span><br \/>\n&nbsp;<span class=\"nu0\">20<\/span> &nbsp;CURSOR c_report IS<br \/>\n&nbsp;<span class=\"nu0\">21<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Select cc<span class=\"sy0\">.<\/span>country_region<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>country_name<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>cust_state_province<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>cust_gender<span class=\"sy0\">,<\/span> sum<span class=\"br0\">&#40;<\/span>ss<span class=\"sy0\">.<\/span>amount_sold<span class=\"br0\">&#41;<\/span> amount_sold<br \/>\n&nbsp;<span class=\"nu0\">22<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;From customers_countries cc<span class=\"sy0\">,<\/span><br \/>\n&nbsp;<span class=\"nu0\">23<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sales_sum ss<br \/>\n&nbsp;<span class=\"nu0\">24<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Where cc<span class=\"sy0\">.<\/span>cust_id <span class=\"sy0\">=<\/span> ss<span class=\"sy0\">.<\/span>cust_id<br \/>\n&nbsp;<span class=\"nu0\">25<\/span> &nbsp; &nbsp; &nbsp; &nbsp;Group By cc<span class=\"sy0\">.<\/span>country_region<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>country_name<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>cust_state_province<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>cust_gender<br \/>\n&nbsp;<span class=\"nu0\">26<\/span> &nbsp; &nbsp; &nbsp; &nbsp;Order By cc<span class=\"sy0\">.<\/span>country_region<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>country_name<span class=\"sy0\">,<\/span> cc<span class=\"sy0\">.<\/span>cust_state_province<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">27<\/span><br \/>\n&nbsp;<span class=\"nu0\">28<\/span><br \/>\n&nbsp;<span class=\"nu0\">29<\/span> &nbsp;reg_cust_count &nbsp; c_cust_count<span class=\"sy0\">%<\/span>ROWTYPE<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">30<\/span><br \/>\n&nbsp;<span class=\"nu0\">31<\/span> &nbsp;reg_sales_sum &nbsp; &nbsp;c_sales_sum<span class=\"sy0\">%<\/span>ROWTYPE<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">32<\/span><br \/>\n&nbsp;<span class=\"nu0\">33<\/span> &nbsp;reg_report &nbsp; &nbsp; &nbsp; c_report<span class=\"sy0\">%<\/span>ROWTYPE<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">34<\/span><br \/>\n&nbsp;<span class=\"nu0\">35<\/span> &nbsp;BEGIN<br \/>\n&nbsp;<span class=\"nu0\">36<\/span><br \/>\n&nbsp;<span class=\"nu0\">37<\/span> &nbsp; &nbsp; EXECUTE IMMEDIATE <span class=\"st_h\">'truncate table customers_countries'<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">38<\/span> &nbsp; &nbsp; EXECUTE IMMEDIATE <span class=\"st_h\">'truncate table sales_sum'<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">39<\/span><br \/>\n&nbsp;<span class=\"nu0\">40<\/span> &nbsp; &nbsp; OPEN c_cust_count<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">41<\/span><br \/>\n&nbsp;<span class=\"nu0\">42<\/span> &nbsp; &nbsp; &nbsp; &nbsp;LOOP<br \/>\n&nbsp;<span class=\"nu0\">43<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FETCH c_cust_count<br \/>\n&nbsp;<span class=\"nu0\">44<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INTO reg_cust_count<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">45<\/span><br \/>\n&nbsp;<span class=\"nu0\">46<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href=\"http:\/\/www.php.net\/exit\"><span class=\"kw3\">EXIT<\/span><\/a> WHEN c_cust_count<span class=\"sy0\">%<\/span>NOTFOUND<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">47<\/span><br \/>\n&nbsp;<span class=\"nu0\">48<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INSERT INTO CUSTOMERS_COUNTRIES <span class=\"br0\">&#40;<\/span>country_name<span class=\"sy0\">,<\/span> country_region<span class=\"sy0\">,<\/span> cust_id<span class=\"sy0\">,<\/span> cust_gender<span class=\"sy0\">,<\/span> cust_state_province<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp;<span class=\"nu0\">49<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VALUES<span class=\"br0\">&#40;<\/span>reg_cust_count<span class=\"sy0\">.<\/span>country_name<span class=\"sy0\">,<\/span> reg_cust_count<span class=\"sy0\">.<\/span>country_region<span class=\"sy0\">,<\/span> reg_cust_count<span class=\"sy0\">.<\/span>cust_id<span class=\"sy0\">,<\/span> reg_cust_count<span class=\"sy0\">.<\/span>cust_gender<span class=\"sy0\">,<\/span> reg_cust_count<span class=\"sy0\">.<\/span>cust_state_province<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">50<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMIT<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">51<\/span><br \/>\n&nbsp;<span class=\"nu0\">52<\/span> &nbsp; &nbsp; &nbsp; &nbsp;<a href=\"http:\/\/www.php.net\/end\"><span class=\"kw3\">END<\/span><\/a> LOOP<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">53<\/span><br \/>\n&nbsp;<span class=\"nu0\">54<\/span> &nbsp; &nbsp; CLOSE c_cust_count<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">55<\/span><br \/>\n&nbsp;<span class=\"nu0\">56<\/span> &nbsp; &nbsp; OPEN c_sales_sum<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">57<\/span><br \/>\n&nbsp;<span class=\"nu0\">58<\/span> &nbsp; &nbsp; &nbsp; &nbsp;LOOP<br \/>\n&nbsp;<span class=\"nu0\">59<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FETCH c_sales_sum<br \/>\n&nbsp;<span class=\"nu0\">60<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INTO reg_sales_sum<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">61<\/span><br \/>\n&nbsp;<span class=\"nu0\">62<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href=\"http:\/\/www.php.net\/exit\"><span class=\"kw3\">EXIT<\/span><\/a> WHEN c_sales_sum<span class=\"sy0\">%<\/span>NOTFOUND<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">63<\/span><br \/>\n&nbsp;<span class=\"nu0\">64<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INSERT INTO SALES_SUM <span class=\"br0\">&#40;<\/span>cust_id<span class=\"sy0\">,<\/span> amount_sold<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp;<span class=\"nu0\">65<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VALUES<span class=\"br0\">&#40;<\/span>reg_sales_sum<span class=\"sy0\">.<\/span>cust_id<span class=\"sy0\">,<\/span> reg_sales_sum<span class=\"sy0\">.<\/span>amount_sold<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">66<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMIT<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">67<\/span><br \/>\n&nbsp;<span class=\"nu0\">68<\/span> &nbsp; &nbsp; &nbsp; &nbsp;<a href=\"http:\/\/www.php.net\/end\"><span class=\"kw3\">END<\/span><\/a> LOOP<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">69<\/span><br \/>\n&nbsp;<span class=\"nu0\">70<\/span> &nbsp; &nbsp; CLOSE c_sales_sum<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">71<\/span><br \/>\n&nbsp;<span class=\"nu0\">72<\/span> &nbsp; &nbsp; OPEN c_report<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">73<\/span><br \/>\n&nbsp;<span class=\"nu0\">74<\/span> &nbsp; &nbsp; &nbsp; &nbsp;LOOP<br \/>\n&nbsp;<span class=\"nu0\">75<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FETCH c_report<br \/>\n&nbsp;<span class=\"nu0\">76<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INTO reg_report<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">77<\/span><br \/>\n&nbsp;<span class=\"nu0\">78<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href=\"http:\/\/www.php.net\/exit\"><span class=\"kw3\">EXIT<\/span><\/a> WHEN c_report<span class=\"sy0\">%<\/span>NOTFOUND<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">79<\/span><br \/>\n&nbsp;<span class=\"nu0\">80<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dbms_output<span class=\"sy0\">.<\/span>put_line<span class=\"br0\">&#40;<\/span>reg_report<span class=\"sy0\">.<\/span>country_region<span class=\"sy0\">||<\/span><span class=\"st_h\">'_'<\/span><span class=\"sy0\">||<\/span>reg_report<span class=\"sy0\">.<\/span>country_name<span class=\"sy0\">||<\/span><span class=\"st_h\">'_'<\/span><span class=\"sy0\">||<\/span>reg_report<span class=\"sy0\">.<\/span>cust_state_province<span class=\"sy0\">||<\/span><span class=\"st_h\">'_'<\/span><span class=\"sy0\">||<\/span>reg_report<span class=\"sy0\">.<\/span>cust_gender<span class=\"sy0\">||<\/span><span class=\"st_h\">' =&gt; '<\/span><span class=\"sy0\">||<\/span> reg_report<span class=\"sy0\">.<\/span>amount_sold<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">81<\/span><br \/>\n&nbsp;<span class=\"nu0\">82<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMIT<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">83<\/span><br \/>\n&nbsp;<span class=\"nu0\">84<\/span> &nbsp; &nbsp; &nbsp; &nbsp;<a href=\"http:\/\/www.php.net\/end\"><span class=\"kw3\">END<\/span><\/a> LOOP<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">85<\/span><br \/>\n&nbsp;<span class=\"nu0\">86<\/span> &nbsp; &nbsp; CLOSE c_report<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">87<\/span><br \/>\n&nbsp;<span class=\"nu0\">88<\/span><br \/>\n&nbsp;<span class=\"nu0\">89<\/span><br \/>\n&nbsp;<span class=\"nu0\">90<\/span> &nbsp;EXCEPTION<br \/>\n&nbsp;<span class=\"nu0\">91<\/span> &nbsp; &nbsp; WHEN OTHERS THEN<br \/>\n&nbsp;<span class=\"nu0\">92<\/span><br \/>\n&nbsp;<span class=\"nu0\">93<\/span> &nbsp; &nbsp; &nbsp; &nbsp;DBMS_OUTPUT<span class=\"sy0\">.<\/span>PUT_LINE<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'ERRO :'<\/span> <span class=\"sy0\">||<\/span> SQLCODE <span class=\"sy0\">||<\/span> <span class=\"st_h\">' - '<\/span> <span class=\"sy0\">||<\/span> SQLERRM<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">94<\/span><br \/>\n&nbsp;<span class=\"nu0\">95<\/span> &nbsp; &nbsp; &nbsp; &nbsp;CLOSE c_cust_count<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">96<\/span> &nbsp; &nbsp; &nbsp; &nbsp;CLOSE c_sales_sum<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">97<\/span> &nbsp; &nbsp; &nbsp; &nbsp;CLOSE c_report<span class=\"sy0\">;<\/span><br \/>\n&nbsp;<span class=\"nu0\">98<\/span><br \/>\n&nbsp;<span class=\"nu0\">99<\/span> &nbsp;<a href=\"http:\/\/www.php.net\/end\"><span class=\"kw3\">END<\/span><\/a> PRC_REPORT_01<span class=\"sy0\">;<\/span><br \/>\n<span class=\"nu0\">100<\/span> &nbsp;<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\nProcedure created<span class=\"sy0\">.<\/span><br \/>\n<br \/>\nSQL<span class=\"sy0\">&gt;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-size: 14pt;\">2) Executar a procedure utilizando HPROF<\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Vamos abrir uma conex\u00e3o no banco Oracle com o usu\u00e1rio SH utilizando o SQLDeveloper, na lista de objetos do usu\u00e1rio SH vamos clicar com o bot\u00e3o direito na PROCEDURE PRC_REPORT_01 e clicar em PROFILE&#8230; conforme imagem abaixo:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/01_acionar_HPROF.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1908\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/01_acionar_HPROF-1024x533.jpg\" alt=\"01_acionar_HPROF\" width=\"860\" height=\"448\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/01_acionar_HPROF-1024x533.jpg 1024w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/01_acionar_HPROF-300x156.jpg 300w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/01_acionar_HPROF.jpg 1095w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Na sequ\u00eancia ser\u00e1 aberta uma janela PERFIL PL\/SQL onde vamos informar o par\u00e2metro PA\u00cdS igual a &#8220;Canada&#8221;, conforme imagem abaixo:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/02_Passar_variavel.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1909\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/02_Passar_variavel.jpg\" alt=\"02_Passar_variavel\" width=\"636\" height=\"500\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/02_Passar_variavel.jpg 636w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/02_Passar_variavel-300x236.jpg 300w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-size: 14pt;\">3) Identificar a linha da procedure com baixo desempenho<\/span><\/h2>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Ap\u00f3s a execu\u00e7\u00e3o da procedure algumas estat\u00edsticas ser\u00e3o exibidas, na imagem abaixo temos o tempo total de execu\u00e7\u00e3o da procedure em micro-segundos indicado pela seta vermelha 01, ao clicarmos nesse valor aparecer\u00e1 uma janela abaixo com as informa\u00e7\u00f5es estat\u00edsticas de cada linha do c\u00f3digo PL\/SQL executado, para identificarmos a linha que esta consumindo mais tempo no c\u00f3digo precisamos clicar na seta de ordena\u00e7\u00e3o descendente do campo FUNCTION % (seta vermelha 02), nesta simula\u00e7\u00e3o podemos ver que a linha 66 da procedure esta consumindo 70,2% do tempo total de execu\u00e7\u00e3o da procedure e essa linha foi executada 7059 vezes.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/03_Estatisticas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1910\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/03_Estatisticas-1024x386.jpg\" alt=\"03_Estatisticas\" width=\"860\" height=\"324\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/03_Estatisticas-1024x386.jpg 1024w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/03_Estatisticas-300x113.jpg 300w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/03_Estatisticas.jpg 1476w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Clicando na aba C\u00d3DIGO e localizando a linha 66, conforme indicado pelas setas vermelhas na imagem abaixo, podemos observar que a linha 66 corresponde ao comando COMMIT, este comando esta dentro de um LOOP que foi executado 7059 vezes pois o cursor C_SALES_SUM selecionou 7059 linhas.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/04_Linha_codigo.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1911\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/04_Linha_codigo-1024x547.jpg\" alt=\"04_Linha_codigo\" width=\"860\" height=\"459\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/04_Linha_codigo-1024x547.jpg 1024w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/04_Linha_codigo-300x160.jpg 300w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/04_Linha_codigo.jpg 1041w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Uma forma de tornar a procedure mais r\u00e1pida seria diminuindo o numero de linhas selecionadas no cursor C_SALES_SUM, verificando a consulta utilizada neste cursor, conforme imagem abaixo, podemos observar que ela esta selecionando todos os registros da tabela SALES, pois n\u00e3o existe um filtro na cl\u00e1usula WHERE. Como o relat\u00f3rio criado por esta procedure visa recuperar somente as informa\u00e7\u00f5es referentes a um determinado PA\u00cdS, podemos alterar esta consulta fazendo um JOIN com a tabela CUSTOMERS_COUNTRIES para selecionar na tabela SALES somente os registros referentes ao PA\u00cdS especificado como par\u00e2metro na procedure. Na procedure que foi executa o c\u00f3digo deste JOIN estava comentado, conforme imagem abaixo:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/05_Consulta.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1912\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/05_Consulta-1024x547.jpg\" alt=\"05_Consulta\" width=\"860\" height=\"459\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/05_Consulta-1024x547.jpg 1024w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/05_Consulta-300x160.jpg 300w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/05_Consulta.jpg 1041w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: justify;\"><span style=\"font-size: 14pt;\">4) Alterar o c\u00f3digo da procedure com baixo desempenho<\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Vamos alterar o c\u00f3digo da procedure conforme imagem abaixo:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/06_Consulta_alterada.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1913\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/06_Consulta_alterada-1024x547.jpg\" alt=\"06_Consulta_alterada\" width=\"860\" height=\"459\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/06_Consulta_alterada-1024x547.jpg 1024w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/06_Consulta_alterada-300x160.jpg 300w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/06_Consulta_alterada.jpg 1041w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Na sequ\u00eancia vamos compilar a procedure no banco, clicando no \u00edcone de engrenagem e na op\u00e7\u00e3o COMPILAR, conforme imagem abaixo:<\/span><\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/07_Compilar_procedure.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1914\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/07_Compilar_procedure-1024x547.jpg\" alt=\"07_Compilar_procedure\" width=\"860\" height=\"459\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/07_Compilar_procedure-1024x547.jpg 1024w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/07_Compilar_procedure-300x160.jpg 300w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/07_Compilar_procedure.jpg 1041w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: justify;\"><span style=\"font-size: 14pt;\">5) Verificar o desempenho da procedure ap\u00f3s altera\u00e7\u00e3o do c\u00f3digo<\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Ap\u00f3s a compila\u00e7\u00e3o da procedure vamos execut\u00e1-la novamente repetindo os passos da etapa 2 e na sequ\u00eancia conferir as estat\u00edsticas conforme imagem abaixo:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/08_Estatisticas2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1915\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/08_Estatisticas2-1024x385.jpg\" alt=\"08_Estatisticas2\" width=\"860\" height=\"323\" srcset=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/08_Estatisticas2-1024x385.jpg 1024w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/08_Estatisticas2-300x113.jpg 300w, http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/11\/08_Estatisticas2.jpg 1477w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12pt;\">Na imagem acima podemos verificar que o tempo de execu\u00e7\u00e3o da procedure antes da altera\u00e7\u00e3o foi de 4.699.941 micro-segundos, ou 4,7 segundos. Na execu\u00e7\u00e3o ap\u00f3s a altera\u00e7\u00e3o da procedure o tempo de execu\u00e7\u00e3o caiu para 122.611 micro-segundos, ou 12 cent\u00e9simos de segundo.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: justify;\"><span style=\"font-size: 14pt;\">Refer\u00eancias<\/span><\/h2>\n<p><strong><span style=\"font-size: 12pt;\"><a href=\"https:\/\/oracle-base.com\/articles\/11g\/plsql-hierarchical-profiler-11gr1\" target=\"_blank\">https:\/\/oracle-base.com\/articles\/11g\/plsql-hierarchical-profiler-11gr1<\/a><\/span><\/strong><\/p>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n<a href=\"http:\/\/dbtimewizard.com.br\/treinamento\/\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-1255\" src=\"http:\/\/dbtimewizard.com.br\/blog\/wp-content\/uploads\/2018\/10\/promo_cur02.jpg\" alt=\"Promo-D75L\" width=\"330\" height=\"242\" \/><\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/l6OphhTle9I\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-1215\" src=\"http:\/\/dbtimewizard.com.br\/wp-content\/uploads\/2018\/01\/video-02-300x168.jpg\" alt=\"video-02\" width=\"330\" height=\"242\" \/><\/a><br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea escreveu seu c\u00f3digo PL\/SQL (Procedure, Function ou Package) e na hora de testar descobre que o desempenho n\u00e3o esta satisfat\u00f3rio, e agora? o que fazer?\u00a0A vers\u00e3o do banco Oracle 11g disp\u00f5e do recurso Hierarchical Profiler que permite medir o desempenho de cada linha de c\u00f3digo do PL\/SQL, com a utiliza\u00e7\u00e3o desse recurso fica f\u00e1cil identificar o que precisa ser<\/p>\n","protected":false},"author":2,"featured_media":1907,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[211],"tags":[207,206,210,209,208],"class_list":["post-1916","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-plsql","tag-dbms_hprof","tag-hierarchical-profiler","tag-plsql-profiler","tag-plsql-tuning","tag-sqldeveloper"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/posts\/1916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/comments?post=1916"}],"version-history":[{"count":16,"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/posts\/1916\/revisions"}],"predecessor-version":[{"id":2071,"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/posts\/1916\/revisions\/2071"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/media\/1907"}],"wp:attachment":[{"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/media?parent=1916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/categories?post=1916"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dbtimewizard.com.br\/blog\/wp-json\/wp\/v2\/tags?post=1916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}