oracle - How can I optimize this SQL Query? -


i have 3 tables on oracle context, let's call them t1, t2, t3 have following structure :

  • t1 : t1_id, t1_name, ...
  • t2 : t1_id, t3_name, ...
  • t3 : t3_name, randomcol1, randomcol2, randomcol3, ...

what want query give me result :

t0_name | randomcol

so made query :

      select t1.t1_name, t3.randomcol1 randomcol       t1       join t2 on t1.t1_id=t2.t1_id       join t3 on t2.t3_name=t3.t3_name       t3.randomcol1 '_%'     union       select t1.t1_name, t3.randomcol2 randomcol       t1       join t2 on t1.t1_id=t2.t1_id       join t3 on t2.t3_name=t3.t3_name       t3.randomcol2 '_%'     union       select t1.t1_name, t3.randomcol3 randomcol       t1       join t2 on t1.t1_id=t2.t1_id       join t3 on t2.t3_name=t3.t3_name       t3.randomcol3 '_%' 

because wanted values of randomcols starting _ in single column, paired t1_name linked them. give more intel, randomcol1 , randomcol2 same (they both not null @ same times , have same values), while randomcol3 null.


i know awful in term of performance, tried improve it.

therefore searched on web various ways optimize solution (like using union , stuff) nothing gave me exact result want.

so question following : do have idea of how can optimize query ?

regards

one possible variant:

  select *   (select t1.t1_name,            case l.l               when 1 t3.randomcol1                when 2 t3.randomcol2                when 3 t3.randomcol3           end randomcol    (select level l dual connect level <= 3) l    cross join t1    join t2 on t1.t1_id=t2.t1_id    join t3 on t2.t3_name=t3.t3_name    '_' in (substr(t3.randomcol1,1,1),                  substr(t3.randomcol2,1,1),                  substr(t3.randomcol3,1,1))   ) randomcol '_%' 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -