Возможные индексы по запросу ниже - PullRequest
0 голосов
/ 12 мая 2018
select uid, user_id, email, mno, orgnztn, status, utype, state,
       to_char(cdate,'yyyy-mm-dd hh:mm:ss') as cdate
from schema.table_1
where puser in (with recursive rel_tree as (
                    select user_id, puser,1 as level,uid
                    from schema.table_1
                    where puser = 9
                    union all
                    select c.user_id, c.puser, p.level + 1 as level ,p.uid
                    from schema.table_1 c
                       join rel_tree p on c.puser = p.uid
                   )
                select uid
                from rel_tree
                union select 9
               )
group by uid, user_id, email, mno, orgnztn, status, utype, state,
         to_char(cdate,'yyyy-mm-dd hh:mm:ss');

1 Ответ

0 голосов
/ 13 мая 2018

вероятно, немного быстрее, как это:

with recursive rel_tree as (
   select
      uid, user_id, email, mno, orgnztn, status, utype, state,
      to_char(cdate,'yyyy-mm-dd hh:mm:ss') as cdate,
      puser,1 as level
   from schema.table_1
   where puser = 9
   union all
   select
      uid, user_id, email, mno, orgnztn, status, utype, state,
      to_char(cdate,'yyyy-mm-dd hh:mm:ss') as cdate,
      puser, p.level + 1 as level
   from schema.table_1 c
   join rel_tree p on c.puser = p.uid
    )
select uid, user_id, email, mno, orgnztn, status, utype, state,
    cdate
from rel_tree
group by uid, user_id, email, mno, orgnztn, status, utype, state,
    cdate;

индекс, который вы хотите это

CREATE INDEX  table_1_puser on  schema.table_1(puser);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...