<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SQL Tunning - Same SELECT diferent DATE parameters in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141216#M800841</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;wow, quite a big join ....&lt;BR /&gt;sure you need everything of this :-)&lt;BR /&gt;&lt;BR /&gt;Did you try /*+ USE_HASH */ as a hint ?&lt;BR /&gt;&lt;BR /&gt;I suppose statistics are up-to-date on all tables and indexes ? Computed or estimated ?&lt;BR /&gt;&lt;BR /&gt;Since you already narrowed it down to a specific column, how many distinct and absolute values do you have on column reportes.f_reporte in the intervals 2001-2002 and 2002-2003 ?&lt;BR /&gt;&lt;BR /&gt;select count(*) from reportes where ...&lt;BR /&gt;and &lt;BR /&gt;select count(distinct f_reporte) from reportes where ...&lt;BR /&gt;&lt;BR /&gt;Also a complete EXPLAIN_PLAN attached would be helpfull. I guess the number of distinct or absolute values of this column makes the optimizer change the access sequence of the tables due to a diffrent amount of expected date. With this change and due to expected data a merge may sound cheaper to friend "optimizer".&lt;BR /&gt;&lt;BR /&gt;No piece of cake, but a real nut to crack&lt;BR /&gt;Volker</description>
    <pubDate>Wed, 10 Dec 2003 16:07:35 GMT</pubDate>
    <dc:creator>Volker Borowski</dc:creator>
    <dc:date>2003-12-10T16:07:35Z</dc:date>
    <item>
      <title>SQL Tunning - Same SELECT diferent DATE parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141215#M800840</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;We have a SELECT sentence than takes a few minutes for a 2 years of data query (2) &amp;amp; it takes several hours for 1 year (1).&lt;BR /&gt;&lt;BR /&gt;We realized that Oracle's Optimizer based on COSTS choose HASH JOIN getting the best results (2) and a MERGE JOIN on the worst case (1) &amp;amp; the cost on the HASH JOIN is higher than MERGE JOIN.&lt;BR /&gt;&lt;BR /&gt;We've tried to force HASH JOIN but we can't get the same execution plan; another HINTS as /*+ INDEX ...*/ /*+ RULE */ have been checked without improvement.&lt;BR /&gt;&lt;BR /&gt;(1)This SQL takes several hours:&lt;BR /&gt;&lt;BR /&gt;SELECT  DISTINCT RD_BUQUE.ID_BUQUE, RD_BUQUE.NOMBRE, RD_BUQUE.LLAMADA,&lt;BR /&gt; RD_TIPO_BUQUES.TIPO, TO_CHAR(rd_trayectoria.f_trayectoria_ini, 'dd/mm/yyyy&lt;BR /&gt;hh24:mi:ss') Fecha_INI,&lt;BR /&gt;  TO_CHAR(rd_trayectoria.f_trayectoria_fin, 'dd/mm/yyyy hh24:mi:ss')&lt;BR /&gt;Fecha_FIN, rd_trayectoria.id_trayectoria,&lt;BR /&gt; RD_CARGA_BUQUE.TN_IMO_7, RD_CARGA_BUQUE.TN_IMO_TOTAL,&lt;BR /&gt;RD_CARGA_BUQUE.TN_TOTAL,RD_REPORTES.DIRECCION ,rd_callsign_pais.nombre_pais&lt;BR /&gt;as pais&lt;BR /&gt; ,RD_TIPO_INCIDENCIAS.descripcion,RD_TIPO_EVENTO.DES_TIPO_EVENTO&lt;BR /&gt;    FROM rd_buque, rd_callsign_pais, rd_carga_buque, rd_evento_track,&lt;BR /&gt;         rd_incidencias, rd_reportes, rd_tipo_buques, rd_tipo_evento,&lt;BR /&gt;         rd_trayectoria, rd_tipo_incidencias&lt;BR /&gt;    WHERE rd_reportes.id_buque = rd_buque.id_buque&lt;BR /&gt;      AND rd_tipo_buques.id_tipo_buque = rd_buque.id_tipo_buque&lt;BR /&gt;      AND rd_reportes.id_reporte = rd_trayectoria.id_reporte&lt;BR /&gt;      AND rd_reportes.id_reporte = rd_carga_buque.id_reporte (+)&lt;BR /&gt;      AND rd_callsign_pais.llamada_ini (+) &amp;lt;= rd_buque.llamada&lt;BR /&gt;      AND rd_callsign_pais.llamada_fin (+) &amp;gt;= rd_buque.llamada&lt;BR /&gt;      AND rd_trayectoria.id_trayectoria = rd_incidencias.id_trayectoria (+)&lt;BR /&gt;      AND rd_tipo_incidencias.id_tipo_incidencia (+) =&lt;BR /&gt;          rd_incidencias.tipoincidencia&lt;BR /&gt;      AND rd_evento_track.id_trayectoria (+) = rd_trayectoria.id_trayectoria&lt;BR /&gt;      AND rd_evento_track.id_tipo_evento = rd_tipo_evento.id_tipo_evento (+)&lt;BR /&gt;      AND rd_reportes.f_reporte BETWEEN to_date('02/12/2002 00.00.00',&lt;BR /&gt;          'dd/mm/yyyy hh24:mi:ss') AND to_date('02/12/2003 23.59.59',&lt;BR /&gt;          'dd/mm/yyyy hh24:mi:ss')&lt;BR /&gt;      AND rd_callsign_pais.nombre_pais = 'Rusia'&lt;BR /&gt;      AND rd_tipo_buques.tipo = 'TANQUE'&lt;BR /&gt;&lt;BR /&gt;(2) And if we ask for " AND reportes.f_reporte BETWEEN to_date('02/12/2001&lt;BR /&gt;00.00.00', ..." instead " AND rd_reportes.f_reporte BETWEEN to_date('02/12/2002 00.00.00',..." takes only several minutes.&lt;BR /&gt;&lt;BR /&gt;Any idea for improving first query?&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 10 Dec 2003 12:25:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141215#M800840</guid>
      <dc:creator>Serafín Cerezales</dc:creator>
      <dc:date>2003-12-10T12:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Tunning - Same SELECT diferent DATE parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141216#M800841</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;wow, quite a big join ....&lt;BR /&gt;sure you need everything of this :-)&lt;BR /&gt;&lt;BR /&gt;Did you try /*+ USE_HASH */ as a hint ?&lt;BR /&gt;&lt;BR /&gt;I suppose statistics are up-to-date on all tables and indexes ? Computed or estimated ?&lt;BR /&gt;&lt;BR /&gt;Since you already narrowed it down to a specific column, how many distinct and absolute values do you have on column reportes.f_reporte in the intervals 2001-2002 and 2002-2003 ?&lt;BR /&gt;&lt;BR /&gt;select count(*) from reportes where ...&lt;BR /&gt;and &lt;BR /&gt;select count(distinct f_reporte) from reportes where ...&lt;BR /&gt;&lt;BR /&gt;Also a complete EXPLAIN_PLAN attached would be helpfull. I guess the number of distinct or absolute values of this column makes the optimizer change the access sequence of the tables due to a diffrent amount of expected date. With this change and due to expected data a merge may sound cheaper to friend "optimizer".&lt;BR /&gt;&lt;BR /&gt;No piece of cake, but a real nut to crack&lt;BR /&gt;Volker</description>
      <pubDate>Wed, 10 Dec 2003 16:07:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141216#M800841</guid>
      <dc:creator>Volker Borowski</dc:creator>
      <dc:date>2003-12-10T16:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Tunning - Same SELECT diferent DATE parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141217#M800842</link>
      <description>Can you post the explain plan for both queries?  Also, can you make sure that the object have current statistics.  &lt;BR /&gt;&lt;BR /&gt;The following is what I use to display information from the plan_table.  &lt;BR /&gt;&lt;BR /&gt;set linesize 150&lt;BR /&gt;set pagesize 1000&lt;BR /&gt;column operation format a50&lt;BR /&gt;column optimizer format a15&lt;BR /&gt;SELECT LPAD(' ',2*(LEVEL-1))||operation operation, optimizer,options, object_name, &lt;BR /&gt;position, cost from plan_table START WITH id = 0 CONNECT BY PRIOR id = parent_id;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Brian</description>
      <pubDate>Wed, 10 Dec 2003 16:33:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141217#M800842</guid>
      <dc:creator>Brian Crabtree</dc:creator>
      <dc:date>2003-12-10T16:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Tunning - Same SELECT diferent DATE parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141218#M800843</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;Are the statistics up-to-date?&lt;BR /&gt;&lt;BR /&gt;You may consider recalculating the statistics on these tables since you are using the CBO this is important.&lt;BR /&gt;&lt;BR /&gt;Hopefully, you have monitoring enabled on all these tables and are using DBMS_STATS package to gather the statistics on all tables where the statistics are STALE.&lt;BR /&gt;&lt;BR /&gt;E.g. &lt;BR /&gt;&lt;BR /&gt;Alter table &lt;TABLE name=""&gt; monitoring;&lt;BR /&gt;&lt;BR /&gt;exec dbms_stats.gather_schema_stats( ownname =&amp;gt; user, options =&amp;gt; 'GATHER STALE' );&lt;BR /&gt;&lt;BR /&gt;(these two commands will keep track for you and only analyze tables in which about 10% of the data has changed)&lt;BR /&gt;&lt;BR /&gt;Then, retry your query.&lt;BR /&gt;&lt;BR /&gt;You may wish to "alter session set sql_trace=true", use tkprof to generate a report on your query using the trace file generated and post it here.&lt;BR /&gt;&lt;BR /&gt;hope this helps too!&lt;BR /&gt;&lt;BR /&gt;regards&lt;BR /&gt;Yogeeraj&lt;/TABLE&gt;</description>
      <pubDate>Wed, 10 Dec 2003 23:03:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sql-tunning-same-select-diferent-date-parameters/m-p/3141218#M800843</guid>
      <dc:creator>Yogeeraj_1</dc:creator>
      <dc:date>2003-12-10T23:03:23Z</dc:date>
    </item>
  </channel>
</rss>

