Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda