Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
How to optimize where clause query that contains to_char

i need to optimize the where clause query to cut down the cost when i use explain plan.

Below is the original statement

create index idx on orders(o_orderdate)

select *
from orders
where (to_char(o_orderdate, 'dd-mon-yy') = '23-MAR-97' and o_totalprice > 2) or (not o_custkey > 3 and to_char(o_orderdate, 'dd-mon-yyyy') = '23-MAR-1997');

original

This is the explain plan that i get from the original query

But when i try to optimize it using this query

select * 
from orders
where o_totalprice > 2
and o_custkey < 3
and o_orderdate >= to_date('23MAR97', 'dd-mon-yy') 
and o_orderdate <= to_date('24MAR1997', 'dd-mon-yyyy');

new where optimization

it return no rows selected

How do i optimize the original where query and still return 4500 rows?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You did not account for the OR properly. It would be:

select *
from orders
where o_orderdate between to_date('23-MAR-1997','DD-MON-YYYY') 
         and to_date('24-MAR-1997','DD-MON-YYYY') - INTERVAL '1' SECOND
and ( o_totalprice > 2
   or not o_custkey > 3 )
;
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda